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/slab.h>
19 #include <linux/skbuff.h>
20 #include <linux/init.h>
21 #include <linux/kmod.h>
22 #include <linux/err.h>
23 #include <linux/module.h>
24 #include <net/net_namespace.h>
26 #include <net/sch_generic.h>
27 #include <net/act_api.h>
28 #include <net/netlink.h>
30 void tcf_hash_destroy(struct tc_action
*a
)
32 struct tcf_common
*p
= a
->priv
;
33 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
35 spin_lock_bh(&hinfo
->lock
);
36 hlist_del(&p
->tcfc_head
);
37 spin_unlock_bh(&hinfo
->lock
);
38 gen_kill_estimator(&p
->tcfc_bstats
,
41 * gen_estimator est_timer() might access p->tcfc_lock
42 * or bstats, wait a RCU grace period before freeing p
44 kfree_rcu(p
, tcfc_rcu
);
46 EXPORT_SYMBOL(tcf_hash_destroy
);
48 int __tcf_hash_release(struct tc_action
*a
, bool bind
, bool strict
)
50 struct tcf_common
*p
= a
->priv
;
56 else if (strict
&& p
->tcfc_bindcnt
> 0)
60 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
62 a
->ops
->cleanup(a
, bind
);
70 EXPORT_SYMBOL(__tcf_hash_release
);
72 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
75 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
76 struct hlist_head
*head
;
78 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
81 spin_lock_bh(&hinfo
->lock
);
85 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
86 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
88 hlist_for_each_entry_rcu(p
, head
, tcfc_head
) {
95 nest
= nla_nest_start(skb
, a
->order
);
98 err
= tcf_action_dump_1(skb
, a
, 0, 0);
101 nlmsg_trim(skb
, nest
);
104 nla_nest_end(skb
, nest
);
106 if (n_i
>= TCA_ACT_MAX_PRIO
)
111 spin_unlock_bh(&hinfo
->lock
);
117 nla_nest_cancel(skb
, nest
);
121 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
)
123 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
124 struct hlist_head
*head
;
125 struct hlist_node
*n
;
126 struct tcf_common
*p
;
131 nest
= nla_nest_start(skb
, a
->order
);
133 goto nla_put_failure
;
134 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
135 goto nla_put_failure
;
136 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
137 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
138 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
140 ret
= __tcf_hash_release(a
, false, true);
141 if (ret
== ACT_P_DELETED
) {
142 module_put(a
->ops
->owner
);
145 goto nla_put_failure
;
148 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
149 goto nla_put_failure
;
150 nla_nest_end(skb
, nest
);
154 nla_nest_cancel(skb
, nest
);
158 static int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
159 int type
, struct tc_action
*a
)
161 if (type
== RTM_DELACTION
) {
162 return tcf_del_walker(skb
, a
);
163 } else if (type
== RTM_GETACTION
) {
164 return tcf_dump_walker(skb
, cb
, a
);
166 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
171 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
173 struct tcf_common
*p
= NULL
;
174 struct hlist_head
*head
;
176 spin_lock_bh(&hinfo
->lock
);
177 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
178 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
179 if (p
->tcfc_index
== index
)
181 spin_unlock_bh(&hinfo
->lock
);
186 u32
tcf_hash_new_index(struct tcf_hashinfo
*hinfo
)
188 u32 val
= hinfo
->index
;
193 } while (tcf_hash_lookup(val
, hinfo
));
198 EXPORT_SYMBOL(tcf_hash_new_index
);
200 int tcf_hash_search(struct tc_action
*a
, u32 index
)
202 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
203 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
211 EXPORT_SYMBOL(tcf_hash_search
);
213 int tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
)
215 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
216 struct tcf_common
*p
= NULL
;
217 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
226 EXPORT_SYMBOL(tcf_hash_check
);
228 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
230 struct tcf_common
*pc
= a
->priv
;
232 gen_kill_estimator(&pc
->tcfc_bstats
,
234 kfree_rcu(pc
, tcfc_rcu
);
236 EXPORT_SYMBOL(tcf_hash_cleanup
);
238 int tcf_hash_create(u32 index
, struct nlattr
*est
, struct tc_action
*a
,
241 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
242 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
250 spin_lock_init(&p
->tcfc_lock
);
251 INIT_HLIST_NODE(&p
->tcfc_head
);
252 p
->tcfc_index
= index
? index
: tcf_hash_new_index(hinfo
);
253 p
->tcfc_tm
.install
= jiffies
;
254 p
->tcfc_tm
.lastuse
= jiffies
;
256 int err
= gen_new_estimator(&p
->tcfc_bstats
, NULL
,
265 a
->priv
= (void *) p
;
268 EXPORT_SYMBOL(tcf_hash_create
);
270 void tcf_hash_insert(struct tc_action
*a
)
272 struct tcf_common
*p
= a
->priv
;
273 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
274 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
276 spin_lock_bh(&hinfo
->lock
);
277 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
278 spin_unlock_bh(&hinfo
->lock
);
280 EXPORT_SYMBOL(tcf_hash_insert
);
282 static LIST_HEAD(act_base
);
283 static DEFINE_RWLOCK(act_mod_lock
);
285 int tcf_register_action(struct tc_action_ops
*act
, unsigned int mask
)
287 struct tc_action_ops
*a
;
290 /* Must supply act, dump and init */
291 if (!act
->act
|| !act
->dump
|| !act
->init
)
294 /* Supply defaults */
296 act
->lookup
= tcf_hash_search
;
298 act
->walk
= tcf_generic_walker
;
300 act
->hinfo
= kmalloc(sizeof(struct tcf_hashinfo
), GFP_KERNEL
);
303 err
= tcf_hashinfo_init(act
->hinfo
, mask
);
309 write_lock(&act_mod_lock
);
310 list_for_each_entry(a
, &act_base
, head
) {
311 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
312 write_unlock(&act_mod_lock
);
313 tcf_hashinfo_destroy(act
->hinfo
);
318 list_add_tail(&act
->head
, &act_base
);
319 write_unlock(&act_mod_lock
);
322 EXPORT_SYMBOL(tcf_register_action
);
324 int tcf_unregister_action(struct tc_action_ops
*act
)
326 struct tc_action_ops
*a
;
329 write_lock(&act_mod_lock
);
330 list_for_each_entry(a
, &act_base
, head
) {
332 list_del(&act
->head
);
333 tcf_hashinfo_destroy(act
->hinfo
);
339 write_unlock(&act_mod_lock
);
342 EXPORT_SYMBOL(tcf_unregister_action
);
345 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
347 struct tc_action_ops
*a
, *res
= NULL
;
350 read_lock(&act_mod_lock
);
351 list_for_each_entry(a
, &act_base
, head
) {
352 if (strcmp(kind
, a
->kind
) == 0) {
353 if (try_module_get(a
->owner
))
358 read_unlock(&act_mod_lock
);
363 /* lookup by nlattr */
364 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
366 struct tc_action_ops
*a
, *res
= NULL
;
369 read_lock(&act_mod_lock
);
370 list_for_each_entry(a
, &act_base
, head
) {
371 if (nla_strcmp(kind
, a
->kind
) == 0) {
372 if (try_module_get(a
->owner
))
377 read_unlock(&act_mod_lock
);
382 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
383 struct tcf_result
*res
)
385 const struct tc_action
*a
;
388 if (skb
->tc_verd
& TC_NCLS
) {
389 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
393 list_for_each_entry(a
, actions
, list
) {
395 ret
= a
->ops
->act(skb
, a
, res
);
396 if (ret
== TC_ACT_REPEAT
)
397 goto repeat
; /* we need a ttl - JHS */
398 if (ret
!= TC_ACT_PIPE
)
404 EXPORT_SYMBOL(tcf_action_exec
);
406 int tcf_action_destroy(struct list_head
*actions
, int bind
)
408 struct tc_action
*a
, *tmp
;
411 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
412 ret
= __tcf_hash_release(a
, bind
, true);
413 if (ret
== ACT_P_DELETED
)
414 module_put(a
->ops
->owner
);
424 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
426 return a
->ops
->dump(skb
, a
, bind
, ref
);
430 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
433 unsigned char *b
= skb_tail_pointer(skb
);
436 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
437 goto nla_put_failure
;
438 if (tcf_action_copy_stats(skb
, a
, 0))
439 goto nla_put_failure
;
440 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
442 goto nla_put_failure
;
443 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
445 nla_nest_end(skb
, nest
);
453 EXPORT_SYMBOL(tcf_action_dump_1
);
456 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
462 list_for_each_entry(a
, actions
, list
) {
463 nest
= nla_nest_start(skb
, a
->order
);
465 goto nla_put_failure
;
466 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
469 nla_nest_end(skb
, nest
);
477 nla_nest_cancel(skb
, nest
);
481 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
482 struct nlattr
*est
, char *name
, int ovr
,
486 struct tc_action_ops
*a_o
;
487 char act_name
[IFNAMSIZ
];
488 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
493 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
497 kind
= tb
[TCA_ACT_KIND
];
500 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
504 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
508 a_o
= tc_lookup_action_n(act_name
);
510 #ifdef CONFIG_MODULES
512 request_module("act_%s", act_name
);
515 a_o
= tc_lookup_action_n(act_name
);
517 /* We dropped the RTNL semaphore in order to
518 * perform the module load. So, even if we
519 * succeeded in loading the module we have to
520 * tell the caller to replay the request. We
521 * indicate this using -EAGAIN.
533 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
538 INIT_LIST_HEAD(&a
->list
);
539 /* backward compatibility for policer */
541 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
543 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
547 /* module count goes up only when brand new policy is created
548 * if it exists and is only bound to in a_o->init() then
549 * ACT_P_CREATED is not returned (a zero is).
551 if (err
!= ACT_P_CREATED
)
552 module_put(a_o
->owner
);
559 module_put(a_o
->owner
);
564 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
565 struct nlattr
*est
, char *name
, int ovr
,
566 int bind
, struct list_head
*actions
)
568 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
569 struct tc_action
*act
;
573 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
577 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
578 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
584 list_add_tail(&act
->list
, actions
);
589 tcf_action_destroy(actions
, bind
);
593 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
598 struct tcf_common
*p
= a
->priv
;
603 /* compat_mode being true specifies a call that is supposed
604 * to add additional backward compatibility statistic TLVs.
607 if (a
->type
== TCA_OLD_COMPAT
)
608 err
= gnet_stats_start_copy_compat(skb
, 0,
609 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
613 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
619 if (gnet_stats_copy_basic(&d
, NULL
, &p
->tcfc_bstats
) < 0 ||
620 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
621 &p
->tcfc_rate_est
) < 0 ||
622 gnet_stats_copy_queue(&d
, NULL
,
624 p
->tcfc_qstats
.qlen
) < 0)
627 if (gnet_stats_finish_copy(&d
) < 0)
637 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
638 u16 flags
, int event
, int bind
, int ref
)
641 struct nlmsghdr
*nlh
;
642 unsigned char *b
= skb_tail_pointer(skb
);
645 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
649 t
->tca_family
= AF_UNSPEC
;
653 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
657 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
660 nla_nest_end(skb
, nest
);
662 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
671 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
672 struct list_head
*actions
, int event
)
676 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
679 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
684 return rtnl_unicast(skb
, net
, portid
);
687 static struct tc_action
*create_a(int i
)
689 struct tc_action
*act
;
691 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
693 pr_debug("create_a: failed to alloc!\n");
697 INIT_LIST_HEAD(&act
->list
);
701 static struct tc_action
*
702 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
704 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
709 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
714 if (tb
[TCA_ACT_INDEX
] == NULL
||
715 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
717 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
725 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
726 if (a
->ops
== NULL
) /* could happen in batch of actions */
729 if (a
->ops
->lookup(a
, index
) == 0)
732 module_put(a
->ops
->owner
);
736 module_put(a
->ops
->owner
);
743 static void cleanup_a(struct list_head
*actions
)
745 struct tc_action
*a
, *tmp
;
747 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
753 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
754 struct nlmsghdr
*n
, u32 portid
)
758 struct nlmsghdr
*nlh
;
760 struct netlink_callback dcb
;
762 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
767 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
769 pr_debug("tca_action_flush: failed skb alloc\n");
773 b
= skb_tail_pointer(skb
);
775 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
780 kind
= tb
[TCA_ACT_KIND
];
781 memset(&a
, 0, sizeof(struct tc_action
));
782 INIT_LIST_HEAD(&a
.list
);
783 a
.ops
= tc_lookup_action(kind
);
784 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
787 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
791 t
->tca_family
= AF_UNSPEC
;
795 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
799 err
= a
.ops
->walk(skb
, &dcb
, RTM_DELACTION
, &a
);
805 nla_nest_end(skb
, nest
);
807 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
808 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
809 module_put(a
.ops
->owner
);
810 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
811 n
->nlmsg_flags
& NLM_F_ECHO
);
818 module_put(a
.ops
->owner
);
826 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
832 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
836 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
842 /* now do the delete */
843 ret
= tcf_action_destroy(actions
, 0);
849 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
850 n
->nlmsg_flags
& NLM_F_ECHO
);
857 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
858 u32 portid
, int event
)
861 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
862 struct tc_action
*act
;
865 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
869 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
871 return tca_action_flush(net
, tb
[1], n
, portid
);
876 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
877 act
= tcf_action_get_1(tb
[i
], n
, portid
);
883 list_add_tail(&act
->list
, &actions
);
886 if (event
== RTM_GETACTION
)
887 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
889 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
900 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
906 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
910 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
911 RTM_NEWACTION
, 0, 0) <= 0) {
916 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
917 n
->nlmsg_flags
& NLM_F_ECHO
);
924 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
930 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
934 /* dump then free all the actions after update; inserted policy
937 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
943 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
945 struct net
*net
= sock_net(skb
->sk
);
946 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
947 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
948 int ret
= 0, ovr
= 0;
950 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
953 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
957 if (tca
[TCA_ACT_TAB
] == NULL
) {
958 pr_notice("tc_ctl_action: received NO action attribs\n");
962 /* n->nlmsg_flags & NLM_F_CREATE */
963 switch (n
->nlmsg_type
) {
965 /* we are going to assume all other flags
966 * imply create only if it doesn't exist
967 * Note that CREATE | EXCL implies that
968 * but since we want avoid ambiguity (eg when flags
969 * is zero) then just set this
971 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
974 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
979 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
980 portid
, RTM_DELACTION
);
983 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
984 portid
, RTM_GETACTION
);
993 static struct nlattr
*
994 find_dump_kind(const struct nlmsghdr
*n
)
996 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
997 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
998 struct nlattr
*nla
[TCAA_MAX
+ 1];
1001 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1003 tb1
= nla
[TCA_ACT_TAB
];
1007 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1008 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1013 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1014 nla_len(tb
[1]), NULL
) < 0)
1016 kind
= tb2
[TCA_ACT_KIND
];
1022 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1024 struct nlmsghdr
*nlh
;
1025 unsigned char *b
= skb_tail_pointer(skb
);
1026 struct nlattr
*nest
;
1027 struct tc_action_ops
*a_o
;
1030 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1031 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1034 pr_info("tc_dump_action: action bad kind\n");
1038 a_o
= tc_lookup_action(kind
);
1042 memset(&a
, 0, sizeof(struct tc_action
));
1045 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1046 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1048 goto out_module_put
;
1049 t
= nlmsg_data(nlh
);
1050 t
->tca_family
= AF_UNSPEC
;
1054 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1056 goto out_module_put
;
1058 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1060 goto out_module_put
;
1063 nla_nest_end(skb
, nest
);
1066 nla_nest_cancel(skb
, nest
);
1068 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1069 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1070 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1071 module_put(a_o
->owner
);
1075 module_put(a_o
->owner
);
1080 static int __init
tc_action_init(void)
1082 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1083 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1084 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1090 subsys_initcall(tc_action_init
);