2 * f_flower.c Flower Classifier
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.
9 * Authors: Jiri Pirko <jiri@resnulli.us>
17 #include <linux/if_arp.h>
18 #include <linux/if_ether.h>
20 #include <linux/tc_act/tc_vlan.h>
21 #include <linux/mpls.h>
27 enum flower_matching_flags
{
31 enum flower_endpoint
{
36 enum flower_icmp_field
{
37 FLOWER_ICMP_FIELD_TYPE
,
38 FLOWER_ICMP_FIELD_CODE
41 static void explain(void)
44 "Usage: ... flower [ MATCH-LIST ] [ verbose ]\n"
45 " [ skip_sw | skip_hw ]\n"
46 " [ action ACTION-SPEC ] [ classid CLASSID ]\n"
48 "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n"
49 " MATCH := { indev DEV-NAME |\n"
51 " vlan_prio PRIORITY |\n"
52 " vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
54 " cvlan_prio PRIORITY |\n"
55 " cvlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
56 " dst_mac MASKED-LLADDR |\n"
57 " src_mac MASKED-LLADDR |\n"
58 " ip_proto [tcp | udp | sctp | icmp | icmpv6 | IP-PROTO ] |\n"
59 " ip_tos MASKED-IP_TOS |\n"
60 " ip_ttl MASKED-IP_TTL |\n"
61 " mpls_label LABEL |\n"
67 " dst_port PORT-NUMBER |\n"
68 " src_port PORT-NUMBER |\n"
69 " tcp_flags MASKED-TCP_FLAGS |\n"
70 " type MASKED-ICMP-TYPE |\n"
71 " code MASKED-ICMP-CODE |\n"
72 " arp_tip IPV4-PREFIX |\n"
73 " arp_sip IPV4-PREFIX |\n"
74 " arp_op [ request | reply | OP ] |\n"
75 " arp_tha MASKED-LLADDR |\n"
76 " arp_sha MASKED-LLADDR |\n"
77 " enc_dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
78 " enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
79 " enc_key_id [ KEY-ID ] |\n"
80 " ip_flags IP-FLAGS | \n"
81 " enc_dst_port [ port_number ] }\n"
82 " FILTERID := X:Y:Z\n"
83 " MASKED_LLADDR := { LLADDR | LLADDR/MASK | LLADDR/BITS }\n"
84 " ACTION-SPEC := ... look at individual actions\n"
86 "NOTE: CLASSID, IP-PROTO are parsed as hexadecimal input.\n"
87 "NOTE: There can be only used one mask per one prio. If user needs\n"
88 " to specify different mask, he has to use different prio.\n");
91 static int flower_parse_eth_addr(char *str
, int addr_type
, int mask_type
,
95 char addr
[ETH_ALEN
], *slash
;
97 slash
= strchr(str
, '/');
101 ret
= ll_addr_a2n(addr
, sizeof(addr
), str
);
104 addattr_l(n
, MAX_MSG
, addr_type
, addr
, sizeof(addr
));
109 if (!get_unsigned(&bits
, slash
+ 1, 10)) {
112 /* Extra 16 bit shift to push mac address into
113 * high bits of uint64_t
115 mask
= htonll(0xffffffffffffULL
<< (16 + 48 - bits
));
116 memcpy(addr
, &mask
, ETH_ALEN
);
118 ret
= ll_addr_a2n(addr
, sizeof(addr
), slash
+ 1);
123 memset(addr
, 0xff, ETH_ALEN
);
125 addattr_l(n
, MAX_MSG
, mask_type
, addr
, sizeof(addr
));
134 static bool eth_type_vlan(__be16 ethertype
)
136 return ethertype
== htons(ETH_P_8021Q
) ||
137 ethertype
== htons(ETH_P_8021AD
);
140 static int flower_parse_vlan_eth_type(char *str
, __be16 eth_type
, int type
,
141 __be16
*p_vlan_eth_type
,
144 __be16 vlan_eth_type
;
146 if (!eth_type_vlan(eth_type
)) {
147 fprintf(stderr
, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD\n",
148 type
== TCA_FLOWER_KEY_VLAN_ETH_TYPE
? "vlan_ethtype" : "cvlan_ethtype");
152 if (ll_proto_a2n(&vlan_eth_type
, str
))
153 invarg("invalid vlan_ethtype", str
);
154 addattr16(n
, MAX_MSG
, type
, vlan_eth_type
);
155 *p_vlan_eth_type
= vlan_eth_type
;
159 struct flag_to_string
{
161 enum flower_matching_flags type
;
165 static struct flag_to_string flags_str
[] = {
166 { TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT
, FLOWER_IP_FLAGS
, "frag" },
167 { TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST
, FLOWER_IP_FLAGS
, "firstfrag" },
170 static int flower_parse_matching_flags(char *str
,
171 enum flower_matching_flags type
,
172 __u32
*mtf
, __u32
*mtf_mask
)
179 token
= strtok(str
, "/");
182 if (!strncmp(token
, "no", 2)) {
189 for (i
= 0; i
< ARRAY_SIZE(flags_str
); i
++) {
190 if (type
!= flags_str
[i
].type
)
193 if (!strcmp(token
, flags_str
[i
].string
)) {
195 *mtf
&= ~flags_str
[i
].flag
;
197 *mtf
|= flags_str
[i
].flag
;
199 *mtf_mask
|= flags_str
[i
].flag
;
207 token
= strtok(NULL
, "/");
213 static int flower_parse_ip_proto(char *str
, __be16 eth_type
, int type
,
214 __u8
*p_ip_proto
, struct nlmsghdr
*n
)
219 if (eth_type
!= htons(ETH_P_IP
) && eth_type
!= htons(ETH_P_IPV6
))
222 if (matches(str
, "tcp") == 0) {
223 ip_proto
= IPPROTO_TCP
;
224 } else if (matches(str
, "udp") == 0) {
225 ip_proto
= IPPROTO_UDP
;
226 } else if (matches(str
, "sctp") == 0) {
227 ip_proto
= IPPROTO_SCTP
;
228 } else if (matches(str
, "icmp") == 0) {
229 if (eth_type
!= htons(ETH_P_IP
))
231 ip_proto
= IPPROTO_ICMP
;
232 } else if (matches(str
, "icmpv6") == 0) {
233 if (eth_type
!= htons(ETH_P_IPV6
))
235 ip_proto
= IPPROTO_ICMPV6
;
237 ret
= get_u8(&ip_proto
, str
, 16);
241 addattr8(n
, MAX_MSG
, type
, ip_proto
);
242 *p_ip_proto
= ip_proto
;
246 fprintf(stderr
, "Illegal \"eth_type\" for ip proto\n");
250 static int __flower_parse_ip_addr(char *str
, int family
,
251 int addr4_type
, int mask4_type
,
252 int addr6_type
, int mask6_type
,
260 ret
= get_prefix(&addr
, str
, family
);
264 if (family
&& (addr
.family
!= family
)) {
265 fprintf(stderr
, "Illegal \"eth_type\" for ip address\n");
269 addattr_l(n
, MAX_MSG
, addr
.family
== AF_INET
? addr4_type
: addr6_type
,
270 addr
.data
, addr
.bytelen
);
272 memset(addr
.data
, 0xff, addr
.bytelen
);
274 for (i
= 0; i
< addr
.bytelen
/ 4; i
++) {
277 } else if (bits
/ 32 >= 1) {
280 addr
.data
[i
] <<= 32 - bits
;
281 addr
.data
[i
] = htonl(addr
.data
[i
]);
286 addattr_l(n
, MAX_MSG
, addr
.family
== AF_INET
? mask4_type
: mask6_type
,
287 addr
.data
, addr
.bytelen
);
292 static int flower_parse_ip_addr(char *str
, __be16 eth_type
,
293 int addr4_type
, int mask4_type
,
294 int addr6_type
, int mask6_type
,
299 if (eth_type
== htons(ETH_P_IP
)) {
301 } else if (eth_type
== htons(ETH_P_IPV6
)) {
303 } else if (!eth_type
) {
309 return __flower_parse_ip_addr(str
, family
, addr4_type
, mask4_type
,
310 addr6_type
, mask6_type
, n
);
313 static bool flower_eth_type_arp(__be16 eth_type
)
315 return eth_type
== htons(ETH_P_ARP
) || eth_type
== htons(ETH_P_RARP
);
318 static int flower_parse_arp_ip_addr(char *str
, __be16 eth_type
,
319 int addr_type
, int mask_type
,
322 if (!flower_eth_type_arp(eth_type
))
325 return __flower_parse_ip_addr(str
, AF_INET
, addr_type
, mask_type
,
326 TCA_FLOWER_UNSPEC
, TCA_FLOWER_UNSPEC
, n
);
329 static int flower_parse_u8(char *str
, int value_type
, int mask_type
,
330 int (*value_from_name
)(const char *str
,
332 bool (*value_validate
)(__u8 value
),
339 slash
= strchr(str
, '/');
343 ret
= value_from_name
? value_from_name(str
, &value
) : -1;
345 ret
= get_u8(&value
, str
, 10);
350 if (value_validate
&& !value_validate(value
))
354 ret
= get_u8(&mask
, slash
+ 1, 10);
362 addattr8(n
, MAX_MSG
, value_type
, value
);
363 addattr8(n
, MAX_MSG
, mask_type
, mask
);
372 static const char *flower_print_arp_op_to_name(__u8 op
)
384 static int flower_arp_op_from_name(const char *name
, __u8
*op
)
386 if (!strcmp(name
, "request"))
388 else if (!strcmp(name
, "reply"))
396 static bool flow_arp_op_validate(__u8 op
)
398 return !op
|| op
== ARPOP_REQUEST
|| op
== ARPOP_REPLY
;
401 static int flower_parse_arp_op(char *str
, __be16 eth_type
,
402 int op_type
, int mask_type
,
405 if (!flower_eth_type_arp(eth_type
))
408 return flower_parse_u8(str
, op_type
, mask_type
, flower_arp_op_from_name
,
409 flow_arp_op_validate
, n
);
412 static int flower_icmp_attr_type(__be16 eth_type
, __u8 ip_proto
,
413 enum flower_icmp_field field
)
415 if (eth_type
== htons(ETH_P_IP
) && ip_proto
== IPPROTO_ICMP
)
416 return field
== FLOWER_ICMP_FIELD_CODE
?
417 TCA_FLOWER_KEY_ICMPV4_CODE
:
418 TCA_FLOWER_KEY_ICMPV4_TYPE
;
419 else if (eth_type
== htons(ETH_P_IPV6
) && ip_proto
== IPPROTO_ICMPV6
)
420 return field
== FLOWER_ICMP_FIELD_CODE
?
421 TCA_FLOWER_KEY_ICMPV6_CODE
:
422 TCA_FLOWER_KEY_ICMPV6_TYPE
;
427 static int flower_icmp_attr_mask_type(__be16 eth_type
, __u8 ip_proto
,
428 enum flower_icmp_field field
)
430 if (eth_type
== htons(ETH_P_IP
) && ip_proto
== IPPROTO_ICMP
)
431 return field
== FLOWER_ICMP_FIELD_CODE
?
432 TCA_FLOWER_KEY_ICMPV4_CODE_MASK
:
433 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK
;
434 else if (eth_type
== htons(ETH_P_IPV6
) && ip_proto
== IPPROTO_ICMPV6
)
435 return field
== FLOWER_ICMP_FIELD_CODE
?
436 TCA_FLOWER_KEY_ICMPV6_CODE_MASK
:
437 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK
;
442 static int flower_parse_icmp(char *str
, __u16 eth_type
, __u8 ip_proto
,
443 enum flower_icmp_field field
, struct nlmsghdr
*n
)
445 int value_type
, mask_type
;
447 value_type
= flower_icmp_attr_type(eth_type
, ip_proto
, field
);
448 mask_type
= flower_icmp_attr_mask_type(eth_type
, ip_proto
, field
);
449 if (value_type
< 0 || mask_type
< 0)
452 return flower_parse_u8(str
, value_type
, mask_type
, NULL
, NULL
, n
);
455 static int flower_port_attr_type(__u8 ip_proto
, enum flower_endpoint endpoint
)
457 if (ip_proto
== IPPROTO_TCP
)
458 return endpoint
== FLOWER_ENDPOINT_SRC
?
459 TCA_FLOWER_KEY_TCP_SRC
:
460 TCA_FLOWER_KEY_TCP_DST
;
461 else if (ip_proto
== IPPROTO_UDP
)
462 return endpoint
== FLOWER_ENDPOINT_SRC
?
463 TCA_FLOWER_KEY_UDP_SRC
:
464 TCA_FLOWER_KEY_UDP_DST
;
465 else if (ip_proto
== IPPROTO_SCTP
)
466 return endpoint
== FLOWER_ENDPOINT_SRC
?
467 TCA_FLOWER_KEY_SCTP_SRC
:
468 TCA_FLOWER_KEY_SCTP_DST
;
473 static int flower_parse_port(char *str
, __u8 ip_proto
,
474 enum flower_endpoint endpoint
,
481 type
= flower_port_attr_type(ip_proto
, endpoint
);
485 ret
= get_be16(&port
, str
, 10);
489 addattr16(n
, MAX_MSG
, type
, port
);
494 #define TCP_FLAGS_MAX_MASK 0xfff
496 static int flower_parse_tcp_flags(char *str
, int flags_type
, int mask_type
,
503 slash
= strchr(str
, '/');
507 ret
= get_u16(&flags
, str
, 16);
508 if (ret
< 0 || flags
& ~TCP_FLAGS_MAX_MASK
)
511 addattr16(n
, MAX_MSG
, flags_type
, htons(flags
));
514 ret
= get_u16(&flags
, slash
+ 1, 16);
515 if (ret
< 0 || flags
& ~TCP_FLAGS_MAX_MASK
)
518 flags
= TCP_FLAGS_MAX_MASK
;
520 addattr16(n
, MAX_MSG
, mask_type
, htons(flags
));
529 static int flower_parse_ip_tos_ttl(char *str
, int key_type
, int mask_type
,
536 slash
= strchr(str
, '/');
540 ret
= get_u8(&tos_ttl
, str
, 10);
542 ret
= get_u8(&tos_ttl
, str
, 16);
546 addattr8(n
, MAX_MSG
, key_type
, tos_ttl
);
549 ret
= get_u8(&tos_ttl
, slash
+ 1, 16);
555 addattr8(n
, MAX_MSG
, mask_type
, tos_ttl
);
564 static int flower_parse_key_id(const char *str
, int type
, struct nlmsghdr
*n
)
569 ret
= get_be32(&key_id
, str
, 10);
571 addattr32(n
, MAX_MSG
, type
, key_id
);
576 static int flower_parse_enc_port(char *str
, int type
, struct nlmsghdr
*n
)
581 ret
= get_be16(&port
, str
, 10);
585 addattr16(n
, MAX_MSG
, type
, port
);
590 static int flower_parse_opt(struct filter_util
*qu
, char *handle
,
591 int argc
, char **argv
, struct nlmsghdr
*n
)
594 struct tcmsg
*t
= NLMSG_DATA(n
);
596 __be16 eth_type
= TC_H_MIN(t
->tcm_info
);
597 __be16 vlan_ethtype
= 0;
598 __be16 cvlan_ethtype
= 0;
599 __u8 ip_proto
= 0xff;
605 ret
= get_u32(&t
->tcm_handle
, handle
, 0);
607 fprintf(stderr
, "Illegal \"handle\"\n");
612 tail
= (struct rtattr
*) (((void *) n
) + NLMSG_ALIGN(n
->nlmsg_len
));
613 addattr_l(n
, MAX_MSG
, TCA_OPTIONS
, NULL
, 0);
616 /*at minimal we will match all ethertype packets */
621 if (matches(*argv
, "classid") == 0 ||
622 matches(*argv
, "flowid") == 0) {
626 ret
= get_tc_classid(&handle
, *argv
);
628 fprintf(stderr
, "Illegal \"classid\"\n");
631 addattr_l(n
, MAX_MSG
, TCA_FLOWER_CLASSID
, &handle
, 4);
632 } else if (matches(*argv
, "hw_tc") == 0) {
638 tc
= strtoul(*argv
, &end
, 0);
640 fprintf(stderr
, "Illegal TC index\n");
643 if (tc
>= TC_QOPT_MAX_QUEUE
) {
644 fprintf(stderr
, "TC index exceeds max range\n");
647 handle
= TC_H_MAKE(TC_H_MAJ(t
->tcm_parent
),
648 TC_H_MIN(tc
+ TC_H_MIN_PRIORITY
));
649 addattr_l(n
, MAX_MSG
, TCA_FLOWER_CLASSID
, &handle
,
651 } else if (matches(*argv
, "ip_flags") == 0) {
653 ret
= flower_parse_matching_flags(*argv
,
658 fprintf(stderr
, "Illegal \"ip_flags\"\n");
661 } else if (matches(*argv
, "verbose") == 0) {
662 flags
|= TCA_CLS_FLAGS_VERBOSE
;
663 } else if (matches(*argv
, "skip_hw") == 0) {
664 flags
|= TCA_CLS_FLAGS_SKIP_HW
;
665 } else if (matches(*argv
, "skip_sw") == 0) {
666 flags
|= TCA_CLS_FLAGS_SKIP_SW
;
667 } else if (matches(*argv
, "indev") == 0) {
669 if (check_ifname(*argv
))
670 invarg("\"indev\" not a valid ifname", *argv
);
671 addattrstrz(n
, MAX_MSG
, TCA_FLOWER_INDEV
, *argv
);
672 } else if (matches(*argv
, "vlan_id") == 0) {
676 if (!eth_type_vlan(eth_type
)) {
677 fprintf(stderr
, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD\n");
680 ret
= get_u16(&vid
, *argv
, 10);
681 if (ret
< 0 || vid
& ~0xfff) {
682 fprintf(stderr
, "Illegal \"vlan_id\"\n");
685 addattr16(n
, MAX_MSG
, TCA_FLOWER_KEY_VLAN_ID
, vid
);
686 } else if (matches(*argv
, "vlan_prio") == 0) {
690 if (!eth_type_vlan(eth_type
)) {
691 fprintf(stderr
, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD\n");
694 ret
= get_u8(&vlan_prio
, *argv
, 10);
695 if (ret
< 0 || vlan_prio
& ~0x7) {
696 fprintf(stderr
, "Illegal \"vlan_prio\"\n");
700 TCA_FLOWER_KEY_VLAN_PRIO
, vlan_prio
);
701 } else if (matches(*argv
, "vlan_ethtype") == 0) {
703 ret
= flower_parse_vlan_eth_type(*argv
, eth_type
,
704 TCA_FLOWER_KEY_VLAN_ETH_TYPE
,
708 } else if (matches(*argv
, "cvlan_id") == 0) {
712 if (!eth_type_vlan(vlan_ethtype
)) {
713 fprintf(stderr
, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
716 ret
= get_u16(&vid
, *argv
, 10);
717 if (ret
< 0 || vid
& ~0xfff) {
718 fprintf(stderr
, "Illegal \"cvlan_id\"\n");
721 addattr16(n
, MAX_MSG
, TCA_FLOWER_KEY_CVLAN_ID
, vid
);
722 } else if (matches(*argv
, "cvlan_prio") == 0) {
726 if (!eth_type_vlan(vlan_ethtype
)) {
727 fprintf(stderr
, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
730 ret
= get_u8(&cvlan_prio
, *argv
, 10);
731 if (ret
< 0 || cvlan_prio
& ~0x7) {
732 fprintf(stderr
, "Illegal \"cvlan_prio\"\n");
736 TCA_FLOWER_KEY_CVLAN_PRIO
, cvlan_prio
);
737 } else if (matches(*argv
, "cvlan_ethtype") == 0) {
739 ret
= flower_parse_vlan_eth_type(*argv
, vlan_ethtype
,
740 TCA_FLOWER_KEY_CVLAN_ETH_TYPE
,
744 } else if (matches(*argv
, "mpls_label") == 0) {
748 if (eth_type
!= htons(ETH_P_MPLS_UC
) &&
749 eth_type
!= htons(ETH_P_MPLS_MC
)) {
751 "Can't set \"mpls_label\" if ethertype isn't MPLS\n");
754 ret
= get_u32(&label
, *argv
, 10);
755 if (ret
< 0 || label
& ~(MPLS_LS_LABEL_MASK
>> MPLS_LS_LABEL_SHIFT
)) {
756 fprintf(stderr
, "Illegal \"mpls_label\"\n");
759 addattr32(n
, MAX_MSG
, TCA_FLOWER_KEY_MPLS_LABEL
, label
);
760 } else if (matches(*argv
, "mpls_tc") == 0) {
764 if (eth_type
!= htons(ETH_P_MPLS_UC
) &&
765 eth_type
!= htons(ETH_P_MPLS_MC
)) {
767 "Can't set \"mpls_tc\" if ethertype isn't MPLS\n");
770 ret
= get_u8(&tc
, *argv
, 10);
771 if (ret
< 0 || tc
& ~(MPLS_LS_TC_MASK
>> MPLS_LS_TC_SHIFT
)) {
772 fprintf(stderr
, "Illegal \"mpls_tc\"\n");
775 addattr8(n
, MAX_MSG
, TCA_FLOWER_KEY_MPLS_TC
, tc
);
776 } else if (matches(*argv
, "mpls_bos") == 0) {
780 if (eth_type
!= htons(ETH_P_MPLS_UC
) &&
781 eth_type
!= htons(ETH_P_MPLS_MC
)) {
783 "Can't set \"mpls_bos\" if ethertype isn't MPLS\n");
786 ret
= get_u8(&bos
, *argv
, 10);
787 if (ret
< 0 || bos
& ~(MPLS_LS_S_MASK
>> MPLS_LS_S_SHIFT
)) {
788 fprintf(stderr
, "Illegal \"mpls_bos\"\n");
791 addattr8(n
, MAX_MSG
, TCA_FLOWER_KEY_MPLS_BOS
, bos
);
792 } else if (matches(*argv
, "mpls_ttl") == 0) {
796 if (eth_type
!= htons(ETH_P_MPLS_UC
) &&
797 eth_type
!= htons(ETH_P_MPLS_MC
)) {
799 "Can't set \"mpls_ttl\" if ethertype isn't MPLS\n");
802 ret
= get_u8(&ttl
, *argv
, 10);
803 if (ret
< 0 || ttl
& ~(MPLS_LS_TTL_MASK
>> MPLS_LS_TTL_SHIFT
)) {
804 fprintf(stderr
, "Illegal \"mpls_ttl\"\n");
807 addattr8(n
, MAX_MSG
, TCA_FLOWER_KEY_MPLS_TTL
, ttl
);
808 } else if (matches(*argv
, "dst_mac") == 0) {
810 ret
= flower_parse_eth_addr(*argv
,
811 TCA_FLOWER_KEY_ETH_DST
,
812 TCA_FLOWER_KEY_ETH_DST_MASK
,
815 fprintf(stderr
, "Illegal \"dst_mac\"\n");
818 } else if (matches(*argv
, "src_mac") == 0) {
820 ret
= flower_parse_eth_addr(*argv
,
821 TCA_FLOWER_KEY_ETH_SRC
,
822 TCA_FLOWER_KEY_ETH_SRC_MASK
,
825 fprintf(stderr
, "Illegal \"src_mac\"\n");
828 } else if (matches(*argv
, "ip_proto") == 0) {
830 ret
= flower_parse_ip_proto(*argv
, cvlan_ethtype
?
831 cvlan_ethtype
: vlan_ethtype
?
832 vlan_ethtype
: eth_type
,
833 TCA_FLOWER_KEY_IP_PROTO
,
836 fprintf(stderr
, "Illegal \"ip_proto\"\n");
839 } else if (matches(*argv
, "ip_tos") == 0) {
841 ret
= flower_parse_ip_tos_ttl(*argv
,
842 TCA_FLOWER_KEY_IP_TOS
,
843 TCA_FLOWER_KEY_IP_TOS_MASK
,
846 fprintf(stderr
, "Illegal \"ip_tos\"\n");
849 } else if (matches(*argv
, "ip_ttl") == 0) {
851 ret
= flower_parse_ip_tos_ttl(*argv
,
852 TCA_FLOWER_KEY_IP_TTL
,
853 TCA_FLOWER_KEY_IP_TTL_MASK
,
856 fprintf(stderr
, "Illegal \"ip_ttl\"\n");
859 } else if (matches(*argv
, "dst_ip") == 0) {
861 ret
= flower_parse_ip_addr(*argv
, cvlan_ethtype
?
862 cvlan_ethtype
: vlan_ethtype
?
863 vlan_ethtype
: eth_type
,
864 TCA_FLOWER_KEY_IPV4_DST
,
865 TCA_FLOWER_KEY_IPV4_DST_MASK
,
866 TCA_FLOWER_KEY_IPV6_DST
,
867 TCA_FLOWER_KEY_IPV6_DST_MASK
,
870 fprintf(stderr
, "Illegal \"dst_ip\"\n");
873 } else if (matches(*argv
, "src_ip") == 0) {
875 ret
= flower_parse_ip_addr(*argv
, cvlan_ethtype
?
876 cvlan_ethtype
: vlan_ethtype
?
877 vlan_ethtype
: eth_type
,
878 TCA_FLOWER_KEY_IPV4_SRC
,
879 TCA_FLOWER_KEY_IPV4_SRC_MASK
,
880 TCA_FLOWER_KEY_IPV6_SRC
,
881 TCA_FLOWER_KEY_IPV6_SRC_MASK
,
884 fprintf(stderr
, "Illegal \"src_ip\"\n");
887 } else if (matches(*argv
, "dst_port") == 0) {
889 ret
= flower_parse_port(*argv
, ip_proto
,
890 FLOWER_ENDPOINT_DST
, n
);
892 fprintf(stderr
, "Illegal \"dst_port\"\n");
895 } else if (matches(*argv
, "src_port") == 0) {
897 ret
= flower_parse_port(*argv
, ip_proto
,
898 FLOWER_ENDPOINT_SRC
, n
);
900 fprintf(stderr
, "Illegal \"src_port\"\n");
903 } else if (matches(*argv
, "tcp_flags") == 0) {
905 ret
= flower_parse_tcp_flags(*argv
,
906 TCA_FLOWER_KEY_TCP_FLAGS
,
907 TCA_FLOWER_KEY_TCP_FLAGS_MASK
,
910 fprintf(stderr
, "Illegal \"tcp_flags\"\n");
913 } else if (matches(*argv
, "type") == 0) {
915 ret
= flower_parse_icmp(*argv
, eth_type
, ip_proto
,
916 FLOWER_ICMP_FIELD_TYPE
, n
);
918 fprintf(stderr
, "Illegal \"icmp type\"\n");
921 } else if (matches(*argv
, "code") == 0) {
923 ret
= flower_parse_icmp(*argv
, eth_type
, ip_proto
,
924 FLOWER_ICMP_FIELD_CODE
, n
);
926 fprintf(stderr
, "Illegal \"icmp code\"\n");
929 } else if (matches(*argv
, "arp_tip") == 0) {
931 ret
= flower_parse_arp_ip_addr(*argv
, vlan_ethtype
?
932 vlan_ethtype
: eth_type
,
933 TCA_FLOWER_KEY_ARP_TIP
,
934 TCA_FLOWER_KEY_ARP_TIP_MASK
,
937 fprintf(stderr
, "Illegal \"arp_tip\"\n");
940 } else if (matches(*argv
, "arp_sip") == 0) {
942 ret
= flower_parse_arp_ip_addr(*argv
, vlan_ethtype
?
943 vlan_ethtype
: eth_type
,
944 TCA_FLOWER_KEY_ARP_SIP
,
945 TCA_FLOWER_KEY_ARP_SIP_MASK
,
948 fprintf(stderr
, "Illegal \"arp_sip\"\n");
951 } else if (matches(*argv
, "arp_op") == 0) {
953 ret
= flower_parse_arp_op(*argv
, vlan_ethtype
?
954 vlan_ethtype
: eth_type
,
955 TCA_FLOWER_KEY_ARP_OP
,
956 TCA_FLOWER_KEY_ARP_OP_MASK
,
959 fprintf(stderr
, "Illegal \"arp_op\"\n");
962 } else if (matches(*argv
, "arp_tha") == 0) {
964 ret
= flower_parse_eth_addr(*argv
,
965 TCA_FLOWER_KEY_ARP_THA
,
966 TCA_FLOWER_KEY_ARP_THA_MASK
,
969 fprintf(stderr
, "Illegal \"arp_tha\"\n");
972 } else if (matches(*argv
, "arp_sha") == 0) {
974 ret
= flower_parse_eth_addr(*argv
,
975 TCA_FLOWER_KEY_ARP_SHA
,
976 TCA_FLOWER_KEY_ARP_SHA_MASK
,
979 fprintf(stderr
, "Illegal \"arp_sha\"\n");
982 } else if (matches(*argv
, "enc_dst_ip") == 0) {
984 ret
= flower_parse_ip_addr(*argv
, 0,
985 TCA_FLOWER_KEY_ENC_IPV4_DST
,
986 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK
,
987 TCA_FLOWER_KEY_ENC_IPV6_DST
,
988 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK
,
991 fprintf(stderr
, "Illegal \"enc_dst_ip\"\n");
994 } else if (matches(*argv
, "enc_src_ip") == 0) {
996 ret
= flower_parse_ip_addr(*argv
, 0,
997 TCA_FLOWER_KEY_ENC_IPV4_SRC
,
998 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK
,
999 TCA_FLOWER_KEY_ENC_IPV6_SRC
,
1000 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK
,
1003 fprintf(stderr
, "Illegal \"enc_src_ip\"\n");
1006 } else if (matches(*argv
, "enc_key_id") == 0) {
1008 ret
= flower_parse_key_id(*argv
,
1009 TCA_FLOWER_KEY_ENC_KEY_ID
, n
);
1011 fprintf(stderr
, "Illegal \"enc_key_id\"\n");
1014 } else if (matches(*argv
, "enc_dst_port") == 0) {
1016 ret
= flower_parse_enc_port(*argv
,
1017 TCA_FLOWER_KEY_ENC_UDP_DST_PORT
, n
);
1019 fprintf(stderr
, "Illegal \"enc_dst_port\"\n");
1022 } else if (matches(*argv
, "action") == 0) {
1024 ret
= parse_action(&argc
, &argv
, TCA_FLOWER_ACT
, n
);
1026 fprintf(stderr
, "Illegal \"action\"\n");
1030 } else if (strcmp(*argv
, "help") == 0) {
1034 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
1042 ret
= addattr32(n
, MAX_MSG
, TCA_FLOWER_FLAGS
, flags
);
1047 ret
= addattr32(n
, MAX_MSG
, TCA_FLOWER_KEY_FLAGS
, htonl(mtf
));
1051 ret
= addattr32(n
, MAX_MSG
, TCA_FLOWER_KEY_FLAGS_MASK
, htonl(mtf_mask
));
1056 if (eth_type
!= htons(ETH_P_ALL
)) {
1057 ret
= addattr16(n
, MAX_MSG
, TCA_FLOWER_KEY_ETH_TYPE
, eth_type
);
1062 tail
->rta_len
= (((void *)n
)+n
->nlmsg_len
) - (void *)tail
;
1067 static int __mask_bits(char *addr
, size_t len
)
1074 for (i
= 0; i
< len
; i
++, addr
++) {
1075 for (j
= 7; j
>= 0; j
--) {
1076 if (((*addr
) >> j
) & 0x1) {
1090 static void flower_print_eth_addr(char *name
, struct rtattr
*addr_attr
,
1091 struct rtattr
*mask_attr
)
1093 SPRINT_BUF(namefrm
);
1099 if (!addr_attr
|| RTA_PAYLOAD(addr_attr
) != ETH_ALEN
)
1101 done
= sprintf(out
, "%s",
1102 ll_addr_n2a(RTA_DATA(addr_attr
), ETH_ALEN
,
1103 0, b1
, sizeof(b1
)));
1104 if (mask_attr
&& RTA_PAYLOAD(mask_attr
) == ETH_ALEN
) {
1105 bits
= __mask_bits(RTA_DATA(mask_attr
), ETH_ALEN
);
1107 sprintf(out
+ done
, "/%s",
1108 ll_addr_n2a(RTA_DATA(mask_attr
), ETH_ALEN
,
1109 0, b1
, sizeof(b1
)));
1110 else if (bits
< ETH_ALEN
* 8)
1111 sprintf(out
+ done
, "/%d", bits
);
1114 sprintf(namefrm
, "\n %s %%s", name
);
1115 print_string(PRINT_ANY
, name
, namefrm
, out
);
1118 static void flower_print_eth_type(__be16
*p_eth_type
,
1119 struct rtattr
*eth_type_attr
)
1127 eth_type
= rta_getattr_u16(eth_type_attr
);
1128 if (eth_type
== htons(ETH_P_IP
))
1129 sprintf(out
, "ipv4");
1130 else if (eth_type
== htons(ETH_P_IPV6
))
1131 sprintf(out
, "ipv6");
1132 else if (eth_type
== htons(ETH_P_ARP
))
1133 sprintf(out
, "arp");
1134 else if (eth_type
== htons(ETH_P_RARP
))
1135 sprintf(out
, "rarp");
1137 sprintf(out
, "%04x", ntohs(eth_type
));
1139 print_string(PRINT_ANY
, "eth_type", "\n eth_type %s", out
);
1140 *p_eth_type
= eth_type
;
1143 static void flower_print_ip_proto(__u8
*p_ip_proto
,
1144 struct rtattr
*ip_proto_attr
)
1152 ip_proto
= rta_getattr_u8(ip_proto_attr
);
1153 if (ip_proto
== IPPROTO_TCP
)
1154 sprintf(out
, "tcp");
1155 else if (ip_proto
== IPPROTO_UDP
)
1156 sprintf(out
, "udp");
1157 else if (ip_proto
== IPPROTO_SCTP
)
1158 sprintf(out
, "sctp");
1159 else if (ip_proto
== IPPROTO_ICMP
)
1160 sprintf(out
, "icmp");
1161 else if (ip_proto
== IPPROTO_ICMPV6
)
1162 sprintf(out
, "icmpv6");
1164 sprintf(out
, "%02x", ip_proto
);
1166 print_string(PRINT_ANY
, "ip_proto", "\n ip_proto %s", out
);
1167 *p_ip_proto
= ip_proto
;
1170 static void flower_print_ip_attr(char *name
, struct rtattr
*key_attr
,
1171 struct rtattr
*mask_attr
)
1173 SPRINT_BUF(namefrm
);
1180 done
= sprintf(out
, "%x", rta_getattr_u8(key_attr
));
1182 sprintf(out
+ done
, "/%x", rta_getattr_u8(mask_attr
));
1184 sprintf(namefrm
, "\n %s %%x", name
);
1185 print_string(PRINT_ANY
, name
, namefrm
, out
);
1188 static void flower_print_matching_flags(char *name
,
1189 enum flower_matching_flags type
,
1190 struct rtattr
*attr
,
1191 struct rtattr
*mask_attr
)
1198 if (!mask_attr
|| RTA_PAYLOAD(mask_attr
) != 4)
1201 mtf
= ntohl(rta_getattr_u32(attr
));
1202 mtf_mask
= ntohl(rta_getattr_u32(mask_attr
));
1204 for (i
= 0; i
< ARRAY_SIZE(flags_str
); i
++) {
1205 if (type
!= flags_str
[i
].type
)
1207 if (mtf_mask
& flags_str
[i
].flag
) {
1209 print_string(PRINT_FP
, NULL
, "\n %s ", name
);
1210 open_json_object(name
);
1212 print_string(PRINT_FP
, NULL
, "/", NULL
);
1215 print_bool(PRINT_JSON
, flags_str
[i
].string
, NULL
,
1216 mtf
& flags_str
[i
].flag
);
1217 if (mtf
& flags_str
[i
].flag
)
1218 print_string(PRINT_FP
, NULL
, "%s",
1219 flags_str
[i
].string
);
1221 print_string(PRINT_FP
, NULL
, "no%s",
1222 flags_str
[i
].string
);
1226 close_json_object();
1229 static void flower_print_ip_addr(char *name
, __be16 eth_type
,
1230 struct rtattr
*addr4_attr
,
1231 struct rtattr
*mask4_attr
,
1232 struct rtattr
*addr6_attr
,
1233 struct rtattr
*mask6_attr
)
1235 struct rtattr
*addr_attr
;
1236 struct rtattr
*mask_attr
;
1237 SPRINT_BUF(namefrm
);
1244 if (eth_type
== htons(ETH_P_IP
)) {
1246 addr_attr
= addr4_attr
;
1247 mask_attr
= mask4_attr
;
1249 } else if (eth_type
== htons(ETH_P_IPV6
)) {
1251 addr_attr
= addr6_attr
;
1252 mask_attr
= mask6_attr
;
1257 if (!addr_attr
|| RTA_PAYLOAD(addr_attr
) != len
)
1259 if (!mask_attr
|| RTA_PAYLOAD(mask_attr
) != len
)
1261 done
= sprintf(out
, "%s", rt_addr_n2a_rta(family
, addr_attr
));
1262 bits
= __mask_bits(RTA_DATA(mask_attr
), len
);
1264 sprintf(out
+ done
, "/%s", rt_addr_n2a_rta(family
, mask_attr
));
1265 else if (bits
< len
* 8)
1266 sprintf(out
+ done
, "/%d", bits
);
1268 sprintf(namefrm
, "\n %s %%s", name
);
1269 print_string(PRINT_ANY
, name
, namefrm
, out
);
1271 static void flower_print_ip4_addr(char *name
, struct rtattr
*addr_attr
,
1272 struct rtattr
*mask_attr
)
1274 return flower_print_ip_addr(name
, htons(ETH_P_IP
),
1275 addr_attr
, mask_attr
, 0, 0);
1278 static void flower_print_port(char *name
, struct rtattr
*attr
)
1280 SPRINT_BUF(namefrm
);
1285 sprintf(namefrm
,"\n %s %%u", name
);
1286 print_hu(PRINT_ANY
, name
, namefrm
, rta_getattr_be16(attr
));
1289 static void flower_print_tcp_flags(char *name
, struct rtattr
*flags_attr
,
1290 struct rtattr
*mask_attr
)
1292 SPRINT_BUF(namefrm
);
1299 done
= sprintf(out
, "%x", rta_getattr_be16(flags_attr
));
1301 sprintf(out
+ done
, "%x", rta_getattr_be16(flags_attr
));
1303 sprintf(namefrm
, "\n %s %%s", name
);
1304 print_string(PRINT_ANY
, name
, namefrm
, out
);
1308 static void flower_print_key_id(const char *name
, struct rtattr
*attr
)
1310 SPRINT_BUF(namefrm
);
1315 sprintf(namefrm
,"\n %s %%u", name
);
1316 print_uint(PRINT_ANY
, name
, namefrm
, rta_getattr_be32(attr
));
1319 static void flower_print_masked_u8(const char *name
, struct rtattr
*attr
,
1320 struct rtattr
*mask_attr
,
1321 const char *(*value_to_str
)(__u8 value
))
1323 const char *value_str
= NULL
;
1325 SPRINT_BUF(namefrm
);
1332 value
= rta_getattr_u8(attr
);
1333 mask
= mask_attr
? rta_getattr_u8(mask_attr
) : UINT8_MAX
;
1334 if (mask
== UINT8_MAX
&& value_to_str
)
1335 value_str
= value_to_str(value
);
1338 done
= sprintf(out
, "%s", value_str
);
1340 done
= sprintf(out
, "%d", value
);
1342 if (mask
!= UINT8_MAX
)
1343 sprintf(out
+ done
, "/%d", mask
);
1345 sprintf(namefrm
,"\n %s %%s", name
);
1346 print_string(PRINT_ANY
, name
, namefrm
, out
);
1349 static void flower_print_u8(const char *name
, struct rtattr
*attr
)
1351 flower_print_masked_u8(name
, attr
, NULL
, NULL
);
1354 static void flower_print_u32(const char *name
, struct rtattr
*attr
)
1356 SPRINT_BUF(namefrm
);
1361 sprintf(namefrm
,"\n %s %%u", name
);
1362 print_uint(PRINT_ANY
, name
, namefrm
, rta_getattr_u32(attr
));
1365 static void flower_print_arp_op(const char *name
,
1366 struct rtattr
*op_attr
,
1367 struct rtattr
*mask_attr
)
1369 flower_print_masked_u8(name
, op_attr
, mask_attr
,
1370 flower_print_arp_op_to_name
);
1373 static int flower_print_opt(struct filter_util
*qu
, FILE *f
,
1374 struct rtattr
*opt
, __u32 handle
)
1376 struct rtattr
*tb
[TCA_FLOWER_MAX
+ 1];
1377 int nl_type
, nl_mask_type
;
1378 __be16 eth_type
= 0;
1379 __u8 ip_proto
= 0xff;
1384 parse_rtattr_nested(tb
, TCA_FLOWER_MAX
, opt
);
1387 print_uint(PRINT_ANY
, "handle", "handle 0x%x ", handle
);
1389 if (tb
[TCA_FLOWER_CLASSID
]) {
1390 __u32 h
= rta_getattr_u32(tb
[TCA_FLOWER_CLASSID
]);
1392 if (TC_H_MIN(h
) < TC_H_MIN_PRIORITY
||
1393 TC_H_MIN(h
) > (TC_H_MIN_PRIORITY
+ TC_QOPT_MAX_QUEUE
- 1)) {
1395 print_string(PRINT_ANY
, "classid", "classid %s ",
1396 sprint_tc_classid(h
, b1
));
1398 print_uint(PRINT_ANY
, "hw_tc", "hw_tc %u ",
1399 TC_H_MIN(h
) - TC_H_MIN_PRIORITY
);
1403 if (tb
[TCA_FLOWER_INDEV
]) {
1404 struct rtattr
*attr
= tb
[TCA_FLOWER_INDEV
];
1406 print_string(PRINT_ANY
, "indev", "\n indev %s",
1407 rta_getattr_str(attr
));
1410 open_json_object("keys");
1412 if (tb
[TCA_FLOWER_KEY_VLAN_ID
]) {
1413 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_VLAN_ID
];
1415 print_uint(PRINT_ANY
, "vlan_id", "\n vlan_id %u",
1416 rta_getattr_u16(attr
));
1419 if (tb
[TCA_FLOWER_KEY_VLAN_PRIO
]) {
1420 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_VLAN_PRIO
];
1422 print_uint(PRINT_ANY
, "vlan_prio", "\n vlan_prio %d",
1423 rta_getattr_u8(attr
));
1426 if (tb
[TCA_FLOWER_KEY_VLAN_ETH_TYPE
]) {
1428 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_VLAN_ETH_TYPE
];
1430 print_string(PRINT_ANY
, "vlan_ethtype", "\n vlan_ethtype %s",
1431 ll_proto_n2a(rta_getattr_u16(attr
),
1435 if (tb
[TCA_FLOWER_KEY_CVLAN_ID
]) {
1436 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_CVLAN_ID
];
1438 print_uint(PRINT_ANY
, "cvlan_id", "\n cvlan_id %u",
1439 rta_getattr_u16(attr
));
1442 if (tb
[TCA_FLOWER_KEY_CVLAN_PRIO
]) {
1443 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_CVLAN_PRIO
];
1445 print_uint(PRINT_ANY
, "cvlan_prio", "\n cvlan_prio %d",
1446 rta_getattr_u8(attr
));
1449 if (tb
[TCA_FLOWER_KEY_CVLAN_ETH_TYPE
]) {
1451 struct rtattr
*attr
= tb
[TCA_FLOWER_KEY_CVLAN_ETH_TYPE
];
1453 print_string(PRINT_ANY
, "cvlan_ethtype", "\n cvlan_ethtype %s",
1454 ll_proto_n2a(rta_getattr_u16(attr
),
1458 flower_print_eth_addr("dst_mac", tb
[TCA_FLOWER_KEY_ETH_DST
],
1459 tb
[TCA_FLOWER_KEY_ETH_DST_MASK
]);
1460 flower_print_eth_addr("src_mac", tb
[TCA_FLOWER_KEY_ETH_SRC
],
1461 tb
[TCA_FLOWER_KEY_ETH_SRC_MASK
]);
1463 flower_print_eth_type(ð_type
, tb
[TCA_FLOWER_KEY_ETH_TYPE
]);
1464 flower_print_ip_proto(&ip_proto
, tb
[TCA_FLOWER_KEY_IP_PROTO
]);
1466 flower_print_ip_attr("ip_tos", tb
[TCA_FLOWER_KEY_IP_TOS
],
1467 tb
[TCA_FLOWER_KEY_IP_TOS_MASK
]);
1468 flower_print_ip_attr("ip_ttl", tb
[TCA_FLOWER_KEY_IP_TTL
],
1469 tb
[TCA_FLOWER_KEY_IP_TTL_MASK
]);
1471 flower_print_u32("mpls_label", tb
[TCA_FLOWER_KEY_MPLS_LABEL
]);
1472 flower_print_u8("mpls_tc", tb
[TCA_FLOWER_KEY_MPLS_TC
]);
1473 flower_print_u8("mpls_bos", tb
[TCA_FLOWER_KEY_MPLS_BOS
]);
1474 flower_print_u8("mpls_ttl", tb
[TCA_FLOWER_KEY_MPLS_TTL
]);
1476 flower_print_ip_addr("dst_ip", eth_type
,
1477 tb
[TCA_FLOWER_KEY_IPV4_DST
],
1478 tb
[TCA_FLOWER_KEY_IPV4_DST_MASK
],
1479 tb
[TCA_FLOWER_KEY_IPV6_DST
],
1480 tb
[TCA_FLOWER_KEY_IPV6_DST_MASK
]);
1482 flower_print_ip_addr("src_ip", eth_type
,
1483 tb
[TCA_FLOWER_KEY_IPV4_SRC
],
1484 tb
[TCA_FLOWER_KEY_IPV4_SRC_MASK
],
1485 tb
[TCA_FLOWER_KEY_IPV6_SRC
],
1486 tb
[TCA_FLOWER_KEY_IPV6_SRC_MASK
]);
1488 nl_type
= flower_port_attr_type(ip_proto
, FLOWER_ENDPOINT_DST
);
1490 flower_print_port("dst_port", tb
[nl_type
]);
1491 nl_type
= flower_port_attr_type(ip_proto
, FLOWER_ENDPOINT_SRC
);
1493 flower_print_port("src_port", tb
[nl_type
]);
1495 flower_print_tcp_flags("tcp_flags", tb
[TCA_FLOWER_KEY_TCP_FLAGS
],
1496 tb
[TCA_FLOWER_KEY_TCP_FLAGS_MASK
]);
1498 nl_type
= flower_icmp_attr_type(eth_type
, ip_proto
,
1499 FLOWER_ICMP_FIELD_TYPE
);
1500 nl_mask_type
= flower_icmp_attr_mask_type(eth_type
, ip_proto
,
1501 FLOWER_ICMP_FIELD_TYPE
);
1502 if (nl_type
>= 0 && nl_mask_type
>= 0)
1503 flower_print_masked_u8("icmp_type", tb
[nl_type
],
1504 tb
[nl_mask_type
], NULL
);
1506 nl_type
= flower_icmp_attr_type(eth_type
, ip_proto
,
1507 FLOWER_ICMP_FIELD_CODE
);
1508 nl_mask_type
= flower_icmp_attr_mask_type(eth_type
, ip_proto
,
1509 FLOWER_ICMP_FIELD_CODE
);
1510 if (nl_type
>= 0 && nl_mask_type
>= 0)
1511 flower_print_masked_u8("icmp_code", tb
[nl_type
],
1512 tb
[nl_mask_type
], NULL
);
1514 flower_print_ip4_addr("arp_sip", tb
[TCA_FLOWER_KEY_ARP_SIP
],
1515 tb
[TCA_FLOWER_KEY_ARP_SIP_MASK
]);
1516 flower_print_ip4_addr("arp_tip", tb
[TCA_FLOWER_KEY_ARP_TIP
],
1517 tb
[TCA_FLOWER_KEY_ARP_TIP_MASK
]);
1518 flower_print_arp_op("arp_op", tb
[TCA_FLOWER_KEY_ARP_OP
],
1519 tb
[TCA_FLOWER_KEY_ARP_OP_MASK
]);
1520 flower_print_eth_addr("arp_sha", tb
[TCA_FLOWER_KEY_ARP_SHA
],
1521 tb
[TCA_FLOWER_KEY_ARP_SHA_MASK
]);
1522 flower_print_eth_addr("arp_tha", tb
[TCA_FLOWER_KEY_ARP_THA
],
1523 tb
[TCA_FLOWER_KEY_ARP_THA_MASK
]);
1525 flower_print_ip_addr("enc_dst_ip",
1526 tb
[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK
] ?
1527 htons(ETH_P_IP
) : htons(ETH_P_IPV6
),
1528 tb
[TCA_FLOWER_KEY_ENC_IPV4_DST
],
1529 tb
[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK
],
1530 tb
[TCA_FLOWER_KEY_ENC_IPV6_DST
],
1531 tb
[TCA_FLOWER_KEY_ENC_IPV6_DST_MASK
]);
1533 flower_print_ip_addr("enc_src_ip",
1534 tb
[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK
] ?
1535 htons(ETH_P_IP
) : htons(ETH_P_IPV6
),
1536 tb
[TCA_FLOWER_KEY_ENC_IPV4_SRC
],
1537 tb
[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK
],
1538 tb
[TCA_FLOWER_KEY_ENC_IPV6_SRC
],
1539 tb
[TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK
]);
1541 flower_print_key_id("enc_key_id", tb
[TCA_FLOWER_KEY_ENC_KEY_ID
]);
1543 flower_print_port("enc_dst_port", tb
[TCA_FLOWER_KEY_ENC_UDP_DST_PORT
]);
1545 flower_print_matching_flags("ip_flags", FLOWER_IP_FLAGS
,
1546 tb
[TCA_FLOWER_KEY_FLAGS
],
1547 tb
[TCA_FLOWER_KEY_FLAGS_MASK
]);
1549 close_json_object();
1551 if (tb
[TCA_FLOWER_FLAGS
]) {
1552 __u32 flags
= rta_getattr_u32(tb
[TCA_FLOWER_FLAGS
]);
1554 if (flags
& TCA_CLS_FLAGS_SKIP_HW
)
1555 print_bool(PRINT_ANY
, "skip_hw", "\n skip_hw", true);
1556 if (flags
& TCA_CLS_FLAGS_SKIP_SW
)
1557 print_bool(PRINT_ANY
, "skip_sw", "\n skip_sw", true);
1559 if (flags
& TCA_CLS_FLAGS_IN_HW
)
1560 print_bool(PRINT_ANY
, "in_hw", "\n in_hw", true);
1561 else if (flags
& TCA_CLS_FLAGS_NOT_IN_HW
)
1562 print_bool(PRINT_ANY
, "not_in_hw", "\n not_in_hw", true);
1565 if (tb
[TCA_FLOWER_ACT
])
1566 tc_print_action(f
, tb
[TCA_FLOWER_ACT
], 0);
1571 struct filter_util flower_filter_util
= {
1573 .parse_fopt
= flower_parse_opt
,
1574 .print_fopt
= flower_print_opt
,