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> | jump <JUMP_COUNT>\n"
50 "\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
51 "\tRANDTYPE := netrand | determ\n"
52 "\tVAL : = value not exceeding 10000\n"
53 "\tJUMP_COUNT := Absolute jump from start of action list\n"
54 "\tINDEX := index value used\n"
57 fprintf(stderr
, "Usage: ... gact <ACTION> [INDEX]\n");
59 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
60 " \t goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
61 "\tINDEX := index value used\n"
62 "\tJUMP_COUNT := Absolute jump from start of action list\n"
76 parse_gact(struct action_util
*a
, int *argc_p
, char ***argv_p
,
77 int tca_id
, struct nlmsghdr
*n
)
80 char **argv
= *argv_p
;
81 struct tc_gact p
= { 0 };
82 #ifdef CONFIG_GACT_PROB
92 if (matches(*argv
, "gact") == 0) {
95 } else if (parse_action_control(&argc
, &argv
, &p
.action
, false) == -1) {
96 usage(); /* does not return */
99 #ifdef CONFIG_GACT_PROB
101 if (matches(*argv
, "random") == 0) {
104 if (matches(*argv
, "netrand") == 0) {
106 pp
.ptype
= PGACT_NETRAND
;
107 } else if (matches(*argv
, "determ") == 0) {
109 pp
.ptype
= PGACT_DETERM
;
111 fprintf(stderr
, "Illegal \"random type\"\n");
115 if (parse_action_control(&argc
, &argv
,
116 &pp
.paction
, false) == -1)
118 if (get_u16(&pp
.pval
, *argv
, 10)) {
119 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
122 if (pp
.pval
> 10000) {
123 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
128 } else if (matches(*argv
, "help") == 0) {
135 if (matches(*argv
, "index") == 0) {
137 if (get_u32(&p
.index
, *argv
, 10)) {
138 fprintf(stderr
, "Illegal \"index\"\n");
143 } else if (matches(*argv
, "help") == 0) {
148 tail
= NLMSG_TAIL(n
);
149 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
150 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
151 #ifdef CONFIG_GACT_PROB
153 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
156 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
164 print_gact(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
166 #ifdef CONFIG_GACT_PROB
167 struct tc_gact_p
*pp
= NULL
;
168 struct tc_gact_p pp_dummy
;
170 struct tc_gact
*p
= NULL
;
171 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
176 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
178 if (tb
[TCA_GACT_PARMS
] == NULL
) {
179 fprintf(f
, "[NULL gact parameters]");
182 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
185 print_action_control(f
, "action ", p
->action
, "");
186 #ifdef CONFIG_GACT_PROB
187 if (tb
[TCA_GACT_PROB
] != NULL
) {
188 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
190 /* need to keep consistent output */
191 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
194 fprintf(f
, "\n\t random type %s", prob_n2a(pp
->ptype
));
195 print_action_control(f
, " ", pp
->paction
, " ");
196 fprintf(f
, "val %d", pp
->pval
);
198 fprintf(f
, "\n\t index %u ref %d bind %d", p
->index
, p
->refcnt
,
201 if (tb
[TCA_GACT_TM
]) {
202 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
211 struct action_util gact_action_util
= {
213 .parse_aopt
= parse_gact
,
214 .print_aopt
= print_gact
,