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>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
27 static void explain(void)
29 fprintf(stderr
, "Usage: ... matchall [skip_sw | skip_hw]\n");
30 fprintf(stderr
, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
31 fprintf(stderr
, "\n");
32 fprintf(stderr
, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
33 fprintf(stderr
, " FILTERID := X:Y:Z\n");
34 fprintf(stderr
, " ACTION_SPEC := ... look at individual actions\n");
35 fprintf(stderr
, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
38 static int matchall_parse_opt(struct filter_util
*qu
, char *handle
,
39 int argc
, char **argv
, struct nlmsghdr
*n
)
41 struct tcmsg
*t
= NLMSG_DATA(n
);
47 h
= strtol(handle
, NULL
, 0);
48 if (h
== LONG_MIN
|| h
== LONG_MAX
) {
49 fprintf(stderr
, "Illegal handle \"%s\", must be numeric.\n",
59 tail
= (struct rtattr
*)(((void *)n
)+NLMSG_ALIGN(n
->nlmsg_len
));
60 addattr_l(n
, MAX_MSG
, TCA_OPTIONS
, NULL
, 0);
63 if (matches(*argv
, "classid") == 0 ||
64 strcmp(*argv
, "flowid") == 0) {
68 if (get_tc_classid(&handle
, *argv
)) {
69 fprintf(stderr
, "Illegal \"classid\"\n");
72 addattr_l(n
, MAX_MSG
, TCA_MATCHALL_CLASSID
, &handle
, 4);
73 } else if (matches(*argv
, "action") == 0) {
75 if (parse_action(&argc
, &argv
, TCA_MATCHALL_ACT
, n
)) {
76 fprintf(stderr
, "Illegal \"action\"\n");
81 } else if (strcmp(*argv
, "skip_hw") == 0) {
83 flags
|= TCA_CLS_FLAGS_SKIP_HW
;
85 } else if (strcmp(*argv
, "skip_sw") == 0) {
87 flags
|= TCA_CLS_FLAGS_SKIP_SW
;
89 } else if (strcmp(*argv
, "help") == 0) {
93 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
101 if (!(flags
^ (TCA_CLS_FLAGS_SKIP_HW
|
102 TCA_CLS_FLAGS_SKIP_SW
))) {
104 "skip_hw and skip_sw are mutually exclusive\n");
107 addattr_l(n
, MAX_MSG
, TCA_MATCHALL_FLAGS
, &flags
, 4);
110 tail
->rta_len
= (((void *)n
)+n
->nlmsg_len
) - (void *)tail
;
114 static int matchall_print_opt(struct filter_util
*qu
, FILE *f
,
115 struct rtattr
*opt
, __u32 handle
)
117 struct rtattr
*tb
[TCA_MATCHALL_MAX
+1];
122 parse_rtattr_nested(tb
, TCA_MATCHALL_MAX
, opt
);
125 fprintf(f
, "handle 0x%x ", handle
);
127 if (tb
[TCA_MATCHALL_CLASSID
]) {
129 fprintf(f
, "flowid %s ",
130 sprint_tc_classid(rta_getattr_u32(tb
[TCA_MATCHALL_CLASSID
]), b1
));
133 if (tb
[TCA_MATCHALL_FLAGS
]) {
134 __u32 flags
= rta_getattr_u32(tb
[TCA_MATCHALL_FLAGS
]);
136 if (flags
& TCA_CLS_FLAGS_SKIP_HW
)
137 fprintf(f
, "\n skip_hw");
138 if (flags
& TCA_CLS_FLAGS_SKIP_SW
)
139 fprintf(f
, "\n skip_sw");
141 if (flags
& TCA_CLS_FLAGS_IN_HW
)
142 fprintf(f
, "\n in_hw");
143 else if (flags
& TCA_CLS_FLAGS_NOT_IN_HW
)
144 fprintf(f
, "\n not_in_hw");
147 if (tb
[TCA_MATCHALL_ACT
])
148 tc_print_action(f
, tb
[TCA_MATCHALL_ACT
], 0);
153 struct filter_util matchall_filter_util
= {
155 .parse_fopt
= matchall_parse_opt
,
156 .print_fopt
= matchall_print_opt
,