Subject: An approach for detachable interfaces.
To: None <tech-net@netbsd.org>
From: Bill Sommerfeld <sommerfeld@orchard.arlington.ma.us>
List: tech-net
Date: 11/05/1999 14:24:32
Recently I worked out a scheme for implementing detachable interfaces
which doesn't require code changes in drivers which don't need to be
detachable, and requires minimal code changes outside drivers and the
interface management code in sys/net.  

This means we can add the infrastructure support for it, then fix the
drivers which really need it one by one, rather than having a big flag
day converting all the drivers.  Most importantly, we don't need to
change the rest of the stack to reference count interfaces and ifaddrs
(though this approach doesn't preclude doing this at a future date).

Here's the desired behavior from my POV:

 - interface attributes set from userland (interface addresses,
	  up/down status, ...) survive detach/reattach cycles.
 - when a device is detached from an interface, the detach routine in
   the driver cleans up any hardware resources and then calls if_detach(); 
   if_detach() resets the function pointers
   in the ifp to point to a "blackhole" handlers which
   simply bitbucket outbound packets
   the detach routine returns success and pcmcia or cardbus or
   whatever causes the softc to be deallocated.
  
 - when the hardware reappears, a new softc is allocated.

   We add a new function i'm tenatively calling if_locate(); the
   device attach routine calls if_locate(sc->sc_dev.dv_xname, ...)  to
   find its ifp; if_locate looks for an interface by name, allocating
   a new one if not found.

if_ether* changes:

 - since the additional state in "struct ethercom" is just the
multicast address list, and that state should survive detach/reattach,
it would seem to make sense to keep the ethercom state separate from
the softc as well.

 - we add a new function akin to if_locate() to find the ethercom
state, and an ether-specific wrapper for if_detach to dissocate it
from the interface.

 - struct ethercom gets a new "ec_ifp" member added.   

 - for backwards compatibility, ether_ifattach just sets ec_ifp to &ec_if.

 - once all drivers and common code are converted to the new format,
we flush the backwards-compat ifnet in struct ethercom

The net effect of this will be that you should be able to (for
instance) move an ethernet card from slot A to slot B with the same
application-visible behavior as if you unplugged and replugged the
network cable for a few seconds.

If you disconnect an interface and leave it disconnected permanently,
the "blackholed" interfaces will hang around forever, but that doesn't
seem like a particuarly problematic behavior in normal use (where one
is switching among a small, but limited, set of interfaces -- for
instance, a modem card, an ethernet card, and a wireless network
interface).

I've started coding this; assuming I can get it working shortly and
assuming I don't hear too many screams of anguish, it may end up in
the tree in the next month or so..

Comments and constructive feedback will be appreciated..

					- Bill