Source-Changes-HG archive

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

[src/trunk]: src/sys implement encapsw instead of protosw and uniform prototype.



details:   https://anonhg.NetBSD.org/src/rev/8cc3e6466a03
branches:  trunk
changeset: 343240:8cc3e6466a03
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Tue Jan 26 05:58:05 2016 +0000

description:
implement encapsw instead of protosw and uniform prototype.

suggested and advised by riastradh@n.o, thanks.

BTW, It seems in_stf_input() had bugs...

diffstat:

 sys/net/if_stf.c          |  47 ++++++++++++++++++------------------------
 sys/net/if_stf.h          |   4 +-
 sys/netinet/in_gif.c      |  23 ++++++++------------
 sys/netinet/ip_encap.c    |  40 ++++++++++++++++++------------------
 sys/netinet/ip_encap.h    |  28 +++++++++++++++++++++---
 sys/netinet/ip_mroute.c   |  19 +++++++---------
 sys/netinet6/in6_gif.c    |  32 +++++++++------------------
 sys/netipsec/xform_ipip.c |  52 ++++++++++++----------------------------------
 8 files changed, 108 insertions(+), 137 deletions(-)

diffs (truncated from 625 to 300 lines):

diff -r 11201223e639 -r 8cc3e6466a03 sys/net/if_stf.c
--- a/sys/net/if_stf.c  Tue Jan 26 02:54:25 2016 +0000
+++ b/sys/net/if_stf.c  Tue Jan 26 05:58:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_stf.c,v 1.85 2016/01/22 23:27:12 riastradh Exp $    */
+/*     $NetBSD: if_stf.c,v 1.86 2016/01/26 05:58:05 knakahara 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.85 2016/01/22 23:27:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.86 2016/01/26 05:58:05 knakahara 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>
 
@@ -158,16 +157,12 @@
 
 extern struct domain inetdomain;
 
-static const struct protosw in_stf_protosw =
+static const struct encapsw in_stf_encapsw =
 {
-       .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,
+       .encapsw6 = {
+               .pr_input       = in_stf_input,
+               .pr_ctlinput    = NULL,
+       }
 };
 
 static int stf_encapcheck(struct mbuf *, int, int, void *);
@@ -206,7 +201,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);
@@ -557,26 +552,22 @@
        return 0;
 }
 
-void
-in_stf_input(struct mbuf *m, ...)
+int
+in_stf_input(struct mbuf **mp, int *offp, int proto)
 {
-       int s, off, proto;
+       int s;
        struct stf_softc *sc;
        struct ip *ip;
        struct ip6_hdr *ip6;
        uint8_t otos, itos;
        struct ifnet *ifp;
        size_t pktlen;
-       va_list ap;
-
-       va_start(ap, m);
-       off = va_arg(ap, int);
-       proto = va_arg(ap, int);
-       va_end(ap);
+       int off = *offp;
+       struct mbuf *m = *mp;
 
        if (proto != IPPROTO_IPV6) {
                m_freem(m);
-               return;
+               return IPPROTO_DONE;
        }
 
        ip = mtod(m, struct ip *);
@@ -585,7 +576,7 @@
 
        if (sc == NULL || (sc->sc_if.if_flags & IFF_UP) == 0) {
                m_freem(m);
-               return;
+               return IPPROTO_DONE;
        }
 
        ifp = &sc->sc_if;
@@ -597,7 +588,7 @@
        if (stf_checkaddr4(sc, &ip->ip_dst, NULL) < 0 ||
            stf_checkaddr4(sc, &ip->ip_src, m->m_pkthdr.rcvif) < 0) {
                m_freem(m);
-               return;
+               return IPPROTO_DONE;
        }
 
        otos = ip->ip_tos;
@@ -606,7 +597,7 @@
        if (m->m_len < sizeof(*ip6)) {
                m = m_pullup(m, sizeof(*ip6));
                if (!m)
-                       return;
+                       return IPPROTO_DONE;
        }
        ip6 = mtod(m, struct ip6_hdr *);
 
@@ -617,7 +608,7 @@
        if (stf_checkaddr6(sc, &ip6->ip6_dst, NULL) < 0 ||
            stf_checkaddr6(sc, &ip6->ip6_src, m->m_pkthdr.rcvif) < 0) {
                m_freem(m);
-               return;
+               return IPPROTO_DONE;
        }
 
        itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
@@ -648,6 +639,8 @@
                m_freem(m);
        }
        splx(s);
+
+       return IPPROTO_DONE;
 }
 
 /* ARGSUSED */
diff -r 11201223e639 -r 8cc3e6466a03 sys/net/if_stf.h
--- a/sys/net/if_stf.h  Tue Jan 26 02:54:25 2016 +0000
+++ b/sys/net/if_stf.h  Tue Jan 26 05:58:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_stf.h,v 1.4 2005/12/11 23:05:25 thorpej Exp $       */
+/*     $NetBSD: if_stf.h,v 1.5 2016/01/26 05:58:05 knakahara Exp $     */
 /*     $KAME: if_stf.h,v 1.3 2000/03/25 07:23:33 sumikawa Exp $        */
 
 /*
@@ -37,6 +37,6 @@
 #define        STF_MTU_MIN     (1280)  /* Minimum MTU */
 #define        STF_MTU_MAX     (8192)  /* Maximum MTU */
 
-void   in_stf_input(struct mbuf *, ...);
+int    in_stf_input(struct mbuf **, int *, int);
 
 #endif /* !_NET_IF_STF_H_ */
diff -r 11201223e639 -r 8cc3e6466a03 sys/netinet/in_gif.c
--- a/sys/netinet/in_gif.c      Tue Jan 26 02:54:25 2016 +0000
+++ b/sys/netinet/in_gif.c      Tue Jan 26 05:58:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_gif.c,v 1.73 2016/01/23 14:48:55 riastradh Exp $    */
+/*     $NetBSD: in_gif.c,v 1.74 2016/01/26 05:58:05 knakahara 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.73 2016/01/23 14:48:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.74 2016/01/26 05:58:05 knakahara 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,11 @@
 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 = {
+       .encapsw4 = {
+               .pr_input       = in_gif_input,
+               .pr_ctlinput    = NULL,
+       }
 };
 
 int
@@ -381,10 +376,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 11201223e639 -r 8cc3e6466a03 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Tue Jan 26 02:54:25 2016 +0000
+++ b/sys/netinet/ip_encap.c    Tue Jan 26 05:58:05 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_encap.c,v 1.50 2016/01/22 23:27:12 riastradh Exp $  */
+/*     $NetBSD: ip_encap.c,v 1.51 2016/01/26 05:58:05 knakahara 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.50 2016/01/22 23:27:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.51 2016/01/26 05:58:05 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -80,7 +80,6 @@
 #include <sys/sockio.h>
 #include <sys/mbuf.h>
 #include <sys/errno.h>
-#include <sys/protosw.h>
 #include <sys/queue.h>
 #include <sys/kmem.h>
 
@@ -99,7 +98,7 @@
 #ifdef INET6
 #include <netinet/ip6.h>
 #include <netinet6/ip6_var.h>
-#include <netinet6/ip6protosw.h>
+#include <netinet6/ip6protosw.h> /* for struct ip6ctlparam */
 #include <netinet6/in6_var.h>
 #include <netinet6/in6_pcb.h>
 #include <netinet/icmp6.h>
@@ -240,7 +239,7 @@
 {
        int off, proto;
        va_list ap;
-       const struct protosw *psw;
+       const struct encapsw *esw;
        struct encaptab *match;
 
        va_start(ap, m);
@@ -252,10 +251,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->encapsw4.pr_input) {
                        encap_fillarg(m, match);
-                       (*psw->pr_input)(m, off, proto);
+                       (*esw->encapsw4.pr_input)(m, off, proto);
                } else
                        m_freem(m);
                return;
@@ -329,17 +328,17 @@
 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->encapsw6.pr_input) {
                        encap_fillarg(m, match);
-                       return (*psw->pr_input)(mp, offp, proto);
+                       return (*esw->encapsw6.pr_input)(mp, offp, proto);
                } else {
                        m_freem(m);
                        return IPPROTO_DONE;
@@ -431,7 +430,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;



Home | Main Index | Thread Index | Old Index