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");
58 "Where: \tACTION := reclassify | drop | continue | pass | pipe |\n"
59 " \t goto chain <CHAIN_INDEX> | jump <JUMP_COUNT>\n"
60 "\tINDEX := index value used\n"
61 "\tJUMP_COUNT := Absolute jump from start of action list\n"
75 parse_gact(struct action_util
*a
, int *argc_p
, char ***argv_p
,
76 int tca_id
, struct nlmsghdr
*n
)
79 char **argv
= *argv_p
;
80 struct tc_gact p
= { 0 };
81 #ifdef CONFIG_GACT_PROB
91 if (matches(*argv
, "gact") == 0) {
94 } else if (parse_action_control(&argc
, &argv
, &p
.action
, false) == -1) {
95 usage(); /* does not return */
98 #ifdef CONFIG_GACT_PROB
100 if (matches(*argv
, "random") == 0) {
103 if (matches(*argv
, "netrand") == 0) {
105 pp
.ptype
= PGACT_NETRAND
;
106 } else if (matches(*argv
, "determ") == 0) {
108 pp
.ptype
= PGACT_DETERM
;
110 fprintf(stderr
, "Illegal \"random type\"\n");
114 if (parse_action_control(&argc
, &argv
,
115 &pp
.paction
, false) == -1)
117 if (get_u16(&pp
.pval
, *argv
, 10)) {
118 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
121 if (pp
.pval
> 10000) {
122 fprintf(stderr
, "Illegal probability val 0x%x\n", pp
.pval
);
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
= NLMSG_TAIL(n
);
148 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
149 addattr_l(n
, MAX_MSG
, TCA_GACT_PARMS
, &p
, sizeof(p
));
150 #ifdef CONFIG_GACT_PROB
152 addattr_l(n
, MAX_MSG
, TCA_GACT_PROB
, &pp
, sizeof(pp
));
155 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
163 print_gact(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
165 #ifdef CONFIG_GACT_PROB
166 struct tc_gact_p
*pp
= NULL
;
167 struct tc_gact_p pp_dummy
;
169 struct tc_gact
*p
= NULL
;
170 struct rtattr
*tb
[TCA_GACT_MAX
+ 1];
175 parse_rtattr_nested(tb
, TCA_GACT_MAX
, arg
);
177 if (tb
[TCA_GACT_PARMS
] == NULL
) {
178 print_string(PRINT_FP
, NULL
, "%s", "[NULL gact parameters]");
181 p
= RTA_DATA(tb
[TCA_GACT_PARMS
]);
183 print_string(PRINT_ANY
, "kind", "%s ", "gact");
184 print_action_control(f
, "action ", p
->action
, "");
185 #ifdef CONFIG_GACT_PROB
186 if (tb
[TCA_GACT_PROB
] != NULL
) {
187 pp
= RTA_DATA(tb
[TCA_GACT_PROB
]);
189 /* need to keep consistent output */
190 memset(&pp_dummy
, 0, sizeof(pp_dummy
));
193 open_json_object("prob");
194 print_string(PRINT_ANY
, "random_type", "\n\t random type %s",
195 prob_n2a(pp
->ptype
));
196 print_action_control(f
, " ", pp
->paction
, " ");
197 print_int(PRINT_ANY
, "val", "val %d", pp
->pval
);
200 print_uint(PRINT_ANY
, "index", "\n\t index %u", p
->index
);
201 print_int(PRINT_ANY
, "ref", " ref %d", p
->refcnt
);
202 print_int(PRINT_ANY
, "bind", " bind %d", p
->bindcnt
);
204 if (tb
[TCA_GACT_TM
]) {
205 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_GACT_TM
]);
210 print_string(PRINT_FP
, NULL
, "%s", "\n");
214 struct action_util gact_action_util
= {
216 .parse_aopt
= parse_gact
,
217 .print_aopt
= print_gact
,