2 * net/sched/act_api.c Packet action API.
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.
9 * Author: Jamal Hadi Salim
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/skbuff.h>
19 #include <linux/init.h>
20 #include <linux/kmod.h>
21 #include <net/net_namespace.h>
23 #include <net/sch_generic.h>
24 #include <net/act_api.h>
25 #include <net/netlink.h>
27 void tcf_hash_destroy(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
29 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
30 struct tcf_common
**p1p
;
32 for (p1p
= &hinfo
->htab
[h
]; *p1p
; p1p
= &(*p1p
)->tcfc_next
) {
34 write_lock_bh(hinfo
->lock
);
36 write_unlock_bh(hinfo
->lock
);
37 gen_kill_estimator(&p
->tcfc_bstats
,
45 EXPORT_SYMBOL(tcf_hash_destroy
);
47 int tcf_hash_release(struct tcf_common
*p
, int bind
,
48 struct tcf_hashinfo
*hinfo
)
57 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
58 tcf_hash_destroy(p
, hinfo
);
64 EXPORT_SYMBOL(tcf_hash_release
);
66 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
67 struct tc_action
*a
, struct tcf_hashinfo
*hinfo
)
70 int err
= 0, index
= -1,i
= 0, s_i
= 0, n_i
= 0;
73 read_lock_bh(hinfo
->lock
);
77 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
78 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
80 for (; p
; p
= p
->tcfc_next
) {
86 r
= (struct rtattr
*)skb_tail_pointer(skb
);
87 RTA_PUT(skb
, a
->order
, 0, NULL
);
88 err
= tcf_action_dump_1(skb
, a
, 0, 0);
94 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
96 if (n_i
>= TCA_ACT_MAX_PRIO
)
101 read_unlock_bh(hinfo
->lock
);
111 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
,
112 struct tcf_hashinfo
*hinfo
)
114 struct tcf_common
*p
, *s_p
;
118 r
= (struct rtattr
*)skb_tail_pointer(skb
);
119 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
)];
126 if (ACT_P_DELETED
== tcf_hash_release(p
, 0, hinfo
))
127 module_put(a
->ops
->owner
);
132 RTA_PUT(skb
, TCA_FCNT
, 4, &n_i
);
133 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
141 int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
142 int type
, struct tc_action
*a
)
144 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
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
);
151 printk("tcf_generic_walker: unknown action %d\n", type
);
155 EXPORT_SYMBOL(tcf_generic_walker
);
157 struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
159 struct tcf_common
*p
;
161 read_lock_bh(hinfo
->lock
);
162 for (p
= hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)]; p
;
164 if (p
->tcfc_index
== index
)
167 read_unlock_bh(hinfo
->lock
);
171 EXPORT_SYMBOL(tcf_hash_lookup
);
173 u32
tcf_hash_new_index(u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
180 } while (tcf_hash_lookup(val
, hinfo
));
182 return (*idx_gen
= val
);
184 EXPORT_SYMBOL(tcf_hash_new_index
);
186 int tcf_hash_search(struct tc_action
*a
, u32 index
)
188 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
189 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
197 EXPORT_SYMBOL(tcf_hash_search
);
199 struct tcf_common
*tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
,
200 struct tcf_hashinfo
*hinfo
)
202 struct tcf_common
*p
= NULL
;
203 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
212 EXPORT_SYMBOL(tcf_hash_check
);
214 struct 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
)
216 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
224 spin_lock_init(&p
->tcfc_lock
);
225 p
->tcfc_index
= index
? index
: tcf_hash_new_index(idx_gen
, hinfo
);
226 p
->tcfc_tm
.install
= jiffies
;
227 p
->tcfc_tm
.lastuse
= jiffies
;
229 gen_new_estimator(&p
->tcfc_bstats
, &p
->tcfc_rate_est
,
231 a
->priv
= (void *) p
;
234 EXPORT_SYMBOL(tcf_hash_create
);
236 void tcf_hash_insert(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
238 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
240 write_lock_bh(hinfo
->lock
);
241 p
->tcfc_next
= hinfo
->htab
[h
];
243 write_unlock_bh(hinfo
->lock
);
245 EXPORT_SYMBOL(tcf_hash_insert
);
247 static struct tc_action_ops
*act_base
= NULL
;
248 static DEFINE_RWLOCK(act_mod_lock
);
250 int tcf_register_action(struct tc_action_ops
*act
)
252 struct tc_action_ops
*a
, **ap
;
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
);
263 write_unlock(&act_mod_lock
);
267 int tcf_unregister_action(struct tc_action_ops
*act
)
269 struct tc_action_ops
*a
, **ap
;
272 write_lock(&act_mod_lock
);
273 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
)
281 write_unlock(&act_mod_lock
);
286 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
288 struct tc_action_ops
*a
= NULL
;
291 read_lock(&act_mod_lock
);
292 for (a
= act_base
; a
; a
= a
->next
) {
293 if (strcmp(kind
, a
->kind
) == 0) {
294 if (!try_module_get(a
->owner
)) {
295 read_unlock(&act_mod_lock
);
301 read_unlock(&act_mod_lock
);
306 /* lookup by rtattr */
307 static struct tc_action_ops
*tc_lookup_action(struct rtattr
*kind
)
309 struct tc_action_ops
*a
= NULL
;
312 read_lock(&act_mod_lock
);
313 for (a
= act_base
; a
; a
= a
->next
) {
314 if (rtattr_strcmp(kind
, a
->kind
) == 0) {
315 if (!try_module_get(a
->owner
)) {
316 read_unlock(&act_mod_lock
);
322 read_unlock(&act_mod_lock
);
329 static struct tc_action_ops
*tc_lookup_action_id(u32 type
)
331 struct tc_action_ops
*a
= NULL
;
334 read_lock(&act_mod_lock
);
335 for (a
= act_base
; a
; a
= a
->next
) {
336 if (a
->type
== type
) {
337 if (!try_module_get(a
->owner
)) {
338 read_unlock(&act_mod_lock
);
344 read_unlock(&act_mod_lock
);
350 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
*act
,
351 struct tcf_result
*res
)
356 if (skb
->tc_verd
& TC_NCLS
) {
357 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
361 while ((a
= act
) != NULL
) {
363 if (a
->ops
&& a
->ops
->act
) {
364 ret
= a
->ops
->act(skb
, a
, res
);
365 if (TC_MUNGED
& skb
->tc_verd
) {
366 /* copied already, allow trampling */
367 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
368 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
370 if (ret
== TC_ACT_REPEAT
)
371 goto repeat
; /* we need a ttl - JHS */
372 if (ret
!= TC_ACT_PIPE
)
381 void tcf_action_destroy(struct tc_action
*act
, int bind
)
385 for (a
= act
; a
; a
= act
) {
386 if (a
->ops
&& a
->ops
->cleanup
) {
387 if (a
->ops
->cleanup(a
, bind
) == ACT_P_DELETED
)
388 module_put(a
->ops
->owner
);
391 } else { /*FIXME: Remove later - catch insertion bugs*/
392 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
400 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
404 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
406 return a
->ops
->dump(skb
, a
, bind
, ref
);
410 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
413 unsigned char *b
= skb_tail_pointer(skb
);
416 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
419 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
420 if (tcf_action_copy_stats(skb
, a
, 0))
422 r
= (struct rtattr
*)skb_tail_pointer(skb
);
423 RTA_PUT(skb
, TCA_OPTIONS
, 0, NULL
);
424 if ((err
= tcf_action_dump_old(skb
, a
, bind
, ref
)) > 0) {
425 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
435 tcf_action_dump(struct sk_buff
*skb
, struct tc_action
*act
, int bind
, int ref
)
439 unsigned char *b
= skb_tail_pointer(skb
);
442 while ((a
= act
) != NULL
) {
443 r
= (struct rtattr
*)skb_tail_pointer(skb
);
445 RTA_PUT(skb
, a
->order
, 0, NULL
);
446 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
449 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
461 struct tc_action
*tcf_action_init_1(struct rtattr
*rta
, struct rtattr
*est
,
462 char *name
, int ovr
, int bind
, int *err
)
465 struct tc_action_ops
*a_o
;
466 char act_name
[IFNAMSIZ
];
467 struct rtattr
*tb
[TCA_ACT_MAX
+1];
473 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
475 kind
= tb
[TCA_ACT_KIND
-1];
478 if (rtattr_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
481 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
485 a_o
= tc_lookup_action_n(act_name
);
489 request_module("act_%s", act_name
);
492 a_o
= tc_lookup_action_n(act_name
);
494 /* We dropped the RTNL semaphore in order to
495 * perform the module load. So, even if we
496 * succeeded in loading the module we have to
497 * tell the caller to replay the request. We
498 * indicate this using -EAGAIN.
510 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
514 /* backward compatibility for policer */
516 *err
= a_o
->init(tb
[TCA_ACT_OPTIONS
-1], est
, a
, ovr
, bind
);
518 *err
= a_o
->init(rta
, est
, a
, ovr
, bind
);
522 /* module count goes up only when brand new policy is created
523 if it exists and is only bound to in a_o->init() then
524 ACT_P_CREATED is not returned (a zero is).
526 if (*err
!= ACT_P_CREATED
)
527 module_put(a_o
->owner
);
536 module_put(a_o
->owner
);
541 struct tc_action
*tcf_action_init(struct rtattr
*rta
, struct rtattr
*est
,
542 char *name
, int ovr
, int bind
, int *err
)
544 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
545 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
548 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0) {
553 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
554 act
= tcf_action_init_1(tb
[i
], est
, name
, ovr
, bind
, err
);
562 act_prev
->next
= act
;
569 tcf_action_destroy(head
, bind
);
573 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
578 struct tcf_act_hdr
*h
= a
->priv
;
583 /* compat_mode being true specifies a call that is supposed
584 * to add additional backward compatiblity statistic TLVs.
587 if (a
->type
== TCA_OLD_COMPAT
)
588 err
= gnet_stats_start_copy_compat(skb
, 0,
589 TCA_STATS
, TCA_XSTATS
, &h
->tcf_lock
, &d
);
593 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
599 if (a
->ops
!= NULL
&& a
->ops
->get_stats
!= NULL
)
600 if (a
->ops
->get_stats(skb
, a
) < 0)
603 if (gnet_stats_copy_basic(&d
, &h
->tcf_bstats
) < 0 ||
604 gnet_stats_copy_rate_est(&d
, &h
->tcf_rate_est
) < 0 ||
605 gnet_stats_copy_queue(&d
, &h
->tcf_qstats
) < 0)
608 if (gnet_stats_finish_copy(&d
) < 0)
618 tca_get_fill(struct sk_buff
*skb
, struct tc_action
*a
, u32 pid
, u32 seq
,
619 u16 flags
, int event
, int bind
, int ref
)
622 struct nlmsghdr
*nlh
;
623 unsigned char *b
= skb_tail_pointer(skb
);
626 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
629 t
->tca_family
= AF_UNSPEC
;
633 x
= (struct rtattr
*)skb_tail_pointer(skb
);
634 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
636 if (tcf_action_dump(skb
, a
, bind
, ref
) < 0)
639 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
641 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
651 act_get_notify(u32 pid
, struct nlmsghdr
*n
, struct tc_action
*a
, int event
)
655 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
658 if (tca_get_fill(skb
, a
, pid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
663 return rtnl_unicast(skb
, &init_net
, pid
);
666 static struct tc_action
*
667 tcf_action_get_1(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int *err
)
669 struct rtattr
*tb
[TCA_ACT_MAX
+1];
674 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
677 if (tb
[TCA_ACT_INDEX
- 1] == NULL
||
678 RTA_PAYLOAD(tb
[TCA_ACT_INDEX
- 1]) < sizeof(index
))
680 index
= *(int *)RTA_DATA(tb
[TCA_ACT_INDEX
- 1]);
683 a
= kzalloc(sizeof(struct tc_action
), GFP_KERNEL
);
688 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
- 1]);
691 if (a
->ops
->lookup
== NULL
)
694 if (a
->ops
->lookup(a
, index
) == 0)
697 module_put(a
->ops
->owner
);
701 module_put(a
->ops
->owner
);
707 static void cleanup_a(struct tc_action
*act
)
711 for (a
= act
; a
; a
= act
) {
717 static struct tc_action
*create_a(int i
)
719 struct tc_action
*act
;
721 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
723 printk("create_a: failed to alloc!\n");
730 static int tca_action_flush(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
)
734 struct nlmsghdr
*nlh
;
736 struct netlink_callback dcb
;
738 struct rtattr
*tb
[TCA_ACT_MAX
+1];
740 struct tc_action
*a
= create_a(0);
744 printk("tca_action_flush: couldnt create tc_action\n");
748 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
750 printk("tca_action_flush: failed skb alloc\n");
755 b
= skb_tail_pointer(skb
);
757 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
760 kind
= tb
[TCA_ACT_KIND
-1];
761 a
->ops
= tc_lookup_action(kind
);
765 nlh
= NLMSG_PUT(skb
, pid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
));
767 t
->tca_family
= AF_UNSPEC
;
771 x
= (struct rtattr
*)skb_tail_pointer(skb
);
772 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
774 err
= a
->ops
->walk(skb
, &dcb
, RTM_DELACTION
, a
);
778 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
780 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
781 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
782 module_put(a
->ops
->owner
);
784 err
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
792 module_put(a
->ops
->owner
);
800 tca_action_gd(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int event
)
803 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
804 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
806 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0)
809 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
&NLM_F_ROOT
) {
810 if (tb
[0] != NULL
&& tb
[1] == NULL
)
811 return tca_action_flush(tb
[0], n
, pid
);
814 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
815 act
= tcf_action_get_1(tb
[i
], n
, pid
, &ret
);
823 act_prev
->next
= act
;
827 if (event
== RTM_GETACTION
)
828 ret
= act_get_notify(pid
, n
, head
, event
);
832 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
838 if (tca_get_fill(skb
, head
, pid
, n
->nlmsg_seq
, 0, event
,
845 /* now do the delete */
846 tcf_action_destroy(head
, 0);
847 ret
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
,
848 n
->nlmsg_flags
&NLM_F_ECHO
);
858 static int tcf_add_notify(struct tc_action
*a
, u32 pid
, u32 seq
, int event
,
862 struct nlmsghdr
*nlh
;
868 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
872 b
= skb_tail_pointer(skb
);
874 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
876 t
->tca_family
= AF_UNSPEC
;
880 x
= (struct rtattr
*)skb_tail_pointer(skb
);
881 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
883 if (tcf_action_dump(skb
, a
, 0, 0) < 0)
886 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
888 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
889 NETLINK_CB(skb
).dst_group
= RTNLGRP_TC
;
891 err
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
, flags
&NLM_F_ECHO
);
904 tcf_action_add(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int ovr
)
907 struct tc_action
*act
;
909 u32 seq
= n
->nlmsg_seq
;
911 act
= tcf_action_init(rta
, NULL
, NULL
, ovr
, 0, &ret
);
915 /* dump then free all the actions after update; inserted policy
918 ret
= tcf_add_notify(act
, pid
, seq
, RTM_NEWACTION
, n
->nlmsg_flags
);
919 for (a
= act
; a
; a
= act
) {
927 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
929 struct net
*net
= skb
->sk
->sk_net
;
930 struct rtattr
**tca
= arg
;
931 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
932 int ret
= 0, ovr
= 0;
934 if (net
!= &init_net
)
937 if (tca
[TCA_ACT_TAB
-1] == NULL
) {
938 printk("tc_ctl_action: received NO action attribs\n");
942 /* n->nlmsg_flags&NLM_F_CREATE
944 switch (n
->nlmsg_type
) {
946 /* we are going to assume all other flags
947 * imply create only if it doesnt exist
948 * Note that CREATE | EXCL implies that
949 * but since we want avoid ambiguity (eg when flags
950 * is zero) then just set this
952 if (n
->nlmsg_flags
&NLM_F_REPLACE
)
955 ret
= tcf_action_add(tca
[TCA_ACT_TAB
-1], n
, pid
, ovr
);
960 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_DELACTION
);
963 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_GETACTION
);
972 static struct rtattr
*
973 find_dump_kind(struct nlmsghdr
*n
)
975 struct rtattr
*tb1
, *tb2
[TCA_ACT_MAX
+1];
976 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
977 struct rtattr
*rta
[TCAA_MAX
+ 1];
979 int min_len
= NLMSG_LENGTH(sizeof(struct tcamsg
));
980 int attrlen
= n
->nlmsg_len
- NLMSG_ALIGN(min_len
);
981 struct rtattr
*attr
= (void *) n
+ NLMSG_ALIGN(min_len
);
983 if (rtattr_parse(rta
, TCAA_MAX
, attr
, attrlen
) < 0)
985 tb1
= rta
[TCA_ACT_TAB
- 1];
989 if (rtattr_parse(tb
, TCA_ACT_MAX_PRIO
, RTA_DATA(tb1
),
990 NLMSG_ALIGN(RTA_PAYLOAD(tb1
))) < 0)
995 if (rtattr_parse(tb2
, TCA_ACT_MAX
, RTA_DATA(tb
[0]),
996 RTA_PAYLOAD(tb
[0])) < 0)
998 kind
= tb2
[TCA_ACT_KIND
-1];
1004 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1006 struct net
*net
= skb
->sk
->sk_net
;
1007 struct nlmsghdr
*nlh
;
1008 unsigned char *b
= skb_tail_pointer(skb
);
1010 struct tc_action_ops
*a_o
;
1013 struct tcamsg
*t
= (struct tcamsg
*) NLMSG_DATA(cb
->nlh
);
1014 struct rtattr
*kind
= find_dump_kind(cb
->nlh
);
1016 if (net
!= &init_net
)
1020 printk("tc_dump_action: action bad kind\n");
1024 a_o
= tc_lookup_action(kind
);
1029 memset(&a
, 0, sizeof(struct tc_action
));
1032 if (a_o
->walk
== NULL
) {
1033 printk("tc_dump_action: %s !capable of dumping table\n", a_o
->kind
);
1034 goto rtattr_failure
;
1037 nlh
= NLMSG_PUT(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
,
1038 cb
->nlh
->nlmsg_type
, sizeof(*t
));
1039 t
= NLMSG_DATA(nlh
);
1040 t
->tca_family
= AF_UNSPEC
;
1044 x
= (struct rtattr
*)skb_tail_pointer(skb
);
1045 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
1047 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1049 goto rtattr_failure
;
1052 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
1057 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1058 if (NETLINK_CB(cb
->skb
).pid
&& ret
)
1059 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1060 module_put(a_o
->owner
);
1065 module_put(a_o
->owner
);
1070 static int __init
tc_action_init(void)
1072 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
);
1073 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
);
1074 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
);
1079 subsys_initcall(tc_action_init
);
1081 EXPORT_SYMBOL(tcf_register_action
);
1082 EXPORT_SYMBOL(tcf_unregister_action
);
1083 EXPORT_SYMBOL(tcf_action_exec
);
1084 EXPORT_SYMBOL(tcf_action_dump_1
);