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)
29 fprintf(stderr
, "Usage: ... route [ from REALM | fromif TAG ] [ to REALM ]\n");
30 fprintf(stderr
, " [ classid CLASSID ] [ action ACTION_SPEC ]\n");
31 fprintf(stderr
, " ACTION_SPEC := ... look at individual actions\n");
32 fprintf(stderr
, " CLASSID := X:Y\n");
33 fprintf(stderr
, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
36 static int route_parse_opt(struct filter_util
*qu
, char *handle
, int argc
, char **argv
, struct nlmsghdr
*n
)
38 struct tcmsg
*t
= NLMSG_DATA(n
);
40 __u32 fh
= 0xFFFF8000;
44 if (get_u32(&t
->tcm_handle
, handle
, 0)) {
45 fprintf(stderr
, "Illegal \"handle\"\n");
53 tail
= addattr_nest(n
, 4096, TCA_OPTIONS
);
56 if (matches(*argv
, "to") == 0) {
60 if (rtnl_rtrealm_a2n(&id
, *argv
)) {
61 fprintf(stderr
, "Illegal \"to\"\n");
64 addattr_l(n
, 4096, TCA_ROUTE4_TO
, &id
, 4);
67 } else if (matches(*argv
, "from") == 0) {
71 if (rtnl_rtrealm_a2n(&id
, *argv
)) {
72 fprintf(stderr
, "Illegal \"from\"\n");
75 addattr_l(n
, 4096, TCA_ROUTE4_FROM
, &id
, 4);
78 } else if (matches(*argv
, "fromif") == 0) {
83 if ((id
= ll_name_to_index(*argv
)) <= 0) {
84 fprintf(stderr
, "Illegal \"fromif\"\n");
87 addattr_l(n
, 4096, TCA_ROUTE4_IIF
, &id
, 4);
89 fh
|= (0x8000|id
)<<16;
90 } else if (matches(*argv
, "classid") == 0 ||
91 strcmp(*argv
, "flowid") == 0) {
95 if (get_tc_classid(&handle
, *argv
)) {
96 fprintf(stderr
, "Illegal \"classid\"\n");
99 addattr_l(n
, 4096, TCA_ROUTE4_CLASSID
, &handle
, 4);
100 } else if (matches(*argv
, "police") == 0) {
102 if (parse_police(&argc
, &argv
, TCA_ROUTE4_POLICE
, n
)) {
103 fprintf(stderr
, "Illegal \"police\"\n");
107 } else if (matches(*argv
, "action") == 0) {
109 if (parse_action(&argc
, &argv
, TCA_ROUTE4_ACT
, n
)) {
110 fprintf(stderr
, "Illegal \"action\"\n");
114 } else if (matches(*argv
, "order") == 0) {
116 if (get_u32(&order
, *argv
, 0)) {
117 fprintf(stderr
, "Illegal \"order\"\n");
120 } else if (strcmp(*argv
, "help") == 0) {
124 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
130 addattr_nest_end(n
, tail
);
133 fh
|= (order
<<8)&0x7F00;
140 static int route_print_opt(struct filter_util
*qu
, FILE *f
, struct rtattr
*opt
, __u32 handle
)
142 struct rtattr
*tb
[TCA_ROUTE4_MAX
+1];
149 parse_rtattr_nested(tb
, TCA_ROUTE4_MAX
, opt
);
152 fprintf(f
, "fh 0x%08x ", handle
);
154 fprintf(f
, "order %d ", (handle
>>8)&0x7F);
156 if (tb
[TCA_ROUTE4_CLASSID
]) {
158 fprintf(f
, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb
[TCA_ROUTE4_CLASSID
]), b1
));
160 if (tb
[TCA_ROUTE4_TO
])
161 fprintf(f
, "to %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb
[TCA_ROUTE4_TO
]), b1
, sizeof(b1
)));
162 if (tb
[TCA_ROUTE4_FROM
])
163 fprintf(f
, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb
[TCA_ROUTE4_FROM
]), b1
, sizeof(b1
)));
164 if (tb
[TCA_ROUTE4_IIF
])
165 fprintf(f
, "fromif %s", ll_index_to_name(rta_getattr_u32(tb
[TCA_ROUTE4_IIF
])));
166 if (tb
[TCA_ROUTE4_POLICE
])
167 tc_print_police(f
, tb
[TCA_ROUTE4_POLICE
]);
168 if (tb
[TCA_ROUTE4_ACT
])
169 tc_print_action(f
, tb
[TCA_ROUTE4_ACT
], 0);
173 struct filter_util route_filter_util
= {
175 .parse_fopt
= route_parse_opt
,
176 .print_fopt
= route_print_opt
,