Source-Changes-HG archive

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

[src/trunk]: src/sys To eliminate gif_softc_list linear search, add extra arg...



details:   https://anonhg.NetBSD.org/src/rev/423ee163b674
branches:  trunk
changeset: 343767:423ee163b674
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Fri Feb 26 07:35:17 2016 +0000

description:
To eliminate gif_softc_list linear search, add extra argument to encapsw.pr_ctlinput().

diffstat:

 sys/net/if_gif.c       |   6 +++---
 sys/netinet/ip_encap.c |   6 +++---
 sys/netinet/ip_encap.h |  24 +++++++++++++++++++-----
 sys/netinet6/in6_gif.c |  39 +++++++++++++++------------------------
 sys/netinet6/in6_gif.h |   4 ++--
 5 files changed, 42 insertions(+), 37 deletions(-)

diffs (200 lines):

diff -r 153db49ca671 -r 423ee163b674 sys/net/if_gif.c
--- a/sys/net/if_gif.c  Thu Feb 25 17:09:39 2016 +0000
+++ b/sys/net/if_gif.c  Fri Feb 26 07:35:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.c,v 1.105 2016/01/18 06:08:26 knakahara Exp $   */
+/*     $NetBSD: if_gif.c,v 1.106 2016/02/26 07:35:17 knakahara Exp $   */
 /*     $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $    */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.105 2016/01/18 06:08:26 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.106 2016/02/26 07:35:17 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -90,7 +90,7 @@
 /*
  * gif global variable definitions
  */
-LIST_HEAD(, gif_softc) gif_softc_list; /* XXX should be static */
+static LIST_HEAD(, gif_softc) gif_softc_list;
 
 static void    gif_sysctl_setup(struct sysctllog **);
 
diff -r 153db49ca671 -r 423ee163b674 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Thu Feb 25 17:09:39 2016 +0000
+++ b/sys/netinet/ip_encap.c    Fri Feb 26 07:35:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_encap.c,v 1.51 2016/01/26 05:58:05 knakahara Exp $  */
+/*     $NetBSD: ip_encap.c,v 1.52 2016/02/26 07:35:17 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.51 2016/01/26 05:58:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.52 2016/02/26 07:35:17 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -676,7 +676,7 @@
                /* XXX need to pass ep->arg or ep itself to listeners */
                esw = ep->esw;
                if (esw && esw->encapsw6.pr_ctlinput) {
-                       (*esw->encapsw6.pr_ctlinput)(cmd, sa, d);
+                       (*esw->encapsw6.pr_ctlinput)(cmd, sa, d, ep->arg);
                }
        }
 
diff -r 153db49ca671 -r 423ee163b674 sys/netinet/ip_encap.h
--- a/sys/netinet/ip_encap.h    Thu Feb 25 17:09:39 2016 +0000
+++ b/sys/netinet/ip_encap.h    Fri Feb 26 07:35:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_encap.h,v 1.17 2016/01/26 06:00:10 knakahara Exp $  */
+/*     $NetBSD: ip_encap.h,v 1.18 2016/02/26 07:35:17 knakahara Exp $  */
 /*     $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $      */
 
 /*
@@ -44,14 +44,14 @@
                struct encapsw4 {
                        void    (*pr_input)     /* input to protocol (from below) */
                                (struct mbuf *, int, int);
-                       void    *(*pr_ctlinput) /* control input (from below) */
-                               (int, const struct sockaddr *, void *);
+                       void    *(*pr_ctlinput)         /* control input (from below) */
+                               (int, const struct sockaddr *, void *, void *);
                } _encapsw4;
                struct encapsw6 {
                        int     (*pr_input)     /* input to protocol (from below) */
                                (struct mbuf **, int *, int);
-                       void    *(*pr_ctlinput) /* control input (from below) */
-                               (int, const struct sockaddr *, void *);
+                       void    *(*pr_ctlinput)         /* control input (from below) */
+                               (int, const struct sockaddr *, void *, void *);
                } _encapsw6;
        } encapsw46;
 };
@@ -105,6 +105,20 @@
 void   *encap6_ctlinput(int, const struct sockaddr *, void *);
 int    encap_detach(const struct encaptab *);
 void   *encap_getarg(struct mbuf *);
+
+void encap_lock_enter(void);
+void encap_lock_exit(void);
+
+#define        ENCAP_PR_WRAP_CTLINPUT(name)                            \
+static void *                                                  \
+name##_wrapper(int a, const struct sockaddr *b, void *c, void *d) \
+{                                                              \
+       void *rv;                                               \
+       KERNEL_LOCK(1, NULL);                                   \
+       rv = name(a, b, c, d);                                  \
+       KERNEL_UNLOCK_ONE(NULL);                                \
+       return rv;                                              \
+}
 #endif
 
 #endif /* !_NETINET_IP_ENCAP_H_ */
diff -r 153db49ca671 -r 423ee163b674 sys/netinet6/in6_gif.c
--- a/sys/netinet6/in6_gif.c    Thu Feb 25 17:09:39 2016 +0000
+++ b/sys/netinet6/in6_gif.c    Fri Feb 26 07:35:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_gif.c,v 1.71 2016/01/26 05:58:05 knakahara Exp $   */
+/*     $NetBSD: in6_gif.c,v 1.72 2016/02/26 07:35:17 knakahara 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.71 2016/01/26 05:58:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.72 2016/02/26 07:35:17 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -76,8 +76,6 @@
 
 int    ip6_gif_hlim = GIF_HLIM;
 
-extern LIST_HEAD(, gif_softc) gif_softc_list;
-
 static const struct encapsw in6_gif_encapsw;
 
 /* 
@@ -398,9 +396,9 @@
 }
 
 void *
-in6_gif_ctlinput(int cmd, const struct sockaddr *sa, void *d)
+in6_gif_ctlinput(int cmd, const struct sockaddr *sa, void *d, void *eparg)
 {
-       struct gif_softc *sc;
+       struct gif_softc *sc = (struct gif_softc *)eparg;
        struct ip6ctlparam *ip6cp = NULL;
        struct ip6_hdr *ip6;
        const struct sockaddr_in6 *dst6;
@@ -427,29 +425,22 @@
        if (!ip6)
                return NULL;
 
-       /*
-        * for now we don't care which type it was, just flush the route cache.
-        * XXX slow.  sc (or sc->encap_cookie6) should be passed from
-        * ip_encap.c.
-        */
-       LIST_FOREACH(sc, &gif_softc_list, gif_list) {
-               if ((sc->gif_if.if_flags & IFF_RUNNING) == 0)
-                       continue;
-               if (sc->gif_psrc->sa_family != AF_INET6)
-                       continue;
+       if ((sc->gif_if.if_flags & IFF_RUNNING) == 0)
+               return NULL;
+       if (sc->gif_psrc->sa_family != AF_INET6)
+               return NULL;
 
-               dst6 = satocsin6(rtcache_getdst(&sc->gif_ro));
-               /* XXX scope */
-               if (dst6 == NULL)
-                       ;
-               else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr))
-                       rtcache_free(&sc->gif_ro);
-       }
+       dst6 = satocsin6(rtcache_getdst(&sc->gif_ro));
+       /* XXX scope */
+       if (dst6 == NULL)
+               ;
+       else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr))
+               rtcache_free(&sc->gif_ro);
 
        return NULL;
 }
 
-PR_WRAP_CTLINPUT(in6_gif_ctlinput)
+ENCAP_PR_WRAP_CTLINPUT(in6_gif_ctlinput)
 #define        in6_gif_ctlinput        in6_gif_ctlinput_wrapper
 
 static const struct encapsw in6_gif_encapsw = {
diff -r 153db49ca671 -r 423ee163b674 sys/netinet6/in6_gif.h
--- a/sys/netinet6/in6_gif.h    Thu Feb 25 17:09:39 2016 +0000
+++ b/sys/netinet6/in6_gif.h    Fri Feb 26 07:35:17 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_gif.h,v 1.13 2008/04/24 11:38:38 ad Exp $  */
+/*     $NetBSD: in6_gif.h,v 1.14 2016/02/26 07:35:17 knakahara Exp $   */
 /*     $KAME: in6_gif.h,v 1.7 2001/07/26 06:53:16 jinmei Exp $ */
 
 /*
@@ -45,6 +45,6 @@
 #endif
 int in6_gif_attach(struct gif_softc *);
 int in6_gif_detach(struct gif_softc *);
-void *in6_gif_ctlinput(int, const struct sockaddr *, void *);
+void *in6_gif_ctlinput(int, const struct sockaddr *, void *, void *);
 
 #endif /* !_NETINET6_IN6_GIF_H_ */



Home | Main Index | Thread Index | Old Index