Back out previous change to introduce struct encapsw.

This change was intended, but Nakahara-san had already made a better
one locally!  So I'll let him commit that one, and I'll try not to
step on anyone's toes again.
This commit is contained in:
riastradh 2016-01-22 23:27:12 +00:00
parent e9e4a6c4b0
commit e588d95c25
7 changed files with 145 additions and 73 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: if_stf.c,v 1.85 2016/01/22 23:27:12 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.84 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.85 2016/01/22 23:27:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -93,6 +93,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $"
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/queue.h>
#include <sys/syslog.h>
@ -155,9 +156,18 @@ extern int ip_gif_ttl; /*XXX*/
static int ip_gif_ttl = 40; /*XXX*/
#endif
static const struct encapsw in_stf_encapsw = {
.en_input = in_stf_input,
.en_ctlinput = NULL,
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 int stf_encapcheck(struct mbuf *, int, int, void *);
@ -196,7 +206,7 @@ stf_clone_create(struct if_clone *ifc, int unit)
if_initname(&sc->sc_if, ifc->ifc_name, unit);
sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
stf_encapcheck, &in_stf_encapsw, sc);
stf_encapcheck, &in_stf_protosw, sc);
if (sc->encap_cookie == NULL) {
printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
free(sc, M_DEVBUF);

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: in_gif.c,v 1.71 2016/01/22 23:27:12 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.70 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.71 2016/01/22 23:27:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $"
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
#include <sys/protosw.h>
#include <sys/kernel.h>
#include <net/if.h>
@ -78,9 +79,15 @@ int ip_gif_ttl = GIF_TTL;
int ip_gif_ttl = 0;
#endif
static const struct encapsw in_gif_encapsw = {
.en_input = in_gif_input,
.en_ctlinput = NULL,
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,
};
int
@ -374,10 +381,10 @@ in_gif_attach(struct gif_softc *sc)
return EINVAL;
sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
(struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
&in_gif_encapsw, sc);
(const struct protosw *)&in_gif_protosw, sc);
#else
sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
&in_gif_encapsw, sc);
&in_gif_protosw, sc);
#endif
if (sc->encap_cookie4 == NULL)
return EEXIST;
@ -385,7 +392,7 @@ in_gif_attach(struct gif_softc *sc)
}
int
in_gif_detach(struct gif_softc *sc)
in_gif_pause(struct gif_softc *sc)
{
int error;
@ -393,7 +400,14 @@ in_gif_detach(struct gif_softc *sc)
if (error == 0)
sc->encap_cookie4 = NULL;
rtcache_free(&sc->gif_ro);
return error;
}
int
in_gif_detach(struct gif_softc *sc)
{
rtcache_free(&sc->gif_ro);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: ip_encap.c,v 1.50 2016/01/22 23:27:12 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.49 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.50 2016/01/22 23:27:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@ -240,7 +240,7 @@ encap4_input(struct mbuf *m, ...)
{
int off, proto;
va_list ap;
const struct encapsw *esw;
const struct protosw *psw;
struct encaptab *match;
va_start(ap, m);
@ -252,10 +252,10 @@ encap4_input(struct mbuf *m, ...)
if (match) {
/* found a match, "match" has the best one */
esw = match->esw;
if (esw && esw->en_input) {
psw = match->psw;
if (psw && psw->pr_input) {
encap_fillarg(m, match);
(*esw->en_input)(m, off, proto);
(*psw->pr_input)(m, off, proto);
} else
m_freem(m);
return;
@ -329,20 +329,17 @@ int
encap6_input(struct mbuf **mp, int *offp, int proto)
{
struct mbuf *m = *mp;
const struct encapsw *esw;
const struct ip6protosw *psw;
struct encaptab *match;
match = encap6_lookup(m, *offp, proto, INBOUND);
if (match) {
/* found a match */
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;
psw = (const struct ip6protosw *)match->psw;
if (psw && psw->pr_input) {
encap_fillarg(m, match);
return (*input)(mp, offp, proto);
return (*psw->pr_input)(mp, offp, proto);
} else {
m_freem(m);
return IPPROTO_DONE;
@ -434,7 +431,7 @@ const struct encaptab *
encap_attach(int af, int proto,
const struct sockaddr *sp, const struct sockaddr *sm,
const struct sockaddr *dp, const struct sockaddr *dm,
const struct encapsw *esw, void *arg)
const struct protosw *psw, void *arg)
{
struct encaptab *ep;
int error;
@ -537,7 +534,7 @@ encap_attach(int af, int proto,
memcpy(ep->srcmask, sm, sp->sa_len);
memcpy(ep->dst, dp, dp->sa_len);
memcpy(ep->dstmask, dm, dp->sa_len);
ep->esw = esw;
ep->psw = psw;
ep->arg = arg;
error = encap_add(ep);
@ -563,7 +560,7 @@ fail:
const struct encaptab *
encap_attach_func(int af, int proto,
int (*func)(struct mbuf *, int, int, void *),
const struct encapsw *esw, void *arg)
const struct protosw *psw, void *arg)
{
struct encaptab *ep;
int error;
@ -590,7 +587,7 @@ encap_attach_func(int af, int proto,
ep->af = af;
ep->proto = proto;
ep->func = func;
ep->esw = esw;
ep->psw = psw;
ep->arg = arg;
error = encap_add(ep);
@ -619,7 +616,7 @@ encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0)
struct ip6ctlparam *ip6cp = NULL;
int nxt;
struct encaptab *ep;
const struct encapsw *esw;
const struct ip6protosw *psw;
if (sa->sa_family != AF_INET6 ||
sa->sa_len != sizeof(struct sockaddr_in6))
@ -678,9 +675,9 @@ encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0)
/* should optimize by looking at address pairs */
/* XXX need to pass ep->arg or ep itself to listeners */
esw = ep->esw;
if (esw && esw->en_ctlinput)
(*esw->en_ctlinput)(cmd, sa, d);
psw = (const struct ip6protosw *)ep->psw;
if (psw && psw->pr_ctlinput)
(*psw->pr_ctlinput)(cmd, sa, d);
}
rip6_ctlinput(cmd, sa, d0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_encap.h,v 1.14 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: ip_encap.h,v 1.15 2016/01/22 23:27:12 riastradh Exp $ */
/* $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $ */
/*
@ -39,11 +39,6 @@
#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;
@ -56,7 +51,7 @@ struct encaptab {
struct sockaddr *dst; /* remote addr */
struct sockaddr *dstmask;
int (*func) (struct mbuf *, int, int, void *);
const struct encapsw *esw;
const struct protosw *psw; /* only pr_input will be used */
void *arg; /* passed via PACKET_TAG_ENCAP */
};
@ -83,10 +78,10 @@ void encap4_input(struct mbuf *, ...);
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 encapsw *, void *);
const struct sockaddr *, const struct protosw *, void *);
const struct encaptab *encap_attach_func(int, int,
int (*)(struct mbuf *, int, int, void *),
const struct encapsw *, void *);
const struct protosw *, void *);
void *encap6_ctlinput(int, const struct sockaddr *, void *);
int encap_detach(const struct encaptab *);
void *encap_getarg(struct mbuf *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: ip_mroute.c,v 1.136 2016/01/22 23:27:12 riastradh Exp $ */
/*
* Copyright (c) 1992, 1993
@ -93,7 +93,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.136 2016/01/22 23:27:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -193,9 +193,14 @@ extern int rsvp_on;
static void vif_input(struct mbuf *, ...);
static int vif_encapcheck(struct mbuf *, int, int, void *);
static const struct encapsw vif_encapsw = {
.en_input = vif_input,
.en_ctlinput = NULL,
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,
};
#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
@ -832,7 +837,7 @@ add_vif(struct vifctl *vifcp)
* function to check, and this is not supported yet.
*/
vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
vif_encapcheck, &vif_encapsw, vifp);
vif_encapcheck, &vif_protosw, vifp);
if (!vifp->v_encap_cookie)
return (EINVAL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: in6_gif.c,v 1.68 2016/01/22 23:27:12 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.67 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.68 2016/01/22 23:27:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/syslog.h>
#include <sys/protosw.h>
#include <sys/kernel.h>
#include <net/if.h>
@ -63,8 +64,8 @@ __KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $
#include <netinet6/ip6_private.h>
#include <netinet6/in6_gif.h>
#include <netinet6/in6_var.h>
#include <netinet6/ip6protosw.h>
#endif
#include <netinet6/ip6protosw.h>
#include <netinet/ip_ecn.h>
#include <net/if_gif.h>
@ -78,7 +79,7 @@ int ip6_gif_hlim = GIF_HLIM;
extern LIST_HEAD(, gif_softc) gif_softc_list;
static const struct encapsw in6_gif_encapsw;
static const struct ip6protosw in6_gif_protosw;
/*
* family - family of the packet to be encapsulate.
@ -373,10 +374,10 @@ in6_gif_attach(struct gif_softc *sc)
return EINVAL;
sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc,
(struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6,
&in6_gif_encapsw, sc);
(const void *)&in6_gif_protosw, sc);
#else
sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck,
&in6_gif_encapsw, sc);
(struct protosw *)&in6_gif_protosw, sc);
#endif
if (sc->encap_cookie6 == NULL)
return EEXIST;
@ -384,7 +385,7 @@ in6_gif_attach(struct gif_softc *sc)
}
int
in6_gif_detach(struct gif_softc *sc)
in6_gif_pause(struct gif_softc *sc)
{
int error;
@ -392,9 +393,16 @@ in6_gif_detach(struct gif_softc *sc)
if (error == 0)
sc->encap_cookie6 = NULL;
return error;
}
int
in6_gif_detach(struct gif_softc *sc)
{
rtcache_free(&sc->gif_ro);
return error;
return 0;
}
void *
@ -450,10 +458,20 @@ in6_gif_ctlinput(int cmd, const struct sockaddr *sa, void *d)
}
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
static const struct encapsw in6_gif_encapsw = {
.en_input = (void (*)(struct mbuf *, ...))in6_gif_input,
.en_ctlinput = in6_gif_ctlinput,
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,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $ */
/* $NetBSD: xform_ipip.c,v 1.35 2016/01/22 23:27:12 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.34 2016/01/22 05:15:10 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.35 2016/01/22 23:27:12 riastradh Exp $");
/*
* IP-inside-IP processing
@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Ex
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/kernel.h>
#include <sys/protosw.h>
#include <sys/sysctl.h>
#include <net/if.h>
@ -69,6 +70,9 @@ __KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Ex
#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>
@ -87,6 +91,7 @@ __KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Ex
# include <netinet6/ip6_ecn.h>
# endif
#include <netinet6/in6_var.h>
#include <netinet6/ip6protosw.h>
#endif
#include <netipsec/key.h>
@ -677,15 +682,43 @@ static struct xformsw ipe4_xformsw = {
};
#ifdef INET
static const struct encapsw ipe4_encapsw = {
.en_input = ip4_input,
.en_ctlinput = NULL,
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,
};
#endif
#ifdef INET6
static const struct encapsw ipe4_encapsw6 = {
.en_input = (void (*)(struct mbuf *, ...))ip4_input6,
.en_ctlinput = NULL,
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,
};
#endif
@ -719,11 +752,11 @@ ipe4_attach(void)
/* XXX save return cookie for detach on module remove */
#ifdef INET
(void) encap_attach_func(AF_INET, -1,
ipe4_encapcheck, &ipe4_encapsw, NULL);
ipe4_encapcheck, (struct protosw*) &ipe4_protosw, NULL);
#endif
#ifdef INET6
(void) encap_attach_func(AF_INET6, -1,
ipe4_encapcheck, &ipe4_encapsw6, NULL);
ipe4_encapcheck, (struct protosw*) &ipe4_protosw6, NULL);
#endif
}