summaryrefslogtreecommitdiff
path: root/templates/interfaces/vxlan/node.def
blob: 70deef608355cc12d46c1d76b485013840b9dba9 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
tag:
priority: 460
type: txt
help: Virtual eXtensible LAN interface
val_help: <vxlanN>; VXLAN interface name
syntax:expression: pattern $VAR(@) "vxlan[0-9]+$"

commit:expression: $VAR(./vni/) != "";			\
		   "Must configure vxlan vni for $VAR(@)"

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


create:
  if [ -e /sys/class/net/$VAR(@) ]; then
    echo "VXLAN interface \"$VAR(@)\" already exists."
    exit 1
  fi

  VXLAN_GROUP=""
  VXLAN_VNI="id $VAR(./vni/@)"
  VXLAN_TTL="ttl 16"
  VXLAN_PORT=""

  if [ ! $VAR(./link/) == "" ]; then
    VXLAN_DEV="dev $VAR(./link/@)"
  fi

  if [ ! $VAR(./group/) == "" ]; then
    VXLAN_GROUP="group $VAR(./group/@)"
    if [ -z "$VXLAN_DEV" ]; then
      echo "For multicast VXLAN, link (network interface) must be configured"
      exit 1
    fi
  fi

  if [ ! $VAR(./remote/) == "" ]; then
    VXLAN_GROUP="remote $VAR(./remote/@)"
  fi

  if [ -z "$VXLAN_GROUP" ]; then
    echo "group or remote must be configured."
    exit 1
  fi

  if [ ! $VAR(./remote-port/) == "" ]; then
    VXLAN_PORT="dstport $VAR(./remote-port/@)"
  fi

  sudo ip link add name $VAR(@) type vxlan \
	$VXLAN_VNI $VXLAN_GROUP $VXLAN_TTL $VXLAN_DEV $VXLAN_PORT
  sudo ip link set $VAR(@) up

  touch /tmp/vxlan-$VAR(@)-create

delete:
  if [ ! -e /sys/class/net/$VAR(@) ]; then
    echo "VXLAN interface \"$VAR(@)\" does not exist."
  else
    sudo ip link del dev $VAR(@)
  fi


end:
  if [ -e /tmp/vxlan-$VAR(@)-create ]; then
    rm /tmp/vxlan-$VAR(@)-create
  fi