Module Name:    src
Committed By:   knakahara
Date:           Fri Feb 26 07:35:17 UTC 2016

Modified Files:
        src/sys/net: if_gif.c
        src/sys/netinet: ip_encap.c ip_encap.h
        src/sys/netinet6: in6_gif.c in6_gif.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/net/if_gif.c
cvs rdiff -u -r1.51 -r1.52 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/ip_encap.h
cvs rdiff -u -r1.71 -r1.72 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet6/in6_gif.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.105 src/sys/net/if_gif.c:1.106
--- src/sys/net/if_gif.c:1.105	Mon Jan 18 06:08:26 2016
+++ src/sys/net/if_gif.c	Fri Feb 26 07:35:17 2016
@@ -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 @@ static void	gifintr(void *);
 /*
  * 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 **);
 

Index: src/sys/netinet/ip_encap.c
diff -u src/sys/netinet/ip_encap.c:1.51 src/sys/netinet/ip_encap.c:1.52
--- src/sys/netinet/ip_encap.c:1.51	Tue Jan 26 05:58:05 2016
+++ src/sys/netinet/ip_encap.c	Fri Feb 26 07:35:17 2016
@@ -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 @@ encap6_ctlinput(int cmd, const struct so
 		/* 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);
 		}
 	}
 

Index: src/sys/netinet/ip_encap.h
diff -u src/sys/netinet/ip_encap.h:1.17 src/sys/netinet/ip_encap.h:1.18
--- src/sys/netinet/ip_encap.h:1.17	Tue Jan 26 06:00:10 2016
+++ src/sys/netinet/ip_encap.h	Fri Feb 26 07:35:17 2016
@@ -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 encapsw {
 		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 @@ const struct encaptab *encap_attach_func
 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_ */

Index: src/sys/netinet6/in6_gif.c
diff -u src/sys/netinet6/in6_gif.c:1.71 src/sys/netinet6/in6_gif.c:1.72
--- src/sys/netinet6/in6_gif.c:1.71	Tue Jan 26 05:58:05 2016
+++ src/sys/netinet6/in6_gif.c	Fri Feb 26 07:35:17 2016
@@ -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 @@ static int gif_validate6(const struct ip
 
 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 @@ in6_gif_detach(struct gif_softc *sc)
 }
 
 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 @@ in6_gif_ctlinput(int cmd, const struct s
 	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;
-
-		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);
-	}
+	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);
 
 	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 = {

Index: src/sys/netinet6/in6_gif.h
diff -u src/sys/netinet6/in6_gif.h:1.13 src/sys/netinet6/in6_gif.h:1.14
--- src/sys/netinet6/in6_gif.h:1.13	Thu Apr 24 11:38:38 2008
+++ src/sys/netinet6/in6_gif.h	Fri Feb 26 07:35:17 2016
@@ -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 @@ int gif_encapcheck6(struct mbuf *, int, 
 #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_ */

Reply via email to