]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/sched/act_api.c
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 tc_action
*p
= container_of(head
, struct tc_action
, tcfa_rcu
);
34 free_percpu(p
->cpu_bstats
);
35 free_percpu(p
->cpu_qstats
);
39 static void tcf_hash_destroy(struct tcf_hashinfo
*hinfo
, struct tc_action
*p
)
41 spin_lock_bh(&hinfo
->lock
);
42 hlist_del(&p
->tcfa_head
);
43 spin_unlock_bh(&hinfo
->lock
);
44 gen_kill_estimator(&p
->tcfa_rate_est
);
46 * gen_estimator est_timer() might access p->tcfa_lock
47 * or bstats, wait a RCU grace period before freeing p
49 call_rcu(&p
->tcfa_rcu
, free_tcf
);
52 int __tcf_hash_release(struct tc_action
*p
, bool bind
, bool strict
)
59 else if (strict
&& p
->tcfa_bindcnt
> 0)
63 if (p
->tcfa_bindcnt
<= 0 && p
->tcfa_refcnt
<= 0) {
65 p
->ops
->cleanup(p
, bind
);
66 tcf_hash_destroy(p
->hinfo
, p
);
73 EXPORT_SYMBOL(__tcf_hash_release
);
75 static int tcf_dump_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
76 struct netlink_callback
*cb
)
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 struct hlist_head
*head
;
89 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
91 hlist_for_each_entry_rcu(p
, head
, tcfa_head
) {
96 nest
= nla_nest_start(skb
, n_i
);
99 err
= tcf_action_dump_1(skb
, p
, 0, 0);
102 nlmsg_trim(skb
, nest
);
105 nla_nest_end(skb
, nest
);
107 if (n_i
>= TCA_ACT_MAX_PRIO
)
112 spin_unlock_bh(&hinfo
->lock
);
118 nla_nest_cancel(skb
, nest
);
122 static int tcf_del_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
123 const struct tc_action_ops
*ops
)
129 nest
= nla_nest_start(skb
, 0);
131 goto nla_put_failure
;
132 if (nla_put_string(skb
, TCA_KIND
, ops
->kind
))
133 goto nla_put_failure
;
134 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
135 struct hlist_head
*head
;
136 struct hlist_node
*n
;
139 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
140 hlist_for_each_entry_safe(p
, n
, head
, tcfa_head
) {
141 ret
= __tcf_hash_release(p
, false, true);
142 if (ret
== ACT_P_DELETED
) {
143 module_put(p
->ops
->owner
);
146 goto nla_put_failure
;
149 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
150 goto nla_put_failure
;
151 nla_nest_end(skb
, nest
);
155 nla_nest_cancel(skb
, nest
);
159 int tcf_generic_walker(struct tc_action_net
*tn
, struct sk_buff
*skb
,
160 struct netlink_callback
*cb
, int type
,
161 const struct tc_action_ops
*ops
)
163 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
165 if (type
== RTM_DELACTION
) {
166 return tcf_del_walker(hinfo
, skb
, ops
);
167 } else if (type
== RTM_GETACTION
) {
168 return tcf_dump_walker(hinfo
, skb
, cb
);
170 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
174 EXPORT_SYMBOL(tcf_generic_walker
);
176 static struct tc_action
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
178 struct tc_action
*p
= NULL
;
179 struct hlist_head
*head
;
181 spin_lock_bh(&hinfo
->lock
);
182 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
183 hlist_for_each_entry_rcu(p
, head
, tcfa_head
)
184 if (p
->tcfa_index
== index
)
186 spin_unlock_bh(&hinfo
->lock
);
191 u32
tcf_hash_new_index(struct tc_action_net
*tn
)
193 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
194 u32 val
= hinfo
->index
;
199 } while (tcf_hash_lookup(val
, hinfo
));
204 EXPORT_SYMBOL(tcf_hash_new_index
);
206 int tcf_hash_search(struct tc_action_net
*tn
, struct tc_action
**a
, u32 index
)
208 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
209 struct tc_action
*p
= tcf_hash_lookup(index
, hinfo
);
217 EXPORT_SYMBOL(tcf_hash_search
);
219 bool tcf_hash_check(struct tc_action_net
*tn
, u32 index
, struct tc_action
**a
,
222 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
223 struct tc_action
*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
)
239 gen_kill_estimator(&a
->tcfa_rate_est
);
240 call_rcu(&a
->tcfa_rcu
, free_tcf
);
242 EXPORT_SYMBOL(tcf_hash_cleanup
);
244 int tcf_hash_create(struct tc_action_net
*tn
, u32 index
, struct nlattr
*est
,
245 struct tc_action
**a
, const struct tc_action_ops
*ops
,
246 int bind
, bool cpustats
)
248 struct tc_action
*p
= kzalloc(ops
->size
, GFP_KERNEL
);
249 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
259 p
->cpu_bstats
= netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu
);
260 if (!p
->cpu_bstats
) {
265 p
->cpu_qstats
= alloc_percpu(struct gnet_stats_queue
);
266 if (!p
->cpu_qstats
) {
268 free_percpu(p
->cpu_bstats
);
272 spin_lock_init(&p
->tcfa_lock
);
273 INIT_HLIST_NODE(&p
->tcfa_head
);
274 p
->tcfa_index
= index
? index
: tcf_hash_new_index(tn
);
275 p
->tcfa_tm
.install
= jiffies
;
276 p
->tcfa_tm
.lastuse
= jiffies
;
277 p
->tcfa_tm
.firstuse
= 0;
279 err
= gen_new_estimator(&p
->tcfa_bstats
, p
->cpu_bstats
,
281 &p
->tcfa_lock
, NULL
, est
);
283 free_percpu(p
->cpu_qstats
);
290 INIT_LIST_HEAD(&p
->list
);
294 EXPORT_SYMBOL(tcf_hash_create
);
296 void tcf_hash_insert(struct tc_action_net
*tn
, struct tc_action
*a
)
298 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
299 unsigned int h
= tcf_hash(a
->tcfa_index
, hinfo
->hmask
);
301 spin_lock_bh(&hinfo
->lock
);
302 hlist_add_head(&a
->tcfa_head
, &hinfo
->htab
[h
]);
303 spin_unlock_bh(&hinfo
->lock
);
305 EXPORT_SYMBOL(tcf_hash_insert
);
307 void tcf_hashinfo_destroy(const struct tc_action_ops
*ops
,
308 struct tcf_hashinfo
*hinfo
)
312 for (i
= 0; i
< hinfo
->hmask
+ 1; i
++) {
314 struct hlist_node
*n
;
316 hlist_for_each_entry_safe(p
, n
, &hinfo
->htab
[i
], tcfa_head
) {
319 ret
= __tcf_hash_release(p
, false, true);
320 if (ret
== ACT_P_DELETED
)
321 module_put(ops
->owner
);
328 EXPORT_SYMBOL(tcf_hashinfo_destroy
);
330 static LIST_HEAD(act_base
);
331 static DEFINE_RWLOCK(act_mod_lock
);
333 int tcf_register_action(struct tc_action_ops
*act
,
334 struct pernet_operations
*ops
)
336 struct tc_action_ops
*a
;
339 if (!act
->act
|| !act
->dump
|| !act
->init
|| !act
->walk
|| !act
->lookup
)
342 /* We have to register pernet ops before making the action ops visible,
343 * otherwise tcf_action_init_1() could get a partially initialized
346 ret
= register_pernet_subsys(ops
);
350 write_lock(&act_mod_lock
);
351 list_for_each_entry(a
, &act_base
, head
) {
352 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
353 write_unlock(&act_mod_lock
);
354 unregister_pernet_subsys(ops
);
358 list_add_tail(&act
->head
, &act_base
);
359 write_unlock(&act_mod_lock
);
363 EXPORT_SYMBOL(tcf_register_action
);
365 int tcf_unregister_action(struct tc_action_ops
*act
,
366 struct pernet_operations
*ops
)
368 struct tc_action_ops
*a
;
371 write_lock(&act_mod_lock
);
372 list_for_each_entry(a
, &act_base
, head
) {
374 list_del(&act
->head
);
379 write_unlock(&act_mod_lock
);
381 unregister_pernet_subsys(ops
);
384 EXPORT_SYMBOL(tcf_unregister_action
);
387 static struct tc_action_ops
*tc_lookup_action_n(char *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 (strcmp(kind
, a
->kind
) == 0) {
395 if (try_module_get(a
->owner
))
400 read_unlock(&act_mod_lock
);
405 /* lookup by nlattr */
406 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
408 struct tc_action_ops
*a
, *res
= NULL
;
411 read_lock(&act_mod_lock
);
412 list_for_each_entry(a
, &act_base
, head
) {
413 if (nla_strcmp(kind
, a
->kind
) == 0) {
414 if (try_module_get(a
->owner
))
419 read_unlock(&act_mod_lock
);
424 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
**actions
,
425 int nr_actions
, struct tcf_result
*res
)
429 if (skb
->tc_verd
& TC_NCLS
) {
430 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
434 for (i
= 0; i
< nr_actions
; i
++) {
435 const struct tc_action
*a
= actions
[i
];
438 ret
= a
->ops
->act(skb
, a
, res
);
439 if (ret
== TC_ACT_REPEAT
)
440 goto repeat
; /* we need a ttl - JHS */
441 if (ret
!= TC_ACT_PIPE
)
447 EXPORT_SYMBOL(tcf_action_exec
);
449 int tcf_action_destroy(struct list_head
*actions
, int bind
)
451 struct tc_action
*a
, *tmp
;
454 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
455 ret
= __tcf_hash_release(a
, bind
, true);
456 if (ret
== ACT_P_DELETED
)
457 module_put(a
->ops
->owner
);
465 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
467 return a
->ops
->dump(skb
, a
, bind
, ref
);
471 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
474 unsigned char *b
= skb_tail_pointer(skb
);
477 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
478 goto nla_put_failure
;
479 if (tcf_action_copy_stats(skb
, a
, 0))
480 goto nla_put_failure
;
481 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
483 goto nla_put_failure
;
484 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
486 nla_nest_end(skb
, nest
);
494 EXPORT_SYMBOL(tcf_action_dump_1
);
496 int tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
,
503 list_for_each_entry(a
, actions
, list
) {
504 nest
= nla_nest_start(skb
, a
->order
);
506 goto nla_put_failure
;
507 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
510 nla_nest_end(skb
, nest
);
518 nla_nest_cancel(skb
, nest
);
522 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
523 struct nlattr
*est
, char *name
, int ovr
,
527 struct tc_action_ops
*a_o
;
528 char act_name
[IFNAMSIZ
];
529 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
534 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
538 kind
= tb
[TCA_ACT_KIND
];
541 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
545 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
549 a_o
= tc_lookup_action_n(act_name
);
551 #ifdef CONFIG_MODULES
553 request_module("act_%s", act_name
);
556 a_o
= tc_lookup_action_n(act_name
);
558 /* We dropped the RTNL semaphore in order to
559 * perform the module load. So, even if we
560 * succeeded in loading the module we have to
561 * tell the caller to replay the request. We
562 * indicate this using -EAGAIN.
573 /* backward compatibility for policer */
575 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, &a
, ovr
, bind
);
577 err
= a_o
->init(net
, nla
, est
, &a
, ovr
, bind
);
581 /* module count goes up only when brand new policy is created
582 * if it exists and is only bound to in a_o->init() then
583 * ACT_P_CREATED is not returned (a zero is).
585 if (err
!= ACT_P_CREATED
)
586 module_put(a_o
->owner
);
591 module_put(a_o
->owner
);
596 static void cleanup_a(struct list_head
*actions
, int ovr
)
603 list_for_each_entry(a
, actions
, list
)
607 int tcf_action_init(struct net
*net
, struct nlattr
*nla
, struct nlattr
*est
,
608 char *name
, int ovr
, int bind
, struct list_head
*actions
)
610 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
611 struct tc_action
*act
;
615 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
619 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
620 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
628 list_add_tail(&act
->list
, actions
);
631 /* Remove the temp refcnt which was necessary to protect against
632 * destroying an existing action which was being replaced
634 cleanup_a(actions
, ovr
);
638 tcf_action_destroy(actions
, bind
);
642 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*p
,
651 /* compat_mode being true specifies a call that is supposed
652 * to add additional backward compatibility statistic TLVs.
655 if (p
->type
== TCA_OLD_COMPAT
)
656 err
= gnet_stats_start_copy_compat(skb
, 0,
664 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
665 &p
->tcfa_lock
, &d
, TCA_ACT_PAD
);
670 if (gnet_stats_copy_basic(NULL
, &d
, p
->cpu_bstats
, &p
->tcfa_bstats
) < 0 ||
671 gnet_stats_copy_rate_est(&d
, &p
->tcfa_rate_est
) < 0 ||
672 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
674 p
->tcfa_qstats
.qlen
) < 0)
677 if (gnet_stats_finish_copy(&d
) < 0)
686 static int tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
,
687 u32 portid
, u32 seq
, u16 flags
, int event
, int bind
,
691 struct nlmsghdr
*nlh
;
692 unsigned char *b
= skb_tail_pointer(skb
);
695 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
699 t
->tca_family
= AF_UNSPEC
;
703 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
707 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
710 nla_nest_end(skb
, nest
);
712 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
721 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
722 struct list_head
*actions
, int event
)
726 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
729 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
,
735 return rtnl_unicast(skb
, net
, portid
);
738 static struct tc_action
*tcf_action_get_1(struct net
*net
, struct nlattr
*nla
,
739 struct nlmsghdr
*n
, u32 portid
)
741 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
742 const struct tc_action_ops
*ops
;
747 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
752 if (tb
[TCA_ACT_INDEX
] == NULL
||
753 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
755 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
758 ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
759 if (!ops
) /* could happen in batch of actions */
762 if (ops
->lookup(net
, &a
, index
) == 0)
765 module_put(ops
->owner
);
769 module_put(ops
->owner
);
774 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
775 struct nlmsghdr
*n
, u32 portid
)
779 struct nlmsghdr
*nlh
;
781 struct netlink_callback dcb
;
783 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
784 const struct tc_action_ops
*ops
;
788 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
790 pr_debug("tca_action_flush: failed skb alloc\n");
794 b
= skb_tail_pointer(skb
);
796 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
801 kind
= tb
[TCA_ACT_KIND
];
802 ops
= tc_lookup_action(kind
);
803 if (!ops
) /*some idjot trying to flush unknown action */
806 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
,
811 t
->tca_family
= AF_UNSPEC
;
815 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
819 err
= ops
->walk(net
, skb
, &dcb
, RTM_DELACTION
, ops
);
825 nla_nest_end(skb
, nest
);
827 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
828 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
829 module_put(ops
->owner
);
830 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
831 n
->nlmsg_flags
& NLM_F_ECHO
);
838 module_put(ops
->owner
);
846 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
852 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
856 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
862 /* now do the delete */
863 ret
= tcf_action_destroy(actions
, 0);
869 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
870 n
->nlmsg_flags
& NLM_F_ECHO
);
877 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
878 u32 portid
, int event
)
881 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
882 struct tc_action
*act
;
885 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
889 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
891 return tca_action_flush(net
, tb
[1], n
, portid
);
896 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
897 act
= tcf_action_get_1(net
, tb
[i
], n
, portid
);
903 list_add_tail(&act
->list
, &actions
);
906 if (event
== RTM_GETACTION
)
907 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
909 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
915 if (event
!= RTM_GETACTION
)
916 tcf_action_destroy(&actions
, 0);
921 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
927 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
931 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
932 RTM_NEWACTION
, 0, 0) <= 0) {
937 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
938 n
->nlmsg_flags
& NLM_F_ECHO
);
944 static int tcf_action_add(struct net
*net
, struct nlattr
*nla
,
945 struct nlmsghdr
*n
, u32 portid
, int ovr
)
950 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
954 return tcf_add_notify(net
, n
, &actions
, portid
);
957 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
959 struct net
*net
= sock_net(skb
->sk
);
960 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
961 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
962 int ret
= 0, ovr
= 0;
964 if ((n
->nlmsg_type
!= RTM_GETACTION
) &&
965 !netlink_capable(skb
, CAP_NET_ADMIN
))
968 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
972 if (tca
[TCA_ACT_TAB
] == NULL
) {
973 pr_notice("tc_ctl_action: received NO action attribs\n");
977 /* n->nlmsg_flags & NLM_F_CREATE */
978 switch (n
->nlmsg_type
) {
980 /* we are going to assume all other flags
981 * imply create only if it doesn't exist
982 * Note that CREATE | EXCL implies that
983 * but since we want avoid ambiguity (eg when flags
984 * is zero) then just set this
986 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
989 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
994 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
995 portid
, RTM_DELACTION
);
998 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
999 portid
, RTM_GETACTION
);
1008 static struct nlattr
*find_dump_kind(const struct nlmsghdr
*n
)
1010 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1011 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1012 struct nlattr
*nla
[TCAA_MAX
+ 1];
1013 struct nlattr
*kind
;
1015 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1017 tb1
= nla
[TCA_ACT_TAB
];
1021 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1022 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1027 if (nla_parse_nested(tb2
, TCA_ACT_MAX
, tb
[1], NULL
) < 0)
1029 kind
= tb2
[TCA_ACT_KIND
];
1034 static int tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1036 struct net
*net
= sock_net(skb
->sk
);
1037 struct nlmsghdr
*nlh
;
1038 unsigned char *b
= skb_tail_pointer(skb
);
1039 struct nlattr
*nest
;
1040 struct tc_action_ops
*a_o
;
1042 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1043 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1046 pr_info("tc_dump_action: action bad kind\n");
1050 a_o
= tc_lookup_action(kind
);
1054 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1055 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1057 goto out_module_put
;
1058 t
= nlmsg_data(nlh
);
1059 t
->tca_family
= AF_UNSPEC
;
1063 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1065 goto out_module_put
;
1067 ret
= a_o
->walk(net
, skb
, cb
, RTM_GETACTION
, a_o
);
1069 goto out_module_put
;
1072 nla_nest_end(skb
, nest
);
1077 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1078 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1079 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1080 module_put(a_o
->owner
);
1084 module_put(a_o
->owner
);
1089 static int __init
tc_action_init(void)
1091 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1092 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1093 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1099 subsys_initcall(tc_action_init
);