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: ACTION := reclassify | drop | continue | pass "
49 "RAND := random <RANDTYPE> <ACTION> <VAL>"
50 "RANDTYPE := netrand | determ"
51 "VAL : = value not exceeding 10000"
52 "INDEX := index value used"
55 fprintf(stderr, "Usage: ... gact <ACTION> [INDEX]\n");
57 "Where: ACTION := reclassify | drop | continue | pass "
58 "INDEX := index value used"
63 #define usage() return(-1)
66 get_act(char ***argv_p)
68 char **argv = *argv_p;
70 if (matches(*argv, "reclassify") == 0) {
71 return TC_ACT_RECLASSIFY;
72 } else if (matches(*argv, "drop") == 0 || matches(*argv, "shot") == 0) {
74 } else if (matches(*argv, "continue") == 0) {
76 } else if (matches(*argv, "pipe") == 0) {
78 } else if (matches(*argv, "pass") == 0 || matches(*argv, "ok") == 0) {
81 fprintf(stderr,"bad action type %s\n",*argv);
87 parse_gact(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
90 char **argv = *argv_p;
92 int action = TC_POLICE_RECLASSIFY;
94 #ifdef CONFIG_GACT_PROB
100 memset(&p, 0, sizeof (p));
101 p.action = TC_POLICE_RECLASSIFY;
107 if (matches(*argv, "gact") == 0) {
110 action = get_act(&argv);
125 #ifdef CONFIG_GACT_PROB
126 if (ok && argc > 0) {
127 if (matches(*argv, "random") == 0) {
130 if (matches(*argv, "netrand") == 0) {
132 pp.ptype = PGACT_NETRAND;
133 } else if (matches(*argv, "determ") == 0) {
135 pp.ptype = PGACT_DETERM;
137 fprintf(stderr, "Illegal \"random type\"\n");
141 action = get_act(&argv);
142 if (action != -10) { /* FIXME */
150 if (get_u16(&pp.pval, *argv, 10)) {
151 fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
154 if (pp.pval > 10000) {
155 fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
165 if (matches(*argv, "index") == 0) {
167 if (get_u32(&p.index, *argv, 10)) {
168 fprintf(stderr, "Illegal \"index\"\n");
180 tail = NLMSG_TAIL(n);
181 addattr_l(n, MAX_MSG, tca_id, NULL, 0);
182 addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof (p));
183 #ifdef CONFIG_GACT_PROB
185 addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof (pp));
188 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
196 print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
199 #ifdef CONFIG_GACT_PROB
201 struct tc_gact_p *pp = NULL;
202 struct tc_gact_p pp_dummy;
204 struct tc_gact *p = NULL;
205 struct rtattr *tb[TCA_GACT_MAX + 1];
210 parse_rtattr_nested(tb, TCA_GACT_MAX, arg);
212 if (tb[TCA_GACT_PARMS] == NULL) {
213 fprintf(f, "[NULL gact parameters]");
216 p = RTA_DATA(tb[TCA_GACT_PARMS]);
218 fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof (b1)));
219 #ifdef CONFIG_GACT_PROB
220 if (NULL != tb[TCA_GACT_PROB]) {
221 pp = RTA_DATA(tb[TCA_GACT_PROB]);
223 /* need to keep consistent output */
224 memset(&pp_dummy, 0, sizeof (pp_dummy));
227 fprintf(f, "\n\t random type %s %s val %d",prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
229 fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt);
231 if (tb[TCA_GACT_TM]) {
232 struct tcf_t *tm = RTA_DATA(tb[TCA_GACT_TM]);
240 struct action_util gact_action_util = {
242 .parse_aopt = parse_gact,
243 .print_aopt = print_gact,