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/sch_generic.h>
22 #include <net/act_api.h>
23 #include <net/netlink.h>
25 void tcf_hash_destroy(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
27 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
28 struct tcf_common
**p1p
;
30 for (p1p
= &hinfo
->htab
[h
]; *p1p
; p1p
= &(*p1p
)->tcfc_next
) {
32 write_lock_bh(hinfo
->lock
);
34 write_unlock_bh(hinfo
->lock
);
35 gen_kill_estimator(&p
->tcfc_bstats
,
43 EXPORT_SYMBOL(tcf_hash_destroy
);
45 int tcf_hash_release(struct tcf_common
*p
, int bind
,
46 struct tcf_hashinfo
*hinfo
)
55 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
56 tcf_hash_destroy(p
, hinfo
);
62 EXPORT_SYMBOL(tcf_hash_release
);
64 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
65 struct tc_action
*a
, struct tcf_hashinfo
*hinfo
)
68 int err
= 0, index
= -1,i
= 0, s_i
= 0, n_i
= 0;
71 read_lock_bh(hinfo
->lock
);
75 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
76 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
78 for (; p
; p
= p
->tcfc_next
) {
84 r
= (struct rtattr
*)skb_tail_pointer(skb
);
85 RTA_PUT(skb
, a
->order
, 0, NULL
);
86 err
= tcf_action_dump_1(skb
, a
, 0, 0);
92 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
94 if (n_i
>= TCA_ACT_MAX_PRIO
)
99 read_unlock_bh(hinfo
->lock
);
109 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
,
110 struct tcf_hashinfo
*hinfo
)
112 struct tcf_common
*p
, *s_p
;
116 r
= (struct rtattr
*)skb_tail_pointer(skb
);
117 RTA_PUT(skb
, a
->order
, 0, NULL
);
118 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
119 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
120 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
124 if (ACT_P_DELETED
== tcf_hash_release(p
, 0, hinfo
))
125 module_put(a
->ops
->owner
);
130 RTA_PUT(skb
, TCA_FCNT
, 4, &n_i
);
131 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
139 int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
140 int type
, struct tc_action
*a
)
142 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
144 if (type
== RTM_DELACTION
) {
145 return tcf_del_walker(skb
, a
, hinfo
);
146 } else if (type
== RTM_GETACTION
) {
147 return tcf_dump_walker(skb
, cb
, a
, hinfo
);
149 printk("tcf_generic_walker: unknown action %d\n", type
);
153 EXPORT_SYMBOL(tcf_generic_walker
);
155 struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
157 struct tcf_common
*p
;
159 read_lock_bh(hinfo
->lock
);
160 for (p
= hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)]; p
;
162 if (p
->tcfc_index
== index
)
165 read_unlock_bh(hinfo
->lock
);
169 EXPORT_SYMBOL(tcf_hash_lookup
);
171 u32
tcf_hash_new_index(u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
178 } while (tcf_hash_lookup(val
, hinfo
));
180 return (*idx_gen
= val
);
182 EXPORT_SYMBOL(tcf_hash_new_index
);
184 int tcf_hash_search(struct tc_action
*a
, u32 index
)
186 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
187 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
195 EXPORT_SYMBOL(tcf_hash_search
);
197 struct tcf_common
*tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
,
198 struct tcf_hashinfo
*hinfo
)
200 struct tcf_common
*p
= NULL
;
201 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
210 EXPORT_SYMBOL(tcf_hash_check
);
212 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
)
214 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
222 spin_lock_init(&p
->tcfc_lock
);
223 p
->tcfc_index
= index
? index
: tcf_hash_new_index(idx_gen
, hinfo
);
224 p
->tcfc_tm
.install
= jiffies
;
225 p
->tcfc_tm
.lastuse
= jiffies
;
227 gen_new_estimator(&p
->tcfc_bstats
, &p
->tcfc_rate_est
,
229 a
->priv
= (void *) p
;
232 EXPORT_SYMBOL(tcf_hash_create
);
234 void tcf_hash_insert(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
236 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
238 write_lock_bh(hinfo
->lock
);
239 p
->tcfc_next
= hinfo
->htab
[h
];
241 write_unlock_bh(hinfo
->lock
);
243 EXPORT_SYMBOL(tcf_hash_insert
);
245 static struct tc_action_ops
*act_base
= NULL
;
246 static DEFINE_RWLOCK(act_mod_lock
);
248 int tcf_register_action(struct tc_action_ops
*act
)
250 struct tc_action_ops
*a
, **ap
;
252 write_lock(&act_mod_lock
);
253 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
) {
254 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
255 write_unlock(&act_mod_lock
);
261 write_unlock(&act_mod_lock
);
265 int tcf_unregister_action(struct tc_action_ops
*act
)
267 struct tc_action_ops
*a
, **ap
;
270 write_lock(&act_mod_lock
);
271 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
)
279 write_unlock(&act_mod_lock
);
284 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
286 struct tc_action_ops
*a
= NULL
;
289 read_lock(&act_mod_lock
);
290 for (a
= act_base
; a
; a
= a
->next
) {
291 if (strcmp(kind
, a
->kind
) == 0) {
292 if (!try_module_get(a
->owner
)) {
293 read_unlock(&act_mod_lock
);
299 read_unlock(&act_mod_lock
);
304 /* lookup by rtattr */
305 static struct tc_action_ops
*tc_lookup_action(struct rtattr
*kind
)
307 struct tc_action_ops
*a
= NULL
;
310 read_lock(&act_mod_lock
);
311 for (a
= act_base
; a
; a
= a
->next
) {
312 if (rtattr_strcmp(kind
, a
->kind
) == 0) {
313 if (!try_module_get(a
->owner
)) {
314 read_unlock(&act_mod_lock
);
320 read_unlock(&act_mod_lock
);
327 static struct tc_action_ops
*tc_lookup_action_id(u32 type
)
329 struct tc_action_ops
*a
= NULL
;
332 read_lock(&act_mod_lock
);
333 for (a
= act_base
; a
; a
= a
->next
) {
334 if (a
->type
== type
) {
335 if (!try_module_get(a
->owner
)) {
336 read_unlock(&act_mod_lock
);
342 read_unlock(&act_mod_lock
);
348 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
*act
,
349 struct tcf_result
*res
)
354 if (skb
->tc_verd
& TC_NCLS
) {
355 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
359 while ((a
= act
) != NULL
) {
361 if (a
->ops
&& a
->ops
->act
) {
362 ret
= a
->ops
->act(skb
, a
, res
);
363 if (TC_MUNGED
& skb
->tc_verd
) {
364 /* copied already, allow trampling */
365 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
366 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
368 if (ret
== TC_ACT_REPEAT
)
369 goto repeat
; /* we need a ttl - JHS */
370 if (ret
!= TC_ACT_PIPE
)
379 void tcf_action_destroy(struct tc_action
*act
, int bind
)
383 for (a
= act
; a
; a
= act
) {
384 if (a
->ops
&& a
->ops
->cleanup
) {
385 if (a
->ops
->cleanup(a
, bind
) == ACT_P_DELETED
)
386 module_put(a
->ops
->owner
);
389 } else { /*FIXME: Remove later - catch insertion bugs*/
390 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
398 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
402 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
404 return a
->ops
->dump(skb
, a
, bind
, ref
);
408 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
411 unsigned char *b
= skb_tail_pointer(skb
);
414 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
417 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
418 if (tcf_action_copy_stats(skb
, a
, 0))
420 r
= (struct rtattr
*)skb_tail_pointer(skb
);
421 RTA_PUT(skb
, TCA_OPTIONS
, 0, NULL
);
422 if ((err
= tcf_action_dump_old(skb
, a
, bind
, ref
)) > 0) {
423 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
433 tcf_action_dump(struct sk_buff
*skb
, struct tc_action
*act
, int bind
, int ref
)
437 unsigned char *b
= skb_tail_pointer(skb
);
440 while ((a
= act
) != NULL
) {
441 r
= (struct rtattr
*)skb_tail_pointer(skb
);
443 RTA_PUT(skb
, a
->order
, 0, NULL
);
444 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
447 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
459 struct tc_action
*tcf_action_init_1(struct rtattr
*rta
, struct rtattr
*est
,
460 char *name
, int ovr
, int bind
, int *err
)
463 struct tc_action_ops
*a_o
;
464 char act_name
[IFNAMSIZ
];
465 struct rtattr
*tb
[TCA_ACT_MAX
+1];
471 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
473 kind
= tb
[TCA_ACT_KIND
-1];
476 if (rtattr_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
479 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
483 a_o
= tc_lookup_action_n(act_name
);
487 request_module("act_%s", act_name
);
490 a_o
= tc_lookup_action_n(act_name
);
492 /* We dropped the RTNL semaphore in order to
493 * perform the module load. So, even if we
494 * succeeded in loading the module we have to
495 * tell the caller to replay the request. We
496 * indicate this using -EAGAIN.
508 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
512 /* backward compatibility for policer */
514 *err
= a_o
->init(tb
[TCA_ACT_OPTIONS
-1], est
, a
, ovr
, bind
);
516 *err
= a_o
->init(rta
, est
, a
, ovr
, bind
);
520 /* module count goes up only when brand new policy is created
521 if it exists and is only bound to in a_o->init() then
522 ACT_P_CREATED is not returned (a zero is).
524 if (*err
!= ACT_P_CREATED
)
525 module_put(a_o
->owner
);
534 module_put(a_o
->owner
);
539 struct tc_action
*tcf_action_init(struct rtattr
*rta
, struct rtattr
*est
,
540 char *name
, int ovr
, int bind
, int *err
)
542 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
543 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
546 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0) {
551 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
552 act
= tcf_action_init_1(tb
[i
], est
, name
, ovr
, bind
, err
);
560 act_prev
->next
= act
;
567 tcf_action_destroy(head
, bind
);
571 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
576 struct tcf_act_hdr
*h
= a
->priv
;
581 /* compat_mode being true specifies a call that is supposed
582 * to add additional backward compatiblity statistic TLVs.
585 if (a
->type
== TCA_OLD_COMPAT
)
586 err
= gnet_stats_start_copy_compat(skb
, 0,
587 TCA_STATS
, TCA_XSTATS
, &h
->tcf_lock
, &d
);
591 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
597 if (a
->ops
!= NULL
&& a
->ops
->get_stats
!= NULL
)
598 if (a
->ops
->get_stats(skb
, a
) < 0)
601 if (gnet_stats_copy_basic(&d
, &h
->tcf_bstats
) < 0 ||
602 gnet_stats_copy_rate_est(&d
, &h
->tcf_rate_est
) < 0 ||
603 gnet_stats_copy_queue(&d
, &h
->tcf_qstats
) < 0)
606 if (gnet_stats_finish_copy(&d
) < 0)
616 tca_get_fill(struct sk_buff
*skb
, struct tc_action
*a
, u32 pid
, u32 seq
,
617 u16 flags
, int event
, int bind
, int ref
)
620 struct nlmsghdr
*nlh
;
621 unsigned char *b
= skb_tail_pointer(skb
);
624 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
627 t
->tca_family
= AF_UNSPEC
;
631 x
= (struct rtattr
*)skb_tail_pointer(skb
);
632 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
634 if (tcf_action_dump(skb
, a
, bind
, ref
) < 0)
637 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
639 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
649 act_get_notify(u32 pid
, struct nlmsghdr
*n
, struct tc_action
*a
, int event
)
653 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
656 if (tca_get_fill(skb
, a
, pid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
661 return rtnl_unicast(skb
, pid
);
664 static struct tc_action
*
665 tcf_action_get_1(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int *err
)
667 struct rtattr
*tb
[TCA_ACT_MAX
+1];
672 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
675 if (tb
[TCA_ACT_INDEX
- 1] == NULL
||
676 RTA_PAYLOAD(tb
[TCA_ACT_INDEX
- 1]) < sizeof(index
))
678 index
= *(int *)RTA_DATA(tb
[TCA_ACT_INDEX
- 1]);
681 a
= kzalloc(sizeof(struct tc_action
), GFP_KERNEL
);
686 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
- 1]);
689 if (a
->ops
->lookup
== NULL
)
692 if (a
->ops
->lookup(a
, index
) == 0)
695 module_put(a
->ops
->owner
);
699 module_put(a
->ops
->owner
);
705 static void cleanup_a(struct tc_action
*act
)
709 for (a
= act
; a
; a
= act
) {
715 static struct tc_action
*create_a(int i
)
717 struct tc_action
*act
;
719 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
721 printk("create_a: failed to alloc!\n");
728 static int tca_action_flush(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
)
732 struct nlmsghdr
*nlh
;
734 struct netlink_callback dcb
;
736 struct rtattr
*tb
[TCA_ACT_MAX
+1];
738 struct tc_action
*a
= create_a(0);
742 printk("tca_action_flush: couldnt create tc_action\n");
746 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
748 printk("tca_action_flush: failed skb alloc\n");
753 b
= skb_tail_pointer(skb
);
755 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
758 kind
= tb
[TCA_ACT_KIND
-1];
759 a
->ops
= tc_lookup_action(kind
);
763 nlh
= NLMSG_PUT(skb
, pid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
));
765 t
->tca_family
= AF_UNSPEC
;
769 x
= (struct rtattr
*)skb_tail_pointer(skb
);
770 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
772 err
= a
->ops
->walk(skb
, &dcb
, RTM_DELACTION
, a
);
776 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
778 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
779 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
780 module_put(a
->ops
->owner
);
782 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
790 module_put(a
->ops
->owner
);
798 tca_action_gd(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int event
)
801 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
802 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
804 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0)
807 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
&NLM_F_ROOT
) {
808 if (tb
[0] != NULL
&& tb
[1] == NULL
)
809 return tca_action_flush(tb
[0], n
, pid
);
812 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
813 act
= tcf_action_get_1(tb
[i
], n
, pid
, &ret
);
821 act_prev
->next
= act
;
825 if (event
== RTM_GETACTION
)
826 ret
= act_get_notify(pid
, n
, head
, event
);
830 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
836 if (tca_get_fill(skb
, head
, pid
, n
->nlmsg_seq
, 0, event
,
843 /* now do the delete */
844 tcf_action_destroy(head
, 0);
845 ret
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
,
846 n
->nlmsg_flags
&NLM_F_ECHO
);
856 static int tcf_add_notify(struct tc_action
*a
, u32 pid
, u32 seq
, int event
,
860 struct nlmsghdr
*nlh
;
866 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
870 b
= skb_tail_pointer(skb
);
872 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
874 t
->tca_family
= AF_UNSPEC
;
878 x
= (struct rtattr
*)skb_tail_pointer(skb
);
879 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
881 if (tcf_action_dump(skb
, a
, 0, 0) < 0)
884 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
886 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
887 NETLINK_CB(skb
).dst_group
= RTNLGRP_TC
;
889 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, flags
&NLM_F_ECHO
);
902 tcf_action_add(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int ovr
)
905 struct tc_action
*act
;
907 u32 seq
= n
->nlmsg_seq
;
909 act
= tcf_action_init(rta
, NULL
, NULL
, ovr
, 0, &ret
);
913 /* dump then free all the actions after update; inserted policy
916 ret
= tcf_add_notify(act
, pid
, seq
, RTM_NEWACTION
, n
->nlmsg_flags
);
917 for (a
= act
; a
; a
= act
) {
925 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
927 struct rtattr
**tca
= arg
;
928 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
929 int ret
= 0, ovr
= 0;
931 if (tca
[TCA_ACT_TAB
-1] == NULL
) {
932 printk("tc_ctl_action: received NO action attribs\n");
936 /* n->nlmsg_flags&NLM_F_CREATE
938 switch (n
->nlmsg_type
) {
940 /* we are going to assume all other flags
941 * imply create only if it doesnt exist
942 * Note that CREATE | EXCL implies that
943 * but since we want avoid ambiguity (eg when flags
944 * is zero) then just set this
946 if (n
->nlmsg_flags
&NLM_F_REPLACE
)
949 ret
= tcf_action_add(tca
[TCA_ACT_TAB
-1], n
, pid
, ovr
);
954 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_DELACTION
);
957 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_GETACTION
);
966 static struct rtattr
*
967 find_dump_kind(struct nlmsghdr
*n
)
969 struct rtattr
*tb1
, *tb2
[TCA_ACT_MAX
+1];
970 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
971 struct rtattr
*rta
[TCAA_MAX
+ 1];
973 int min_len
= NLMSG_LENGTH(sizeof(struct tcamsg
));
974 int attrlen
= n
->nlmsg_len
- NLMSG_ALIGN(min_len
);
975 struct rtattr
*attr
= (void *) n
+ NLMSG_ALIGN(min_len
);
977 if (rtattr_parse(rta
, TCAA_MAX
, attr
, attrlen
) < 0)
979 tb1
= rta
[TCA_ACT_TAB
- 1];
983 if (rtattr_parse(tb
, TCA_ACT_MAX_PRIO
, RTA_DATA(tb1
),
984 NLMSG_ALIGN(RTA_PAYLOAD(tb1
))) < 0)
989 if (rtattr_parse(tb2
, TCA_ACT_MAX
, RTA_DATA(tb
[0]),
990 RTA_PAYLOAD(tb
[0])) < 0)
992 kind
= tb2
[TCA_ACT_KIND
-1];
998 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1000 struct nlmsghdr
*nlh
;
1001 unsigned char *b
= skb_tail_pointer(skb
);
1003 struct tc_action_ops
*a_o
;
1006 struct tcamsg
*t
= (struct tcamsg
*) NLMSG_DATA(cb
->nlh
);
1007 struct rtattr
*kind
= find_dump_kind(cb
->nlh
);
1010 printk("tc_dump_action: action bad kind\n");
1014 a_o
= tc_lookup_action(kind
);
1019 memset(&a
, 0, sizeof(struct tc_action
));
1022 if (a_o
->walk
== NULL
) {
1023 printk("tc_dump_action: %s !capable of dumping table\n", a_o
->kind
);
1024 goto rtattr_failure
;
1027 nlh
= NLMSG_PUT(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
,
1028 cb
->nlh
->nlmsg_type
, sizeof(*t
));
1029 t
= NLMSG_DATA(nlh
);
1030 t
->tca_family
= AF_UNSPEC
;
1034 x
= (struct rtattr
*)skb_tail_pointer(skb
);
1035 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
1037 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1039 goto rtattr_failure
;
1042 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
1047 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1048 if (NETLINK_CB(cb
->skb
).pid
&& ret
)
1049 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1050 module_put(a_o
->owner
);
1055 module_put(a_o
->owner
);
1060 static int __init
tc_action_init(void)
1062 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
);
1063 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
);
1064 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
);
1069 subsys_initcall(tc_action_init
);
1071 EXPORT_SYMBOL(tcf_register_action
);
1072 EXPORT_SYMBOL(tcf_unregister_action
);
1073 EXPORT_SYMBOL(tcf_action_exec
);
1074 EXPORT_SYMBOL(tcf_action_dump_1
);