]>
Commit | Line | Data |
---|---|---|
7951dea2 SS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
855ee1a1 | 6 | Copyright 2014 Susant Sahani |
7951dea2 SS |
7 | |
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
7951dea2 SS |
22 | #include <arpa/inet.h> |
23 | #include <net/if.h> | |
24 | #include <linux/ip.h> | |
25 | #include <linux/if_tunnel.h> | |
855ee1a1 | 26 | #include <linux/ip6_tunnel.h> |
7951dea2 | 27 | |
1c4baffc | 28 | #include "sd-netlink.h" |
07630cea LP |
29 | |
30 | #include "conf-parser.h" | |
31 | #include "missing.h" | |
0b1831c2 | 32 | #include "networkd-link.h" |
6bedfcbb LP |
33 | #include "networkd-netdev-tunnel.h" |
34 | #include "parse-util.h" | |
8b43440b | 35 | #include "string-table.h" |
07630cea | 36 | #include "string-util.h" |
7951dea2 SS |
37 | #include "util.h" |
38 | ||
855ee1a1 | 39 | #define DEFAULT_TNL_HOP_LIMIT 64 |
407af9dd | 40 | #define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF) |
855ee1a1 SS |
41 | |
42 | static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = { | |
43 | [NETDEV_IP6_TNL_MODE_IP6IP6] = "ip6ip6", | |
73b23bea | 44 | [NETDEV_IP6_TNL_MODE_IPIP6] = "ipip6", |
855ee1a1 SS |
45 | [NETDEV_IP6_TNL_MODE_ANYIP6] = "any", |
46 | }; | |
47 | ||
48 | DEFINE_STRING_TABLE_LOOKUP(ip6tnl_mode, Ip6TnlMode); | |
49 | DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode, "Failed to parse ip6 tunnel Mode"); | |
50 | ||
1c4baffc | 51 | static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 52 | Tunnel *t = IPIP(netdev); |
7951dea2 SS |
53 | int r; |
54 | ||
3be1d7e0 | 55 | assert(netdev); |
7951dea2 | 56 | assert(link); |
7951dea2 | 57 | assert(m); |
aa9f1140 TG |
58 | assert(t); |
59 | assert(t->family == AF_INET); | |
7951dea2 | 60 | |
1c4baffc | 61 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
62 | if (r < 0) |
63 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
7951dea2 | 64 | |
1c4baffc | 65 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); |
5289f3ff SS |
66 | if (r < 0) |
67 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
7951dea2 | 68 | |
1c4baffc | 69 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in); |
5289f3ff SS |
70 | if (r < 0) |
71 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
7951dea2 | 72 | |
1c4baffc | 73 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
74 | if (r < 0) |
75 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
9ae70211 | 76 | |
1c4baffc | 77 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
78 | if (r < 0) |
79 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m"); | |
9243e967 | 80 | |
7951dea2 SS |
81 | return r; |
82 | } | |
83 | ||
1c4baffc | 84 | static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 85 | Tunnel *t = SIT(netdev); |
abf446af SS |
86 | int r; |
87 | ||
3be1d7e0 | 88 | assert(netdev); |
abf446af | 89 | assert(link); |
abf446af | 90 | assert(m); |
aa9f1140 TG |
91 | assert(t); |
92 | assert(t->family == AF_INET); | |
abf446af | 93 | |
1c4baffc | 94 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
95 | if (r < 0) |
96 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
abf446af | 97 | |
1c4baffc | 98 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); |
5289f3ff SS |
99 | if (r < 0) |
100 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
abf446af | 101 | |
1c4baffc | 102 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in); |
5289f3ff SS |
103 | if (r < 0) |
104 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
abf446af | 105 | |
1c4baffc | 106 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
107 | if (r < 0) |
108 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
a9f434cf | 109 | |
1c4baffc | 110 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
111 | if (r < 0) |
112 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m"); | |
436b910f | 113 | |
abf446af SS |
114 | return r; |
115 | } | |
116 | ||
1c4baffc | 117 | static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
1af2536a | 118 | Tunnel *t; |
8bb088c5 SS |
119 | int r; |
120 | ||
3be1d7e0 | 121 | assert(netdev); |
1af2536a SS |
122 | |
123 | if (netdev->kind == NETDEV_KIND_GRE) | |
5289f3ff | 124 | t = GRE(netdev); |
1af2536a | 125 | else |
5289f3ff | 126 | t = GRETAP(netdev); |
1af2536a | 127 | |
aa9f1140 TG |
128 | assert(t); |
129 | assert(t->family == AF_INET); | |
1af2536a SS |
130 | assert(link); |
131 | assert(m); | |
8bb088c5 | 132 | |
1c4baffc | 133 | r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); |
5289f3ff SS |
134 | if (r < 0) |
135 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); | |
8bb088c5 | 136 | |
1c4baffc | 137 | r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in); |
5289f3ff SS |
138 | if (r < 0) |
139 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); | |
8bb088c5 | 140 | |
1c4baffc | 141 | r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in); |
5289f3ff SS |
142 | if (r < 0) |
143 | log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); | |
8bb088c5 | 144 | |
1c4baffc | 145 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); |
5289f3ff SS |
146 | if (r < 0) |
147 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); | |
8bb088c5 | 148 | |
1c4baffc | 149 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TOS, t->tos); |
5289f3ff SS |
150 | if (r < 0) |
151 | log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TOS attribute: %m"); | |
8bb088c5 | 152 | |
1c4baffc | 153 | r = sd_netlink_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
154 | if (r < 0) |
155 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_PMTUDISC attribute: %m"); | |
9243e967 | 156 | |
8bb088c5 SS |
157 | return r; |
158 | } | |
159 | ||
1c4baffc | 160 | static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
b16492f8 SS |
161 | Tunnel *t; |
162 | int r; | |
163 | ||
164 | assert(netdev); | |
165 | ||
166 | if (netdev->kind == NETDEV_KIND_IP6GRE) | |
5289f3ff | 167 | t = IP6GRE(netdev); |
b16492f8 | 168 | else |
5289f3ff | 169 | t = IP6GRETAP(netdev); |
b16492f8 SS |
170 | |
171 | assert(t); | |
172 | assert(t->family == AF_INET6); | |
173 | assert(link); | |
174 | assert(m); | |
175 | ||
1c4baffc | 176 | r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); |
5289f3ff SS |
177 | if (r < 0) |
178 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); | |
b16492f8 | 179 | |
1c4baffc | 180 | r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6); |
5289f3ff SS |
181 | if (r < 0) |
182 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); | |
b16492f8 | 183 | |
1c4baffc | 184 | r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6); |
5289f3ff SS |
185 | if (r < 0) |
186 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); | |
b16492f8 | 187 | |
1c4baffc | 188 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); |
5289f3ff SS |
189 | if (r < 0) |
190 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); | |
b16492f8 | 191 | |
54a9d20c SS |
192 | if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { |
193 | r = sd_netlink_message_append_u32(m, IFLA_GRE_FLOWINFO, t->ipv6_flowlabel); | |
194 | if (r < 0) | |
195 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLOWINFO attribute: %m"); | |
196 | } | |
197 | ||
198 | r = sd_netlink_message_append_u32(m, IFLA_GRE_FLAGS, t->flags); | |
199 | if (r < 0) | |
200 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLAGS attribute: %m"); | |
201 | ||
b16492f8 SS |
202 | return r; |
203 | } | |
204 | ||
1c4baffc | 205 | static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 206 | Tunnel *t = VTI(netdev); |
a613382b SS |
207 | int r; |
208 | ||
3be1d7e0 | 209 | assert(netdev); |
a613382b | 210 | assert(link); |
a613382b | 211 | assert(m); |
aa9f1140 TG |
212 | assert(t); |
213 | assert(t->family == AF_INET); | |
a613382b | 214 | |
1c4baffc | 215 | r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); |
5289f3ff SS |
216 | if (r < 0) |
217 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
a613382b | 218 | |
1c4baffc | 219 | r = sd_netlink_message_append_in_addr(m, IFLA_VTI_LOCAL, &t->local.in); |
5289f3ff SS |
220 | if (r < 0) |
221 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
a613382b | 222 | |
1c4baffc | 223 | r = sd_netlink_message_append_in_addr(m, IFLA_VTI_REMOTE, &t->remote.in); |
5289f3ff SS |
224 | if (r < 0) |
225 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
a613382b | 226 | |
a613382b SS |
227 | return r; |
228 | } | |
8bb088c5 | 229 | |
1c4baffc | 230 | static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
9011ce77 SS |
231 | Tunnel *t = VTI6(netdev); |
232 | int r; | |
233 | ||
234 | assert(netdev); | |
235 | assert(link); | |
236 | assert(m); | |
237 | assert(t); | |
238 | assert(t->family == AF_INET6); | |
239 | ||
1c4baffc | 240 | r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); |
9011ce77 SS |
241 | if (r < 0) |
242 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
243 | ||
1c4baffc | 244 | r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_LOCAL, &t->local.in6); |
9011ce77 SS |
245 | if (r < 0) |
246 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
247 | ||
1c4baffc | 248 | r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_REMOTE, &t->remote.in6); |
9011ce77 SS |
249 | if (r < 0) |
250 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
251 | ||
252 | return r; | |
253 | } | |
254 | ||
1c4baffc | 255 | static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
855ee1a1 SS |
256 | Tunnel *t = IP6TNL(netdev); |
257 | uint8_t proto; | |
258 | int r; | |
259 | ||
260 | assert(netdev); | |
261 | assert(link); | |
262 | assert(m); | |
263 | assert(t); | |
264 | assert(t->family == AF_INET6); | |
265 | ||
1c4baffc | 266 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
267 | if (r < 0) |
268 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
855ee1a1 | 269 | |
1c4baffc | 270 | r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6); |
5289f3ff SS |
271 | if (r < 0) |
272 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
855ee1a1 | 273 | |
1c4baffc | 274 | r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6); |
5289f3ff SS |
275 | if (r < 0) |
276 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
855ee1a1 | 277 | |
1c4baffc | 278 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
279 | if (r < 0) |
280 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
855ee1a1 | 281 | |
407af9dd SS |
282 | if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { |
283 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLOWINFO, t->ipv6_flowlabel); | |
284 | if (r < 0) | |
285 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLOWINFO attribute: %m"); | |
286 | } | |
287 | ||
a9b70f9d | 288 | if (t->copy_dscp) |
ec2a3e3a SS |
289 | t->flags |= IP6_TNL_F_RCV_DSCP_COPY; |
290 | ||
b4828886 SS |
291 | if (t->encap_limit != IPV6_DEFAULT_TNL_ENCAP_LIMIT) { |
292 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_ENCAP_LIMIT, t->encap_limit); | |
293 | if (r < 0) | |
294 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_LIMIT attribute: %m"); | |
295 | } | |
296 | ||
407af9dd SS |
297 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLAGS, t->flags); |
298 | if (r < 0) | |
299 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m"); | |
300 | ||
855ee1a1 SS |
301 | switch (t->ip6tnl_mode) { |
302 | case NETDEV_IP6_TNL_MODE_IP6IP6: | |
303 | proto = IPPROTO_IPV6; | |
304 | break; | |
305 | case NETDEV_IP6_TNL_MODE_IPIP6: | |
306 | proto = IPPROTO_IPIP; | |
307 | break; | |
308 | case NETDEV_IP6_TNL_MODE_ANYIP6: | |
309 | default: | |
310 | proto = 0; | |
311 | break; | |
312 | } | |
313 | ||
1c4baffc | 314 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto); |
5289f3ff SS |
315 | if (r < 0) |
316 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_MODE attribute: %m"); | |
855ee1a1 SS |
317 | |
318 | return r; | |
319 | } | |
320 | ||
3be1d7e0 | 321 | static int netdev_tunnel_verify(NetDev *netdev, const char *filename) { |
aa9f1140 TG |
322 | Tunnel *t = NULL; |
323 | ||
7951dea2 | 324 | assert(netdev); |
3be1d7e0 | 325 | assert(filename); |
7951dea2 | 326 | |
aa9f1140 TG |
327 | switch (netdev->kind) { |
328 | case NETDEV_KIND_IPIP: | |
329 | t = IPIP(netdev); | |
330 | break; | |
331 | case NETDEV_KIND_SIT: | |
332 | t = SIT(netdev); | |
333 | break; | |
334 | case NETDEV_KIND_GRE: | |
335 | t = GRE(netdev); | |
336 | break; | |
1af2536a SS |
337 | case NETDEV_KIND_GRETAP: |
338 | t = GRETAP(netdev); | |
339 | break; | |
b16492f8 SS |
340 | case NETDEV_KIND_IP6GRE: |
341 | t = IP6GRE(netdev); | |
342 | break; | |
343 | case NETDEV_KIND_IP6GRETAP: | |
344 | t = IP6GRETAP(netdev); | |
345 | break; | |
aa9f1140 TG |
346 | case NETDEV_KIND_VTI: |
347 | t = VTI(netdev); | |
348 | break; | |
9011ce77 SS |
349 | case NETDEV_KIND_VTI6: |
350 | t = VTI6(netdev); | |
351 | break; | |
855ee1a1 SS |
352 | case NETDEV_KIND_IP6TNL: |
353 | t = IP6TNL(netdev); | |
354 | break; | |
aa9f1140 TG |
355 | default: |
356 | assert_not_reached("Invalid tunnel kind"); | |
357 | } | |
358 | ||
359 | assert(t); | |
360 | ||
aa9f1140 | 361 | if (t->remote.in.s_addr == INADDR_ANY) { |
5289f3ff SS |
362 | log_warning("Tunnel without remote address configured in %s. Ignoring", filename); |
363 | return -EINVAL; | |
7951dea2 SS |
364 | } |
365 | ||
855ee1a1 | 366 | if (t->family != AF_INET && t->family != AF_INET6) { |
5289f3ff SS |
367 | log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename); |
368 | return -EINVAL; | |
7951dea2 SS |
369 | } |
370 | ||
855ee1a1 SS |
371 | if (netdev->kind == NETDEV_KIND_IP6TNL) { |
372 | if (t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) { | |
373 | log_warning("IP6 Tunnel without mode configured in %s. Ignoring", filename); | |
374 | return -EINVAL; | |
375 | } | |
376 | } | |
377 | ||
7951dea2 SS |
378 | return 0; |
379 | } | |
6ef892fc TG |
380 | |
381 | int config_parse_tunnel_address(const char *unit, | |
382 | const char *filename, | |
383 | unsigned line, | |
384 | const char *section, | |
385 | unsigned section_line, | |
386 | const char *lvalue, | |
387 | int ltype, | |
388 | const char *rvalue, | |
389 | void *data, | |
390 | void *userdata) { | |
aa9f1140 | 391 | Tunnel *t = userdata; |
44e7b949 LP |
392 | union in_addr_union *addr = data, buffer; |
393 | int r, f; | |
6ef892fc TG |
394 | |
395 | assert(filename); | |
396 | assert(lvalue); | |
397 | assert(rvalue); | |
398 | assert(data); | |
399 | ||
44e7b949 | 400 | r = in_addr_from_string_auto(rvalue, &f, &buffer); |
6ef892fc | 401 | if (r < 0) { |
12ca818f | 402 | log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel address is invalid, ignoring assignment: %s", rvalue); |
6ef892fc TG |
403 | return 0; |
404 | } | |
405 | ||
44e7b949 | 406 | if (t->family != AF_UNSPEC && t->family != f) { |
12ca818f | 407 | log_syntax(unit, LOG_ERR, filename, line, 0, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue); |
44e7b949 LP |
408 | return 0; |
409 | } | |
410 | ||
411 | t->family = f; | |
412 | *addr = buffer; | |
413 | ||
6ef892fc TG |
414 | return 0; |
415 | } | |
3be1d7e0 | 416 | |
407af9dd SS |
417 | int config_parse_ipv6_flowlabel(const char* unit, |
418 | const char *filename, | |
419 | unsigned line, | |
420 | const char *section, | |
421 | unsigned section_line, | |
422 | const char *lvalue, | |
423 | int ltype, | |
424 | const char *rvalue, | |
425 | void *data, | |
426 | void *userdata) { | |
427 | IPv6FlowLabel *ipv6_flowlabel = data; | |
428 | Tunnel *t = userdata; | |
407af9dd SS |
429 | int k = 0; |
430 | int r; | |
431 | ||
432 | assert(filename); | |
433 | assert(lvalue); | |
434 | assert(rvalue); | |
435 | assert(ipv6_flowlabel); | |
436 | ||
6870b415 | 437 | if (streq(rvalue, "inherit")) { |
407af9dd SS |
438 | *ipv6_flowlabel = IP6_FLOWINFO_FLOWLABEL; |
439 | t->flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL; | |
440 | } else { | |
6870b415 | 441 | r = config_parse_int(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata); |
12ca818f LP |
442 | if (r < 0) |
443 | return r; | |
444 | ||
445 | if (k > 0xFFFFF) | |
446 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPv6 flowlabel option, ignoring: %s", rvalue); | |
447 | else { | |
448 | *ipv6_flowlabel = htonl(k) & IP6_FLOWINFO_FLOWLABEL; | |
449 | t->flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL; | |
407af9dd SS |
450 | } |
451 | } | |
452 | ||
453 | return 0; | |
454 | } | |
455 | ||
b4828886 SS |
456 | int config_parse_encap_limit(const char* unit, |
457 | const char *filename, | |
458 | unsigned line, | |
459 | const char *section, | |
460 | unsigned section_line, | |
461 | const char *lvalue, | |
462 | int ltype, | |
463 | const char *rvalue, | |
464 | void *data, | |
465 | void *userdata) { | |
466 | Tunnel *t = userdata; | |
467 | int k = 0; | |
468 | int r; | |
469 | ||
470 | assert(filename); | |
471 | assert(lvalue); | |
472 | assert(rvalue); | |
473 | ||
474 | if (streq(rvalue, "none")) | |
475 | t->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT; | |
476 | else { | |
477 | r = safe_atoi(rvalue, &k); | |
478 | if (r < 0) { | |
12ca818f | 479 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Tunnel Encapsulation Limit option, ignoring: %s", rvalue); |
b4828886 SS |
480 | return 0; |
481 | } | |
482 | ||
483 | if (k > 255 || k < 0) | |
12ca818f | 484 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid Tunnel Encapsulation value, ignoring: %d", k); |
b4828886 SS |
485 | else { |
486 | t->encap_limit = k; | |
487 | t->flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT; | |
488 | } | |
489 | } | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
aa9f1140 TG |
494 | static void ipip_init(NetDev *n) { |
495 | Tunnel *t = IPIP(n); | |
496 | ||
497 | assert(n); | |
498 | assert(t); | |
499 | ||
500 | t->pmtudisc = true; | |
501 | } | |
502 | ||
503 | static void sit_init(NetDev *n) { | |
504 | Tunnel *t = SIT(n); | |
505 | ||
506 | assert(n); | |
507 | assert(t); | |
508 | ||
509 | t->pmtudisc = true; | |
510 | } | |
511 | ||
512 | static void vti_init(NetDev *n) { | |
7185d805 | 513 | Tunnel *t; |
aa9f1140 TG |
514 | |
515 | assert(n); | |
9011ce77 SS |
516 | |
517 | if (n->kind == NETDEV_KIND_VTI) | |
7185d805 | 518 | t = VTI(n); |
9011ce77 SS |
519 | else |
520 | t = VTI6(n); | |
521 | ||
aa9f1140 TG |
522 | assert(t); |
523 | ||
524 | t->pmtudisc = true; | |
525 | } | |
526 | ||
527 | static void gre_init(NetDev *n) { | |
1af2536a | 528 | Tunnel *t; |
aa9f1140 TG |
529 | |
530 | assert(n); | |
1af2536a SS |
531 | |
532 | if (n->kind == NETDEV_KIND_GRE) | |
533 | t = GRE(n); | |
534 | else | |
535 | t = GRETAP(n); | |
536 | ||
aa9f1140 TG |
537 | assert(t); |
538 | ||
539 | t->pmtudisc = true; | |
540 | } | |
541 | ||
b16492f8 SS |
542 | static void ip6gre_init(NetDev *n) { |
543 | Tunnel *t; | |
544 | ||
545 | assert(n); | |
546 | ||
547 | if (n->kind == NETDEV_KIND_IP6GRE) | |
548 | t = IP6GRE(n); | |
549 | else | |
550 | t = IP6GRETAP(n); | |
551 | ||
552 | assert(t); | |
553 | ||
554 | t->ttl = DEFAULT_TNL_HOP_LIMIT; | |
555 | } | |
556 | ||
855ee1a1 SS |
557 | static void ip6tnl_init(NetDev *n) { |
558 | Tunnel *t = IP6TNL(n); | |
559 | ||
560 | assert(n); | |
561 | assert(t); | |
562 | ||
563 | t->ttl = DEFAULT_TNL_HOP_LIMIT; | |
564 | t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT; | |
565 | t->ip6tnl_mode = _NETDEV_IP6_TNL_MODE_INVALID; | |
407af9dd | 566 | t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID; |
855ee1a1 SS |
567 | } |
568 | ||
3be1d7e0 | 569 | const NetDevVTable ipip_vtable = { |
aa9f1140 TG |
570 | .object_size = sizeof(Tunnel), |
571 | .init = ipip_init, | |
572 | .sections = "Match\0NetDev\0Tunnel\0", | |
573 | .fill_message_create = netdev_ipip_fill_message_create, | |
574 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
575 | .config_verify = netdev_tunnel_verify, |
576 | }; | |
577 | ||
578 | const NetDevVTable sit_vtable = { | |
aa9f1140 TG |
579 | .object_size = sizeof(Tunnel), |
580 | .init = sit_init, | |
581 | .sections = "Match\0NetDev\0Tunnel\0", | |
582 | .fill_message_create = netdev_sit_fill_message_create, | |
583 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
584 | .config_verify = netdev_tunnel_verify, |
585 | }; | |
586 | ||
587 | const NetDevVTable vti_vtable = { | |
aa9f1140 TG |
588 | .object_size = sizeof(Tunnel), |
589 | .init = vti_init, | |
590 | .sections = "Match\0NetDev\0Tunnel\0", | |
591 | .fill_message_create = netdev_vti_fill_message_create, | |
592 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
593 | .config_verify = netdev_tunnel_verify, |
594 | }; | |
595 | ||
9011ce77 SS |
596 | const NetDevVTable vti6_vtable = { |
597 | .object_size = sizeof(Tunnel), | |
598 | .init = vti_init, | |
599 | .sections = "Match\0NetDev\0Tunnel\0", | |
600 | .fill_message_create = netdev_vti6_fill_message_create, | |
601 | .create_type = NETDEV_CREATE_STACKED, | |
602 | .config_verify = netdev_tunnel_verify, | |
603 | }; | |
604 | ||
3be1d7e0 | 605 | const NetDevVTable gre_vtable = { |
aa9f1140 TG |
606 | .object_size = sizeof(Tunnel), |
607 | .init = gre_init, | |
608 | .sections = "Match\0NetDev\0Tunnel\0", | |
609 | .fill_message_create = netdev_gre_fill_message_create, | |
610 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
611 | .config_verify = netdev_tunnel_verify, |
612 | }; | |
1af2536a SS |
613 | |
614 | const NetDevVTable gretap_vtable = { | |
615 | .object_size = sizeof(Tunnel), | |
616 | .init = gre_init, | |
617 | .sections = "Match\0NetDev\0Tunnel\0", | |
618 | .fill_message_create = netdev_gre_fill_message_create, | |
619 | .create_type = NETDEV_CREATE_STACKED, | |
620 | .config_verify = netdev_tunnel_verify, | |
621 | }; | |
855ee1a1 | 622 | |
b16492f8 SS |
623 | const NetDevVTable ip6gre_vtable = { |
624 | .object_size = sizeof(Tunnel), | |
625 | .init = ip6gre_init, | |
626 | .sections = "Match\0NetDev\0Tunnel\0", | |
627 | .fill_message_create = netdev_ip6gre_fill_message_create, | |
628 | .create_type = NETDEV_CREATE_STACKED, | |
629 | .config_verify = netdev_tunnel_verify, | |
630 | }; | |
631 | ||
632 | const NetDevVTable ip6gretap_vtable = { | |
633 | .object_size = sizeof(Tunnel), | |
634 | .init = ip6gre_init, | |
635 | .sections = "Match\0NetDev\0Tunnel\0", | |
636 | .fill_message_create = netdev_ip6gre_fill_message_create, | |
637 | .create_type = NETDEV_CREATE_STACKED, | |
638 | .config_verify = netdev_tunnel_verify, | |
639 | }; | |
640 | ||
855ee1a1 SS |
641 | const NetDevVTable ip6tnl_vtable = { |
642 | .object_size = sizeof(Tunnel), | |
643 | .init = ip6tnl_init, | |
644 | .sections = "Match\0NetDev\0Tunnel\0", | |
645 | .fill_message_create = netdev_ip6tnl_fill_message_create, | |
646 | .create_type = NETDEV_CREATE_STACKED, | |
647 | .config_verify = netdev_tunnel_verify, | |
648 | }; |