summaryrefslogtreecommitdiff
path: root/templates/interfaces/l2tpv3/node.def
blob: 924d27b7d330f829216b7c2ce4e3bdda4ed2ce2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
tag:
priority: 380
type: txt
help: l2tpv3 interface
val_help: <l2tpethN>; l2tpv3 interface name
syntax:expression: pattern $VAR(@) "^l2tpeth[0-9]+$" \
                   ; "tunnel must be (l2tpeth0-l2tpeth999)"

commit:expression: $VAR(./local-ip/) != "" ;                    \
                   "Must configure the l2tpv3 local-ip for $VAR(@)"
commit:expression: $VAR(./remote-ip/) != "" ;                   \
                   "Must configure the l2tpv3 remote-ip for $VAR(@)"
commit:expression: $VAR(./endpoint/local-ip/) != "" ;                    \
                   "Must configure the l2tpv3 endpoint local-ip for $VAR(@)"
commit:expression: $VAR(./endpoint/remote-ip/) != "" ;                    \
                   "Must configure the l2tpv3 endpoint remote-ip for $VAR(@)"
commit:expression: $VAR(./tunnel-id/) != "" ;                    \
                   "Must configure the l2tpv3 tunnel-id for $VAR(@)"
commit:expression: $VAR(./peer-tunnel-id/) != "" ;                    \
                   "Must configure the l2tpv3 peer-tunnel-id for $VAR(@)"
commit:expression: $VAR(./session-id/) != "" ;                    \
                   "Must configure the l2tpv3 session-id for $VAR(@)"
commit:expression: $VAR(./peer-session-id/) != "" ;                    \
                   "Must configure the l2tpv3 peer-session-id for $VAR(@)"

begin:
  [ -d /sys/module/l2tp_eth ] || sudo modprobe l2tp_eth
  [ -d /sys/module/l2tp_netlink ] || sudo modprobe l2tp_netlink

create:
  for i in `seq 1 $VAR(./wait/@)`
  do
    ping -c 1 $VAR(./remote-ip/@)  > /dev/null 2>&1 && break
    sleep 1
  done 
  ip l2tp add tunnel tunnel_id $VAR(./tunnel-id/@) peer_tunnel_id $VAR(./peer-tunnel-id/@) udp_sport $VAR(./sport/@) udp_dport $VAR(./dport/@) encap $VAR(./encap/@) local $VAR(./local-ip/@) remote $VAR(./remote-ip/@) ||
  echo "ip l2tp add tunnel tunnel_id $VAR(./tunnel-id/@) peer_tunnel_id  $VAR(./peer-tunnel-id/@) udp_sport $VAR(./sport/@) udp_dport $VAR(./dport/@) encap $VAR(./encap/@) local $VAR(./local-ip/@) remote $VAR(./remote-ip/@)"
  ip l2tp add session tunnel_id  $VAR(./tunnel-id/@) session_id $VAR(./session-id/@) peer_session_id $VAR(./peer-session-id/@) || echo "ip l2tp add session tunnel_id  $VAR(./tunnel-id/@) session_id $VAR(./session-id/@) peer_session_id $VAR(./peer-session-id/@)"
  ip addr add $VAR(./endpoint/local-ip/@) peer $VAR(./endpoint/remote-ip/@) dev  $VAR(@) || echo "ip addr add $VAR(./endpoint/local-ip/@) peer $VAR(./endpoint/remote-ip/@) dev  $VAR(@)"
  ip link set  $VAR(@) up mtu 1500

delete:
  ip link set $VAR(@) down
  if [ -n "$VAR(./tunnel-id@/)" ] && [ -n "$VAR(./session-id@/)" ] ; then
    ip l2tp del session $VAR(./tunnel-id/@) session_id $VAR(./session-id/@)
  fi
  if [ -n "$VAR(./tunnel-id@/)" ] ; then
    ip l2tp del tunnel tunnel_id  $VAR(./tunnel-id/@)
  fi