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 int prob_a2n(unsigned char *n)
32 if (!strcmp(n,"none"))
34 if (!strcmp(n,"netrand"))
36 if (!strcmp(n,"determ"))
46 if (p == PGACT_NETRAND)
48 if (p == PGACT_DETERM)
56 #ifdef CONFIG_GACT_PROB
57 fprintf(stderr, "Usage: ... gact <ACTION> [RAND] [INDEX]\n");
59 "Where: ACTION := reclassify | drop | continue | pass "
60 "RAND := random <RANDTYPE> <ACTION> <VAL>"
61 "RANDTYPE := netrand | determ"
62 "VAL : = value not exceeding 10000"
63 "INDEX := index value used"
66 fprintf(stderr, "Usage: ... gact <ACTION> [INDEX]\n");
68 "Where: ACTION := reclassify | drop | continue | pass "
69 "INDEX := index value used"
74 #define usage() return(-1)
77 get_act(char ***argv_p)
79 char **argv = *argv_p;
81 if (matches(*argv, "reclassify") == 0) {
82 return TC_ACT_RECLASSIFY;
83 } else if (matches(*argv, "drop") == 0 || matches(*argv, "shot") == 0) {
85 } else if (matches(*argv, "continue") == 0) {
87 } else if (matches(*argv, "pipe") == 0) {
89 } else if (matches(*argv, "pass") == 0 || matches(*argv, "ok") == 0) {
92 fprintf(stderr,"bad action type %s\n",*argv);
98 parse_gact(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
101 char **argv = *argv_p;
103 int action = TC_POLICE_RECLASSIFY;
105 #ifdef CONFIG_GACT_PROB
111 memset(&p, 0, sizeof (p));
112 p.action = TC_POLICE_RECLASSIFY;
118 if (matches(*argv, "gact") == 0) {
121 action = get_act(&argv);
136 #ifdef CONFIG_GACT_PROB
137 if (ok && argc > 0) {
138 if (matches(*argv, "random") == 0) {
141 if (matches(*argv, "netrand") == 0) {
143 pp.ptype = PGACT_NETRAND;
144 } else if (matches(*argv, "determ") == 0) {
146 pp.ptype = PGACT_DETERM;
148 fprintf(stderr, "Illegal \"random type\"\n");
152 action = get_act(&argv);
153 if (action != -10) { /* FIXME */
161 if (get_u16(&pp.pval, *argv, 10)) {
162 fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
165 if (pp.pval > 10000) {
166 fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
176 if (matches(*argv, "index") == 0) {
178 if (get_u32(&p.index, *argv, 10)) {
179 fprintf(stderr, "Illegal \"index\"\n");
191 tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
192 addattr_l(n, MAX_MSG, tca_id, NULL, 0);
193 addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof (p));
194 #ifdef CONFIG_GACT_PROB
196 addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof (pp));
200 (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail;
208 print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
211 #ifdef CONFIG_GACT_PROB
213 struct tc_gact_p *pp = NULL;
214 struct tc_gact_p pp_dummy;
216 struct tc_gact *p = NULL;
217 struct rtattr *tb[TCA_GACT_MAX + 1];
222 memset(tb, 0, sizeof (tb));
223 parse_rtattr(tb, TCA_GACT_MAX, RTA_DATA(arg), RTA_PAYLOAD(arg));
225 if (tb[TCA_GACT_PARMS] == NULL) {
226 fprintf(f, "[NULL gact parameters]");
229 p = RTA_DATA(tb[TCA_GACT_PARMS]);
231 fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof (b1)));
232 #ifdef CONFIG_GACT_PROB
233 if (NULL != tb[TCA_GACT_PROB]) {
234 pp = RTA_DATA(tb[TCA_GACT_PROB]);
236 /* need to keep consistent output */
237 memset(&pp_dummy, 0, sizeof (pp_dummy));
240 fprintf(f, "\n\t random type %s %s val %d",prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
242 fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt);
244 if (tb[TCA_GACT_TM]) {
245 struct tcf_t *tm = RTA_DATA(tb[TCA_GACT_TM]);
254 gact_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats)
260 struct action_util gact_util = {