From 567ba9b00a248431e7c1147c4e079fd7a11b9ecf Mon Sep 17 00:00:00 2001 From: brooks Date: Fri, 10 Jun 2005 16:49:24 +0000 Subject: Stop embedding struct ifnet at the top of driver softcs. Instead the struct ifnet or the layer 2 common structure it was embedded in have been replaced with a struct ifnet pointer to be filled by a call to the new function, if_alloc(). The layer 2 common structure is also allocated via if_alloc() based on the interface type. It is hung off the new struct ifnet member, if_l2com. This change removes the size of these structures from the kernel ABI and will allow us to better manage them as interfaces come and go. Other changes of note: - Struct arpcom is no longer referenced in normal interface code. Instead the Ethernet address is accessed via the IFP2ENADDR() macro. To enforce this ac_enaddr has been renamed to _ac_enaddr. - The second argument to ether_ifattach is now always the mac address from driver private storage rather than sometimes being ac_enaddr. Reviewed by: sobomax, sam --- sys/dev/cp/if_cp.c | 138 ++++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 65 deletions(-) (limited to 'sys/dev/cp/if_cp.c') diff --git a/sys/dev/cp/if_cp.c b/sys/dev/cp/if_cp.c index df8f7ce..39990fe 100644 --- a/sys/dev/cp/if_cp.c +++ b/sys/dev/cp/if_cp.c @@ -56,6 +56,8 @@ __FBSDID("$FreeBSD$"); # include #else # include +# include +#include # define PP_CISCO IFF_LINK2 # include #endif @@ -135,7 +137,7 @@ typedef struct _drv_t { struct callout timeout_handle; #else struct ifqueue queue; - struct sppp pp; + struct ifnet *ifp; #endif struct cdev *devt; } drv_t; @@ -329,7 +331,7 @@ static void cp_intr (void *arg) IF_DEQUEUE (&d->queue,m); if (!m) continue; - sppp_input (&d->pp.pp_if, m); + sppp_input (d->ifp, m); } } #endif @@ -514,25 +516,30 @@ static int cp_attach (device_t dev) callout_init (&d->timeout_handle, cp_mpsafenet ? CALLOUT_MPSAFE : 0); #else /*NETGRAPH*/ - d->pp.pp_if.if_softc = d; - if_initname (&d->pp.pp_if, "cp", b->num * NCHAN + c->num); - d->pp.pp_if.if_mtu = PP_MTU; - d->pp.pp_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; + d->ifp = if_alloc(IFT_PPP); + if (d->ifp == NULL) { + printf ("%s: cannot if_alloc() interface\n", d->name); + continue; + } + d->ifp->if_softc = d; + if_initname (d->ifp, "cp", b->num * NCHAN + c->num); + d->ifp->if_mtu = PP_MTU; + d->ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST; if (!cp_mpsafenet) - d->pp.pp_if.if_flags |= IFF_NEEDSGIANT; - d->pp.pp_if.if_ioctl = cp_sioctl; - d->pp.pp_if.if_start = cp_ifstart; - d->pp.pp_if.if_watchdog = cp_ifwatchdog; - d->pp.pp_if.if_init = cp_initialize; + d->ifp->if_flags |= IFF_NEEDSGIANT; + d->ifp->if_ioctl = cp_sioctl; + d->ifp->if_start = cp_ifstart; + d->ifp->if_watchdog = cp_ifwatchdog; + d->ifp->if_init = cp_initialize; d->queue.ifq_maxlen = NRBUF; mtx_init (&d->queue.ifq_mtx, "cp_queue", NULL, MTX_DEF); - sppp_attach (&d->pp.pp_if); - if_attach (&d->pp.pp_if); - d->pp.pp_tlf = cp_tlf; - d->pp.pp_tls = cp_tls; + sppp_attach (d->ifp); + if_attach (d->ifp); + IFP2SP(d->ifp)->pp_tlf = cp_tlf; + IFP2SP(d->ifp)->pp_tls = cp_tls; /* If BPF is in the kernel, call the attach for it. * The header size of PPP or Cisco/HDLC is 4 bytes. */ - bpfattach (&d->pp.pp_if, DLT_PPP, 4); + bpfattach (d->ifp, DLT_PPP, 4); #endif /*NETGRAPH*/ cp_start_e1 (c); cp_start_chan (c, 1, 1, d->dmamem.virt, d->dmamem.phys); @@ -603,13 +610,14 @@ static int cp_detach (device_t dev) continue; #ifndef NETGRAPH /* Detach from the packet filter list of interfaces. */ - bpfdetach (&d->pp.pp_if); + bpfdetach (d->ifp); /* Detach from the sync PPP list. */ - sppp_detach (&d->pp.pp_if); + sppp_detach (d->ifp); /* Detach from the system list of interfaces. */ - if_detach (&d->pp.pp_if); + if_detach (d->ifp); + if_free (d->ifp); IF_DRAIN (&d->queue); mtx_destroy (&d->queue.ifq_mtx); #else @@ -677,22 +685,22 @@ static void cp_ifwatchdog (struct ifnet *ifp) static void cp_tlf (struct sppp *sp) { - drv_t *d = sp->pp_if.if_softc; + drv_t *d = SP2IFP(sp)->if_softc; CP_DEBUG2 (d, ("cp_tlf\n")); /* XXXRIK: Don't forget to protect them by LOCK, or kill them. */ /* cp_set_dtr (d->chan, 0);*/ /* cp_set_rts (d->chan, 0);*/ - if (!(d->pp.pp_flags & PP_FR) && !(d->pp.pp_if.if_flags & PP_CISCO)) + if (!(sp->pp_flags & PP_FR) && !(d->ifp->if_flags & PP_CISCO)) sp->pp_down (sp); } static void cp_tls (struct sppp *sp) { - drv_t *d = sp->pp_if.if_softc; + drv_t *d = SP2IFP(sp)->if_softc; CP_DEBUG2 (d, ("cp_tls\n")); - if (!(d->pp.pp_flags & PP_FR) && !(d->pp.pp_if.if_flags & PP_CISCO)) + if (!(sp->pp_flags & PP_FR) && !(d->ifp->if_flags & PP_CISCO)) sp->pp_up (sp); } @@ -734,7 +742,7 @@ static int cp_sioctl (struct ifnet *ifp, u_long cmd, caddr_t data) cp_start (d); } else if (was_up && ! should_be_up) { /* Interface is going down -- stop it. */ -/* if ((d->pp.pp_flags & PP_FR) || (ifp->if_flags & PP_CISCO))*/ +/* if ((IFP2SP(ifp)->pp_flags & PP_FR) || (ifp->if_flags & PP_CISCO))*/ cp_down (d); } CP_DEBUG (d, ("ioctl 0x%lx p4\n", cmd)); @@ -807,13 +815,13 @@ static void cp_send (drv_t *d) if (! m) IF_DEQUEUE (&d->queue, m); #else - m = sppp_dequeue (&d->pp.pp_if); + m = sppp_dequeue (d->ifp); #endif if (! m) return; #ifndef NETGRAPH - if (d->pp.pp_if.if_bpf) - BPF_MTAP (&d->pp.pp_if, m); + if (d->ifp->if_bpf) + BPF_MTAP (d->ifp, m); #endif len = m->m_pkthdr.len; if (len >= BUFSZ) @@ -831,11 +839,11 @@ static void cp_send (drv_t *d) #ifdef NETGRAPH d->timeout = 10; #else - d->pp.pp_if.if_timer = 10; + d->ifp->if_timer = 10; #endif } #ifndef NETGRAPH - d->pp.pp_if.if_flags |= IFF_OACTIVE; + d->ifp->if_flags |= IFF_OACTIVE; #endif } @@ -886,9 +894,9 @@ static void cp_transmit (cp_chan_t *c, void *attachment, int len) #ifdef NETGRAPH d->timeout = 0; #else - ++d->pp.pp_if.if_opackets; - d->pp.pp_if.if_flags &= ~IFF_OACTIVE; - d->pp.pp_if.if_timer = 0; + ++d->ifp->if_opackets; + d->ifp->if_flags &= ~IFF_OACTIVE; + d->ifp->if_timer = 0; #endif cp_start (d); } @@ -908,7 +916,7 @@ static void cp_receive (cp_chan_t *c, unsigned char *data, int len) if (! m) { CP_DEBUG (d, ("no memory for packet\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_iqdrops; + ++d->ifp->if_iqdrops; #endif return; } @@ -918,12 +926,12 @@ static void cp_receive (cp_chan_t *c, unsigned char *data, int len) m->m_pkthdr.rcvif = 0; NG_SEND_DATA_ONLY (error, d->hook, m); #else - ++d->pp.pp_if.if_ipackets; - m->m_pkthdr.rcvif = &d->pp.pp_if; + ++d->ifp->if_ipackets; + m->m_pkthdr.rcvif = d->ifp; /* Check if there's a BPF listener on this interface. * If so, hand off the raw packet to bpf. */ - if (d->pp.pp_if.if_bpf) - BPF_TAP (&d->pp.pp_if, data, len); + if (d->ifp->if_bpf) + BPF_TAP (d->ifp, data, len); IF_ENQUEUE (&d->queue, m); #endif } @@ -936,26 +944,26 @@ static void cp_error (cp_chan_t *c, int data) case CP_FRAME: CP_DEBUG (d, ("frame error\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CP_CRC: CP_DEBUG (d, ("crc error\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CP_OVERRUN: CP_DEBUG (d, ("overrun error\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_collisions; - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_collisions; + ++d->ifp->if_ierrors; #endif break; case CP_OVERFLOW: CP_DEBUG (d, ("overflow error\n")); #ifndef NETGRAPH - ++d->pp.pp_if.if_ierrors; + ++d->ifp->if_ierrors; #endif break; case CP_UNDERRUN: @@ -963,9 +971,9 @@ static void cp_error (cp_chan_t *c, int data) #ifdef NETGRAPH d->timeout = 0; #else - ++d->pp.pp_if.if_oerrors; - d->pp.pp_if.if_flags &= ~IFF_OACTIVE; - d->pp.pp_if.if_timer = 0; + ++d->ifp->if_oerrors; + d->ifp->if_flags &= ~IFF_OACTIVE; + d->ifp->if_timer = 0; #endif cp_start (d); break; @@ -1044,8 +1052,8 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc #ifndef NETGRAPH case SERIAL_GETPROTO: CP_DEBUG2 (d, ("ioctl: getproto\n")); - strcpy ((char*)data, (d->pp.pp_flags & PP_FR) ? "fr" : - (d->pp.pp_if.if_flags & PP_CISCO) ? "cisco" : "ppp"); + strcpy ((char*)data, (IFP2SP(d->ifp)->pp_flags & PP_FR) ? "fr" : + (d->ifp->if_flags & PP_CISCO) ? "cisco" : "ppp"); return 0; case SERIAL_SETPROTO: @@ -1054,29 +1062,29 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc error = suser (td); if (error) return error; - if (d->pp.pp_if.if_flags & IFF_RUNNING) + if (d->ifp->if_flags & IFF_RUNNING) return EBUSY; if (! strcmp ("cisco", (char*)data)) { - d->pp.pp_flags &= ~(PP_FR); - d->pp.pp_flags |= PP_KEEPALIVE; - d->pp.pp_if.if_flags |= PP_CISCO; + IFP2SP(d->ifp)->pp_flags &= ~(PP_FR); + IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; + d->ifp->if_flags |= PP_CISCO; } else if (! strcmp ("fr", (char*)data) && PP_FR) { - d->pp.pp_if.if_flags &= ~(PP_CISCO); - d->pp.pp_flags |= PP_FR | PP_KEEPALIVE; + d->ifp->if_flags &= ~(PP_CISCO); + IFP2SP(d->ifp)->pp_flags |= PP_FR | PP_KEEPALIVE; } else if (! strcmp ("ppp", (char*)data)) { - d->pp.pp_flags &= ~PP_FR; - d->pp.pp_flags &= ~PP_KEEPALIVE; - d->pp.pp_if.if_flags &= ~(PP_CISCO); + IFP2SP(d->ifp)->pp_flags &= ~PP_FR; + IFP2SP(d->ifp)->pp_flags &= ~PP_KEEPALIVE; + d->ifp->if_flags &= ~(PP_CISCO); } else return EINVAL; return 0; case SERIAL_GETKEEPALIVE: CP_DEBUG2 (d, ("ioctl: getkeepalive\n")); - if ((d->pp.pp_flags & PP_FR) || - (d->pp.pp_if.if_flags & PP_CISCO)) + if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || + (d->ifp->if_flags & PP_CISCO)) return EINVAL; - *(int*)data = (d->pp.pp_flags & PP_KEEPALIVE) ? 1 : 0; + *(int*)data = (IFP2SP(d->ifp)->pp_flags & PP_KEEPALIVE) ? 1 : 0; return 0; case SERIAL_SETKEEPALIVE: @@ -1085,15 +1093,15 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc error = suser (td); if (error) return error; - if ((d->pp.pp_flags & PP_FR) || - (d->pp.pp_if.if_flags & PP_CISCO)) + if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || + (d->ifp->if_flags & PP_CISCO)) return EINVAL; s = splimp (); CP_LOCK (bd); if (*(int*)data) - d->pp.pp_flags |= PP_KEEPALIVE; + IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; else - d->pp.pp_flags &= ~PP_KEEPALIVE; + IFP2SP(d->ifp)->pp_flags &= ~PP_KEEPALIVE; CP_UNLOCK (bd); splx (s); return 0; @@ -1334,9 +1342,9 @@ static int cp_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struc d->chan->debug = *(int*)data; #ifndef NETGRAPH if (d->chan->debug) - d->pp.pp_if.if_flags |= IFF_DEBUG; + d->ifp->if_flags |= IFF_DEBUG; else - d->pp.pp_if.if_flags &= ~IFF_DEBUG; + d->ifp->if_flags &= ~IFF_DEBUG; #endif return 0; -- cgit v1.1