diff options
Diffstat (limited to 'templates/interfaces/tunnel/node.def')
-rw-r--r-- | templates/interfaces/tunnel/node.def | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/templates/interfaces/tunnel/node.def b/templates/interfaces/tunnel/node.def index 34ef1ad6..2a80592e 100644 --- a/templates/interfaces/tunnel/node.def +++ b/templates/interfaces/tunnel/node.def @@ -1,9 +1,8 @@ tag: priority: 380 type: txt -help: Set tunnel interface name +help: Set tunnel interface comp_help: Enter tunnel interface name (tun0 - tun999) - syntax:expression: pattern $VAR(@) "^tun[0-9]+$" \ ; "tunnel must be (tun0-tun999)" @@ -14,18 +13,28 @@ commit:expression: $VAR(./remote-ip/) != "" ; \ commit:expression: $VAR(./encapsulation/) != "" ; \ "Must configure the tunnel encapsulation for $VAR(@)" -create:expression: "\ - if [ -n \"$VAR(./key/@)\" ]; then \ - KEY=\"key $VAR(./key/@)\"; \ - fi; \ - if [ x$VAR(./multicast/@) == xenable ]; then \ - MC=\"multicast on allmulticast on\"; \ - fi; \ - ip tunnel add $VAR(@) \ - local $VAR(./local-ip/@) remote $VAR(./remote-ip/@) \ - mode $VAR(./encapsulation/@) $KEY; \ - ip link set $VAR(@) $MC up;" ; \ - "Error creating $VAR(@)" - -delete:expression: "ip tunnel del $VAR(@)" ; "Error deleting $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 + sudo ip link add $VAR(@) type gretap local $VAR(./local-ip/@) remote $VAR(./remote-ip/@) || + echo "interfaces tunnel $VAR(@): error creating tunnel interface" + else + sudo 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 + sudo ip link set $VAR(@) $MC up || + echo "interfaces tunnel $VAR(@): error setting tunnel interface active" +delete:if [ "$VAR(./encapsulation/@)" == "gre-bridge" ]; then + sudo ip link delete $VAR(@) + else + sudo ip tunnel del $VAR(@) + fi |