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
}