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_bstats
,
47 * gen_estimator est_timer() might access p->tcfa_lock
48 * or bstats, wait a RCU grace period before freeing p
50 call_rcu(&p
->tcfa_rcu
, free_tcf
);
53 int __tcf_hash_release(struct tc_action
*p
, bool bind
, bool strict
)
60 else if (strict
&& p
->tcfa_bindcnt
> 0)
64 if (p
->tcfa_bindcnt
<= 0 && p
->tcfa_refcnt
<= 0) {
66 p
->ops
->cleanup(p
, bind
);
68 tcf_hash_destroy(p
->hinfo
, p
);
75 EXPORT_SYMBOL(__tcf_hash_release
);
77 static int tcf_dump_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
78 struct netlink_callback
*cb
)
80 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
83 spin_lock_bh(&hinfo
->lock
);
87 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
88 struct hlist_head
*head
;
91 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
93 hlist_for_each_entry_rcu(p
, head
, tcfa_head
) {
98 nest
= nla_nest_start(skb
, n_i
);
100 goto nla_put_failure
;
101 err
= tcf_action_dump_1(skb
, p
, 0, 0);
104 nlmsg_trim(skb
, nest
);
107 nla_nest_end(skb
, nest
);
109 if (n_i
>= TCA_ACT_MAX_PRIO
)
114 spin_unlock_bh(&hinfo
->lock
);
120 nla_nest_cancel(skb
, nest
);
124 static int tcf_del_walker(struct tcf_hashinfo
*hinfo
, struct sk_buff
*skb
,
125 const struct tc_action_ops
*ops
)
131 nest
= nla_nest_start(skb
, 0);
133 goto nla_put_failure
;
134 if (nla_put_string(skb
, TCA_KIND
, ops
->kind
))
135 goto nla_put_failure
;
136 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
137 struct hlist_head
*head
;
138 struct hlist_node
*n
;
141 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
142 hlist_for_each_entry_safe(p
, n
, head
, tcfa_head
) {
143 ret
= __tcf_hash_release(p
, false, true);
144 if (ret
== ACT_P_DELETED
) {
145 module_put(p
->ops
->owner
);
148 goto nla_put_failure
;
151 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
152 goto nla_put_failure
;
153 nla_nest_end(skb
, nest
);
157 nla_nest_cancel(skb
, nest
);
161 int tcf_generic_walker(struct tc_action_net
*tn
, struct sk_buff
*skb
,
162 struct netlink_callback
*cb
, int type
,
163 const struct tc_action_ops
*ops
)
165 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
167 if (type
== RTM_DELACTION
) {
168 return tcf_del_walker(hinfo
, skb
, ops
);
169 } else if (type
== RTM_GETACTION
) {
170 return tcf_dump_walker(hinfo
, skb
, cb
);
172 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
176 EXPORT_SYMBOL(tcf_generic_walker
);
178 static struct tc_action
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
180 struct tc_action
*p
= NULL
;
181 struct hlist_head
*head
;
183 spin_lock_bh(&hinfo
->lock
);
184 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
185 hlist_for_each_entry_rcu(p
, head
, tcfa_head
)
186 if (p
->tcfa_index
== index
)
188 spin_unlock_bh(&hinfo
->lock
);
193 u32
tcf_hash_new_index(struct tc_action_net
*tn
)
195 struct tcf_hashinfo
*hinfo
= tn
->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_net
*tn
, struct tc_action
**a
, u32 index
)
210 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
211 struct tc_action
*p
= tcf_hash_lookup(index
, hinfo
);
219 EXPORT_SYMBOL(tcf_hash_search
);
221 bool tcf_hash_check(struct tc_action_net
*tn
, u32 index
, struct tc_action
**a
,
224 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
225 struct tc_action
*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
)
241 gen_kill_estimator(&a
->tcfa_bstats
,
243 call_rcu(&a
->tcfa_rcu
, free_tcf
);
245 EXPORT_SYMBOL(tcf_hash_cleanup
);
247 int tcf_hash_create(struct tc_action_net
*tn
, u32 index
, struct nlattr
*est
,
248 struct tc_action
**a
, const struct tc_action_ops
*ops
,
249 int bind
, bool cpustats
)
251 struct tc_action
*p
= kzalloc(ops
->size
, GFP_KERNEL
);
252 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
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
->tcfa_lock
);
276 INIT_HLIST_NODE(&p
->tcfa_head
);
277 p
->tcfa_index
= index
? index
: tcf_hash_new_index(tn
);
278 p
->tcfa_tm
.install
= jiffies
;
279 p
->tcfa_tm
.lastuse
= jiffies
;
280 p
->tcfa_tm
.firstuse
= 0;
282 err
= gen_new_estimator(&p
->tcfa_bstats
, p
->cpu_bstats
,
284 &p
->tcfa_lock
, NULL
, est
);
286 free_percpu(p
->cpu_qstats
);
293 INIT_LIST_HEAD(&p
->list
);
297 EXPORT_SYMBOL(tcf_hash_create
);
299 void tcf_hash_insert(struct tc_action_net
*tn
, struct tc_action
*a
)
301 struct tcf_hashinfo
*hinfo
= tn
->hinfo
;
302 unsigned int h
= tcf_hash(a
->tcfa_index
, hinfo
->hmask
);
304 spin_lock_bh(&hinfo
->lock
);
305 hlist_add_head(&a
->tcfa_head
, &hinfo
->htab
[h
]);
306 spin_unlock_bh(&hinfo
->lock
);
308 EXPORT_SYMBOL(tcf_hash_insert
);
310 void tcf_hashinfo_destroy(const struct tc_action_ops
*ops
,
311 struct tcf_hashinfo
*hinfo
)
315 for (i
= 0; i
< hinfo
->hmask
+ 1; i
++) {
317 struct hlist_node
*n
;
319 hlist_for_each_entry_safe(p
, n
, &hinfo
->htab
[i
], tcfa_head
) {
322 ret
= __tcf_hash_release(p
, false, true);
323 if (ret
== ACT_P_DELETED
)
324 module_put(ops
->owner
);
331 EXPORT_SYMBOL(tcf_hashinfo_destroy
);
333 static LIST_HEAD(act_base
);
334 static DEFINE_RWLOCK(act_mod_lock
);
336 int tcf_register_action(struct tc_action_ops
*act
,
337 struct pernet_operations
*ops
)
339 struct tc_action_ops
*a
;
342 if (!act
->act
|| !act
->dump
|| !act
->init
|| !act
->walk
|| !act
->lookup
)
345 write_lock(&act_mod_lock
);
346 list_for_each_entry(a
, &act_base
, head
) {
347 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
348 write_unlock(&act_mod_lock
);
352 list_add_tail(&act
->head
, &act_base
);
353 write_unlock(&act_mod_lock
);
355 ret
= register_pernet_subsys(ops
);
357 tcf_unregister_action(act
, ops
);
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 unregister_pernet_subsys(ops
);
373 write_lock(&act_mod_lock
);
374 list_for_each_entry(a
, &act_base
, head
) {
376 list_del(&act
->head
);
381 write_unlock(&act_mod_lock
);
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
, const struct list_head
*actions
,
425 struct tcf_result
*res
)
427 const struct tc_action
*a
;
430 if (skb
->tc_verd
& TC_NCLS
) {
431 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
435 list_for_each_entry(a
, actions
, list
) {
437 ret
= a
->ops
->act(skb
, a
, res
);
438 if (ret
== TC_ACT_REPEAT
)
439 goto repeat
; /* we need a ttl - JHS */
440 if (ret
!= TC_ACT_PIPE
)
446 EXPORT_SYMBOL(tcf_action_exec
);
448 int tcf_action_destroy(struct list_head
*actions
, int bind
)
450 struct tc_action
*a
, *tmp
;
453 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
454 ret
= __tcf_hash_release(a
, bind
, true);
455 if (ret
== ACT_P_DELETED
)
456 module_put(a
->ops
->owner
);
464 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
466 return a
->ops
->dump(skb
, a
, bind
, ref
);
470 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
473 unsigned char *b
= skb_tail_pointer(skb
);
476 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
477 goto nla_put_failure
;
478 if (tcf_action_copy_stats(skb
, a
, 0))
479 goto nla_put_failure
;
480 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
482 goto nla_put_failure
;
483 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
485 nla_nest_end(skb
, nest
);
493 EXPORT_SYMBOL(tcf_action_dump_1
);
495 int tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
,
502 list_for_each_entry(a
, actions
, list
) {
503 nest
= nla_nest_start(skb
, a
->order
);
505 goto nla_put_failure
;
506 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
509 nla_nest_end(skb
, nest
);
517 nla_nest_cancel(skb
, nest
);
521 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
522 struct nlattr
*est
, char *name
, int ovr
,
526 struct tc_action_ops
*a_o
;
527 char act_name
[IFNAMSIZ
];
528 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
533 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
537 kind
= tb
[TCA_ACT_KIND
];
540 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
544 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
548 a_o
= tc_lookup_action_n(act_name
);
550 #ifdef CONFIG_MODULES
552 request_module("act_%s", act_name
);
555 a_o
= tc_lookup_action_n(act_name
);
557 /* We dropped the RTNL semaphore in order to
558 * perform the module load. So, even if we
559 * succeeded in loading the module we have to
560 * tell the caller to replay the request. We
561 * indicate this using -EAGAIN.
572 /* backward compatibility for policer */
574 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, &a
, ovr
, bind
);
576 err
= a_o
->init(net
, nla
, est
, &a
, ovr
, bind
);
580 /* module count goes up only when brand new policy is created
581 * if it exists and is only bound to in a_o->init() then
582 * ACT_P_CREATED is not returned (a zero is).
584 if (err
!= ACT_P_CREATED
)
585 module_put(a_o
->owner
);
590 module_put(a_o
->owner
);
595 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
596 struct nlattr
*est
, char *name
, int ovr
,
597 int bind
, struct list_head
*actions
)
599 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
600 struct tc_action
*act
;
604 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
608 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
609 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
615 list_add_tail(&act
->list
, actions
);
620 tcf_action_destroy(actions
, bind
);
624 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*p
,
633 /* compat_mode being true specifies a call that is supposed
634 * to add additional backward compatibility statistic TLVs.
637 if (p
->type
== TCA_OLD_COMPAT
)
638 err
= gnet_stats_start_copy_compat(skb
, 0,
646 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
647 &p
->tcfa_lock
, &d
, TCA_ACT_PAD
);
652 if (gnet_stats_copy_basic(NULL
, &d
, p
->cpu_bstats
, &p
->tcfa_bstats
) < 0 ||
653 gnet_stats_copy_rate_est(&d
, &p
->tcfa_bstats
,
654 &p
->tcfa_rate_est
) < 0 ||
655 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
657 p
->tcfa_qstats
.qlen
) < 0)
660 if (gnet_stats_finish_copy(&d
) < 0)
669 static int tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
,
670 u32 portid
, u32 seq
, u16 flags
, int event
, int bind
,
674 struct nlmsghdr
*nlh
;
675 unsigned char *b
= skb_tail_pointer(skb
);
678 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
682 t
->tca_family
= AF_UNSPEC
;
686 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
690 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
693 nla_nest_end(skb
, nest
);
695 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
704 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
705 struct list_head
*actions
, int event
)
709 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
712 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
,
718 return rtnl_unicast(skb
, net
, portid
);
721 static struct tc_action
*tcf_action_get_1(struct net
*net
, struct nlattr
*nla
,
722 struct nlmsghdr
*n
, u32 portid
)
724 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
725 const struct tc_action_ops
*ops
;
730 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
735 if (tb
[TCA_ACT_INDEX
] == NULL
||
736 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
738 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
741 ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
742 if (!ops
) /* could happen in batch of actions */
745 if (ops
->lookup(net
, &a
, index
) == 0)
748 module_put(ops
->owner
);
752 module_put(ops
->owner
);
757 static void cleanup_a(struct list_head
*actions
)
759 struct tc_action
*a
, *tmp
;
761 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
767 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
768 struct nlmsghdr
*n
, u32 portid
)
772 struct nlmsghdr
*nlh
;
774 struct netlink_callback dcb
;
776 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
777 const struct tc_action_ops
*ops
;
781 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
783 pr_debug("tca_action_flush: failed skb alloc\n");
787 b
= skb_tail_pointer(skb
);
789 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
794 kind
= tb
[TCA_ACT_KIND
];
795 ops
= tc_lookup_action(kind
);
796 if (!ops
) /*some idjot trying to flush unknown action */
799 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
,
804 t
->tca_family
= AF_UNSPEC
;
808 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
812 err
= ops
->walk(net
, skb
, &dcb
, RTM_DELACTION
, ops
);
818 nla_nest_end(skb
, nest
);
820 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
821 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
822 module_put(ops
->owner
);
823 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
824 n
->nlmsg_flags
& NLM_F_ECHO
);
831 module_put(ops
->owner
);
839 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
845 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
849 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
855 /* now do the delete */
856 ret
= tcf_action_destroy(actions
, 0);
862 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
863 n
->nlmsg_flags
& NLM_F_ECHO
);
870 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
871 u32 portid
, int event
)
874 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
875 struct tc_action
*act
;
878 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
882 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
884 return tca_action_flush(net
, tb
[1], n
, portid
);
889 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
890 act
= tcf_action_get_1(net
, tb
[i
], n
, portid
);
896 list_add_tail(&act
->list
, &actions
);
899 if (event
== RTM_GETACTION
)
900 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
902 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
913 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
919 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
923 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
924 RTM_NEWACTION
, 0, 0) <= 0) {
929 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
930 n
->nlmsg_flags
& NLM_F_ECHO
);
937 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
943 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
947 /* dump then free all the actions after update; inserted policy
950 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
956 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
958 struct net
*net
= sock_net(skb
->sk
);
959 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
960 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
961 int ret
= 0, ovr
= 0;
963 if ((n
->nlmsg_type
!= RTM_GETACTION
) &&
964 !netlink_capable(skb
, CAP_NET_ADMIN
))
967 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
971 if (tca
[TCA_ACT_TAB
] == NULL
) {
972 pr_notice("tc_ctl_action: received NO action attribs\n");
976 /* n->nlmsg_flags & NLM_F_CREATE */
977 switch (n
->nlmsg_type
) {
979 /* we are going to assume all other flags
980 * imply create only if it doesn't exist
981 * Note that CREATE | EXCL implies that
982 * but since we want avoid ambiguity (eg when flags
983 * is zero) then just set this
985 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
988 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
993 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
994 portid
, RTM_DELACTION
);
997 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
998 portid
, RTM_GETACTION
);
1007 static struct nlattr
*
1008 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(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1028 nla_len(tb
[1]), NULL
) < 0)
1030 kind
= tb2
[TCA_ACT_KIND
];
1036 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1038 struct net
*net
= sock_net(skb
->sk
);
1039 struct nlmsghdr
*nlh
;
1040 unsigned char *b
= skb_tail_pointer(skb
);
1041 struct nlattr
*nest
;
1042 struct tc_action_ops
*a_o
;
1044 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1045 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1048 pr_info("tc_dump_action: action bad kind\n");
1052 a_o
= tc_lookup_action(kind
);
1056 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1057 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1059 goto out_module_put
;
1060 t
= nlmsg_data(nlh
);
1061 t
->tca_family
= AF_UNSPEC
;
1065 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1067 goto out_module_put
;
1069 ret
= a_o
->walk(net
, skb
, cb
, RTM_GETACTION
, a_o
);
1071 goto out_module_put
;
1074 nla_nest_end(skb
, nest
);
1079 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1080 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1081 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1082 module_put(a_o
->owner
);
1086 module_put(a_o
->owner
);
1091 static int __init
tc_action_init(void)
1093 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1094 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1095 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1101 subsys_initcall(tc_action_init
);
This page took 0.05411 seconds and 6 git commands to generate.