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 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
);
55 EXPORT_SYMBOL(tcf_hash_destroy
);
57 int __tcf_hash_release(struct tc_action
*a
, bool bind
, bool strict
)
59 struct tcf_common
*p
= a
->priv
;
65 else if (strict
&& p
->tcfc_bindcnt
> 0)
69 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
71 a
->ops
->cleanup(a
, bind
);
79 EXPORT_SYMBOL(__tcf_hash_release
);
81 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
84 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
85 struct hlist_head
*head
;
87 int err
= 0, index
= -1, i
= 0, s_i
= 0, n_i
= 0;
90 spin_lock_bh(&hinfo
->lock
);
94 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
95 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
97 hlist_for_each_entry_rcu(p
, head
, tcfc_head
) {
104 nest
= nla_nest_start(skb
, a
->order
);
106 goto nla_put_failure
;
107 err
= tcf_action_dump_1(skb
, a
, 0, 0);
110 nlmsg_trim(skb
, nest
);
113 nla_nest_end(skb
, nest
);
115 if (n_i
>= TCA_ACT_MAX_PRIO
)
120 spin_unlock_bh(&hinfo
->lock
);
126 nla_nest_cancel(skb
, nest
);
130 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
)
132 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
133 struct hlist_head
*head
;
134 struct hlist_node
*n
;
135 struct tcf_common
*p
;
140 nest
= nla_nest_start(skb
, a
->order
);
142 goto nla_put_failure
;
143 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
144 goto nla_put_failure
;
145 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
146 head
= &hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
147 hlist_for_each_entry_safe(p
, n
, head
, tcfc_head
) {
149 ret
= __tcf_hash_release(a
, false, true);
150 if (ret
== ACT_P_DELETED
) {
151 module_put(a
->ops
->owner
);
154 goto nla_put_failure
;
157 if (nla_put_u32(skb
, TCA_FCNT
, n_i
))
158 goto nla_put_failure
;
159 nla_nest_end(skb
, nest
);
163 nla_nest_cancel(skb
, nest
);
167 static int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
168 int type
, struct tc_action
*a
)
170 if (type
== RTM_DELACTION
) {
171 return tcf_del_walker(skb
, a
);
172 } else if (type
== RTM_GETACTION
) {
173 return tcf_dump_walker(skb
, cb
, a
);
175 WARN(1, "tcf_generic_walker: unknown action %d\n", type
);
180 static struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
182 struct tcf_common
*p
= NULL
;
183 struct hlist_head
*head
;
185 spin_lock_bh(&hinfo
->lock
);
186 head
= &hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)];
187 hlist_for_each_entry_rcu(p
, head
, tcfc_head
)
188 if (p
->tcfc_index
== index
)
190 spin_unlock_bh(&hinfo
->lock
);
195 u32
tcf_hash_new_index(struct tcf_hashinfo
*hinfo
)
197 u32 val
= hinfo
->index
;
202 } while (tcf_hash_lookup(val
, hinfo
));
207 EXPORT_SYMBOL(tcf_hash_new_index
);
209 int tcf_hash_search(struct tc_action
*a
, u32 index
)
211 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
212 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
220 EXPORT_SYMBOL(tcf_hash_search
);
222 int tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
)
224 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
225 struct tcf_common
*p
= NULL
;
226 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
235 EXPORT_SYMBOL(tcf_hash_check
);
237 void tcf_hash_cleanup(struct tc_action
*a
, struct nlattr
*est
)
239 struct tcf_common
*pc
= a
->priv
;
241 gen_kill_estimator(&pc
->tcfc_bstats
,
243 call_rcu(&pc
->tcfc_rcu
, free_tcf
);
245 EXPORT_SYMBOL(tcf_hash_cleanup
);
247 int tcf_hash_create(u32 index
, struct nlattr
*est
, struct tc_action
*a
,
248 int size
, int bind
, bool cpustats
)
250 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
251 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
261 p
->cpu_bstats
= netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu
);
262 if (!p
->cpu_bstats
) {
267 p
->cpu_qstats
= alloc_percpu(struct gnet_stats_queue
);
268 if (!p
->cpu_qstats
) {
270 free_percpu(p
->cpu_bstats
);
274 spin_lock_init(&p
->tcfc_lock
);
275 INIT_HLIST_NODE(&p
->tcfc_head
);
276 p
->tcfc_index
= index
? index
: tcf_hash_new_index(hinfo
);
277 p
->tcfc_tm
.install
= jiffies
;
278 p
->tcfc_tm
.lastuse
= jiffies
;
280 err
= gen_new_estimator(&p
->tcfc_bstats
, p
->cpu_bstats
,
284 free_percpu(p
->cpu_qstats
);
289 a
->priv
= (void *) p
;
292 EXPORT_SYMBOL(tcf_hash_create
);
294 void tcf_hash_insert(struct tc_action
*a
)
296 struct tcf_common
*p
= a
->priv
;
297 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
298 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
300 spin_lock_bh(&hinfo
->lock
);
301 hlist_add_head(&p
->tcfc_head
, &hinfo
->htab
[h
]);
302 spin_unlock_bh(&hinfo
->lock
);
304 EXPORT_SYMBOL(tcf_hash_insert
);
306 static LIST_HEAD(act_base
);
307 static DEFINE_RWLOCK(act_mod_lock
);
309 int tcf_register_action(struct tc_action_ops
*act
, unsigned int mask
)
311 struct tc_action_ops
*a
;
314 /* Must supply act, dump and init */
315 if (!act
->act
|| !act
->dump
|| !act
->init
)
318 /* Supply defaults */
320 act
->lookup
= tcf_hash_search
;
322 act
->walk
= tcf_generic_walker
;
324 act
->hinfo
= kmalloc(sizeof(struct tcf_hashinfo
), GFP_KERNEL
);
327 err
= tcf_hashinfo_init(act
->hinfo
, mask
);
333 write_lock(&act_mod_lock
);
334 list_for_each_entry(a
, &act_base
, head
) {
335 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
336 write_unlock(&act_mod_lock
);
337 tcf_hashinfo_destroy(act
->hinfo
);
342 list_add_tail(&act
->head
, &act_base
);
343 write_unlock(&act_mod_lock
);
346 EXPORT_SYMBOL(tcf_register_action
);
348 int tcf_unregister_action(struct tc_action_ops
*act
)
350 struct tc_action_ops
*a
;
353 write_lock(&act_mod_lock
);
354 list_for_each_entry(a
, &act_base
, head
) {
356 list_del(&act
->head
);
357 tcf_hashinfo_destroy(act
->hinfo
);
363 write_unlock(&act_mod_lock
);
366 EXPORT_SYMBOL(tcf_unregister_action
);
369 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
371 struct tc_action_ops
*a
, *res
= NULL
;
374 read_lock(&act_mod_lock
);
375 list_for_each_entry(a
, &act_base
, head
) {
376 if (strcmp(kind
, a
->kind
) == 0) {
377 if (try_module_get(a
->owner
))
382 read_unlock(&act_mod_lock
);
387 /* lookup by nlattr */
388 static struct tc_action_ops
*tc_lookup_action(struct nlattr
*kind
)
390 struct tc_action_ops
*a
, *res
= NULL
;
393 read_lock(&act_mod_lock
);
394 list_for_each_entry(a
, &act_base
, head
) {
395 if (nla_strcmp(kind
, a
->kind
) == 0) {
396 if (try_module_get(a
->owner
))
401 read_unlock(&act_mod_lock
);
406 int tcf_action_exec(struct sk_buff
*skb
, const struct list_head
*actions
,
407 struct tcf_result
*res
)
409 const struct tc_action
*a
;
412 if (skb
->tc_verd
& TC_NCLS
) {
413 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
417 list_for_each_entry(a
, actions
, list
) {
419 ret
= a
->ops
->act(skb
, a
, res
);
420 if (ret
== TC_ACT_REPEAT
)
421 goto repeat
; /* we need a ttl - JHS */
422 if (ret
!= TC_ACT_PIPE
)
428 EXPORT_SYMBOL(tcf_action_exec
);
430 int tcf_action_destroy(struct list_head
*actions
, int bind
)
432 struct tc_action
*a
, *tmp
;
435 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
436 ret
= __tcf_hash_release(a
, bind
, true);
437 if (ret
== ACT_P_DELETED
)
438 module_put(a
->ops
->owner
);
448 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
450 return a
->ops
->dump(skb
, a
, bind
, ref
);
454 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
457 unsigned char *b
= skb_tail_pointer(skb
);
460 if (nla_put_string(skb
, TCA_KIND
, a
->ops
->kind
))
461 goto nla_put_failure
;
462 if (tcf_action_copy_stats(skb
, a
, 0))
463 goto nla_put_failure
;
464 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
466 goto nla_put_failure
;
467 err
= tcf_action_dump_old(skb
, a
, bind
, ref
);
469 nla_nest_end(skb
, nest
);
477 EXPORT_SYMBOL(tcf_action_dump_1
);
480 tcf_action_dump(struct sk_buff
*skb
, struct list_head
*actions
, int bind
, int ref
)
486 list_for_each_entry(a
, actions
, list
) {
487 nest
= nla_nest_start(skb
, a
->order
);
489 goto nla_put_failure
;
490 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
493 nla_nest_end(skb
, nest
);
501 nla_nest_cancel(skb
, nest
);
505 struct tc_action
*tcf_action_init_1(struct net
*net
, struct nlattr
*nla
,
506 struct nlattr
*est
, char *name
, int ovr
,
510 struct tc_action_ops
*a_o
;
511 char act_name
[IFNAMSIZ
];
512 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
517 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
521 kind
= tb
[TCA_ACT_KIND
];
524 if (nla_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
528 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
532 a_o
= tc_lookup_action_n(act_name
);
534 #ifdef CONFIG_MODULES
536 request_module("act_%s", act_name
);
539 a_o
= tc_lookup_action_n(act_name
);
541 /* We dropped the RTNL semaphore in order to
542 * perform the module load. So, even if we
543 * succeeded in loading the module we have to
544 * tell the caller to replay the request. We
545 * indicate this using -EAGAIN.
557 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
562 INIT_LIST_HEAD(&a
->list
);
563 /* backward compatibility for policer */
565 err
= a_o
->init(net
, tb
[TCA_ACT_OPTIONS
], est
, a
, ovr
, bind
);
567 err
= a_o
->init(net
, nla
, est
, a
, ovr
, bind
);
571 /* module count goes up only when brand new policy is created
572 * if it exists and is only bound to in a_o->init() then
573 * ACT_P_CREATED is not returned (a zero is).
575 if (err
!= ACT_P_CREATED
)
576 module_put(a_o
->owner
);
583 module_put(a_o
->owner
);
588 int tcf_action_init(struct net
*net
, struct nlattr
*nla
,
589 struct nlattr
*est
, char *name
, int ovr
,
590 int bind
, struct list_head
*actions
)
592 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
593 struct tc_action
*act
;
597 err
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
601 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
602 act
= tcf_action_init_1(net
, tb
[i
], est
, name
, ovr
, bind
);
608 list_add_tail(&act
->list
, actions
);
613 tcf_action_destroy(actions
, bind
);
617 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
622 struct tcf_common
*p
= a
->priv
;
627 /* compat_mode being true specifies a call that is supposed
628 * to add additional backward compatibility statistic TLVs.
631 if (a
->type
== TCA_OLD_COMPAT
)
632 err
= gnet_stats_start_copy_compat(skb
, 0,
633 TCA_STATS
, TCA_XSTATS
, &p
->tcfc_lock
, &d
);
637 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
643 if (gnet_stats_copy_basic(&d
, p
->cpu_bstats
, &p
->tcfc_bstats
) < 0 ||
644 gnet_stats_copy_rate_est(&d
, &p
->tcfc_bstats
,
645 &p
->tcfc_rate_est
) < 0 ||
646 gnet_stats_copy_queue(&d
, p
->cpu_qstats
,
648 p
->tcfc_qstats
.qlen
) < 0)
651 if (gnet_stats_finish_copy(&d
) < 0)
661 tca_get_fill(struct sk_buff
*skb
, struct list_head
*actions
, u32 portid
, u32 seq
,
662 u16 flags
, int event
, int bind
, int ref
)
665 struct nlmsghdr
*nlh
;
666 unsigned char *b
= skb_tail_pointer(skb
);
669 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*t
), flags
);
673 t
->tca_family
= AF_UNSPEC
;
677 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
681 if (tcf_action_dump(skb
, actions
, bind
, ref
) < 0)
684 nla_nest_end(skb
, nest
);
686 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
695 act_get_notify(struct net
*net
, u32 portid
, struct nlmsghdr
*n
,
696 struct list_head
*actions
, int event
)
700 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
703 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
708 return rtnl_unicast(skb
, net
, portid
);
711 static struct tc_action
*create_a(int i
)
713 struct tc_action
*act
;
715 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
717 pr_debug("create_a: failed to alloc!\n");
721 INIT_LIST_HEAD(&act
->list
);
725 static struct tc_action
*
726 tcf_action_get_1(struct nlattr
*nla
, struct nlmsghdr
*n
, u32 portid
)
728 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
733 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
738 if (tb
[TCA_ACT_INDEX
] == NULL
||
739 nla_len(tb
[TCA_ACT_INDEX
]) < sizeof(index
))
741 index
= nla_get_u32(tb
[TCA_ACT_INDEX
]);
749 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
]);
750 if (a
->ops
== NULL
) /* could happen in batch of actions */
753 if (a
->ops
->lookup(a
, index
) == 0)
756 module_put(a
->ops
->owner
);
760 module_put(a
->ops
->owner
);
767 static void cleanup_a(struct list_head
*actions
)
769 struct tc_action
*a
, *tmp
;
771 list_for_each_entry_safe(a
, tmp
, actions
, list
) {
777 static int tca_action_flush(struct net
*net
, struct nlattr
*nla
,
778 struct nlmsghdr
*n
, u32 portid
)
782 struct nlmsghdr
*nlh
;
784 struct netlink_callback dcb
;
786 struct nlattr
*tb
[TCA_ACT_MAX
+ 1];
791 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
793 pr_debug("tca_action_flush: failed skb alloc\n");
797 b
= skb_tail_pointer(skb
);
799 err
= nla_parse_nested(tb
, TCA_ACT_MAX
, nla
, NULL
);
804 kind
= tb
[TCA_ACT_KIND
];
805 memset(&a
, 0, sizeof(struct tc_action
));
806 INIT_LIST_HEAD(&a
.list
);
807 a
.ops
= tc_lookup_action(kind
);
808 if (a
.ops
== NULL
) /*some idjot trying to flush unknown action */
811 nlh
= nlmsg_put(skb
, portid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
), 0);
815 t
->tca_family
= AF_UNSPEC
;
819 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
823 err
= a
.ops
->walk(skb
, &dcb
, RTM_DELACTION
, &a
);
829 nla_nest_end(skb
, nest
);
831 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
832 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
833 module_put(a
.ops
->owner
);
834 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
835 n
->nlmsg_flags
& NLM_F_ECHO
);
842 module_put(a
.ops
->owner
);
850 tcf_del_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
856 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
860 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, 0, RTM_DELACTION
,
866 /* now do the delete */
867 ret
= tcf_action_destroy(actions
, 0);
873 ret
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
874 n
->nlmsg_flags
& NLM_F_ECHO
);
881 tca_action_gd(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
882 u32 portid
, int event
)
885 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
886 struct tc_action
*act
;
889 ret
= nla_parse_nested(tb
, TCA_ACT_MAX_PRIO
, nla
, NULL
);
893 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
& NLM_F_ROOT
) {
895 return tca_action_flush(net
, tb
[1], n
, portid
);
900 for (i
= 1; i
<= TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
901 act
= tcf_action_get_1(tb
[i
], n
, portid
);
907 list_add_tail(&act
->list
, &actions
);
910 if (event
== RTM_GETACTION
)
911 ret
= act_get_notify(net
, portid
, n
, &actions
, event
);
913 ret
= tcf_del_notify(net
, n
, &actions
, portid
);
924 tcf_add_notify(struct net
*net
, struct nlmsghdr
*n
, struct list_head
*actions
,
930 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
934 if (tca_get_fill(skb
, actions
, portid
, n
->nlmsg_seq
, n
->nlmsg_flags
,
935 RTM_NEWACTION
, 0, 0) <= 0) {
940 err
= rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
941 n
->nlmsg_flags
& NLM_F_ECHO
);
948 tcf_action_add(struct net
*net
, struct nlattr
*nla
, struct nlmsghdr
*n
,
954 ret
= tcf_action_init(net
, nla
, NULL
, NULL
, ovr
, 0, &actions
);
958 /* dump then free all the actions after update; inserted policy
961 ret
= tcf_add_notify(net
, n
, &actions
, portid
);
967 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
)
969 struct net
*net
= sock_net(skb
->sk
);
970 struct nlattr
*tca
[TCA_ACT_MAX
+ 1];
971 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
972 int ret
= 0, ovr
= 0;
974 if ((n
->nlmsg_type
!= RTM_GETACTION
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
977 ret
= nlmsg_parse(n
, sizeof(struct tcamsg
), tca
, TCA_ACT_MAX
, NULL
);
981 if (tca
[TCA_ACT_TAB
] == NULL
) {
982 pr_notice("tc_ctl_action: received NO action attribs\n");
986 /* n->nlmsg_flags & NLM_F_CREATE */
987 switch (n
->nlmsg_type
) {
989 /* we are going to assume all other flags
990 * imply create only if it doesn't exist
991 * Note that CREATE | EXCL implies that
992 * but since we want avoid ambiguity (eg when flags
993 * is zero) then just set this
995 if (n
->nlmsg_flags
& NLM_F_REPLACE
)
998 ret
= tcf_action_add(net
, tca
[TCA_ACT_TAB
], n
, portid
, ovr
);
1003 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1004 portid
, RTM_DELACTION
);
1007 ret
= tca_action_gd(net
, tca
[TCA_ACT_TAB
], n
,
1008 portid
, RTM_GETACTION
);
1017 static struct nlattr
*
1018 find_dump_kind(const struct nlmsghdr
*n
)
1020 struct nlattr
*tb1
, *tb2
[TCA_ACT_MAX
+ 1];
1021 struct nlattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
1022 struct nlattr
*nla
[TCAA_MAX
+ 1];
1023 struct nlattr
*kind
;
1025 if (nlmsg_parse(n
, sizeof(struct tcamsg
), nla
, TCAA_MAX
, NULL
) < 0)
1027 tb1
= nla
[TCA_ACT_TAB
];
1031 if (nla_parse(tb
, TCA_ACT_MAX_PRIO
, nla_data(tb1
),
1032 NLMSG_ALIGN(nla_len(tb1
)), NULL
) < 0)
1037 if (nla_parse(tb2
, TCA_ACT_MAX
, nla_data(tb
[1]),
1038 nla_len(tb
[1]), NULL
) < 0)
1040 kind
= tb2
[TCA_ACT_KIND
];
1046 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1048 struct nlmsghdr
*nlh
;
1049 unsigned char *b
= skb_tail_pointer(skb
);
1050 struct nlattr
*nest
;
1051 struct tc_action_ops
*a_o
;
1054 struct tcamsg
*t
= (struct tcamsg
*) nlmsg_data(cb
->nlh
);
1055 struct nlattr
*kind
= find_dump_kind(cb
->nlh
);
1058 pr_info("tc_dump_action: action bad kind\n");
1062 a_o
= tc_lookup_action(kind
);
1066 memset(&a
, 0, sizeof(struct tc_action
));
1069 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
1070 cb
->nlh
->nlmsg_type
, sizeof(*t
), 0);
1072 goto out_module_put
;
1073 t
= nlmsg_data(nlh
);
1074 t
->tca_family
= AF_UNSPEC
;
1078 nest
= nla_nest_start(skb
, TCA_ACT_TAB
);
1080 goto out_module_put
;
1082 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1084 goto out_module_put
;
1087 nla_nest_end(skb
, nest
);
1090 nla_nest_cancel(skb
, nest
);
1092 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1093 if (NETLINK_CB(cb
->skb
).portid
&& ret
)
1094 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1095 module_put(a_o
->owner
);
1099 module_put(a_o
->owner
);
1104 static int __init
tc_action_init(void)
1106 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
, NULL
);
1107 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
, NULL
);
1108 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
,
1114 subsys_initcall(tc_action_init
);
This page took 0.058595 seconds and 5 git commands to generate.