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 static void free_tcf(struct rcu_head
*head
)
32 struct tcf_common
*p
= container_of(head
, struct tcf_common
, tcfc_rcu
);
34 free_percpu(p
->cpu_bstats
);
35 free_percpu(p
->cpu_qstats
);
39 static void tcf_hash_destroy(struct tc_action
*a
)
41 struct tcf_common
*p
= a
->priv
;
42 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
44 spin_lock_bh(&hinfo
->lock
);
45 hlist_del(&p
->tcfc_head
);
46 spin_unlock_bh(&hinfo
->lock
);
47 gen_kill_estimator(&p
->tcfc_bstats
,
50 * gen_estimator est_timer() might access p->tcfc_lock
51 * or bstats, wait a RCU grace period before freeing p
53 call_rcu(&p
->tcfc_rcu
, free_tcf
);
56 int __tcf_hash_release(struct tc_action
*a
, bool bind
, bool strict
)
58 struct tcf_common
*p
= a
->priv
;
64 else if (strict
&& p
->tcfc_bindcnt
> 0)
68 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
70 a
->ops
->cleanup(a
, bind
);
78 EXPORT_SYMBOL(__tcf_hash_release
);
80 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
83 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
84 struct hlist_head
*head
;
86 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
89 spin_lock_bh(&hinfo
->lock
);
93 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
94 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
96 hlist_for_each_entry_rcu(p
, head
, tcfc_head
) {
103 nest
= nla_nest_start(skb
, a
->order
);
106 goto nla_put_failure
;
108 err
= tcf_action_dump_1(skb
, a
, 0, 0);
111 nlmsg_trim(skb
, nest
);
114 nla_nest_end(skb
, nest
);
116 if (n_i
>= TCA_ACT_MAX_PRIO
)
121 spin_unlock_bh(&hinfo
->lock
);
127 nla_nest_cancel(skb
, nest
);
131 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
)
133 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
134 struct hlist_head
*head
;
135 struct hlist_node
*n
;
136 struct tcf_common
*p
;
141 nest
= nla_nest_start(skb
, a
->order
);
143 goto nla_put_failure
;
144 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
145 goto nla_put_failure
;
146 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
147 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
148 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
150 ret
= __tcf_hash_release(a
, false, true);
151 if (ret
== ACT_P_DELETED
) {
152 module_put(a
->ops
->owner
);
155 goto nla_put_failure
;
158 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
159 goto nla_put_failure
;
160 nla_nest_end(skb
, nest
);
164 nla_nest_cancel(skb
, nest
);
168 static int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
169 int type
, struct tc_action
*a
)
171 if (type
== RTM_DELACTION
) {
172 return tcf_del_walker(skb
, a
);
173 } else if (type
== RTM_GETACTION
) {
174 return tcf_dump_walker(skb
, cb
, a
);
176 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
181 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
183 struct tcf_common
*p
= NULL
;
184 struct hlist_head
*head
;
186 spin_lock_bh(&hinfo
->lock
);
187 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
188 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
189 if (p
->tcfc_index
== index
)
191 spin_unlock_bh(&hinfo
->lock
);
196 u32
tcf_hash_new_index(struct tcf_hashinfo
*hinfo
)
198 u32 val
= hinfo
->index
;
203 } while (tcf_hash_lookup(val
, hinfo
));
208 EXPORT_SYMBOL(tcf_hash_new_index
);
210 int tcf_hash_search(struct tc_action
*a
, u32 index
)
212 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
213 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
221 EXPORT_SYMBOL(tcf_hash_search
);
223 int tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
)
225 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
226 struct tcf_common
*p
= NULL
;
227 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
236 EXPORT_SYMBOL(tcf_hash_check
);
238 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
240 struct tcf_common
*pc
= a
->priv
;
242 gen_kill_estimator(&pc
->tcfc_bstats
,
244 call_rcu(&pc
->tcfc_rcu
, free_tcf
);
246 EXPORT_SYMBOL(tcf_hash_cleanup
);
248 int tcf_hash_create(u32 index
, struct nlattr
*est
, struct tc_action
*a
,
249 int size
, int bind
, bool cpustats
)
251 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
252 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
262 p
->cpu_bstats
= netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu
);
263 if (!p
->cpu_bstats
) {
268 p
->cpu_qstats
= alloc_percpu(struct gnet_stats_queue
);
269 if (!p
->cpu_qstats
) {
271 free_percpu(p
->cpu_bstats
);
275 spin_lock_init(&p
->tcfc_lock
);
276 INIT_HLIST_NODE(&p
->tcfc_head
);
277 p
->tcfc_index
= index
? index
: tcf_hash_new_index(hinfo
);
278 p
->tcfc_tm
.install
= jiffies
;
279 p
->tcfc_tm
.lastuse
= jiffies
;
281 err
= gen_new_estimator(&p
->tcfc_bstats
, p
->cpu_bstats
,
285 free_percpu(p
->cpu_qstats
);
290 a
->priv
= (void *) p
;
293 EXPORT_SYMBOL(tcf_hash_create
);
295 void tcf_hash_insert(struct tc_action
*a
)
297 struct tcf_common
*p
= a
->priv
;
298 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
299 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
301 spin_lock_bh(&hinfo
->lock
);
302 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
303 spin_unlock_bh(&hinfo
->lock
);
305 EXPORT_SYMBOL(tcf_hash_insert
);
307 static LIST_HEAD(act_base
);
308 static DEFINE_RWLOCK(act_mod_lock
);
310 int tcf_register_action(struct tc_action_ops
*act
, unsigned int mask
)
312 struct tc_action_ops
*a
;
315 /* Must supply act, dump and init */
316 if (!act
->act
|| !act
->dump
|| !act
->init
)
319 /* Supply defaults */
321 act
->lookup
= tcf_hash_search
;
323 act
->walk
= tcf_generic_walker
;
325 act
->hinfo
= kmalloc(sizeof(struct tcf_hashinfo
), GFP_KERNEL
);
328 err
= tcf_hashinfo_init(act
->hinfo
, mask
);
334 write_lock(&act_mod_lock
);
335 list_for_each_entry(a
, &act_base
, head
) {
336 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
337 write_unlock(&act_mod_lock
);
338 tcf_hashinfo_destroy(act
->hinfo
);
343 list_add_tail(&act
->head
, &act_base
);
344 write_unlock(&act_mod_lock
);
347 EXPORT_SYMBOL(tcf_register_action
);
349 int tcf_unregister_action(struct tc_action_ops
*act
)
351 struct tc_action_ops
*a
;
354 write_lock(&act_mod_lock
);
355 list_for_each_entry(a
, &act_base
, head
) {
357 list_del(&act
->head
);
358 tcf_hashinfo_destroy(act
->hinfo
);
364 write_unlock(&act_mod_lock
);
367 EXPORT_SYMBOL(tcf_unregister_action
);
370 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
372 struct tc_action_ops
*a
, *res
= NULL
;
375 read_lock(&act_mod_lock
);
376 list_for_each_entry(a
, &act_base
, head
) {
377 if (strcmp(kind
, a
->kind
) == 0) {
378 if (try_module_get(a
->owner
))
383 read_unlock(&act_mod_lock
);
388 /* lookup by nlattr */
389 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
391 struct tc_action_ops
*a
, *res
= NULL
;
394 read_lock(&act_mod_lock
);
395 list_for_each_entry(a
, &act_base
, head
) {
396 if (nla_strcmp(kind
, a
->kind
) == 0) {
397 if (try_module_get(a
->owner
))
402 read_unlock(&act_mod_lock
);
407 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
408 struct tcf_result
*res
)
410 const struct tc_action
*a
;
413 if (skb
->tc_verd
& TC_NCLS
) {
414 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
418 list_for_each_entry(a
, actions
, list
) {
420 ret
= a
->ops
->act(skb
, a
, res
);
421 if (ret
== TC_ACT_REPEAT
)
422 goto repeat
; /* we need a ttl - JHS */
423 if (ret
!= TC_ACT_PIPE
)
429 EXPORT_SYMBOL(tcf_action_exec
);
431 int tcf_action_destroy(struct list_head
*actions
, int bind
)
433 struct tc_action
*a
, *tmp
;
436 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
437 ret
= __tcf_hash_release(a
, bind
, true);
438 if (ret
== ACT_P_DELETED
)
439 module_put(a
->ops
->owner
);
449 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
451 return a
->ops
->dump(skb
, a
, bind
, ref
);
455 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
458 unsigned char *b
= skb_tail_pointer(skb
);
461 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
462 goto nla_put_failure
;
463 if (tcf_action_copy_stats(skb
, a
, 0))
464 goto nla_put_failure
;
465 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
467 goto nla_put_failure
;
468 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
470 nla_nest_end(skb
, nest
);
478 EXPORT_SYMBOL(tcf_action_dump_1
);
481 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
487 list_for_each_entry(a
, actions
, list
) {
488 nest
= nla_nest_start(skb
, a
->order
);
490 goto nla_put_failure
;
491 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
494 nla_nest_end(skb
, nest
);
502 nla_nest_cancel(skb
, nest
);
506 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
507 struct nlattr
*est
, char *name
, int ovr
,
511 struct tc_action_ops
*a_o
;
512 char act_name
[IFNAMSIZ
];
513 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
518 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
522 kind
= tb
[TCA_ACT_KIND
];
525 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
529 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
533 a_o
= tc_lookup_action_n(act_name
);
535 #ifdef CONFIG_MODULES
537 request_module("act_%s", act_name
);
540 a_o
= tc_lookup_action_n(act_name
);
542 /* We dropped the RTNL semaphore in order to
543 * perform the module load. So, even if we
544 * succeeded in loading the module we have to
545 * tell the caller to replay the request. We
546 * indicate this using -EAGAIN.
558 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
563 INIT_LIST_HEAD(&a
->list
);
564 /* backward compatibility for policer */
566 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
568 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
572 /* module count goes up only when brand new policy is created
573 * if it exists and is only bound to in a_o->init() then
574 * ACT_P_CREATED is not returned (a zero is).
576 if (err
!= ACT_P_CREATED
)
577 module_put(a_o
->owner
);
584 module_put(a_o
->owner
);
589 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
590 struct nlattr
*est
, char *name
, int ovr
,
591 int bind
, struct list_head
*actions
)
593 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
594 struct tc_action
*act
;
598 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
602 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
603 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
609 list_add_tail(&act
->list
, actions
);
614 tcf_action_destroy(actions
, bind
);
618 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
623 struct tcf_common
*p
= a
->priv
;
628 /* compat_mode being true specifies a call that is supposed
629 * to add additional backward compatibility statistic TLVs.
632 if (a
->type
== TCA_OLD_COMPAT
)
633 err
= gnet_stats_start_copy_compat(skb
, 0,
634 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
638 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
644 if (gnet_stats_copy_basic(&d
, p
->cpu_bstats
, &p
->tcfc_bstats
) < 0 ||
645 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
646 &p
->tcfc_rate_est
) < 0 ||
647 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
649 p
->tcfc_qstats
.qlen
) < 0)
652 if (gnet_stats_finish_copy(&d
) < 0)
662 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
663 u16 flags
, int event
, int bind
, int ref
)
666 struct nlmsghdr
*nlh
;
667 unsigned char *b
= skb_tail_pointer(skb
);
670 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
674 t
->tca_family
= AF_UNSPEC
;
678 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
682 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
685 nla_nest_end(skb
, nest
);
687 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
696 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
697 struct list_head
*actions
, int event
)
701 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
704 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
709 return rtnl_unicast(skb
, net
, portid
);
712 static struct tc_action
*create_a(int i
)
714 struct tc_action
*act
;
716 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
718 pr_debug("create_a: failed to alloc!\n");
722 INIT_LIST_HEAD(&act
->list
);
726 static struct tc_action
*
727 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
729 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
734 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
739 if (tb
[TCA_ACT_INDEX
] == NULL
||
740 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
742 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
750 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
751 if (a
->ops
== NULL
) /* could happen in batch of actions */
754 if (a
->ops
->lookup(a
, index
) == 0)
757 module_put(a
->ops
->owner
);
761 module_put(a
->ops
->owner
);
768 static void cleanup_a(struct list_head
*actions
)
770 struct tc_action
*a
, *tmp
;
772 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
778 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
779 struct nlmsghdr
*n
, u32 portid
)
783 struct nlmsghdr
*nlh
;
785 struct netlink_callback dcb
;
787 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
792 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
794 pr_debug("tca_action_flush: failed skb alloc\n");
798 b
= skb_tail_pointer(skb
);
800 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
805 kind
= tb
[TCA_ACT_KIND
];
806 memset(&a
, 0, sizeof(struct tc_action
));
807 INIT_LIST_HEAD(&a
.list
);
808 a
.ops
= tc_lookup_action(kind
);
809 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
812 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
816 t
->tca_family
= AF_UNSPEC
;
820 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
824 err
= a
.ops
->walk(skb
, &dcb
, RTM_DELACTION
, &a
);
828 nla_nest_end(skb
, nest
);
830 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
831 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
832 module_put(a
.ops
->owner
);
833 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
834 n
->nlmsg_flags
& NLM_F_ECHO
);
841 module_put(a
.ops
->owner
);
848 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
854 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
858 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
864 /* now do the delete */
865 ret
= tcf_action_destroy(actions
, 0);
871 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
872 n
->nlmsg_flags
& NLM_F_ECHO
);
879 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
880 u32 portid
, int event
)
883 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
884 struct tc_action
*act
;
887 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
891 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
893 return tca_action_flush(net
, tb
[1], n
, portid
);
898 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
899 act
= tcf_action_get_1(tb
[i
], n
, portid
);
905 list_add_tail(&act
->list
, &actions
);
908 if (event
== RTM_GETACTION
)
909 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
911 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
922 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
928 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
932 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
933 RTM_NEWACTION
, 0, 0) <= 0) {
938 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
939 n
->nlmsg_flags
& NLM_F_ECHO
);
946 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
952 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
956 /* dump then free all the actions after update; inserted policy
959 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
965 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
967 struct net
*net
= sock_net(skb
->sk
);
968 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
969 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
970 int ret
= 0, ovr
= 0;
972 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
975 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
979 if (tca
[TCA_ACT_TAB
] == NULL
) {
980 pr_notice("tc_ctl_action: received NO action attribs\n");
984 /* n->nlmsg_flags & NLM_F_CREATE */
985 switch (n
->nlmsg_type
) {
987 /* we are going to assume all other flags
988 * imply create only if it doesn't exist
989 * Note that CREATE | EXCL implies that
990 * but since we want avoid ambiguity (eg when flags
991 * is zero) then just set this
993 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
996 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
1001 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1002 portid
, RTM_DELACTION
);
1005 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1006 portid
, RTM_GETACTION
);
1015 static struct nlattr
*
1016 find_dump_kind(const struct nlmsghdr
*n
)
1018 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1019 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1020 struct nlattr
*nla
[TCAA_MAX
+ 1];
1021 struct nlattr
*kind
;
1023 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1025 tb1
= nla
[TCA_ACT_TAB
];
1029 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1030 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1035 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1036 nla_len(tb
[1]), NULL
) < 0)
1038 kind
= tb2
[TCA_ACT_KIND
];
1044 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1046 struct nlmsghdr
*nlh
;
1047 unsigned char *b
= skb_tail_pointer(skb
);
1048 struct nlattr
*nest
;
1049 struct tc_action_ops
*a_o
;
1052 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1053 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1056 pr_info("tc_dump_action: action bad kind\n");
1060 a_o
= tc_lookup_action(kind
);
1064 memset(&a
, 0, sizeof(struct tc_action
));
1067 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1068 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1070 goto out_module_put
;
1071 t
= nlmsg_data(nlh
);
1072 t
->tca_family
= AF_UNSPEC
;
1076 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1078 goto out_module_put
;
1080 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1082 goto out_module_put
;
1085 nla_nest_end(skb
, nest
);
1088 nla_nest_cancel(skb
, nest
);
1090 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1091 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1092 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1093 module_put(a_o
->owner
);
1097 module_put(a_o
->owner
);
1102 static int __init
tc_action_init(void)
1104 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1105 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1106 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1112 subsys_initcall(tc_action_init
);