Source-Changes-HG archive

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

[src/trunk]: src/sys Back out previous change to introduce struct encapsw.



details:   https://anonhg.NetBSD.org/src/rev/86c0cde23427
branches:  trunk
changeset: 343107:86c0cde23427
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jan 22 23:27:12 2016 +0000

description:
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.

diffstat:

 sys/net/if_stf.c          |  22 ++++++++++++++-----
 sys/netinet/in_gif.c      |  32 ++++++++++++++++++++-------
 sys/netinet/ip_encap.c    |  39 +++++++++++++++------------------
 sys/netinet/ip_encap.h    |  13 +++-------
 sys/netinet/ip_mroute.c   |  17 +++++++++-----
 sys/netinet6/in6_gif.c    |  40 +++++++++++++++++++++++++---------
 sys/netipsec/xform_ipip.c |  53 ++++++++++++++++++++++++++++++++++++++--------
 7 files changed, 144 insertions(+), 72 deletions(-)

diffs (truncated from 569 to 300 lines):

diff -r 45c11b812419 -r 86c0cde23427 sys/net/if_stf.c
--- a/sys/net/if_stf.c  Fri Jan 22 23:25:51 2016 +0000
+++ b/sys/net/if_stf.c  Fri Jan 22 23:27:12 2016 +0000
@@ -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 @@
 #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 @@
 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 @@
        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);
diff -r 45c11b812419 -r 86c0cde23427 sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Fri Jan 22 23:25:51 2016 +0000
+++ b/sys/netinet/in_gif.c      Fri Jan 22 23:27:12 2016 +0000
@@ -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 @@
 #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 = 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 @@
                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 @@
 }
 
 int
-in_gif_detach(struct gif_softc *sc)
+in_gif_pause(struct gif_softc *sc)
 {
        int error;
 
@@ -393,7 +400,14 @@
        if (error == 0)
                sc->encap_cookie4 = NULL;
 
+       return error;
+}
+
+int
+in_gif_detach(struct gif_softc *sc)
+{
+
        rtcache_free(&sc->gif_ro);
 
-       return error;
+       return 0;
 }
diff -r 45c11b812419 -r 86c0cde23427 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Fri Jan 22 23:25:51 2016 +0000
+++ b/sys/netinet/ip_encap.c    Fri Jan 22 23:27:12 2016 +0000
@@ -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 @@
 {
        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 @@
 
        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 @@
 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 @@
 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 @@
        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 @@
 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 @@
        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 @@
        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 @@
                /* 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);
diff -r 45c11b812419 -r 86c0cde23427 sys/netinet/ip_encap.h
--- a/sys/netinet/ip_encap.h    Fri Jan 22 23:25:51 2016 +0000
+++ b/sys/netinet/ip_encap.h    Fri Jan 22 23:27:12 2016 +0000
@@ -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 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 @@
 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 *);



Home | Main Index | Thread Index | Old Index