Source-Changes-HG archive

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

[src/trunk]: src/sys/net factor out the interface queueing code into two func...



details:   https://anonhg.NetBSD.org/src/rev/3c6a63ecbf6c
branches:  trunk
changeset: 579914:3c6a63ecbf6c
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Mar 31 15:48:13 2005 +0000

description:
factor out the interface queueing code into two functions. One used by
the non point-to-point interfaces that has one queue, and one used by
the point to point interfaces that has two queues. No functional changes.
XXX: The ALTQ stuff makes the code ugly.
XXX: More cleanup to come

diffstat:

 sys/net/if.c           |  64 ++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/net/if.h           |   9 ++++++-
 sys/net/if_arcsubr.c   |  42 ++++----------------------------
 sys/net/if_atmsubr.c   |  24 +++---------------
 sys/net/if_ecosubr.c   |  40 ++++--------------------------
 sys/net/if_ethersubr.c |  28 +++------------------
 sys/net/if_fddisubr.c  |  29 +++------------------
 sys/net/if_hippisubr.c |  24 +++---------------
 sys/net/if_ppp.c       |  45 +++++++----------------------------
 sys/net/if_sl.c        |  28 ++++++---------------
 sys/net/if_spppsubr.c  |  58 ++++++++++++++-------------------------------
 sys/net/if_strip.c     |  21 +++------------
 sys/net/if_tokensubr.c |  29 +++-------------------
 13 files changed, 143 insertions(+), 298 deletions(-)

diffs (truncated from 860 to 300 lines):

diff -r 06cdae933c8f -r 3c6a63ecbf6c sys/net/if.c
--- a/sys/net/if.c      Thu Mar 31 15:45:53 2005 +0000
+++ b/sys/net/if.c      Thu Mar 31 15:48:13 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.154 2005/02/26 22:45:09 perry Exp $   */
+/*     $NetBSD: if.c,v 1.155 2005/03/31 15:48:13 christos Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.154 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.155 2005/03/31 15:48:13 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -1728,6 +1728,66 @@
        return (error);
 }
 
+/*
+ * Queue message on interface, and start output if interface
+ * not yet active.
+ */
+int
+ifq_enqueue(struct ifnet *ifp, struct mbuf *m
+    ALTQ_COMMA ALTQ_DECL(struct altq_pktattr *pktattr))
+{
+       int len = m->m_pkthdr.len;
+       int mflags = m->m_flags;
+       int s = splnet();
+       int error;
+
+       IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
+       if (error) {
+               splx(s);
+               return error;
+       }
+       ifp->if_obytes += len;
+       if (mflags & M_MCAST)
+               ifp->if_omcasts++;
+       if ((ifp->if_flags & IFF_OACTIVE) == 0)
+               (*ifp->if_start)(ifp);
+       splx(s);
+       return error;
+}
+
+/*
+ * Queue message on interface, possibly using a second fast queue
+ */
+int
+ifq_enqueue2(struct ifnet *ifp, struct ifqueue *ifq, struct mbuf *m
+    ALTQ_COMMA ALTQ_DECL(struct altq_pktattr *pktattr))
+{
+       int error = 0;
+
+       if (ifq != NULL
+#ifdef ALTQ
+           && ALTQ_IS_ENABLED(&ifp->if_snd) == 0
+#endif
+           ) {
+               if (IF_QFULL(ifq)) {
+                       IF_DROP(&ifp->if_snd);
+                       m_freem(m);
+                       if (error == 0)
+                               error = ENOBUFS;
+               }
+               else
+                       IF_ENQUEUE(ifq, m);
+       } else
+               IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
+       if (error != 0) {
+               ++ifp->if_oerrors;
+               return error;
+       }
+
+       return 0;
+}
+
+
 #if defined(INET) || defined(INET6)
 static void
 sysctl_net_ifq_setup(struct sysctllog **clog,
diff -r 06cdae933c8f -r 3c6a63ecbf6c sys/net/if.h
--- a/sys/net/if.h      Thu Mar 31 15:45:53 2005 +0000
+++ b/sys/net/if.h      Thu Mar 31 15:48:13 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.106 2005/03/20 07:47:29 agc Exp $     */
+/*     $NetBSD: if.h,v 1.107 2005/03/31 15:48:13 christos Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -645,6 +645,7 @@
 
 #ifdef ALTQ
 #define        ALTQ_DECL(x)            x
+#define ALTQ_COMMA             ,
 
 #define IFQ_ENQUEUE(ifq, m, pattr, err)                                        \
 do {                                                                   \
@@ -708,6 +709,7 @@
 } while (/*CONSTCOND*/ 0)
 #else /* ! ALTQ */
 #define        ALTQ_DECL(x)            /* nothing */
+#define ALTQ_COMMA
 
 #define        IFQ_ENQUEUE(ifq, m, pattr, err)                                 \
 do {                                                                   \
@@ -788,6 +790,11 @@
 int    if_clone_create __P((const char *));
 int    if_clone_destroy __P((const char *));
 
+int    ifq_enqueue(struct ifnet *, struct mbuf * ALTQ_COMMA
+    ALTQ_DECL(struct altq_pktattr *));
+int    ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf * ALTQ_COMMA
+    ALTQ_DECL(struct altq_pktattr *));
+
 int    loioctl __P((struct ifnet *, u_long, caddr_t));
 void   loopattach __P((int));
 int    looutput __P((struct ifnet *,
diff -r 06cdae933c8f -r 3c6a63ecbf6c sys/net/if_arcsubr.c
--- a/sys/net/if_arcsubr.c      Thu Mar 31 15:45:53 2005 +0000
+++ b/sys/net/if_arcsubr.c      Thu Mar 31 15:48:13 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arcsubr.c,v 1.46 2005/02/26 22:45:09 perry Exp $    */
+/*     $NetBSD: if_arcsubr.c,v 1.47 2005/03/31 15:48:13 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Ignatios Souvatzis
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.46 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.47 2005/03/31 15:48:13 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -125,7 +125,7 @@
        struct arccom           *ac;
        struct arc_header       *ah;
        struct arphdr           *arph;
-       int                     s, error, newencoding, len;
+       int                     error, newencoding;
        u_int8_t                atype, adst, myself;
        int                     tfrags, sflag, fsflag, rsflag;
        ALTQ_DECL(struct altq_pktattr pktattr;)
@@ -298,22 +298,9 @@
                        ah->arc_flag = rsflag;
                        ah->arc_seqid = ac->ac_seqid;
 
-                       len = m->m_pkthdr.len;
-                       s = splnet();
-                       /*
-                        * Queue message on interface, and start output if
-                        * interface not yet active.
-                        */
-                       IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
-                       if (error) {
-                               /* mbuf is already freed */
-                               splx(s);
+                       if ((error = ifq_enqueue(ifp, m ALTQ_COMMA
+                           ALTQ_DECL(&pktattr))) != 0)
                                return (error);
-                       }
-                       ifp->if_obytes += len;
-                       if ((ifp->if_flags & IFF_OACTIVE) == 0)
-                               (*ifp->if_start)(ifp);
-                       splx(s);
 
                        m = m1;
                        sflag += 2;
@@ -360,24 +347,7 @@
                ah->arc_shost = myself;
        }
 
-       len = m->m_pkthdr.len;
-       s = splnet();
-       /*
-        * Queue message on interface, and start output if interface
-        * not yet active.
-        */
-       IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
-       if (error) {
-               /* mbuf is already freed */
-               splx(s);
-               return (error);
-       }
-       ifp->if_obytes += len;
-       if ((ifp->if_flags & IFF_OACTIVE) == 0)
-               (*ifp->if_start)(ifp);
-       splx(s);
-
-       return (error);
+       return ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(&pktattr));
 
 bad:
        if (m1)
diff -r 06cdae933c8f -r 3c6a63ecbf6c sys/net/if_atmsubr.c
--- a/sys/net/if_atmsubr.c      Thu Mar 31 15:45:53 2005 +0000
+++ b/sys/net/if_atmsubr.c      Thu Mar 31 15:48:13 2005 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_atmsubr.c,v 1.34 2005/02/26 22:45:09 perry Exp $       */
+/*      $NetBSD: if_atmsubr.c,v 1.35 2005/03/31 15:48:13 christos Exp $       */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_atmsubr.c,v 1.34 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_atmsubr.c,v 1.35 2005/03/31 15:48:13 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_gateway.h"
@@ -105,7 +105,7 @@
        struct rtentry *rt0;
 {
        u_int16_t etype = 0;                    /* if using LLC/SNAP */
-       int s, error = 0, sz, len;
+       int error = 0, sz;
        struct atm_pseudohdr atmdst, *ad;
        struct mbuf *m = m0;
        struct rtentry *rt;
@@ -223,23 +223,7 @@
                }
        }
 
-       /*
-        * Queue message on interface, and start output if interface
-        * not yet active.
-        */
-
-       len = m->m_pkthdr.len;
-       s = splnet();
-       IFQ_ENQUEUE(&ifp->if_snd, m, &pktattr, error);
-       if (error) {
-               splx(s);
-               return (error);
-       }
-       ifp->if_obytes += len;
-       if ((ifp->if_flags & IFF_OACTIVE) == 0)
-               (*ifp->if_start)(ifp);
-       splx(s);
-       return (error);
+       return ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(&pktattr));
 
 bad:
        if (m)
diff -r 06cdae933c8f -r 3c6a63ecbf6c sys/net/if_ecosubr.c
--- a/sys/net/if_ecosubr.c      Thu Mar 31 15:45:53 2005 +0000
+++ b/sys/net/if_ecosubr.c      Thu Mar 31 15:48:13 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ecosubr.c,v 1.15 2005/02/26 22:45:09 perry Exp $    */
+/*     $NetBSD: if_ecosubr.c,v 1.16 2005/03/31 15:48:13 christos Exp $ */
 
 /*-
  * Copyright (c) 2001 Ben Harris
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.15 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.16 2005/03/31 15:48:13 christos Exp $");
 
 #include "bpfilter.h"
 #include "opt_inet.h"
@@ -66,7 +66,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.15 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.16 2005/03/31 15:48:13 christos Exp $");
 
 #include <sys/errno.h>
 #include <sys/kernel.h>
@@ -175,11 +175,10 @@
     struct rtentry *rt0)
 {
        struct eco_header ehdr, *eh;
-       int error, s;
+       int error;
        struct mbuf *m = m0, *mcopy = NULL;
        struct rtentry *rt;
        int hdrcmplt;
-       size_t len;
        int delay, count;
        struct m_tag *mtag;
        struct eco_retryparms *erp;
@@ -334,23 +333,7 @@
                return (0);
 #endif
 
-       /*
-        * Queue message on interface, and start output if interface
-        * not yet active.
-        */



Home | Main Index | Thread Index | Old Index