4 * This program is free software; you can redistribute 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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
22 #include <linux/if.h> /* IFNAMSIZ */
26 static void explain(void)
28 fprintf(stderr, "Usage: ... fw [ classid CLASSID ] [ police POLICE_SPEC ]\n");
29 fprintf(stderr, " POLICE_SPEC := ... look at TBF\n");
30 fprintf(stderr, " CLASSID := X:Y\n");
31 fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
34 #define usage() return(-1)
36 static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
39 struct tcmsg *t = NLMSG_DATA(n);
42 memset(&tp, 0, sizeof(tp));
45 addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
50 if ((slash = strchr(handle, '/')) != NULL)
52 if (get_u32(&t->tcm_handle, handle, 0)) {
53 fprintf(stderr, "Illegal \"handle\"\n");
57 if (get_u32(&mask, slash+1, 0)) {
58 fprintf(stderr, "Illegal \"handle\" mask\n");
61 addattr32(n, MAX_MSG, TCA_FW_MASK, mask);
69 if (matches(*argv, "classid") == 0 ||
70 matches(*argv, "flowid") == 0) {
73 if (get_tc_classid(&handle, *argv)) {
74 fprintf(stderr, "Illegal \"classid\"\n");
77 addattr_l(n, 4096, TCA_FW_CLASSID, &handle, 4);
78 } else if (matches(*argv, "police") == 0) {
80 if (parse_police(&argc, &argv, TCA_FW_POLICE, n)) {
81 fprintf(stderr, "Illegal \"police\"\n");
85 } else if (matches(*argv, "action") == 0) {
87 if (parse_action(&argc, &argv, TCA_FW_ACT, n)) {
88 fprintf(stderr, "Illegal fw \"action\"\n");
92 } else if (strcmp(*argv, "indev") == 0) {
94 memset(d, 0, sizeof (d));
98 fprintf(stderr, "Illegal indev\n");
101 strncpy(d, *argv, sizeof (d) - 1);
102 addattr_l(n, MAX_MSG, TCA_FW_INDEV, d, strlen(d) + 1);
103 } else if (strcmp(*argv, "help") == 0) {
107 fprintf(stderr, "What is \"%s\"?\n", *argv);
113 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
117 static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle)
119 struct rtattr *tb[TCA_FW_MAX+1];
124 parse_rtattr_nested(tb, TCA_FW_MAX, opt);
126 if (handle || tb[TCA_FW_MASK]) {
127 __u32 mark = 0, mask = 0;
130 if(tb[TCA_FW_MASK] &&
131 (mask = *(__u32*)RTA_DATA(tb[TCA_FW_MASK])) != 0xFFFFFFFF)
132 fprintf(f, "handle 0x%x/0x%x ", mark, mask);
134 fprintf(f, "handle 0x%x ", handle);
137 if (tb[TCA_FW_CLASSID]) {
139 fprintf(f, "classid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_FW_CLASSID]), b1));
142 if (tb[TCA_FW_POLICE])
143 tc_print_police(f, tb[TCA_FW_POLICE]);
144 if (tb[TCA_FW_INDEV]) {
145 struct rtattr *idev = tb[TCA_FW_INDEV];
146 fprintf(f, "input dev %s ",(char *)RTA_DATA(idev));
149 if (tb[TCA_FW_ACT]) {
151 tc_print_action(f, tb[TCA_FW_ACT]);
156 struct filter_util fw_filter_util = {
158 .parse_fopt = fw_parse_opt,
159 .print_fopt = fw_print_opt,