Module Name:    src
Committed By:   knakahara
Date:           Mon Oct 30 11:24:04 UTC 2017

Modified Files:
        src/sys/net: if_l2tp.c if_l2tp.h

Log Message:
If if_attach() failed in the attach function, return. Add comments about 
if_initialize().

suggested by ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.2 -r1.3 src/sys/net/if_l2tp.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_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.12 src/sys/net/if_l2tp.c:1.13
--- src/sys/net/if_l2tp.c:1.12	Thu Oct 19 11:28:30 2017
+++ src/sys/net/if_l2tp.c	Mon Oct 30 11:24:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.13 2017/10/30 11:24:04 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.13 2017/10/30 11:24:04 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -227,10 +227,17 @@ l2tp_clone_create(struct if_clone *ifc, 
 {
 	struct l2tp_softc *sc;
 	struct l2tp_variant *var;
+	int rv;
 
 	sc = kmem_zalloc(sizeof(struct l2tp_softc), KM_SLEEP);
-	var = kmem_zalloc(sizeof(struct l2tp_variant), KM_SLEEP);
+	if_initname(&sc->l2tp_ec.ec_if, ifc->ifc_name, unit);
+	rv = l2tpattach0(sc);
+	if (rv != 0) {
+		kmem_free(sc, sizeof(struct l2tp_softc));
+		return rv;
+	}
 
+	var = kmem_zalloc(sizeof(struct l2tp_variant), KM_SLEEP);
 	var->lv_softc = sc;
 	var->lv_state = L2TP_STATE_DOWN;
 	var->lv_use_cookie = L2TP_COOKIE_OFF;
@@ -240,10 +247,6 @@ l2tp_clone_create(struct if_clone *ifc, 
 	mutex_init(&sc->l2tp_lock, MUTEX_DEFAULT, IPL_NONE);
 	PSLIST_ENTRY_INIT(sc, l2tp_hash);
 
-	if_initname(&sc->l2tp_ec.ec_if, ifc->ifc_name, unit);
-
-	l2tpattach0(sc);
-
 	sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
 	percpu_foreach(sc->l2tp_ro_percpu, l2tp_ro_init_pc, NULL);
 
@@ -254,9 +257,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	return (0);
 }
 
-void
+int
 l2tpattach0(struct l2tp_softc *sc)
 {
+	int rv;
 
 	sc->l2tp_ec.ec_if.if_addrlen = 0;
 	sc->l2tp_ec.ec_if.if_mtu    = L2TP_MTU;
@@ -270,9 +274,19 @@ l2tpattach0(struct l2tp_softc *sc)
 	sc->l2tp_ec.ec_if.if_transmit = l2tp_transmit;
 	sc->l2tp_ec.ec_if._if_input = ether_input;
 	IFQ_SET_READY(&sc->l2tp_ec.ec_if.if_snd);
-	if_attach(&sc->l2tp_ec.ec_if);
+	/* XXX
+	 * It may improve performance to use if_initialize()/if_register()
+	 * so that l2tp_input() calls if_input() instead of
+	 * if_percpuq_enqueue(). However, that causes recursive softnet_lock
+	 * when NET_MPSAFE is not set.
+	 */
+	rv = if_attach(&sc->l2tp_ec.ec_if);
+	if (rv != 0)
+		return rv;
 	if_alloc_sadl(&sc->l2tp_ec.ec_if);
 	bpf_attach(&sc->l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header));
+
+	return 0;
 }
 
 void

Index: src/sys/net/if_l2tp.h
diff -u src/sys/net/if_l2tp.h:1.2 src/sys/net/if_l2tp.h:1.3
--- src/sys/net/if_l2tp.h:1.2	Wed May 31 08:19:44 2017
+++ src/sys/net/if_l2tp.h	Mon Oct 30 11:24:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.h,v 1.2 2017/05/31 08:19:44 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.h,v 1.3 2017/10/30 11:24:04 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -162,7 +162,7 @@ l2tp_heldref_variant(struct l2tp_variant
 
 /* Prototypes */
 void l2tpattach(int);
-void l2tpattach0(struct l2tp_softc *);
+int l2tpattach0(struct l2tp_softc *);
 void l2tp_input(struct mbuf *, struct ifnet *);
 int l2tp_ioctl(struct ifnet *, u_long, void *);
 

Reply via email to