summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_tun.c117
-rw-r--r--sys/net/intrq.c67
-rw-r--r--sys/net/intrq.h15
3 files changed, 68 insertions, 131 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index 9db0048..6a59859 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -46,42 +46,11 @@
#include <net/route.h>
#include <net/intrq.h>
-#ifdef ATM_CORE
-#include <netatm/kern_include.h>
-#include <netatm/atm.h>
-#include <netatm/atm_var.h>
-#endif
-
#ifdef INET
#include <netinet/in.h>
#include <netinet/in_var.h>
#endif
-#ifdef INET6
-#include <netinet6/in6.h>
-#include <netinet6/in6_var.h>
-#endif
-
-#ifdef IPX
-#include <netipx/ipx.h>
-#include <netipx/ipx_if.h>
-#endif
-
-#ifdef NATM
-#include <netnatm/natm.h>
-#endif
-
-#ifdef NETATALK
-#include <netatalk/at.h>
-#include <netatalk/at_var.h>
-#endif
-
-#ifdef NS
-/* This will never be defined by config(8), or for the if_tun module ! */
-#include <netns/ns.h>
-#include <netns/ns_if.h>
-#endif
-
#include <net/bpf.h>
#include <net/if_tunvar.h>
@@ -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 df6e45c..b2d6259 100644
--- a/sys/net/intrq.c
+++ b/sys/net/intrq.c
@@ -26,35 +26,92 @@
* $FreeBSD$
*/
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mbuf.h>
#include <sys/socket.h>
+#include <sys/systm.h>
#include <sys/time.h>
#include <net/if.h>
#include <net/if_var.h>
+#include <net/netisr.h>
#include <net/intrq.h>
+#ifdef __i386__
+#include <netatm/atm_if.h>
+#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 a97cf29..c17cafd 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_ */
OpenPOWER on IntegriCloud