NetBSD Documentation:Converting ancient BSD Ethernet drivers to NetBSD-1.2D and later |
struct ifnet *ifp;is a pointer to the interface structure of "our" device and
struct foo_softc *sc;is a pointer to our softc structure.
#include <netinet/if_ether.h>use
#include <net/if_dl.h> /* for the LLADDR macro */ #include <net/if_ether.h> /* for real Ethernet stuff */ #include <netinet/if_inarp.h> /* for IP-specific ARP stuff. */Sometimes you also need
#include <net/if_arp.h>
struct arpcom
from the beginning of the softc
definition. In most drivers it is called
struct arpcom sc_ac;or
struct arpcom sc_arpcom;Throughout this text, we assume the former.
struct ethercom
instead. Throughout this text, we
assume you called it
struct ethercom sc_ec;
sc->sc_ac
by sc->sc_ec
.
sc_ac.ac_if
by
sc_ec.ec_if
.
[While you are here: I've seen lots of places, where, at the beginning of a function, a struct ifnet * parameter is converted to a struct foo_softc *, and later there are lots of sc->sc_if.bar or &sc->sc_if accesses. This is ugly, confusing and unnecessary. Depending on the nature of the driver you might want to change this while you're at it.]
arp_ifinit()
(there is a man page on this) takes a
struct ifnet *
as
the first parameter, instead of a struct arpcom *
.
You may have noticed by now, that you don't have a hardware address any longer in the softc.
There are two types of accesses to it. One is initialization, in the
foo_attach()
function (if this is done in the
fooprobe()/foomatch()
function,
your driver is broken for other reasons and should be fixed); the
other is runtime reads, and for crazy protocols like XNS, OSI, DECnet,
even writes.
ether_ifattach()
(there should
be a man page on this) with a 2nd parameter, a u_int8_t *
pointing to the address. ether_ifattach()
will create (as before)
a struct sockaddr_dl
in the interface address list, copy (among
other initialization) the address there, and makes ifp->if_sadl
point to it.
LLADDR(ifp->if_sadl)
as a caddr_t pointing
to our Ethernet address. If you need the address length, you should probably
use ETHER_ADDR_LEN
.
|
|