2 * f_basic.c Basic Classifier
4 * This program is free software; you can u32istribute 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: Thomas Graf <tgraf@suug.ch>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
28 static void explain(void)
30 fprintf(stderr
, "Usage: ... basic [ match EMATCH_TREE ] [ police POLICE_SPEC ]\n");
31 fprintf(stderr
, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
32 fprintf(stderr
, "\n");
33 fprintf(stderr
, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
34 fprintf(stderr
, " FILTERID := X:Y:Z\n");
37 static int basic_parse_opt(struct filter_util
*qu
, char *handle
,
38 int argc
, char **argv
, struct nlmsghdr
*n
)
40 struct tcmsg
*t
= NLMSG_DATA(n
);
48 h
= strtol(handle
, NULL
, 0);
49 if (h
== LONG_MIN
|| h
== LONG_MAX
) {
50 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
, "match") == 0) {
64 if (parse_ematch(&argc
, &argv
, TCA_BASIC_EMATCHES
, n
)) {
65 fprintf(stderr
, "Illegal \"ematch\"\n");
69 } else if (matches(*argv
, "classid") == 0 ||
70 strcmp(*argv
, "flowid") == 0) {
73 if (get_tc_classid(&handle
, *argv
)) {
74 fprintf(stderr
, "Illegal \"classid\"\n");
77 addattr_l(n
, MAX_MSG
, TCA_BASIC_CLASSID
, &handle
, 4);
78 } else if (matches(*argv
, "action") == 0) {
80 if (parse_action(&argc
, &argv
, TCA_BASIC_ACT
, n
)) {
81 fprintf(stderr
, "Illegal \"action\"\n");
86 } else if (matches(*argv
, "police") == 0) {
88 if (parse_police(&argc
, &argv
, TCA_BASIC_POLICE
, n
)) {
89 fprintf(stderr
, "Illegal \"police\"\n");
93 } else if (strcmp(*argv
, "help") == 0) {
97 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
104 tail
->rta_len
= (((void*)n
)+n
->nlmsg_len
) - (void*)tail
;
108 static int basic_print_opt(struct filter_util
*qu
, FILE *f
,
109 struct rtattr
*opt
, __u32 handle
)
111 struct rtattr
*tb
[TCA_BASIC_MAX
+1];
116 parse_rtattr_nested(tb
, TCA_BASIC_MAX
, opt
);
119 fprintf(f
, "handle 0x%x ", handle
);
121 if (tb
[TCA_BASIC_CLASSID
]) {
123 fprintf(f
, "flowid %s ",
124 sprint_tc_classid(*(__u32
*)RTA_DATA(tb
[TCA_BASIC_CLASSID
]), b1
));
127 if (tb
[TCA_BASIC_EMATCHES
])
128 print_ematch(f
, tb
[TCA_BASIC_EMATCHES
]);
130 if (tb
[TCA_BASIC_POLICE
]) {
132 tc_print_police(f
, tb
[TCA_BASIC_POLICE
]);
135 if (tb
[TCA_BASIC_ACT
]) {
136 tc_print_action(f
, tb
[TCA_BASIC_ACT
]);
142 struct filter_util basic_filter_util
= {
144 .parse_fopt
= basic_parse_opt
,
145 .print_fopt
= basic_print_opt
,