tech-net archive

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

patch make struct protosw pr_input non-variadic



Hi,

The attached patch for review (originally produced by riastradh@)
that provides the structural changes needed to make
protosw::pr_input protocol-specific and ditch its variadic
prototype pr_input(struct mbuf *, ...).

Similar work has already been done & discussed.

https://mail-index.netbsd.org/tech-net/2016/01/16/msg005484.html

Once the structural changes are in I'll generate a second patch
adapting the variadic implementations of pr_input to functions with
apropriate prototypes.

This patch:
* moves pr_input out of struct protosw and places it into <proto>sw
  specitic structure.
* converts domain::dom_protosw to an array of pointers

comments? objections? cleanups?

Thanks
? .cvsignore
Index: sys/kern/uipc_domain.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_domain.c,v
retrieving revision 1.96
diff -u -p -r1.96 uipc_domain.c
--- sys/kern/uipc_domain.c	2 Dec 2014 19:45:58 -0000	1.96
+++ sys/kern/uipc_domain.c	13 May 2016 12:27:51 -0000
@@ -121,6 +121,7 @@ void
 domain_attach(struct domain *dp)
 {
 	const struct protosw *pr;
+	size_t i;
 
 	STAILQ_INSERT_TAIL(&domains, dp, dom_link);
 	if (dp->dom_family < __arraycount(domain_array))
@@ -136,7 +137,8 @@ domain_attach(struct domain *dp)
 		MOWNER_ATTACH(&dp->dom_mowner);
 	}
 #endif
-	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+	for (i = 0; i < dp->dom_nprotosw; i++) {
+		pr = dp->dom_protosw[i];
 		if (pr->pr_init)
 			(*pr->pr_init)();
 	}
@@ -166,14 +168,17 @@ pffindtype(int family, int type)
 {
 	struct domain *dp;
 	const struct protosw *pr;
+	size_t i;
 
 	dp = pffinddomain(family);
 	if (dp == NULL)
 		return NULL;
 
-	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+	for (i = 0; i < dp->dom_nprotosw; i++) {
+		pr = dp->dom_protosw[i];
 		if (pr->pr_type && pr->pr_type == type)
 			return pr;
+	}
 
 	return NULL;
 }
@@ -184,6 +189,7 @@ pffindproto(int family, int protocol, in
 	struct domain *dp;
 	const struct protosw *pr;
 	const struct protosw *maybe = NULL;
+	size_t i;
 
 	if (family == 0)
 		return NULL;
@@ -192,7 +198,8 @@ pffindproto(int family, int protocol, in
 	if (dp == NULL)
 		return NULL;
 
-	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+	for (i = 0; i < dp->dom_nprotosw; i++) {
+		pr = dp->dom_protosw[i];
 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
 			return pr;
 
@@ -657,9 +664,11 @@ pfctlinput(int cmd, const struct sockadd
 {
 	struct domain *dp;
 	const struct protosw *pr;
+	size_t i;
 
 	DOMAIN_FOREACH(dp) {
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			if (pr->pr_ctlinput != NULL)
 				(*pr->pr_ctlinput)(cmd, sa, NULL);
 		}
@@ -671,6 +680,7 @@ pfctlinput2(int cmd, const struct sockad
 {
 	struct domain *dp;
 	const struct protosw *pr;
+	size_t i;
 
 	if (sa == NULL)
 		return;
@@ -684,7 +694,8 @@ pfctlinput2(int cmd, const struct sockad
 		if (dp->dom_family != sa->sa_family)
 			continue;
 
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			if (pr->pr_ctlinput != NULL)
 				(*pr->pr_ctlinput)(cmd, sa, ctlparam);
 		}
@@ -696,13 +707,16 @@ pfslowtimo(void *arg)
 {
 	struct domain *dp;
 	const struct protosw *pr;
+	size_t i;
 
 	pfslowtimo_now++;
 
 	DOMAIN_FOREACH(dp) {
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			if (pr->pr_slowtimo)
 				(*pr->pr_slowtimo)();
+		}
 	}
 	callout_schedule(&pfslowtimo_ch, hz / PR_SLOWHZ);
 }
@@ -712,13 +726,16 @@ pffasttimo(void *arg)
 {
 	struct domain *dp;
 	const struct protosw *pr;
+	size_t i;
 
 	pffasttimo_now++;
 
 	DOMAIN_FOREACH(dp) {
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			if (pr->pr_fasttimo)
 				(*pr->pr_fasttimo)();
+		}
 	}
 	callout_schedule(&pffasttimo_ch, hz / PR_FASTHZ);
 }
Index: sys/kern/uipc_mbuf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.165
diff -u -p -r1.165 uipc_mbuf.c
--- sys/kern/uipc_mbuf.c	12 May 2016 02:24:16 -0000	1.165
+++ sys/kern/uipc_mbuf.c	13 May 2016 12:27:51 -0000
@@ -546,15 +546,17 @@ m_reclaim(void *arg, int flags)
 	struct domain *dp;
 	const struct protosw *pr;
 	struct ifnet *ifp;
+	size_t i;
 	int s;
 
 	KERNEL_LOCK(1, NULL);
 	s = splvm();
 	DOMAIN_FOREACH(dp) {
-		for (pr = dp->dom_protosw;
-		     pr < dp->dom_protoswNPROTOSW; pr++)
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			if (pr->pr_drain)
 				(*pr->pr_drain)();
+		}
 	}
 	/* XXX we cannot use psref in H/W interrupt */
 	if (!cpu_intr_p()) {
Index: sys/kern/uipc_proto.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_proto.c,v
retrieving revision 1.23
diff -u -p -r1.23 uipc_proto.c
--- sys/kern/uipc_proto.c	18 May 2014 14:46:15 -0000	1.23
+++ sys/kern/uipc_proto.c	13 May 2016 12:27:51 -0000
@@ -51,22 +51,22 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_proto.c
 
 DOMAIN_DEFINE(unixdomain);	/* forward define and add to link set */
 
-const struct protosw unixsw[] = {
-	{
+const struct protosw *unixsw[] = {
+	&(const struct protosw) {
 		.pr_type = SOCK_STREAM,
 		.pr_domain = &unixdomain,
 		.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN,
 		.pr_ctloutput = uipc_ctloutput,
 		.pr_usrreqs = &unp_usrreqs,
 	},
-	{
+	&(const struct protosw) {
 		.pr_type = SOCK_DGRAM,
 		.pr_domain = &unixdomain,
 		.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
 		.pr_ctloutput = uipc_ctloutput,
 		.pr_usrreqs = &unp_usrreqs,
 	},
-	{
+	&(const struct protosw) {
 		.pr_type = SOCK_SEQPACKET,
 		.pr_domain = &unixdomain,
 		.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN|
@@ -83,5 +83,5 @@ struct domain unixdomain = {
 	.dom_externalize = unp_externalize,
 	.dom_dispose = unp_dispose,
 	.dom_protosw = unixsw,
-	.dom_protoswNPROTOSW = &unixsw[__arraycount(unixsw)],
+	.dom_nprotosw = __arraycount(unixsw),
 };
Index: sys/net/if.c
===================================================================
RCS file: /cvsroot/src/sys/net/if.c,v
retrieving revision 1.334
diff -u -p -r1.334 if.c
--- sys/net/if.c	12 May 2016 02:24:16 -0000	1.334
+++ sys/net/if.c	13 May 2016 12:27:51 -0000
@@ -1035,7 +1035,8 @@ if_detach(struct ifnet *ifp)
 #endif
 	struct domain *dp;
 	const struct protosw *pr;
-	int s, i, family, purged;
+	size_t i;
+	int s, family, purged;
 	uint64_t xc;
 
 	/*
@@ -1126,8 +1127,8 @@ again:
 		 * ifp->if_addrlist.
 		 */
 		purged = 0;
-		for (pr = dp->dom_protosw;
-		     pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			so.so_proto = pr;
 			if (pr->pr_usrreqs) {
 				(void) (*pr->pr_usrreqs->pr_purgeif)(&so, ifp);
@@ -1177,7 +1178,8 @@ again:
 		 * addresses.  (Protocols which might store ifnet
 		 * pointers are marked with PR_PURGEIF.)
 		 */
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (i = 0; i < dp->dom_nprotosw; i++) {
+			pr = dp->dom_protosw[i];
 			so.so_proto = pr;
 			if (pr->pr_usrreqs && pr->pr_flags & PR_PURGEIF)
 				(void)(*pr->pr_usrreqs->pr_purgeif)(&so, ifp);
Index: sys/net/link_proto.c
===================================================================
RCS file: /cvsroot/src/sys/net/link_proto.c,v
retrieving revision 1.30
diff -u -p -r1.30 link_proto.c
--- sys/net/link_proto.c	21 Jan 2016 15:41:29 -0000	1.30
+++ sys/net/link_proto.c	13 May 2016 12:27:51 -0000
@@ -98,12 +98,12 @@ static const struct pr_usrreqs link_usrr
 	.pr_purgeif	= link_purgeif,
 };
 
-const struct protosw linksw[] = {
-	{	.pr_type = SOCK_DGRAM,
+const struct protosw *linksw[] = {
+	&(const struct protosw) {
+		.pr_type = SOCK_DGRAM,
 		.pr_domain = &linkdomain,
 		.pr_protocol = 0,	/* XXX */
 		.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
-		.pr_input = NULL,
 		.pr_ctlinput = NULL,
 		.pr_ctloutput = NULL,
 		.pr_usrreqs = &link_usrreqs,
@@ -117,7 +117,7 @@ struct domain linkdomain = {
 	.dom_externalize = NULL,
 	.dom_dispose = NULL,
 	.dom_protosw = linksw,
-	.dom_protoswNPROTOSW = &linksw[__arraycount(linksw)],
+	.dom_nprotosw = __arraycount(linksw),
 	.dom_sockaddr_cmp = sockaddr_dl_cmp
 };
 
Index: sys/net/rtsock.c
===================================================================
RCS file: /cvsroot/src/sys/net/rtsock.c,v
retrieving revision 1.186
diff -u -p -r1.186 rtsock.c
--- sys/net/rtsock.c	12 May 2016 02:24:16 -0000	1.186
+++ sys/net/rtsock.c	13 May 2016 12:27:51 -0000
@@ -150,6 +150,16 @@ struct route_info COMPATNAME(route_info)
 	.ri_maxqlen = IFQ_MAXLEN,
 };
 
+struct routeprotosw {
+	struct protosw	routepr_protosw;
+#ifdef notyet
+	void		(*routepr_input)(struct mbuf *,
+			    struct sockaddr *, struct sockaddr *);
+#else
+	void		(*routepr_input)(struct mbuf *, ...);
+#endif
+};
+
 #define	PRESERVED_RTF	(RTF_UP | RTF_GATEWAY | RTF_HOST | RTF_DONE | RTF_MASK)
 
 static void COMPATNAME(route_init)(void);
@@ -167,7 +177,7 @@ static int sysctl_iflist(int, struct rt_
 static int sysctl_rtable(SYSCTLFN_PROTO);
 static void rt_adjustcount(int, int);
 
-static const struct protosw COMPATNAME(route_protosw)[];
+static const struct routeprotosw COMPATNAME(routesw)[];
 
 static void
 rt_adjustcount(int af, int cnt)
@@ -394,7 +404,7 @@ COMPATNAME(route_send)(struct socket *so
 	int s;
 
 	KASSERT(solocked(so));
-	KASSERT(so->so_proto == &COMPATNAME(route_protosw)[0]);
+	KASSERT(so->so_proto == &COMPATNAME(routesw)[0].routepr_protosw);
 
 	s = splsoftnet();
 	error = raw_send(so, m, nam, control, l, &COMPATNAME(route_output));
@@ -1682,21 +1692,6 @@ COMPATNAME(route_enqueue)(struct mbuf *m
 	splx(s);
 }
 
-static void
-COMPATNAME(route_init)(void)
-{
-	struct route_info * const ri = &COMPATNAME(route_info);
-
-#ifndef COMPAT_RTSOCK
-	rt_init();
-#endif
-
-	sysctl_net_route_setup(NULL);
-	ri->ri_intrq.ifq_maxlen = ri->ri_maxqlen;
-	ri->ri_sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
-	    COMPATNAME(route_intr), NULL);
-}
-
 /*
  * Definitions of protocols supported in the ROUTE domain.
  */
@@ -1728,25 +1723,49 @@ static const struct pr_usrreqs route_usr
 	.pr_purgeif	= COMPATNAME(route_purgeif_wrapper),
 };
 
-static const struct protosw COMPATNAME(route_protosw)[] = {
-	{
+static const struct routeprotosw COMPATNAME(routesw)[] = {
+{
+	.routepr_protosw = {
 		.pr_type = SOCK_RAW,
 		.pr_domain = &COMPATNAME(routedomain),
 		.pr_flags = PR_ATOMIC|PR_ADDR,
-		.pr_input = raw_input,
 		.pr_ctlinput = raw_ctlinput,
 		.pr_usrreqs = &route_usrreqs,
 		.pr_init = raw_init,
 	},
+	.routepr_input = raw_input,
+},
 };
 
+static const struct protosw
+    *COMPATNAME(routeprotosw)[__arraycount(COMPATNAME(routesw))];
+
+static void
+COMPATNAME(route_init)(void)
+{
+	size_t i;
+	struct route_info * const ri = &COMPATNAME(route_info);
+
+	for (i = 0; i < COMPATNAME(routedomain).dom_nprotosw; i++) {
+		COMPATNAME(routedomain).dom_protosw[i] =
+		    &COMPATNAME(routesw)[i].routepr_protosw;
+	}
+#ifndef COMPAT_RTSOCK
+	rt_init();
+#endif
+
+	sysctl_net_route_setup(NULL);
+	ri->ri_intrq.ifq_maxlen = ri->ri_maxqlen;
+	ri->ri_sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+	    COMPATNAME(route_intr), NULL);
+}
+
 struct domain COMPATNAME(routedomain) = {
 	.dom_family = PF_XROUTE,
 	.dom_name = DOMAINNAME,
 	.dom_init = COMPATNAME(route_init),
-	.dom_protosw = COMPATNAME(route_protosw),
-	.dom_protoswNPROTOSW =
-	    &COMPATNAME(route_protosw)[__arraycount(COMPATNAME(route_protosw))],
+	.dom_protosw = COMPATNAME(routeprotosw),
+	.dom_nprotosw = __arraycount(COMPATNAME(routeprotosw)),
 };
 
 static void
Index: sys/netatalk/at.h
===================================================================
RCS file: /cvsroot/src/sys/netatalk/at.h,v
retrieving revision 1.8
diff -u -p -r1.8 at.h
--- sys/netatalk/at.h	2 Dec 2014 19:33:44 -0000	1.8
+++ sys/netatalk/at.h	13 May 2016 12:27:51 -0000
@@ -99,7 +99,7 @@ struct sockaddr_at {
 #include <sys/protosw.h>
 
 extern struct domain atalkdomain;
-extern const struct protosw atalksw[];
+extern const struct protosw *atalksw[];
 #endif
 
 #if defined(_KERNEL) || defined(_TEST)
Index: sys/netatalk/at_proto.c
===================================================================
RCS file: /cvsroot/src/sys/netatalk/at_proto.c,v
retrieving revision 1.21
diff -u -p -r1.21 at_proto.c
--- sys/netatalk/at_proto.c	21 Jan 2016 15:41:30 -0000	1.21
+++ sys/netatalk/at_proto.c	13 May 2016 12:27:51 -0000
@@ -49,8 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: at_proto.c,v
 
 DOMAIN_DEFINE(atalkdomain);	/* forward declare and add to link set */
 
-const struct protosw atalksw[] = {
-    {
+const struct protosw *atalksw[] = {
+    &(const struct protosw) {
 	.pr_type = SOCK_DGRAM,
 	.pr_domain = &atalkdomain,
 	.pr_protocol = ATPROTO_DDP,
@@ -67,7 +67,7 @@ struct domain atalkdomain = {
 	.dom_externalize = NULL,
 	.dom_dispose = NULL,
 	.dom_protosw = atalksw,
-	.dom_protoswNPROTOSW = &atalksw[__arraycount(atalksw)],
+	.dom_nprotosw = __arraycount(atalksw),
 	.dom_rtattach = rt_inithead,
 	.dom_rtoffset = 32,
 	.dom_maxrtkey = sizeof(struct sockaddr_at),
Index: sys/netbt/bt_proto.c
===================================================================
RCS file: /cvsroot/src/sys/netbt/bt_proto.c,v
retrieving revision 1.16
diff -u -p -r1.16 bt_proto.c
--- sys/netbt/bt_proto.c	21 Jan 2016 15:41:30 -0000	1.16
+++ sys/netbt/bt_proto.c	13 May 2016 12:27:51 -0000
@@ -62,8 +62,8 @@ PR_WRAP_CTLOUTPUT(rfcomm_ctloutput)
 #define	l2cap_ctloutput		l2cap_ctloutput_wrapper
 #define	rfcomm_ctloutput	rfcomm_ctloutput_wrapper
 
-static const struct protosw btsw[] = {
-	{ /* raw HCI commands */
+static const struct protosw *btsw[] = {
+	&(const struct protosw) { /* raw HCI commands */
 		.pr_type = SOCK_RAW,
 		.pr_domain = &btdomain,
 		.pr_protocol = BTPROTO_HCI,
@@ -72,7 +72,7 @@ static const struct protosw btsw[] = {
 		.pr_ctloutput = hci_ctloutput,
 		.pr_usrreqs = &hci_usrreqs,
 	},
-	{ /* HCI SCO data (audio) */
+	&(const struct protosw) { /* HCI SCO data (audio) */
 		.pr_type = SOCK_SEQPACKET,
 		.pr_domain = &btdomain,
 		.pr_protocol = BTPROTO_SCO,
@@ -80,7 +80,7 @@ static const struct protosw btsw[] = {
 		.pr_ctloutput = sco_ctloutput,
 		.pr_usrreqs = &sco_usrreqs,
 	},
-	{ /* L2CAP Connection Oriented */
+	&(const struct protosw) { /* L2CAP Connection Oriented */
 		.pr_type = SOCK_SEQPACKET,
 		.pr_domain = &btdomain,
 		.pr_protocol = BTPROTO_L2CAP,
@@ -89,7 +89,7 @@ static const struct protosw btsw[] = {
 		.pr_usrreqs = &l2cap_usrreqs,
 		.pr_init = l2cap_init,
 	},
-	{ /* RFCOMM */
+	&(const struct protosw) { /* RFCOMM */
 		.pr_type = SOCK_STREAM,
 		.pr_domain = &btdomain,
 		.pr_protocol = BTPROTO_RFCOMM,
@@ -105,7 +105,7 @@ struct domain btdomain = {
 	.dom_name = "bluetooth",
 	.dom_init = bt_init,
 	.dom_protosw = btsw,
-	.dom_protoswNPROTOSW = &btsw[__arraycount(btsw)],
+	.dom_nprotosw = __arraycount(btsw),
 };
 
 kmutex_t *bt_lock;
Index: sys/netinet/if_arp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/if_arp.c,v
retrieving revision 1.209
diff -u -p -r1.209 if_arp.c
--- sys/netinet/if_arp.c	25 Apr 2016 14:38:08 -0000	1.209
+++ sys/netinet/if_arp.c	13 May 2016 12:27:51 -0000
@@ -257,12 +257,12 @@ arp_fasttimo(void)
 	}
 }
 
-const struct protosw arpsw[] = {
-	{ .pr_type = 0,
+const struct protosw *arpsw[] = {
+	&(const struct protosw) {
+	  .pr_type = 0,
 	  .pr_domain = &arpdomain,
 	  .pr_protocol = 0,
 	  .pr_flags = 0,
-	  .pr_input = 0,
 	  .pr_ctlinput = 0,
 	  .pr_ctloutput = 0,
 	  .pr_usrreqs = 0,
@@ -277,7 +277,7 @@ struct domain arpdomain = {
 	.dom_family = PF_ARP,
 	.dom_name = "arp",
 	.dom_protosw = arpsw,
-	.dom_protoswNPROTOSW = &arpsw[__arraycount(arpsw)],
+	.dom_nprotosw = __arraycount(arpsw),
 };
 
 static void sysctl_net_inet_arp_setup(struct sysctllog **);
Index: sys/netinet/in_proto.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_proto.c,v
retrieving revision 1.120
diff -u -p -r1.120 in_proto.c
--- sys/netinet/in_proto.c	26 Apr 2016 08:44:44 -0000	1.120
+++ sys/netinet/in_proto.c	13 May 2016 12:27:51 -0000
@@ -194,214 +194,277 @@ PR_WRAP_CTLINPUT(esp4_ctlinput)
 #define	esp4_ctlinput	esp4_ctlinput_wrapper
 #endif
 
-const struct protosw inetsw[] = {
-{	.pr_domain = &inetdomain,
+const struct ipprotosw inetsw[] = {
+{
+    .ippr_protosw = {
+	.pr_domain = &inetdomain,
 	.pr_init = ip_init,
 	.pr_fasttimo = ip_fasttimo,
 	.pr_slowtimo = ip_slowtimo,
 	.pr_drain = ip_drainstub,
+    },
 },
-{	.pr_type = SOCK_DGRAM,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_DGRAM,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_UDP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
-	.pr_input = udp_input,
 	.pr_ctlinput = udp_ctlinput,
 	.pr_ctloutput = udp_ctloutput,
 	.pr_usrreqs = &udp_usrreqs,
 	.pr_init = udp_init,
+    },
+    .ippr_input = udp_input,
 },
-{	.pr_type = SOCK_STREAM,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_STREAM,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_TCP,
 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
-	.pr_input = tcp_input,
 	.pr_ctlinput = tcp_ctlinput,
 	.pr_ctloutput = tcp_ctloutput,
 	.pr_usrreqs = &tcp_usrreqs,
 	.pr_init = tcp_init,
 	.pr_fasttimo = tcp_fasttimo,
 	.pr_drain = tcp_drainstub,
+    },
+    .ippr_input = tcp_input,
 },
 #ifdef DCCP
-{	.pr_type = SOCK_CONN_DGRAM,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_CONN_DGRAM,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_DCCP,
 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_ATOMIC|PR_LISTEN|PR_ABRTACPTDIS,
-	.pr_input = dccp_input,
 	.pr_ctlinput = dccp_ctlinput,
 	.pr_ctloutput = dccp_ctloutput,
 	.pr_usrreqs = &dccp_usrreqs,
 	.pr_init = dccp_init,
+    },
+    .ippr_input = dccp_input,
 },
 #endif
 #ifdef SCTP
-{	.pr_type = SOCK_DGRAM,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_DGRAM,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
-	.pr_input = sctp_input,
 	.pr_ctlinput = sctp_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_usrreqs = &sctp_usrreqs,
 	.pr_init = sctp_init,
 	.pr_drain = sctp_drain
+    },
+    .ippr_input = sctp_input,
 },
-{	.pr_type = SOCK_SEQPACKET,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_SEQPACKET,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
-	.pr_input = sctp_input,
 	.pr_ctlinput = sctp_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_usrreqs = &sctp_usrreqs,
 	.pr_drain = sctp_drain
+    },
+    .ippr_input = sctp_input,
 },
-{	.pr_type = SOCK_STREAM,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_STREAM,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
-	.pr_input = sctp_input,
 	.pr_ctlinput = sctp_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_usrreqs = &sctp_usrreqs,
 	.pr_drain = sctp_drain
+    },
+    .ippr_input = sctp_input,
 },
 #endif /* SCTP */
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_RAW,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
-	.pr_input = rip_input,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
+    },
+    .ippr_input = rip_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_ICMP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = icmp_input,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_init = icmp_init,
+    },
+    .ippr_input = icmp_input,
 },
 #ifdef GATEWAY
-{	.pr_domain = &inetdomain,
+{
+    .ippr_protosw = {
+	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_IP,
 	.pr_slowtimo = ipflow_slowtimo,
 	.pr_init = ipflow_poolinit,
+    },
 },
 #endif /* GATEWAY */
 #ifdef IPSEC
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_AH,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec4_common_input,
 	.pr_ctlinput = ah4_ctlinput,
+    },
+    .ippr_input = ipsec4_common_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_ESP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec4_common_input,
 	.pr_ctlinput = esp4_ctlinput,
+    },
+    .ippr_input = ipsec4_common_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_IPCOMP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec4_common_input,
+    },
+    .ippr_input = ipsec4_common_input,
 },
 #endif /* IPSEC */
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_IPV4,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = encap4_input,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_init = encap_init,
+    },
+    .ippr_input = encap4_input,
 },
 #ifdef INET6
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_IPV6,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = encap4_input,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_init = encap_init,
+    },
+    .ippr_input = encap4_input,
 },
 #endif /* INET6 */
 #if NETHERIP > 0
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_ETHERIP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = ip_etherip_input,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
+    },
+    .ippr_input = ip_etherip_input,
 },
 #endif /* NETHERIP > 0 */
 #if NCARP > 0
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_CARP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = carp_proto_input,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_init = carp_init,
+    },
+    .ippr_input = carp_proto_input,
 },
 #endif /* NCARP > 0 */
 #if NPFSYNC > 0
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_PFSYNC,
 	.pr_flags	 = PR_ATOMIC|PR_ADDR,
-	.pr_input	 = pfsync_input,
 	.pr_ctloutput = rip_ctloutput,
 	.pr_usrreqs	 = &rip_usrreqs,
+    },
+    .ippr_input	 = pfsync_input,
 },
 #endif /* NPFSYNC > 0 */
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_IGMP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = igmp_input, 
 	.pr_ctloutput = rip_ctloutput,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_fasttimo = igmp_fasttimo,
 	.pr_slowtimo = igmp_slowtimo,
 	.pr_init = igmp_init,
+    },
+    .ippr_input = igmp_input,
 },
 #ifdef PIM
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_protocol = IPPROTO_PIM,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = pim_input, 
 	.pr_ctloutput = rip_ctloutput,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_usrreqs = &rip_usrreqs,
+    },
+    .ippr_input = pim_input,
 },
 #endif /* PIM */
 /* raw wildcard */
-{	.pr_type = SOCK_RAW,
+{
+    .ippr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inetdomain,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = rip_input, 
 	.pr_ctloutput = rip_ctloutput,
 	.pr_ctlinput = rip_ctlinput,
 	.pr_usrreqs = &rip_usrreqs,
 	.pr_init = rip_init,
+    },
+    .ippr_input = rip_input,
 },
 };
 
@@ -412,11 +475,24 @@ const struct sockaddr_in in_any = {
 	, .sin_addr = {.s_addr = 0 /* INADDR_ANY */}
 };
 
+static const struct protosw *inetprotosw[__arraycount(inetsw)];
+
+static void
+in_dom_init(void)
+{
+	size_t i;
+
+	for (i = 0; i < inetdomain.dom_nprotosw; i++) {
+		inetdomain.dom_protosw[i] = &inetsw[i].ippr_protosw;
+	}
+}
+
 struct domain inetdomain = {
-	.dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
+	.dom_family = PF_INET, .dom_name = "internet",
+	.dom_init = in_dom_init,
 	.dom_externalize = NULL, .dom_dispose = NULL,
-	.dom_protosw = inetsw,
-	.dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)],
+	.dom_protosw = inetprotosw,
+	.dom_nprotosw = __arraycount(inetprotosw),
 	.dom_rtattach = rt_inithead,
 	.dom_rtoffset = 32,
 	.dom_maxrtkey = sizeof(struct ip_pack4),
Index: sys/netinet/in_proto.h
===================================================================
RCS file: /cvsroot/src/sys/netinet/in_proto.h,v
retrieving revision 1.4
diff -u -p -r1.4 in_proto.h
--- sys/netinet/in_proto.h	21 Jan 2016 15:41:30 -0000	1.4
+++ sys/netinet/in_proto.h	13 May 2016 12:27:51 -0000
@@ -34,6 +34,14 @@
 #ifndef _NETINET_IN_PROTO_H_
 #define _NETINET_IN_PROTO_H_
 
-extern const struct protosw inetsw[];
+struct ipprotosw {
+	struct protosw	ippr_protosw;
+#ifdef notyet
+	void		(*ippr_input)(struct mbuf *, int, int);
+#endif
+	void		(*ippr_input)(struct mbuf *, ...);
+};
+
+extern const struct ipprotosw inetsw[];
 
 #endif /* !_NETINET_IN_PROTO_H_ */
Index: sys/netinet/ip_icmp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.145
diff -u -p -r1.145 ip_icmp.c
--- sys/netinet/ip_icmp.c	1 Apr 2016 09:16:02 -0000	1.145
+++ sys/netinet/ip_icmp.c	13 May 2016 12:27:51 -0000
@@ -526,7 +526,7 @@ icmp_input(struct mbuf *m, ...)
 			printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
 #endif
 		icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
-		ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput;
+		ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].ippr_protosw.pr_ctlinput;
 		if (ctlfunc)
 			(void) (*ctlfunc)(code, sintosa(&icmpsrc),
 			    &icp->icmp_ip);
Index: sys/netinet/ip_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_input.c,v
retrieving revision 1.328
diff -u -p -r1.328 ip_input.c
--- sys/netinet/ip_input.c	21 Jan 2016 15:41:30 -0000	1.328
+++ sys/netinet/ip_input.c	13 May 2016 12:27:51 -0000
@@ -301,24 +301,29 @@ void
 ip_init(void)
 {
 	const struct protosw *pr;
+	const struct ipprotosw *ippr;
+	size_t i;
 
 	in_init();
 	sysctl_net_inet_ip_setup(NULL);
 
 	pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
 	KASSERT(pr != NULL);
+	ippr = const_container_of(pr, struct ipprotosw, ippr_protosw);
 
 	ip_pktq = pktq_create(IFQ_MAXLEN, ipintr, NULL);
 	KASSERT(ip_pktq != NULL);
 
-	for (u_int i = 0; i < IPPROTO_MAX; i++) {
-		ip_protox[i] = pr - inetsw;
+	for (i = 0; i < IPPROTO_MAX; i++) {
+		ip_protox[i] = ippr - inetsw;
 	}
-	for (pr = inetdomain.dom_protosw;
-	    pr < inetdomain.dom_protoswNPROTOSW; pr++)
+	for (i = 0; i < inetdomain.dom_nprotosw; i++) {
+		pr = inetdomain.dom_protosw[i];
+		ippr = const_container_of(pr, struct ipprotosw, ippr_protosw);
 		if (pr->pr_domain->dom_family == PF_INET &&
 		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
-			ip_protox[pr->pr_protocol] = pr - inetsw;
+			ip_protox[pr->pr_protocol] = ippr - inetsw;
+	}
 
 	ip_reass_init();
 
@@ -755,7 +760,8 @@ ours:
 	 * code - like UDP/TCP/raw IP.
 	 */
 	if (ipsec_used &&
-	    (inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
+	    ((inetsw[ip_protox[ip->ip_p]].ippr_protosw.pr_flags & PR_LASTHDR)
+		!= 0)) {
 		SOFTNET_LOCK();
 		if (ipsec4_input(m, 0) != 0) {
 			SOFTNET_UNLOCK();
@@ -777,7 +783,7 @@ ours:
 	const int off = hlen, nh = ip->ip_p;
 
 	SOFTNET_LOCK();
-	(*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
+	(*inetsw[ip_protox[nh]].ippr_input)(m, off, nh);
 	SOFTNET_UNLOCK();
 	return;
 bad:
Index: sys/netinet/raw_ip.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/raw_ip.c,v
retrieving revision 1.158
diff -u -p -r1.158 raw_ip.c
--- sys/netinet/raw_ip.c	12 May 2016 02:24:17 -0000	1.158
+++ sys/netinet/raw_ip.c	13 May 2016 12:27:51 -0000
@@ -236,7 +236,7 @@ rip_input(struct mbuf *m, ...)
 #endif /*IPSEC*/
 	if (last != NULL)
 		rip_sbappendaddr(last, ip, sintosa(&ripsrc), hlen, opts, m);
-	else if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {
+	else if (inetsw[ip_protox[ip->ip_p]].ippr_input == rip_input) {
 		uint64_t *ips;
 
 		icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,
Index: sys/netinet6/icmp6.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/icmp6.c,v
retrieving revision 1.183
diff -u -p -r1.183 icmp6.c
--- sys/netinet6/icmp6.c	12 May 2016 02:24:17 -0000	1.183
+++ sys/netinet6/icmp6.c	13 May 2016 12:27:52 -0000
@@ -909,7 +909,7 @@ icmp6_notify_error(struct mbuf *m, int o
 
 	/* Detect the upper level protocol */
 	{
-		void (*ctlfunc)(int, struct sockaddr *, void *);
+		void *(*ctlfunc)(int, const struct sockaddr *, void *);
 		u_int8_t nxt = eip6->ip6_nxt;
 		int eoff = off + sizeof(struct icmp6_hdr) +
 			sizeof(struct ip6_hdr);
@@ -1057,9 +1057,7 @@ icmp6_notify_error(struct mbuf *m, int o
 			notifymtu = ntohl(icmp6->icmp6_mtu);
 			ip6cp.ip6c_cmdarg = (void *)&notifymtu;
 		}
-
-		ctlfunc = (void (*)(int, struct sockaddr *, void *))
-			(inet6sw[ip6_protox[nxt]].pr_ctlinput);
+		ctlfunc = inet6sw[ip6_protox[nxt]].ip6pr_protosw.pr_ctlinput;
 		if (ctlfunc) {
 			(void) (*ctlfunc)(code, (struct sockaddr *)&icmp6dst,
 					  &ip6cp);
Index: sys/netinet6/in6_proto.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/in6_proto.c,v
retrieving revision 1.112
diff -u -p -r1.112 in6_proto.c
--- sys/netinet6/in6_proto.c	26 Apr 2016 08:44:45 -0000	1.112
+++ sys/netinet6/in6_proto.c	13 May 2016 12:27:52 -0000
@@ -208,205 +208,271 @@ tcp6_init(void)
 }
 
 const struct ip6protosw inet6sw[] = {
-{	.pr_domain = &inet6domain,
+{
+    .ip6pr_protosw = {
+	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_IPV6,
 	.pr_init = ip6_init,
 	.pr_fasttimo = frag6_fasttimo,
 	.pr_slowtimo = frag6_slowtimo,
 	.pr_drain = frag6_drainstub,
+	},
 },
-{	.pr_type = SOCK_DGRAM,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_DGRAM,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_UDP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
-	.pr_input = udp6_input,
 	.pr_ctlinput = udp6_ctlinput,
 	.pr_ctloutput = udp6_ctloutput,
 	.pr_usrreqs = &udp6_usrreqs,
 	.pr_init = udp6_init,
+    },
+    .ip6pr_input = udp6_input,
 },
-{	.pr_type = SOCK_STREAM,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_STREAM,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_TCP,
 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
-	.pr_input = tcp6_input,
 	.pr_ctlinput = tcp6_ctlinput,
 	.pr_ctloutput = tcp_ctloutput,
 	.pr_usrreqs = &tcp_usrreqs,
 	.pr_init = tcp6_init,
 	.pr_fasttimo = tcp_fasttimo,
 	.pr_drain = tcp_drainstub,
+    },
+    .ip6pr_input = tcp6_input,
 },
 #ifdef DCCP
-{	.pr_type = SOCK_CONN_DGRAM,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_CONN_DGRAM,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_DCCP,
 	.pr_flags = PR_CONNREQUIRED|PR_ATOMIC|PR_LISTEN,
-	.pr_input = dccp6_input,
 	.pr_ctlinput = dccp6_ctlinput,
 	.pr_ctloutput = dccp_ctloutput,
 	.pr_usrreqs = &dccp6_usrreqs,
 #ifndef INET
 	.pr_init = dccp_init,
 #endif
+    },
+    .ip6pr_input = dccp6_input,
 },
 #endif /* DCCP */
 #ifdef SCTP
-{	.pr_type = SOCK_DGRAM,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_DGRAM,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
-	.pr_input = sctp6_input,
 	.pr_ctlinput = sctp6_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_usrreqs = &sctp6_usrreqs,
 	.pr_drain = sctp_drain,
+    },
+    .ip6pr_input = sctp6_input,
 },
-{	.pr_type = SOCK_SEQPACKET,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_SEQPACKET,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
-	.pr_input = sctp6_input,
 	.pr_ctlinput = sctp6_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_drain = sctp_drain,
+    },
+    .ip6pr_input = sctp6_input,
 },
-{	.pr_type = SOCK_STREAM,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_STREAM,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_SCTP,
 	.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
-	.pr_input = sctp6_input,
 	.pr_ctlinput = sctp6_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
 	.pr_drain = sctp_drain,
+    },
+    .ip6pr_input = sctp6_input,
 },
 #endif /* SCTP */
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_RAW,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
-	.pr_input = rip6_input,
 	.pr_ctlinput = rip6_ctlinput,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
+    },
+    .ip6pr_input = rip6_input,
 },
 #ifdef GATEWAY
-{	.pr_domain = &inet6domain,
+{
+    .ip6pr_protosw = {
+	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_IPV6,
 	.pr_slowtimo = ip6flow_slowtimo,
 	.pr_init = ip6flow_poolinit,
+    }
 },
 #endif /* GATEWAY */
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_ICMPV6,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = icmp6_input,
 	.pr_ctlinput = rip6_ctlinput,
 	.pr_ctloutput = icmp6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
 	.pr_init = icmp6_init,
+    },
+    .ip6pr_input = icmp6_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_DSTOPTS,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = dest6_input,
+    },
+    .ip6pr_input = dest6_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_ROUTING,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = route6_input,
+    },
+    .ip6pr_input = route6_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_FRAGMENT,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = frag6_input,
+    },
+    .ip6pr_input = frag6_input,
 },
 #ifdef IPSEC
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_AH,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec6_common_input,
 	.pr_ctlinput = ah6_ctlinput,
+    },
+    .ip6pr_input = ipsec6_common_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_ESP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec6_common_input,
 	.pr_ctlinput = esp6_ctlinput,
+    },
+    .ip6pr_input = ipsec6_common_input,
 },
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_IPCOMP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = ipsec6_common_input,
+    },
+    .ip6pr_input = ipsec6_common_input,
 },
 #endif /* IPSEC */
 #ifdef INET
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_IPV4,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = encap6_input,
 	.pr_ctlinput = encap6_ctlinput,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
 	.pr_init = encap_init,
+    },
+    .ip6pr_input = encap6_input,
 },
 #endif
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_IPV6,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = encap6_input,
 	.pr_ctlinput = encap6_ctlinput,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
 	.pr_init = encap_init,
+    },
+    .ip6pr_input = encap6_input,
 },
 #if NETHERIP > 0
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_ETHERIP,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = ip6_etherip_input,
 	.pr_ctlinput = rip6_ctlinput,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
+    },
+    .ip6pr_input = ip6_etherip_input,
 },
 #endif
 #if NCARP > 0
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_CARP,
 	.pr_flags = PR_ATOMIC|PR_ADDR,
-	.pr_input = carp6_proto_input,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
+    },
+    .ip6pr_input = carp6_proto_input,
 },
 #endif /* NCARP */
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_protocol = IPPROTO_PIM,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = pim6_input,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
 	.pr_init = pim6_init,
+    },
+    .ip6pr_input = pim6_input,
 },
 /* raw wildcard */
-{	.pr_type = SOCK_RAW,
+{
+    .ip6pr_protosw = {
+	.pr_type = SOCK_RAW,
 	.pr_domain = &inet6domain,
 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input = rip6_input,
 	.pr_ctloutput = rip6_ctloutput,
 	.pr_usrreqs = &rip6_usrreqs,
 	.pr_init = rip6_init,
+    },
+    .ip6pr_input = rip6_input,
 },
 };
 
@@ -419,19 +485,25 @@ static const struct sockaddr_in6 in6_any
 	, .sin6_scope_id = 0
 };
 
+static const struct protosw *inet6protosw[__arraycount(inet6sw)];
+
 bool in6_present = false;
 static void
-in6_init(void)
+in6_dom_init(void)
 {
+	size_t i;
 
 	in6_present = true;
+	for (i = 0; i < inet6domain.dom_nprotosw; i++) {
+		inet6domain.dom_protosw[i] = &inet6sw[i].ip6pr_protosw;
+	}
 }
 
 struct domain inet6domain = {
 	.dom_family = AF_INET6, .dom_name = "internet6",
-	.dom_init = in6_init, .dom_externalize = NULL, .dom_dispose = NULL,
-	.dom_protosw = (const struct protosw *)inet6sw,
-	.dom_protoswNPROTOSW = (const struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
+	.dom_init = in6_dom_init, .dom_externalize = NULL, .dom_dispose = NULL,
+	.dom_protosw = inet6protosw,
+	.dom_nprotosw = __arraycount(inet6sw),
 	.dom_rtattach = rt_inithead,
 	.dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3,
 	.dom_maxrtkey = sizeof(struct ip_pack6),
Index: sys/netinet6/ip6_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.158
diff -u -p -r1.158 ip6_input.c
--- sys/netinet6/ip6_input.c	4 Apr 2016 07:37:07 -0000	1.158
+++ sys/netinet6/ip6_input.c	13 May 2016 12:27:52 -0000
@@ -160,20 +160,26 @@ static void sysctl_net_inet6_ip6_setup(s
 void
 ip6_init(void)
 {
-	const struct ip6protosw *pr;
-	int i;
+	const struct protosw *pr;
+	const struct ip6protosw *ip6pr;
+	size_t i;
 
 	sysctl_net_inet6_ip6_setup(NULL);
-	pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
-	if (pr == 0)
-		panic("ip6_init");
+
+	pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
+	KASSERT(pr != NULL);
+	ip6pr = const_container_of(pr, struct ip6protosw, ip6pr_protosw);
+
 	for (i = 0; i < IPPROTO_MAX; i++)
-		ip6_protox[i] = pr - inet6sw;
-	for (pr = (const struct ip6protosw *)inet6domain.dom_protosw;
-	    pr < (const struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
+		ip6_protox[i] = ip6pr - inet6sw;
+	for (i = 0; i < inet6domain.dom_nprotosw; i++) {
+		pr = inet6domain.dom_protosw[i];
+		ip6pr = const_container_of(pr,
+		    struct ip6protosw, ip6pr_protosw);
 		if (pr->pr_domain->dom_family == PF_INET6 &&
 		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
-			ip6_protox[pr->pr_protocol] = pr - inet6sw;
+			ip6_protox[pr->pr_protocol] = ip6pr - inet6sw;
+	}
 
 	ip6_pktq = pktq_create(IFQ_MAXLEN, ip6intr, NULL);
 	KASSERT(ip6_pktq != NULL);
@@ -742,7 +748,7 @@ ip6_input(struct mbuf *m)
 			 * header. note that we do not visit this with
 			 * protocols with pcb layer code - like udp/tcp/raw ip.
 			 */
-			if ((inet6sw[ip_protox[nxt]].pr_flags
+			if ((inet6sw[ip_protox[nxt]].ip6pr_protosw.pr_flags
 			    & PR_LASTHDR) != 0) {
 				int error = ipsec6_input(m);
 				if (error)
@@ -751,7 +757,7 @@ ip6_input(struct mbuf *m)
 		}
 #endif /* IPSEC */
 
-		nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
+		nxt = (*inet6sw[ip6_protox[nxt]].ip6pr_input)(&m, &off, nxt);
 	}
 	return;
  bad:
Index: sys/netinet6/ip6protosw.h
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6protosw.h,v
retrieving revision 1.25
diff -u -p -r1.25 ip6protosw.h
--- sys/netinet6/ip6protosw.h	21 Jan 2016 15:41:30 -0000	1.25
+++ sys/netinet6/ip6protosw.h	13 May 2016 12:27:52 -0000
@@ -112,32 +112,8 @@ struct ip6ctlparam {
 };
 
 struct ip6protosw {
-	int 	pr_type;		/* socket type used for */
-	struct	domain *pr_domain;	/* domain protocol a member of */
-	short	pr_protocol;		/* protocol number */
-	short	pr_flags;		/* see below */
-
-/* protocol-protocol hooks */
-	int	(*pr_input)		/* input to protocol (from below) */
-			(struct mbuf **, int *, int);
-	void	*(*pr_ctlinput)		/* control input (from below) */
-			(int, const struct sockaddr *, void *);
-	int	(*pr_ctloutput)		/* control output (from above) */
-			(int, struct socket *, struct sockopt *);
-
-/* user-protocol hook */
-	const struct pr_usrreqs *pr_usrreqs;
-
-/* utility hooks */
-	void	(*pr_init)		/* initialization hook */
-			(void);
-
-	void	(*pr_fasttimo)		/* fast timeout (200ms) */
-			(void);
-	void	(*pr_slowtimo)		/* slow timeout (500ms) */
-			(void);
-	void	(*pr_drain)		/* flush any excess space possible */
-			(void);
+	struct protosw	ip6pr_protosw;
+	int		(*ip6pr_input)(struct mbuf **, int *, int);
 };
 
 extern const struct ip6protosw inet6sw[];
Index: sys/netipsec/ipsec_input.c
===================================================================
RCS file: /cvsroot/src/sys/netipsec/ipsec_input.c,v
retrieving revision 1.35
diff -u -p -r1.35 ipsec_input.c
--- sys/netipsec/ipsec_input.c	21 Jan 2016 15:41:30 -0000	1.35
+++ sys/netipsec/ipsec_input.c	13 May 2016 12:27:52 -0000
@@ -431,12 +431,12 @@ ipsec4_common_input_cb(struct mbuf *m, s
 
 	key_sa_recordxfer(sav, m);		/* record data transfer */
 
-	if ((inetsw[ip_protox[prot]].pr_flags & PR_LASTHDR) != 0 &&
+	if ((inetsw[ip_protox[prot]].ippr_protosw.pr_flags & PR_LASTHDR) != 0 &&
 				ipsec4_in_reject(m, NULL)) {
 		error = EINVAL;
 		goto bad;
 	}
-	(*inetsw[ip_protox[prot]].pr_input)(m, skip, prot);
+	(*inetsw[ip_protox[prot]].ippr_input)(m, skip, prot);
 	return 0;
 bad:
 	m_freem(m);
@@ -778,12 +778,12 @@ ipsec6_common_input_cb(struct mbuf *m, s
 		 * note that we do not visit this with protocols with pcb layer
 		 * code - like udp/tcp/raw ip.
 		 */
-		if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 &&
-		    ipsec6_in_reject(m, NULL)) {
+		if ((inet6sw[ip6_protox[nxt]].ip6pr_protosw.pr_flags &
+		    PR_LASTHDR) != 0 && ipsec6_in_reject(m, NULL)) {
 			error = EINVAL;
 			goto bad;
 		}
-		nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &skip, nxt);
+		nxt = (*inet6sw[ip6_protox[nxt]].ip6pr_input)(&m, &skip, nxt);
 	}
 	return 0;
 bad:
Index: sys/netipsec/ipsec_osdep.h
===================================================================
RCS file: /cvsroot/src/sys/netipsec/ipsec_osdep.h,v
retrieving revision 1.25
diff -u -p -r1.25 ipsec_osdep.h
--- sys/netipsec/ipsec_osdep.h	28 Apr 2016 01:37:17 -0000	1.25
+++ sys/netipsec/ipsec_osdep.h	13 May 2016 12:27:52 -0000
@@ -172,7 +172,6 @@ if_handoff(struct ifqueue *ifq, struct m
 /* protosw glue */
 #ifdef __NetBSD__
 #include <sys/protosw.h>
-#define ipprotosw protosw
 #endif	/* __NetBSD__ */
 
 /*
Index: sys/netipsec/keysock.c
===================================================================
RCS file: /cvsroot/src/sys/netipsec/keysock.c,v
retrieving revision 1.49
diff -u -p -r1.49 keysock.c
--- sys/netipsec/keysock.c	20 Jan 2016 21:44:00 -0000	1.49
+++ sys/netipsec/keysock.c	13 May 2016 12:27:52 -0000
@@ -76,7 +76,7 @@ static struct sockaddr key_src = {
     .sa_family = PF_KEY,
 };
 
-static const struct protosw keysw[];
+static const struct protosw *keysw[];
 
 static int key_sendup0(struct rawcb *, struct mbuf *, int, int);
 
@@ -631,7 +631,7 @@ key_send(struct socket *so, struct mbuf 
 	int s;
 
 	KASSERT(solocked(so));
-	KASSERT(so->so_proto == &keysw[0]);
+	KASSERT(so->so_proto == keysw[0]);
 
 	s = splsoftnet();
 	error = raw_send(so, m, nam, control, l, &key_output);
@@ -709,8 +709,8 @@ static const struct pr_usrreqs key_usrre
 	.pr_purgeif	= key_purgeif,
 };
 
-static const struct protosw keysw[] = {
-    {
+static const struct protosw *keysw[] = {
+    &(const struct protosw) {
 	.pr_type = SOCK_RAW,
 	.pr_domain = &keydomain,
 	.pr_protocol = PF_KEY_V2,
@@ -726,5 +726,5 @@ struct domain keydomain = {
     .dom_name = "key",
     .dom_init = key_init,
     .dom_protosw = keysw,
-    .dom_protoswNPROTOSW = &keysw[__arraycount(keysw)],
+    .dom_nprotosw = __arraycount(keysw),
 };
Index: sys/sys/domain.h
===================================================================
RCS file: /cvsroot/src/sys/sys/domain.h,v
retrieving revision 1.32
diff -u -p -r1.32 domain.h
--- sys/sys/domain.h	22 Apr 2015 19:46:08 -0000	1.32
+++ sys/sys/domain.h	13 May 2016 12:27:52 -0000
@@ -61,7 +61,8 @@ struct	domain {
 			(struct mbuf *, struct lwp *, int);
 	void	(*dom_dispose)		/* dispose of internalized rights */
 			(struct mbuf *);
-	const struct protosw *dom_protosw, *dom_protoswNPROTOSW;
+	const struct protosw **dom_protosw;
+	size_t	dom_nprotosw;
 	int	(*dom_rtattach)		/* initialize routing table */
 			(rtbl_t **, int);
 	int	dom_rtoffset;		/* an arg to rtattach, in bits */
Index: sys/sys/protosw.h
===================================================================
RCS file: /cvsroot/src/sys/sys/protosw.h,v
retrieving revision 1.66
diff -u -p -r1.66 protosw.h
--- sys/sys/protosw.h	20 Jan 2016 21:43:59 -0000	1.66
+++ sys/sys/protosw.h	13 May 2016 12:27:52 -0000
@@ -75,8 +75,6 @@ struct protosw {
 	short	pr_flags;		/* see below */
 
 /* protocol-protocol hooks */
-	void	(*pr_input)		/* input to protocol (from below) */
-			(struct mbuf *, ...);
 	void	*(*pr_ctlinput)		/* control input (from below) */
 			(int, const struct sockaddr *, void *);
 	int	(*pr_ctloutput)		/* control output (from above) */


Home | Main Index | Thread Index | Old Index