ipfw: Implement state based "redirect", i.e. without using libalias.
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 30 Sep 2017 06:39:48 +0000 (14:39 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 14 Oct 2017 23:19:04 +0000 (07:19 +0800)
commite622598eabbac3d195b7fd68780c9131296b638c
tree5c09c78128fd181a64a6316e47fa35be13d2e3e8
parentde7ba607e4500e7df6ade3916977cc8a91e1b4e9
ipfw: Implement state based "redirect", i.e. without using libalias.

Redirection creates two states, i.e. one before the translation (xlat0)
and one after the translation (xlat1).  If the hash of the translated
packet indicates that it is owned by a remote CPU:
- If the packet triggers the state pair creation, the 'xlat1' will be
  piggybacked by the translated packet, which will be forwarded to the
  remote CPU for further evalution.  And the 'xlat1' will be installed
  on the remote CPU before the evalution of the translated packet.
- Else only the translated packet will be forwarded to the remote CPU
  for further evalution.

The 'xlat1' is called the slave state, which will be deleted only when
the 'xlat0' (the master state) is deleted.  The state pair is always
deleted on the CPU owning the 'xlat1'; the 'xlat0' will be forwarded
there.

The reference counting of the state pair is maintained independently
in each state, the memory of the state pair will be freed only after
the sum of the counter in each state reaches 0.  This avoids expensive
per-packet atomic ops.

As far as I have tested, this implementation of "redirect" does _not_
introduce any noticeable performance reduction, latency increasing or
latency destability.

This commit makes most of the necessary bits for NAT ready too.
sbin/ipfw/ipfw.8
sbin/ipfw/ipfw2.c
sys/net/if_ethersubr.c
sys/net/ipfw/ip_fw2.c
sys/net/ipfw/ip_fw2.h
sys/netinet/ip_output.c
sys/sys/mbuf.h