From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-890429-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 3F5431382EF
	for <garchives@archives.gentoo.org>; Tue,  5 Jul 2016 18:15:01 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 3CA35E0B3E;
	Tue,  5 Jul 2016 18:14:59 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 7ACFFE0B44
	for <gentoo-commits@lists.gentoo.org>; Tue,  5 Jul 2016 18:14:58 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 3F37E340D09
	for <gentoo-commits@lists.gentoo.org>; Tue,  5 Jul 2016 18:14:57 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 70D2697B
	for <gentoo-commits@lists.gentoo.org>; Tue,  5 Jul 2016 18:14:55 +0000 (UTC)
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" <robbat2@gentoo.org>
Message-ID: <1461442675.4a8358aaf9c0048930194e0bbe3d2509d9da4fd0.robbat2@OpenRC>
Subject: [gentoo-commits] proj/netifrc:master commit in: net/
X-VCS-Repository: proj/netifrc
X-VCS-Files: net/iproute2.sh
X-VCS-Directories: net/
X-VCS-Committer: robbat2
X-VCS-Committer-Name: Robin H. Johnson
X-VCS-Revision: 4a8358aaf9c0048930194e0bbe3d2509d9da4fd0
X-VCS-Branch: master
Date: Tue,  5 Jul 2016 18:14:55 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: c850a54f-5fe1-4284-8113-c16557d82cb3
X-Archives-Hash: 1b0d12d72955f0fe2793b8f9489b05d9

commit:     4a8358aaf9c0048930194e0bbe3d2509d9da4fd0
Author:     Emeric Verschuur <emeric <AT> mbedsys <DOT> org>
AuthorDate: Sat Apr 23 20:17:55 2016 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Sat Apr 23 20:17:55 2016 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4a8358aa

Add L2TPv3 tunnel/session support to iproute2 module

Add L2TPv3 tunnel/session support to iproute2 module:

Example of config to add two L2TPv3 session/two interfaces with a shared tunnel:

l2tptunnel_net1="remote 1.2.3.4 local 1.2.3.5tunnel_id 3 peer_tunnel_id 3 encap ip"
l2tpsession_net1="tunnel_id 3 session_id 3 peer_session_id 3"
config_net1="null"

l2tptunnel_net2="remote 1.2.3.4 local 1.2.3.5 tunnel_id 3 peer_tunnel_id 3 encap ip"
l2tpsession_net2="tunnel_id 3 session_id 4 peer_session_id 4"
config_net2="null"

 net/iproute2.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 0b2a8d6..825b9b1 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -318,6 +318,32 @@ iproute2_pre_start()
 		eend $? || return 1
 		_up
 	fi
+	
+	# L2TPv3
+	local l2tpsession=
+	eval l2tpsession=\$l2tpsession_${IFVAR}
+	if [ -n "${l2tpsession}" ]; then
+		ebegin "Creating L2TPv3 tunnel ${IFVAR}"
+		local l2tptunnel=
+		eval l2tptunnel=\$l2tptunnel_${IFVAR}
+		if [ -n "${l2tptunnel}" ]; then
+			local retcode
+			veinfo ip l2tp add tunnel ${l2tptunnel}
+			ip l2tp add tunnel ${l2tptunnel}
+			#a L2TPv3 tunnel can host several sessions (1 session <=> 1 interface)
+			#if $?=2 the tunnel id already exists, just ignore this error
+			#we assume that the existing one have the same property that we want to create...
+			if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+				eend $? || return 1
+			fi
+		fi
+		veinfo ip l2tp add session ${l2tpsession} name "${IFACE}"
+		ip l2tp add session ${l2tpsession} name "${IFACE}"
+		if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+			eend $? || return 1
+		fi
+		_up
+	fi
 
 	# MTU support
 	local mtu=
@@ -424,6 +450,25 @@ iproute2_post_stop()
 			ip tunnel del "${IFACE}"
 			eend $?
 		fi
+		local l2tptuple
+		# Searching for l2tp session associated to ${IFACE}
+		l2tptuple="$(ip l2tp show session | \
+			awk "match(\$0, /^Session ([0-9]+) in tunnel ([0-9]+)\$/, ret) {sid=ret[1]; tid=ret[2]} 
+				match(\$0, /^[ ]*interface name: ${IFACE}\$/) {print sid\":\"tid; exit}")"
+		if [ -n "$l2tptuple" ]; then
+			local l2tpsession_id l2tptunnel_id
+			l2tpsession_id=${l2tptuple%:*}
+			l2tptunnel_id=${l2tptuple#*:}
+			ebegin "Destroying L2TPv3 tunnel ${IFACE}"
+			veinfo ip l2tp del session tunnel_id $l2tptunnel_id session_id $l2tpsession_id
+			ip l2tp del session tunnel_id $l2tptunnel_id session_id $l2tpsession_id
+			if [ -z "$(ip l2tp show session | grep -E "^Session [0-9]+ in tunnel $l2tptunnel_id\$")" ]; then
+				#tunnel $l2tptunnel_id no longer used, destoying it...
+				veinfo ip l2tp del tunnel tunnel_id $l2tptunnel_id
+				ip l2tp del tunnel tunnel_id $l2tptunnel_id
+			fi
+			eend $?
+		fi
 	fi
 }