Fri Jan 22 05:15:10 2016 UTC ()
Don't abuse struct protosw for ip_encap -- introduce struct encapsw.
Mostly mechanical change to replace it, culling some now-needless
boilerplate around all the users.
This does not substantively change the ip_encap API or eliminate
abuse of sketchy pointer casts -- that will come later, and will be
easier now that it is not tangled up with struct protosw.
(riastradh)
diff -r1.83 -r1.84 src/sys/net/if_stf.c
diff -r1.69 -r1.70 src/sys/netinet/in_gif.c
diff -r1.48 -r1.49 src/sys/netinet/ip_encap.c
diff -r1.13 -r1.14 src/sys/netinet/ip_encap.h
diff -r1.134 -r1.135 src/sys/netinet/ip_mroute.c
diff -r1.66 -r1.67 src/sys/netinet6/in6_gif.c
diff -r1.33 -r1.34 src/sys/netipsec/xform_ipip.c
--- src/sys/net/if_stf.c 2016/01/20 21:43:59 1.83
+++ src/sys/net/if_stf.c 2016/01/22 05:15:10 1.84
@@ -1,4 +1,4 @@
-/* $NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $ */
+/* $NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $ */
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
/*
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -93,7 +93,6 @@
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
-#include <sys/protosw.h>
#include <sys/queue.h>
#include <sys/syslog.h>
@@ -156,18 +155,9 @@
static int ip_gif_ttl = 40; /*XXX*/
#endif
-extern struct domain inetdomain;
-
-static const struct protosw in_stf_protosw =
-{
- .pr_type = SOCK_RAW,
- .pr_domain = &inetdomain,
- .pr_protocol = IPPROTO_IPV6,
- .pr_flags = PR_ATOMIC|PR_ADDR,
- .pr_input = in_stf_input,
- .pr_ctlinput = NULL,
- .pr_ctloutput = rip_ctloutput,
- .pr_usrreqs = &rip_usrreqs,
+static const struct encapsw in_stf_encapsw = {
+ .en_input = in_stf_input,
+ .en_ctlinput = NULL,
};
static int stf_encapcheck(struct mbuf *, int, int, void *);
@@ -206,7 +196,7 @@
if_initname(&sc->sc_if, ifc->ifc_name, unit);
sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
- stf_encapcheck, &in_stf_protosw, sc);
+ stf_encapcheck, &in_stf_encapsw, sc);
if (sc->encap_cookie == NULL) {
printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
free(sc, M_DEVBUF);
--- src/sys/netinet/in_gif.c 2016/01/20 21:43:59 1.69
+++ src/sys/netinet/in_gif.c 2016/01/22 05:15:10 1.70
@@ -1,4 +1,4 @@
-/* $NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $ */
+/* $NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $ */
/* $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -45,7 +45,6 @@
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
-#include <sys/protosw.h>
#include <sys/kernel.h>
#include <net/if.h>
@@ -79,15 +78,9 @@
int ip_gif_ttl = 0;
#endif
-static const struct protosw in_gif_protosw = {
- .pr_type = SOCK_RAW,
- .pr_domain = &inetdomain,
- .pr_protocol = 0 /* IPPROTO_IPV[46] */,
- .pr_flags = PR_ATOMIC|PR_ADDR,
- .pr_input = in_gif_input,
- .pr_ctlinput = NULL,
- .pr_ctloutput = rip_ctloutput,
- .pr_usrreqs = &rip_usrreqs,
+static const struct encapsw in_gif_encapsw = {
+ .en_input = in_gif_input,
+ .en_ctlinput = NULL,
};
int
@@ -381,10 +374,10 @@
return EINVAL;
sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
(struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
- (const struct protosw *)&in_gif_protosw, sc);
+ &in_gif_encapsw, sc);
#else
sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
- &in_gif_protosw, sc);
+ &in_gif_encapsw, sc);
#endif
if (sc->encap_cookie4 == NULL)
return EEXIST;
--- src/sys/netinet/ip_encap.c 2016/01/20 05:58:49 1.48
+++ src/sys/netinet/ip_encap.c 2016/01/22 05:15:10 1.49
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_encap.c,v 1.48 2016/01/20 05:58:49 knakahara Exp $ */
+/* $NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $ */
/* $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $ */
/*
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.48 2016/01/20 05:58:49 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@@ -240,7 +240,7 @@
{
int off, proto;
va_list ap;
- const struct protosw *psw;
+ const struct encapsw *esw;
struct encaptab *match;
va_start(ap, m);
@@ -252,10 +252,10 @@
if (match) {
/* found a match, "match" has the best one */
- psw = match->psw;
- if (psw && psw->pr_input) {
+ esw = match->esw;
+ if (esw && esw->en_input) {
encap_fillarg(m, match);
- (*psw->pr_input)(m, off, proto);
+ (*esw->en_input)(m, off, proto);
} else
m_freem(m);
return;
@@ -329,17 +329,20 @@
encap6_input(struct mbuf **mp, int *offp, int proto)
{
struct mbuf *m = *mp;
- const struct ip6protosw *psw;
+ const struct encapsw *esw;
struct encaptab *match;
match = encap6_lookup(m, *offp, proto, INBOUND);
if (match) {
/* found a match */
- psw = (const struct ip6protosw *)match->psw;
- if (psw && psw->pr_input) {
+ esw = match->esw;
+ if (esw && esw->en_input) {
+ /* XXX IPv6 cast, eliminate me */
+ int (*input)(struct mbuf **, int *, int) =
+ (int (*)(struct mbuf **, int *, int))esw->en_input;
encap_fillarg(m, match);
- return (*psw->pr_input)(mp, offp, proto);
+ return (*input)(mp, offp, proto);
} else {
m_freem(m);
return IPPROTO_DONE;
@@ -431,7 +434,7 @@
encap_attach(int af, int proto,
const struct sockaddr *sp, const struct sockaddr *sm,
const struct sockaddr *dp, const struct sockaddr *dm,
- const struct protosw *psw, void *arg)
+ const struct encapsw *esw, void *arg)
{
struct encaptab *ep;
int error;
@@ -534,7 +537,7 @@
memcpy(ep->srcmask, sm, sp->sa_len);
memcpy(ep->dst, dp, dp->sa_len);
memcpy(ep->dstmask, dm, dp->sa_len);
- ep->psw = psw;
+ ep->esw = esw;
ep->arg = arg;
error = encap_add(ep);
@@ -560,7 +563,7 @@
const struct encaptab *
encap_attach_func(int af, int proto,
int (*func)(struct mbuf *, int, int, void *),
- const struct protosw *psw, void *arg)
+ const struct encapsw *esw, void *arg)
{
struct encaptab *ep;
int error;
@@ -587,7 +590,7 @@
ep->af = af;
ep->proto = proto;
ep->func = func;
- ep->psw = psw;
+ ep->esw = esw;
ep->arg = arg;
error = encap_add(ep);
@@ -616,7 +619,7 @@
struct ip6ctlparam *ip6cp = NULL;
int nxt;
struct encaptab *ep;
- const struct ip6protosw *psw;
+ const struct encapsw *esw;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
@@ -675,9 +678,9 @@
/* should optimize by looking at address pairs */
/* XXX need to pass ep->arg or ep itself to listeners */
- psw = (const struct ip6protosw *)ep->psw;
- if (psw && psw->pr_ctlinput)
- (*psw->pr_ctlinput)(cmd, sa, d);
+ esw = ep->esw;
+ if (esw && esw->en_ctlinput)
+ (*esw->en_ctlinput)(cmd, sa, d);
}
rip6_ctlinput(cmd, sa, d0);
--- src/sys/netinet/ip_encap.h 2008/11/25 18:28:05 1.13
+++ src/sys/netinet/ip_encap.h 2016/01/22 05:15:10 1.14
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_encap.h,v 1.13 2008/11/25 18:28:05 pooka Exp $ */
+/* $NetBSD: ip_encap.h,v 1.14 2016/01/22 05:15:10 riastradh Exp $ */
/* $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $ */
/*
@@ -39,6 +39,11 @@
#include <net/radix.h>
#endif
+struct encapsw {
+ void (*en_input)(struct mbuf *, ...);
+ void *(*en_ctlinput)(int, const struct sockaddr *, void *);
+};
+
struct encaptab {
struct radix_node nodes[2];
LIST_ENTRY(encaptab) chain;
@@ -51,7 +56,7 @@
struct sockaddr *dst; /* remote addr */
struct sockaddr *dstmask;
int (*func) (struct mbuf *, int, int, void *);
- const struct protosw *psw; /* only pr_input will be used */
+ const struct encapsw *esw;
void *arg; /* passed via PACKET_TAG_ENCAP */
};
@@ -78,10 +83,10 @@
int encap6_input(struct mbuf **, int *, int);
const struct encaptab *encap_attach(int, int, const struct sockaddr *,
const struct sockaddr *, const struct sockaddr *,
- const struct sockaddr *, const struct protosw *, void *);
+ const struct sockaddr *, const struct encapsw *, void *);
const struct encaptab *encap_attach_func(int, int,
int (*)(struct mbuf *, int, int, void *),
- const struct protosw *, void *);
+ const struct encapsw *, void *);
void *encap6_ctlinput(int, const struct sockaddr *, void *);
int encap_detach(const struct encaptab *);
void *encap_getarg(struct mbuf *);
--- src/sys/netinet/ip_mroute.c 2016/01/20 21:43:59 1.134
+++ src/sys/netinet/ip_mroute.c 2016/01/22 05:15:10 1.135
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_mroute.c,v 1.134 2016/01/20 21:43:59 riastradh Exp $ */
+/* $NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.134 2016/01/20 21:43:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -193,14 +193,9 @@
static void vif_input(struct mbuf *, ...);
static int vif_encapcheck(struct mbuf *, int, int, void *);
-static const struct protosw vif_protosw = {
- .pr_type = SOCK_RAW,
- .pr_domain = &inetdomain,
- .pr_protocol = IPPROTO_IPV4,
- .pr_flags = PR_ATOMIC|PR_ADDR,
- .pr_input = vif_input,
- .pr_ctloutput = rip_ctloutput,
- .pr_usrreqs = &rip_usrreqs,
+static const struct encapsw vif_encapsw = {
+ .en_input = vif_input,
+ .en_ctlinput = NULL,
};
#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
@@ -837,7 +832,7 @@
* function to check, and this is not supported yet.
*/
vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
- vif_encapcheck, &vif_protosw, vifp);
+ vif_encapcheck, &vif_encapsw, vifp);
if (!vifp->v_encap_cookie)
return (EINVAL);
--- src/sys/netinet6/in6_gif.c 2016/01/20 21:44:00 1.66
+++ src/sys/netinet6/in6_gif.c 2016/01/22 05:15:10 1.67
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_gif.c,v 1.66 2016/01/20 21:44:00 riastradh Exp $ */
+/* $NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $ */
/* $KAME: in6_gif.c,v 1.62 2001/07/29 04:27:25 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.66 2016/01/20 21:44:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -46,7 +46,6 @@
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/syslog.h>
-#include <sys/protosw.h>
#include <sys/kernel.h>
#include <net/if.h>
@@ -64,8 +63,8 @@
#include <netinet6/ip6_private.h>
#include <netinet6/in6_gif.h>
#include <netinet6/in6_var.h>
-#endif
#include <netinet6/ip6protosw.h>
+#endif
#include <netinet/ip_ecn.h>
#include <net/if_gif.h>
@@ -79,7 +78,7 @@
extern LIST_HEAD(, gif_softc) gif_softc_list;
-static const struct ip6protosw in6_gif_protosw;
+static const struct encapsw in6_gif_encapsw;
/*
* family - family of the packet to be encapsulate.
@@ -374,10 +373,10 @@
return EINVAL;
sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc,
(struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6,
- (const void *)&in6_gif_protosw, sc);
+ &in6_gif_encapsw, sc);
#else
sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck,
- (struct protosw *)&in6_gif_protosw, sc);
+ &in6_gif_encapsw, sc);
#endif
if (sc->encap_cookie6 == NULL)
return EEXIST;
@@ -451,20 +450,10 @@
}
PR_WRAP_CTLINPUT(in6_gif_ctlinput)
-PR_WRAP_CTLOUTPUT(rip6_ctloutput)
#define in6_gif_ctlinput in6_gif_ctlinput_wrapper
-#define rip6_ctloutput rip6_ctloutput_wrapper
-extern struct domain inet6domain;
-
-static const struct ip6protosw in6_gif_protosw = {
- .pr_type = SOCK_RAW,
- .pr_domain = &inet6domain,
- .pr_protocol = 0 /* IPPROTO_IPV[46] */,
- .pr_flags = PR_ATOMIC | PR_ADDR,
- .pr_input = in6_gif_input,
- .pr_ctlinput = in6_gif_ctlinput,
- .pr_ctloutput = rip6_ctloutput,
- .pr_usrreqs = &rip6_usrreqs,
+static const struct encapsw in6_gif_encapsw = {
+ .en_input = (void (*)(struct mbuf *, ...))in6_gif_input,
+ .en_ctlinput = in6_gif_ctlinput,
};
--- src/sys/netipsec/xform_ipip.c 2016/01/20 21:44:00 1.33
+++ src/sys/netipsec/xform_ipip.c 2016/01/22 05:15:10 1.34
@@ -1,4 +1,4 @@
-/* $NetBSD: xform_ipip.c,v 1.33 2016/01/20 21:44:00 riastradh Exp $ */
+/* $NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $ */
/* $FreeBSD: src/sys/netipsec/xform_ipip.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */
/* $OpenBSD: ip_ipip.c,v 1.25 2002/06/10 18:04:55 itojun Exp $ */
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.33 2016/01/20 21:44:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $");
/*
* IP-inside-IP processing
@@ -56,7 +56,6 @@
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/kernel.h>
-#include <sys/protosw.h>
#include <sys/sysctl.h>
#include <net/if.h>
@@ -70,9 +69,6 @@
#include <netinet/ip_ecn.h>
#include <netinet/ip_var.h>
#include <netinet/ip_encap.h>
-#ifdef __FreeBSD__
-#include <netinet/ipprotosw.h>
-#endif
#include <netipsec/ipsec.h>
#include <netipsec/ipsec_private.h>
@@ -91,7 +87,6 @@
# include <netinet6/ip6_ecn.h>
# endif
#include <netinet6/in6_var.h>
-#include <netinet6/ip6protosw.h>
#endif
#include <netipsec/key.h>
@@ -682,43 +677,15 @@
};
#ifdef INET
-PR_WRAP_CTLOUTPUT(rip_ctloutput)
-#define rip_ctloutput rip_ctloutput_wrapper
-
-extern struct domain inetdomain;
-static struct ipprotosw ipe4_protosw = {
- .pr_type = SOCK_RAW,
- .pr_domain = &inetdomain,
- .pr_protocol = IPPROTO_IPV4,
- .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
- .pr_input = ip4_input,
- .pr_ctlinput = 0,
- .pr_ctloutput = rip_ctloutput,
- .pr_usrreqs = &rip_usrreqs,
- .pr_init = 0,
- .pr_fasttimo = 0,
- .pr_slowtimo = 0,
- .pr_drain = 0,
+static const struct encapsw ipe4_encapsw = {
+ .en_input = ip4_input,
+ .en_ctlinput = NULL,
};
#endif
#ifdef INET6
-PR_WRAP_CTLOUTPUT(rip6_ctloutput)
-#define rip6_ctloutput rip6_ctloutput_wrapper
-
-extern struct domain inet6domain;
-static struct ip6protosw ipe4_protosw6 = {
- .pr_type = SOCK_RAW,
- .pr_domain = &inet6domain,
- .pr_protocol = IPPROTO_IPV6,
- .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
- .pr_input = ip4_input6,
- .pr_ctlinput = 0,
- .pr_ctloutput = rip6_ctloutput,
- .pr_usrreqs = &rip6_usrreqs,
- .pr_init = 0,
- .pr_fasttimo = 0,
- .pr_slowtimo = 0,
- .pr_drain = 0,
+static const struct encapsw ipe4_encapsw6 = {
+ .en_input = (void (*)(struct mbuf *, ...))ip4_input6,
+ .en_ctlinput = NULL,
};
#endif
@@ -752,11 +719,11 @@
/* XXX save return cookie for detach on module remove */
#ifdef INET
(void) encap_attach_func(AF_INET, -1,
- ipe4_encapcheck, (struct protosw*) &ipe4_protosw, NULL);
+ ipe4_encapcheck, &ipe4_encapsw, NULL);
#endif
#ifdef INET6
(void) encap_attach_func(AF_INET6, -1,
- ipe4_encapcheck, (struct protosw*) &ipe4_protosw6, NULL);
+ ipe4_encapcheck, &ipe4_encapsw6, NULL);
#endif
}