Module Name:    src
Committed By:   knakahara
Date:           Mon Sep  3 02:33:31 UTC 2018

Modified Files:
        src/sys/netinet: in_l2tp.c
        src/sys/netinet6: in6_l2tp.c

Log Message:
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.15 -r1.16 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.16 -r1.17 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.15 src/sys/netinet/in_l2tp.c:1.16
--- src/sys/netinet/in_l2tp.c:1.15	Thu Jun 21 10:37:50 2018
+++ src/sys/netinet/in_l2tp.c	Mon Sep  3 02:33:30 2018
@@ -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 @@ 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);
@@ -385,19 +394,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.16 src/sys/netinet6/in6_l2tp.c:1.17
--- src/sys/netinet6/in6_l2tp.c:1.16	Thu Jun 21 10:37:50 2018
+++ src/sys/netinet6/in6_l2tp.c	Mon Sep  3 02:33:31 2018
@@ -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 @@ 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;
 

Reply via email to