From 367d34f853aa3911180a4159df4d5fa0334ac816 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Mon, 24 Jan 2000 20:39:02 +0000 Subject: [PATCH] Move the *intrq variables into net/intrq.c and unconditionally include this in all kernels. Declare some const *intrq_present variables that can be checked by a module prior to using *intrq to queue data. Make the if_tun module capable of processing atm, ip, ip6, ipx, natm and netatalk packets when TUNSIFHEAD is ioctl()d on. Review not required by: freebsd-hackers --- sys/conf/files | 1 + sys/modules/if_tun/Makefile | 20 ++++++--- sys/net/if_tun.c | 86 ++++++++++++++++++++++++++++--------- sys/net/intrq.c | 60 ++++++++++++++++++++++++++ sys/net/intrq.h | 43 +++++++++++++++++++ sys/netatalk/ddp_input.c | 7 ++- sys/netatm/atm_subr.c | 3 +- sys/netinet/ip_input.c | 3 +- sys/netinet6/ip6_input.c | 4 +- sys/netipx/ipx_input.c | 3 +- sys/netnatm/natm_proto.c | 5 ++- sys/netns/ns_input.c | 4 +- 12 files changed, 203 insertions(+), 36 deletions(-) create mode 100644 sys/net/intrq.c create mode 100644 sys/net/intrq.h diff --git a/sys/conf/files b/sys/conf/files index 6dd29653978..79963268699 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -552,6 +552,7 @@ net/if_vlan.c optional vlan net/net_osdep.c standard net/ppp_deflate.c optional ppp_deflate net/ppp_tty.c optional ppp +net/intrq.c standard net/radix.c standard net/raw_cb.c standard net/raw_usrreq.c standard diff --git a/sys/modules/if_tun/Makefile b/sys/modules/if_tun/Makefile index afd05c22a79..8d97cce832a 100644 --- a/sys/modules/if_tun/Makefile +++ b/sys/modules/if_tun/Makefile @@ -2,8 +2,8 @@ .PATH: ${.CURDIR}/../../net KMOD= if_tun -SRCS= if_tun.c opt_devfs.h opt_inet.h opt_inet6.h opt_atalk.h opt_ipx.h \ - vnode_if.h +SRCS= if_tun.c opt_devfs.h opt_atalk.h opt_atm.h opt_inet.h opt_inet6.h \ + opt_ipx.h opt_natm.h vnode_if.h NOMAN= NBPF?= 1 @@ -11,16 +11,22 @@ NTUN?= 2 CFLAGS+= ${PROTOS} +opt_atalk.h: + echo "#define NETATALK 1" > opt_atalk.h + +opt_atm.h: + echo "#define ATM_CORE 1" > opt_atm.h + opt_inet.h: echo "#define INET 1" > opt_inet.h opt_inet6.h: - echo "#undef INET6" > opt_inet6.h - -opt_atalk.h: - echo "#undef NETATALK" > opt_atalk.h + echo "#define INET6 1" > opt_inet6.h opt_ipx.h: - echo "#undef IPX" > opt_ipx.h + echo "#define IPX 1" > opt_ipx.h + +opt_natm.h: + echo "#define NATM 1" > opt_natm.h .include diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 06befe43af0..9db0048b73a 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -17,9 +17,11 @@ */ #include "opt_atalk.h" +#include "opt_atm.h" #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipx.h" +#include "opt_natm.h" #include #include @@ -42,6 +44,13 @@ #include #include #include +#include + +#ifdef ATM_CORE +#include +#include +#include +#endif #ifdef INET #include @@ -53,22 +62,26 @@ #include #endif -#ifdef NS -/* This will never be defined by config(8), or for the if_tun module ! */ -#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 @@ -700,38 +713,69 @@ 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: - q = &ipintrq; - isr = NETISR_IP; + if (ipintrq_present) { + q = &ipintrq; + isr = NETISR_IP; + } break; #endif #ifdef INET6 case AF_INET6: - q = &ip6intrq; - isr = NETISR_IPV6; - break; -#endif -#ifdef NS - case AF_NS: - q = &nsintrq; - isr = NETISR_NS; + if (ip6intrq_present) { + q = &ip6intrq; + isr = NETISR_IPV6; + } break; #endif #ifdef IPX case AF_IPX: - q = &ipxintrq; - isr = NETISR_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: - q = &atintrq2; - isr = NETISR_ATALK; + if (atintrq2_present) { + q = &atintrq2; + isr = NETISR_ATALK; + } break; #endif - default: +#ifdef NS + case AF_NS: + if (nsintrq_present) { + q = &nsintrq; + isr = NETISR_NS; + } + break; +#endif + } + + if (!q) { m_freem(top); return EAFNOSUPPORT; } diff --git a/sys/net/intrq.c b/sys/net/intrq.c new file mode 100644 index 00000000000..df6e45c020d --- /dev/null +++ b/sys/net/intrq.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2000 Brian Somers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include + +#include +#include +#include + +/* + * 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; +const int atmintrq_present; +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 ipintrq; +struct ifqueue ip6intrq; +struct ifqueue ipxintrq; +struct ifqueue natmintrq; +struct ifqueue nsintrq; diff --git a/sys/net/intrq.h b/sys/net/intrq.h new file mode 100644 index 00000000000..a97cf2957e2 --- /dev/null +++ b/sys/net/intrq.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2000 Brian Somers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _INTRQ_H_ +#define _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; +#endif + +#endif /* _INTRQ_H_ */ diff --git a/sys/netatalk/ddp_input.c b/sys/netatalk/ddp_input.c index 6f7e9f3d068..ad15d8130d5 100644 --- a/sys/netatalk/ddp_input.c +++ b/sys/netatalk/ddp_input.c @@ -1,6 +1,8 @@ /* * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. + * + * $FreeBSD$ */ #include @@ -12,6 +14,7 @@ #include #include #include +#include #include #include @@ -19,13 +22,13 @@ #include #include -struct ifqueue atintrq1, atintrq2; - static volatile int ddp_forward = 1; static volatile int ddp_firewall = 0; static struct ddpstat ddpstat; static struct route forwro; +const int atintrq1_present = 1, atintrq2_present = 1; + static void ddp_input(struct mbuf *, struct ifnet *, struct elaphdr *, int); /* diff --git a/sys/netatm/atm_subr.c b/sys/netatm/atm_subr.c index 507f4f1e0ba..a328a78eb11 100644 --- a/sys/netatm/atm_subr.c +++ b/sys/netatm/atm_subr.c @@ -36,6 +36,7 @@ */ #include +#include #ifndef lint __RCSID("@(#) $FreeBSD$"); @@ -50,7 +51,6 @@ struct atm_ncm *atm_netconv_head = NULL; Atm_endpoint *atm_endpoints[ENDPT_MAX+1] = {NULL}; struct sp_info *atm_pool_head = NULL; struct stackq_entry *atm_stackq_head = NULL, *atm_stackq_tail; -struct ifqueue atm_intrq; #ifdef sgi int atm_intr_index; #endif @@ -61,6 +61,7 @@ int atm_dev_print = 0; int atm_print_data = 0; int atm_version = ATM_VERSION; struct timeval atm_debugtime = {0, 0}; +const int atmintrq_present = 1; struct sp_info atm_attributes_pool = { "atm attributes pool", /* si_name */ diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index be6d25d6782..df9176fc13a 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -137,7 +138,6 @@ extern struct ipprotosw inetsw[]; u_char ip_protox[IPPROTO_MAX]; static int ipqmaxlen = IFQ_MAXLEN; struct in_ifaddrhead in_ifaddrhead; /* first inet address */ -struct ifqueue ipintrq; SYSCTL_INT(_net_inet_ip, IPCTL_INTRQMAXLEN, intr_queue_maxlen, CTLFLAG_RW, &ipintrq.ifq_maxlen, 0, "Maximum size of the IP input queue"); SYSCTL_INT(_net_inet_ip, IPCTL_INTRQDROPS, intr_queue_drops, CTLFLAG_RD, @@ -157,6 +157,7 @@ SYSCTL_STRUCT(_net_inet_ip, IPCTL_STATS, stats, CTLFLAG_RD, static struct ipq ipq[IPREASS_NHASH]; static int nipq = 0; /* total # of reass queues */ static int maxnipq; +const int ipintrq_present = 1; #ifdef IPCTL_DEFMTU SYSCTL_INT(_net_inet_ip, IPCTL_DEFMTU, mtu, CTLFLAG_RW, diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index ce74b63b05b..8953a5db338 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -85,6 +85,7 @@ #include #include #include +#include #include #include @@ -123,12 +124,13 @@ extern struct ip6protosw inet6sw[]; u_char ip6_protox[IPPROTO_MAX]; static int ip6qmaxlen = IFQ_MAXLEN; struct in6_ifaddr *in6_ifaddr; -struct ifqueue ip6intrq; int ip6_forward_srcrt; /* XXX */ int ip6_sourcecheck; /* XXX */ int ip6_sourcecheck_interval; /* XXX */ +const int int6intrq_present = 1; + #ifdef IPV6FIREWALL /* firewall hooks */ ip6_fw_chk_t *ip6_fw_chk_ptr; diff --git a/sys/netipx/ipx_input.c b/sys/netipx/ipx_input.c index 0b51a9bccb3..7494912b16f 100644 --- a/sys/netipx/ipx_input.c +++ b/sys/netipx/ipx_input.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -86,10 +87,10 @@ static u_short allones[] = {-1, -1, -1}; struct ipxpcb ipxpcb; struct ipxpcb ipxrawpcb; -struct ifqueue ipxintrq; static int ipxqmaxlen = IFQ_MAXLEN; long ipx_pexseq; +const int ipxintrq_present = 1; NETISR_SET(NETISR_IPX, ipxintr); diff --git a/sys/netnatm/natm_proto.c b/sys/netnatm/natm_proto.c index 58ecaf17d12..2a37a377043 100644 --- a/sys/netnatm/natm_proto.c +++ b/sys/netnatm/natm_proto.c @@ -30,6 +30,8 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ */ /* @@ -44,6 +46,7 @@ #include #include +#include #include @@ -103,7 +106,6 @@ static struct domain natmdomain = natmsw, &natmsw[sizeof(natmsw)/sizeof(natmsw[0])], 0, 0, 0, 0}; -struct ifqueue natmintrq; /* natm packet input queue */ static int natmqmaxlen = IFQ_MAXLEN; /* max # of packets on queue */ #ifdef NATM_STAT u_int natm_sodropcnt = 0; /* # mbufs dropped due to full sb */ @@ -112,6 +114,7 @@ u_int natm_sookcnt = 0; /* # mbufs ok */ u_int natm_sookbytes = 0; /* # of bytes ok */ #endif +const int natmintrq_present = 1; void natm_init() diff --git a/sys/netns/ns_input.c b/sys/netns/ns_input.c index 21d64a09a8a..18b1025eab6 100644 --- a/sys/netns/ns_input.c +++ b/sys/netns/ns_input.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -73,12 +74,13 @@ static u_short allones[] = {-1, -1, -1}; struct nspcb nspcb; struct nspcb nsrawpcb; -struct ifqueue nsintrq; int nsqmaxlen = IFQ_MAXLEN; int idpcksum = 1; long ns_pexseq; +const int nsintrq_present = 1; + ns_init() { extern struct timeval time;