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
, int bind
)
50 struct tcf_common
*p
= a
->priv
;
56 else if (p
->tcfc_bindcnt
> 0)
60 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
62 a
->ops
->cleanup(a
, bind
);
69 EXPORT_SYMBOL(tcf_hash_release
);
71 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
74 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
75 struct hlist_head
*head
;
77 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
80 spin_lock_bh(&hinfo
->lock
);
84 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
85 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
87 hlist_for_each_entry_rcu(p
, head
, tcfc_head
) {
94 nest
= nla_nest_start(skb
, a
->order
);
97 err
= tcf_action_dump_1(skb
, a
, 0, 0);
100 nlmsg_trim(skb
, nest
);
103 nla_nest_end(skb
, nest
);
105 if (n_i
>= TCA_ACT_MAX_PRIO
)
110 spin_unlock_bh(&hinfo
->lock
);
116 nla_nest_cancel(skb
, nest
);
120 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
)
122 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
123 struct hlist_head
*head
;
124 struct hlist_node
*n
;
125 struct tcf_common
*p
;
130 nest
= nla_nest_start(skb
, a
->order
);
132 goto nla_put_failure
;
133 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
134 goto nla_put_failure
;
135 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
136 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
137 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
139 ret
= tcf_hash_release(a
, 0);
140 if (ret
== ACT_P_DELETED
) {
141 module_put(a
->ops
->owner
);
144 goto nla_put_failure
;
147 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
148 goto nla_put_failure
;
149 nla_nest_end(skb
, nest
);
153 nla_nest_cancel(skb
, nest
);
157 static int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
158 int type
, struct tc_action
*a
)
160 if (type
== RTM_DELACTION
) {
161 return tcf_del_walker(skb
, a
);
162 } else if (type
== RTM_GETACTION
) {
163 return tcf_dump_walker(skb
, cb
, a
);
165 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
170 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
172 struct tcf_common
*p
= NULL
;
173 struct hlist_head
*head
;
175 spin_lock_bh(&hinfo
->lock
);
176 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
177 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
178 if (p
->tcfc_index
== index
)
180 spin_unlock_bh(&hinfo
->lock
);
185 u32
tcf_hash_new_index(struct tcf_hashinfo
*hinfo
)
187 u32 val
= hinfo
->index
;
192 } while (tcf_hash_lookup(val
, hinfo
));
197 EXPORT_SYMBOL(tcf_hash_new_index
);
199 int tcf_hash_search(struct tc_action
*a
, u32 index
)
201 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
202 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
210 EXPORT_SYMBOL(tcf_hash_search
);
212 int tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
)
214 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
215 struct tcf_common
*p
= NULL
;
216 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
225 EXPORT_SYMBOL(tcf_hash_check
);
227 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
229 struct tcf_common
*pc
= a
->priv
;
231 gen_kill_estimator(&pc
->tcfc_bstats
,
233 kfree_rcu(pc
, tcfc_rcu
);
235 EXPORT_SYMBOL(tcf_hash_cleanup
);
237 int tcf_hash_create(u32 index
, struct nlattr
*est
, struct tc_action
*a
,
240 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
241 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
249 spin_lock_init(&p
->tcfc_lock
);
250 INIT_HLIST_NODE(&p
->tcfc_head
);
251 p
->tcfc_index
= index
? index
: tcf_hash_new_index(hinfo
);
252 p
->tcfc_tm
.install
= jiffies
;
253 p
->tcfc_tm
.lastuse
= jiffies
;
255 int err
= gen_new_estimator(&p
->tcfc_bstats
, NULL
,
264 a
->priv
= (void *) p
;
267 EXPORT_SYMBOL(tcf_hash_create
);
269 void tcf_hash_insert(struct tc_action
*a
)
271 struct tcf_common
*p
= a
->priv
;
272 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
273 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
275 spin_lock_bh(&hinfo
->lock
);
276 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
277 spin_unlock_bh(&hinfo
->lock
);
279 EXPORT_SYMBOL(tcf_hash_insert
);
281 static LIST_HEAD(act_base
);
282 static DEFINE_RWLOCK(act_mod_lock
);
284 int tcf_register_action(struct tc_action_ops
*act
, unsigned int mask
)
286 struct tc_action_ops
*a
;
289 /* Must supply act, dump and init */
290 if (!act
->act
|| !act
->dump
|| !act
->init
)
293 /* Supply defaults */
295 act
->lookup
= tcf_hash_search
;
297 act
->walk
= tcf_generic_walker
;
299 act
->hinfo
= kmalloc(sizeof(struct tcf_hashinfo
), GFP_KERNEL
);
302 err
= tcf_hashinfo_init(act
->hinfo
, mask
);
308 write_lock(&act_mod_lock
);
309 list_for_each_entry(a
, &act_base
, head
) {
310 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
311 write_unlock(&act_mod_lock
);
312 tcf_hashinfo_destroy(act
->hinfo
);
317 list_add_tail(&act
->head
, &act_base
);
318 write_unlock(&act_mod_lock
);
321 EXPORT_SYMBOL(tcf_register_action
);
323 int tcf_unregister_action(struct tc_action_ops
*act
)
325 struct tc_action_ops
*a
;
328 write_lock(&act_mod_lock
);
329 list_for_each_entry(a
, &act_base
, head
) {
331 list_del(&act
->head
);
332 tcf_hashinfo_destroy(act
->hinfo
);
338 write_unlock(&act_mod_lock
);
341 EXPORT_SYMBOL(tcf_unregister_action
);
344 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
346 struct tc_action_ops
*a
, *res
= NULL
;
349 read_lock(&act_mod_lock
);
350 list_for_each_entry(a
, &act_base
, head
) {
351 if (strcmp(kind
, a
->kind
) == 0) {
352 if (try_module_get(a
->owner
))
357 read_unlock(&act_mod_lock
);
362 /* lookup by nlattr */
363 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
365 struct tc_action_ops
*a
, *res
= NULL
;
368 read_lock(&act_mod_lock
);
369 list_for_each_entry(a
, &act_base
, head
) {
370 if (nla_strcmp(kind
, a
->kind
) == 0) {
371 if (try_module_get(a
->owner
))
376 read_unlock(&act_mod_lock
);
381 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
382 struct tcf_result
*res
)
384 const struct tc_action
*a
;
387 if (skb
->tc_verd
& TC_NCLS
) {
388 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
392 list_for_each_entry(a
, actions
, list
) {
394 ret
= a
->ops
->act(skb
, a
, res
);
395 if (TC_MUNGED
& skb
->tc_verd
) {
396 /* copied already, allow trampling */
397 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
398 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
400 if (ret
== TC_ACT_REPEAT
)
401 goto repeat
; /* we need a ttl - JHS */
402 if (ret
!= TC_ACT_PIPE
)
408 EXPORT_SYMBOL(tcf_action_exec
);
410 int tcf_action_destroy(struct list_head
*actions
, int bind
)
412 struct tc_action
*a
, *tmp
;
415 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
416 ret
= tcf_hash_release(a
, bind
);
417 if (ret
== ACT_P_DELETED
)
418 module_put(a
->ops
->owner
);
428 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
430 return a
->ops
->dump(skb
, a
, bind
, ref
);
434 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
437 unsigned char *b
= skb_tail_pointer(skb
);
440 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
441 goto nla_put_failure
;
442 if (tcf_action_copy_stats(skb
, a
, 0))
443 goto nla_put_failure
;
444 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
446 goto nla_put_failure
;
447 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
449 nla_nest_end(skb
, nest
);
457 EXPORT_SYMBOL(tcf_action_dump_1
);
460 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
466 list_for_each_entry(a
, actions
, list
) {
467 nest
= nla_nest_start(skb
, a
->order
);
469 goto nla_put_failure
;
470 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
473 nla_nest_end(skb
, nest
);
481 nla_nest_cancel(skb
, nest
);
485 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
486 struct nlattr
*est
, char *name
, int ovr
,
490 struct tc_action_ops
*a_o
;
491 char act_name
[IFNAMSIZ
];
492 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
497 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
501 kind
= tb
[TCA_ACT_KIND
];
504 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
508 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
512 a_o
= tc_lookup_action_n(act_name
);
514 #ifdef CONFIG_MODULES
516 request_module("act_%s", act_name
);
519 a_o
= tc_lookup_action_n(act_name
);
521 /* We dropped the RTNL semaphore in order to
522 * perform the module load. So, even if we
523 * succeeded in loading the module we have to
524 * tell the caller to replay the request. We
525 * indicate this using -EAGAIN.
537 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
542 INIT_LIST_HEAD(&a
->list
);
543 /* backward compatibility for policer */
545 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
547 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
551 /* module count goes up only when brand new policy is created
552 * if it exists and is only bound to in a_o->init() then
553 * ACT_P_CREATED is not returned (a zero is).
555 if (err
!= ACT_P_CREATED
)
556 module_put(a_o
->owner
);
563 module_put(a_o
->owner
);
568 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
569 struct nlattr
*est
, char *name
, int ovr
,
570 int bind
, struct list_head
*actions
)
572 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
573 struct tc_action
*act
;
577 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
581 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
582 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
588 list_add_tail(&act
->list
, actions
);
593 tcf_action_destroy(actions
, bind
);
597 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
602 struct tcf_common
*p
= a
->priv
;
607 /* compat_mode being true specifies a call that is supposed
608 * to add additional backward compatibility statistic TLVs.
611 if (a
->type
== TCA_OLD_COMPAT
)
612 err
= gnet_stats_start_copy_compat(skb
, 0,
613 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
617 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
623 if (gnet_stats_copy_basic(&d
, NULL
, &p
->tcfc_bstats
) < 0 ||
624 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
625 &p
->tcfc_rate_est
) < 0 ||
626 gnet_stats_copy_queue(&d
, NULL
,
628 p
->tcfc_qstats
.qlen
) < 0)
631 if (gnet_stats_finish_copy(&d
) < 0)
641 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
642 u16 flags
, int event
, int bind
, int ref
)
645 struct nlmsghdr
*nlh
;
646 unsigned char *b
= skb_tail_pointer(skb
);
649 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
653 t
->tca_family
= AF_UNSPEC
;
657 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
661 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
664 nla_nest_end(skb
, nest
);
666 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
675 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
676 struct list_head
*actions
, int event
)
680 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
683 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
688 return rtnl_unicast(skb
, net
, portid
);
691 static struct tc_action
*create_a(int i
)
693 struct tc_action
*act
;
695 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
697 pr_debug("create_a: failed to alloc!\n");
701 INIT_LIST_HEAD(&act
->list
);
705 static struct tc_action
*
706 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
708 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
713 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
718 if (tb
[TCA_ACT_INDEX
] == NULL
||
719 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
721 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
729 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
730 if (a
->ops
== NULL
) /* could happen in batch of actions */
733 if (a
->ops
->lookup(a
, index
) == 0)
736 module_put(a
->ops
->owner
);
740 module_put(a
->ops
->owner
);
747 static void cleanup_a(struct list_head
*actions
)
749 struct tc_action
*a
, *tmp
;
751 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
757 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
758 struct nlmsghdr
*n
, u32 portid
)
762 struct nlmsghdr
*nlh
;
764 struct netlink_callback dcb
;
766 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
771 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
773 pr_debug("tca_action_flush: failed skb alloc\n");
777 b
= skb_tail_pointer(skb
);
779 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
784 kind
= tb
[TCA_ACT_KIND
];
785 memset(&a
, 0, sizeof(struct tc_action
));
786 INIT_LIST_HEAD(&a
.list
);
787 a
.ops
= tc_lookup_action(kind
);
788 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
791 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
795 t
->tca_family
= AF_UNSPEC
;
799 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
803 err
= a
.ops
->walk(skb
, &dcb
, RTM_DELACTION
, &a
);
809 nla_nest_end(skb
, nest
);
811 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
812 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
813 module_put(a
.ops
->owner
);
814 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
815 n
->nlmsg_flags
& NLM_F_ECHO
);
822 module_put(a
.ops
->owner
);
830 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
836 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
840 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
846 /* now do the delete */
847 ret
= tcf_action_destroy(actions
, 0);
853 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
854 n
->nlmsg_flags
& NLM_F_ECHO
);
861 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
862 u32 portid
, int event
)
865 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
866 struct tc_action
*act
;
869 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
873 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
875 return tca_action_flush(net
, tb
[1], n
, portid
);
880 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
881 act
= tcf_action_get_1(tb
[i
], n
, portid
);
887 list_add_tail(&act
->list
, &actions
);
890 if (event
== RTM_GETACTION
)
891 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
893 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
904 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
910 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
914 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
915 RTM_NEWACTION
, 0, 0) <= 0) {
920 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
921 n
->nlmsg_flags
& NLM_F_ECHO
);
928 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
934 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
938 /* dump then free all the actions after update; inserted policy
941 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
947 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
949 struct net
*net
= sock_net(skb
->sk
);
950 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
951 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
952 int ret
= 0, ovr
= 0;
954 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
957 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
961 if (tca
[TCA_ACT_TAB
] == NULL
) {
962 pr_notice("tc_ctl_action: received NO action attribs\n");
966 /* n->nlmsg_flags & NLM_F_CREATE */
967 switch (n
->nlmsg_type
) {
969 /* we are going to assume all other flags
970 * imply create only if it doesn't exist
971 * Note that CREATE | EXCL implies that
972 * but since we want avoid ambiguity (eg when flags
973 * is zero) then just set this
975 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
978 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
983 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
984 portid
, RTM_DELACTION
);
987 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
988 portid
, RTM_GETACTION
);
997 static struct nlattr
*
998 find_dump_kind(const struct nlmsghdr
*n
)
1000 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1001 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1002 struct nlattr
*nla
[TCAA_MAX
+ 1];
1003 struct nlattr
*kind
;
1005 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1007 tb1
= nla
[TCA_ACT_TAB
];
1011 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1012 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1017 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1018 nla_len(tb
[1]), NULL
) < 0)
1020 kind
= tb2
[TCA_ACT_KIND
];
1026 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1028 struct nlmsghdr
*nlh
;
1029 unsigned char *b
= skb_tail_pointer(skb
);
1030 struct nlattr
*nest
;
1031 struct tc_action_ops
*a_o
;
1034 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1035 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1038 pr_info("tc_dump_action: action bad kind\n");
1042 a_o
= tc_lookup_action(kind
);
1046 memset(&a
, 0, sizeof(struct tc_action
));
1049 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1050 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1052 goto out_module_put
;
1053 t
= nlmsg_data(nlh
);
1054 t
->tca_family
= AF_UNSPEC
;
1058 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1060 goto out_module_put
;
1062 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1064 goto out_module_put
;
1067 nla_nest_end(skb
, nest
);
1070 nla_nest_cancel(skb
, nest
);
1072 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1073 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1074 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1075 module_put(a_o
->owner
);
1079 module_put(a_o
->owner
);
1084 static int __init
tc_action_init(void)
1086 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1087 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1088 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1094 subsys_initcall(tc_action_init
);