summaryrefslogtreecommitdiff
path: root/templates/interfaces/tunnel/node.def
blob: a90c01f984ef762f6164e5541d1c5ce7ebf8a96f (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
tag:
priority: 380
type: txt
help: Set tunnel interface
comp_help: Enter tunnel interface name (tun0 - tun999)
syntax:expression: pattern $VAR(@) "^tun[0-9]+$" \
		   ; "tunnel must be (tun0-tun999)"

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

create:if [ -n "$VAR(./key/@)" ]; then
          KEY="key $VAR(./key/@)";
       fi
       if [ x$VAR(./multicast/@) == xenable ]; then
          MC="multicast on allmulticast on";
       fi
       if [ -n "$VAR(./bridge-group/)" ] && [ "$VAR(./encapsulation/@)" != "gre-bridge" ]; then
          echo "interfaces tunnel $VAR(@): Tunnel encapsulation type must be gre-bridge if a bridge group is defined";
	  exit 1;
       fi
       if [ "$VAR(./encapsulation/@)" == "gre-bridge" ]; then
          ip link add $VAR(@) type gretap local $VAR(./local-ip/@) remote $VAR(./remote-ip/@) ||
             echo "interfaces tunnel $VAR(@): error creating tunnel interface"
       else
          ip tunnel add $VAR(@) local $VAR(./local-ip/@) remote $VAR(./remote-ip/@) mode $VAR(./encapsulation/@) $KEY ||
             echo "interfaces tunnel $VAR(@): error creating tunnel interface"
       fi
       ip link set $VAR(@) $MC up ||
          echo "interfaces tunnel $VAR(@): error setting tunnel interface active"

delete:if [ "$VAR(./encapsulation/@)" == "gre-bridge" ]; then
          ip link delete $VAR(@) 
       else 
          ip tunnel del $VAR(@) 
       fi