]>
Commit | Line | Data |
---|---|---|
30eb304e JP |
1 | /* |
2 | * f_flower.c Flower Classifier | |
3 | * | |
4 | * This program is free software; you can distribute 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: Jiri Pirko <jiri@resnulli.us> | |
10 | */ | |
11 | ||
12 | #include <stdio.h> | |
13 | #include <stdlib.h> | |
14 | #include <unistd.h> | |
30eb304e JP |
15 | #include <string.h> |
16 | #include <net/if.h> | |
f888f4e2 | 17 | #include <linux/if_arp.h> |
30eb304e JP |
18 | #include <linux/if_ether.h> |
19 | #include <linux/ip.h> | |
745d9172 | 20 | #include <linux/tc_act/tc_vlan.h> |
7638ee13 | 21 | #include <linux/mpls.h> |
30eb304e JP |
22 | |
23 | #include "utils.h" | |
24 | #include "tc_util.h" | |
25 | #include "rt_names.h" | |
26 | ||
08f66c80 PB |
27 | enum flower_matching_flags { |
28 | FLOWER_IP_FLAGS, | |
29 | }; | |
30 | ||
6910d656 SH |
31 | enum flower_endpoint { |
32 | FLOWER_ENDPOINT_SRC, | |
33 | FLOWER_ENDPOINT_DST | |
34 | }; | |
35 | ||
eb3b5696 SH |
36 | enum flower_icmp_field { |
37 | FLOWER_ICMP_FIELD_TYPE, | |
38 | FLOWER_ICMP_FIELD_CODE | |
39 | }; | |
40 | ||
30eb304e JP |
41 | static void explain(void) |
42 | { | |
512caeb2 | 43 | fprintf(stderr, |
ac6a4c22 | 44 | "Usage: ... flower [ MATCH-LIST ] [ verbose ]\n" |
512caeb2 SH |
45 | " [ skip_sw | skip_hw ]\n" |
46 | " [ action ACTION-SPEC ] [ classid CLASSID ]\n" | |
47 | "\n" | |
48 | "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n" | |
49 | " MATCH := { indev DEV-NAME |\n" | |
50 | " vlan_id VID |\n" | |
51 | " vlan_prio PRIORITY |\n" | |
52 | " vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n" | |
1f0a5dfd JL |
53 | " cvlan_id VID |\n" |
54 | " cvlan_prio PRIORITY |\n" | |
55 | " cvlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n" | |
c2078f8d SH |
56 | " dst_mac MASKED-LLADDR |\n" |
57 | " src_mac MASKED-LLADDR |\n" | |
eb3b5696 | 58 | " ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n" |
6ea2c2b1 OG |
59 | " ip_tos MASKED-IP_TOS |\n" |
60 | " ip_ttl MASKED-IP_TTL |\n" | |
7638ee13 BL |
61 | " mpls_label LABEL |\n" |
62 | " mpls_tc TC |\n" | |
63 | " mpls_bos BOS |\n" | |
64 | " mpls_ttl TTL |\n" | |
b2a1f740 SH |
65 | " dst_ip PREFIX |\n" |
66 | " src_ip PREFIX |\n" | |
512caeb2 | 67 | " dst_port PORT-NUMBER |\n" |
bb9b63b1 | 68 | " src_port PORT-NUMBER |\n" |
0c30d14d | 69 | " tcp_flags MASKED-TCP_FLAGS |\n" |
6374961a SH |
70 | " type MASKED-ICMP-TYPE |\n" |
71 | " code MASKED-ICMP-CODE |\n" | |
c7ec052b SH |
72 | " arp_tip IPV4-PREFIX |\n" |
73 | " arp_sip IPV4-PREFIX |\n" | |
f888f4e2 SH |
74 | " arp_op [ request | reply | OP ] |\n" |
75 | " arp_tha MASKED-LLADDR |\n" | |
76 | " arp_sha MASKED-LLADDR |\n" | |
10da5528 SH |
77 | " enc_dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n" |
78 | " enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n" | |
bf73c650 | 79 | " enc_key_id [ KEY-ID ] |\n" |
761ec9e2 OG |
80 | " enc_tos MASKED-IP_TOS |\n" |
81 | " enc_ttl MASKED-IP_TTL |\n" | |
56155d4d | 82 | " geneve_opts MASKED-OPTIONS |\n" |
08f66c80 | 83 | " ip_flags IP-FLAGS | \n" |
a5ae170e | 84 | " enc_dst_port [ port_number ] }\n" |
512caeb2 | 85 | " FILTERID := X:Y:Z\n" |
c2078f8d | 86 | " MASKED_LLADDR := { LLADDR | LLADDR/MASK | LLADDR/BITS }\n" |
512caeb2 SH |
87 | " ACTION-SPEC := ... look at individual actions\n" |
88 | "\n" | |
328374dc | 89 | "NOTE: CLASSID, IP-PROTO are parsed as hexadecimal input.\n" |
512caeb2 SH |
90 | "NOTE: There can be only used one mask per one prio. If user needs\n" |
91 | " to specify different mask, he has to use different prio.\n"); | |
30eb304e JP |
92 | } |
93 | ||
94 | static int flower_parse_eth_addr(char *str, int addr_type, int mask_type, | |
95 | struct nlmsghdr *n) | |
96 | { | |
c2078f8d SH |
97 | int ret, err = -1; |
98 | char addr[ETH_ALEN], *slash; | |
99 | ||
100 | slash = strchr(str, '/'); | |
101 | if (slash) | |
102 | *slash = '\0'; | |
30eb304e JP |
103 | |
104 | ret = ll_addr_a2n(addr, sizeof(addr), str); | |
105 | if (ret < 0) | |
c2078f8d | 106 | goto err; |
30eb304e | 107 | addattr_l(n, MAX_MSG, addr_type, addr, sizeof(addr)); |
c2078f8d SH |
108 | |
109 | if (slash) { | |
110 | unsigned bits; | |
111 | ||
112 | if (!get_unsigned(&bits, slash + 1, 10)) { | |
113 | uint64_t mask; | |
114 | ||
115 | /* Extra 16 bit shift to push mac address into | |
116 | * high bits of uint64_t | |
117 | */ | |
118 | mask = htonll(0xffffffffffffULL << (16 + 48 - bits)); | |
119 | memcpy(addr, &mask, ETH_ALEN); | |
120 | } else { | |
121 | ret = ll_addr_a2n(addr, sizeof(addr), slash + 1); | |
122 | if (ret < 0) | |
123 | goto err; | |
124 | } | |
125 | } else { | |
126 | memset(addr, 0xff, ETH_ALEN); | |
127 | } | |
30eb304e | 128 | addattr_l(n, MAX_MSG, mask_type, addr, sizeof(addr)); |
c2078f8d SH |
129 | |
130 | err = 0; | |
131 | err: | |
132 | if (slash) | |
133 | *slash = '/'; | |
134 | return err; | |
30eb304e JP |
135 | } |
136 | ||
1f0a5dfd JL |
137 | static bool eth_type_vlan(__be16 ethertype) |
138 | { | |
139 | return ethertype == htons(ETH_P_8021Q) || | |
140 | ethertype == htons(ETH_P_8021AD); | |
141 | } | |
142 | ||
745d9172 | 143 | static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type, |
512caeb2 SH |
144 | __be16 *p_vlan_eth_type, |
145 | struct nlmsghdr *n) | |
745d9172 HHZ |
146 | { |
147 | __be16 vlan_eth_type; | |
148 | ||
1f0a5dfd JL |
149 | if (!eth_type_vlan(eth_type)) { |
150 | fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD\n", | |
151 | type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype"); | |
745d9172 HHZ |
152 | return -1; |
153 | } | |
154 | ||
155 | if (ll_proto_a2n(&vlan_eth_type, str)) | |
156 | invarg("invalid vlan_ethtype", str); | |
157 | addattr16(n, MAX_MSG, type, vlan_eth_type); | |
158 | *p_vlan_eth_type = vlan_eth_type; | |
159 | return 0; | |
160 | } | |
161 | ||
08f66c80 PB |
162 | struct flag_to_string { |
163 | int flag; | |
164 | enum flower_matching_flags type; | |
165 | char *string; | |
166 | }; | |
22a8f019 | 167 | |
08f66c80 PB |
168 | static struct flag_to_string flags_str[] = { |
169 | { TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT, FLOWER_IP_FLAGS, "frag" }, | |
fb4e6abf | 170 | { TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST, FLOWER_IP_FLAGS, "firstfrag" }, |
08f66c80 | 171 | }; |
22a8f019 | 172 | |
08f66c80 PB |
173 | static int flower_parse_matching_flags(char *str, |
174 | enum flower_matching_flags type, | |
175 | __u32 *mtf, __u32 *mtf_mask) | |
176 | { | |
177 | char *token; | |
178 | bool no; | |
179 | bool found; | |
180 | int i; | |
22a8f019 | 181 | |
08f66c80 PB |
182 | token = strtok(str, "/"); |
183 | ||
184 | while (token) { | |
185 | if (!strncmp(token, "no", 2)) { | |
186 | no = true; | |
187 | token += 2; | |
188 | } else | |
189 | no = false; | |
190 | ||
191 | found = false; | |
192 | for (i = 0; i < ARRAY_SIZE(flags_str); i++) { | |
193 | if (type != flags_str[i].type) | |
194 | continue; | |
195 | ||
196 | if (!strcmp(token, flags_str[i].string)) { | |
197 | if (no) | |
198 | *mtf &= ~flags_str[i].flag; | |
199 | else | |
200 | *mtf |= flags_str[i].flag; | |
201 | ||
202 | *mtf_mask |= flags_str[i].flag; | |
203 | found = true; | |
204 | break; | |
205 | } | |
206 | } | |
207 | if (!found) | |
22a8f019 | 208 | return -1; |
08f66c80 PB |
209 | |
210 | token = strtok(NULL, "/"); | |
22a8f019 PB |
211 | } |
212 | ||
22a8f019 PB |
213 | return 0; |
214 | } | |
215 | ||
30eb304e JP |
216 | static int flower_parse_ip_proto(char *str, __be16 eth_type, int type, |
217 | __u8 *p_ip_proto, struct nlmsghdr *n) | |
218 | { | |
219 | int ret; | |
220 | __u8 ip_proto; | |
221 | ||
eb3b5696 SH |
222 | if (eth_type != htons(ETH_P_IP) && eth_type != htons(ETH_P_IPV6)) |
223 | goto err; | |
224 | ||
30eb304e JP |
225 | if (matches(str, "tcp") == 0) { |
226 | ip_proto = IPPROTO_TCP; | |
227 | } else if (matches(str, "udp") == 0) { | |
228 | ip_proto = IPPROTO_UDP; | |
a1fb0d48 SH |
229 | } else if (matches(str, "sctp") == 0) { |
230 | ip_proto = IPPROTO_SCTP; | |
eb3b5696 SH |
231 | } else if (matches(str, "icmp") == 0) { |
232 | if (eth_type != htons(ETH_P_IP)) | |
233 | goto err; | |
234 | ip_proto = IPPROTO_ICMP; | |
235 | } else if (matches(str, "icmpv6") == 0) { | |
236 | if (eth_type != htons(ETH_P_IPV6)) | |
237 | goto err; | |
238 | ip_proto = IPPROTO_ICMPV6; | |
30eb304e JP |
239 | } else { |
240 | ret = get_u8(&ip_proto, str, 16); | |
241 | if (ret) | |
242 | return -1; | |
243 | } | |
244 | addattr8(n, MAX_MSG, type, ip_proto); | |
245 | *p_ip_proto = ip_proto; | |
246 | return 0; | |
eb3b5696 SH |
247 | |
248 | err: | |
249 | fprintf(stderr, "Illegal \"eth_type\" for ip proto\n"); | |
250 | return -1; | |
30eb304e JP |
251 | } |
252 | ||
f888f4e2 SH |
253 | static int __flower_parse_ip_addr(char *str, int family, |
254 | int addr4_type, int mask4_type, | |
255 | int addr6_type, int mask6_type, | |
256 | struct nlmsghdr *n) | |
30eb304e JP |
257 | { |
258 | int ret; | |
259 | inet_prefix addr; | |
30eb304e JP |
260 | int bits; |
261 | int i; | |
262 | ||
30eb304e JP |
263 | ret = get_prefix(&addr, str, family); |
264 | if (ret) | |
265 | return -1; | |
266 | ||
bb9b63b1 AV |
267 | if (family && (addr.family != family)) { |
268 | fprintf(stderr, "Illegal \"eth_type\" for ip address\n"); | |
30eb304e | 269 | return -1; |
bb9b63b1 | 270 | } |
30eb304e JP |
271 | |
272 | addattr_l(n, MAX_MSG, addr.family == AF_INET ? addr4_type : addr6_type, | |
273 | addr.data, addr.bytelen); | |
274 | ||
275 | memset(addr.data, 0xff, addr.bytelen); | |
276 | bits = addr.bitlen; | |
277 | for (i = 0; i < addr.bytelen / 4; i++) { | |
278 | if (!bits) { | |
279 | addr.data[i] = 0; | |
280 | } else if (bits / 32 >= 1) { | |
281 | bits -= 32; | |
282 | } else { | |
283 | addr.data[i] <<= 32 - bits; | |
284 | addr.data[i] = htonl(addr.data[i]); | |
285 | bits = 0; | |
286 | } | |
287 | } | |
288 | ||
289 | addattr_l(n, MAX_MSG, addr.family == AF_INET ? mask4_type : mask6_type, | |
290 | addr.data, addr.bytelen); | |
291 | ||
292 | return 0; | |
293 | } | |
294 | ||
f888f4e2 SH |
295 | static int flower_parse_ip_addr(char *str, __be16 eth_type, |
296 | int addr4_type, int mask4_type, | |
297 | int addr6_type, int mask6_type, | |
298 | struct nlmsghdr *n) | |
299 | { | |
300 | int family; | |
301 | ||
302 | if (eth_type == htons(ETH_P_IP)) { | |
303 | family = AF_INET; | |
304 | } else if (eth_type == htons(ETH_P_IPV6)) { | |
305 | family = AF_INET6; | |
306 | } else if (!eth_type) { | |
307 | family = AF_UNSPEC; | |
308 | } else { | |
309 | return -1; | |
310 | } | |
311 | ||
164a9ff4 RD |
312 | return __flower_parse_ip_addr(str, family, addr4_type, mask4_type, |
313 | addr6_type, mask6_type, n); | |
f888f4e2 SH |
314 | } |
315 | ||
316 | static bool flower_eth_type_arp(__be16 eth_type) | |
317 | { | |
318 | return eth_type == htons(ETH_P_ARP) || eth_type == htons(ETH_P_RARP); | |
319 | } | |
320 | ||
321 | static int flower_parse_arp_ip_addr(char *str, __be16 eth_type, | |
322 | int addr_type, int mask_type, | |
323 | struct nlmsghdr *n) | |
324 | { | |
325 | if (!flower_eth_type_arp(eth_type)) | |
326 | return -1; | |
327 | ||
328 | return __flower_parse_ip_addr(str, AF_INET, addr_type, mask_type, | |
329 | TCA_FLOWER_UNSPEC, TCA_FLOWER_UNSPEC, n); | |
330 | } | |
331 | ||
180136e5 SH |
332 | static int flower_parse_u8(char *str, int value_type, int mask_type, |
333 | int (*value_from_name)(const char *str, | |
334 | __u8 *value), | |
335 | bool (*value_validate)(__u8 value), | |
336 | struct nlmsghdr *n) | |
f888f4e2 SH |
337 | { |
338 | char *slash; | |
339 | int ret, err = -1; | |
180136e5 | 340 | __u8 value, mask; |
f888f4e2 SH |
341 | |
342 | slash = strchr(str, '/'); | |
343 | if (slash) | |
344 | *slash = '\0'; | |
345 | ||
180136e5 SH |
346 | ret = value_from_name ? value_from_name(str, &value) : -1; |
347 | if (ret < 0) { | |
f888f4e2 SH |
348 | ret = get_u8(&value, str, 10); |
349 | if (ret) | |
350 | goto err; | |
f888f4e2 SH |
351 | } |
352 | ||
180136e5 SH |
353 | if (value_validate && !value_validate(value)) |
354 | goto err; | |
355 | ||
f888f4e2 SH |
356 | if (slash) { |
357 | ret = get_u8(&mask, slash + 1, 10); | |
358 | if (ret) | |
359 | goto err; | |
360 | } | |
361 | else { | |
362 | mask = UINT8_MAX; | |
363 | } | |
364 | ||
180136e5 | 365 | addattr8(n, MAX_MSG, value_type, value); |
f888f4e2 SH |
366 | addattr8(n, MAX_MSG, mask_type, mask); |
367 | ||
368 | err = 0; | |
369 | err: | |
370 | if (slash) | |
371 | *slash = '/'; | |
372 | return err; | |
373 | } | |
374 | ||
9d36e54f SH |
375 | static const char *flower_print_arp_op_to_name(__u8 op) |
376 | { | |
377 | switch (op) { | |
378 | case ARPOP_REQUEST: | |
379 | return "request"; | |
380 | case ARPOP_REPLY: | |
381 | return "reply"; | |
382 | default: | |
383 | return NULL; | |
384 | } | |
385 | } | |
386 | ||
180136e5 SH |
387 | static int flower_arp_op_from_name(const char *name, __u8 *op) |
388 | { | |
389 | if (!strcmp(name, "request")) | |
390 | *op = ARPOP_REQUEST; | |
391 | else if (!strcmp(name, "reply")) | |
392 | *op = ARPOP_REPLY; | |
393 | else | |
394 | return -1; | |
395 | ||
396 | return 0; | |
397 | } | |
398 | ||
399 | static bool flow_arp_op_validate(__u8 op) | |
400 | { | |
401 | return !op || op == ARPOP_REQUEST || op == ARPOP_REPLY; | |
402 | } | |
403 | ||
404 | static int flower_parse_arp_op(char *str, __be16 eth_type, | |
405 | int op_type, int mask_type, | |
406 | struct nlmsghdr *n) | |
407 | { | |
408 | if (!flower_eth_type_arp(eth_type)) | |
409 | return -1; | |
410 | ||
411 | return flower_parse_u8(str, op_type, mask_type, flower_arp_op_from_name, | |
412 | flow_arp_op_validate, n); | |
413 | } | |
414 | ||
eb3b5696 SH |
415 | static int flower_icmp_attr_type(__be16 eth_type, __u8 ip_proto, |
416 | enum flower_icmp_field field) | |
417 | { | |
418 | if (eth_type == htons(ETH_P_IP) && ip_proto == IPPROTO_ICMP) | |
419 | return field == FLOWER_ICMP_FIELD_CODE ? | |
420 | TCA_FLOWER_KEY_ICMPV4_CODE : | |
421 | TCA_FLOWER_KEY_ICMPV4_TYPE; | |
422 | else if (eth_type == htons(ETH_P_IPV6) && ip_proto == IPPROTO_ICMPV6) | |
423 | return field == FLOWER_ICMP_FIELD_CODE ? | |
424 | TCA_FLOWER_KEY_ICMPV6_CODE : | |
425 | TCA_FLOWER_KEY_ICMPV6_TYPE; | |
426 | ||
427 | return -1; | |
428 | } | |
429 | ||
6374961a SH |
430 | static int flower_icmp_attr_mask_type(__be16 eth_type, __u8 ip_proto, |
431 | enum flower_icmp_field field) | |
432 | { | |
433 | if (eth_type == htons(ETH_P_IP) && ip_proto == IPPROTO_ICMP) | |
434 | return field == FLOWER_ICMP_FIELD_CODE ? | |
435 | TCA_FLOWER_KEY_ICMPV4_CODE_MASK : | |
436 | TCA_FLOWER_KEY_ICMPV4_TYPE_MASK; | |
437 | else if (eth_type == htons(ETH_P_IPV6) && ip_proto == IPPROTO_ICMPV6) | |
438 | return field == FLOWER_ICMP_FIELD_CODE ? | |
439 | TCA_FLOWER_KEY_ICMPV6_CODE_MASK : | |
440 | TCA_FLOWER_KEY_ICMPV6_TYPE_MASK; | |
441 | ||
442 | return -1; | |
443 | } | |
444 | ||
eb3b5696 SH |
445 | static int flower_parse_icmp(char *str, __u16 eth_type, __u8 ip_proto, |
446 | enum flower_icmp_field field, struct nlmsghdr *n) | |
447 | { | |
6374961a | 448 | int value_type, mask_type; |
eb3b5696 | 449 | |
6374961a SH |
450 | value_type = flower_icmp_attr_type(eth_type, ip_proto, field); |
451 | mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto, field); | |
452 | if (value_type < 0 || mask_type < 0) | |
eb3b5696 SH |
453 | return -1; |
454 | ||
6374961a | 455 | return flower_parse_u8(str, value_type, mask_type, NULL, NULL, n); |
eb3b5696 SH |
456 | } |
457 | ||
6910d656 | 458 | static int flower_port_attr_type(__u8 ip_proto, enum flower_endpoint endpoint) |
30eb304e | 459 | { |
6bd5b80c | 460 | if (ip_proto == IPPROTO_TCP) |
6910d656 SH |
461 | return endpoint == FLOWER_ENDPOINT_SRC ? |
462 | TCA_FLOWER_KEY_TCP_SRC : | |
a1fb0d48 | 463 | TCA_FLOWER_KEY_TCP_DST; |
6bd5b80c | 464 | else if (ip_proto == IPPROTO_UDP) |
6910d656 SH |
465 | return endpoint == FLOWER_ENDPOINT_SRC ? |
466 | TCA_FLOWER_KEY_UDP_SRC : | |
a1fb0d48 | 467 | TCA_FLOWER_KEY_UDP_DST; |
6bd5b80c | 468 | else if (ip_proto == IPPROTO_SCTP) |
6910d656 SH |
469 | return endpoint == FLOWER_ENDPOINT_SRC ? |
470 | TCA_FLOWER_KEY_SCTP_SRC : | |
a1fb0d48 | 471 | TCA_FLOWER_KEY_SCTP_DST; |
6bd5b80c | 472 | else |
30eb304e | 473 | return -1; |
a1fb0d48 SH |
474 | } |
475 | ||
6910d656 SH |
476 | static int flower_parse_port(char *str, __u8 ip_proto, |
477 | enum flower_endpoint endpoint, | |
a1fb0d48 SH |
478 | struct nlmsghdr *n) |
479 | { | |
480 | int ret; | |
481 | int type; | |
482 | __be16 port; | |
483 | ||
6910d656 | 484 | type = flower_port_attr_type(ip_proto, endpoint); |
a1fb0d48 SH |
485 | if (type < 0) |
486 | return -1; | |
30eb304e | 487 | |
9f7401fa | 488 | ret = get_be16(&port, str, 10); |
30eb304e JP |
489 | if (ret) |
490 | return -1; | |
491 | ||
9f7401fa | 492 | addattr16(n, MAX_MSG, type, port); |
30eb304e JP |
493 | |
494 | return 0; | |
495 | } | |
496 | ||
0c30d14d JP |
497 | #define TCP_FLAGS_MAX_MASK 0xfff |
498 | ||
499 | static int flower_parse_tcp_flags(char *str, int flags_type, int mask_type, | |
500 | struct nlmsghdr *n) | |
501 | { | |
502 | char *slash; | |
503 | int ret, err = -1; | |
504 | __u16 flags; | |
505 | ||
506 | slash = strchr(str, '/'); | |
507 | if (slash) | |
508 | *slash = '\0'; | |
509 | ||
510 | ret = get_u16(&flags, str, 16); | |
511 | if (ret < 0 || flags & ~TCP_FLAGS_MAX_MASK) | |
512 | goto err; | |
513 | ||
514 | addattr16(n, MAX_MSG, flags_type, htons(flags)); | |
515 | ||
516 | if (slash) { | |
517 | ret = get_u16(&flags, slash + 1, 16); | |
518 | if (ret < 0 || flags & ~TCP_FLAGS_MAX_MASK) | |
519 | goto err; | |
520 | } else { | |
521 | flags = TCP_FLAGS_MAX_MASK; | |
522 | } | |
523 | addattr16(n, MAX_MSG, mask_type, htons(flags)); | |
524 | ||
525 | err = 0; | |
526 | err: | |
527 | if (slash) | |
528 | *slash = '/'; | |
529 | return err; | |
530 | } | |
531 | ||
6ea2c2b1 OG |
532 | static int flower_parse_ip_tos_ttl(char *str, int key_type, int mask_type, |
533 | struct nlmsghdr *n) | |
534 | { | |
535 | char *slash; | |
536 | int ret, err = -1; | |
537 | __u8 tos_ttl; | |
538 | ||
539 | slash = strchr(str, '/'); | |
540 | if (slash) | |
541 | *slash = '\0'; | |
542 | ||
543 | ret = get_u8(&tos_ttl, str, 10); | |
544 | if (ret < 0) | |
545 | ret = get_u8(&tos_ttl, str, 16); | |
546 | if (ret < 0) | |
547 | goto err; | |
548 | ||
549 | addattr8(n, MAX_MSG, key_type, tos_ttl); | |
550 | ||
551 | if (slash) { | |
552 | ret = get_u8(&tos_ttl, slash + 1, 16); | |
553 | if (ret < 0) | |
554 | goto err; | |
555 | } else { | |
556 | tos_ttl = 0xff; | |
557 | } | |
558 | addattr8(n, MAX_MSG, mask_type, tos_ttl); | |
559 | ||
560 | err = 0; | |
561 | err: | |
562 | if (slash) | |
563 | *slash = '/'; | |
564 | return err; | |
565 | } | |
566 | ||
bb9b63b1 AV |
567 | static int flower_parse_key_id(const char *str, int type, struct nlmsghdr *n) |
568 | { | |
569 | int ret; | |
570 | __be32 key_id; | |
571 | ||
572 | ret = get_be32(&key_id, str, 10); | |
573 | if (!ret) | |
574 | addattr32(n, MAX_MSG, type, key_id); | |
575 | ||
576 | return ret; | |
577 | } | |
578 | ||
41aa17ff HHZ |
579 | static int flower_parse_enc_port(char *str, int type, struct nlmsghdr *n) |
580 | { | |
581 | int ret; | |
582 | __be16 port; | |
583 | ||
584 | ret = get_be16(&port, str, 10); | |
585 | if (ret) | |
586 | return -1; | |
587 | ||
588 | addattr16(n, MAX_MSG, type, port); | |
589 | ||
590 | return 0; | |
591 | } | |
592 | ||
56155d4d PJV |
593 | static int flower_parse_geneve_opts(char *str, struct nlmsghdr *n) |
594 | { | |
595 | struct rtattr *nest; | |
596 | char *token; | |
597 | int i, err; | |
598 | ||
599 | nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_GENEVE); | |
600 | ||
601 | i = 1; | |
602 | token = strsep(&str, ":"); | |
603 | while (token) { | |
604 | switch (i) { | |
605 | case TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS: | |
606 | { | |
607 | __be16 opt_class; | |
608 | ||
609 | if (!strlen(token)) | |
610 | break; | |
611 | err = get_be16(&opt_class, token, 16); | |
612 | if (err) | |
613 | return err; | |
614 | ||
615 | addattr16(n, MAX_MSG, i, opt_class); | |
616 | break; | |
617 | } | |
618 | case TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE: | |
619 | { | |
620 | __u8 opt_type; | |
621 | ||
622 | if (!strlen(token)) | |
623 | break; | |
624 | err = get_u8(&opt_type, token, 16); | |
625 | if (err) | |
626 | return err; | |
627 | ||
628 | addattr8(n, MAX_MSG, i, opt_type); | |
629 | break; | |
630 | } | |
631 | case TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA: | |
632 | { | |
633 | size_t token_len = strlen(token); | |
634 | __u8 *opts; | |
635 | ||
636 | if (!token_len) | |
637 | break; | |
638 | opts = malloc(token_len / 2); | |
639 | if (!opts) | |
640 | return -1; | |
641 | if (hex2mem(token, opts, token_len / 2) < 0) { | |
642 | free(opts); | |
643 | return -1; | |
644 | } | |
645 | addattr_l(n, MAX_MSG, i, opts, token_len / 2); | |
646 | free(opts); | |
647 | ||
648 | break; | |
649 | } | |
650 | default: | |
651 | fprintf(stderr, "Unknown \"geneve_opts\" type\n"); | |
652 | return -1; | |
653 | } | |
654 | ||
655 | token = strsep(&str, ":"); | |
656 | i++; | |
657 | } | |
658 | addattr_nest_end(n, nest); | |
659 | ||
660 | return 0; | |
661 | } | |
662 | ||
663 | static int flower_parse_enc_opt_part(char *str, struct nlmsghdr *n) | |
664 | { | |
665 | char *token; | |
666 | int err; | |
667 | ||
668 | token = strsep(&str, ","); | |
669 | while (token) { | |
670 | err = flower_parse_geneve_opts(token, n); | |
671 | if (err) | |
672 | return err; | |
673 | ||
674 | token = strsep(&str, ","); | |
675 | } | |
676 | ||
677 | return 0; | |
678 | } | |
679 | ||
680 | static int flower_check_enc_opt_key(char *key) | |
681 | { | |
682 | int key_len, col_cnt = 0; | |
683 | ||
684 | key_len = strlen(key); | |
685 | while ((key = strchr(key, ':'))) { | |
686 | if (strlen(key) == key_len) | |
687 | return -1; | |
688 | ||
689 | key_len = strlen(key) - 1; | |
690 | col_cnt++; | |
691 | key++; | |
692 | } | |
693 | ||
694 | if (col_cnt != 2 || !key_len) | |
695 | return -1; | |
696 | ||
697 | return 0; | |
698 | } | |
699 | ||
700 | static int flower_parse_enc_opts(char *str, struct nlmsghdr *n) | |
701 | { | |
702 | char key[XATTR_SIZE_MAX], mask[XATTR_SIZE_MAX]; | |
703 | int data_len, key_len, mask_len, err; | |
704 | char *token, *slash; | |
705 | struct rtattr *nest; | |
706 | ||
707 | key_len = 0; | |
708 | mask_len = 0; | |
709 | token = strsep(&str, ","); | |
710 | while (token) { | |
711 | slash = strchr(token, '/'); | |
712 | if (slash) | |
713 | *slash = '\0'; | |
714 | ||
715 | if ((key_len + strlen(token) > XATTR_SIZE_MAX) || | |
716 | flower_check_enc_opt_key(token)) | |
717 | return -1; | |
718 | ||
719 | strcpy(&key[key_len], token); | |
720 | key_len += strlen(token) + 1; | |
721 | key[key_len - 1] = ','; | |
722 | ||
723 | if (!slash) { | |
724 | /* Pad out mask when not provided */ | |
725 | if (mask_len + strlen(token) > XATTR_SIZE_MAX) | |
726 | return -1; | |
727 | ||
728 | data_len = strlen(rindex(token, ':')); | |
729 | sprintf(&mask[mask_len], "ffff:ff:"); | |
730 | mask_len += 8; | |
731 | memset(&mask[mask_len], 'f', data_len - 1); | |
732 | mask_len += data_len; | |
733 | mask[mask_len - 1] = ','; | |
734 | token = strsep(&str, ","); | |
735 | continue; | |
736 | } | |
737 | ||
738 | if (mask_len + strlen(slash + 1) > XATTR_SIZE_MAX) | |
739 | return -1; | |
740 | ||
741 | strcpy(&mask[mask_len], slash + 1); | |
742 | mask_len += strlen(slash + 1) + 1; | |
743 | mask[mask_len - 1] = ','; | |
744 | ||
745 | *slash = '/'; | |
746 | token = strsep(&str, ","); | |
747 | } | |
748 | key[key_len - 1] = '\0'; | |
749 | mask[mask_len - 1] = '\0'; | |
750 | ||
751 | nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS); | |
752 | err = flower_parse_enc_opt_part(key, n); | |
753 | if (err) | |
754 | return err; | |
755 | addattr_nest_end(n, nest); | |
756 | ||
757 | nest = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_ENC_OPTS_MASK); | |
758 | err = flower_parse_enc_opt_part(mask, n); | |
759 | if (err) | |
760 | return err; | |
761 | addattr_nest_end(n, nest); | |
762 | ||
763 | return 0; | |
764 | } | |
765 | ||
30eb304e JP |
766 | static int flower_parse_opt(struct filter_util *qu, char *handle, |
767 | int argc, char **argv, struct nlmsghdr *n) | |
768 | { | |
769 | int ret; | |
770 | struct tcmsg *t = NLMSG_DATA(n); | |
771 | struct rtattr *tail; | |
488b41d0 | 772 | __be16 eth_type = TC_H_MIN(t->tcm_info); |
745d9172 | 773 | __be16 vlan_ethtype = 0; |
1f0a5dfd | 774 | __be16 cvlan_ethtype = 0; |
30eb304e | 775 | __u8 ip_proto = 0xff; |
cfcabf18 | 776 | __u32 flags = 0; |
08f66c80 PB |
777 | __u32 mtf = 0; |
778 | __u32 mtf_mask = 0; | |
30eb304e | 779 | |
30eb304e JP |
780 | if (handle) { |
781 | ret = get_u32(&t->tcm_handle, handle, 0); | |
782 | if (ret) { | |
783 | fprintf(stderr, "Illegal \"handle\"\n"); | |
784 | return -1; | |
785 | } | |
786 | } | |
787 | ||
788 | tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)); | |
789 | addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0); | |
790 | ||
488b41d0 JHS |
791 | if (argc == 0) { |
792 | /*at minimal we will match all ethertype packets */ | |
793 | goto parse_done; | |
794 | } | |
795 | ||
30eb304e JP |
796 | while (argc > 0) { |
797 | if (matches(*argv, "classid") == 0 || | |
798 | matches(*argv, "flowid") == 0) { | |
32a121cb | 799 | unsigned int handle; |
30eb304e JP |
800 | |
801 | NEXT_ARG(); | |
802 | ret = get_tc_classid(&handle, *argv); | |
803 | if (ret) { | |
804 | fprintf(stderr, "Illegal \"classid\"\n"); | |
805 | return -1; | |
806 | } | |
807 | addattr_l(n, MAX_MSG, TCA_FLOWER_CLASSID, &handle, 4); | |
0d575c4d AN |
808 | } else if (matches(*argv, "hw_tc") == 0) { |
809 | unsigned int handle; | |
810 | __u32 tc; | |
811 | char *end; | |
812 | ||
813 | NEXT_ARG(); | |
814 | tc = strtoul(*argv, &end, 0); | |
815 | if (*end) { | |
816 | fprintf(stderr, "Illegal TC index\n"); | |
817 | return -1; | |
818 | } | |
819 | if (tc >= TC_QOPT_MAX_QUEUE) { | |
820 | fprintf(stderr, "TC index exceeds max range\n"); | |
821 | return -1; | |
822 | } | |
823 | handle = TC_H_MAKE(TC_H_MAJ(t->tcm_parent), | |
824 | TC_H_MIN(tc + TC_H_MIN_PRIORITY)); | |
825 | addattr_l(n, MAX_MSG, TCA_FLOWER_CLASSID, &handle, | |
826 | sizeof(handle)); | |
08f66c80 | 827 | } else if (matches(*argv, "ip_flags") == 0) { |
22a8f019 PB |
828 | NEXT_ARG(); |
829 | ret = flower_parse_matching_flags(*argv, | |
08f66c80 PB |
830 | FLOWER_IP_FLAGS, |
831 | &mtf, | |
832 | &mtf_mask); | |
22a8f019 | 833 | if (ret < 0) { |
08f66c80 | 834 | fprintf(stderr, "Illegal \"ip_flags\"\n"); |
22a8f019 PB |
835 | return -1; |
836 | } | |
ac6a4c22 MRL |
837 | } else if (matches(*argv, "verbose") == 0) { |
838 | flags |= TCA_CLS_FLAGS_VERBOSE; | |
cfcabf18 AV |
839 | } else if (matches(*argv, "skip_hw") == 0) { |
840 | flags |= TCA_CLS_FLAGS_SKIP_HW; | |
841 | } else if (matches(*argv, "skip_sw") == 0) { | |
842 | flags |= TCA_CLS_FLAGS_SKIP_SW; | |
30eb304e | 843 | } else if (matches(*argv, "indev") == 0) { |
30eb304e | 844 | NEXT_ARG(); |
625df645 PS |
845 | if (check_ifname(*argv)) |
846 | invarg("\"indev\" not a valid ifname", *argv); | |
ee474849 | 847 | addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, *argv); |
745d9172 HHZ |
848 | } else if (matches(*argv, "vlan_id") == 0) { |
849 | __u16 vid; | |
850 | ||
851 | NEXT_ARG(); | |
1f0a5dfd JL |
852 | if (!eth_type_vlan(eth_type)) { |
853 | fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD\n"); | |
745d9172 HHZ |
854 | return -1; |
855 | } | |
856 | ret = get_u16(&vid, *argv, 10); | |
857 | if (ret < 0 || vid & ~0xfff) { | |
858 | fprintf(stderr, "Illegal \"vlan_id\"\n"); | |
859 | return -1; | |
860 | } | |
861 | addattr16(n, MAX_MSG, TCA_FLOWER_KEY_VLAN_ID, vid); | |
862 | } else if (matches(*argv, "vlan_prio") == 0) { | |
863 | __u8 vlan_prio; | |
864 | ||
865 | NEXT_ARG(); | |
1f0a5dfd JL |
866 | if (!eth_type_vlan(eth_type)) { |
867 | fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD\n"); | |
745d9172 HHZ |
868 | return -1; |
869 | } | |
870 | ret = get_u8(&vlan_prio, *argv, 10); | |
871 | if (ret < 0 || vlan_prio & ~0x7) { | |
872 | fprintf(stderr, "Illegal \"vlan_prio\"\n"); | |
873 | return -1; | |
874 | } | |
512caeb2 SH |
875 | addattr8(n, MAX_MSG, |
876 | TCA_FLOWER_KEY_VLAN_PRIO, vlan_prio); | |
745d9172 HHZ |
877 | } else if (matches(*argv, "vlan_ethtype") == 0) { |
878 | NEXT_ARG(); | |
879 | ret = flower_parse_vlan_eth_type(*argv, eth_type, | |
512caeb2 SH |
880 | TCA_FLOWER_KEY_VLAN_ETH_TYPE, |
881 | &vlan_ethtype, n); | |
745d9172 HHZ |
882 | if (ret < 0) |
883 | return -1; | |
1f0a5dfd JL |
884 | } else if (matches(*argv, "cvlan_id") == 0) { |
885 | __u16 vid; | |
886 | ||
887 | NEXT_ARG(); | |
888 | if (!eth_type_vlan(vlan_ethtype)) { | |
889 | fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n"); | |
890 | return -1; | |
891 | } | |
892 | ret = get_u16(&vid, *argv, 10); | |
893 | if (ret < 0 || vid & ~0xfff) { | |
894 | fprintf(stderr, "Illegal \"cvlan_id\"\n"); | |
895 | return -1; | |
896 | } | |
897 | addattr16(n, MAX_MSG, TCA_FLOWER_KEY_CVLAN_ID, vid); | |
898 | } else if (matches(*argv, "cvlan_prio") == 0) { | |
899 | __u8 cvlan_prio; | |
900 | ||
901 | NEXT_ARG(); | |
902 | if (!eth_type_vlan(vlan_ethtype)) { | |
903 | fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n"); | |
904 | return -1; | |
905 | } | |
906 | ret = get_u8(&cvlan_prio, *argv, 10); | |
907 | if (ret < 0 || cvlan_prio & ~0x7) { | |
908 | fprintf(stderr, "Illegal \"cvlan_prio\"\n"); | |
909 | return -1; | |
910 | } | |
911 | addattr8(n, MAX_MSG, | |
912 | TCA_FLOWER_KEY_CVLAN_PRIO, cvlan_prio); | |
913 | } else if (matches(*argv, "cvlan_ethtype") == 0) { | |
914 | NEXT_ARG(); | |
915 | ret = flower_parse_vlan_eth_type(*argv, vlan_ethtype, | |
916 | TCA_FLOWER_KEY_CVLAN_ETH_TYPE, | |
917 | &cvlan_ethtype, n); | |
918 | if (ret < 0) | |
919 | return -1; | |
7638ee13 BL |
920 | } else if (matches(*argv, "mpls_label") == 0) { |
921 | __u32 label; | |
922 | ||
923 | NEXT_ARG(); | |
924 | if (eth_type != htons(ETH_P_MPLS_UC) && | |
925 | eth_type != htons(ETH_P_MPLS_MC)) { | |
926 | fprintf(stderr, | |
927 | "Can't set \"mpls_label\" if ethertype isn't MPLS\n"); | |
928 | return -1; | |
929 | } | |
930 | ret = get_u32(&label, *argv, 10); | |
931 | if (ret < 0 || label & ~(MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT)) { | |
932 | fprintf(stderr, "Illegal \"mpls_label\"\n"); | |
933 | return -1; | |
934 | } | |
935 | addattr32(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_LABEL, label); | |
936 | } else if (matches(*argv, "mpls_tc") == 0) { | |
937 | __u8 tc; | |
938 | ||
939 | NEXT_ARG(); | |
940 | if (eth_type != htons(ETH_P_MPLS_UC) && | |
941 | eth_type != htons(ETH_P_MPLS_MC)) { | |
942 | fprintf(stderr, | |
943 | "Can't set \"mpls_tc\" if ethertype isn't MPLS\n"); | |
944 | return -1; | |
945 | } | |
946 | ret = get_u8(&tc, *argv, 10); | |
947 | if (ret < 0 || tc & ~(MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT)) { | |
948 | fprintf(stderr, "Illegal \"mpls_tc\"\n"); | |
949 | return -1; | |
950 | } | |
951 | addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_TC, tc); | |
952 | } else if (matches(*argv, "mpls_bos") == 0) { | |
953 | __u8 bos; | |
954 | ||
955 | NEXT_ARG(); | |
956 | if (eth_type != htons(ETH_P_MPLS_UC) && | |
957 | eth_type != htons(ETH_P_MPLS_MC)) { | |
958 | fprintf(stderr, | |
959 | "Can't set \"mpls_bos\" if ethertype isn't MPLS\n"); | |
960 | return -1; | |
961 | } | |
962 | ret = get_u8(&bos, *argv, 10); | |
963 | if (ret < 0 || bos & ~(MPLS_LS_S_MASK >> MPLS_LS_S_SHIFT)) { | |
964 | fprintf(stderr, "Illegal \"mpls_bos\"\n"); | |
965 | return -1; | |
966 | } | |
967 | addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_BOS, bos); | |
968 | } else if (matches(*argv, "mpls_ttl") == 0) { | |
969 | __u8 ttl; | |
970 | ||
971 | NEXT_ARG(); | |
972 | if (eth_type != htons(ETH_P_MPLS_UC) && | |
973 | eth_type != htons(ETH_P_MPLS_MC)) { | |
974 | fprintf(stderr, | |
975 | "Can't set \"mpls_ttl\" if ethertype isn't MPLS\n"); | |
976 | return -1; | |
977 | } | |
978 | ret = get_u8(&ttl, *argv, 10); | |
979 | if (ret < 0 || ttl & ~(MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)) { | |
980 | fprintf(stderr, "Illegal \"mpls_ttl\"\n"); | |
981 | return -1; | |
982 | } | |
983 | addattr8(n, MAX_MSG, TCA_FLOWER_KEY_MPLS_TTL, ttl); | |
30eb304e JP |
984 | } else if (matches(*argv, "dst_mac") == 0) { |
985 | NEXT_ARG(); | |
986 | ret = flower_parse_eth_addr(*argv, | |
987 | TCA_FLOWER_KEY_ETH_DST, | |
988 | TCA_FLOWER_KEY_ETH_DST_MASK, | |
989 | n); | |
990 | if (ret < 0) { | |
991 | fprintf(stderr, "Illegal \"dst_mac\"\n"); | |
992 | return -1; | |
993 | } | |
994 | } else if (matches(*argv, "src_mac") == 0) { | |
995 | NEXT_ARG(); | |
996 | ret = flower_parse_eth_addr(*argv, | |
997 | TCA_FLOWER_KEY_ETH_SRC, | |
998 | TCA_FLOWER_KEY_ETH_SRC_MASK, | |
999 | n); | |
1000 | if (ret < 0) { | |
1001 | fprintf(stderr, "Illegal \"src_mac\"\n"); | |
1002 | return -1; | |
1003 | } | |
30eb304e JP |
1004 | } else if (matches(*argv, "ip_proto") == 0) { |
1005 | NEXT_ARG(); | |
1f0a5dfd JL |
1006 | ret = flower_parse_ip_proto(*argv, cvlan_ethtype ? |
1007 | cvlan_ethtype : vlan_ethtype ? | |
745d9172 | 1008 | vlan_ethtype : eth_type, |
30eb304e JP |
1009 | TCA_FLOWER_KEY_IP_PROTO, |
1010 | &ip_proto, n); | |
1011 | if (ret < 0) { | |
1012 | fprintf(stderr, "Illegal \"ip_proto\"\n"); | |
1013 | return -1; | |
1014 | } | |
6ea2c2b1 OG |
1015 | } else if (matches(*argv, "ip_tos") == 0) { |
1016 | NEXT_ARG(); | |
1017 | ret = flower_parse_ip_tos_ttl(*argv, | |
1018 | TCA_FLOWER_KEY_IP_TOS, | |
1019 | TCA_FLOWER_KEY_IP_TOS_MASK, | |
1020 | n); | |
1021 | if (ret < 0) { | |
1022 | fprintf(stderr, "Illegal \"ip_tos\"\n"); | |
1023 | return -1; | |
1024 | } | |
1025 | } else if (matches(*argv, "ip_ttl") == 0) { | |
1026 | NEXT_ARG(); | |
1027 | ret = flower_parse_ip_tos_ttl(*argv, | |
1028 | TCA_FLOWER_KEY_IP_TTL, | |
1029 | TCA_FLOWER_KEY_IP_TTL_MASK, | |
1030 | n); | |
1031 | if (ret < 0) { | |
1032 | fprintf(stderr, "Illegal \"ip_ttl\"\n"); | |
1033 | return -1; | |
1034 | } | |
30eb304e JP |
1035 | } else if (matches(*argv, "dst_ip") == 0) { |
1036 | NEXT_ARG(); | |
1f0a5dfd JL |
1037 | ret = flower_parse_ip_addr(*argv, cvlan_ethtype ? |
1038 | cvlan_ethtype : vlan_ethtype ? | |
745d9172 | 1039 | vlan_ethtype : eth_type, |
30eb304e JP |
1040 | TCA_FLOWER_KEY_IPV4_DST, |
1041 | TCA_FLOWER_KEY_IPV4_DST_MASK, | |
1042 | TCA_FLOWER_KEY_IPV6_DST, | |
1043 | TCA_FLOWER_KEY_IPV6_DST_MASK, | |
1044 | n); | |
1045 | if (ret < 0) { | |
1046 | fprintf(stderr, "Illegal \"dst_ip\"\n"); | |
1047 | return -1; | |
1048 | } | |
1049 | } else if (matches(*argv, "src_ip") == 0) { | |
1050 | NEXT_ARG(); | |
1f0a5dfd JL |
1051 | ret = flower_parse_ip_addr(*argv, cvlan_ethtype ? |
1052 | cvlan_ethtype : vlan_ethtype ? | |
745d9172 | 1053 | vlan_ethtype : eth_type, |
30eb304e JP |
1054 | TCA_FLOWER_KEY_IPV4_SRC, |
1055 | TCA_FLOWER_KEY_IPV4_SRC_MASK, | |
1056 | TCA_FLOWER_KEY_IPV6_SRC, | |
1057 | TCA_FLOWER_KEY_IPV6_SRC_MASK, | |
1058 | n); | |
1059 | if (ret < 0) { | |
1060 | fprintf(stderr, "Illegal \"src_ip\"\n"); | |
1061 | return -1; | |
1062 | } | |
1063 | } else if (matches(*argv, "dst_port") == 0) { | |
1064 | NEXT_ARG(); | |
dd7d522a DA |
1065 | ret = flower_parse_port(*argv, ip_proto, |
1066 | FLOWER_ENDPOINT_DST, n); | |
1067 | if (ret < 0) { | |
1068 | fprintf(stderr, "Illegal \"dst_port\"\n"); | |
1069 | return -1; | |
30eb304e JP |
1070 | } |
1071 | } else if (matches(*argv, "src_port") == 0) { | |
1072 | NEXT_ARG(); | |
dd7d522a DA |
1073 | ret = flower_parse_port(*argv, ip_proto, |
1074 | FLOWER_ENDPOINT_SRC, n); | |
1075 | if (ret < 0) { | |
1076 | fprintf(stderr, "Illegal \"src_port\"\n"); | |
1077 | return -1; | |
30eb304e | 1078 | } |
0c30d14d JP |
1079 | } else if (matches(*argv, "tcp_flags") == 0) { |
1080 | NEXT_ARG(); | |
1081 | ret = flower_parse_tcp_flags(*argv, | |
1082 | TCA_FLOWER_KEY_TCP_FLAGS, | |
1083 | TCA_FLOWER_KEY_TCP_FLAGS_MASK, | |
1084 | n); | |
1085 | if (ret < 0) { | |
1086 | fprintf(stderr, "Illegal \"tcp_flags\"\n"); | |
1087 | return -1; | |
1088 | } | |
eb3b5696 SH |
1089 | } else if (matches(*argv, "type") == 0) { |
1090 | NEXT_ARG(); | |
1091 | ret = flower_parse_icmp(*argv, eth_type, ip_proto, | |
1092 | FLOWER_ICMP_FIELD_TYPE, n); | |
1093 | if (ret < 0) { | |
1094 | fprintf(stderr, "Illegal \"icmp type\"\n"); | |
1095 | return -1; | |
1096 | } | |
1097 | } else if (matches(*argv, "code") == 0) { | |
1098 | NEXT_ARG(); | |
1099 | ret = flower_parse_icmp(*argv, eth_type, ip_proto, | |
1100 | FLOWER_ICMP_FIELD_CODE, n); | |
1101 | if (ret < 0) { | |
1102 | fprintf(stderr, "Illegal \"icmp code\"\n"); | |
1103 | return -1; | |
1104 | } | |
f888f4e2 SH |
1105 | } else if (matches(*argv, "arp_tip") == 0) { |
1106 | NEXT_ARG(); | |
1107 | ret = flower_parse_arp_ip_addr(*argv, vlan_ethtype ? | |
1108 | vlan_ethtype : eth_type, | |
1109 | TCA_FLOWER_KEY_ARP_TIP, | |
1110 | TCA_FLOWER_KEY_ARP_TIP_MASK, | |
1111 | n); | |
1112 | if (ret < 0) { | |
1113 | fprintf(stderr, "Illegal \"arp_tip\"\n"); | |
1114 | return -1; | |
1115 | } | |
1116 | } else if (matches(*argv, "arp_sip") == 0) { | |
1117 | NEXT_ARG(); | |
1118 | ret = flower_parse_arp_ip_addr(*argv, vlan_ethtype ? | |
1119 | vlan_ethtype : eth_type, | |
1120 | TCA_FLOWER_KEY_ARP_SIP, | |
1121 | TCA_FLOWER_KEY_ARP_SIP_MASK, | |
1122 | n); | |
1123 | if (ret < 0) { | |
1124 | fprintf(stderr, "Illegal \"arp_sip\"\n"); | |
1125 | return -1; | |
1126 | } | |
1127 | } else if (matches(*argv, "arp_op") == 0) { | |
1128 | NEXT_ARG(); | |
1129 | ret = flower_parse_arp_op(*argv, vlan_ethtype ? | |
1130 | vlan_ethtype : eth_type, | |
1131 | TCA_FLOWER_KEY_ARP_OP, | |
1132 | TCA_FLOWER_KEY_ARP_OP_MASK, | |
1133 | n); | |
1134 | if (ret < 0) { | |
1135 | fprintf(stderr, "Illegal \"arp_op\"\n"); | |
1136 | return -1; | |
1137 | } | |
1138 | } else if (matches(*argv, "arp_tha") == 0) { | |
1139 | NEXT_ARG(); | |
1140 | ret = flower_parse_eth_addr(*argv, | |
1141 | TCA_FLOWER_KEY_ARP_THA, | |
1142 | TCA_FLOWER_KEY_ARP_THA_MASK, | |
1143 | n); | |
1144 | if (ret < 0) { | |
1145 | fprintf(stderr, "Illegal \"arp_tha\"\n"); | |
1146 | return -1; | |
1147 | } | |
1148 | } else if (matches(*argv, "arp_sha") == 0) { | |
1149 | NEXT_ARG(); | |
1150 | ret = flower_parse_eth_addr(*argv, | |
1151 | TCA_FLOWER_KEY_ARP_SHA, | |
1152 | TCA_FLOWER_KEY_ARP_SHA_MASK, | |
1153 | n); | |
1154 | if (ret < 0) { | |
1155 | fprintf(stderr, "Illegal \"arp_sha\"\n"); | |
1156 | return -1; | |
1157 | } | |
bb9b63b1 AV |
1158 | } else if (matches(*argv, "enc_dst_ip") == 0) { |
1159 | NEXT_ARG(); | |
1160 | ret = flower_parse_ip_addr(*argv, 0, | |
1161 | TCA_FLOWER_KEY_ENC_IPV4_DST, | |
1162 | TCA_FLOWER_KEY_ENC_IPV4_DST_MASK, | |
1163 | TCA_FLOWER_KEY_ENC_IPV6_DST, | |
1164 | TCA_FLOWER_KEY_ENC_IPV6_DST_MASK, | |
1165 | n); | |
1166 | if (ret < 0) { | |
1167 | fprintf(stderr, "Illegal \"enc_dst_ip\"\n"); | |
1168 | return -1; | |
1169 | } | |
1170 | } else if (matches(*argv, "enc_src_ip") == 0) { | |
1171 | NEXT_ARG(); | |
1172 | ret = flower_parse_ip_addr(*argv, 0, | |
1173 | TCA_FLOWER_KEY_ENC_IPV4_SRC, | |
1174 | TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK, | |
1175 | TCA_FLOWER_KEY_ENC_IPV6_SRC, | |
1176 | TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK, | |
1177 | n); | |
1178 | if (ret < 0) { | |
1179 | fprintf(stderr, "Illegal \"enc_src_ip\"\n"); | |
1180 | return -1; | |
1181 | } | |
1182 | } else if (matches(*argv, "enc_key_id") == 0) { | |
1183 | NEXT_ARG(); | |
1184 | ret = flower_parse_key_id(*argv, | |
1185 | TCA_FLOWER_KEY_ENC_KEY_ID, n); | |
1186 | if (ret < 0) { | |
1187 | fprintf(stderr, "Illegal \"enc_key_id\"\n"); | |
1188 | return -1; | |
1189 | } | |
41aa17ff HHZ |
1190 | } else if (matches(*argv, "enc_dst_port") == 0) { |
1191 | NEXT_ARG(); | |
1192 | ret = flower_parse_enc_port(*argv, | |
1193 | TCA_FLOWER_KEY_ENC_UDP_DST_PORT, n); | |
1194 | if (ret < 0) { | |
1195 | fprintf(stderr, "Illegal \"enc_dst_port\"\n"); | |
1196 | return -1; | |
1197 | } | |
761ec9e2 OG |
1198 | } else if (matches(*argv, "enc_tos") == 0) { |
1199 | NEXT_ARG(); | |
1200 | ret = flower_parse_ip_tos_ttl(*argv, | |
1201 | TCA_FLOWER_KEY_ENC_IP_TOS, | |
1202 | TCA_FLOWER_KEY_ENC_IP_TOS_MASK, | |
1203 | n); | |
1204 | if (ret < 0) { | |
1205 | fprintf(stderr, "Illegal \"enc_tos\"\n"); | |
1206 | return -1; | |
1207 | } | |
1208 | } else if (matches(*argv, "enc_ttl") == 0) { | |
1209 | NEXT_ARG(); | |
1210 | ret = flower_parse_ip_tos_ttl(*argv, | |
1211 | TCA_FLOWER_KEY_ENC_IP_TTL, | |
1212 | TCA_FLOWER_KEY_ENC_IP_TTL_MASK, | |
1213 | n); | |
1214 | if (ret < 0) { | |
1215 | fprintf(stderr, "Illegal \"enc_ttl\"\n"); | |
1216 | return -1; | |
1217 | } | |
56155d4d PJV |
1218 | } else if (matches(*argv, "geneve_opts") == 0) { |
1219 | NEXT_ARG(); | |
1220 | ret = flower_parse_enc_opts(*argv, n); | |
1221 | if (ret < 0) { | |
1222 | fprintf(stderr, "Illegal \"geneve_opts\"\n"); | |
1223 | return -1; | |
1224 | } | |
30eb304e JP |
1225 | } else if (matches(*argv, "action") == 0) { |
1226 | NEXT_ARG(); | |
1227 | ret = parse_action(&argc, &argv, TCA_FLOWER_ACT, n); | |
1228 | if (ret) { | |
1229 | fprintf(stderr, "Illegal \"action\"\n"); | |
1230 | return -1; | |
1231 | } | |
1232 | continue; | |
1233 | } else if (strcmp(*argv, "help") == 0) { | |
1234 | explain(); | |
1235 | return -1; | |
1236 | } else { | |
1237 | fprintf(stderr, "What is \"%s\"?\n", *argv); | |
1238 | explain(); | |
1239 | return -1; | |
1240 | } | |
1241 | argc--; argv++; | |
1242 | } | |
1243 | ||
488b41d0 | 1244 | parse_done: |
c85609b2 RD |
1245 | ret = addattr32(n, MAX_MSG, TCA_FLOWER_FLAGS, flags); |
1246 | if (ret) | |
1247 | return ret; | |
cfcabf18 | 1248 | |
08f66c80 PB |
1249 | if (mtf_mask) { |
1250 | ret = addattr32(n, MAX_MSG, TCA_FLOWER_KEY_FLAGS, htonl(mtf)); | |
1251 | if (ret) | |
1252 | return ret; | |
1253 | ||
1254 | ret = addattr32(n, MAX_MSG, TCA_FLOWER_KEY_FLAGS_MASK, htonl(mtf_mask)); | |
1255 | if (ret) | |
1256 | return ret; | |
1257 | } | |
1258 | ||
4f7d406f BL |
1259 | if (eth_type != htons(ETH_P_ALL)) { |
1260 | ret = addattr16(n, MAX_MSG, TCA_FLOWER_KEY_ETH_TYPE, eth_type); | |
1261 | if (ret) | |
1262 | return ret; | |
1263 | } | |
488b41d0 | 1264 | |
32a121cb | 1265 | tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail; |
30eb304e JP |
1266 | |
1267 | return 0; | |
1268 | } | |
1269 | ||
1270 | static int __mask_bits(char *addr, size_t len) | |
1271 | { | |
1272 | int bits = 0; | |
1273 | bool hole = false; | |
1274 | int i; | |
1275 | int j; | |
1276 | ||
1277 | for (i = 0; i < len; i++, addr++) { | |
1278 | for (j = 7; j >= 0; j--) { | |
1279 | if (((*addr) >> j) & 0x1) { | |
1280 | if (hole) | |
1281 | return -1; | |
1282 | bits++; | |
1283 | } else if (bits) { | |
1284 | hole = true; | |
1285 | } else{ | |
1286 | return -1; | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | return bits; | |
1291 | } | |
1292 | ||
e28b88a4 | 1293 | static void flower_print_eth_addr(char *name, struct rtattr *addr_attr, |
30eb304e JP |
1294 | struct rtattr *mask_attr) |
1295 | { | |
e28b88a4 JP |
1296 | SPRINT_BUF(namefrm); |
1297 | SPRINT_BUF(out); | |
30eb304e | 1298 | SPRINT_BUF(b1); |
e28b88a4 | 1299 | size_t done; |
30eb304e JP |
1300 | int bits; |
1301 | ||
1302 | if (!addr_attr || RTA_PAYLOAD(addr_attr) != ETH_ALEN) | |
1303 | return; | |
e28b88a4 JP |
1304 | done = sprintf(out, "%s", |
1305 | ll_addr_n2a(RTA_DATA(addr_attr), ETH_ALEN, | |
1306 | 0, b1, sizeof(b1))); | |
1307 | if (mask_attr && RTA_PAYLOAD(mask_attr) == ETH_ALEN) { | |
1308 | bits = __mask_bits(RTA_DATA(mask_attr), ETH_ALEN); | |
1309 | if (bits < 0) | |
1310 | sprintf(out + done, "/%s", | |
1311 | ll_addr_n2a(RTA_DATA(mask_attr), ETH_ALEN, | |
1312 | 0, b1, sizeof(b1))); | |
1313 | else if (bits < ETH_ALEN * 8) | |
1314 | sprintf(out + done, "/%d", bits); | |
1315 | } | |
1316 | ||
1317 | sprintf(namefrm, "\n %s %%s", name); | |
1318 | print_string(PRINT_ANY, name, namefrm, out); | |
30eb304e JP |
1319 | } |
1320 | ||
e28b88a4 | 1321 | static void flower_print_eth_type(__be16 *p_eth_type, |
30eb304e JP |
1322 | struct rtattr *eth_type_attr) |
1323 | { | |
e28b88a4 | 1324 | SPRINT_BUF(out); |
30eb304e JP |
1325 | __be16 eth_type; |
1326 | ||
1327 | if (!eth_type_attr) | |
1328 | return; | |
1329 | ||
1330 | eth_type = rta_getattr_u16(eth_type_attr); | |
30eb304e | 1331 | if (eth_type == htons(ETH_P_IP)) |
e28b88a4 | 1332 | sprintf(out, "ipv4"); |
30eb304e | 1333 | else if (eth_type == htons(ETH_P_IPV6)) |
e28b88a4 | 1334 | sprintf(out, "ipv6"); |
f888f4e2 | 1335 | else if (eth_type == htons(ETH_P_ARP)) |
e28b88a4 | 1336 | sprintf(out, "arp"); |
f888f4e2 | 1337 | else if (eth_type == htons(ETH_P_RARP)) |
e28b88a4 | 1338 | sprintf(out, "rarp"); |
30eb304e | 1339 | else |
e28b88a4 JP |
1340 | sprintf(out, "%04x", ntohs(eth_type)); |
1341 | ||
1342 | print_string(PRINT_ANY, "eth_type", "\n eth_type %s", out); | |
30eb304e JP |
1343 | *p_eth_type = eth_type; |
1344 | } | |
1345 | ||
e28b88a4 | 1346 | static void flower_print_ip_proto(__u8 *p_ip_proto, |
30eb304e JP |
1347 | struct rtattr *ip_proto_attr) |
1348 | { | |
e28b88a4 | 1349 | SPRINT_BUF(out); |
30eb304e JP |
1350 | __u8 ip_proto; |
1351 | ||
1352 | if (!ip_proto_attr) | |
1353 | return; | |
1354 | ||
1355 | ip_proto = rta_getattr_u8(ip_proto_attr); | |
30eb304e | 1356 | if (ip_proto == IPPROTO_TCP) |
e28b88a4 | 1357 | sprintf(out, "tcp"); |
30eb304e | 1358 | else if (ip_proto == IPPROTO_UDP) |
e28b88a4 | 1359 | sprintf(out, "udp"); |
a1fb0d48 | 1360 | else if (ip_proto == IPPROTO_SCTP) |
e28b88a4 | 1361 | sprintf(out, "sctp"); |
eb3b5696 | 1362 | else if (ip_proto == IPPROTO_ICMP) |
e28b88a4 | 1363 | sprintf(out, "icmp"); |
eb3b5696 | 1364 | else if (ip_proto == IPPROTO_ICMPV6) |
e28b88a4 | 1365 | sprintf(out, "icmpv6"); |
30eb304e | 1366 | else |
e28b88a4 JP |
1367 | sprintf(out, "%02x", ip_proto); |
1368 | ||
1369 | print_string(PRINT_ANY, "ip_proto", "\n ip_proto %s", out); | |
30eb304e JP |
1370 | *p_ip_proto = ip_proto; |
1371 | } | |
1372 | ||
e8bd3955 | 1373 | static void flower_print_ip_attr(const char *name, struct rtattr *key_attr, |
6ea2c2b1 OG |
1374 | struct rtattr *mask_attr) |
1375 | { | |
e28b88a4 JP |
1376 | SPRINT_BUF(namefrm); |
1377 | SPRINT_BUF(out); | |
1378 | size_t done; | |
1379 | ||
6ea2c2b1 OG |
1380 | if (!key_attr) |
1381 | return; | |
1382 | ||
e8bd3955 | 1383 | done = sprintf(out, "0x%x", rta_getattr_u8(key_attr)); |
e28b88a4 JP |
1384 | if (mask_attr) |
1385 | sprintf(out + done, "/%x", rta_getattr_u8(mask_attr)); | |
1386 | ||
e8bd3955 KL |
1387 | print_string(PRINT_FP, NULL, "%s ", _SL_); |
1388 | sprintf(namefrm, "%s %%s", name); | |
e28b88a4 | 1389 | print_string(PRINT_ANY, name, namefrm, out); |
6ea2c2b1 OG |
1390 | } |
1391 | ||
e28b88a4 | 1392 | static void flower_print_matching_flags(char *name, |
08f66c80 | 1393 | enum flower_matching_flags type, |
22a8f019 PB |
1394 | struct rtattr *attr, |
1395 | struct rtattr *mask_attr) | |
1396 | { | |
08f66c80 PB |
1397 | int i; |
1398 | int count = 0; | |
1399 | __u32 mtf; | |
1400 | __u32 mtf_mask; | |
1401 | ||
22a8f019 PB |
1402 | if (!mask_attr || RTA_PAYLOAD(mask_attr) != 4) |
1403 | return; | |
1404 | ||
08f66c80 PB |
1405 | mtf = ntohl(rta_getattr_u32(attr)); |
1406 | mtf_mask = ntohl(rta_getattr_u32(mask_attr)); | |
1407 | ||
1408 | for (i = 0; i < ARRAY_SIZE(flags_str); i++) { | |
1409 | if (type != flags_str[i].type) | |
1410 | continue; | |
1411 | if (mtf_mask & flags_str[i].flag) { | |
e28b88a4 JP |
1412 | if (++count == 1) { |
1413 | print_string(PRINT_FP, NULL, "\n %s ", name); | |
1414 | open_json_object(name); | |
1415 | } else { | |
1416 | print_string(PRINT_FP, NULL, "/", NULL); | |
1417 | } | |
08f66c80 | 1418 | |
e28b88a4 JP |
1419 | print_bool(PRINT_JSON, flags_str[i].string, NULL, |
1420 | mtf & flags_str[i].flag); | |
08f66c80 | 1421 | if (mtf & flags_str[i].flag) |
e28b88a4 JP |
1422 | print_string(PRINT_FP, NULL, "%s", |
1423 | flags_str[i].string); | |
08f66c80 | 1424 | else |
e28b88a4 JP |
1425 | print_string(PRINT_FP, NULL, "no%s", |
1426 | flags_str[i].string); | |
08f66c80 PB |
1427 | } |
1428 | } | |
e28b88a4 JP |
1429 | if (count) |
1430 | close_json_object(); | |
22a8f019 PB |
1431 | } |
1432 | ||
e28b88a4 | 1433 | static void flower_print_ip_addr(char *name, __be16 eth_type, |
30eb304e JP |
1434 | struct rtattr *addr4_attr, |
1435 | struct rtattr *mask4_attr, | |
1436 | struct rtattr *addr6_attr, | |
1437 | struct rtattr *mask6_attr) | |
1438 | { | |
30eb304e JP |
1439 | struct rtattr *addr_attr; |
1440 | struct rtattr *mask_attr; | |
e28b88a4 JP |
1441 | SPRINT_BUF(namefrm); |
1442 | SPRINT_BUF(out); | |
1443 | size_t done; | |
30eb304e JP |
1444 | int family; |
1445 | size_t len; | |
1446 | int bits; | |
1447 | ||
1448 | if (eth_type == htons(ETH_P_IP)) { | |
1449 | family = AF_INET; | |
1450 | addr_attr = addr4_attr; | |
1451 | mask_attr = mask4_attr; | |
1452 | len = 4; | |
1453 | } else if (eth_type == htons(ETH_P_IPV6)) { | |
1454 | family = AF_INET6; | |
1455 | addr_attr = addr6_attr; | |
1456 | mask_attr = mask6_attr; | |
1457 | len = 16; | |
1458 | } else { | |
1459 | return; | |
1460 | } | |
1461 | if (!addr_attr || RTA_PAYLOAD(addr_attr) != len) | |
1462 | return; | |
30eb304e JP |
1463 | if (!mask_attr || RTA_PAYLOAD(mask_attr) != len) |
1464 | return; | |
e28b88a4 | 1465 | done = sprintf(out, "%s", rt_addr_n2a_rta(family, addr_attr)); |
30eb304e JP |
1466 | bits = __mask_bits(RTA_DATA(mask_attr), len); |
1467 | if (bits < 0) | |
e28b88a4 | 1468 | sprintf(out + done, "/%s", rt_addr_n2a_rta(family, mask_attr)); |
30eb304e | 1469 | else if (bits < len * 8) |
e28b88a4 JP |
1470 | sprintf(out + done, "/%d", bits); |
1471 | ||
1472 | sprintf(namefrm, "\n %s %%s", name); | |
1473 | print_string(PRINT_ANY, name, namefrm, out); | |
30eb304e | 1474 | } |
e28b88a4 | 1475 | static void flower_print_ip4_addr(char *name, struct rtattr *addr_attr, |
f888f4e2 SH |
1476 | struct rtattr *mask_attr) |
1477 | { | |
e28b88a4 | 1478 | return flower_print_ip_addr(name, htons(ETH_P_IP), |
f888f4e2 SH |
1479 | addr_attr, mask_attr, 0, 0); |
1480 | } | |
30eb304e | 1481 | |
e28b88a4 | 1482 | static void flower_print_port(char *name, struct rtattr *attr) |
30eb304e | 1483 | { |
e28b88a4 JP |
1484 | SPRINT_BUF(namefrm); |
1485 | ||
1486 | if (!attr) | |
1487 | return; | |
1488 | ||
1489 | sprintf(namefrm,"\n %s %%u", name); | |
0b01f088 | 1490 | print_hu(PRINT_ANY, name, namefrm, rta_getattr_be16(attr)); |
30eb304e JP |
1491 | } |
1492 | ||
e8bd3955 | 1493 | static void flower_print_tcp_flags(const char *name, struct rtattr *flags_attr, |
e28b88a4 | 1494 | struct rtattr *mask_attr) |
0c30d14d | 1495 | { |
e28b88a4 JP |
1496 | SPRINT_BUF(namefrm); |
1497 | SPRINT_BUF(out); | |
1498 | size_t done; | |
1499 | ||
0c30d14d JP |
1500 | if (!flags_attr) |
1501 | return; | |
e28b88a4 | 1502 | |
e8bd3955 | 1503 | done = sprintf(out, "0x%x", rta_getattr_be16(flags_attr)); |
e28b88a4 | 1504 | if (mask_attr) |
e8bd3955 | 1505 | sprintf(out + done, "/%x", rta_getattr_be16(mask_attr)); |
e28b88a4 | 1506 | |
e8bd3955 KL |
1507 | print_string(PRINT_FP, NULL, "%s ", _SL_); |
1508 | sprintf(namefrm, "%s %%s", name); | |
e28b88a4 | 1509 | print_string(PRINT_ANY, name, namefrm, out); |
0c30d14d JP |
1510 | } |
1511 | ||
1512 | ||
e28b88a4 | 1513 | static void flower_print_key_id(const char *name, struct rtattr *attr) |
bb9b63b1 | 1514 | { |
e28b88a4 JP |
1515 | SPRINT_BUF(namefrm); |
1516 | ||
1517 | if (!attr) | |
1518 | return; | |
1519 | ||
1520 | sprintf(namefrm,"\n %s %%u", name); | |
1521 | print_uint(PRINT_ANY, name, namefrm, rta_getattr_be32(attr)); | |
bb9b63b1 AV |
1522 | } |
1523 | ||
56155d4d PJV |
1524 | static void flower_print_geneve_opts(const char *name, struct rtattr *attr, |
1525 | char *strbuf) | |
1526 | { | |
1527 | struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX + 1]; | |
1528 | int ii, data_len, offset = 0, slen = 0; | |
1529 | struct rtattr *i = RTA_DATA(attr); | |
1530 | int rem = RTA_PAYLOAD(attr); | |
1531 | __u8 type, data_r[rem]; | |
1532 | char data[rem * 2 + 1]; | |
1533 | __u16 class; | |
1534 | ||
1535 | open_json_array(PRINT_JSON, name); | |
1536 | while (rem) { | |
1537 | parse_rtattr(tb, TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX, i, rem); | |
1538 | class = rta_getattr_be16(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS]); | |
1539 | type = rta_getattr_u8(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE]); | |
1540 | data_len = RTA_PAYLOAD(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA]); | |
1541 | hexstring_n2a(RTA_DATA(tb[TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA]), | |
1542 | data_len, data, sizeof(data)); | |
1543 | hex2mem(data, data_r, data_len); | |
1544 | offset += data_len + 20; | |
1545 | rem -= data_len + 20; | |
1546 | i = RTA_DATA(attr) + offset; | |
1547 | ||
1548 | open_json_object(NULL); | |
1549 | print_uint(PRINT_JSON, "class", NULL, class); | |
1550 | print_uint(PRINT_JSON, "type", NULL, type); | |
1551 | open_json_array(PRINT_JSON, "data"); | |
1552 | for (ii = 0; ii < data_len; ii++) | |
1553 | print_uint(PRINT_JSON, NULL, NULL, data_r[ii]); | |
1554 | close_json_array(PRINT_JSON, "data"); | |
1555 | close_json_object(); | |
1556 | ||
1557 | slen += sprintf(strbuf + slen, "%04x:%02x:%s", | |
1558 | class, type, data); | |
1559 | if (rem) | |
1560 | slen += sprintf(strbuf + slen, ","); | |
1561 | } | |
1562 | close_json_array(PRINT_JSON, name); | |
1563 | } | |
1564 | ||
1565 | static void flower_print_geneve_parts(const char *name, struct rtattr *attr, | |
1566 | char *key, char *mask) | |
1567 | { | |
1568 | char *namefrm = "\n geneve_opt %s"; | |
1569 | char *key_token, *mask_token, *out; | |
1570 | int len; | |
1571 | ||
1572 | out = malloc(RTA_PAYLOAD(attr) * 4 + 3); | |
1573 | if (!out) | |
1574 | return; | |
1575 | ||
1576 | len = 0; | |
1577 | key_token = strsep(&key, ","); | |
1578 | mask_token = strsep(&mask, ","); | |
1579 | while (key_token) { | |
1580 | len += sprintf(&out[len], "%s/%s,", key_token, mask_token); | |
1581 | mask_token = strsep(&mask, ","); | |
1582 | key_token = strsep(&key, ","); | |
1583 | } | |
1584 | ||
1585 | out[len - 1] = '\0'; | |
1586 | print_string(PRINT_FP, name, namefrm, out); | |
1587 | free(out); | |
1588 | } | |
1589 | ||
1590 | static void flower_print_enc_opts(const char *name, struct rtattr *attr, | |
1591 | struct rtattr *mask_attr) | |
1592 | { | |
1593 | struct rtattr *key_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1]; | |
1594 | struct rtattr *msk_tb[TCA_FLOWER_KEY_ENC_OPTS_MAX + 1]; | |
1595 | char *key, *msk; | |
1596 | ||
1597 | if (!attr) | |
1598 | return; | |
1599 | ||
1600 | key = malloc(RTA_PAYLOAD(attr) * 2 + 1); | |
1601 | if (!key) | |
1602 | return; | |
1603 | ||
1604 | msk = malloc(RTA_PAYLOAD(attr) * 2 + 1); | |
1605 | if (!msk) | |
1606 | goto err_key_free; | |
1607 | ||
1608 | parse_rtattr_nested(key_tb, TCA_FLOWER_KEY_ENC_OPTS_MAX, attr); | |
1609 | flower_print_geneve_opts("geneve_opt_key", | |
1610 | key_tb[TCA_FLOWER_KEY_ENC_OPTS_GENEVE], key); | |
1611 | ||
1612 | parse_rtattr_nested(msk_tb, TCA_FLOWER_KEY_ENC_OPTS_MAX, mask_attr); | |
1613 | flower_print_geneve_opts("geneve_opt_mask", | |
1614 | msk_tb[TCA_FLOWER_KEY_ENC_OPTS_GENEVE], msk); | |
1615 | ||
1616 | flower_print_geneve_parts(name, attr, key, msk); | |
1617 | ||
1618 | free(msk); | |
1619 | err_key_free: | |
1620 | free(key); | |
1621 | } | |
1622 | ||
e28b88a4 | 1623 | static void flower_print_masked_u8(const char *name, struct rtattr *attr, |
9d36e54f SH |
1624 | struct rtattr *mask_attr, |
1625 | const char *(*value_to_str)(__u8 value)) | |
f888f4e2 | 1626 | { |
9d36e54f SH |
1627 | const char *value_str = NULL; |
1628 | __u8 value, mask; | |
e28b88a4 JP |
1629 | SPRINT_BUF(namefrm); |
1630 | SPRINT_BUF(out); | |
1631 | size_t done; | |
f888f4e2 | 1632 | |
9d36e54f | 1633 | if (!attr) |
f888f4e2 SH |
1634 | return; |
1635 | ||
9d36e54f | 1636 | value = rta_getattr_u8(attr); |
f888f4e2 | 1637 | mask = mask_attr ? rta_getattr_u8(mask_attr) : UINT8_MAX; |
9d36e54f SH |
1638 | if (mask == UINT8_MAX && value_to_str) |
1639 | value_str = value_to_str(value); | |
f888f4e2 | 1640 | |
9d36e54f | 1641 | if (value_str) |
e28b88a4 | 1642 | done = sprintf(out, "%s", value_str); |
f888f4e2 | 1643 | else |
e28b88a4 | 1644 | done = sprintf(out, "%d", value); |
f888f4e2 SH |
1645 | |
1646 | if (mask != UINT8_MAX) | |
e28b88a4 JP |
1647 | sprintf(out + done, "/%d", mask); |
1648 | ||
1649 | sprintf(namefrm,"\n %s %%s", name); | |
1650 | print_string(PRINT_ANY, name, namefrm, out); | |
f888f4e2 SH |
1651 | } |
1652 | ||
e28b88a4 | 1653 | static void flower_print_u8(const char *name, struct rtattr *attr) |
7638ee13 | 1654 | { |
e28b88a4 | 1655 | flower_print_masked_u8(name, attr, NULL, NULL); |
7638ee13 BL |
1656 | } |
1657 | ||
e28b88a4 | 1658 | static void flower_print_u32(const char *name, struct rtattr *attr) |
7638ee13 | 1659 | { |
e28b88a4 | 1660 | SPRINT_BUF(namefrm); |
7638ee13 BL |
1661 | |
1662 | if (!attr) | |
1663 | return; | |
1664 | ||
e28b88a4 JP |
1665 | sprintf(namefrm,"\n %s %%u", name); |
1666 | print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr)); | |
7638ee13 BL |
1667 | } |
1668 | ||
e28b88a4 | 1669 | static void flower_print_arp_op(const char *name, |
9d36e54f SH |
1670 | struct rtattr *op_attr, |
1671 | struct rtattr *mask_attr) | |
1672 | { | |
e28b88a4 | 1673 | flower_print_masked_u8(name, op_attr, mask_attr, |
9d36e54f SH |
1674 | flower_print_arp_op_to_name); |
1675 | } | |
1676 | ||
30eb304e JP |
1677 | static int flower_print_opt(struct filter_util *qu, FILE *f, |
1678 | struct rtattr *opt, __u32 handle) | |
1679 | { | |
1680 | struct rtattr *tb[TCA_FLOWER_MAX + 1]; | |
6374961a | 1681 | int nl_type, nl_mask_type; |
30eb304e JP |
1682 | __be16 eth_type = 0; |
1683 | __u8 ip_proto = 0xff; | |
1684 | ||
1685 | if (!opt) | |
1686 | return 0; | |
1687 | ||
1688 | parse_rtattr_nested(tb, TCA_FLOWER_MAX, opt); | |
1689 | ||
1690 | if (handle) | |
e28b88a4 | 1691 | print_uint(PRINT_ANY, "handle", "handle 0x%x ", handle); |
30eb304e JP |
1692 | |
1693 | if (tb[TCA_FLOWER_CLASSID]) { | |
0d575c4d AN |
1694 | __u32 h = rta_getattr_u32(tb[TCA_FLOWER_CLASSID]); |
1695 | ||
1696 | if (TC_H_MIN(h) < TC_H_MIN_PRIORITY || | |
1697 | TC_H_MIN(h) > (TC_H_MIN_PRIORITY + TC_QOPT_MAX_QUEUE - 1)) { | |
1698 | SPRINT_BUF(b1); | |
e28b88a4 JP |
1699 | print_string(PRINT_ANY, "classid", "classid %s ", |
1700 | sprint_tc_classid(h, b1)); | |
0d575c4d | 1701 | } else { |
e28b88a4 JP |
1702 | print_uint(PRINT_ANY, "hw_tc", "hw_tc %u ", |
1703 | TC_H_MIN(h) - TC_H_MIN_PRIORITY); | |
0d575c4d | 1704 | } |
30eb304e JP |
1705 | } |
1706 | ||
1707 | if (tb[TCA_FLOWER_INDEV]) { | |
1708 | struct rtattr *attr = tb[TCA_FLOWER_INDEV]; | |
1709 | ||
e28b88a4 JP |
1710 | print_string(PRINT_ANY, "indev", "\n indev %s", |
1711 | rta_getattr_str(attr)); | |
30eb304e JP |
1712 | } |
1713 | ||
e28b88a4 JP |
1714 | open_json_object("keys"); |
1715 | ||
745d9172 HHZ |
1716 | if (tb[TCA_FLOWER_KEY_VLAN_ID]) { |
1717 | struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID]; | |
1718 | ||
e28b88a4 JP |
1719 | print_uint(PRINT_ANY, "vlan_id", "\n vlan_id %u", |
1720 | rta_getattr_u16(attr)); | |
745d9172 HHZ |
1721 | } |
1722 | ||
1723 | if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) { | |
1724 | struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_PRIO]; | |
1725 | ||
e28b88a4 JP |
1726 | print_uint(PRINT_ANY, "vlan_prio", "\n vlan_prio %d", |
1727 | rta_getattr_u8(attr)); | |
745d9172 HHZ |
1728 | } |
1729 | ||
1f0a5dfd JL |
1730 | if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) { |
1731 | SPRINT_BUF(buf); | |
1732 | struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]; | |
1733 | ||
1734 | print_string(PRINT_ANY, "vlan_ethtype", "\n vlan_ethtype %s", | |
1735 | ll_proto_n2a(rta_getattr_u16(attr), | |
1736 | buf, sizeof(buf))); | |
1737 | } | |
1738 | ||
1739 | if (tb[TCA_FLOWER_KEY_CVLAN_ID]) { | |
1740 | struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ID]; | |
1741 | ||
1742 | print_uint(PRINT_ANY, "cvlan_id", "\n cvlan_id %u", | |
1743 | rta_getattr_u16(attr)); | |
1744 | } | |
1745 | ||
1746 | if (tb[TCA_FLOWER_KEY_CVLAN_PRIO]) { | |
1747 | struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_PRIO]; | |
1748 | ||
1749 | print_uint(PRINT_ANY, "cvlan_prio", "\n cvlan_prio %d", | |
1750 | rta_getattr_u8(attr)); | |
1751 | } | |
1752 | ||
1753 | if (tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE]) { | |
1754 | SPRINT_BUF(buf); | |
1755 | struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE]; | |
1756 | ||
1757 | print_string(PRINT_ANY, "cvlan_ethtype", "\n cvlan_ethtype %s", | |
1758 | ll_proto_n2a(rta_getattr_u16(attr), | |
1759 | buf, sizeof(buf))); | |
1760 | } | |
1761 | ||
e28b88a4 | 1762 | flower_print_eth_addr("dst_mac", tb[TCA_FLOWER_KEY_ETH_DST], |
30eb304e | 1763 | tb[TCA_FLOWER_KEY_ETH_DST_MASK]); |
e28b88a4 | 1764 | flower_print_eth_addr("src_mac", tb[TCA_FLOWER_KEY_ETH_SRC], |
30eb304e JP |
1765 | tb[TCA_FLOWER_KEY_ETH_SRC_MASK]); |
1766 | ||
e28b88a4 JP |
1767 | flower_print_eth_type(ð_type, tb[TCA_FLOWER_KEY_ETH_TYPE]); |
1768 | flower_print_ip_proto(&ip_proto, tb[TCA_FLOWER_KEY_IP_PROTO]); | |
30eb304e | 1769 | |
e28b88a4 | 1770 | flower_print_ip_attr("ip_tos", tb[TCA_FLOWER_KEY_IP_TOS], |
6ea2c2b1 | 1771 | tb[TCA_FLOWER_KEY_IP_TOS_MASK]); |
e28b88a4 | 1772 | flower_print_ip_attr("ip_ttl", tb[TCA_FLOWER_KEY_IP_TTL], |
6ea2c2b1 OG |
1773 | tb[TCA_FLOWER_KEY_IP_TTL_MASK]); |
1774 | ||
e28b88a4 JP |
1775 | flower_print_u32("mpls_label", tb[TCA_FLOWER_KEY_MPLS_LABEL]); |
1776 | flower_print_u8("mpls_tc", tb[TCA_FLOWER_KEY_MPLS_TC]); | |
1777 | flower_print_u8("mpls_bos", tb[TCA_FLOWER_KEY_MPLS_BOS]); | |
1778 | flower_print_u8("mpls_ttl", tb[TCA_FLOWER_KEY_MPLS_TTL]); | |
7638ee13 | 1779 | |
e28b88a4 | 1780 | flower_print_ip_addr("dst_ip", eth_type, |
30eb304e JP |
1781 | tb[TCA_FLOWER_KEY_IPV4_DST], |
1782 | tb[TCA_FLOWER_KEY_IPV4_DST_MASK], | |
1783 | tb[TCA_FLOWER_KEY_IPV6_DST], | |
1784 | tb[TCA_FLOWER_KEY_IPV6_DST_MASK]); | |
1785 | ||
e28b88a4 | 1786 | flower_print_ip_addr("src_ip", eth_type, |
30eb304e JP |
1787 | tb[TCA_FLOWER_KEY_IPV4_SRC], |
1788 | tb[TCA_FLOWER_KEY_IPV4_SRC_MASK], | |
1789 | tb[TCA_FLOWER_KEY_IPV6_SRC], | |
1790 | tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]); | |
1791 | ||
b2141de1 | 1792 | nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_DST); |
6bd5b80c | 1793 | if (nl_type >= 0) |
e28b88a4 | 1794 | flower_print_port("dst_port", tb[nl_type]); |
b2141de1 | 1795 | nl_type = flower_port_attr_type(ip_proto, FLOWER_ENDPOINT_SRC); |
6bd5b80c | 1796 | if (nl_type >= 0) |
e28b88a4 | 1797 | flower_print_port("src_port", tb[nl_type]); |
30eb304e | 1798 | |
e28b88a4 | 1799 | flower_print_tcp_flags("tcp_flags", tb[TCA_FLOWER_KEY_TCP_FLAGS], |
0c30d14d JP |
1800 | tb[TCA_FLOWER_KEY_TCP_FLAGS_MASK]); |
1801 | ||
81f6e5a7 SH |
1802 | nl_type = flower_icmp_attr_type(eth_type, ip_proto, |
1803 | FLOWER_ICMP_FIELD_TYPE); | |
6374961a SH |
1804 | nl_mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto, |
1805 | FLOWER_ICMP_FIELD_TYPE); | |
1806 | if (nl_type >= 0 && nl_mask_type >= 0) | |
e28b88a4 | 1807 | flower_print_masked_u8("icmp_type", tb[nl_type], |
6374961a SH |
1808 | tb[nl_mask_type], NULL); |
1809 | ||
81f6e5a7 SH |
1810 | nl_type = flower_icmp_attr_type(eth_type, ip_proto, |
1811 | FLOWER_ICMP_FIELD_CODE); | |
6374961a SH |
1812 | nl_mask_type = flower_icmp_attr_mask_type(eth_type, ip_proto, |
1813 | FLOWER_ICMP_FIELD_CODE); | |
1814 | if (nl_type >= 0 && nl_mask_type >= 0) | |
e28b88a4 | 1815 | flower_print_masked_u8("icmp_code", tb[nl_type], |
6374961a | 1816 | tb[nl_mask_type], NULL); |
eb3b5696 | 1817 | |
e28b88a4 | 1818 | flower_print_ip4_addr("arp_sip", tb[TCA_FLOWER_KEY_ARP_SIP], |
f888f4e2 | 1819 | tb[TCA_FLOWER_KEY_ARP_SIP_MASK]); |
e28b88a4 | 1820 | flower_print_ip4_addr("arp_tip", tb[TCA_FLOWER_KEY_ARP_TIP], |
f888f4e2 | 1821 | tb[TCA_FLOWER_KEY_ARP_TIP_MASK]); |
e28b88a4 | 1822 | flower_print_arp_op("arp_op", tb[TCA_FLOWER_KEY_ARP_OP], |
f888f4e2 | 1823 | tb[TCA_FLOWER_KEY_ARP_OP_MASK]); |
e28b88a4 | 1824 | flower_print_eth_addr("arp_sha", tb[TCA_FLOWER_KEY_ARP_SHA], |
f888f4e2 | 1825 | tb[TCA_FLOWER_KEY_ARP_SHA_MASK]); |
e28b88a4 | 1826 | flower_print_eth_addr("arp_tha", tb[TCA_FLOWER_KEY_ARP_THA], |
f888f4e2 SH |
1827 | tb[TCA_FLOWER_KEY_ARP_THA_MASK]); |
1828 | ||
e28b88a4 | 1829 | flower_print_ip_addr("enc_dst_ip", |
bb9b63b1 AV |
1830 | tb[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK] ? |
1831 | htons(ETH_P_IP) : htons(ETH_P_IPV6), | |
1832 | tb[TCA_FLOWER_KEY_ENC_IPV4_DST], | |
1833 | tb[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK], | |
1834 | tb[TCA_FLOWER_KEY_ENC_IPV6_DST], | |
1835 | tb[TCA_FLOWER_KEY_ENC_IPV6_DST_MASK]); | |
1836 | ||
e28b88a4 | 1837 | flower_print_ip_addr("enc_src_ip", |
bb9b63b1 AV |
1838 | tb[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK] ? |
1839 | htons(ETH_P_IP) : htons(ETH_P_IPV6), | |
1840 | tb[TCA_FLOWER_KEY_ENC_IPV4_SRC], | |
1841 | tb[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK], | |
1842 | tb[TCA_FLOWER_KEY_ENC_IPV6_SRC], | |
1843 | tb[TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK]); | |
1844 | ||
e28b88a4 | 1845 | flower_print_key_id("enc_key_id", tb[TCA_FLOWER_KEY_ENC_KEY_ID]); |
bb9b63b1 | 1846 | |
e28b88a4 | 1847 | flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]); |
41aa17ff | 1848 | |
761ec9e2 OG |
1849 | flower_print_ip_attr("enc_tos", tb[TCA_FLOWER_KEY_ENC_IP_TOS], |
1850 | tb[TCA_FLOWER_KEY_ENC_IP_TOS_MASK]); | |
1851 | flower_print_ip_attr("enc_ttl", tb[TCA_FLOWER_KEY_ENC_IP_TTL], | |
1852 | tb[TCA_FLOWER_KEY_ENC_IP_TTL_MASK]); | |
56155d4d PJV |
1853 | flower_print_enc_opts("enc_opt", tb[TCA_FLOWER_KEY_ENC_OPTS], |
1854 | tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]); | |
761ec9e2 | 1855 | |
e28b88a4 | 1856 | flower_print_matching_flags("ip_flags", FLOWER_IP_FLAGS, |
22a8f019 PB |
1857 | tb[TCA_FLOWER_KEY_FLAGS], |
1858 | tb[TCA_FLOWER_KEY_FLAGS_MASK]); | |
1859 | ||
e28b88a4 JP |
1860 | close_json_object(); |
1861 | ||
512caeb2 | 1862 | if (tb[TCA_FLOWER_FLAGS]) { |
cfcabf18 AV |
1863 | __u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]); |
1864 | ||
1865 | if (flags & TCA_CLS_FLAGS_SKIP_HW) | |
e28b88a4 | 1866 | print_bool(PRINT_ANY, "skip_hw", "\n skip_hw", true); |
cfcabf18 | 1867 | if (flags & TCA_CLS_FLAGS_SKIP_SW) |
e28b88a4 | 1868 | print_bool(PRINT_ANY, "skip_sw", "\n skip_sw", true); |
e57285b8 | 1869 | |
f6b498f9 | 1870 | if (flags & TCA_CLS_FLAGS_IN_HW) { |
e28b88a4 | 1871 | print_bool(PRINT_ANY, "in_hw", "\n in_hw", true); |
f6b498f9 VB |
1872 | |
1873 | if (tb[TCA_FLOWER_IN_HW_COUNT]) { | |
1874 | __u32 count = rta_getattr_u32(tb[TCA_FLOWER_IN_HW_COUNT]); | |
1875 | ||
1876 | print_uint(PRINT_ANY, "in_hw_count", | |
1877 | " in_hw_count %u", count); | |
1878 | } | |
1879 | } | |
e57285b8 | 1880 | else if (flags & TCA_CLS_FLAGS_NOT_IN_HW) |
e28b88a4 | 1881 | print_bool(PRINT_ANY, "not_in_hw", "\n not_in_hw", true); |
cfcabf18 AV |
1882 | } |
1883 | ||
512caeb2 | 1884 | if (tb[TCA_FLOWER_ACT]) |
9e713525 | 1885 | tc_print_action(f, tb[TCA_FLOWER_ACT], 0); |
30eb304e JP |
1886 | |
1887 | return 0; | |
1888 | } | |
1889 | ||
1890 | struct filter_util flower_filter_util = { | |
1891 | .id = "flower", | |
1892 | .parse_fopt = flower_parse_opt, | |
1893 | .print_fopt = flower_print_opt, | |
1894 | }; |