2 * f_basic.c Basic 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: Thomas Graf <tgraf@suug.ch>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
27 static void explain(void)
30 "Usage: ... basic [ match EMATCH_TREE ]\n"
31 " [ action ACTION_SPEC ] [ classid CLASSID ]\n"
33 "Where: SELECTOR := SAMPLE SAMPLE ...\n"
34 " FILTERID := X:Y:Z\n"
35 " ACTION_SPEC := ... look at individual actions\n"
37 "NOTE: CLASSID is parsed as hexadecimal input.\n");
40 static int basic_parse_opt(struct filter_util *qu, char *handle,
41 int argc, char **argv, struct nlmsghdr *n)
43 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",
60 tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
61 addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
64 if (matches(*argv, "match") == 0) {
66 if (parse_ematch(&argc, &argv, TCA_BASIC_EMATCHES, n)) {
67 fprintf(stderr, "Illegal \"ematch\"\n");
71 } else if (matches(*argv, "classid") == 0 ||
72 strcmp(*argv, "flowid") == 0) {
76 if (get_tc_classid(&handle, *argv)) {
77 fprintf(stderr, "Illegal \"classid\"\n");
80 addattr_l(n, MAX_MSG, TCA_BASIC_CLASSID, &handle, 4);
81 } else if (matches(*argv, "action") == 0) {
83 if (parse_action(&argc, &argv, TCA_BASIC_ACT, n)) {
84 fprintf(stderr, "Illegal \"action\"\n");
89 } else if (matches(*argv, "police") == 0) {
91 if (parse_police(&argc, &argv, TCA_BASIC_POLICE, n)) {
92 fprintf(stderr, "Illegal \"police\"\n");
96 } else if (strcmp(*argv, "help") == 0) {
100 fprintf(stderr, "What is \"%s\"?\n", *argv);
107 tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
111 static int basic_print_opt(struct filter_util *qu, FILE *f,
112 struct rtattr *opt, __u32 handle)
114 struct rtattr *tb[TCA_BASIC_MAX+1];
119 parse_rtattr_nested(tb, TCA_BASIC_MAX, opt);
122 fprintf(f, "handle 0x%x ", handle);
124 if (tb[TCA_BASIC_CLASSID]) {
126 fprintf(f, "flowid %s ",
127 sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1));
130 if (tb[TCA_BASIC_EMATCHES])
131 print_ematch(f, tb[TCA_BASIC_EMATCHES]);
133 if (tb[TCA_BASIC_POLICE]) {
135 tc_print_police(f, tb[TCA_BASIC_POLICE]);
138 if (tb[TCA_BASIC_ACT]) {
139 tc_print_action(f, tb[TCA_BASIC_ACT], 0);
145 struct filter_util basic_filter_util = {
147 .parse_fopt = basic_parse_opt,
148 .print_fopt = basic_print_opt,