]>
Commit | Line | Data |
---|---|---|
1ce2de97 ND |
1 | /* |
2 | * link_iptnl.c ipip and sit driver module | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Nicolas Dichtel <nicolas.dichtel@6wind.com> | |
10 | * | |
11 | */ | |
12 | ||
13 | #include <string.h> | |
14 | #include <net/if.h> | |
15 | #include <sys/types.h> | |
16 | #include <sys/socket.h> | |
17 | #include <arpa/inet.h> | |
18 | ||
f005b700 | 19 | #include <linux/in.h> |
1ce2de97 ND |
20 | #include <linux/ip.h> |
21 | #include <linux/if_tunnel.h> | |
22 | #include "rt_names.h" | |
23 | #include "utils.h" | |
24 | #include "ip_common.h" | |
25 | #include "tunnel.h" | |
26 | ||
06e3975f SP |
27 | static void iptunnel_print_help(struct link_util *lu, int argc, char **argv, |
28 | FILE *f) | |
1ce2de97 | 29 | { |
06e3975f | 30 | const char *mode; |
8b471354 PS |
31 | |
32 | fprintf(f, | |
06e3975f SP |
33 | "Usage: ... %-6s [ remote ADDR ]\n", |
34 | lu->id | |
35 | ); | |
36 | fprintf(f, | |
37 | " [ local ADDR ]\n" | |
38 | " [ ttl TTL ]\n" | |
39 | " [ tos TOS ]\n" | |
40 | " [ [no]pmtudisc ]\n" | |
41 | " [ 6rd-prefix ADDR ]\n" | |
42 | " [ 6rd-relay_prefix ADDR ]\n" | |
43 | " [ 6rd-reset ]\n" | |
44 | " [ dev PHYS_DEV ]\n" | |
45 | " [ fwmark MARK ]\n" | |
46 | " [ external ]\n" | |
47 | " [ noencap ]\n" | |
48 | " [ encap { fou | gue | none } ]\n" | |
49 | " [ encap-sport PORT ]\n" | |
50 | " [ encap-dport PORT ]\n" | |
51 | " [ [no]encap-csum ]\n" | |
52 | " [ [no]encap-csum6 ]\n" | |
53 | " [ [no]encap-remcsum ]\n" | |
8b471354 | 54 | ); |
06e3975f SP |
55 | if (strcmp(lu->id, "sit") == 0) { |
56 | mode = "{ ip6ip | ipip | mplsip | any } ]\n" | |
57 | " [ isatap"; | |
288c28bc | 58 | } else { |
06e3975f | 59 | mode = "{ ipip | mplsip | any }"; |
77620be8 | 60 | } |
06e3975f SP |
61 | fprintf(f, |
62 | " [ mode %s ]\n" | |
63 | "\n", | |
64 | mode | |
65 | ); | |
66 | fprintf(f, | |
67 | "Where: ADDR := { IP_ADDRESS | any }\n" | |
68 | " TOS := { NUMBER | inherit }\n" | |
69 | " TTL := { 1..255 | inherit }\n" | |
70 | " MARK := { 0x0..0xffffffff }\n" | |
71 | ); | |
1ce2de97 ND |
72 | } |
73 | ||
74 | static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv, | |
75 | struct nlmsghdr *n) | |
76 | { | |
28254695 | 77 | struct ifinfomsg *ifi = NLMSG_DATA(n); |
1ce2de97 ND |
78 | struct { |
79 | struct nlmsghdr n; | |
80 | struct ifinfomsg i; | |
d17b136f PS |
81 | } req = { |
82 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)), | |
83 | .n.nlmsg_flags = NLM_F_REQUEST, | |
84 | .n.nlmsg_type = RTM_GETLINK, | |
85 | .i.ifi_family = preferred_family, | |
86 | .i.ifi_index = ifi->ifi_index, | |
87 | }; | |
08ede25f | 88 | struct nlmsghdr *answer; |
1ce2de97 ND |
89 | struct rtattr *tb[IFLA_MAX + 1]; |
90 | struct rtattr *linkinfo[IFLA_INFO_MAX+1]; | |
91 | struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1]; | |
92 | int len; | |
7bda9fd3 | 93 | inet_prefix saddr, daddr, ip6rdprefix, ip6rdrelayprefix; |
1ce2de97 | 94 | __u8 pmtudisc = 1; |
5bd93795 | 95 | __u8 tos = 0; |
1ce2de97 | 96 | __u16 iflags = 0; |
5bd93795 | 97 | __u8 ttl = 0; |
5bd93795 SP |
98 | __u8 proto = 0; |
99 | __u32 link = 0; | |
c1159152 TH |
100 | __u16 encaptype = 0; |
101 | __u16 encapflags = 0; | |
102 | __u16 encapsport = 0; | |
103 | __u16 encapdport = 0; | |
4bfe6825 | 104 | __u8 metadata = 0; |
ad4b1425 | 105 | __u32 fwmark = 0; |
1ce2de97 | 106 | |
7bda9fd3 SP |
107 | inet_prefix_reset(&saddr); |
108 | inet_prefix_reset(&daddr); | |
109 | ||
110 | inet_prefix_reset(&ip6rdprefix); | |
111 | inet_prefix_reset(&ip6rdrelayprefix); | |
112 | ||
1ce2de97 | 113 | if (!(n->nlmsg_flags & NLM_F_CREATE)) { |
7bda9fd3 SP |
114 | const struct rtattr *rta; |
115 | ||
86bf43c7 | 116 | if (rtnl_talk(&rth, &req.n, &answer) < 0) { |
1ce2de97 ND |
117 | get_failed: |
118 | fprintf(stderr, | |
119 | "Failed to get existing tunnel info.\n"); | |
120 | return -1; | |
121 | } | |
122 | ||
86bf43c7 | 123 | len = answer->nlmsg_len; |
1ce2de97 ND |
124 | len -= NLMSG_LENGTH(sizeof(*ifi)); |
125 | if (len < 0) | |
126 | goto get_failed; | |
127 | ||
86bf43c7 | 128 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len); |
1ce2de97 ND |
129 | |
130 | if (!tb[IFLA_LINKINFO]) | |
131 | goto get_failed; | |
132 | ||
133 | parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]); | |
134 | ||
135 | if (!linkinfo[IFLA_INFO_DATA]) | |
136 | goto get_failed; | |
137 | ||
138 | parse_rtattr_nested(iptuninfo, IFLA_IPTUN_MAX, | |
139 | linkinfo[IFLA_INFO_DATA]); | |
140 | ||
7bda9fd3 SP |
141 | rta = iptuninfo[IFLA_IPTUN_LOCAL]; |
142 | if (rta && get_addr_rta(&saddr, rta, AF_INET)) | |
143 | goto get_failed; | |
144 | ||
145 | rta = iptuninfo[IFLA_IPTUN_REMOTE]; | |
146 | if (rta && get_addr_rta(&daddr, rta, AF_INET)) | |
147 | goto get_failed; | |
148 | ||
149 | rta = iptuninfo[IFLA_IPTUN_6RD_PREFIX]; | |
150 | if (rta && get_addr_rta(&ip6rdprefix, rta, AF_INET6)) | |
151 | goto get_failed; | |
152 | ||
153 | rta = iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIX]; | |
154 | if (rta && get_addr_rta(&ip6rdrelayprefix, rta, AF_INET)) | |
155 | goto get_failed; | |
156 | ||
157 | rta = iptuninfo[IFLA_IPTUN_6RD_PREFIXLEN]; | |
158 | ip6rdprefix.bitlen = rta ? rta_getattr_u16(rta) : 0; | |
1ce2de97 | 159 | |
7bda9fd3 SP |
160 | rta = iptuninfo[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]; |
161 | ip6rdrelayprefix.bitlen = rta ? rta_getattr_u16(rta) : 0; | |
1ce2de97 ND |
162 | |
163 | if (iptuninfo[IFLA_IPTUN_TTL]) | |
164 | ttl = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TTL]); | |
165 | ||
1ce2de97 ND |
166 | if (iptuninfo[IFLA_IPTUN_PMTUDISC]) |
167 | pmtudisc = | |
168 | rta_getattr_u8(iptuninfo[IFLA_IPTUN_PMTUDISC]); | |
169 | ||
5bd93795 SP |
170 | if (iptuninfo[IFLA_IPTUN_TOS]) |
171 | tos = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TOS]); | |
172 | ||
1ce2de97 ND |
173 | if (iptuninfo[IFLA_IPTUN_FLAGS]) |
174 | iflags = rta_getattr_u16(iptuninfo[IFLA_IPTUN_FLAGS]); | |
175 | ||
176 | if (iptuninfo[IFLA_IPTUN_LINK]) | |
177 | link = rta_getattr_u32(iptuninfo[IFLA_IPTUN_LINK]); | |
178 | ||
77620be8 ND |
179 | if (iptuninfo[IFLA_IPTUN_PROTO]) |
180 | proto = rta_getattr_u8(iptuninfo[IFLA_IPTUN_PROTO]); | |
181 | ||
c1159152 TH |
182 | if (iptuninfo[IFLA_IPTUN_ENCAP_TYPE]) |
183 | encaptype = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_TYPE]); | |
184 | if (iptuninfo[IFLA_IPTUN_ENCAP_FLAGS]) | |
185 | encapflags = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_FLAGS]); | |
186 | if (iptuninfo[IFLA_IPTUN_ENCAP_SPORT]) | |
187 | encapsport = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_SPORT]); | |
188 | if (iptuninfo[IFLA_IPTUN_ENCAP_DPORT]) | |
189 | encapdport = rta_getattr_u16(iptuninfo[IFLA_IPTUN_ENCAP_DPORT]); | |
7bda9fd3 | 190 | |
4bfe6825 AS |
191 | if (iptuninfo[IFLA_IPTUN_COLLECT_METADATA]) |
192 | metadata = 1; | |
ad4b1425 CG |
193 | |
194 | if (iptuninfo[IFLA_IPTUN_FWMARK]) | |
195 | fwmark = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FWMARK]); | |
196 | ||
86bf43c7 | 197 | free(answer); |
1ce2de97 ND |
198 | } |
199 | ||
200 | while (argc > 0) { | |
5bd93795 SP |
201 | if (strcmp(*argv, "mode") == 0) { |
202 | NEXT_ARG(); | |
203 | if (strcmp(lu->id, "sit") == 0 && | |
204 | (strcmp(*argv, "ipv6/ipv4") == 0 || | |
205 | strcmp(*argv, "ip6ip") == 0)) | |
206 | proto = IPPROTO_IPV6; | |
207 | else if (strcmp(*argv, "ipv4/ipv4") == 0 || | |
208 | strcmp(*argv, "ipip") == 0 || | |
209 | strcmp(*argv, "ip4ip4") == 0) | |
210 | proto = IPPROTO_IPIP; | |
211 | else if (strcmp(*argv, "mpls/ipv4") == 0 || | |
212 | strcmp(*argv, "mplsip") == 0) | |
213 | proto = IPPROTO_MPLS; | |
214 | else if (strcmp(*argv, "any/ipv4") == 0 || | |
215 | strcmp(*argv, "any") == 0) | |
216 | proto = 0; | |
217 | else | |
218 | invarg("Cannot guess tunnel mode.", *argv); | |
219 | } else if (strcmp(*argv, "remote") == 0) { | |
1ce2de97 | 220 | NEXT_ARG(); |
7bda9fd3 | 221 | get_addr(&daddr, *argv, AF_INET); |
1ce2de97 ND |
222 | } else if (strcmp(*argv, "local") == 0) { |
223 | NEXT_ARG(); | |
7bda9fd3 | 224 | get_addr(&saddr, *argv, AF_INET); |
1ce2de97 ND |
225 | } else if (matches(*argv, "dev") == 0) { |
226 | NEXT_ARG(); | |
7a14358b | 227 | link = ll_name_to_index(*argv); |
fe99adbc SP |
228 | if (!link) |
229 | exit(nodev(*argv)); | |
1ce2de97 | 230 | } else if (strcmp(*argv, "ttl") == 0 || |
c4743c4d SP |
231 | strcmp(*argv, "hoplimit") == 0 || |
232 | strcmp(*argv, "hlim") == 0) { | |
1ce2de97 ND |
233 | NEXT_ARG(); |
234 | if (strcmp(*argv, "inherit") != 0) { | |
235 | if (get_u8(&ttl, *argv, 0)) | |
236 | invarg("invalid TTL\n", *argv); | |
237 | } else | |
238 | ttl = 0; | |
239 | } else if (strcmp(*argv, "tos") == 0 || | |
240 | strcmp(*argv, "tclass") == 0 || | |
5bd93795 | 241 | strcmp(*argv, "tc") == 0 || |
1ce2de97 ND |
242 | matches(*argv, "dsfield") == 0) { |
243 | __u32 uval; | |
56f5daac | 244 | |
1ce2de97 ND |
245 | NEXT_ARG(); |
246 | if (strcmp(*argv, "inherit") != 0) { | |
247 | if (rtnl_dsfield_a2n(&uval, *argv)) | |
248 | invarg("bad TOS value", *argv); | |
249 | tos = uval; | |
250 | } else | |
251 | tos = 1; | |
252 | } else if (strcmp(*argv, "nopmtudisc") == 0) { | |
253 | pmtudisc = 0; | |
254 | } else if (strcmp(*argv, "pmtudisc") == 0) { | |
255 | pmtudisc = 1; | |
256 | } else if (strcmp(lu->id, "sit") == 0 && | |
257 | strcmp(*argv, "isatap") == 0) { | |
258 | iflags |= SIT_ISATAP; | |
c1159152 TH |
259 | } else if (strcmp(*argv, "noencap") == 0) { |
260 | encaptype = TUNNEL_ENCAP_NONE; | |
261 | } else if (strcmp(*argv, "encap") == 0) { | |
262 | NEXT_ARG(); | |
263 | if (strcmp(*argv, "fou") == 0) | |
264 | encaptype = TUNNEL_ENCAP_FOU; | |
265 | else if (strcmp(*argv, "gue") == 0) | |
266 | encaptype = TUNNEL_ENCAP_GUE; | |
267 | else if (strcmp(*argv, "none") == 0) | |
268 | encaptype = TUNNEL_ENCAP_NONE; | |
269 | else | |
270 | invarg("Invalid encap type.", *argv); | |
271 | } else if (strcmp(*argv, "encap-sport") == 0) { | |
272 | NEXT_ARG(); | |
273 | if (strcmp(*argv, "auto") == 0) | |
274 | encapsport = 0; | |
275 | else if (get_u16(&encapsport, *argv, 0)) | |
276 | invarg("Invalid source port.", *argv); | |
277 | } else if (strcmp(*argv, "encap-dport") == 0) { | |
278 | NEXT_ARG(); | |
279 | if (get_u16(&encapdport, *argv, 0)) | |
280 | invarg("Invalid destination port.", *argv); | |
281 | } else if (strcmp(*argv, "encap-csum") == 0) { | |
282 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM; | |
283 | } else if (strcmp(*argv, "noencap-csum") == 0) { | |
284 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM; | |
285 | } else if (strcmp(*argv, "encap-udp6-csum") == 0) { | |
286 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM6; | |
287 | } else if (strcmp(*argv, "noencap-udp6-csum") == 0) { | |
288 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6; | |
858dbb20 TH |
289 | } else if (strcmp(*argv, "encap-remcsum") == 0) { |
290 | encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM; | |
291 | } else if (strcmp(*argv, "noencap-remcsum") == 0) { | |
292 | encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM; | |
4bfe6825 AS |
293 | } else if (strcmp(*argv, "external") == 0) { |
294 | metadata = 1; | |
1ce2de97 | 295 | } else if (strcmp(*argv, "6rd-prefix") == 0) { |
1ce2de97 | 296 | NEXT_ARG(); |
7bda9fd3 | 297 | if (get_prefix(&ip6rdprefix, *argv, AF_INET6)) |
1ce2de97 | 298 | invarg("invalid 6rd_prefix\n", *argv); |
1ce2de97 | 299 | } else if (strcmp(*argv, "6rd-relay_prefix") == 0) { |
1ce2de97 | 300 | NEXT_ARG(); |
7bda9fd3 | 301 | if (get_prefix(&ip6rdrelayprefix, *argv, AF_INET)) |
1ce2de97 | 302 | invarg("invalid 6rd-relay_prefix\n", *argv); |
1ce2de97 | 303 | } else if (strcmp(*argv, "6rd-reset") == 0) { |
7bda9fd3 SP |
304 | get_prefix(&ip6rdprefix, "2002::/16", AF_INET6); |
305 | inet_prefix_reset(&ip6rdrelayprefix); | |
ad4b1425 CG |
306 | } else if (strcmp(*argv, "fwmark") == 0) { |
307 | NEXT_ARG(); | |
308 | if (get_u32(&fwmark, *argv, 0)) | |
309 | invarg("invalid fwmark\n", *argv); | |
06e3975f SP |
310 | } else { |
311 | iptunnel_print_help(lu, argc, argv, stderr); | |
312 | return -1; | |
313 | } | |
1ce2de97 ND |
314 | argc--, argv++; |
315 | } | |
316 | ||
317 | if (ttl && pmtudisc == 0) { | |
30d07e9e | 318 | fprintf(stderr, "ttl != 0 and nopmtudisc are incompatible\n"); |
1ce2de97 ND |
319 | exit(-1); |
320 | } | |
321 | ||
68a7f5ed | 322 | addattr8(n, 1024, IFLA_IPTUN_PROTO, proto); |
4bfe6825 AS |
323 | if (metadata) { |
324 | addattr_l(n, 1024, IFLA_IPTUN_COLLECT_METADATA, NULL, 0); | |
325 | return 0; | |
326 | } | |
327 | ||
fa1e658e | 328 | if (is_addrtype_inet_not_unspec(&saddr)) { |
7bda9fd3 SP |
329 | addattr_l(n, 1024, IFLA_IPTUN_LOCAL, |
330 | saddr.data, saddr.bytelen); | |
331 | } | |
fa1e658e | 332 | if (is_addrtype_inet_not_unspec(&daddr)) { |
7bda9fd3 SP |
333 | addattr_l(n, 1024, IFLA_IPTUN_REMOTE, |
334 | daddr.data, daddr.bytelen); | |
335 | } | |
1ce2de97 | 336 | addattr8(n, 1024, IFLA_IPTUN_PMTUDISC, pmtudisc); |
5bd93795 SP |
337 | addattr8(n, 1024, IFLA_IPTUN_TOS, tos); |
338 | addattr8(n, 1024, IFLA_IPTUN_TTL, ttl); | |
339 | addattr32(n, 1024, IFLA_IPTUN_LINK, link); | |
ad4b1425 | 340 | addattr32(n, 1024, IFLA_IPTUN_FWMARK, fwmark); |
c1159152 TH |
341 | |
342 | addattr16(n, 1024, IFLA_IPTUN_ENCAP_TYPE, encaptype); | |
343 | addattr16(n, 1024, IFLA_IPTUN_ENCAP_FLAGS, encapflags); | |
344 | addattr16(n, 1024, IFLA_IPTUN_ENCAP_SPORT, htons(encapsport)); | |
345 | addattr16(n, 1024, IFLA_IPTUN_ENCAP_DPORT, htons(encapdport)); | |
346 | ||
1ce2de97 ND |
347 | if (strcmp(lu->id, "sit") == 0) { |
348 | addattr16(n, 1024, IFLA_IPTUN_FLAGS, iflags); | |
7bda9fd3 | 349 | if (is_addrtype_inet(&ip6rdprefix)) { |
1ce2de97 | 350 | addattr_l(n, 1024, IFLA_IPTUN_6RD_PREFIX, |
7bda9fd3 | 351 | ip6rdprefix.data, ip6rdprefix.bytelen); |
1ce2de97 | 352 | addattr16(n, 1024, IFLA_IPTUN_6RD_PREFIXLEN, |
7bda9fd3 SP |
353 | ip6rdprefix.bitlen); |
354 | } | |
355 | if (is_addrtype_inet(&ip6rdrelayprefix)) { | |
1ce2de97 | 356 | addattr32(n, 1024, IFLA_IPTUN_6RD_RELAY_PREFIX, |
7bda9fd3 | 357 | ip6rdrelayprefix.data[0]); |
1ce2de97 | 358 | addattr16(n, 1024, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, |
7bda9fd3 | 359 | ip6rdrelayprefix.bitlen); |
1ce2de97 ND |
360 | } |
361 | } | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) | |
367 | { | |
1ce2de97 | 368 | char s2[64]; |
bad76e6b | 369 | __u16 prefixlen; |
375560c4 | 370 | __u8 ttl = 0; |
3caa526c | 371 | __u8 tos = 0; |
1ce2de97 ND |
372 | |
373 | if (!tb) | |
374 | return; | |
375 | ||
00ff4b8e SP |
376 | if (tb[IFLA_IPTUN_COLLECT_METADATA]) { |
377 | print_bool(PRINT_ANY, "external", "external", true); | |
378 | return; | |
379 | } | |
7b178324 | 380 | |
d9aefbc0 SP |
381 | if (tb[IFLA_IPTUN_PROTO]) { |
382 | switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) { | |
383 | case IPPROTO_IPIP: | |
384 | print_string(PRINT_ANY, "proto", "%s ", "ipip"); | |
385 | break; | |
386 | case IPPROTO_IPV6: | |
387 | print_string(PRINT_ANY, "proto", "%s ", "ip6ip"); | |
388 | break; | |
389 | case IPPROTO_MPLS: | |
390 | print_string(PRINT_ANY, "proto", "%s ", "mplsip"); | |
391 | break; | |
392 | case 0: | |
393 | print_string(PRINT_ANY, "proto", "%s ", "any"); | |
394 | break; | |
395 | } | |
396 | } | |
397 | ||
b761fc41 SP |
398 | tnl_print_endpoint("remote", tb[IFLA_IPTUN_REMOTE], AF_INET); |
399 | tnl_print_endpoint("local", tb[IFLA_IPTUN_LOCAL], AF_INET); | |
1ce2de97 | 400 | |
45d3a6ef | 401 | if (tb[IFLA_IPTUN_LINK]) { |
5bd93795 | 402 | __u32 link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]); |
1ce2de97 | 403 | |
45d3a6ef SP |
404 | if (link) { |
405 | print_string(PRINT_ANY, "link", "dev %s ", | |
406 | ll_index_to_name(link)); | |
407 | } | |
1ce2de97 ND |
408 | } |
409 | ||
375560c4 SP |
410 | if (tb[IFLA_IPTUN_TTL]) |
411 | ttl = rta_getattr_u8(tb[IFLA_IPTUN_TTL]); | |
412 | if (is_json_context() || ttl) | |
413 | print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl); | |
414 | else | |
2539a407 | 415 | print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); |
1ce2de97 | 416 | |
3caa526c SP |
417 | if (tb[IFLA_IPTUN_TOS]) |
418 | tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]); | |
419 | if (tos) { | |
420 | if (is_json_context() || tos != 1) | |
421 | print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); | |
422 | else | |
423 | print_string(PRINT_FP, NULL, "tos %s ", "inherit"); | |
1ce2de97 ND |
424 | } |
425 | ||
426 | if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC])) | |
2539a407 | 427 | print_bool(PRINT_ANY, "pmtudisc", "pmtudisc ", true); |
1ce2de97 | 428 | else |
2539a407 | 429 | print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false); |
1ce2de97 ND |
430 | |
431 | if (tb[IFLA_IPTUN_FLAGS]) { | |
195f0f62 | 432 | __u16 iflags = rta_getattr_u16(tb[IFLA_IPTUN_FLAGS]); |
1ce2de97 | 433 | |
195f0f62 | 434 | if (iflags & SIT_ISATAP) |
2539a407 | 435 | print_bool(PRINT_ANY, "isatap", "isatap ", true); |
1ce2de97 ND |
436 | } |
437 | ||
438 | if (tb[IFLA_IPTUN_6RD_PREFIXLEN] && | |
9f1370c0 | 439 | (prefixlen = rta_getattr_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]))) { |
1ce2de97 ND |
440 | __u16 relayprefixlen = |
441 | rta_getattr_u16(tb[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]); | |
442 | __u32 relayprefix = | |
443 | rta_getattr_u32(tb[IFLA_IPTUN_6RD_RELAY_PREFIX]); | |
444 | ||
2539a407 JF |
445 | const char *prefix = inet_ntop(AF_INET6, |
446 | RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]), | |
e97ad3d2 | 447 | s2, sizeof(s2)); |
2539a407 JF |
448 | |
449 | if (is_json_context()) { | |
450 | print_string(PRINT_JSON, "prefix", NULL, prefix); | |
451 | print_int(PRINT_JSON, "prefixlen", NULL, prefixlen); | |
452 | if (relayprefix) { | |
453 | print_string(PRINT_JSON, | |
454 | "relay_prefix", | |
455 | NULL, | |
456 | format_host(AF_INET, | |
457 | 4, | |
458 | &relayprefix)); | |
459 | print_int(PRINT_JSON, | |
460 | "relay_prefixlen", | |
461 | NULL, | |
462 | relayprefixlen); | |
463 | } | |
464 | } else { | |
465 | printf("6rd-prefix %s/%u ", prefix, prefixlen); | |
466 | if (relayprefix) { | |
467 | printf("6rd-relay_prefix %s/%u ", | |
468 | format_host(AF_INET, 4, &relayprefix), | |
469 | relayprefixlen); | |
470 | } | |
1ce2de97 ND |
471 | } |
472 | } | |
c1159152 | 473 | |
e97ad3d2 SP |
474 | if (tb[IFLA_IPTUN_FWMARK]) { |
475 | __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]); | |
476 | ||
477 | if (fwmark) { | |
478 | print_0xhex(PRINT_ANY, | |
479 | "fwmark", "fwmark 0x%x ", fwmark); | |
480 | } | |
481 | } | |
482 | ||
bad76e6b SP |
483 | tnl_print_encap(tb, |
484 | IFLA_IPTUN_ENCAP_TYPE, | |
485 | IFLA_IPTUN_ENCAP_FLAGS, | |
486 | IFLA_IPTUN_ENCAP_SPORT, | |
487 | IFLA_IPTUN_ENCAP_DPORT); | |
1ce2de97 ND |
488 | } |
489 | ||
490 | struct link_util ipip_link_util = { | |
491 | .id = "ipip", | |
492 | .maxattr = IFLA_IPTUN_MAX, | |
493 | .parse_opt = iptunnel_parse_opt, | |
494 | .print_opt = iptunnel_print_opt, | |
561e650e | 495 | .print_help = iptunnel_print_help, |
1ce2de97 ND |
496 | }; |
497 | ||
498 | struct link_util sit_link_util = { | |
499 | .id = "sit", | |
500 | .maxattr = IFLA_IPTUN_MAX, | |
501 | .parse_opt = iptunnel_parse_opt, | |
502 | .print_opt = iptunnel_print_opt, | |
561e650e | 503 | .print_help = iptunnel_print_help, |
1ce2de97 | 504 | }; |