Module Name:    src
Committed By:   knakahara
Date:           Mon Jul  4 04:40:13 UTC 2016

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

Log Message:
make gif(4) and ip_encap MP-ify


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/net/if_gif.c
cvs rdiff -u -r1.60 -r1.61 src/sys/netinet/ip_encap.c

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.117 src/sys/net/if_gif.c:1.118
--- src/sys/net/if_gif.c:1.117	Mon Jul  4 04:35:09 2016
+++ src/sys/net/if_gif.c	Mon Jul  4 04:40:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.117 2016/07/04 04:35:09 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.118 2016/07/04 04:40:13 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,10 +31,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.117 2016/07/04 04:35:09 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.118 2016/07/04 04:40:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -86,6 +87,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
 
 #include "ioconf.h"
 
+#ifdef NET_MPSAFE
+#define GIF_MPSAFE	1
+#endif
+
 /*
  * gif global variable definitions
  */
@@ -322,7 +327,9 @@ gif_output(struct ifnet *ifp, struct mbu
 {
 	struct gif_softc *sc = ifp->if_softc;
 	int error = 0;
+#ifndef GIF_MPSAFE
 	int s;
+#endif
 
 	IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family);
 
@@ -353,13 +360,19 @@ gif_output(struct ifnet *ifp, struct mbu
 	m->m_pkthdr.csum_flags = 0;
 	m->m_pkthdr.csum_data = 0;
 
+#ifndef GIF_MPSAFE
 	s = splnet();
+#endif
 	IFQ_ENQUEUE(&ifp->if_snd, m, error);
 	if (error) {
+#ifndef GIF_MPSAFE
 		splx(s);
+#endif
 		goto end;
 	}
+#ifndef GIF_MPSAFE
 	splx(s);
+#endif
 
 	gif_start(ifp);
 
@@ -378,16 +391,22 @@ gif_start(struct ifnet *ifp)
 	struct mbuf *m;
 	int family;
 	int len;
+#ifndef GIF_MPSAFE
 	int s;
+#endif
 	int error;
 
 	sc = ifp->if_softc;
 
 	/* output processing */
 	while (1) {
+#ifndef GIF_MPSAFE
 		s = splnet();
+#endif
 		IFQ_DEQUEUE(&sc->gif_if.if_snd, m);
+#ifndef GIF_MPSAFE
 		splx(s);
+#endif
 		if (m == NULL)
 			break;
 
@@ -446,7 +465,9 @@ gif_input(struct mbuf *m, int af, struct
 {
 	pktqueue_t *pktq;
 	size_t pktlen;
+#ifndef GIF_MPSAFE
 	int s;
+#endif
 
 	if (ifp == NULL) {
 		/* just in case */
@@ -481,14 +502,18 @@ gif_input(struct mbuf *m, int af, struct
 		return;
 	}
 
+#ifndef GIF_MPSAFE
 	s = splnet();
+#endif
 	if (__predict_true(pktq_enqueue(pktq, m, 0))) {
 		ifp->if_ibytes += pktlen;
 		ifp->if_ipackets++;
 	} else {
 		m_freem(m);
 	}
+#ifndef GIF_MPSAFE
 	splx(s);
+#endif
 }
 
 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
@@ -825,13 +850,17 @@ gif_set_tunnel(struct ifnet *ifp, struct
 	struct gif_softc *sc2;
 	struct sockaddr *osrc, *odst;
 	struct sockaddr *nsrc, *ndst;
-	int s;
 	int error;
+#ifndef GIF_MPSAFE
+	int s;
 
 	s = splsoftnet();
+#endif
 	error = encap_lock_enter();
 	if (error) {
+#ifndef GIF_MPSAFE
 		splx(s);
+#endif
 		return error;
 	}
 
@@ -844,24 +873,21 @@ gif_set_tunnel(struct ifnet *ifp, struct
 		if (sockaddr_cmp(sc2->gif_pdst, dst) == 0 &&
 		    sockaddr_cmp(sc2->gif_psrc, src) == 0) {
 			/* continue to use the old configureation. */
-			encap_lock_exit();
-			splx(s);
-			return EADDRNOTAVAIL;
+			error =  EADDRNOTAVAIL;
+			goto out;
 		}
 
 		/* XXX both end must be valid? (I mean, not 0.0.0.0) */
 	}
 
 	if ((nsrc = sockaddr_dup(src, M_WAITOK)) == NULL) {
-		encap_lock_exit();
-		splx(s);
-		return ENOMEM;
+		error =  ENOMEM;
+		goto out;
 	}
 	if ((ndst = sockaddr_dup(dst, M_WAITOK)) == NULL) {
 		sockaddr_free(nsrc);
-		encap_lock_exit();
-		splx(s);
-		return ENOMEM;
+		error = ENOMEM;
+		goto out;
 	}
 
 	gif_encap_pause(sc);
@@ -910,8 +936,11 @@ gif_set_tunnel(struct ifnet *ifp, struct
 	else
 		ifp->if_flags &= ~IFF_RUNNING;
 
+ out:
 	encap_lock_exit();
+#ifndef GIF_MPSAFE
 	splx(s);
+#endif
 	return error;
 }
 
@@ -919,13 +948,17 @@ static void
 gif_delete_tunnel(struct ifnet *ifp)
 {
 	struct gif_softc *sc = ifp->if_softc;
-	int s;
 	int error;
+#ifndef GIF_MPSAFE
+	int s;
 
 	s = splsoftnet();
+#endif
 	error = encap_lock_enter();
 	if (error) {
+#ifndef GIF_MPSAFE
 		splx(s);
+#endif
 		return;
 	}
 
@@ -952,5 +985,7 @@ gif_delete_tunnel(struct ifnet *ifp)
 		ifp->if_flags &= ~IFF_RUNNING;
 
 	encap_lock_exit();
+#ifndef GIF_MPSAFE
 	splx(s);
+#endif
 }

Index: src/sys/netinet/ip_encap.c
diff -u src/sys/netinet/ip_encap.c:1.60 src/sys/netinet/ip_encap.c:1.61
--- src/sys/netinet/ip_encap.c:1.60	Mon Jul  4 04:38:14 2016
+++ src/sys/netinet/ip_encap.c	Mon Jul  4 04:40:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.60 2016/07/04 04:38:14 knakahara Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.61 2016/07/04 04:40:13 knakahara Exp $	*/
 /*	$KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $	*/
 
 /*
@@ -68,11 +68,12 @@
 #define USE_RADIX
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.60 2016/07/04 04:38:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.61 2016/07/04 04:40:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
 #include "opt_inet.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -110,6 +111,10 @@ __KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v
 
 #include <net/net_osdep.h>
 
+#ifdef NET_MPSAFE
+#define ENCAP_MPSAFE	1
+#endif
+
 enum direction { INBOUND, OUTBOUND };
 
 #ifdef INET
@@ -648,14 +653,17 @@ encap_attach(int af, int proto,
 {
 	struct encaptab *ep;
 	int error;
-	int s, pss;
+	int pss;
 	size_t l;
 	struct ip_pack4 *pack4;
 #ifdef INET6
 	struct ip_pack6 *pack6;
 #endif
+#ifndef ENCAP_MPSAFE
+	int s;
 
 	s = splsoftnet();
+#endif
 	/* sanity check on args */
 	error = encap_afcheck(af, sp, dp);
 	if (error)
@@ -761,7 +769,9 @@ encap_attach(int af, int proto,
 		goto gc;
 
 	error = 0;
+#ifndef ENCAP_MPSAFE
 	splx(s);
+#endif
 	return ep;
 
 gc:
@@ -772,7 +782,9 @@ gc:
 	if (ep)
 		kmem_free(ep, sizeof(*ep));
 fail:
+#ifndef ENCAP_MPSAFE
 	splx(s);
+#endif
 	return NULL;
 }
 
@@ -783,9 +795,11 @@ encap_attach_func(int af, int proto,
 {
 	struct encaptab *ep;
 	int error;
+#ifndef ENCAP_MPSAFE
 	int s;
 
 	s = splsoftnet();
+#endif
 	/* sanity check on args */
 	if (!func) {
 		error = EINVAL;
@@ -815,11 +829,15 @@ encap_attach_func(int af, int proto,
 		goto fail;
 
 	error = 0;
+#ifndef ENCAP_MPSAFE
 	splx(s);
+#endif
 	return ep;
 
 fail:
+#ifndef ENCAP_MPSAFE
 	splx(s);
+#endif
 	return NULL;
 }
 

Reply via email to