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 tcf_hashinfo
*hinfo
, struct tc_action
*a
)
41 struct tcf_common
*p
= a
->priv
;
43 spin_lock_bh(&hinfo
->lock
);
44 hlist_del(&p
->tcfc_head
);
45 spin_unlock_bh(&hinfo
->lock
);
46 gen_kill_estimator(&p
->tcfc_bstats
,
49 * gen_estimator est_timer() might access p->tcfc_lock
50 * or bstats, wait a RCU grace period before freeing p
52 call_rcu(&p
->tcfc_rcu
, free_tcf
);
55 int __tcf_hash_release(struct tc_action
*a
, bool bind
, bool strict
)
57 struct tcf_common
*p
= a
->priv
;
63 else if (strict
&& p
->tcfc_bindcnt
> 0)
67 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
69 a
->ops
->cleanup(a
, bind
);
70 tcf_hash_destroy(a
->hinfo
, a
);
77 EXPORT_SYMBOL(__tcf_hash_release
);
79 static int tcf_dump_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
80 struct netlink_callback
*cb
, struct tc_action
*a
)
82 struct hlist_head
*head
;
84 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
87 spin_lock_bh(&hinfo
->lock
);
91 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
92 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
94 hlist_for_each_entry_rcu(p
, head
, tcfc_head
) {
101 nest
= nla_nest_start(skb
, a
->order
);
103 goto nla_put_failure
;
104 err
= tcf_action_dump_1(skb
, a
, 0, 0);
107 nlmsg_trim(skb
, nest
);
110 nla_nest_end(skb
, nest
);
112 if (n_i
>= TCA_ACT_MAX_PRIO
)
117 spin_unlock_bh(&hinfo
->lock
);
123 nla_nest_cancel(skb
, nest
);
127 static int tcf_del_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
130 struct hlist_head
*head
;
131 struct hlist_node
*n
;
132 struct tcf_common
*p
;
137 nest
= nla_nest_start(skb
, a
->order
);
139 goto nla_put_failure
;
140 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
141 goto nla_put_failure
;
142 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
143 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
144 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
146 ret
= __tcf_hash_release(a
, false, true);
147 if (ret
== ACT_P_DELETED
) {
148 module_put(a
->ops
->owner
);
151 goto nla_put_failure
;
154 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
155 goto nla_put_failure
;
156 nla_nest_end(skb
, nest
);
160 nla_nest_cancel(skb
, nest
);
164 int tcf_generic_walker(struct tc_action_net
*tn
, struct sk_buff
*skb
,
165 struct netlink_callback
*cb
, int type
,
168 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
172 if (type
== RTM_DELACTION
) {
173 return tcf_del_walker(hinfo
, skb
, a
);
174 } else if (type
== RTM_GETACTION
) {
175 return tcf_dump_walker(hinfo
, skb
, cb
, a
);
177 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
181 EXPORT_SYMBOL(tcf_generic_walker
);
183 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
185 struct tcf_common
*p
= NULL
;
186 struct hlist_head
*head
;
188 spin_lock_bh(&hinfo
->lock
);
189 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
190 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
191 if (p
->tcfc_index
== index
)
193 spin_unlock_bh(&hinfo
->lock
);
198 u32
tcf_hash_new_index(struct tc_action_net
*tn
)
200 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
201 u32 val
= hinfo
->index
;
206 } while (tcf_hash_lookup(val
, hinfo
));
211 EXPORT_SYMBOL(tcf_hash_new_index
);
213 int tcf_hash_search(struct tc_action_net
*tn
, struct tc_action
*a
, u32 index
)
215 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
216 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
225 EXPORT_SYMBOL(tcf_hash_search
);
227 int tcf_hash_check(struct tc_action_net
*tn
, u32 index
, struct tc_action
*a
,
230 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
231 struct tcf_common
*p
= NULL
;
232 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
242 EXPORT_SYMBOL(tcf_hash_check
);
244 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
246 struct tcf_common
*pc
= a
->priv
;
248 gen_kill_estimator(&pc
->tcfc_bstats
,
250 call_rcu(&pc
->tcfc_rcu
, free_tcf
);
252 EXPORT_SYMBOL(tcf_hash_cleanup
);
254 int tcf_hash_create(struct tc_action_net
*tn
, u32 index
, struct nlattr
*est
,
255 struct tc_action
*a
, int size
, int bind
, bool cpustats
)
257 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
258 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
268 p
->cpu_bstats
= netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu
);
269 if (!p
->cpu_bstats
) {
274 p
->cpu_qstats
= alloc_percpu(struct gnet_stats_queue
);
275 if (!p
->cpu_qstats
) {
277 free_percpu(p
->cpu_bstats
);
281 spin_lock_init(&p
->tcfc_lock
);
282 INIT_HLIST_NODE(&p
->tcfc_head
);
283 p
->tcfc_index
= index
? index
: tcf_hash_new_index(tn
);
284 p
->tcfc_tm
.install
= jiffies
;
285 p
->tcfc_tm
.lastuse
= jiffies
;
286 p
->tcfc_tm
.firstuse
= 0;
288 err
= gen_new_estimator(&p
->tcfc_bstats
, p
->cpu_bstats
,
292 free_percpu(p
->cpu_qstats
);
297 a
->priv
= (void *) p
;
301 EXPORT_SYMBOL(tcf_hash_create
);
303 void tcf_hash_insert(struct tc_action_net
*tn
, struct tc_action
*a
)
305 struct tcf_common
*p
= a
->priv
;
306 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
307 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
309 spin_lock_bh(&hinfo
->lock
);
310 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
311 spin_unlock_bh(&hinfo
->lock
);
313 EXPORT_SYMBOL(tcf_hash_insert
);
315 void tcf_hashinfo_destroy(const struct tc_action_ops
*ops
,
316 struct tcf_hashinfo
*hinfo
)
318 struct tc_action a
= {
324 for (i
= 0; i
< hinfo
->hmask
+ 1; i
++) {
325 struct tcf_common
*p
;
326 struct hlist_node
*n
;
328 hlist_for_each_entry_safe(p
, n
, &hinfo
->htab
[i
], tcfc_head
) {
332 ret
= __tcf_hash_release(&a
, false, true);
333 if (ret
== ACT_P_DELETED
)
334 module_put(ops
->owner
);
341 EXPORT_SYMBOL(tcf_hashinfo_destroy
);
343 static LIST_HEAD(act_base
);
344 static DEFINE_RWLOCK(act_mod_lock
);
346 int tcf_register_action(struct tc_action_ops
*act
,
347 struct pernet_operations
*ops
)
349 struct tc_action_ops
*a
;
352 if (!act
->act
|| !act
->dump
|| !act
->init
|| !act
->walk
|| !act
->lookup
)
355 write_lock(&act_mod_lock
);
356 list_for_each_entry(a
, &act_base
, head
) {
357 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
358 write_unlock(&act_mod_lock
);
362 list_add_tail(&act
->head
, &act_base
);
363 write_unlock(&act_mod_lock
);
365 ret
= register_pernet_subsys(ops
);
367 tcf_unregister_action(act
, ops
);
373 EXPORT_SYMBOL(tcf_register_action
);
375 int tcf_unregister_action(struct tc_action_ops
*act
,
376 struct pernet_operations
*ops
)
378 struct tc_action_ops
*a
;
381 unregister_pernet_subsys(ops
);
383 write_lock(&act_mod_lock
);
384 list_for_each_entry(a
, &act_base
, head
) {
386 list_del(&act
->head
);
391 write_unlock(&act_mod_lock
);
394 EXPORT_SYMBOL(tcf_unregister_action
);
397 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
399 struct tc_action_ops
*a
, *res
= NULL
;
402 read_lock(&act_mod_lock
);
403 list_for_each_entry(a
, &act_base
, head
) {
404 if (strcmp(kind
, a
->kind
) == 0) {
405 if (try_module_get(a
->owner
))
410 read_unlock(&act_mod_lock
);
415 /* lookup by nlattr */
416 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
418 struct tc_action_ops
*a
, *res
= NULL
;
421 read_lock(&act_mod_lock
);
422 list_for_each_entry(a
, &act_base
, head
) {
423 if (nla_strcmp(kind
, a
->kind
) == 0) {
424 if (try_module_get(a
->owner
))
429 read_unlock(&act_mod_lock
);
434 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
435 struct tcf_result
*res
)
437 const struct tc_action
*a
;
440 if (skb
->tc_verd
& TC_NCLS
) {
441 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
445 list_for_each_entry(a
, actions
, list
) {
447 ret
= a
->ops
->act(skb
, a
, res
);
448 if (ret
== TC_ACT_REPEAT
)
449 goto repeat
; /* we need a ttl - JHS */
450 if (ret
!= TC_ACT_PIPE
)
456 EXPORT_SYMBOL(tcf_action_exec
);
458 int tcf_action_destroy(struct list_head
*actions
, int bind
)
460 struct tc_action
*a
, *tmp
;
463 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
464 ret
= __tcf_hash_release(a
, bind
, true);
465 if (ret
== ACT_P_DELETED
)
466 module_put(a
->ops
->owner
);
476 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
478 return a
->ops
->dump(skb
, a
, bind
, ref
);
482 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
485 unsigned char *b
= skb_tail_pointer(skb
);
488 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
489 goto nla_put_failure
;
490 if (tcf_action_copy_stats(skb
, a
, 0))
491 goto nla_put_failure
;
492 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
494 goto nla_put_failure
;
495 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
497 nla_nest_end(skb
, nest
);
505 EXPORT_SYMBOL(tcf_action_dump_1
);
507 int tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
,
514 list_for_each_entry(a
, actions
, list
) {
515 nest
= nla_nest_start(skb
, a
->order
);
517 goto nla_put_failure
;
518 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
521 nla_nest_end(skb
, nest
);
529 nla_nest_cancel(skb
, nest
);
533 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
534 struct nlattr
*est
, char *name
, int ovr
,
538 struct tc_action_ops
*a_o
;
539 char act_name
[IFNAMSIZ
];
540 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
545 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
549 kind
= tb
[TCA_ACT_KIND
];
552 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
556 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
560 a_o
= tc_lookup_action_n(act_name
);
562 #ifdef CONFIG_MODULES
564 request_module("act_%s", act_name
);
567 a_o
= tc_lookup_action_n(act_name
);
569 /* We dropped the RTNL semaphore in order to
570 * perform the module load. So, even if we
571 * succeeded in loading the module we have to
572 * tell the caller to replay the request. We
573 * indicate this using -EAGAIN.
585 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
590 INIT_LIST_HEAD(&a
->list
);
591 /* backward compatibility for policer */
593 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
595 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
599 /* module count goes up only when brand new policy is created
600 * if it exists and is only bound to in a_o->init() then
601 * ACT_P_CREATED is not returned (a zero is).
603 if (err
!= ACT_P_CREATED
)
604 module_put(a_o
->owner
);
611 module_put(a_o
->owner
);
616 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
617 struct nlattr
*est
, char *name
, int ovr
,
618 int bind
, struct list_head
*actions
)
620 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
621 struct tc_action
*act
;
625 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
629 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
630 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
636 list_add_tail(&act
->list
, actions
);
641 tcf_action_destroy(actions
, bind
);
645 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
650 struct tcf_common
*p
= a
->priv
;
655 /* compat_mode being true specifies a call that is supposed
656 * to add additional backward compatibility statistic TLVs.
659 if (a
->type
== TCA_OLD_COMPAT
)
660 err
= gnet_stats_start_copy_compat(skb
, 0,
668 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
669 &p
->tcfc_lock
, &d
, TCA_ACT_PAD
);
674 if (gnet_stats_copy_basic(&d
, p
->cpu_bstats
, &p
->tcfc_bstats
) < 0 ||
675 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
676 &p
->tcfc_rate_est
) < 0 ||
677 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
679 p
->tcfc_qstats
.qlen
) < 0)
682 if (gnet_stats_finish_copy(&d
) < 0)
691 static int tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
,
692 u32 portid
, u32 seq
, u16 flags
, int event
, int bind
,
696 struct nlmsghdr
*nlh
;
697 unsigned char *b
= skb_tail_pointer(skb
);
700 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
704 t
->tca_family
= AF_UNSPEC
;
708 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
712 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
715 nla_nest_end(skb
, nest
);
717 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
726 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
727 struct list_head
*actions
, int event
)
731 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
734 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
,
740 return rtnl_unicast(skb
, net
, portid
);
743 static struct tc_action
*create_a(int i
)
745 struct tc_action
*act
;
747 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
749 pr_debug("create_a: failed to alloc!\n");
753 INIT_LIST_HEAD(&act
->list
);
757 static struct tc_action
*tcf_action_get_1(struct net
*net
, struct nlattr
*nla
,
758 struct nlmsghdr
*n
, u32 portid
)
760 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
765 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
770 if (tb
[TCA_ACT_INDEX
] == NULL
||
771 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
773 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
781 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
782 if (a
->ops
== NULL
) /* could happen in batch of actions */
785 if (a
->ops
->lookup(net
, a
, index
) == 0)
788 module_put(a
->ops
->owner
);
792 module_put(a
->ops
->owner
);
799 static void cleanup_a(struct list_head
*actions
)
801 struct tc_action
*a
, *tmp
;
803 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
809 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
810 struct nlmsghdr
*n
, u32 portid
)
814 struct nlmsghdr
*nlh
;
816 struct netlink_callback dcb
;
818 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
823 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
825 pr_debug("tca_action_flush: failed skb alloc\n");
829 b
= skb_tail_pointer(skb
);
831 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
836 kind
= tb
[TCA_ACT_KIND
];
837 memset(&a
, 0, sizeof(struct tc_action
));
838 INIT_LIST_HEAD(&a
.list
);
839 a
.ops
= tc_lookup_action(kind
);
840 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
843 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
,
848 t
->tca_family
= AF_UNSPEC
;
852 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
856 err
= a
.ops
->walk(net
, skb
, &dcb
, RTM_DELACTION
, &a
);
862 nla_nest_end(skb
, nest
);
864 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
865 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
866 module_put(a
.ops
->owner
);
867 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
868 n
->nlmsg_flags
& NLM_F_ECHO
);
875 module_put(a
.ops
->owner
);
883 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
889 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
893 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
899 /* now do the delete */
900 ret
= tcf_action_destroy(actions
, 0);
906 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
907 n
->nlmsg_flags
& NLM_F_ECHO
);
914 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
915 u32 portid
, int event
)
918 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
919 struct tc_action
*act
;
922 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
926 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
928 return tca_action_flush(net
, tb
[1], n
, portid
);
933 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
934 act
= tcf_action_get_1(net
, tb
[i
], n
, portid
);
940 list_add_tail(&act
->list
, &actions
);
943 if (event
== RTM_GETACTION
)
944 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
946 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
957 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
963 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
967 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
968 RTM_NEWACTION
, 0, 0) <= 0) {
973 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
974 n
->nlmsg_flags
& NLM_F_ECHO
);
981 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
987 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
991 /* dump then free all the actions after update; inserted policy
994 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
1000 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
1002 struct net
*net
= sock_net(skb
->sk
);
1003 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
1004 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
1005 int ret
= 0, ovr
= 0;
1007 if ((n
->nlmsg_type
!= RTM_GETACTION
) &&
1008 !netlink_capable(skb
, CAP_NET_ADMIN
))
1011 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
1015 if (tca
[TCA_ACT_TAB
] == NULL
) {
1016 pr_notice("tc_ctl_action: received NO action attribs\n");
1020 /* n->nlmsg_flags & NLM_F_CREATE */
1021 switch (n
->nlmsg_type
) {
1023 /* we are going to assume all other flags
1024 * imply create only if it doesn't exist
1025 * Note that CREATE | EXCL implies that
1026 * but since we want avoid ambiguity (eg when flags
1027 * is zero) then just set this
1029 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
1032 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
1037 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1038 portid
, RTM_DELACTION
);
1041 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1042 portid
, RTM_GETACTION
);
1051 static struct nlattr
*
1052 find_dump_kind(const struct nlmsghdr
*n
)
1054 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1055 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1056 struct nlattr
*nla
[TCAA_MAX
+ 1];
1057 struct nlattr
*kind
;
1059 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1061 tb1
= nla
[TCA_ACT_TAB
];
1065 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1066 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1071 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1072 nla_len(tb
[1]), NULL
) < 0)
1074 kind
= tb2
[TCA_ACT_KIND
];
1080 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1082 struct net
*net
= sock_net(skb
->sk
);
1083 struct nlmsghdr
*nlh
;
1084 unsigned char *b
= skb_tail_pointer(skb
);
1085 struct nlattr
*nest
;
1086 struct tc_action_ops
*a_o
;
1089 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1090 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1093 pr_info("tc_dump_action: action bad kind\n");
1097 a_o
= tc_lookup_action(kind
);
1101 memset(&a
, 0, sizeof(struct tc_action
));
1104 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1105 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1107 goto out_module_put
;
1108 t
= nlmsg_data(nlh
);
1109 t
->tca_family
= AF_UNSPEC
;
1113 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1115 goto out_module_put
;
1117 ret
= a_o
->walk(net
, skb
, cb
, RTM_GETACTION
, &a
);
1119 goto out_module_put
;
1122 nla_nest_end(skb
, nest
);
1125 nla_nest_cancel(skb
, nest
);
1127 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1128 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1129 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1130 module_put(a_o
->owner
);
1134 module_put(a_o
->owner
);
1139 static int __init
tc_action_init(void)
1141 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1142 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1143 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1149 subsys_initcall(tc_action_init
);
This page took 0.053687 seconds and 6 git commands to generate.