Source-Changes-HG archive

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

[src/trunk]: src/sys Don't abuse struct protosw for ip_encap -- introduce str...



details:   https://anonhg.NetBSD.org/src/rev/aa8f123d6ea4
branches:  trunk
changeset: 343068:aa8f123d6ea4
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jan 22 05:15:10 2016 +0000

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

diffstat:

 sys/net/if_stf.c          |  22 +++++--------------
 sys/netinet/in_gif.c      |  21 ++++++------------
 sys/netinet/ip_encap.c    |  39 ++++++++++++++++++---------------
 sys/netinet/ip_encap.h    |  13 +++++++---
 sys/netinet/ip_mroute.c   |  17 +++++---------
 sys/netinet6/in6_gif.c    |  29 +++++++-----------------
 sys/netipsec/xform_ipip.c |  53 ++++++++--------------------------------------
 7 files changed, 68 insertions(+), 126 deletions(-)

diffs (truncated from 517 to 300 lines):

diff -r 5f03dce58d44 -r aa8f123d6ea4 sys/net/if_stf.c
--- a/sys/net/if_stf.c  Fri Jan 22 04:26:01 2016 +0000
+++ b/sys/net/if_stf.c  Fri Jan 22 05:15:10 2016 +0000
@@ -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);
diff -r 5f03dce58d44 -r aa8f123d6ea4 sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Fri Jan 22 04:26:01 2016 +0000
+++ b/sys/netinet/in_gif.c      Fri Jan 22 05:15:10 2016 +0000
@@ -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;
diff -r 5f03dce58d44 -r aa8f123d6ea4 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Fri Jan 22 04:26:01 2016 +0000
+++ b/sys/netinet/ip_encap.c    Fri Jan 22 05:15:10 2016 +0000
@@ -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);
diff -r 5f03dce58d44 -r aa8f123d6ea4 sys/netinet/ip_encap.h
--- a/sys/netinet/ip_encap.h    Fri Jan 22 04:26:01 2016 +0000
+++ b/sys/netinet/ip_encap.h    Fri Jan 22 05:15:10 2016 +0000
@@ -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 *);
diff -r 5f03dce58d44 -r aa8f123d6ea4 sys/netinet/ip_mroute.c
--- a/sys/netinet/ip_mroute.c   Fri Jan 22 04:26:01 2016 +0000
+++ b/sys/netinet/ip_mroute.c   Fri Jan 22 05:15:10 2016 +0000
@@ -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"



Home | Main Index | Thread Index | Old Index