2 * net/sched/cls_api.c Packet classifier 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 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
13 * Eduardo J. Blanco <ejbs@netlabs.com.uy> :990222: kmod support
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
22 #include <linux/err.h>
23 #include <linux/skbuff.h>
24 #include <linux/init.h>
25 #include <linux/kmod.h>
26 #include <linux/err.h>
27 #include <linux/slab.h>
28 #include <net/net_namespace.h>
30 #include <net/netlink.h>
31 #include <net/pkt_sched.h>
32 #include <net/pkt_cls.h>
34 /* The list of all installed classifier types */
35 static LIST_HEAD(tcf_proto_base);
37 /* Protects list of registered TC modules. It is pure SMP lock. */
38 static DEFINE_RWLOCK(cls_mod_lock);
40 /* Find classifier type by string name */
42 static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind)
44 const struct tcf_proto_ops *t, *res = NULL;
47 read_lock(&cls_mod_lock);
48 list_for_each_entry(t, &tcf_proto_base, head) {
49 if (strcmp(kind, t->kind) == 0) {
50 if (try_module_get(t->owner))
55 read_unlock(&cls_mod_lock);
60 /* Register(unregister) new classifier type */
62 int register_tcf_proto_ops(struct tcf_proto_ops *ops)
64 struct tcf_proto_ops *t;
67 write_lock(&cls_mod_lock);
68 list_for_each_entry(t, &tcf_proto_base, head)
69 if (!strcmp(ops->kind, t->kind))
72 list_add_tail(&ops->head, &tcf_proto_base);
75 write_unlock(&cls_mod_lock);
78 EXPORT_SYMBOL(register_tcf_proto_ops);
80 static struct workqueue_struct *tc_filter_wq;
82 int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
84 struct tcf_proto_ops *t;
87 /* Wait for outstanding call_rcu()s, if any, from a
88 * tcf_proto_ops's destroy() handler.
91 flush_workqueue(tc_filter_wq);
93 write_lock(&cls_mod_lock);
94 list_for_each_entry(t, &tcf_proto_base, head) {
101 write_unlock(&cls_mod_lock);
104 EXPORT_SYMBOL(unregister_tcf_proto_ops);
106 bool tcf_queue_work(struct work_struct *work)
108 return queue_work(tc_filter_wq, work);
110 EXPORT_SYMBOL(tcf_queue_work);
112 /* Select new prio value from the range, managed by kernel. */
114 static inline u32 tcf_auto_prio(struct tcf_proto *tp)
116 u32 first = TC_H_MAKE(0xC0000000U, 0U);
119 first = tp->prio - 1;
121 return TC_H_MAJ(first);
124 static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
125 u32 prio, u32 parent, struct Qdisc *q,
126 struct tcf_chain *chain)
128 struct tcf_proto *tp;
131 tp = kzalloc(sizeof(*tp), GFP_KERNEL);
133 return ERR_PTR(-ENOBUFS);
136 tp->ops = tcf_proto_lookup_ops(kind);
138 #ifdef CONFIG_MODULES
140 request_module("cls_%s", kind);
142 tp->ops = tcf_proto_lookup_ops(kind);
143 /* We dropped the RTNL semaphore in order to perform
144 * the module load. So, even if we succeeded in loading
145 * the module we have to replay the request. We indicate
146 * this using -EAGAIN.
149 module_put(tp->ops->owner);
157 tp->classify = tp->ops->classify;
158 tp->protocol = protocol;
160 tp->classid = parent;
164 err = tp->ops->init(tp);
166 module_put(tp->ops->owner);
176 static void tcf_proto_destroy(struct tcf_proto *tp)
178 tp->ops->destroy(tp);
179 module_put(tp->ops->owner);
183 static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
186 struct tcf_chain *chain;
188 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
191 list_add_tail(&chain->list, &block->chain_list);
192 chain->block = block;
193 chain->index = chain_index;
198 static void tcf_chain_flush(struct tcf_chain *chain)
200 struct tcf_proto *tp;
202 if (chain->p_filter_chain)
203 RCU_INIT_POINTER(*chain->p_filter_chain, NULL);
204 while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
205 RCU_INIT_POINTER(chain->filter_chain, tp->next);
206 tcf_chain_put(chain);
207 tcf_proto_destroy(tp);
211 static void tcf_chain_destroy(struct tcf_chain *chain)
213 list_del(&chain->list);
217 static void tcf_chain_hold(struct tcf_chain *chain)
222 struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
225 struct tcf_chain *chain;
227 list_for_each_entry(chain, &block->chain_list, list) {
228 if (chain->index == chain_index) {
229 tcf_chain_hold(chain);
234 return create ? tcf_chain_create(block, chain_index) : NULL;
236 EXPORT_SYMBOL(tcf_chain_get);
238 void tcf_chain_put(struct tcf_chain *chain)
240 if (--chain->refcnt == 0)
241 tcf_chain_destroy(chain);
243 EXPORT_SYMBOL(tcf_chain_put);
246 tcf_chain_filter_chain_ptr_set(struct tcf_chain *chain,
247 struct tcf_proto __rcu **p_filter_chain)
249 chain->p_filter_chain = p_filter_chain;
252 int tcf_block_get(struct tcf_block **p_block,
253 struct tcf_proto __rcu **p_filter_chain)
255 struct tcf_block *block = kzalloc(sizeof(*block), GFP_KERNEL);
256 struct tcf_chain *chain;
261 INIT_LIST_HEAD(&block->chain_list);
262 /* Create chain 0 by default, it has to be always present. */
263 chain = tcf_chain_create(block, 0);
266 goto err_chain_create;
268 tcf_chain_filter_chain_ptr_set(chain, p_filter_chain);
276 EXPORT_SYMBOL(tcf_block_get);
278 static void tcf_block_put_final(struct work_struct *work)
280 struct tcf_block *block = container_of(work, struct tcf_block, work);
281 struct tcf_chain *chain, *tmp;
284 /* Only chain 0 should be still here. */
285 list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
286 tcf_chain_put(chain);
291 /* XXX: Standalone actions are not allowed to jump to any chain, and bound
292 * actions should be all removed after flushing. However, filters are now
293 * destroyed in tc filter workqueue with RTNL lock, they can not race here.
295 void tcf_block_put(struct tcf_block *block)
297 struct tcf_chain *chain, *tmp;
302 list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
303 tcf_chain_flush(chain);
305 INIT_WORK(&block->work, tcf_block_put_final);
306 /* Wait for RCU callbacks to release the reference count and make
307 * sure their works have been queued before this.
310 tcf_queue_work(&block->work);
312 EXPORT_SYMBOL(tcf_block_put);
314 /* Main classifier routine: scans classifier chain attached
315 * to this qdisc, (optionally) tests for protocol and asks
316 * specific classifiers.
318 int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
319 struct tcf_result *res, bool compat_mode)
321 __be16 protocol = tc_skb_protocol(skb);
322 #ifdef CONFIG_NET_CLS_ACT
323 const int max_reclassify_loop = 4;
324 const struct tcf_proto *orig_tp = tp;
325 const struct tcf_proto *first_tp;
330 for (; tp; tp = rcu_dereference_bh(tp->next)) {
333 if (tp->protocol != protocol &&
334 tp->protocol != htons(ETH_P_ALL))
337 err = tp->classify(skb, tp, res);
338 #ifdef CONFIG_NET_CLS_ACT
339 if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) {
342 } else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) {
343 first_tp = res->goto_tp;
351 return TC_ACT_UNSPEC; /* signal: continue lookup */
352 #ifdef CONFIG_NET_CLS_ACT
354 if (unlikely(limit++ >= max_reclassify_loop)) {
355 net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n",
356 tp->q->ops->id, tp->prio & 0xffff,
357 ntohs(tp->protocol));
362 protocol = tc_skb_protocol(skb);
366 EXPORT_SYMBOL(tcf_classify);
368 struct tcf_chain_info {
369 struct tcf_proto __rcu **pprev;
370 struct tcf_proto __rcu *next;
373 static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain_info *chain_info)
375 return rtnl_dereference(*chain_info->pprev);
378 static void tcf_chain_tp_insert(struct tcf_chain *chain,
379 struct tcf_chain_info *chain_info,
380 struct tcf_proto *tp)
382 if (chain->p_filter_chain &&
383 *chain_info->pprev == chain->filter_chain)
384 rcu_assign_pointer(*chain->p_filter_chain, tp);
385 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain_info));
386 rcu_assign_pointer(*chain_info->pprev, tp);
387 tcf_chain_hold(chain);
390 static void tcf_chain_tp_remove(struct tcf_chain *chain,
391 struct tcf_chain_info *chain_info,
392 struct tcf_proto *tp)
394 struct tcf_proto *next = rtnl_dereference(chain_info->next);
396 if (chain->p_filter_chain && tp == chain->filter_chain)
397 RCU_INIT_POINTER(*chain->p_filter_chain, next);
398 RCU_INIT_POINTER(*chain_info->pprev, next);
399 tcf_chain_put(chain);
402 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
403 struct tcf_chain_info *chain_info,
404 u32 protocol, u32 prio,
407 struct tcf_proto **pprev;
408 struct tcf_proto *tp;
410 /* Check the chain for existence of proto-tcf with this priority */
411 for (pprev = &chain->filter_chain;
412 (tp = rtnl_dereference(*pprev)); pprev = &tp->next) {
413 if (tp->prio >= prio) {
414 if (tp->prio == prio) {
416 (tp->protocol != protocol && protocol))
417 return ERR_PTR(-EINVAL);
424 chain_info->pprev = pprev;
425 chain_info->next = tp ? tp->next : NULL;
429 static int tcf_fill_node(struct net *net, struct sk_buff *skb,
430 struct tcf_proto *tp, void *fh, u32 portid,
431 u32 seq, u16 flags, int event)
434 struct nlmsghdr *nlh;
435 unsigned char *b = skb_tail_pointer(skb);
437 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
440 tcm = nlmsg_data(nlh);
441 tcm->tcm_family = AF_UNSPEC;
444 tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
445 tcm->tcm_parent = tp->classid;
446 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
447 if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
448 goto nla_put_failure;
449 if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
450 goto nla_put_failure;
454 if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0)
455 goto nla_put_failure;
457 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
466 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
467 struct nlmsghdr *n, struct tcf_proto *tp,
468 void *fh, int event, bool unicast)
471 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
473 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
477 if (tcf_fill_node(net, skb, tp, fh, portid, n->nlmsg_seq,
478 n->nlmsg_flags, event) <= 0) {
484 return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
486 return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
487 n->nlmsg_flags & NLM_F_ECHO);
490 static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
491 struct nlmsghdr *n, struct tcf_proto *tp,
492 void *fh, bool unicast, bool *last)
495 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
498 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
502 if (tcf_fill_node(net, skb, tp, fh, portid, n->nlmsg_seq,
503 n->nlmsg_flags, RTM_DELTFILTER) <= 0) {
508 err = tp->ops->delete(tp, fh, last);
515 return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
517 return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
518 n->nlmsg_flags & NLM_F_ECHO);
521 static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
523 struct tcf_chain *chain, int event)
525 struct tcf_proto *tp;
527 for (tp = rtnl_dereference(chain->filter_chain);
528 tp; tp = rtnl_dereference(tp->next))
529 tfilter_notify(net, oskb, n, tp, 0, event, false);
532 /* Add/change/delete/get a filter node */
534 static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
535 struct netlink_ext_ack *extack)
537 struct net *net = sock_net(skb->sk);
538 struct nlattr *tca[TCA_MAX + 1];
545 struct net_device *dev;
547 struct tcf_chain_info chain_info;
548 struct tcf_chain *chain = NULL;
549 struct tcf_block *block;
550 struct tcf_proto *tp;
551 const struct Qdisc_class_ops *cops;
557 if ((n->nlmsg_type != RTM_GETTFILTER) &&
558 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
564 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
569 protocol = TC_H_MIN(t->tcm_info);
570 prio = TC_H_MAJ(t->tcm_info);
571 prio_allocate = false;
572 parent = t->tcm_parent;
576 switch (n->nlmsg_type) {
578 if (protocol || t->tcm_handle || tca[TCA_KIND])
582 /* If no priority is provided by the user,
585 if (n->nlmsg_flags & NLM_F_CREATE) {
586 prio = TC_H_MAKE(0x80000000U, 0U);
587 prio_allocate = true;
596 /* Find head of filter chain. */
599 dev = __dev_get_by_index(net, t->tcm_ifindex);
608 q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent));
613 /* Is it classful? */
614 cops = q->ops->cl_ops;
618 if (!cops->tcf_block)
621 /* Do we search for filter, attached to class? */
622 if (TC_H_MIN(parent)) {
623 cl = cops->find(q, parent);
628 /* And the last stroke */
629 block = cops->tcf_block(q, cl);
635 chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
636 if (chain_index > TC_ACT_EXT_VAL_MASK) {
640 chain = tcf_chain_get(block, chain_index,
641 n->nlmsg_type == RTM_NEWTFILTER);
643 err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL;
647 if (n->nlmsg_type == RTM_DELTFILTER && prio == 0) {
648 tfilter_notify_chain(net, skb, n, chain, RTM_DELTFILTER);
649 tcf_chain_flush(chain);
654 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
655 prio, prio_allocate);
662 /* Proto-tcf does not exist, create new one */
664 if (tca[TCA_KIND] == NULL || !protocol) {
669 if (n->nlmsg_type != RTM_NEWTFILTER ||
670 !(n->nlmsg_flags & NLM_F_CREATE)) {
676 prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info));
678 tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
679 protocol, prio, parent, q, chain);
685 } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
690 fh = tp->ops->get(tp, t->tcm_handle);
693 if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
694 tcf_chain_tp_remove(chain, &chain_info, tp);
695 tfilter_notify(net, skb, n, tp, fh,
696 RTM_DELTFILTER, false);
697 tcf_proto_destroy(tp);
702 if (n->nlmsg_type != RTM_NEWTFILTER ||
703 !(n->nlmsg_flags & NLM_F_CREATE)) {
710 switch (n->nlmsg_type) {
712 if (n->nlmsg_flags & NLM_F_EXCL) {
714 tcf_proto_destroy(tp);
720 err = tfilter_del_notify(net, skb, n, tp, fh, false,
725 tcf_chain_tp_remove(chain, &chain_info, tp);
726 tcf_proto_destroy(tp);
730 err = tfilter_notify(net, skb, n, tp, fh,
731 RTM_NEWTFILTER, true);
739 err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
740 n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE);
743 tcf_chain_tp_insert(chain, &chain_info, tp);
744 tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
747 tcf_proto_destroy(tp);
752 tcf_chain_put(chain);
754 /* Replay the request. */
759 struct tcf_dump_args {
762 struct netlink_callback *cb;
765 static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
767 struct tcf_dump_args *a = (void *)arg;
768 struct net *net = sock_net(a->skb->sk);
770 return tcf_fill_node(net, a->skb, tp, n, NETLINK_CB(a->cb->skb).portid,
771 a->cb->nlh->nlmsg_seq, NLM_F_MULTI,
775 static bool tcf_chain_dump(struct tcf_chain *chain, struct sk_buff *skb,
776 struct netlink_callback *cb,
777 long index_start, long *p_index)
779 struct net *net = sock_net(skb->sk);
780 struct tcmsg *tcm = nlmsg_data(cb->nlh);
781 struct tcf_dump_args arg;
782 struct tcf_proto *tp;
784 for (tp = rtnl_dereference(chain->filter_chain);
785 tp; tp = rtnl_dereference(tp->next), (*p_index)++) {
786 if (*p_index < index_start)
788 if (TC_H_MAJ(tcm->tcm_info) &&
789 TC_H_MAJ(tcm->tcm_info) != tp->prio)
791 if (TC_H_MIN(tcm->tcm_info) &&
792 TC_H_MIN(tcm->tcm_info) != tp->protocol)
794 if (*p_index > index_start)
795 memset(&cb->args[1], 0,
796 sizeof(cb->args) - sizeof(cb->args[0]));
797 if (cb->args[1] == 0) {
798 if (tcf_fill_node(net, skb, tp, 0,
799 NETLINK_CB(cb->skb).portid,
800 cb->nlh->nlmsg_seq, NLM_F_MULTI,
801 RTM_NEWTFILTER) <= 0)
808 arg.w.fn = tcf_node_dump;
812 arg.w.skip = cb->args[1] - 1;
814 tp->ops->walk(tp, &arg.w);
815 cb->args[1] = arg.w.count + 1;
822 /* called with RTNL */
823 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
825 struct net *net = sock_net(skb->sk);
826 struct nlattr *tca[TCA_MAX + 1];
827 struct net_device *dev;
829 struct tcf_block *block;
830 struct tcf_chain *chain;
831 struct tcmsg *tcm = nlmsg_data(cb->nlh);
832 unsigned long cl = 0;
833 const struct Qdisc_class_ops *cops;
838 if (nlmsg_len(cb->nlh) < sizeof(*tcm))
841 err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, NULL);
845 dev = __dev_get_by_index(net, tcm->tcm_ifindex);
849 if (!tcm->tcm_parent)
852 q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
855 cops = q->ops->cl_ops;
858 if (!cops->tcf_block)
860 if (TC_H_MIN(tcm->tcm_parent)) {
861 cl = cops->find(q, tcm->tcm_parent);
865 block = cops->tcf_block(q, cl);
869 index_start = cb->args[0];
872 list_for_each_entry(chain, &block->chain_list, list) {
873 if (tca[TCA_CHAIN] &&
874 nla_get_u32(tca[TCA_CHAIN]) != chain->index)
876 if (!tcf_chain_dump(chain, skb, cb, index_start, &index))
886 void tcf_exts_destroy(struct tcf_exts *exts)
888 #ifdef CONFIG_NET_CLS_ACT
892 tcf_exts_to_list(exts, &actions);
893 tcf_action_destroy(&actions, TCA_ACT_UNBIND);
894 kfree(exts->actions);
895 exts->nr_actions = 0;
898 EXPORT_SYMBOL(tcf_exts_destroy);
900 int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
901 struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr)
903 #ifdef CONFIG_NET_CLS_ACT
905 struct tc_action *act;
907 if (exts->police && tb[exts->police]) {
908 act = tcf_action_init_1(net, tp, tb[exts->police],
909 rate_tlv, "police", ovr,
914 act->type = exts->type = TCA_OLD_COMPAT;
915 exts->actions[0] = act;
916 exts->nr_actions = 1;
917 } else if (exts->action && tb[exts->action]) {
921 err = tcf_action_init(net, tp, tb[exts->action],
922 rate_tlv, NULL, ovr, TCA_ACT_BIND,
926 list_for_each_entry(act, &actions, list)
927 exts->actions[i++] = act;
928 exts->nr_actions = i;
932 if ((exts->action && tb[exts->action]) ||
933 (exts->police && tb[exts->police]))
939 EXPORT_SYMBOL(tcf_exts_validate);
941 void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src)
943 #ifdef CONFIG_NET_CLS_ACT
944 struct tcf_exts old = *dst;
947 tcf_exts_destroy(&old);
950 EXPORT_SYMBOL(tcf_exts_change);
952 #ifdef CONFIG_NET_CLS_ACT
953 static struct tc_action *tcf_exts_first_act(struct tcf_exts *exts)
955 if (exts->nr_actions == 0)
958 return exts->actions[0];
962 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
964 #ifdef CONFIG_NET_CLS_ACT
967 if (exts->action && tcf_exts_has_actions(exts)) {
969 * again for backward compatible mode - we want
970 * to work with both old and new modes of entering
971 * tc data even if iproute2 was newer - jhs
973 if (exts->type != TCA_OLD_COMPAT) {
976 nest = nla_nest_start(skb, exts->action);
978 goto nla_put_failure;
980 tcf_exts_to_list(exts, &actions);
981 if (tcf_action_dump(skb, &actions, 0, 0) < 0)
982 goto nla_put_failure;
983 nla_nest_end(skb, nest);
984 } else if (exts->police) {
985 struct tc_action *act = tcf_exts_first_act(exts);
986 nest = nla_nest_start(skb, exts->police);
987 if (nest == NULL || !act)
988 goto nla_put_failure;
989 if (tcf_action_dump_old(skb, act, 0, 0) < 0)
990 goto nla_put_failure;
991 nla_nest_end(skb, nest);
997 nla_nest_cancel(skb, nest);
1003 EXPORT_SYMBOL(tcf_exts_dump);
1006 int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
1008 #ifdef CONFIG_NET_CLS_ACT
1009 struct tc_action *a = tcf_exts_first_act(exts);
1010 if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
1015 EXPORT_SYMBOL(tcf_exts_dump_stats);
1017 int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,
1018 struct net_device **hw_dev)
1020 #ifdef CONFIG_NET_CLS_ACT
1021 const struct tc_action *a;
1024 if (!tcf_exts_has_actions(exts))
1027 tcf_exts_to_list(exts, &actions);
1028 list_for_each_entry(a, &actions, list) {
1029 if (a->ops->get_dev) {
1030 a->ops->get_dev(a, dev_net(dev), hw_dev);
1039 EXPORT_SYMBOL(tcf_exts_get_dev);
1041 static int __init tc_filter_init(void)
1043 tc_filter_wq = alloc_ordered_workqueue("tc_filter_workqueue", 0);
1047 rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_ctl_tfilter, NULL, 0);
1048 rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_ctl_tfilter, NULL, 0);
1049 rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_ctl_tfilter,
1050 tc_dump_tfilter, 0);
1055 subsys_initcall(tc_filter_init);