1 |
commit: 4a8358aaf9c0048930194e0bbe3d2509d9da4fd0 |
2 |
Author: Emeric Verschuur <emeric <AT> mbedsys <DOT> org> |
3 |
AuthorDate: Sat Apr 23 20:17:55 2016 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Apr 23 20:17:55 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4a8358aa |
7 |
|
8 |
Add L2TPv3 tunnel/session support to iproute2 module |
9 |
|
10 |
Add L2TPv3 tunnel/session support to iproute2 module: |
11 |
|
12 |
Example of config to add two L2TPv3 session/two interfaces with a shared tunnel: |
13 |
|
14 |
l2tptunnel_net1="remote 1.2.3.4 local 1.2.3.5tunnel_id 3 peer_tunnel_id 3 encap ip" |
15 |
l2tpsession_net1="tunnel_id 3 session_id 3 peer_session_id 3" |
16 |
config_net1="null" |
17 |
|
18 |
l2tptunnel_net2="remote 1.2.3.4 local 1.2.3.5 tunnel_id 3 peer_tunnel_id 3 encap ip" |
19 |
l2tpsession_net2="tunnel_id 3 session_id 4 peer_session_id 4" |
20 |
config_net2="null" |
21 |
|
22 |
net/iproute2.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ |
23 |
1 file changed, 45 insertions(+) |
24 |
|
25 |
diff --git a/net/iproute2.sh b/net/iproute2.sh |
26 |
index 0b2a8d6..825b9b1 100644 |
27 |
--- a/net/iproute2.sh |
28 |
+++ b/net/iproute2.sh |
29 |
@@ -318,6 +318,32 @@ iproute2_pre_start() |
30 |
eend $? || return 1 |
31 |
_up |
32 |
fi |
33 |
+ |
34 |
+ # L2TPv3 |
35 |
+ local l2tpsession= |
36 |
+ eval l2tpsession=\$l2tpsession_${IFVAR} |
37 |
+ if [ -n "${l2tpsession}" ]; then |
38 |
+ ebegin "Creating L2TPv3 tunnel ${IFVAR}" |
39 |
+ local l2tptunnel= |
40 |
+ eval l2tptunnel=\$l2tptunnel_${IFVAR} |
41 |
+ if [ -n "${l2tptunnel}" ]; then |
42 |
+ local retcode |
43 |
+ veinfo ip l2tp add tunnel ${l2tptunnel} |
44 |
+ ip l2tp add tunnel ${l2tptunnel} |
45 |
+ #a L2TPv3 tunnel can host several sessions (1 session <=> 1 interface) |
46 |
+ #if $?=2 the tunnel id already exists, just ignore this error |
47 |
+ #we assume that the existing one have the same property that we want to create... |
48 |
+ if [ $? -ne 0 ] && [ $? -ne 2 ]; then |
49 |
+ eend $? || return 1 |
50 |
+ fi |
51 |
+ fi |
52 |
+ veinfo ip l2tp add session ${l2tpsession} name "${IFACE}" |
53 |
+ ip l2tp add session ${l2tpsession} name "${IFACE}" |
54 |
+ if [ $? -ne 0 ] && [ $? -ne 2 ]; then |
55 |
+ eend $? || return 1 |
56 |
+ fi |
57 |
+ _up |
58 |
+ fi |
59 |
|
60 |
# MTU support |
61 |
local mtu= |
62 |
@@ -424,6 +450,25 @@ iproute2_post_stop() |
63 |
ip tunnel del "${IFACE}" |
64 |
eend $? |
65 |
fi |
66 |
+ local l2tptuple |
67 |
+ # Searching for l2tp session associated to ${IFACE} |
68 |
+ l2tptuple="$(ip l2tp show session | \ |
69 |
+ awk "match(\$0, /^Session ([0-9]+) in tunnel ([0-9]+)\$/, ret) {sid=ret[1]; tid=ret[2]} |
70 |
+ match(\$0, /^[ ]*interface name: ${IFACE}\$/) {print sid\":\"tid; exit}")" |
71 |
+ if [ -n "$l2tptuple" ]; then |
72 |
+ local l2tpsession_id l2tptunnel_id |
73 |
+ l2tpsession_id=${l2tptuple%:*} |
74 |
+ l2tptunnel_id=${l2tptuple#*:} |
75 |
+ ebegin "Destroying L2TPv3 tunnel ${IFACE}" |
76 |
+ veinfo ip l2tp del session tunnel_id $l2tptunnel_id session_id $l2tpsession_id |
77 |
+ ip l2tp del session tunnel_id $l2tptunnel_id session_id $l2tpsession_id |
78 |
+ if [ -z "$(ip l2tp show session | grep -E "^Session [0-9]+ in tunnel $l2tptunnel_id\$")" ]; then |
79 |
+ #tunnel $l2tptunnel_id no longer used, destoying it... |
80 |
+ veinfo ip l2tp del tunnel tunnel_id $l2tptunnel_id |
81 |
+ ip l2tp del tunnel tunnel_id $l2tptunnel_id |
82 |
+ fi |
83 |
+ eend $? |
84 |
+ fi |
85 |
fi |
86 |
} |