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)
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
24 #include <linux/tc_act/tc_gact.h>
26 /* define to turn on probablity stuff */
28 #ifdef CONFIG_GACT_PROB
29 static const char *prob_n2a(int p
)
33 if (p
== PGACT_NETRAND
)
35 if (p
== PGACT_DETERM
)
44 #ifdef CONFIG_GACT_PROB
45 fprintf(stderr
, "Usage: ... gact <ACTION> [RAND] [INDEX]\n");
47 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
48 " \t goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
49 "\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
50 "\tRANDTYPE := netrand | determ\n"
51 "\tVAL : = value not exceeding 10000\n"
52 "\tJUMP_COUNT := Absolute jump from start of action list\n"
53 "\tINDEX := index value used\n"
56 fprintf(stderr
, "Usage: ... gact <ACTION> [INDEX]\n"
57 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
58 " \t goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
59 "\tINDEX := index value used\n"
60 "\tJUMP_COUNT := Absolute jump from start of action list\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
;
79 struct tc_gact p
= { 0 };
80 #ifdef CONFIG_GACT_PROB
89 if (!matches(*argv
, "gact"))
91 if (parse_action_control(&argc
, &argv
, &p
.action
, false))
92 usage(); /* does not return */
94 #ifdef CONFIG_GACT_PROB
96 if (matches(*argv
, "random") == 0) {
99 if (matches(*argv
, "netrand") == 0) {
101 pp
.ptype
= PGACT_NETRAND
;
102 } else if (matches(*argv
, "determ") == 0) {
104 pp
.ptype
= PGACT_DETERM
;
106 fprintf(stderr
, "Illegal \"random type\"\n");
110 if (parse_action_control(&argc
, &argv
,
111 &pp
.paction
, false) == -1)
113 if (get_u16(&pp
.pval
, *argv
, 10)) {
115 "Illegal probability val 0x%x\n",
119 if (pp
.pval
> 10000) {
121 "Illegal probability val 0x%x\n",
127 } else if (matches(*argv
, "help") == 0) {
134 if (matches(*argv
, "index") == 0) {
136 if (get_u32(&p
.index
, *argv
, 10)) {
137 fprintf(stderr
, "Illegal \"index\"\n");
142 } else if (matches(*argv
, "help") == 0) {
147 tail
= addattr_nest(n
, MAX_MSG
, tca_id
);
148 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
149 #ifdef CONFIG_GACT_PROB
151 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
153 addattr_nest_end(n
, tail
);
161 print_gact(struct action_util
*au
, FILE *f
, struct rtattr
*arg
)
163 #ifdef CONFIG_GACT_PROB
164 struct tc_gact_p
*pp
= NULL
;
165 struct tc_gact_p pp_dummy
;
167 struct tc_gact
*p
= NULL
;
168 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
173 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
175 if (tb
[TCA_GACT_PARMS
] == NULL
) {
176 print_string(PRINT_FP
, NULL
, "%s", "[NULL gact parameters]");
179 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
181 print_string(PRINT_ANY
, "kind", "%s ", "gact");
182 print_action_control(f
, "action ", p
->action
, "");
183 #ifdef CONFIG_GACT_PROB
184 if (tb
[TCA_GACT_PROB
] != NULL
) {
185 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
187 /* need to keep consistent output */
188 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
191 open_json_object("prob");
192 print_string(PRINT_ANY
, "random_type", "\n\t random type %s",
193 prob_n2a(pp
->ptype
));
194 print_action_control(f
, " ", pp
->paction
, " ");
195 print_int(PRINT_ANY
, "val", "val %d", pp
->pval
);
198 print_uint(PRINT_ANY
, "index", "\n\t index %u", p
->index
);
199 print_int(PRINT_ANY
, "ref", " ref %d", p
->refcnt
);
200 print_int(PRINT_ANY
, "bind", " bind %d", p
->bindcnt
);
202 if (tb
[TCA_GACT_TM
]) {
203 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
208 print_string(PRINT_FP
, NULL
, "%s", "\n");
212 struct action_util gact_action_util
= {
214 .parse_aopt
= parse_gact
,
215 .print_aopt
= print_gact
,