2 * f_route.c ROUTE filter.
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>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
24 #include "tc_common.h"
27 static void explain(void)
30 "Usage: ... route [ from REALM | fromif TAG ] [ to REALM ]\n"
31 " [ classid CLASSID ] [ action ACTION_SPEC ]\n"
32 " ACTION_SPEC := ... look at individual actions\n"
35 "NOTE: CLASSID is parsed as hexadecimal input.\n");
38 static int route_parse_opt(struct filter_util
*qu
, char *handle
, int argc
, char **argv
, struct nlmsghdr
*n
)
40 struct tcmsg
*t
= NLMSG_DATA(n
);
42 __u32 fh
= 0xFFFF8000;
46 if (get_u32(&t
->tcm_handle
, handle
, 0)) {
47 fprintf(stderr
, "Illegal \"handle\"\n");
55 tail
= addattr_nest(n
, 4096, TCA_OPTIONS
);
58 if (matches(*argv
, "to") == 0) {
62 if (rtnl_rtrealm_a2n(&id
, *argv
)) {
63 fprintf(stderr
, "Illegal \"to\"\n");
66 addattr_l(n
, 4096, TCA_ROUTE4_TO
, &id
, 4);
69 } else if (matches(*argv
, "from") == 0) {
73 if (rtnl_rtrealm_a2n(&id
, *argv
)) {
74 fprintf(stderr
, "Illegal \"from\"\n");
77 addattr_l(n
, 4096, TCA_ROUTE4_FROM
, &id
, 4);
80 } else if (matches(*argv
, "fromif") == 0) {
85 if ((id
= ll_name_to_index(*argv
)) <= 0) {
86 fprintf(stderr
, "Illegal \"fromif\"\n");
89 addattr_l(n
, 4096, TCA_ROUTE4_IIF
, &id
, 4);
91 fh
|= (0x8000|id
)<<16;
92 } else if (matches(*argv
, "classid") == 0 ||
93 strcmp(*argv
, "flowid") == 0) {
97 if (get_tc_classid(&handle
, *argv
)) {
98 fprintf(stderr
, "Illegal \"classid\"\n");
101 addattr_l(n
, 4096, TCA_ROUTE4_CLASSID
, &handle
, 4);
102 } else if (matches(*argv
, "police") == 0) {
104 if (parse_police(&argc
, &argv
, TCA_ROUTE4_POLICE
, n
)) {
105 fprintf(stderr
, "Illegal \"police\"\n");
109 } else if (matches(*argv
, "action") == 0) {
111 if (parse_action(&argc
, &argv
, TCA_ROUTE4_ACT
, n
)) {
112 fprintf(stderr
, "Illegal \"action\"\n");
116 } else if (matches(*argv
, "order") == 0) {
118 if (get_u32(&order
, *argv
, 0)) {
119 fprintf(stderr
, "Illegal \"order\"\n");
122 } else if (strcmp(*argv
, "help") == 0) {
126 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
132 addattr_nest_end(n
, tail
);
135 fh
|= (order
<<8)&0x7F00;
142 static int route_print_opt(struct filter_util
*qu
, FILE *f
, struct rtattr
*opt
, __u32 handle
)
144 struct rtattr
*tb
[TCA_ROUTE4_MAX
+1];
151 parse_rtattr_nested(tb
, TCA_ROUTE4_MAX
, opt
);
154 fprintf(f
, "fh 0x%08x ", handle
);
156 fprintf(f
, "order %d ", (handle
>>8)&0x7F);
158 if (tb
[TCA_ROUTE4_CLASSID
]) {
160 fprintf(f
, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb
[TCA_ROUTE4_CLASSID
]), b1
));
162 if (tb
[TCA_ROUTE4_TO
])
163 fprintf(f
, "to %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb
[TCA_ROUTE4_TO
]), b1
, sizeof(b1
)));
164 if (tb
[TCA_ROUTE4_FROM
])
165 fprintf(f
, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb
[TCA_ROUTE4_FROM
]), b1
, sizeof(b1
)));
166 if (tb
[TCA_ROUTE4_IIF
])
167 fprintf(f
, "fromif %s", ll_index_to_name(rta_getattr_u32(tb
[TCA_ROUTE4_IIF
])));
168 if (tb
[TCA_ROUTE4_POLICE
])
169 tc_print_police(f
, tb
[TCA_ROUTE4_POLICE
]);
170 if (tb
[TCA_ROUTE4_ACT
])
171 tc_print_action(f
, tb
[TCA_ROUTE4_ACT
], 0);
175 struct filter_util route_filter_util
= {
177 .parse_fopt
= route_parse_opt
,
178 .print_fopt
= route_print_opt
,