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) {
96 if (parse_action_control(&argc
, &argv
, &p
.action
, false) == -1)
101 #ifdef CONFIG_GACT_PROB
102 if (ok
&& argc
> 0) {
103 if (matches(*argv
, "random") == 0) {
106 if (matches(*argv
, "netrand") == 0) {
108 pp
.ptype
= PGACT_NETRAND
;
109 } else if (matches(*argv
, "determ") == 0) {
111 pp
.ptype
= PGACT_DETERM
;
113 fprintf(stderr
, "Illegal \"random type\"\n");
117 if (parse_action_control(&argc
, &argv
,
118 &pp
.paction
, false) == -1)
120 if (get_u16(&pp
.pval
, *argv
, 10)) {
121 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
124 if (pp
.pval
> 10000) {
125 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
130 } else if (matches(*argv
, "help") == 0) {
137 if (matches(*argv
, "index") == 0) {
139 if (get_u32(&p
.index
, *argv
, 10)) {
140 fprintf(stderr
, "Illegal \"index\"\n");
146 } else if (matches(*argv
, "help") == 0) {
154 tail
= NLMSG_TAIL(n
);
155 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
156 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
157 #ifdef CONFIG_GACT_PROB
159 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
162 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
170 print_gact(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
172 #ifdef CONFIG_GACT_PROB
173 struct tc_gact_p
*pp
= NULL
;
174 struct tc_gact_p pp_dummy
;
176 struct tc_gact
*p
= NULL
;
177 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
182 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
184 if (tb
[TCA_GACT_PARMS
] == NULL
) {
185 fprintf(f
, "[NULL gact parameters]");
188 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
191 print_action_control(f
, "action ", p
->action
, "");
192 #ifdef CONFIG_GACT_PROB
193 if (tb
[TCA_GACT_PROB
] != NULL
) {
194 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
196 /* need to keep consistent output */
197 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
200 fprintf(f
, "\n\t random type %s", prob_n2a(pp
->ptype
));
201 print_action_control(f
, " ", pp
->paction
, " ");
202 fprintf(f
, "val %d", pp
->pval
);
204 fprintf(f
, "\n\t index %u ref %d bind %d", p
->index
, p
->refcnt
,
207 if (tb
[TCA_GACT_TM
]) {
208 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
217 struct action_util gact_action_util
= {
219 .parse_aopt
= parse_gact
,
220 .print_aopt
= print_gact
,