Source-Changes-HG archive

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

[src/trunk]: src/sys fix: l2tp(4) cannot receive packets after reset session ...



details:   https://anonhg.NetBSD.org/src/rev/eda9cb323354
branches:  trunk
changeset: 366570:eda9cb323354
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Mon Sep 03 02:33:30 2018 +0000

description:
fix: l2tp(4) cannot receive packets after reset session without reset tunnel. Pointed out by k-goda@IIJ

When the following operations are done after established session, the l2tp0
cannot receive packets until done deletetunnel && tunnel "src" "dst".
====================
ifconfig l2tp0 deletesession
ifconfig l2tp0 deletecookie
ifconfig l2tp0 session 200 100
====================

XXX pullup-8

diffstat:

 sys/netinet/in_l2tp.c   |  34 +++++++++++++++++++++++++---------
 sys/netinet6/in6_l2tp.c |  34 +++++++++++++++++++++++++---------
 2 files changed, 50 insertions(+), 18 deletions(-)

diffs (156 lines):

diff -r 64bb49df1e01 -r eda9cb323354 sys/netinet/in_l2tp.c
--- a/sys/netinet/in_l2tp.c     Mon Sep 03 00:17:00 2018 +0000
+++ b/sys/netinet/in_l2tp.c     Mon Sep 03 02:33:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_l2tp.c,v 1.15 2018/06/21 10:37:50 knakahara Exp $   */
+/*     $NetBSD: in_l2tp.c,v 1.16 2018/09/03 02:33:30 knakahara Exp $   */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.15 2018/06/21 10:37:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.16 2018/09/03 02:33:30 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -366,16 +366,25 @@
 static int
 in_l2tp_match(struct mbuf *m, int off, int proto, void *arg)
 {
-       struct l2tp_variant *var = arg;
+       struct l2tp_softc *sc = arg;
+       struct l2tp_variant *var;
+       struct psref psref;
        uint32_t sess_id;
+       int rv = 0;
 
        KASSERT(proto == IPPROTO_L2TP);
 
+       var = l2tp_getref_variant(sc, &psref);
+       if (__predict_false(var == NULL))
+               return rv;
+
        /*
         * If the packet contains no session ID it cannot match
         */
-       if (m_length(m) < off + sizeof(uint32_t))
-               return 0;
+       if (m_length(m) < off + sizeof(uint32_t)) {
+               rv = 0;
+               goto out;
+       }
 
        /* get L2TP session ID */
        m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);
@@ -385,19 +394,26 @@
                 * L2TPv3 control packet received.
                 * userland daemon(l2tpd?) should process.
                 */
-               return 32 * 2;
+               rv = 32 * 2;
        } else if (sess_id == var->lv_my_sess_id)
-               return 32 * 2;
+               rv = 32 * 2;
        else
-               return 0;
+               rv = 0;
+
+out:
+       l2tp_putref_variant(var, &psref);
+       return rv;
 }
 
 int
 in_l2tp_attach(struct l2tp_variant *var)
 {
+       struct l2tp_softc *sc = var->lv_softc;
 
+       if (sc == NULL)
+               return EINVAL;
        var->lv_encap_cookie = encap_attach_func(AF_INET, IPPROTO_L2TP,
-           in_l2tp_match, &in_l2tp_encapsw, var);
+           in_l2tp_match, &in_l2tp_encapsw, sc);
        if (var->lv_encap_cookie == NULL)
                return EEXIST;
 
diff -r 64bb49df1e01 -r eda9cb323354 sys/netinet6/in6_l2tp.c
--- a/sys/netinet6/in6_l2tp.c   Mon Sep 03 00:17:00 2018 +0000
+++ b/sys/netinet6/in6_l2tp.c   Mon Sep 03 02:33:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_l2tp.c,v 1.16 2018/06/21 10:37:50 knakahara Exp $  */
+/*     $NetBSD: in6_l2tp.c,v 1.17 2018/09/03 02:33:31 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.16 2018/06/21 10:37:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.17 2018/09/03 02:33:31 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -361,16 +361,25 @@
 static int
 in6_l2tp_match(struct mbuf *m, int off, int proto, void *arg)
 {
-       struct l2tp_variant *var = arg;
+       struct l2tp_softc *sc = arg;
+       struct l2tp_variant *var;
+       struct psref psref;
        uint32_t sess_id;
+       int rv = 0;
 
        KASSERT(proto == IPPROTO_L2TP);
 
+       var = l2tp_getref_variant(sc, &psref);
+       if (__predict_false(var == NULL))
+               return rv;
+
        /*
         * If the packet contains no session ID it cannot match
         */
-       if (m_length(m) < off + sizeof(uint32_t))
-               return 0;
+       if (m_length(m) < off + sizeof(uint32_t)) {
+               rv = 0 ;
+               goto out;
+       }
 
        /* get L2TP session ID */
        m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);
@@ -380,19 +389,26 @@
                 * L2TPv3 control packet received.
                 * userland daemon(l2tpd?) should process.
                 */
-               return 128 * 2;
+               rv = 128 * 2;
        } else if (sess_id == var->lv_my_sess_id)
-               return 128 * 2;
+               rv = 128 * 2;
        else
-               return 0;
+               rv = 0;
+
+out:
+       l2tp_putref_variant(var, &psref);
+       return rv;
 }
 
 int
 in6_l2tp_attach(struct l2tp_variant *var)
 {
+       struct l2tp_softc *sc = var->lv_softc;
 
+       if (sc == NULL)
+               return EINVAL;
        var->lv_encap_cookie = encap_attach_func(AF_INET6, IPPROTO_L2TP,
-           in6_l2tp_match, &in6_l2tp_encapsw, var);
+           in6_l2tp_match, &in6_l2tp_encapsw, sc);
        if (var->lv_encap_cookie == NULL)
                return EEXIST;
 



Home | Main Index | Thread Index | Old Index