bdcaa628c4416cc83258dd38a6fc0978ea55a3bb
[openwrt/openwrt.git] / package / network / config / vxlan / files / vxlan.sh
1 #!/bin/sh
2
3 [ -n "$INCLUDE_ONLY" ] || {
4 . /lib/functions.sh
5 . /lib/functions/network.sh
6 . ../netifd-proto.sh
7 init_proto "$@"
8 }
9
10 vxlan_generic_setup() {
11 local cfg="$1"
12 local mode="$2"
13 local local="$3"
14 local remote="$4"
15
16 local link="$cfg"
17
18 local port vid ttl tos mtu macaddr zone rxcsum txcsum
19 json_get_vars port vid ttl tos mtu macaddr zone rxcsum txcsum
20
21
22 proto_init_update "$link" 1
23
24 proto_add_tunnel
25 json_add_string mode "$mode"
26
27 [ -n "$tunlink" ] && json_add_string link "$tunlink"
28 [ -n "$local" ] && json_add_string local "$local"
29 [ -n "$remote" ] && json_add_string remote "$remote"
30
31 [ -n "$ttl" ] && json_add_int ttl "$ttl"
32 [ -n "$tos" ] && json_add_string tos "$tos"
33 [ -n "$mtu" ] && json_add_int mtu "$mtu"
34
35 json_add_object 'data'
36 [ -n "$port" ] && json_add_int port "$port"
37 [ -n "$vid" ] && json_add_int id "$vid"
38 [ -n "$macaddr" ] && json_add_string macaddr "$macaddr"
39 [ -n "$rxcsum" ] && json_add_boolean rxcsum "$rxcsum"
40 [ -n "$txcsum" ] && json_add_boolean txcsum "$txcsum"
41 json_close_object
42
43 proto_close_tunnel
44
45 proto_add_data
46 [ -n "$zone" ] && json_add_string zone "$zone"
47 proto_close_data
48
49 proto_send_update "$cfg"
50 }
51
52 proto_vxlan_setup() {
53 local cfg="$1"
54
55 local ipaddr peeraddr
56 json_get_vars ipaddr peeraddr tunlink
57
58 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
59
60 [ -z "$ipaddr" ] && {
61 local wanif="$tunlink"
62 if [ -z "$wanif" ] && ! network_find_wan wanif; then
63 proto_notify_error "$cfg" "NO_WAN_LINK"
64 exit
65 fi
66
67 if ! network_get_ipaddr ipaddr "$wanif"; then
68 proto_notify_error "$cfg" "NO_WAN_LINK"
69 exit
70 fi
71 }
72
73 vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
74 }
75
76 proto_vxlan6_setup() {
77 local cfg="$1"
78
79 local ip6addr peer6addr
80 json_get_vars ip6addr peer6addr tunlink
81
82 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
83
84 [ -z "$ip6addr" ] && {
85 local wanif="$tunlink"
86 if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
87 proto_notify_error "$cfg" "NO_WAN_LINK"
88 exit
89 fi
90
91 if ! network_get_ipaddr6 ip6addr "$wanif"; then
92 proto_notify_error "$cfg" "NO_WAN_LINK"
93 exit
94 fi
95 }
96
97 vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
98 }
99
100 proto_vxlan_teardown() {
101 local cfg="$1"
102 }
103
104 proto_vxlan6_teardown() {
105 local cfg="$1"
106 }
107
108 vxlan_generic_init_config() {
109 no_device=1
110 available=1
111
112 proto_config_add_string "tunlink"
113 proto_config_add_string "zone"
114
115 proto_config_add_int "vid"
116 proto_config_add_int "port"
117 proto_config_add_int "ttl"
118 proto_config_add_int "tos"
119 proto_config_add_int "mtu"
120 proto_config_add_boolean "rxcsum"
121 proto_config_add_boolean "txcsum"
122 proto_config_add_string "macaddr"
123 }
124
125 proto_vxlan_init_config() {
126 vxlan_generic_init_config
127 proto_config_add_string "ipaddr"
128 proto_config_add_string "peeraddr"
129 }
130
131 proto_vxlan6_init_config() {
132 vxlan_generic_init_config
133 proto_config_add_string "ip6addr"
134 proto_config_add_string "peer6addr"
135 }
136
137 [ -n "$INCLUDE_ONLY" ] || {
138 add_protocol vxlan
139 add_protocol vxlan6
140 }