2 * m_gact.c generic actions module
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: J Hadi Salim (hadi@cyberus.ca)
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
25 #include <linux/tc_act/tc_gact.h>
27 /* define to turn on probablity stuff */
29 #ifdef CONFIG_GACT_PROB
30 static const char *prob_n2a(int p
)
34 if (p
== PGACT_NETRAND
)
36 if (p
== PGACT_DETERM
)
45 #ifdef CONFIG_GACT_PROB
46 fprintf(stderr
, "Usage: ... gact <ACTION> [RAND] [INDEX]\n");
48 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
49 " \t goto chain <CHAIN_INDEX>\n"
50 "\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
51 "\tRANDTYPE := netrand | determ\n"
52 "\tVAL : = value not exceeding 10000\n"
53 "\tINDEX := index value used\n"
56 fprintf(stderr
, "Usage: ... gact <ACTION> [INDEX]\n");
58 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
59 " \t goto chain <CHAIN_INDEX>\n"
60 "\tINDEX := index value used\n"
74 parse_gact(struct action_util
*a
, int *argc_p
, char ***argv_p
,
75 int tca_id
, struct nlmsghdr
*n
)
78 char **argv
= *argv_p
;
80 struct tc_gact p
= { 0 };
81 #ifdef CONFIG_GACT_PROB
91 if (matches(*argv
, "gact") == 0) {
94 if (parse_action_control(&argc
, &argv
, &p
.action
, false) == -1)
104 #ifdef CONFIG_GACT_PROB
105 if (ok
&& argc
> 0) {
106 if (matches(*argv
, "random") == 0) {
109 if (matches(*argv
, "netrand") == 0) {
111 pp
.ptype
= PGACT_NETRAND
;
112 } else if (matches(*argv
, "determ") == 0) {
114 pp
.ptype
= PGACT_DETERM
;
116 fprintf(stderr
, "Illegal \"random type\"\n");
120 if (parse_action_control(&argc
, &argv
,
121 &pp
.paction
, false) == -1)
125 if (get_u16(&pp
.pval
, *argv
, 10)) {
126 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
129 if (pp
.pval
> 10000) {
130 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
135 } else if (matches(*argv
, "help") == 0) {
142 if (matches(*argv
, "index") == 0) {
144 if (get_u32(&p
.index
, *argv
, 10)) {
145 fprintf(stderr
, "Illegal \"index\"\n");
151 } else if (matches(*argv
, "help") == 0) {
159 tail
= NLMSG_TAIL(n
);
160 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
161 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
162 #ifdef CONFIG_GACT_PROB
164 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
167 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
175 print_gact(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
177 #ifdef CONFIG_GACT_PROB
178 struct tc_gact_p
*pp
= NULL
;
179 struct tc_gact_p pp_dummy
;
181 struct tc_gact
*p
= NULL
;
182 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
187 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
189 if (tb
[TCA_GACT_PARMS
] == NULL
) {
190 fprintf(f
, "[NULL gact parameters]");
193 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
196 print_action_control(f
, "action ", p
->action
, "");
197 #ifdef CONFIG_GACT_PROB
198 if (tb
[TCA_GACT_PROB
] != NULL
) {
199 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
201 /* need to keep consistent output */
202 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
205 fprintf(f
, "\n\t random type %s", prob_n2a(pp
->ptype
));
206 print_action_control(f
, " ", pp
->paction
, " ");
207 fprintf(f
, "val %d", pp
->pval
);
209 fprintf(f
, "\n\t index %u ref %d bind %d", p
->index
, p
->refcnt
,
212 if (tb
[TCA_GACT_TM
]) {
213 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
222 struct action_util gact_action_util
= {
224 .parse_aopt
= parse_gact
,
225 .print_aopt
= print_gact
,