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
);
105 goto nla_put_failure
;
106 err
= tcf_action_dump_1(skb
, a
, 0, 0);
109 nlmsg_trim(skb
, nest
);
112 nla_nest_end(skb
, nest
);
114 if (n_i
>= TCA_ACT_MAX_PRIO
)
119 spin_unlock_bh(&hinfo
->lock
);
125 nla_nest_cancel(skb
, nest
);
129 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
)
131 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
132 struct hlist_head
*head
;
133 struct hlist_node
*n
;
134 struct tcf_common
*p
;
139 nest
= nla_nest_start(skb
, a
->order
);
141 goto nla_put_failure
;
142 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
143 goto nla_put_failure
;
144 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
145 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
146 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
148 ret
= __tcf_hash_release(a
, false, true);
149 if (ret
== ACT_P_DELETED
) {
150 module_put(a
->ops
->owner
);
153 goto nla_put_failure
;
156 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
157 goto nla_put_failure
;
158 nla_nest_end(skb
, nest
);
162 nla_nest_cancel(skb
, nest
);
166 static int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
167 int type
, struct tc_action
*a
)
169 if (type
== RTM_DELACTION
) {
170 return tcf_del_walker(skb
, a
);
171 } else if (type
== RTM_GETACTION
) {
172 return tcf_dump_walker(skb
, cb
, a
);
174 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
179 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
181 struct tcf_common
*p
= NULL
;
182 struct hlist_head
*head
;
184 spin_lock_bh(&hinfo
->lock
);
185 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
186 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
187 if (p
->tcfc_index
== index
)
189 spin_unlock_bh(&hinfo
->lock
);
194 u32
tcf_hash_new_index(struct tcf_hashinfo
*hinfo
)
196 u32 val
= hinfo
->index
;
201 } while (tcf_hash_lookup(val
, hinfo
));
206 EXPORT_SYMBOL(tcf_hash_new_index
);
208 int tcf_hash_search(struct tc_action
*a
, u32 index
)
210 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
211 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
219 EXPORT_SYMBOL(tcf_hash_search
);
221 int tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
)
223 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
224 struct tcf_common
*p
= NULL
;
225 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
234 EXPORT_SYMBOL(tcf_hash_check
);
236 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
238 struct tcf_common
*pc
= a
->priv
;
240 gen_kill_estimator(&pc
->tcfc_bstats
,
242 call_rcu(&pc
->tcfc_rcu
, free_tcf
);
244 EXPORT_SYMBOL(tcf_hash_cleanup
);
246 int tcf_hash_create(u32 index
, struct nlattr
*est
, struct tc_action
*a
,
247 int size
, int bind
, bool cpustats
)
249 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
250 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
260 p
->cpu_bstats
= netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu
);
261 if (!p
->cpu_bstats
) {
266 p
->cpu_qstats
= alloc_percpu(struct gnet_stats_queue
);
267 if (!p
->cpu_qstats
) {
269 free_percpu(p
->cpu_bstats
);
273 spin_lock_init(&p
->tcfc_lock
);
274 INIT_HLIST_NODE(&p
->tcfc_head
);
275 p
->tcfc_index
= index
? index
: tcf_hash_new_index(hinfo
);
276 p
->tcfc_tm
.install
= jiffies
;
277 p
->tcfc_tm
.lastuse
= jiffies
;
279 err
= gen_new_estimator(&p
->tcfc_bstats
, p
->cpu_bstats
,
283 free_percpu(p
->cpu_qstats
);
288 a
->priv
= (void *) p
;
291 EXPORT_SYMBOL(tcf_hash_create
);
293 void tcf_hash_insert(struct tc_action
*a
)
295 struct tcf_common
*p
= a
->priv
;
296 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
297 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
299 spin_lock_bh(&hinfo
->lock
);
300 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
301 spin_unlock_bh(&hinfo
->lock
);
303 EXPORT_SYMBOL(tcf_hash_insert
);
305 static LIST_HEAD(act_base
);
306 static DEFINE_RWLOCK(act_mod_lock
);
308 int tcf_register_action(struct tc_action_ops
*act
, unsigned int mask
)
310 struct tc_action_ops
*a
;
313 /* Must supply act, dump and init */
314 if (!act
->act
|| !act
->dump
|| !act
->init
)
317 /* Supply defaults */
319 act
->lookup
= tcf_hash_search
;
321 act
->walk
= tcf_generic_walker
;
323 act
->hinfo
= kmalloc(sizeof(struct tcf_hashinfo
), GFP_KERNEL
);
326 err
= tcf_hashinfo_init(act
->hinfo
, mask
);
332 write_lock(&act_mod_lock
);
333 list_for_each_entry(a
, &act_base
, head
) {
334 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
335 write_unlock(&act_mod_lock
);
336 tcf_hashinfo_destroy(act
->hinfo
);
341 list_add_tail(&act
->head
, &act_base
);
342 write_unlock(&act_mod_lock
);
345 EXPORT_SYMBOL(tcf_register_action
);
347 int tcf_unregister_action(struct tc_action_ops
*act
)
349 struct tc_action_ops
*a
;
352 write_lock(&act_mod_lock
);
353 list_for_each_entry(a
, &act_base
, head
) {
355 list_del(&act
->head
);
356 tcf_hashinfo_destroy(act
->hinfo
);
362 write_unlock(&act_mod_lock
);
365 EXPORT_SYMBOL(tcf_unregister_action
);
368 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
370 struct tc_action_ops
*a
, *res
= NULL
;
373 read_lock(&act_mod_lock
);
374 list_for_each_entry(a
, &act_base
, head
) {
375 if (strcmp(kind
, a
->kind
) == 0) {
376 if (try_module_get(a
->owner
))
381 read_unlock(&act_mod_lock
);
386 /* lookup by nlattr */
387 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
389 struct tc_action_ops
*a
, *res
= NULL
;
392 read_lock(&act_mod_lock
);
393 list_for_each_entry(a
, &act_base
, head
) {
394 if (nla_strcmp(kind
, a
->kind
) == 0) {
395 if (try_module_get(a
->owner
))
400 read_unlock(&act_mod_lock
);
405 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
406 struct tcf_result
*res
)
408 const struct tc_action
*a
;
411 if (skb
->tc_verd
& TC_NCLS
) {
412 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
416 list_for_each_entry(a
, actions
, list
) {
418 ret
= a
->ops
->act(skb
, a
, res
);
419 if (ret
== TC_ACT_REPEAT
)
420 goto repeat
; /* we need a ttl - JHS */
421 if (ret
!= TC_ACT_PIPE
)
427 EXPORT_SYMBOL(tcf_action_exec
);
429 int tcf_action_destroy(struct list_head
*actions
, int bind
)
431 struct tc_action
*a
, *tmp
;
434 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
435 ret
= __tcf_hash_release(a
, bind
, true);
436 if (ret
== ACT_P_DELETED
)
437 module_put(a
->ops
->owner
);
447 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
449 return a
->ops
->dump(skb
, a
, bind
, ref
);
453 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
456 unsigned char *b
= skb_tail_pointer(skb
);
459 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
460 goto nla_put_failure
;
461 if (tcf_action_copy_stats(skb
, a
, 0))
462 goto nla_put_failure
;
463 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
465 goto nla_put_failure
;
466 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
468 nla_nest_end(skb
, nest
);
476 EXPORT_SYMBOL(tcf_action_dump_1
);
479 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
485 list_for_each_entry(a
, actions
, list
) {
486 nest
= nla_nest_start(skb
, a
->order
);
488 goto nla_put_failure
;
489 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
492 nla_nest_end(skb
, nest
);
500 nla_nest_cancel(skb
, nest
);
504 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
505 struct nlattr
*est
, char *name
, int ovr
,
509 struct tc_action_ops
*a_o
;
510 char act_name
[IFNAMSIZ
];
511 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
516 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
520 kind
= tb
[TCA_ACT_KIND
];
523 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
527 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
531 a_o
= tc_lookup_action_n(act_name
);
533 #ifdef CONFIG_MODULES
535 request_module("act_%s", act_name
);
538 a_o
= tc_lookup_action_n(act_name
);
540 /* We dropped the RTNL semaphore in order to
541 * perform the module load. So, even if we
542 * succeeded in loading the module we have to
543 * tell the caller to replay the request. We
544 * indicate this using -EAGAIN.
556 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
561 INIT_LIST_HEAD(&a
->list
);
562 /* backward compatibility for policer */
564 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
566 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
570 /* module count goes up only when brand new policy is created
571 * if it exists and is only bound to in a_o->init() then
572 * ACT_P_CREATED is not returned (a zero is).
574 if (err
!= ACT_P_CREATED
)
575 module_put(a_o
->owner
);
582 module_put(a_o
->owner
);
587 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
588 struct nlattr
*est
, char *name
, int ovr
,
589 int bind
, struct list_head
*actions
)
591 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
592 struct tc_action
*act
;
596 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
600 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
601 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
607 list_add_tail(&act
->list
, actions
);
612 tcf_action_destroy(actions
, bind
);
616 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
621 struct tcf_common
*p
= a
->priv
;
626 /* compat_mode being true specifies a call that is supposed
627 * to add additional backward compatibility statistic TLVs.
630 if (a
->type
== TCA_OLD_COMPAT
)
631 err
= gnet_stats_start_copy_compat(skb
, 0,
632 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
636 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
642 if (gnet_stats_copy_basic(&d
, p
->cpu_bstats
, &p
->tcfc_bstats
) < 0 ||
643 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
644 &p
->tcfc_rate_est
) < 0 ||
645 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
647 p
->tcfc_qstats
.qlen
) < 0)
650 if (gnet_stats_finish_copy(&d
) < 0)
660 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
661 u16 flags
, int event
, int bind
, int ref
)
664 struct nlmsghdr
*nlh
;
665 unsigned char *b
= skb_tail_pointer(skb
);
668 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
672 t
->tca_family
= AF_UNSPEC
;
676 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
680 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
683 nla_nest_end(skb
, nest
);
685 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
694 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
695 struct list_head
*actions
, int event
)
699 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
702 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
707 return rtnl_unicast(skb
, net
, portid
);
710 static struct tc_action
*create_a(int i
)
712 struct tc_action
*act
;
714 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
716 pr_debug("create_a: failed to alloc!\n");
720 INIT_LIST_HEAD(&act
->list
);
724 static struct tc_action
*
725 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
727 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
732 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
737 if (tb
[TCA_ACT_INDEX
] == NULL
||
738 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
740 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
748 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
749 if (a
->ops
== NULL
) /* could happen in batch of actions */
752 if (a
->ops
->lookup(a
, index
) == 0)
755 module_put(a
->ops
->owner
);
759 module_put(a
->ops
->owner
);
766 static void cleanup_a(struct list_head
*actions
)
768 struct tc_action
*a
, *tmp
;
770 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
776 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
777 struct nlmsghdr
*n
, u32 portid
)
781 struct nlmsghdr
*nlh
;
783 struct netlink_callback dcb
;
785 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
790 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
792 pr_debug("tca_action_flush: failed skb alloc\n");
796 b
= skb_tail_pointer(skb
);
798 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
803 kind
= tb
[TCA_ACT_KIND
];
804 memset(&a
, 0, sizeof(struct tc_action
));
805 INIT_LIST_HEAD(&a
.list
);
806 a
.ops
= tc_lookup_action(kind
);
807 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
810 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
814 t
->tca_family
= AF_UNSPEC
;
818 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
822 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
);
849 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
855 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
859 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
865 /* now do the delete */
866 ret
= tcf_action_destroy(actions
, 0);
872 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
873 n
->nlmsg_flags
& NLM_F_ECHO
);
880 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
881 u32 portid
, int event
)
884 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
885 struct tc_action
*act
;
888 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
892 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
894 return tca_action_flush(net
, tb
[1], n
, portid
);
899 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
900 act
= tcf_action_get_1(tb
[i
], n
, portid
);
906 list_add_tail(&act
->list
, &actions
);
909 if (event
== RTM_GETACTION
)
910 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
912 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
923 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
929 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
933 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
934 RTM_NEWACTION
, 0, 0) <= 0) {
939 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
940 n
->nlmsg_flags
& NLM_F_ECHO
);
947 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
953 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
957 /* dump then free all the actions after update; inserted policy
960 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
966 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
968 struct net
*net
= sock_net(skb
->sk
);
969 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
970 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
971 int ret
= 0, ovr
= 0;
973 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
976 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
980 if (tca
[TCA_ACT_TAB
] == NULL
) {
981 pr_notice("tc_ctl_action: received NO action attribs\n");
985 /* n->nlmsg_flags & NLM_F_CREATE */
986 switch (n
->nlmsg_type
) {
988 /* we are going to assume all other flags
989 * imply create only if it doesn't exist
990 * Note that CREATE | EXCL implies that
991 * but since we want avoid ambiguity (eg when flags
992 * is zero) then just set this
994 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
997 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
1002 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1003 portid
, RTM_DELACTION
);
1006 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1007 portid
, RTM_GETACTION
);
1016 static struct nlattr
*
1017 find_dump_kind(const struct nlmsghdr
*n
)
1019 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1020 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1021 struct nlattr
*nla
[TCAA_MAX
+ 1];
1022 struct nlattr
*kind
;
1024 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1026 tb1
= nla
[TCA_ACT_TAB
];
1030 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1031 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1036 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1037 nla_len(tb
[1]), NULL
) < 0)
1039 kind
= tb2
[TCA_ACT_KIND
];
1045 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1047 struct nlmsghdr
*nlh
;
1048 unsigned char *b
= skb_tail_pointer(skb
);
1049 struct nlattr
*nest
;
1050 struct tc_action_ops
*a_o
;
1053 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1054 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1057 pr_info("tc_dump_action: action bad kind\n");
1061 a_o
= tc_lookup_action(kind
);
1065 memset(&a
, 0, sizeof(struct tc_action
));
1068 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1069 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1071 goto out_module_put
;
1072 t
= nlmsg_data(nlh
);
1073 t
->tca_family
= AF_UNSPEC
;
1077 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1079 goto out_module_put
;
1081 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1083 goto out_module_put
;
1086 nla_nest_end(skb
, nest
);
1089 nla_nest_cancel(skb
, nest
);
1091 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1092 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1093 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1094 module_put(a_o
->owner
);
1098 module_put(a_o
->owner
);
1103 static int __init
tc_action_init(void)
1105 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1106 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1107 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1113 subsys_initcall(tc_action_init
);