From 6af3fd8d22dcc4a45a3a04799eaa75514d2cafbc Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Thu, 27 Jan 2000 23:37:39 +0000 Subject: [PATCH] Redo the intrq.c idea as int family_enqueue(sa_family_t, struct mbuf *); --- sys/net/if_tun.c | 117 +---------------------------------------------- sys/net/intrq.c | 67 +++++++++++++++++++++++++-- sys/net/intrq.h | 15 ++---- 3 files changed, 68 insertions(+), 131 deletions(-) diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 9db0048b73a1..6a59859028ca 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -46,42 +46,11 @@ #include #include -#ifdef ATM_CORE -#include -#include -#include -#endif - #ifdef INET #include #include #endif -#ifdef INET6 -#include -#include -#endif - -#ifdef IPX -#include -#include -#endif - -#ifdef NATM -#include -#endif - -#ifdef NETATALK -#include -#include -#endif - -#ifdef NS -/* This will never be defined by config(8), or for the if_tun module ! */ -#include -#include -#endif - #include #include @@ -631,9 +600,8 @@ tunwrite(dev, uio, flag) struct tun_softc *tp = dev->si_drv1; struct ifnet *ifp = &tp->tun_if; struct mbuf *top, **mp, *m; - int error=0, s, tlen, mlen, isr; + int error=0, tlen, mlen; u_int32_t family; - struct ifqueue *q; TUNDEBUG("%s%d: tunwrite\n", ifp->if_name, ifp->if_unit); @@ -713,88 +681,7 @@ tunwrite(dev, uio, flag) } else family = AF_INET; - q = NULL; - isr = 0; - - switch (family) { -#ifdef ATM_CORE - case AF_ATM: - if (atmintrq_present) { - q = &atm_intrq; - isr = NETISR_ATM; - } - break; -#endif -#ifdef INET - case AF_INET: - if (ipintrq_present) { - q = &ipintrq; - isr = NETISR_IP; - } - break; -#endif -#ifdef INET6 - case AF_INET6: - if (ip6intrq_present) { - q = &ip6intrq; - isr = NETISR_IPV6; - } - break; -#endif -#ifdef IPX - case AF_IPX: - if (ipxintrq_present) { - q = &ipxintrq; - isr = NETISR_IPX; - } - break; -#endif -#ifdef NATM - case AF_NATM: - if (natmintrq_present) { - q = &natmintrq; - isr = NETISR_NATM; - } - break; -#endif -#ifdef NETATALK - case AF_APPLETALK: - if (atintrq2_present) { - q = &atintrq2; - isr = NETISR_ATALK; - } - break; -#endif -#ifdef NS - case AF_NS: - if (nsintrq_present) { - q = &nsintrq; - isr = NETISR_NS; - } - break; -#endif - } - - if (!q) { - m_freem(top); - return EAFNOSUPPORT; - } - - s = splimp(); - if (IF_QFULL (q)) { - IF_DROP(q); - splx(s); - ifp->if_collisions++; - m_freem(top); - return ENOBUFS; - } - IF_ENQUEUE(q, top); - splx(s); - ifp->if_ibytes += tlen; - ifp->if_ipackets++; - schednetisr(isr); - - return error; + return family_enqueue(family, top); } /* diff --git a/sys/net/intrq.c b/sys/net/intrq.c index df6e45c020de..b2d625965cbf 100644 --- a/sys/net/intrq.c +++ b/sys/net/intrq.c @@ -26,35 +26,92 @@ * $FreeBSD$ */ -#include +#include +#include #include +#include #include #include #include +#include #include +#ifdef __i386__ +#include +#endif + /* * If the appropriate intrq_present variable is zero, don't use * the queue (as it'll never get processed). * When defined, each of the network stacks declares their own * *intrq_present variable to be non-zero. */ - const int atintrq1_present; const int atintrq2_present; +#ifdef NETISR_ATM const int atmintrq_present; +#endif const int ipintrq_present; const int ip6intrq_present; const int ipxintrq_present; const int natmintrq_present; const int nsintrq_present; -struct ifqueue atintrq1; -struct ifqueue atintrq2; -struct ifqueue atm_intrq; +struct ifqueue at1intrq; +struct ifqueue at2intrq; +#ifdef NETISR_ATM +struct ifqueue atmintrq; +#endif struct ifqueue ipintrq; struct ifqueue ip6intrq; struct ifqueue ipxintrq; struct ifqueue natmintrq; struct ifqueue nsintrq; + + +static const struct { + sa_family_t family; + struct ifqueue *q; + int const *present; + int isr; +} queue[] = { +#ifdef NETISR_ATM + { AF_ATM, &atm_intrq, &atmintrq_present, NETISR_ATM }, +#endif + { AF_INET, &ipintrq, &ipintrq_present, NETISR_IP }, + { AF_INET6, &ip6intrq, &ip6intrq_present, NETISR_IPV6 }, + { AF_IPX, &ipxintrq, &ipxintrq_present, NETISR_IPX }, + { AF_NATM, &natmintrq, &natmintrq_present, NETISR_NATM }, + { AF_APPLETALK, &at2intrq, &atintrq2_present, NETISR_ATALK }, + { AF_NS, &nsintrq, &nsintrq_present, NETISR_NS } +}; + +int +family_enqueue(family, m) + sa_family_t family; + struct mbuf *m; +{ + int entry, s; + + for (entry = 0; entry < sizeof queue / sizeof queue[0]; entry++) + if (queue[entry].family == family) { + if (queue[entry].present) { + s = splimp(); + if (IF_QFULL(queue[entry].q)) { + IF_DROP(queue[entry].q); + splx(s); + m_freem(m); + return ENOBUFS; + } + IF_ENQUEUE(queue[entry].q, m); + splx(s); + schednetisr(queue[entry].isr); + return 0; + } else + break; + } + + m_freem(m); + return EAFNOSUPPORT; +} diff --git a/sys/net/intrq.h b/sys/net/intrq.h index a97cf2957e29..c17cafd4ddc1 100644 --- a/sys/net/intrq.h +++ b/sys/net/intrq.h @@ -26,18 +26,11 @@ * $FreeBSD$ */ -#ifndef _INTRQ_H_ -#define _INTRQ_H_ +#ifndef _NET_INTRQ_H_ +#define _NET_INTRQ_H_ #ifdef _KERNEL -extern const int atintrq1_present; -extern const int atintrq2_present; -extern const int atmintrq_present; -extern const int ipintrq_present; -extern const int ip6intrq_present; -extern const int ipxintrq_present; -extern const int natmintrq_present; -extern const int nsintrq_present; +extern int family_enqueue __P((sa_family_t, struct mbuf *)); #endif -#endif /* _INTRQ_H_ */ +#endif /* _NET_INTRQ_H_ */