carp: Make carp interfaces work like ethernet interfaces
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 23 Jan 2012 08:19:06 +0000 (16:19 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 1 Feb 2012 06:27:02 +0000 (14:27 +0800)
commit24c6e413b468b125c85ed0ae5010dddd6de548ee
treed7f18b8cc5e73ea118f3b20b5d0cf5639e37087c
parentf84f7e8121e08af5d133a8b38a385aaca6c66e29
carp: Make carp interfaces work like ethernet interfaces

- Use ether_ifattach() instead of if_attach() to attach carp and carp's
  ioctl methed will fallback to ether_ioctl().
- VHID changes will be reflected into the carp's ethernet address.
- Reimplement carp output path.
  *  carp uses the parent's if_output() i.e. ether_output(), but passes
     the carp interface's ifp.
  *  The ether_output() is adjusted to detect the carp interface and
     switch to the carp's parent interface just before performing the
     real output.
  *  ARP resolve will use carp instead of its parent interface, thus
     the ARP output's source ethernet address and the sender hardware
     address are consistent and loopback on the carp will work as
     expected.
- Reimplement carp input path>
  *  Input interface will be changed to carp if the packet is destined
     to the carp's ethernet address.
  *  If the received packet is broadcast or multicast, all of the carps
     on the receiving interface will receive a copy of the packet.
- Fix up gratuitous ARP.
  *  No gratuitous ARP will be sent for carp upon IP address changes.
  *  Gratuitous ARP sent by carp use itself as interface not carp's
     parent interface.
- Fix up ARP input path.  Since ARP request is broadcast packet, parent
  interface of the carp will also receive the packet and will reply the
  ARP request.  If carp and its parent interface have same IP address,
  the parent's ARP reply will confuse the ARP requester: the ethernet
  address of the IP is no longer carp's ethernet address.
- Rework carp's prefix route addition and deletion.
  *  Add IP addresses to carp will not add prefix routes
  *  Bring carp interface up will not add prefix routes for carp's
     existing IP addresses
  *  Carp IP addresses prefix route will be added when carp is master,
     and the parent's corresponding IP addresses prefix route will be
     deleted.
  *  Carp IP addresses prefix route will be deleted when carp is no
     longer master and the parent's corresponding IP addresses prefix
     route will be added back.
- Handle carp parent interface's up/down events.
  *  When carp's parent is down, we fake up a parent IP address deletion
     event for carp.
  *  When carp's parent is up, we fake up a parent IP address addition
     event for carp.
- Stringent checks on CARP proto input path.
- Nullfy ifnet's serialier; carp is protected by global carp token.
- Mark CARP protocol MPSAFE

Idea-from: OpenBSD
sys/net/if_ethersubr.c
sys/netinet/if_ether.c
sys/netinet/if_ether.h
sys/netinet/in.c
sys/netinet/in_proto.c
sys/netinet/ip_carp.c
sys/netinet/ip_carp.h
sys/netinet/raw_ip.c
sys/netinet6/in6_proto.c