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 (TC_MUNGED
& skb
->tc_verd
) {
397 /* copied already, allow trampling */
398 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
399 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
401 if (ret
== TC_ACT_REPEAT
)
402 goto repeat
; /* we need a ttl - JHS */
403 if (ret
!= TC_ACT_PIPE
)
409 EXPORT_SYMBOL(tcf_action_exec
);
411 int tcf_action_destroy(struct list_head
*actions
, int bind
)
413 struct tc_action
*a
, *tmp
;
416 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
417 ret
= __tcf_hash_release(a
, bind
, true);
418 if (ret
== ACT_P_DELETED
)
419 module_put(a
->ops
->owner
);
429 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
431 return a
->ops
->dump(skb
, a
, bind
, ref
);
435 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
438 unsigned char *b
= skb_tail_pointer(skb
);
441 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
442 goto nla_put_failure
;
443 if (tcf_action_copy_stats(skb
, a
, 0))
444 goto nla_put_failure
;
445 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
447 goto nla_put_failure
;
448 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
450 nla_nest_end(skb
, nest
);
458 EXPORT_SYMBOL(tcf_action_dump_1
);
461 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
467 list_for_each_entry(a
, actions
, list
) {
468 nest
= nla_nest_start(skb
, a
->order
);
470 goto nla_put_failure
;
471 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
474 nla_nest_end(skb
, nest
);
482 nla_nest_cancel(skb
, nest
);
486 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
487 struct nlattr
*est
, char *name
, int ovr
,
491 struct tc_action_ops
*a_o
;
492 char act_name
[IFNAMSIZ
];
493 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
498 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
502 kind
= tb
[TCA_ACT_KIND
];
505 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
509 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
513 a_o
= tc_lookup_action_n(act_name
);
515 #ifdef CONFIG_MODULES
517 request_module("act_%s", act_name
);
520 a_o
= tc_lookup_action_n(act_name
);
522 /* We dropped the RTNL semaphore in order to
523 * perform the module load. So, even if we
524 * succeeded in loading the module we have to
525 * tell the caller to replay the request. We
526 * indicate this using -EAGAIN.
538 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
543 INIT_LIST_HEAD(&a
->list
);
544 /* backward compatibility for policer */
546 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
548 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
552 /* module count goes up only when brand new policy is created
553 * if it exists and is only bound to in a_o->init() then
554 * ACT_P_CREATED is not returned (a zero is).
556 if (err
!= ACT_P_CREATED
)
557 module_put(a_o
->owner
);
564 module_put(a_o
->owner
);
569 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
570 struct nlattr
*est
, char *name
, int ovr
,
571 int bind
, struct list_head
*actions
)
573 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
574 struct tc_action
*act
;
578 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
582 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
583 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
589 list_add_tail(&act
->list
, actions
);
594 tcf_action_destroy(actions
, bind
);
598 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
603 struct tcf_common
*p
= a
->priv
;
608 /* compat_mode being true specifies a call that is supposed
609 * to add additional backward compatibility statistic TLVs.
612 if (a
->type
== TCA_OLD_COMPAT
)
613 err
= gnet_stats_start_copy_compat(skb
, 0,
614 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
618 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
624 if (gnet_stats_copy_basic(&d
, NULL
, &p
->tcfc_bstats
) < 0 ||
625 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
626 &p
->tcfc_rate_est
) < 0 ||
627 gnet_stats_copy_queue(&d
, NULL
,
629 p
->tcfc_qstats
.qlen
) < 0)
632 if (gnet_stats_finish_copy(&d
) < 0)
642 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
643 u16 flags
, int event
, int bind
, int ref
)
646 struct nlmsghdr
*nlh
;
647 unsigned char *b
= skb_tail_pointer(skb
);
650 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
654 t
->tca_family
= AF_UNSPEC
;
658 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
662 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
665 nla_nest_end(skb
, nest
);
667 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
676 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
677 struct list_head
*actions
, int event
)
681 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
684 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
689 return rtnl_unicast(skb
, net
, portid
);
692 static struct tc_action
*create_a(int i
)
694 struct tc_action
*act
;
696 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
698 pr_debug("create_a: failed to alloc!\n");
702 INIT_LIST_HEAD(&act
->list
);
706 static struct tc_action
*
707 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
709 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
714 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
719 if (tb
[TCA_ACT_INDEX
] == NULL
||
720 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
722 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
730 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
731 if (a
->ops
== NULL
) /* could happen in batch of actions */
734 if (a
->ops
->lookup(a
, index
) == 0)
737 module_put(a
->ops
->owner
);
741 module_put(a
->ops
->owner
);
748 static void cleanup_a(struct list_head
*actions
)
750 struct tc_action
*a
, *tmp
;
752 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
758 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
759 struct nlmsghdr
*n
, u32 portid
)
763 struct nlmsghdr
*nlh
;
765 struct netlink_callback dcb
;
767 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
772 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
774 pr_debug("tca_action_flush: failed skb alloc\n");
778 b
= skb_tail_pointer(skb
);
780 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
785 kind
= tb
[TCA_ACT_KIND
];
786 memset(&a
, 0, sizeof(struct tc_action
));
787 INIT_LIST_HEAD(&a
.list
);
788 a
.ops
= tc_lookup_action(kind
);
789 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
792 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
796 t
->tca_family
= AF_UNSPEC
;
800 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
804 err
= a
.ops
->walk(skb
, &dcb
, RTM_DELACTION
, &a
);
810 nla_nest_end(skb
, nest
);
812 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
813 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
814 module_put(a
.ops
->owner
);
815 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
816 n
->nlmsg_flags
& NLM_F_ECHO
);
823 module_put(a
.ops
->owner
);
831 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
837 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
841 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
847 /* now do the delete */
848 ret
= tcf_action_destroy(actions
, 0);
854 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
855 n
->nlmsg_flags
& NLM_F_ECHO
);
862 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
863 u32 portid
, int event
)
866 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
867 struct tc_action
*act
;
870 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
874 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
876 return tca_action_flush(net
, tb
[1], n
, portid
);
881 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
882 act
= tcf_action_get_1(tb
[i
], n
, portid
);
888 list_add_tail(&act
->list
, &actions
);
891 if (event
== RTM_GETACTION
)
892 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
894 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
905 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
911 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
915 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
916 RTM_NEWACTION
, 0, 0) <= 0) {
921 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
922 n
->nlmsg_flags
& NLM_F_ECHO
);
929 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
935 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
939 /* dump then free all the actions after update; inserted policy
942 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
948 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
950 struct net
*net
= sock_net(skb
->sk
);
951 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
952 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
953 int ret
= 0, ovr
= 0;
955 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
958 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
962 if (tca
[TCA_ACT_TAB
] == NULL
) {
963 pr_notice("tc_ctl_action: received NO action attribs\n");
967 /* n->nlmsg_flags & NLM_F_CREATE */
968 switch (n
->nlmsg_type
) {
970 /* we are going to assume all other flags
971 * imply create only if it doesn't exist
972 * Note that CREATE | EXCL implies that
973 * but since we want avoid ambiguity (eg when flags
974 * is zero) then just set this
976 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
979 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
984 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
985 portid
, RTM_DELACTION
);
988 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
989 portid
, RTM_GETACTION
);
998 static struct nlattr
*
999 find_dump_kind(const struct nlmsghdr
*n
)
1001 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1002 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1003 struct nlattr
*nla
[TCAA_MAX
+ 1];
1004 struct nlattr
*kind
;
1006 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1008 tb1
= nla
[TCA_ACT_TAB
];
1012 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1013 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1018 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1019 nla_len(tb
[1]), NULL
) < 0)
1021 kind
= tb2
[TCA_ACT_KIND
];
1027 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1029 struct nlmsghdr
*nlh
;
1030 unsigned char *b
= skb_tail_pointer(skb
);
1031 struct nlattr
*nest
;
1032 struct tc_action_ops
*a_o
;
1035 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1036 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1039 pr_info("tc_dump_action: action bad kind\n");
1043 a_o
= tc_lookup_action(kind
);
1047 memset(&a
, 0, sizeof(struct tc_action
));
1050 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1051 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1053 goto out_module_put
;
1054 t
= nlmsg_data(nlh
);
1055 t
->tca_family
= AF_UNSPEC
;
1059 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1061 goto out_module_put
;
1063 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1065 goto out_module_put
;
1068 nla_nest_end(skb
, nest
);
1071 nla_nest_cancel(skb
, nest
);
1073 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1074 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1075 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1076 module_put(a_o
->owner
);
1080 module_put(a_o
->owner
);
1085 static int __init
tc_action_init(void)
1087 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1088 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1089 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1095 subsys_initcall(tc_action_init
);