Source-Changes-HG archive

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

[src/trunk]: src/sys/net If if_attach() failed in the attach function, return...



details:   https://anonhg.NetBSD.org/src/rev/ba6d637bb194
branches:  trunk
changeset: 827483:ba6d637bb194
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Mon Oct 30 11:24:04 2017 +0000

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

suggested by ozaki-r@n.o.

diffstat:

 sys/net/if_l2tp.c |  32 +++++++++++++++++++++++---------
 sys/net/if_l2tp.h |   4 ++--
 2 files changed, 25 insertions(+), 11 deletions(-)

diffs (99 lines):

diff -r 4bc5077090ef -r ba6d637bb194 sys/net/if_l2tp.c
--- a/sys/net/if_l2tp.c Mon Oct 30 04:53:43 2017 +0000
+++ b/sys/net/if_l2tp.c Mon Oct 30 11:24:04 2017 +0000
@@ -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 @@
 {
        struct l2tp_softc *sc;
        struct l2tp_variant *var;
+       int rv;
 
        sc = kmem_zalloc(sizeof(struct l2tp_softc), 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 @@
        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 @@
        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 @@
        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
diff -r 4bc5077090ef -r ba6d637bb194 sys/net/if_l2tp.h
--- a/sys/net/if_l2tp.h Mon Oct 30 04:53:43 2017 +0000
+++ b/sys/net/if_l2tp.h Mon Oct 30 11:24:04 2017 +0000
@@ -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 @@
 
 /* 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 *);
 



Home | Main Index | Thread Index | Old Index