vxlan: add options to enable and disable UDP checksums
[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 [ -z "$peeraddr" ] && {
59 proto_notify_error "$cfg" "MISSING_ADDRESS"
60 proto_block_restart "$cfg"
61 exit
62 }
63
64 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
65
66 [ -z "$ipaddr" ] && {
67 local wanif="$tunlink"
68 if [ -z "$wanif" ] && ! network_find_wan wanif; then
69 proto_notify_error "$cfg" "NO_WAN_LINK"
70 exit
71 fi
72
73 if ! network_get_ipaddr ipaddr "$wanif"; then
74 proto_notify_error "$cfg" "NO_WAN_LINK"
75 exit
76 fi
77 }
78
79 vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
80 }
81
82 proto_vxlan6_setup() {
83 local cfg="$1"
84
85 local ip6addr peer6addr
86 json_get_vars ip6addr peer6addr tunlink
87
88 [ -z "$peer6addr" ] && {
89 proto_notify_error "$cfg" "MISSING_ADDRESS"
90 proto_block_restart "$cfg"
91 exit
92 }
93
94 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
95
96 [ -z "$ip6addr" ] && {
97 local wanif="$tunlink"
98 if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
99 proto_notify_error "$cfg" "NO_WAN_LINK"
100 exit
101 fi
102
103 if ! network_get_ipaddr6 ip6addr "$wanif"; then
104 proto_notify_error "$cfg" "NO_WAN_LINK"
105 exit
106 fi
107 }
108
109 vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
110 }
111
112 proto_vxlan_teardown() {
113 local cfg="$1"
114 }
115
116 proto_vxlan6_teardown() {
117 local cfg="$1"
118 }
119
120 vxlan_generic_init_config() {
121 no_device=1
122 available=1
123
124 proto_config_add_string "tunlink"
125 proto_config_add_string "zone"
126
127 proto_config_add_int "vid"
128 proto_config_add_int "port"
129 proto_config_add_int "ttl"
130 proto_config_add_int "tos"
131 proto_config_add_int "mtu"
132 proto_config_add_string "macaddr"
133 }
134
135 proto_vxlan_init_config() {
136 vxlan_generic_init_config
137 proto_config_add_string "ipaddr"
138 proto_config_add_string "peeraddr"
139 }
140
141 proto_vxlan6_init_config() {
142 vxlan_generic_init_config
143 proto_config_add_string "ip6addr"
144 proto_config_add_string "peer6addr"
145 }
146
147 [ -n "$INCLUDE_ONLY" ] || {
148 add_protocol vxlan
149 add_protocol vxlan6
150 }