2 * f_matchall.c Match-all 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@mellanox.com>, Yotam Gigi <yotamg@mellanox.com>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
26 static void explain(void)
28 fprintf(stderr
, "Usage: ... matchall [skip_sw | skip_hw]\n");
29 fprintf(stderr
, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
30 fprintf(stderr
, "\n");
31 fprintf(stderr
, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
32 fprintf(stderr
, " FILTERID := X:Y:Z\n");
33 fprintf(stderr
, " ACTION_SPEC := ... look at individual actions\n");
34 fprintf(stderr
, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
37 static int matchall_parse_opt(struct filter_util
*qu
, char *handle
,
38 int argc
, char **argv
, struct nlmsghdr
*n
)
40 struct tcmsg
*t
= NLMSG_DATA(n
);
46 h
= strtol(handle
, NULL
, 0);
47 if (h
== LONG_MIN
|| h
== LONG_MAX
) {
48 fprintf(stderr
, "Illegal handle \"%s\", must be numeric.\n",
58 tail
= (struct rtattr
*)(((void *)n
)+NLMSG_ALIGN(n
->nlmsg_len
));
59 addattr_l(n
, MAX_MSG
, TCA_OPTIONS
, NULL
, 0);
62 if (matches(*argv
, "classid") == 0 ||
63 strcmp(*argv
, "flowid") == 0) {
67 if (get_tc_classid(&handle
, *argv
)) {
68 fprintf(stderr
, "Illegal \"classid\"\n");
71 addattr_l(n
, MAX_MSG
, TCA_MATCHALL_CLASSID
, &handle
, 4);
72 } else if (matches(*argv
, "action") == 0) {
74 if (parse_action(&argc
, &argv
, TCA_MATCHALL_ACT
, n
)) {
75 fprintf(stderr
, "Illegal \"action\"\n");
80 } else if (strcmp(*argv
, "skip_hw") == 0) {
82 flags
|= TCA_CLS_FLAGS_SKIP_HW
;
84 } else if (strcmp(*argv
, "skip_sw") == 0) {
86 flags
|= TCA_CLS_FLAGS_SKIP_SW
;
88 } else if (strcmp(*argv
, "help") == 0) {
92 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
100 if (!(flags
^ (TCA_CLS_FLAGS_SKIP_HW
|
101 TCA_CLS_FLAGS_SKIP_SW
))) {
103 "skip_hw and skip_sw are mutually exclusive\n");
106 addattr_l(n
, MAX_MSG
, TCA_MATCHALL_FLAGS
, &flags
, 4);
109 tail
->rta_len
= (((void *)n
)+n
->nlmsg_len
) - (void *)tail
;
113 static int matchall_print_opt(struct filter_util
*qu
, FILE *f
,
114 struct rtattr
*opt
, __u32 handle
)
116 struct rtattr
*tb
[TCA_MATCHALL_MAX
+1];
121 parse_rtattr_nested(tb
, TCA_MATCHALL_MAX
, opt
);
124 print_uint(PRINT_ANY
, "handle", "handle 0x%x ", handle
);
126 if (tb
[TCA_MATCHALL_CLASSID
]) {
128 print_string(PRINT_ANY
, "flowid", "flowid %s ",
129 sprint_tc_classid(rta_getattr_u32(tb
[TCA_MATCHALL_CLASSID
]), b1
));
132 if (tb
[TCA_MATCHALL_FLAGS
]) {
133 __u32 flags
= rta_getattr_u32(tb
[TCA_MATCHALL_FLAGS
]);
135 if (flags
& TCA_CLS_FLAGS_SKIP_HW
)
136 print_bool(PRINT_ANY
, "skip_hw", "\n skip_hw", true);
137 if (flags
& TCA_CLS_FLAGS_SKIP_SW
)
138 print_bool(PRINT_ANY
, "skip_sw", "\n skip_sw", true);
140 if (flags
& TCA_CLS_FLAGS_IN_HW
)
141 print_bool(PRINT_ANY
, "in_hw", "\n in_hw", true);
142 else if (flags
& TCA_CLS_FLAGS_NOT_IN_HW
)
143 print_bool(PRINT_ANY
, "not_in_hw", "\n not_in_hw", true);
146 if (tb
[TCA_MATCHALL_ACT
])
147 tc_print_action(f
, tb
[TCA_MATCHALL_ACT
], 0);
152 struct filter_util matchall_filter_util
= {
154 .parse_fopt
= matchall_parse_opt
,
155 .print_fopt
= matchall_print_opt
,