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
,
94 int tca_id
, struct nlmsghdr
*n
)
97 char **argv
= *argv_p
;
99 int action
= TC_POLICE_RECLASSIFY
;
100 struct tc_gact p
= { .action
= TC_POLICE_RECLASSIFY
};
101 #ifdef CONFIG_GACT_PROB
111 if (matches(*argv
, "gact") == 0) {
114 action
= get_act(&argv
);
129 #ifdef CONFIG_GACT_PROB
130 if (ok
&& argc
> 0) {
131 if (matches(*argv
, "random") == 0) {
134 if (matches(*argv
, "netrand") == 0) {
136 pp
.ptype
= PGACT_NETRAND
;
137 } else if (matches(*argv
, "determ") == 0) {
139 pp
.ptype
= PGACT_DETERM
;
141 fprintf(stderr
, "Illegal \"random type\"\n");
145 action
= get_act(&argv
);
146 if (action
!= -10) { /* FIXME */
154 if (get_u16(&pp
.pval
, *argv
, 10)) {
155 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
158 if (pp
.pval
> 10000) {
159 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
164 } else if (matches(*argv
, "help") == 0) {
171 if (matches(*argv
, "index") == 0) {
173 if (get_u32(&p
.index
, *argv
, 10)) {
174 fprintf(stderr
, "Illegal \"index\"\n");
180 } else if (matches(*argv
, "help") == 0) {
188 tail
= NLMSG_TAIL(n
);
189 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
190 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
191 #ifdef CONFIG_GACT_PROB
193 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
196 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
204 print_gact(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
207 #ifdef CONFIG_GACT_PROB
209 struct tc_gact_p
*pp
= NULL
;
210 struct tc_gact_p pp_dummy
;
212 struct tc_gact
*p
= NULL
;
213 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
218 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
220 if (tb
[TCA_GACT_PARMS
] == NULL
) {
221 fprintf(f
, "[NULL gact parameters]");
224 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
226 fprintf(f
, "gact action %s", action_n2a(p
->action
, b1
, sizeof(b1
)));
227 #ifdef CONFIG_GACT_PROB
228 if (tb
[TCA_GACT_PROB
] != NULL
) {
229 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
231 /* need to keep consistent output */
232 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
235 fprintf(f
, "\n\t random type %s %s val %d", prob_n2a(pp
->ptype
), action_n2a(pp
->paction
, b2
, sizeof (b2
)), pp
->pval
);
237 fprintf(f
, "\n\t index %d ref %d bind %d", p
->index
, p
->refcnt
, p
->bindcnt
);
239 if (tb
[TCA_GACT_TM
]) {
240 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
249 struct action_util gact_action_util
= {
251 .parse_aopt
= parse_gact
,
252 .print_aopt
= print_gact
,