Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Rework layer 2 protocol input routines. Instead of call...



details:   https://anonhg.NetBSD.org/src/rev/648eb9e18df8
branches:  trunk
changeset: 473061:648eb9e18df8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue May 18 23:52:51 1999 +0000

description:
Rework layer 2 protocol input routines.  Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m).  The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary.  Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.

diffstat:

 sys/arch/alpha/a12/if_ade.c      |  28 +++++++++++++----------
 sys/arch/amiga/dev/if_ed.c       |   6 +---
 sys/arch/amiga/dev/if_es.c       |   9 +-----
 sys/arch/amiga/dev/if_qn.c       |   6 +---
 sys/arch/arm32/podulebus/if_ea.c |  11 ++------
 sys/arch/arm32/podulebus/if_eb.c |  11 ++------
 sys/arch/arm32/podulebus/if_ie.c |  27 ++++++++++++----------
 sys/arch/arm32/rc7500/if_es.c    |  11 +++-----
 sys/arch/mac68k/dev/if_mc.c      |   7 ++---
 sys/arch/mac68k/dev/if_sn.c      |  23 +++++++-----------
 sys/arch/macppc/dev/am79c950.c   |   7 ++---
 sys/arch/macppc/dev/if_bm.c      |   5 +--
 sys/arch/next68k/dev/mb8795.c    |  10 ++-----
 sys/arch/pc532/dev/lpt.c         |   6 +---
 sys/arch/sun3/dev/if_ie.c        |  45 +++++++++++++++++++++-----------------
 sys/arch/vax/if/if_de.c          |  15 ++++++++++--
 sys/arch/vax/if/if_qe.c          |  23 +++++++++++-------
 sys/arch/vax/vsa/if_ln.c         |   7 ++---
 sys/arch/x68k/dev/if_se.c        |  12 +--------
 sys/dev/ic/dp8390.c              |   6 +---
 sys/dev/ic/elink3.c              |   7 +----
 sys/dev/ic/elinkxl.c             |  10 ++-----
 sys/dev/ic/i82586.c              |  47 ++++++++++++++++++++++-----------------
 sys/dev/ic/lance.c               |   7 ++---
 sys/dev/ic/lemac.c               |   8 ++----
 sys/dev/ic/mb86960.c             |   6 +---
 sys/dev/ic/pdq_ifsubr.c          |  12 +++++-----
 sys/dev/ic/rrunner.c             |  10 +++-----
 sys/dev/ic/smc83c170.c           |   7 ++---
 sys/dev/ic/smc90cx6.c            |   7 +----
 sys/dev/ic/smc91cxx.c            |  11 ++------
 sys/dev/ic/tropic.c              |  11 +-------
 sys/dev/isa/cs89x0.c             |  10 ++-----
 sys/dev/isa/if_eg.c              |   6 +---
 sys/dev/isa/if_el.c              |   6 +---
 sys/dev/isa/if_iy.c              |   5 +--
 sys/dev/ofw/ofnet.c              |   7 +----
 sys/dev/pci/if_de.c              |  28 +++++++++++++----------
 sys/dev/pci/if_fxp.c             |  10 ++-----
 sys/dev/pci/if_tl.c              |   8 ++----
 sys/dev/pci/if_vr.c              |   8 ++----
 sys/dev/pcmcia/if_cnw.c          |   7 ++---
 sys/dev/sbus/be.c                |  11 ++------
 sys/dev/sbus/qe.c                |  11 ++------
 sys/dev/scsipi/if_se.c           |   7 ++---
 sys/ipkdb/ipkdb_if.c             |   9 +-----
 sys/net/if.h                     |   7 ++---
 sys/net/if_arcsubr.c             |  12 +++++++--
 sys/net/if_atmsubr.c             |   5 +++-
 sys/net/if_ethersubr.c           |  28 +++++++++++++++++------
 sys/net/if_fddi.h                |   6 +----
 sys/net/if_fddisubr.c            |  28 +++++++++++++++++------
 sys/net/if_hippi.h               |   6 +----
 sys/net/if_hippisubr.c           |  25 ++++++++++++++------
 sys/net/if_token.h               |   6 +----
 sys/net/if_tokensubr.c           |  39 ++++++++++++++++++++++----------
 56 files changed, 339 insertions(+), 374 deletions(-)

diffs (truncated from 2242 to 300 lines):

diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/alpha/a12/if_ade.c
--- a/sys/arch/alpha/a12/if_ade.c       Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/alpha/a12/if_ade.c       Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ade.c,v 1.2 1999/04/10 01:21:36 cgd Exp $   */
+/*     $NetBSD: if_ade.c,v 1.3 1999/05/18 23:52:51 thorpej Exp $       */
 
 /*
  * NOTE: this version of if_de was modified for bounce buffers prior
@@ -3389,7 +3389,6 @@
                    goto next;
            accept = 1;
            sc->tulip_flags |= TULIP_RXACT;
-           total_len -= sizeof(struct ether_header);
        } else {
            ifp->if_ierrors++;
            if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
@@ -3445,7 +3444,7 @@
            MGETHDR(m0, M_DONTWAIT, MT_DATA);
            if (m0 != NULL) {
 #if defined(TULIP_COPY_RXDATA)
-               if (!accept || total_len >= MHLEN) {
+               if (!accept || total_len >= MHLEN - 2) {
 #endif
                    MCLGET(m0, M_DONTWAIT);
                    if ((m0->m_flags & M_EXT) == 0) {
@@ -3465,11 +3464,14 @@
                eh.ether_type = ntohs(eh.ether_type);
 #endif
 #if !defined(TULIP_COPY_RXDATA)
-               ms->m_data += sizeof(struct ether_header);
-               ms->m_len -= sizeof(struct ether_header);
                ms->m_pkthdr.len = total_len;
                ms->m_pkthdr.rcvif = ifp;
+#if defined(__NetBSD__)
+               (*ifp->if_input)(ifp, ms);
+#else
+               m_adj(ms, sizeof(struct ether_header);
                ether_input(ifp, &eh, ms);
+#endif /* __NetBSD__ */
 #ifdef LCLDMA
 #error LCLDMA requires TULIP_COPY_RXDATA
 #endif
@@ -3477,16 +3479,18 @@
 #ifdef BIG_PACKET
 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
 #endif
-               if (ms == me)
-                   bcopy(mtod(ms, caddr_t) + sizeof(struct ether_header),
-                         mtod(m0, caddr_t), total_len);
-               else
-                   m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
+               m0->m_data += 2;        /* align data after header */
+               m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
                m0->m_len = m0->m_pkthdr.len = total_len;
                m0->m_pkthdr.rcvif = ifp;
+#if defined(__NetBSD__)
+               (*ifp->if_input)(ifp, m0);
+#else
+               m_adj(m0, sizeof(struct ether_header);
                ether_input(ifp, &eh, m0);
+#endif /* __NetBSD__ */
                m0 = ms;
-#endif
+#endif /* ! TULIP_COPY_RXDATA */
            }
            ms = m0;
        }
@@ -4434,7 +4438,7 @@
     ifp->if_start = tulip_ifstart;
     ifp->if_watchdog = tulip_ifwatchdog;
     ifp->if_timer = 1;
-#if !defined(__bsdi__) || _BSDI_VERSION < 199401
+#if (!defined(__bsdi__) || _BSDI_VERSION < 199401) && !defined(__NetBSD__)
     ifp->if_output = ether_output;
 #endif
 #if defined(__bsdi__) && _BSDI_VERSION < 199401
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/amiga/dev/if_ed.c
--- a/sys/arch/amiga/dev/if_ed.c        Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/amiga/dev/if_ed.c        Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ed.c,v 1.31 1999/03/25 23:10:13 thorpej Exp $       */
+/*     $NetBSD: if_ed.c,v 1.32 1999/05/18 23:52:52 thorpej Exp $       */
 
 /*
  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@@ -1027,9 +1027,7 @@
        }
 #endif
 
-       /* Fix up data start offset in mbuf to point past ether header. */
-       m_adj(m, sizeof(struct ether_header));
-       ether_input(ifp, eh, m);
+       (*ifp->if_input)(ifp, m);
 }
 
 /*
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/amiga/dev/if_es.c
--- a/sys/arch/amiga/dev/if_es.c        Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/amiga/dev/if_es.c        Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_es.c,v 1.22 1998/07/05 06:49:03 jonathan Exp $      */
+/*     $NetBSD: if_es.c,v 1.23 1999/05/18 23:52:52 thorpej Exp $       */
 
 /*
  * Copyright (c) 1995 Michael L. Hitch
@@ -185,7 +185,6 @@
        /* Initialize ifnet structure. */
        bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
        ifp->if_softc = sc;
-       ifp->if_output = ether_output;
        ifp->if_ioctl = esioctl;
        ifp->if_start = esstart;
        ifp->if_watchdog = eswatchdog;
@@ -732,11 +731,7 @@
                }
        }
 #endif
-       top->m_pkthdr.len -= sizeof (*eh);
-       top->m_len -= sizeof (*eh);
-       top->m_data += sizeof (*eh);
-
-       ether_input(ifp, eh, top);
+       (*ifp->if_input)(ifp, top);
 #ifdef ESDEBUG
        if (--sc->sc_smcbusy) {
                printf("%s: esintr busy on exit\n", sc->sc_dev.dv_xname);
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/amiga/dev/if_qn.c
--- a/sys/arch/amiga/dev/if_qn.c        Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/amiga/dev/if_qn.c        Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_qn.c,v 1.17 1999/03/25 23:10:53 thorpej Exp $       */
+/*     $NetBSD: if_qn.c,v 1.18 1999/05/18 23:52:52 thorpej Exp $       */
 
 /*
  * Copyright (c) 1995 Mika Kortelainen
@@ -244,7 +244,6 @@
        ifp->if_softc = sc;
        ifp->if_ioctl = qnioctl;
        ifp->if_watchdog = qnwatchdog;
-       ifp->if_output = ether_output;
        ifp->if_start = qnstart;
        /* XXX IFF_MULTICAST */
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
@@ -643,8 +642,7 @@
        }
 #endif
 
-       m_adj(head, sizeof(struct ether_header));
-       ether_input(ifp, eh, head);
+       (*ifp->if_input)(ifp, head);
        return;
 
 bad:
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/arm32/podulebus/if_ea.c
--- a/sys/arch/arm32/podulebus/if_ea.c  Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/arm32/podulebus/if_ea.c  Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ea.c,v 1.21 1999/03/25 23:11:51 thorpej Exp $ */
+/* $NetBSD: if_ea.c,v 1.22 1999/05/18 23:52:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995 Mark Brinicombe
@@ -1321,9 +1321,6 @@
 
        ifp = &sc->sc_ethercom.ec_if;
        eh = (struct ether_header *)buf;
-       len -= sizeof(struct ether_header);
-       if (len <= 0)
-               return;
 
        /* Pull packet off interface. */
        m = eaget(buf, len, ifp);
@@ -1336,8 +1333,7 @@
         * If so, hand off the raw packet to bpf.
         */
        if (ifp->if_bpf) {
-               bpf_tap(ifp->if_bpf, buf, len + sizeof(struct ether_header));
-/*             bpf_mtap(ifp->if_bpf, m);*/
+               bpf_mtap(ifp->if_bpf, m);
 
                /*
                 * Note that the interface cannot be in promiscuous mode if
@@ -1354,7 +1350,7 @@
        }
 #endif
 
-       ether_input(ifp, eh, m);
+       (*ifp->if_input)(ifp, m);
 }
 
 /*
@@ -1374,7 +1370,6 @@
         register caddr_t cp = buf;
         char *epkt;
 
-        buf += sizeof(struct ether_header);
         cp = buf;
         epkt = cp + totlen;
 
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/arm32/podulebus/if_eb.c
--- a/sys/arch/arm32/podulebus/if_eb.c  Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/arm32/podulebus/if_eb.c  Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_eb.c,v 1.21 1999/03/25 23:11:52 thorpej Exp $ */
+/* $NetBSD: if_eb.c,v 1.22 1999/05/18 23:52:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995 Mark Brinicombe
@@ -1335,9 +1335,6 @@
 
        ifp = &sc->sc_ethercom.ec_if;
        eh = (struct ether_header *)buf;
-       len -= sizeof(struct ether_header);
-       if (len <= 0)
-               return;
 
        /* Pull packet off interface. */
        m = ebget(buf, len, ifp);
@@ -1350,8 +1347,7 @@
         * If so, hand off the raw packet to bpf.
         */
        if (ifp->if_bpf) {
-               bpf_tap(ifp->if_bpf, buf, len + sizeof(struct ether_header));
-/*             bpf_mtap(ifp->if_bpf, m);*/
+               bpf_mtap(ifp->if_bpf, m);
 
                /*
                 * Note that the interface cannot be in promiscuous mode if
@@ -1368,7 +1364,7 @@
        }
 #endif
 
-       ether_input(ifp, eh, m);
+       (*ifp->if_input)(ifp, m);
 }
 
 /*
@@ -1388,7 +1384,6 @@
         register caddr_t cp = buf;
         char *epkt;
 
-        buf += sizeof(struct ether_header);
         cp = buf;
         epkt = cp + totlen;
 
diff -r 45fdffcb9793 -r 648eb9e18df8 sys/arch/arm32/podulebus/if_ie.c
--- a/sys/arch/arm32/podulebus/if_ie.c  Tue May 18 23:42:56 1999 +0000
+++ b/sys/arch/arm32/podulebus/if_ie.c  Tue May 18 23:52:51 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ie.c,v 1.22 1999/03/25 23:11:52 thorpej Exp $ */
+/* $NetBSD: if_ie.c,v 1.23 1999/05/18 23:52:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995 Melvin Tang-Richardson.
@@ -1116,12 +1116,13 @@
 }
 
 struct mbuf *
-ieget(struct ie_softc *sc, struct ether_header *ehp, int *to_bpf )
+ieget(struct ie_softc *sc, int *to_bpf )
 {
     struct mbuf *top, **mp, *m;
     int head;
     int resid, totlen, thisrboff, thismboff;
     int len;
+    struct ether_header eh;
 
     totlen = ie_packet_len(sc);
 
@@ -1137,11 +1138,11 @@
     head = sc->rbhead;
 
     /* Read the ethernet header */
-    ie2host ( sc, sc->cbuffs[head], (caddr_t)ehp, sizeof *ehp );
+    ie2host ( sc, sc->cbuffs[head], (caddr_t)&eh, sizeof eh );
 
     /* Check if the packet is for us */
 
-    resid = totlen -= (thisrboff = sizeof *ehp);
+    resid = totlen;
 
     MGETHDR ( m, M_DONTWAIT, MT_DATA );
     if ( m==0 )
@@ -1181,6 +1182,14 @@
     thismboff = 0;
 
     /*
+     * Copy the Ethernet header into the mbuf chain.
+     */
+    memcpy(mtod(m, caddr_t), &eh, sizeof(struct ether_header));
+    thismboff = sizeof(struct ether_header);
+    thisrboff = sizeof(struct ether_header);
+    resid -= sizeof(struct ether_header);
+
+    /*
      * Now we take the mbuf chain (hopefully only one mbuf most of the
      * time) and stuff the data into it.  There are no possible failures at
      * or after this point.
@@ -1271,7 +1280,6 @@



Home | Main Index | Thread Index | Old Index