vxlan: add capability for multiple fdb entries
[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 proto_vxlan_setup_peer() {
11 type bridge &> /dev/null || {
12 proto_notify_error "$cfg" "MISSING_BRIDGE_COMMAND"
13 exit
14 }
15
16 local peer_config="$1"
17
18 local vxlan
19 local lladdr
20 local dst
21 local src_vni
22 local vni
23 local port
24 local via
25
26 config_get vxlan "${peer_config}" "vxlan"
27 config_get lladdr "${peer_config}" "lladdr"
28 config_get dst "${peer_config}" "dst"
29 config_get src_vni "${peer_config}" "src_vni"
30 config_get vni "${peer_config}" "vni"
31 config_get port "${peer_config}" "port"
32 config_get via "${peer_config}" "via"
33
34 [ "$cfg" = "$vxlan" ] || {
35 # This peer section belongs to another device
36 return
37 }
38
39 [ -n "${dst}" ] || {
40 proto_notify_error "$cfg" "MISSING_PEER_ADDRESS"
41 exit
42 }
43
44 bridge fdb append \
45 ${lladdr:-00:00:00:00:00:00} \
46 dev ${cfg} \
47 dst ${dst} \
48 ${src_vni:+src_vni $src_vni} \
49 ${vni:+vni $vni} \
50 ${port:+port $port} \
51 ${via:+via $via}
52 }
53
54 vxlan_generic_setup() {
55 local cfg="$1"
56 local mode="$2"
57 local local="$3"
58 local remote="$4"
59
60 local link="$cfg"
61
62 local port vid ttl tos mtu macaddr zone rxcsum txcsum
63 json_get_vars port vid ttl tos mtu macaddr zone rxcsum txcsum
64
65 proto_init_update "$link" 1
66
67 proto_add_tunnel
68 json_add_string mode "$mode"
69
70 [ -n "$tunlink" ] && json_add_string link "$tunlink"
71 [ -n "$local" ] && json_add_string local "$local"
72 [ -n "$remote" ] && json_add_string remote "$remote"
73
74 [ -n "$ttl" ] && json_add_int ttl "$ttl"
75 [ -n "$tos" ] && json_add_string tos "$tos"
76 [ -n "$mtu" ] && json_add_int mtu "$mtu"
77
78 json_add_object 'data'
79 [ -n "$port" ] && json_add_int port "$port"
80 [ -n "$vid" ] && json_add_int id "$vid"
81 [ -n "$macaddr" ] && json_add_string macaddr "$macaddr"
82 [ -n "$rxcsum" ] && json_add_boolean rxcsum "$rxcsum"
83 [ -n "$txcsum" ] && json_add_boolean txcsum "$txcsum"
84 json_close_object
85
86 proto_close_tunnel
87
88 proto_add_data
89 [ -n "$zone" ] && json_add_string zone "$zone"
90 proto_close_data
91
92 proto_send_update "$cfg"
93
94 config_load network
95 config_foreach proto_vxlan_setup_peer "vxlan_peer"
96 }
97
98 proto_vxlan_setup() {
99 local cfg="$1"
100
101 local ipaddr peeraddr
102 json_get_vars ipaddr peeraddr tunlink
103
104 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
105
106 [ -z "$ipaddr" ] && {
107 local wanif="$tunlink"
108 if [ -z "$wanif" ] && ! network_find_wan wanif; then
109 proto_notify_error "$cfg" "NO_WAN_LINK"
110 exit
111 fi
112
113 if ! network_get_ipaddr ipaddr "$wanif"; then
114 proto_notify_error "$cfg" "NO_WAN_LINK"
115 exit
116 fi
117 }
118
119 vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
120 }
121
122 proto_vxlan6_setup() {
123 local cfg="$1"
124
125 local ip6addr peer6addr
126 json_get_vars ip6addr peer6addr tunlink
127
128 ( proto_add_host_dependency "$cfg" '' "$tunlink" )
129
130 [ -z "$ip6addr" ] && {
131 local wanif="$tunlink"
132 if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
133 proto_notify_error "$cfg" "NO_WAN_LINK"
134 exit
135 fi
136
137 if ! network_get_ipaddr6 ip6addr "$wanif"; then
138 proto_notify_error "$cfg" "NO_WAN_LINK"
139 exit
140 fi
141 }
142
143 vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
144 }
145
146 proto_vxlan_teardown() {
147 local cfg="$1"
148 }
149
150 proto_vxlan6_teardown() {
151 local cfg="$1"
152 }
153
154 vxlan_generic_init_config() {
155 no_device=1
156 available=1
157
158 proto_config_add_string "tunlink"
159 proto_config_add_string "zone"
160
161 proto_config_add_int "vid"
162 proto_config_add_int "port"
163 proto_config_add_int "ttl"
164 proto_config_add_int "tos"
165 proto_config_add_int "mtu"
166 proto_config_add_boolean "rxcsum"
167 proto_config_add_boolean "txcsum"
168 proto_config_add_string "macaddr"
169 }
170
171 proto_vxlan_init_config() {
172 vxlan_generic_init_config
173 proto_config_add_string "ipaddr"
174 proto_config_add_string "peeraddr"
175 }
176
177 proto_vxlan6_init_config() {
178 vxlan_generic_init_config
179 proto_config_add_string "ip6addr"
180 proto_config_add_string "peer6addr"
181 }
182
183 [ -n "$INCLUDE_ONLY" ] || {
184 add_protocol vxlan
185 add_protocol vxlan6
186 }