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 \n"
49 "\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
50 "\tRANDTYPE := netrand | determ\n"
51 "\tVAL : = value not exceeding 10000\n"
52 "\tINDEX := index value used\n"
55 fprintf(stderr
, "Usage: ... gact <ACTION> [INDEX]\n");
57 "Where: \tACTION := reclassify | drop | continue | pass \n"
58 "\tINDEX := index value used\n"
72 get_act(char ***argv_p
)
74 char **argv
= *argv_p
;
76 if (matches(*argv
, "reclassify") == 0) {
77 return TC_ACT_RECLASSIFY
;
78 } else if (matches(*argv
, "drop") == 0 || matches(*argv
, "shot") == 0) {
80 } else if (matches(*argv
, "continue") == 0) {
82 } else if (matches(*argv
, "pipe") == 0) {
84 } else if (matches(*argv
, "pass") == 0 || matches(*argv
, "ok") == 0) {
87 fprintf(stderr
,"bad action type %s\n",*argv
);
93 parse_gact(struct action_util
*a
, int *argc_p
, char ***argv_p
, int tca_id
, struct nlmsghdr
*n
)
96 char **argv
= *argv_p
;
98 int action
= TC_POLICE_RECLASSIFY
;
100 #ifdef CONFIG_GACT_PROB
106 memset(&p
, 0, sizeof (p
));
107 p
.action
= TC_POLICE_RECLASSIFY
;
113 if (matches(*argv
, "gact") == 0) {
116 action
= get_act(&argv
);
131 #ifdef CONFIG_GACT_PROB
132 if (ok
&& argc
> 0) {
133 if (matches(*argv
, "random") == 0) {
136 if (matches(*argv
, "netrand") == 0) {
138 pp
.ptype
= PGACT_NETRAND
;
139 } else if (matches(*argv
, "determ") == 0) {
141 pp
.ptype
= PGACT_DETERM
;
143 fprintf(stderr
, "Illegal \"random type\"\n");
147 action
= get_act(&argv
);
148 if (action
!= -10) { /* FIXME */
156 if (get_u16(&pp
.pval
, *argv
, 10)) {
157 fprintf(stderr
, "Illegal probability val 0x%x\n",pp
.pval
);
160 if (pp
.pval
> 10000) {
161 fprintf(stderr
, "Illegal probability val 0x%x\n",pp
.pval
);
166 } else if (matches(*argv
, "help") == 0) {
173 if (matches(*argv
, "index") == 0) {
175 if (get_u32(&p
.index
, *argv
, 10)) {
176 fprintf(stderr
, "Illegal \"index\"\n");
182 } else if (matches(*argv
, "help") == 0) {
190 tail
= NLMSG_TAIL(n
);
191 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
192 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof (p
));
193 #ifdef CONFIG_GACT_PROB
195 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof (pp
));
198 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
206 print_gact(struct action_util
*au
,FILE * f
, struct rtattr
*arg
)
209 #ifdef CONFIG_GACT_PROB
211 struct tc_gact_p
*pp
= NULL
;
212 struct tc_gact_p pp_dummy
;
214 struct tc_gact
*p
= NULL
;
215 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
220 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
222 if (tb
[TCA_GACT_PARMS
] == NULL
) {
223 fprintf(f
, "[NULL gact parameters]");
226 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
228 fprintf(f
, "gact action %s", action_n2a(p
->action
, b1
, sizeof (b1
)));
229 #ifdef CONFIG_GACT_PROB
230 if (NULL
!= tb
[TCA_GACT_PROB
]) {
231 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
233 /* need to keep consistent output */
234 memset(&pp_dummy
, 0, sizeof (pp_dummy
));
237 fprintf(f
, "\n\t random type %s %s val %d",prob_n2a(pp
->ptype
), action_n2a(pp
->paction
, b2
, sizeof (b2
)), pp
->pval
);
239 fprintf(f
, "\n\t index %d ref %d bind %d",p
->index
, p
->refcnt
, p
->bindcnt
);
241 if (tb
[TCA_GACT_TM
]) {
242 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
250 struct action_util gact_action_util
= {
252 .parse_aopt
= parse_gact
,
253 .print_aopt
= print_gact
,