blob: 3825508fdcd1613e66164e01bcf5fa87aee132cb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * net/sched/act_api.c Packet action API.
3 *
4 * This program is free software; you can redistribute 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.
8 *
9 * Author: Jamal Hadi Salim
10 *
11 *
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/init.h>
20#include <linux/kmod.h>
Denis V. Lunevb8542722007-12-01 00:21:31 +110021#include <net/net_namespace.h>
22#include <net/sock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <net/sch_generic.h>
24#include <net/act_api.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070025#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
David S. Millere9ce1cd2006-08-21 23:54:55 -070027void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)
28{
29 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
30 struct tcf_common **p1p;
31
32 for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) {
33 if (*p1p == p) {
34 write_lock_bh(hinfo->lock);
35 *p1p = p->tcfc_next;
36 write_unlock_bh(hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -070037 gen_kill_estimator(&p->tcfc_bstats,
38 &p->tcfc_rate_est);
David S. Millere9ce1cd2006-08-21 23:54:55 -070039 kfree(p);
40 return;
41 }
42 }
43 BUG_TRAP(0);
44}
45EXPORT_SYMBOL(tcf_hash_destroy);
46
47int tcf_hash_release(struct tcf_common *p, int bind,
48 struct tcf_hashinfo *hinfo)
49{
50 int ret = 0;
51
52 if (p) {
53 if (bind)
54 p->tcfc_bindcnt--;
55
56 p->tcfc_refcnt--;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090057 if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
David S. Millere9ce1cd2006-08-21 23:54:55 -070058 tcf_hash_destroy(p, hinfo);
59 ret = 1;
60 }
61 }
62 return ret;
63}
64EXPORT_SYMBOL(tcf_hash_release);
65
66static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
67 struct tc_action *a, struct tcf_hashinfo *hinfo)
68{
69 struct tcf_common *p;
70 int err = 0, index = -1,i = 0, s_i = 0, n_i = 0;
71 struct rtattr *r ;
72
Jamal Hadi Salime1e992e2007-09-12 16:32:59 +020073 read_lock_bh(hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -070074
75 s_i = cb->args[0];
76
77 for (i = 0; i < (hinfo->hmask + 1); i++) {
78 p = hinfo->htab[tcf_hash(i, hinfo->hmask)];
79
80 for (; p; p = p->tcfc_next) {
81 index++;
82 if (index < s_i)
83 continue;
84 a->priv = p;
85 a->order = n_i;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -070086 r = (struct rtattr *)skb_tail_pointer(skb);
David S. Millere9ce1cd2006-08-21 23:54:55 -070087 RTA_PUT(skb, a->order, 0, NULL);
88 err = tcf_action_dump_1(skb, a, 0, 0);
89 if (err < 0) {
90 index--;
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070091 nlmsg_trim(skb, r);
David S. Millere9ce1cd2006-08-21 23:54:55 -070092 goto done;
93 }
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -070094 r->rta_len = skb_tail_pointer(skb) - (u8 *)r;
David S. Millere9ce1cd2006-08-21 23:54:55 -070095 n_i++;
96 if (n_i >= TCA_ACT_MAX_PRIO)
97 goto done;
98 }
99 }
100done:
Jamal Hadi Salime1e992e2007-09-12 16:32:59 +0200101 read_unlock_bh(hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700102 if (n_i)
103 cb->args[0] += n_i;
104 return n_i;
105
106rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700107 nlmsg_trim(skb, r);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700108 goto done;
109}
110
111static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
112 struct tcf_hashinfo *hinfo)
113{
114 struct tcf_common *p, *s_p;
115 struct rtattr *r ;
116 int i= 0, n_i = 0;
117
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700118 r = (struct rtattr *)skb_tail_pointer(skb);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700119 RTA_PUT(skb, a->order, 0, NULL);
120 RTA_PUT(skb, TCA_KIND, IFNAMSIZ, a->ops->kind);
121 for (i = 0; i < (hinfo->hmask + 1); i++) {
122 p = hinfo->htab[tcf_hash(i, hinfo->hmask)];
123
124 while (p != NULL) {
125 s_p = p->tcfc_next;
126 if (ACT_P_DELETED == tcf_hash_release(p, 0, hinfo))
127 module_put(a->ops->owner);
128 n_i++;
129 p = s_p;
130 }
131 }
132 RTA_PUT(skb, TCA_FCNT, 4, &n_i);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700133 r->rta_len = skb_tail_pointer(skb) - (u8 *)r;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700134
135 return n_i;
136rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700137 nlmsg_trim(skb, r);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700138 return -EINVAL;
139}
140
141int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb,
142 int type, struct tc_action *a)
143{
144 struct tcf_hashinfo *hinfo = a->ops->hinfo;
145
146 if (type == RTM_DELACTION) {
147 return tcf_del_walker(skb, a, hinfo);
148 } else if (type == RTM_GETACTION) {
149 return tcf_dump_walker(skb, cb, a, hinfo);
150 } else {
151 printk("tcf_generic_walker: unknown action %d\n", type);
152 return -EINVAL;
153 }
154}
155EXPORT_SYMBOL(tcf_generic_walker);
156
157struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
158{
159 struct tcf_common *p;
160
Jamal Hadi Salime1e992e2007-09-12 16:32:59 +0200161 read_lock_bh(hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700162 for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p;
163 p = p->tcfc_next) {
164 if (p->tcfc_index == index)
165 break;
166 }
Jamal Hadi Salime1e992e2007-09-12 16:32:59 +0200167 read_unlock_bh(hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700168
169 return p;
170}
171EXPORT_SYMBOL(tcf_hash_lookup);
172
173u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo)
174{
175 u32 val = *idx_gen;
176
177 do {
178 if (++val == 0)
179 val = 1;
180 } while (tcf_hash_lookup(val, hinfo));
181
182 return (*idx_gen = val);
183}
184EXPORT_SYMBOL(tcf_hash_new_index);
185
186int tcf_hash_search(struct tc_action *a, u32 index)
187{
188 struct tcf_hashinfo *hinfo = a->ops->hinfo;
189 struct tcf_common *p = tcf_hash_lookup(index, hinfo);
190
191 if (p) {
192 a->priv = p;
193 return 1;
194 }
195 return 0;
196}
197EXPORT_SYMBOL(tcf_hash_search);
198
199struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind,
200 struct tcf_hashinfo *hinfo)
201{
202 struct tcf_common *p = NULL;
203 if (index && (p = tcf_hash_lookup(index, hinfo)) != NULL) {
204 if (bind) {
205 p->tcfc_bindcnt++;
206 p->tcfc_refcnt++;
207 }
208 a->priv = p;
209 }
210 return p;
211}
212EXPORT_SYMBOL(tcf_hash_check);
213
214struct tcf_common *tcf_hash_create(u32 index, struct rtattr *est, struct tc_action *a, int size, int bind, u32 *idx_gen, struct tcf_hashinfo *hinfo)
215{
216 struct tcf_common *p = kzalloc(size, GFP_KERNEL);
217
218 if (unlikely(!p))
219 return p;
220 p->tcfc_refcnt = 1;
221 if (bind)
222 p->tcfc_bindcnt = 1;
223
224 spin_lock_init(&p->tcfc_lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700225 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
226 p->tcfc_tm.install = jiffies;
227 p->tcfc_tm.lastuse = jiffies;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700228 if (est)
229 gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
Patrick McHardy4bdf3992007-07-02 22:47:37 -0700230 &p->tcfc_lock, est);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700231 a->priv = (void *) p;
232 return p;
233}
234EXPORT_SYMBOL(tcf_hash_create);
235
236void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
237{
238 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
239
240 write_lock_bh(hinfo->lock);
241 p->tcfc_next = hinfo->htab[h];
242 hinfo->htab[h] = p;
243 write_unlock_bh(hinfo->lock);
244}
245EXPORT_SYMBOL(tcf_hash_insert);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247static struct tc_action_ops *act_base = NULL;
248static DEFINE_RWLOCK(act_mod_lock);
249
250int tcf_register_action(struct tc_action_ops *act)
251{
252 struct tc_action_ops *a, **ap;
253
254 write_lock(&act_mod_lock);
255 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
256 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
257 write_unlock(&act_mod_lock);
258 return -EEXIST;
259 }
260 }
261 act->next = NULL;
262 *ap = act;
263 write_unlock(&act_mod_lock);
264 return 0;
265}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800266EXPORT_SYMBOL(tcf_register_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268int tcf_unregister_action(struct tc_action_ops *act)
269{
270 struct tc_action_ops *a, **ap;
271 int err = -ENOENT;
272
273 write_lock(&act_mod_lock);
274 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next)
275 if (a == act)
276 break;
277 if (a) {
278 *ap = a->next;
279 a->next = NULL;
280 err = 0;
281 }
282 write_unlock(&act_mod_lock);
283 return err;
284}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800285EXPORT_SYMBOL(tcf_unregister_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/* lookup by name */
288static struct tc_action_ops *tc_lookup_action_n(char *kind)
289{
290 struct tc_action_ops *a = NULL;
291
292 if (kind) {
293 read_lock(&act_mod_lock);
294 for (a = act_base; a; a = a->next) {
295 if (strcmp(kind, a->kind) == 0) {
296 if (!try_module_get(a->owner)) {
297 read_unlock(&act_mod_lock);
298 return NULL;
299 }
300 break;
301 }
302 }
303 read_unlock(&act_mod_lock);
304 }
305 return a;
306}
307
308/* lookup by rtattr */
309static struct tc_action_ops *tc_lookup_action(struct rtattr *kind)
310{
311 struct tc_action_ops *a = NULL;
312
313 if (kind) {
314 read_lock(&act_mod_lock);
315 for (a = act_base; a; a = a->next) {
316 if (rtattr_strcmp(kind, a->kind) == 0) {
317 if (!try_module_get(a->owner)) {
318 read_unlock(&act_mod_lock);
319 return NULL;
320 }
321 break;
322 }
323 }
324 read_unlock(&act_mod_lock);
325 }
326 return a;
327}
328
329#if 0
330/* lookup by id */
331static struct tc_action_ops *tc_lookup_action_id(u32 type)
332{
333 struct tc_action_ops *a = NULL;
334
335 if (type) {
336 read_lock(&act_mod_lock);
337 for (a = act_base; a; a = a->next) {
338 if (a->type == type) {
339 if (!try_module_get(a->owner)) {
340 read_unlock(&act_mod_lock);
341 return NULL;
342 }
343 break;
344 }
345 }
346 read_unlock(&act_mod_lock);
347 }
348 return a;
349}
350#endif
351
352int tcf_action_exec(struct sk_buff *skb, struct tc_action *act,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900353 struct tcf_result *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
355 struct tc_action *a;
356 int ret = -1;
357
358 if (skb->tc_verd & TC_NCLS) {
359 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 ret = TC_ACT_OK;
361 goto exec_done;
362 }
363 while ((a = act) != NULL) {
364repeat:
365 if (a->ops && a->ops->act) {
Patrick McHardyf43c5a02006-01-08 22:15:34 -0800366 ret = a->ops->act(skb, a, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (TC_MUNGED & skb->tc_verd) {
368 /* copied already, allow trampling */
369 skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
370 skb->tc_verd = CLR_TC_MUNGED(skb->tc_verd);
371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (ret == TC_ACT_REPEAT)
373 goto repeat; /* we need a ttl - JHS */
J Hadi Salim14d50e72005-05-03 16:29:13 -0700374 if (ret != TC_ACT_PIPE)
375 goto exec_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377 act = a->next;
378 }
379exec_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return ret;
381}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800382EXPORT_SYMBOL(tcf_action_exec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384void tcf_action_destroy(struct tc_action *act, int bind)
385{
386 struct tc_action *a;
387
388 for (a = act; a; a = act) {
389 if (a->ops && a->ops->cleanup) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
391 module_put(a->ops->owner);
392 act = act->next;
393 kfree(a);
394 } else { /*FIXME: Remove later - catch insertion bugs*/
395 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
396 act = act->next;
397 kfree(a);
398 }
399 }
400}
401
402int
403tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
404{
405 int err = -EINVAL;
406
407 if (a->ops == NULL || a->ops->dump == NULL)
408 return err;
409 return a->ops->dump(skb, a, bind, ref);
410}
411
412int
413tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
414{
415 int err = -EINVAL;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700416 unsigned char *b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct rtattr *r;
418
419 if (a->ops == NULL || a->ops->dump == NULL)
420 return err;
421
422 RTA_PUT(skb, TCA_KIND, IFNAMSIZ, a->ops->kind);
423 if (tcf_action_copy_stats(skb, a, 0))
424 goto rtattr_failure;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700425 r = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
427 if ((err = tcf_action_dump_old(skb, a, bind, ref)) > 0) {
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700428 r->rta_len = skb_tail_pointer(skb) - (u8 *)r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return err;
430 }
431
432rtattr_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700433 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return -1;
435}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800436EXPORT_SYMBOL(tcf_action_dump_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438int
439tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref)
440{
441 struct tc_action *a;
442 int err = -EINVAL;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700443 unsigned char *b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 struct rtattr *r ;
445
446 while ((a = act) != NULL) {
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700447 r = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 act = a->next;
449 RTA_PUT(skb, a->order, 0, NULL);
450 err = tcf_action_dump_1(skb, a, bind, ref);
451 if (err < 0)
Thomas Graf4fe683f2006-07-05 20:47:28 -0700452 goto errout;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700453 r->rta_len = skb_tail_pointer(skb) - (u8 *)r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 return 0;
457
458rtattr_failure:
Thomas Graf4fe683f2006-07-05 20:47:28 -0700459 err = -EINVAL;
460errout:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700461 nlmsg_trim(skb, b);
Thomas Graf4fe683f2006-07-05 20:47:28 -0700462 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
465struct tc_action *tcf_action_init_1(struct rtattr *rta, struct rtattr *est,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900466 char *name, int ovr, int bind, int *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468 struct tc_action *a;
469 struct tc_action_ops *a_o;
470 char act_name[IFNAMSIZ];
471 struct rtattr *tb[TCA_ACT_MAX+1];
472 struct rtattr *kind;
473
474 *err = -EINVAL;
475
476 if (name == NULL) {
477 if (rtattr_parse_nested(tb, TCA_ACT_MAX, rta) < 0)
478 goto err_out;
479 kind = tb[TCA_ACT_KIND-1];
480 if (kind == NULL)
481 goto err_out;
482 if (rtattr_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
483 goto err_out;
484 } else {
485 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
486 goto err_out;
487 }
488
489 a_o = tc_lookup_action_n(act_name);
490 if (a_o == NULL) {
491#ifdef CONFIG_KMOD
492 rtnl_unlock();
Patrick McHardy4bba3922006-01-08 22:22:14 -0800493 request_module("act_%s", act_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 rtnl_lock();
495
496 a_o = tc_lookup_action_n(act_name);
497
498 /* We dropped the RTNL semaphore in order to
499 * perform the module load. So, even if we
500 * succeeded in loading the module we have to
501 * tell the caller to replay the request. We
502 * indicate this using -EAGAIN.
503 */
504 if (a_o != NULL) {
505 *err = -EAGAIN;
506 goto err_mod;
507 }
508#endif
Thomas Grafd152b4e2006-07-05 20:45:57 -0700509 *err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 goto err_out;
511 }
512
513 *err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700514 a = kzalloc(sizeof(*a), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (a == NULL)
516 goto err_mod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 /* backward compatibility for policer */
519 if (name == NULL)
520 *err = a_o->init(tb[TCA_ACT_OPTIONS-1], est, a, ovr, bind);
521 else
522 *err = a_o->init(rta, est, a, ovr, bind);
523 if (*err < 0)
524 goto err_free;
525
526 /* module count goes up only when brand new policy is created
527 if it exists and is only bound to in a_o->init() then
528 ACT_P_CREATED is not returned (a zero is).
529 */
530 if (*err != ACT_P_CREATED)
531 module_put(a_o->owner);
532 a->ops = a_o;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 *err = 0;
535 return a;
536
537err_free:
538 kfree(a);
539err_mod:
540 module_put(a_o->owner);
541err_out:
542 return NULL;
543}
544
545struct tc_action *tcf_action_init(struct rtattr *rta, struct rtattr *est,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900546 char *name, int ovr, int bind, int *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
548 struct rtattr *tb[TCA_ACT_MAX_PRIO+1];
549 struct tc_action *head = NULL, *act, *act_prev = NULL;
550 int i;
551
552 if (rtattr_parse_nested(tb, TCA_ACT_MAX_PRIO, rta) < 0) {
553 *err = -EINVAL;
554 return head;
555 }
556
557 for (i=0; i < TCA_ACT_MAX_PRIO && tb[i]; i++) {
558 act = tcf_action_init_1(tb[i], est, name, ovr, bind, err);
559 if (act == NULL)
560 goto err;
561 act->order = i+1;
562
563 if (head == NULL)
564 head = act;
565 else
566 act_prev->next = act;
567 act_prev = act;
568 }
569 return head;
570
571err:
572 if (head != NULL)
573 tcf_action_destroy(head, bind);
574 return NULL;
575}
576
577int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
578 int compat_mode)
579{
580 int err = 0;
581 struct gnet_dump d;
582 struct tcf_act_hdr *h = a->priv;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (h == NULL)
585 goto errout;
586
587 /* compat_mode being true specifies a call that is supposed
588 * to add additional backward compatiblity statistic TLVs.
589 */
590 if (compat_mode) {
591 if (a->type == TCA_OLD_COMPAT)
592 err = gnet_stats_start_copy_compat(skb, 0,
Patrick McHardy4bdf3992007-07-02 22:47:37 -0700593 TCA_STATS, TCA_XSTATS, &h->tcf_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 else
595 return 0;
596 } else
597 err = gnet_stats_start_copy(skb, TCA_ACT_STATS,
Patrick McHardy4bdf3992007-07-02 22:47:37 -0700598 &h->tcf_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 if (err < 0)
601 goto errout;
602
603 if (a->ops != NULL && a->ops->get_stats != NULL)
604 if (a->ops->get_stats(skb, a) < 0)
605 goto errout;
606
David S. Millere9ce1cd2006-08-21 23:54:55 -0700607 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 ||
David S. Millere9ce1cd2006-08-21 23:54:55 -0700608 gnet_stats_copy_rate_est(&d, &h->tcf_rate_est) < 0 ||
David S. Millere9ce1cd2006-08-21 23:54:55 -0700609 gnet_stats_copy_queue(&d, &h->tcf_qstats) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 goto errout;
611
612 if (gnet_stats_finish_copy(&d) < 0)
613 goto errout;
614
615 return 0;
616
617errout:
618 return -1;
619}
620
621static int
622tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900623 u16 flags, int event, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
625 struct tcamsg *t;
626 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700627 unsigned char *b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 struct rtattr *x;
629
Jamal Hadi Salime431b8c2005-06-18 22:55:31 -0700630 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 t = NLMSG_DATA(nlh);
633 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700634 t->tca__pad1 = 0;
635 t->tca__pad2 = 0;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900636
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700637 x = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
639
640 if (tcf_action_dump(skb, a, bind, ref) < 0)
641 goto rtattr_failure;
642
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700643 x->rta_len = skb_tail_pointer(skb) - (u8 *)x;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900644
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700645 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 return skb->len;
647
648rtattr_failure:
649nlmsg_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700650 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return -1;
652}
653
654static int
655act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event)
656{
657 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
660 if (!skb)
661 return -ENOBUFS;
662 if (tca_get_fill(skb, a, pid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
663 kfree_skb(skb);
664 return -EINVAL;
665 }
Thomas Graf2942e902006-08-15 00:30:25 -0700666
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800667 return rtnl_unicast(skb, &init_net, pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670static struct tc_action *
671tcf_action_get_1(struct rtattr *rta, struct nlmsghdr *n, u32 pid, int *err)
672{
673 struct rtattr *tb[TCA_ACT_MAX+1];
674 struct tc_action *a;
675 int index;
676
677 *err = -EINVAL;
678 if (rtattr_parse_nested(tb, TCA_ACT_MAX, rta) < 0)
679 return NULL;
680
681 if (tb[TCA_ACT_INDEX - 1] == NULL ||
682 RTA_PAYLOAD(tb[TCA_ACT_INDEX - 1]) < sizeof(index))
683 return NULL;
684 index = *(int *)RTA_DATA(tb[TCA_ACT_INDEX - 1]);
685
686 *err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700687 a = kzalloc(sizeof(struct tc_action), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (a == NULL)
689 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 *err = -EINVAL;
692 a->ops = tc_lookup_action(tb[TCA_ACT_KIND - 1]);
693 if (a->ops == NULL)
694 goto err_free;
695 if (a->ops->lookup == NULL)
696 goto err_mod;
697 *err = -ENOENT;
698 if (a->ops->lookup(a, index) == 0)
699 goto err_mod;
700
701 module_put(a->ops->owner);
702 *err = 0;
703 return a;
704err_mod:
705 module_put(a->ops->owner);
706err_free:
707 kfree(a);
708 return NULL;
709}
710
711static void cleanup_a(struct tc_action *act)
712{
713 struct tc_action *a;
714
715 for (a = act; a; a = act) {
716 act = a->next;
717 kfree(a);
718 }
719}
720
721static struct tc_action *create_a(int i)
722{
723 struct tc_action *act;
724
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700725 act = kzalloc(sizeof(*act), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if (act == NULL) {
727 printk("create_a: failed to alloc!\n");
728 return NULL;
729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 act->order = i;
731 return act;
732}
733
734static int tca_action_flush(struct rtattr *rta, struct nlmsghdr *n, u32 pid)
735{
736 struct sk_buff *skb;
737 unsigned char *b;
738 struct nlmsghdr *nlh;
739 struct tcamsg *t;
740 struct netlink_callback dcb;
741 struct rtattr *x;
742 struct rtattr *tb[TCA_ACT_MAX+1];
743 struct rtattr *kind;
744 struct tc_action *a = create_a(0);
745 int err = -EINVAL;
746
747 if (a == NULL) {
748 printk("tca_action_flush: couldnt create tc_action\n");
749 return err;
750 }
751
752 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
753 if (!skb) {
754 printk("tca_action_flush: failed skb alloc\n");
755 kfree(a);
756 return -ENOBUFS;
757 }
758
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700759 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 if (rtattr_parse_nested(tb, TCA_ACT_MAX, rta) < 0)
762 goto err_out;
763
764 kind = tb[TCA_ACT_KIND-1];
765 a->ops = tc_lookup_action(kind);
766 if (a->ops == NULL)
767 goto err_out;
768
769 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t));
770 t = NLMSG_DATA(nlh);
771 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700772 t->tca__pad1 = 0;
773 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700775 x = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
777
778 err = a->ops->walk(skb, &dcb, RTM_DELACTION, a);
779 if (err < 0)
780 goto rtattr_failure;
781
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700782 x->rta_len = skb_tail_pointer(skb) - (u8 *)x;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700784 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 nlh->nlmsg_flags |= NLM_F_ROOT;
786 module_put(a->ops->owner);
787 kfree(a);
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800788 err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 if (err > 0)
790 return 0;
791
792 return err;
793
794rtattr_failure:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795nlmsg_failure:
Thomas Grafebbaeab2006-07-09 11:36:23 -0700796 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797err_out:
798 kfree_skb(skb);
799 kfree(a);
800 return err;
801}
802
803static int
804tca_action_gd(struct rtattr *rta, struct nlmsghdr *n, u32 pid, int event)
805{
806 int i, ret = 0;
807 struct rtattr *tb[TCA_ACT_MAX_PRIO+1];
808 struct tc_action *head = NULL, *act, *act_prev = NULL;
809
810 if (rtattr_parse_nested(tb, TCA_ACT_MAX_PRIO, rta) < 0)
811 return -EINVAL;
812
813 if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) {
814 if (tb[0] != NULL && tb[1] == NULL)
815 return tca_action_flush(tb[0], n, pid);
816 }
817
818 for (i=0; i < TCA_ACT_MAX_PRIO && tb[i]; i++) {
819 act = tcf_action_get_1(tb[i], n, pid, &ret);
820 if (act == NULL)
821 goto err;
822 act->order = i+1;
823
824 if (head == NULL)
825 head = act;
826 else
827 act_prev->next = act;
828 act_prev = act;
829 }
830
831 if (event == RTM_GETACTION)
832 ret = act_get_notify(pid, n, head, event);
833 else { /* delete */
834 struct sk_buff *skb;
835
836 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
837 if (!skb) {
838 ret = -ENOBUFS;
839 goto err;
840 }
841
842 if (tca_get_fill(skb, head, pid, n->nlmsg_seq, 0, event,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900843 0, 1) <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 kfree_skb(skb);
845 ret = -EINVAL;
846 goto err;
847 }
848
849 /* now do the delete */
850 tcf_action_destroy(head, 0);
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800851 ret = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900852 n->nlmsg_flags&NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (ret > 0)
854 return 0;
855 return ret;
856 }
857err:
858 cleanup_a(head);
859 return ret;
860}
861
862static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900863 u16 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
865 struct tcamsg *t;
866 struct nlmsghdr *nlh;
867 struct sk_buff *skb;
868 struct rtattr *x;
869 unsigned char *b;
870 int err = 0;
871
872 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
873 if (!skb)
874 return -ENOBUFS;
875
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700876 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Jamal Hadi Salime431b8c2005-06-18 22:55:31 -0700878 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 t = NLMSG_DATA(nlh);
880 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700881 t->tca__pad1 = 0;
882 t->tca__pad2 = 0;
883
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700884 x = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
886
887 if (tcf_action_dump(skb, a, 0, 0) < 0)
888 goto rtattr_failure;
889
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700890 x->rta_len = skb_tail_pointer(skb) - (u8 *)x;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900891
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700892 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Patrick McHardyac6d4392005-08-14 19:29:52 -0700893 NETLINK_CB(skb).dst_group = RTNLGRP_TC;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900894
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800895 err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, flags&NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 if (err > 0)
897 err = 0;
898 return err;
899
900rtattr_failure:
901nlmsg_failure:
Patrick McHardyf6e57462006-03-12 20:33:22 -0800902 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return -1;
904}
905
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907static int
908tcf_action_add(struct rtattr *rta, struct nlmsghdr *n, u32 pid, int ovr)
909{
910 int ret = 0;
911 struct tc_action *act;
912 struct tc_action *a;
913 u32 seq = n->nlmsg_seq;
914
915 act = tcf_action_init(rta, NULL, NULL, ovr, 0, &ret);
916 if (act == NULL)
917 goto done;
918
919 /* dump then free all the actions after update; inserted policy
920 * stays intact
921 * */
922 ret = tcf_add_notify(act, pid, seq, RTM_NEWACTION, n->nlmsg_flags);
923 for (a = act; a; a = act) {
924 act = a->next;
925 kfree(a);
926 }
927done:
928 return ret;
929}
930
931static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
932{
Denis V. Lunevb8542722007-12-01 00:21:31 +1100933 struct net *net = skb->sk->sk_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 struct rtattr **tca = arg;
935 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
936 int ret = 0, ovr = 0;
937
Denis V. Lunevb8542722007-12-01 00:21:31 +1100938 if (net != &init_net)
939 return -EINVAL;
940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 if (tca[TCA_ACT_TAB-1] == NULL) {
942 printk("tc_ctl_action: received NO action attribs\n");
943 return -EINVAL;
944 }
945
946 /* n->nlmsg_flags&NLM_F_CREATE
947 * */
948 switch (n->nlmsg_type) {
949 case RTM_NEWACTION:
950 /* we are going to assume all other flags
951 * imply create only if it doesnt exist
952 * Note that CREATE | EXCL implies that
953 * but since we want avoid ambiguity (eg when flags
954 * is zero) then just set this
955 */
956 if (n->nlmsg_flags&NLM_F_REPLACE)
957 ovr = 1;
958replay:
959 ret = tcf_action_add(tca[TCA_ACT_TAB-1], n, pid, ovr);
960 if (ret == -EAGAIN)
961 goto replay;
962 break;
963 case RTM_DELACTION:
964 ret = tca_action_gd(tca[TCA_ACT_TAB-1], n, pid, RTM_DELACTION);
965 break;
966 case RTM_GETACTION:
967 ret = tca_action_gd(tca[TCA_ACT_TAB-1], n, pid, RTM_GETACTION);
968 break;
969 default:
970 BUG();
971 }
972
973 return ret;
974}
975
Thomas Graf26dab892006-07-05 20:45:06 -0700976static struct rtattr *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977find_dump_kind(struct nlmsghdr *n)
978{
979 struct rtattr *tb1, *tb2[TCA_ACT_MAX+1];
980 struct rtattr *tb[TCA_ACT_MAX_PRIO + 1];
981 struct rtattr *rta[TCAA_MAX + 1];
982 struct rtattr *kind;
983 int min_len = NLMSG_LENGTH(sizeof(struct tcamsg));
984 int attrlen = n->nlmsg_len - NLMSG_ALIGN(min_len);
985 struct rtattr *attr = (void *) n + NLMSG_ALIGN(min_len);
986
987 if (rtattr_parse(rta, TCAA_MAX, attr, attrlen) < 0)
988 return NULL;
989 tb1 = rta[TCA_ACT_TAB - 1];
990 if (tb1 == NULL)
991 return NULL;
992
993 if (rtattr_parse(tb, TCA_ACT_MAX_PRIO, RTA_DATA(tb1),
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900994 NLMSG_ALIGN(RTA_PAYLOAD(tb1))) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 return NULL;
996 if (tb[0] == NULL)
997 return NULL;
998
999 if (rtattr_parse(tb2, TCA_ACT_MAX, RTA_DATA(tb[0]),
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +09001000 RTA_PAYLOAD(tb[0])) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return NULL;
1002 kind = tb2[TCA_ACT_KIND-1];
1003
Thomas Graf26dab892006-07-05 20:45:06 -07001004 return kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
1007static int
1008tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1009{
Denis V. Lunevb8542722007-12-01 00:21:31 +11001010 struct net *net = skb->sk->sk_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001012 unsigned char *b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 struct rtattr *x;
1014 struct tc_action_ops *a_o;
1015 struct tc_action a;
1016 int ret = 0;
1017 struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh);
Thomas Graf26dab892006-07-05 20:45:06 -07001018 struct rtattr *kind = find_dump_kind(cb->nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Denis V. Lunevb8542722007-12-01 00:21:31 +11001020 if (net != &init_net)
1021 return 0;
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 if (kind == NULL) {
1024 printk("tc_dump_action: action bad kind\n");
1025 return 0;
1026 }
1027
Thomas Graf26dab892006-07-05 20:45:06 -07001028 a_o = tc_lookup_action(kind);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (a_o == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return 0;
1031 }
1032
1033 memset(&a, 0, sizeof(struct tc_action));
1034 a.ops = a_o;
1035
1036 if (a_o->walk == NULL) {
Thomas Graf26dab892006-07-05 20:45:06 -07001037 printk("tc_dump_action: %s !capable of dumping table\n", a_o->kind);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 goto rtattr_failure;
1039 }
1040
1041 nlh = NLMSG_PUT(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +09001042 cb->nlh->nlmsg_type, sizeof(*t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 t = NLMSG_DATA(nlh);
1044 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -07001045 t->tca__pad1 = 0;
1046 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001048 x = (struct rtattr *)skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
1050
1051 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1052 if (ret < 0)
1053 goto rtattr_failure;
1054
1055 if (ret > 0) {
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001056 x->rta_len = skb_tail_pointer(skb) - (u8 *)x;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 ret = skb->len;
1058 } else
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001059 nlmsg_trim(skb, x);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001061 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if (NETLINK_CB(cb->skb).pid && ret)
1063 nlh->nlmsg_flags |= NLM_F_MULTI;
1064 module_put(a_o->owner);
1065 return skb->len;
1066
1067rtattr_failure:
1068nlmsg_failure:
1069 module_put(a_o->owner);
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001070 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 return skb->len;
1072}
1073
1074static int __init tc_action_init(void)
1075{
Thomas Graf708914c2007-03-22 11:56:59 -07001076 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL);
1077 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL);
1078 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 return 0;
1081}
1082
1083subsys_initcall(tc_action_init);