Module Name: src Committed By: martin Date: Mon Sep 10 15:58:47 UTC 2018
Modified Files: src/sys/netinet [netbsd-8]: in_l2tp.c src/sys/netinet6 [netbsd-8]: in6_l2tp.c Log Message: Pull up following revision(s) (requested by knakahara in ticket #1018): sys/netinet6/in6_l2tp.c: revision 1.17 sys/netinet/in_l2tp.c: revision 1.16 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 To generate a diff of this commit: cvs rdiff -u -r1.2.8.6 -r1.2.8.7 src/sys/netinet/in_l2tp.c cvs rdiff -u -r1.5.8.6 -r1.5.8.7 src/sys/netinet6/in6_l2tp.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/netinet/in_l2tp.c diff -u src/sys/netinet/in_l2tp.c:1.2.8.6 src/sys/netinet/in_l2tp.c:1.2.8.7 --- src/sys/netinet/in_l2tp.c:1.2.8.6 Fri Jul 13 14:26:47 2018 +++ src/sys/netinet/in_l2tp.c Mon Sep 10 15:58:47 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: in_l2tp.c,v 1.2.8.6 2018/07/13 14:26:47 martin Exp $ */ +/* $NetBSD: in_l2tp.c,v 1.2.8.7 2018/09/10 15:58:47 martin 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.2.8.6 2018/07/13 14:26:47 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.2.8.7 2018/09/10 15:58:47 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_l2tp.h" @@ -368,16 +368,25 @@ out: 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); @@ -387,19 +396,26 @@ in_l2tp_match(struct mbuf *m, int off, i * 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; Index: src/sys/netinet6/in6_l2tp.c diff -u src/sys/netinet6/in6_l2tp.c:1.5.8.6 src/sys/netinet6/in6_l2tp.c:1.5.8.7 --- src/sys/netinet6/in6_l2tp.c:1.5.8.6 Fri Jul 13 14:26:47 2018 +++ src/sys/netinet6/in6_l2tp.c Mon Sep 10 15:58:47 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: in6_l2tp.c,v 1.5.8.6 2018/07/13 14:26:47 martin Exp $ */ +/* $NetBSD: in6_l2tp.c,v 1.5.8.7 2018/09/10 15:58:47 martin 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.5.8.6 2018/07/13 14:26:47 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.5.8.7 2018/09/10 15:58:47 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_l2tp.h" @@ -361,16 +361,25 @@ out: 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 @@ in6_l2tp_match(struct mbuf *m, int off, * 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;