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/slab.h>
27 #include <linux/idr.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 rcu_work *rwork, work_func_t func)
108 INIT_RCU_WORK(rwork, func);
109 return queue_rcu_work(tc_filter_wq, rwork);
111 EXPORT_SYMBOL(tcf_queue_work);
113 /* Select new prio value from the range, managed by kernel. */
115 static inline u32 tcf_auto_prio(struct tcf_proto *tp)
117 u32 first = TC_H_MAKE(0xC0000000U, 0U);
120 first = tp->prio - 1;
122 return TC_H_MAJ(first);
125 static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
126 u32 prio, struct tcf_chain *chain,
127 struct netlink_ext_ack *extack)
129 struct tcf_proto *tp;
132 tp = kzalloc(sizeof(*tp), GFP_KERNEL);
134 return ERR_PTR(-ENOBUFS);
137 tp->ops = tcf_proto_lookup_ops(kind);
139 #ifdef CONFIG_MODULES
141 request_module("cls_%s", kind);
143 tp->ops = tcf_proto_lookup_ops(kind);
144 /* We dropped the RTNL semaphore in order to perform
145 * the module load. So, even if we succeeded in loading
146 * the module we have to replay the request. We indicate
147 * this using -EAGAIN.
150 module_put(tp->ops->owner);
153 NL_SET_ERR_MSG(extack, "TC classifier not found");
159 tp->classify = tp->ops->classify;
160 tp->protocol = protocol;
164 err = tp->ops->init(tp);
166 module_put(tp->ops->owner);
176 static void tcf_proto_destroy(struct tcf_proto *tp,
177 struct netlink_ext_ack *extack)
179 tp->ops->destroy(tp, extack);
180 module_put(tp->ops->owner);
184 struct tcf_filter_chain_list_item {
185 struct list_head list;
186 tcf_chain_head_change_t *chain_head_change;
187 void *chain_head_change_priv;
190 static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
193 struct tcf_chain *chain;
195 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
198 INIT_LIST_HEAD(&chain->filter_chain_list);
199 list_add_tail(&chain->list, &block->chain_list);
200 chain->block = block;
201 chain->index = chain_index;
206 static void tcf_chain_head_change_item(struct tcf_filter_chain_list_item *item,
207 struct tcf_proto *tp_head)
209 if (item->chain_head_change)
210 item->chain_head_change(tp_head, item->chain_head_change_priv);
212 static void tcf_chain_head_change(struct tcf_chain *chain,
213 struct tcf_proto *tp_head)
215 struct tcf_filter_chain_list_item *item;
217 list_for_each_entry(item, &chain->filter_chain_list, list)
218 tcf_chain_head_change_item(item, tp_head);
221 static void tcf_chain_flush(struct tcf_chain *chain)
223 struct tcf_proto *tp = rtnl_dereference(chain->filter_chain);
225 tcf_chain_head_change(chain, NULL);
227 RCU_INIT_POINTER(chain->filter_chain, tp->next);
228 tcf_proto_destroy(tp, NULL);
229 tp = rtnl_dereference(chain->filter_chain);
230 tcf_chain_put(chain);
234 static void tcf_chain_destroy(struct tcf_chain *chain)
236 struct tcf_block *block = chain->block;
238 list_del(&chain->list);
240 if (list_empty(&block->chain_list))
244 static void tcf_chain_hold(struct tcf_chain *chain)
249 struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
252 struct tcf_chain *chain;
254 list_for_each_entry(chain, &block->chain_list, list) {
255 if (chain->index == chain_index) {
256 tcf_chain_hold(chain);
261 return create ? tcf_chain_create(block, chain_index) : NULL;
263 EXPORT_SYMBOL(tcf_chain_get);
265 void tcf_chain_put(struct tcf_chain *chain)
267 if (--chain->refcnt == 0)
268 tcf_chain_destroy(chain);
270 EXPORT_SYMBOL(tcf_chain_put);
272 static bool tcf_block_offload_in_use(struct tcf_block *block)
274 return block->offloadcnt;
277 static int tcf_block_offload_cmd(struct tcf_block *block,
278 struct net_device *dev,
279 struct tcf_block_ext_info *ei,
280 enum tc_block_command command,
281 struct netlink_ext_ack *extack)
283 struct tc_block_offload bo = {};
285 bo.command = command;
286 bo.binder_type = ei->binder_type;
289 return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_BLOCK, &bo);
292 static int tcf_block_offload_bind(struct tcf_block *block, struct Qdisc *q,
293 struct tcf_block_ext_info *ei,
294 struct netlink_ext_ack *extack)
296 struct net_device *dev = q->dev_queue->dev;
299 if (!dev->netdev_ops->ndo_setup_tc)
300 goto no_offload_dev_inc;
302 /* If tc offload feature is disabled and the block we try to bind
303 * to already has some offloaded filters, forbid to bind.
305 if (!tc_can_offload(dev) && tcf_block_offload_in_use(block)) {
306 NL_SET_ERR_MSG(extack, "Bind to offloaded block failed as dev has offload disabled");
310 err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_BIND, extack);
311 if (err == -EOPNOTSUPP)
312 goto no_offload_dev_inc;
316 if (tcf_block_offload_in_use(block))
318 block->nooffloaddevcnt++;
322 static void tcf_block_offload_unbind(struct tcf_block *block, struct Qdisc *q,
323 struct tcf_block_ext_info *ei)
325 struct net_device *dev = q->dev_queue->dev;
328 if (!dev->netdev_ops->ndo_setup_tc)
329 goto no_offload_dev_dec;
330 err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_UNBIND, NULL);
331 if (err == -EOPNOTSUPP)
332 goto no_offload_dev_dec;
336 WARN_ON(block->nooffloaddevcnt-- == 0);
340 tcf_chain_head_change_cb_add(struct tcf_chain *chain,
341 struct tcf_block_ext_info *ei,
342 struct netlink_ext_ack *extack)
344 struct tcf_filter_chain_list_item *item;
346 item = kmalloc(sizeof(*item), GFP_KERNEL);
348 NL_SET_ERR_MSG(extack, "Memory allocation for head change callback item failed");
351 item->chain_head_change = ei->chain_head_change;
352 item->chain_head_change_priv = ei->chain_head_change_priv;
353 if (chain->filter_chain)
354 tcf_chain_head_change_item(item, chain->filter_chain);
355 list_add(&item->list, &chain->filter_chain_list);
360 tcf_chain_head_change_cb_del(struct tcf_chain *chain,
361 struct tcf_block_ext_info *ei)
363 struct tcf_filter_chain_list_item *item;
365 list_for_each_entry(item, &chain->filter_chain_list, list) {
366 if ((!ei->chain_head_change && !ei->chain_head_change_priv) ||
367 (item->chain_head_change == ei->chain_head_change &&
368 item->chain_head_change_priv == ei->chain_head_change_priv)) {
369 tcf_chain_head_change_item(item, NULL);
370 list_del(&item->list);
382 static unsigned int tcf_net_id;
384 static int tcf_block_insert(struct tcf_block *block, struct net *net,
385 struct netlink_ext_ack *extack)
387 struct tcf_net *tn = net_generic(net, tcf_net_id);
389 return idr_alloc_u32(&tn->idr, block, &block->index, block->index,
393 static void tcf_block_remove(struct tcf_block *block, struct net *net)
395 struct tcf_net *tn = net_generic(net, tcf_net_id);
397 idr_remove(&tn->idr, block->index);
400 static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,
402 struct netlink_ext_ack *extack)
404 struct tcf_block *block;
405 struct tcf_chain *chain;
408 block = kzalloc(sizeof(*block), GFP_KERNEL);
410 NL_SET_ERR_MSG(extack, "Memory allocation for block failed");
411 return ERR_PTR(-ENOMEM);
413 INIT_LIST_HEAD(&block->chain_list);
414 INIT_LIST_HEAD(&block->cb_list);
415 INIT_LIST_HEAD(&block->owner_list);
417 /* Create chain 0 by default, it has to be always present. */
418 chain = tcf_chain_create(block, 0);
420 NL_SET_ERR_MSG(extack, "Failed to create new tcf chain");
422 goto err_chain_create;
426 block->index = block_index;
428 /* Don't store q pointer for blocks which are shared */
429 if (!tcf_block_shared(block))
438 static struct tcf_block *tcf_block_lookup(struct net *net, u32 block_index)
440 struct tcf_net *tn = net_generic(net, tcf_net_id);
442 return idr_find(&tn->idr, block_index);
446 * Set q, parent, cl when appropriate.
449 static struct tcf_block *tcf_block_find(struct net *net, struct Qdisc **q,
450 u32 *parent, unsigned long *cl,
451 int ifindex, u32 block_index,
452 struct netlink_ext_ack *extack)
454 struct tcf_block *block;
456 if (ifindex == TCM_IFINDEX_MAGIC_BLOCK) {
457 block = tcf_block_lookup(net, block_index);
459 NL_SET_ERR_MSG(extack, "Block of given index was not found");
460 return ERR_PTR(-EINVAL);
463 const struct Qdisc_class_ops *cops;
464 struct net_device *dev;
467 dev = __dev_get_by_index(net, ifindex);
469 return ERR_PTR(-ENODEV);
474 *parent = (*q)->handle;
476 *q = qdisc_lookup(dev, TC_H_MAJ(*parent));
478 NL_SET_ERR_MSG(extack, "Parent Qdisc doesn't exists");
479 return ERR_PTR(-EINVAL);
483 /* Is it classful? */
484 cops = (*q)->ops->cl_ops;
486 NL_SET_ERR_MSG(extack, "Qdisc not classful");
487 return ERR_PTR(-EINVAL);
490 if (!cops->tcf_block) {
491 NL_SET_ERR_MSG(extack, "Class doesn't support blocks");
492 return ERR_PTR(-EOPNOTSUPP);
495 /* Do we search for filter, attached to class? */
496 if (TC_H_MIN(*parent)) {
497 *cl = cops->find(*q, *parent);
499 NL_SET_ERR_MSG(extack, "Specified class doesn't exist");
500 return ERR_PTR(-ENOENT);
504 /* And the last stroke */
505 block = cops->tcf_block(*q, *cl, extack);
507 return ERR_PTR(-EINVAL);
508 if (tcf_block_shared(block)) {
509 NL_SET_ERR_MSG(extack, "This filter block is shared. Please use the block index to manipulate the filters");
510 return ERR_PTR(-EOPNOTSUPP);
517 static struct tcf_chain *tcf_block_chain_zero(struct tcf_block *block)
519 return list_first_entry(&block->chain_list, struct tcf_chain, list);
522 struct tcf_block_owner_item {
523 struct list_head list;
525 enum tcf_block_binder_type binder_type;
529 tcf_block_owner_netif_keep_dst(struct tcf_block *block,
531 enum tcf_block_binder_type binder_type)
533 if (block->keep_dst &&
534 binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS &&
535 binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
536 netif_keep_dst(qdisc_dev(q));
539 void tcf_block_netif_keep_dst(struct tcf_block *block)
541 struct tcf_block_owner_item *item;
543 block->keep_dst = true;
544 list_for_each_entry(item, &block->owner_list, list)
545 tcf_block_owner_netif_keep_dst(block, item->q,
548 EXPORT_SYMBOL(tcf_block_netif_keep_dst);
550 static int tcf_block_owner_add(struct tcf_block *block,
552 enum tcf_block_binder_type binder_type)
554 struct tcf_block_owner_item *item;
556 item = kmalloc(sizeof(*item), GFP_KERNEL);
560 item->binder_type = binder_type;
561 list_add(&item->list, &block->owner_list);
565 static void tcf_block_owner_del(struct tcf_block *block,
567 enum tcf_block_binder_type binder_type)
569 struct tcf_block_owner_item *item;
571 list_for_each_entry(item, &block->owner_list, list) {
572 if (item->q == q && item->binder_type == binder_type) {
573 list_del(&item->list);
581 int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
582 struct tcf_block_ext_info *ei,
583 struct netlink_ext_ack *extack)
585 struct net *net = qdisc_net(q);
586 struct tcf_block *block = NULL;
587 bool created = false;
590 if (ei->block_index) {
591 /* block_index not 0 means the shared block is requested */
592 block = tcf_block_lookup(net, ei->block_index);
598 block = tcf_block_create(net, q, ei->block_index, extack);
600 return PTR_ERR(block);
602 if (tcf_block_shared(block)) {
603 err = tcf_block_insert(block, net, extack);
605 goto err_block_insert;
609 err = tcf_block_owner_add(block, q, ei->binder_type);
611 goto err_block_owner_add;
613 tcf_block_owner_netif_keep_dst(block, q, ei->binder_type);
615 err = tcf_chain_head_change_cb_add(tcf_block_chain_zero(block),
618 goto err_chain_head_change_cb_add;
620 err = tcf_block_offload_bind(block, q, ei, extack);
622 goto err_block_offload_bind;
627 err_block_offload_bind:
628 tcf_chain_head_change_cb_del(tcf_block_chain_zero(block), ei);
629 err_chain_head_change_cb_add:
630 tcf_block_owner_del(block, q, ei->binder_type);
633 if (tcf_block_shared(block))
634 tcf_block_remove(block, net);
636 kfree(tcf_block_chain_zero(block));
643 EXPORT_SYMBOL(tcf_block_get_ext);
645 static void tcf_chain_head_change_dflt(struct tcf_proto *tp_head, void *priv)
647 struct tcf_proto __rcu **p_filter_chain = priv;
649 rcu_assign_pointer(*p_filter_chain, tp_head);
652 int tcf_block_get(struct tcf_block **p_block,
653 struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
654 struct netlink_ext_ack *extack)
656 struct tcf_block_ext_info ei = {
657 .chain_head_change = tcf_chain_head_change_dflt,
658 .chain_head_change_priv = p_filter_chain,
661 WARN_ON(!p_filter_chain);
662 return tcf_block_get_ext(p_block, q, &ei, extack);
664 EXPORT_SYMBOL(tcf_block_get);
666 /* XXX: Standalone actions are not allowed to jump to any chain, and bound
667 * actions should be all removed after flushing.
669 void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
670 struct tcf_block_ext_info *ei)
672 struct tcf_chain *chain, *tmp;
676 tcf_chain_head_change_cb_del(tcf_block_chain_zero(block), ei);
677 tcf_block_owner_del(block, q, ei->binder_type);
679 if (--block->refcnt == 0) {
680 if (tcf_block_shared(block))
681 tcf_block_remove(block, block->net);
683 /* Hold a refcnt for all chains, so that they don't disappear
684 * while we are iterating.
686 list_for_each_entry(chain, &block->chain_list, list)
687 tcf_chain_hold(chain);
689 list_for_each_entry(chain, &block->chain_list, list)
690 tcf_chain_flush(chain);
693 tcf_block_offload_unbind(block, q, ei);
695 if (block->refcnt == 0) {
696 /* At this point, all the chains should have refcnt >= 1. */
697 list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
698 tcf_chain_put(chain);
700 /* Finally, put chain 0 and allow block to be freed. */
701 tcf_chain_put(tcf_block_chain_zero(block));
704 EXPORT_SYMBOL(tcf_block_put_ext);
706 void tcf_block_put(struct tcf_block *block)
708 struct tcf_block_ext_info ei = {0, };
712 tcf_block_put_ext(block, block->q, &ei);
715 EXPORT_SYMBOL(tcf_block_put);
717 struct tcf_block_cb {
718 struct list_head list;
725 void *tcf_block_cb_priv(struct tcf_block_cb *block_cb)
727 return block_cb->cb_priv;
729 EXPORT_SYMBOL(tcf_block_cb_priv);
731 struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
732 tc_setup_cb_t *cb, void *cb_ident)
733 { struct tcf_block_cb *block_cb;
735 list_for_each_entry(block_cb, &block->cb_list, list)
736 if (block_cb->cb == cb && block_cb->cb_ident == cb_ident)
740 EXPORT_SYMBOL(tcf_block_cb_lookup);
742 void tcf_block_cb_incref(struct tcf_block_cb *block_cb)
746 EXPORT_SYMBOL(tcf_block_cb_incref);
748 unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
750 return --block_cb->refcnt;
752 EXPORT_SYMBOL(tcf_block_cb_decref);
755 tcf_block_playback_offloads(struct tcf_block *block, tc_setup_cb_t *cb,
756 void *cb_priv, bool add, bool offload_in_use,
757 struct netlink_ext_ack *extack)
759 struct tcf_chain *chain;
760 struct tcf_proto *tp;
763 list_for_each_entry(chain, &block->chain_list, list) {
764 for (tp = rtnl_dereference(chain->filter_chain); tp;
765 tp = rtnl_dereference(tp->next)) {
766 if (tp->ops->reoffload) {
767 err = tp->ops->reoffload(tp, add, cb, cb_priv,
770 goto err_playback_remove;
771 } else if (add && offload_in_use) {
773 NL_SET_ERR_MSG(extack, "Filter HW offload failed - classifier without re-offloading support");
774 goto err_playback_remove;
782 tcf_block_playback_offloads(block, cb, cb_priv, false, offload_in_use,
787 struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
788 tc_setup_cb_t *cb, void *cb_ident,
790 struct netlink_ext_ack *extack)
792 struct tcf_block_cb *block_cb;
795 /* Replay any already present rules */
796 err = tcf_block_playback_offloads(block, cb, cb_priv, true,
797 tcf_block_offload_in_use(block),
802 block_cb = kzalloc(sizeof(*block_cb), GFP_KERNEL);
804 return ERR_PTR(-ENOMEM);
806 block_cb->cb_ident = cb_ident;
807 block_cb->cb_priv = cb_priv;
808 list_add(&block_cb->list, &block->cb_list);
811 EXPORT_SYMBOL(__tcf_block_cb_register);
813 int tcf_block_cb_register(struct tcf_block *block,
814 tc_setup_cb_t *cb, void *cb_ident,
815 void *cb_priv, struct netlink_ext_ack *extack)
817 struct tcf_block_cb *block_cb;
819 block_cb = __tcf_block_cb_register(block, cb, cb_ident, cb_priv,
821 return IS_ERR(block_cb) ? PTR_ERR(block_cb) : 0;
823 EXPORT_SYMBOL(tcf_block_cb_register);
825 void __tcf_block_cb_unregister(struct tcf_block *block,
826 struct tcf_block_cb *block_cb)
828 tcf_block_playback_offloads(block, block_cb->cb, block_cb->cb_priv,
829 false, tcf_block_offload_in_use(block),
831 list_del(&block_cb->list);
834 EXPORT_SYMBOL(__tcf_block_cb_unregister);
836 void tcf_block_cb_unregister(struct tcf_block *block,
837 tc_setup_cb_t *cb, void *cb_ident)
839 struct tcf_block_cb *block_cb;
841 block_cb = tcf_block_cb_lookup(block, cb, cb_ident);
844 __tcf_block_cb_unregister(block, block_cb);
846 EXPORT_SYMBOL(tcf_block_cb_unregister);
848 static int tcf_block_cb_call(struct tcf_block *block, enum tc_setup_type type,
849 void *type_data, bool err_stop)
851 struct tcf_block_cb *block_cb;
855 /* Make sure all netdevs sharing this block are offload-capable. */
856 if (block->nooffloaddevcnt && err_stop)
859 list_for_each_entry(block_cb, &block->cb_list, list) {
860 err = block_cb->cb(type, type_data, block_cb->cb_priv);
871 /* Main classifier routine: scans classifier chain attached
872 * to this qdisc, (optionally) tests for protocol and asks
873 * specific classifiers.
875 int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
876 struct tcf_result *res, bool compat_mode)
878 __be16 protocol = tc_skb_protocol(skb);
879 #ifdef CONFIG_NET_CLS_ACT
880 const int max_reclassify_loop = 4;
881 const struct tcf_proto *orig_tp = tp;
882 const struct tcf_proto *first_tp;
887 for (; tp; tp = rcu_dereference_bh(tp->next)) {
890 if (tp->protocol != protocol &&
891 tp->protocol != htons(ETH_P_ALL))
894 err = tp->classify(skb, tp, res);
895 #ifdef CONFIG_NET_CLS_ACT
896 if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) {
899 } else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) {
900 first_tp = res->goto_tp;
908 return TC_ACT_UNSPEC; /* signal: continue lookup */
909 #ifdef CONFIG_NET_CLS_ACT
911 if (unlikely(limit++ >= max_reclassify_loop)) {
912 net_notice_ratelimited("%u: reclassify loop, rule prio %u, protocol %02x\n",
913 tp->chain->block->index,
915 ntohs(tp->protocol));
920 protocol = tc_skb_protocol(skb);
924 EXPORT_SYMBOL(tcf_classify);
926 struct tcf_chain_info {
927 struct tcf_proto __rcu **pprev;
928 struct tcf_proto __rcu *next;
931 static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain_info *chain_info)
933 return rtnl_dereference(*chain_info->pprev);
936 static void tcf_chain_tp_insert(struct tcf_chain *chain,
937 struct tcf_chain_info *chain_info,
938 struct tcf_proto *tp)
940 if (*chain_info->pprev == chain->filter_chain)
941 tcf_chain_head_change(chain, tp);
942 RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain_info));
943 rcu_assign_pointer(*chain_info->pprev, tp);
944 tcf_chain_hold(chain);
947 static void tcf_chain_tp_remove(struct tcf_chain *chain,
948 struct tcf_chain_info *chain_info,
949 struct tcf_proto *tp)
951 struct tcf_proto *next = rtnl_dereference(chain_info->next);
953 if (tp == chain->filter_chain)
954 tcf_chain_head_change(chain, next);
955 RCU_INIT_POINTER(*chain_info->pprev, next);
956 tcf_chain_put(chain);
959 static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
960 struct tcf_chain_info *chain_info,
961 u32 protocol, u32 prio,
964 struct tcf_proto **pprev;
965 struct tcf_proto *tp;
967 /* Check the chain for existence of proto-tcf with this priority */
968 for (pprev = &chain->filter_chain;
969 (tp = rtnl_dereference(*pprev)); pprev = &tp->next) {
970 if (tp->prio >= prio) {
971 if (tp->prio == prio) {
973 (tp->protocol != protocol && protocol))
974 return ERR_PTR(-EINVAL);
981 chain_info->pprev = pprev;
982 chain_info->next = tp ? tp->next : NULL;
986 static int tcf_fill_node(struct net *net, struct sk_buff *skb,
987 struct tcf_proto *tp, struct tcf_block *block,
988 struct Qdisc *q, u32 parent, void *fh,
989 u32 portid, u32 seq, u16 flags, int event)
992 struct nlmsghdr *nlh;
993 unsigned char *b = skb_tail_pointer(skb);
995 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
998 tcm = nlmsg_data(nlh);
999 tcm->tcm_family = AF_UNSPEC;
1003 tcm->tcm_ifindex = qdisc_dev(q)->ifindex;
1004 tcm->tcm_parent = parent;
1006 tcm->tcm_ifindex = TCM_IFINDEX_MAGIC_BLOCK;
1007 tcm->tcm_block_index = block->index;
1009 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
1010 if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
1011 goto nla_put_failure;
1012 if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
1013 goto nla_put_failure;
1015 tcm->tcm_handle = 0;
1017 if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0)
1018 goto nla_put_failure;
1020 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1029 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
1030 struct nlmsghdr *n, struct tcf_proto *tp,
1031 struct tcf_block *block, struct Qdisc *q,
1032 u32 parent, void *fh, int event, bool unicast)
1034 struct sk_buff *skb;
1035 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1037 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1041 if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid,
1042 n->nlmsg_seq, n->nlmsg_flags, event) <= 0) {
1048 return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1050 return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1051 n->nlmsg_flags & NLM_F_ECHO);
1054 static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
1055 struct nlmsghdr *n, struct tcf_proto *tp,
1056 struct tcf_block *block, struct Qdisc *q,
1057 u32 parent, void *fh, bool unicast, bool *last,
1058 struct netlink_ext_ack *extack)
1060 struct sk_buff *skb;
1061 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1064 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1068 if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid,
1069 n->nlmsg_seq, n->nlmsg_flags, RTM_DELTFILTER) <= 0) {
1070 NL_SET_ERR_MSG(extack, "Failed to build del event notification");
1075 err = tp->ops->delete(tp, fh, last, extack);
1082 return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1084 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1085 n->nlmsg_flags & NLM_F_ECHO);
1087 NL_SET_ERR_MSG(extack, "Failed to send filter delete notification");
1091 static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
1092 struct tcf_block *block, struct Qdisc *q,
1093 u32 parent, struct nlmsghdr *n,
1094 struct tcf_chain *chain, int event)
1096 struct tcf_proto *tp;
1098 for (tp = rtnl_dereference(chain->filter_chain);
1099 tp; tp = rtnl_dereference(tp->next))
1100 tfilter_notify(net, oskb, n, tp, block,
1101 q, parent, 0, event, false);
1104 static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
1105 struct netlink_ext_ack *extack)
1107 struct net *net = sock_net(skb->sk);
1108 struct nlattr *tca[TCA_MAX + 1];
1115 struct Qdisc *q = NULL;
1116 struct tcf_chain_info chain_info;
1117 struct tcf_chain *chain = NULL;
1118 struct tcf_block *block;
1119 struct tcf_proto *tp;
1125 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
1131 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1136 protocol = TC_H_MIN(t->tcm_info);
1137 prio = TC_H_MAJ(t->tcm_info);
1138 prio_allocate = false;
1139 parent = t->tcm_parent;
1143 /* If no priority is provided by the user,
1146 if (n->nlmsg_flags & NLM_F_CREATE) {
1147 prio = TC_H_MAKE(0x80000000U, 0U);
1148 prio_allocate = true;
1150 NL_SET_ERR_MSG(extack, "Invalid filter command with priority of zero");
1155 /* Find head of filter chain. */
1157 block = tcf_block_find(net, &q, &parent, &cl,
1158 t->tcm_ifindex, t->tcm_block_index, extack);
1159 if (IS_ERR(block)) {
1160 err = PTR_ERR(block);
1164 chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
1165 if (chain_index > TC_ACT_EXT_VAL_MASK) {
1166 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
1170 chain = tcf_chain_get(block, chain_index, true);
1172 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
1177 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
1178 prio, prio_allocate);
1180 NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found");
1186 /* Proto-tcf does not exist, create new one */
1188 if (tca[TCA_KIND] == NULL || !protocol) {
1189 NL_SET_ERR_MSG(extack, "Filter kind and protocol must be specified");
1194 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
1195 NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter");
1201 prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info));
1203 tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
1204 protocol, prio, chain, extack);
1210 } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
1211 NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one");
1216 fh = tp->ops->get(tp, t->tcm_handle);
1219 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
1220 NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter");
1224 } else if (n->nlmsg_flags & NLM_F_EXCL) {
1225 NL_SET_ERR_MSG(extack, "Filter already exists");
1230 err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
1231 n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE,
1235 tcf_chain_tp_insert(chain, &chain_info, tp);
1236 tfilter_notify(net, skb, n, tp, block, q, parent, fh,
1237 RTM_NEWTFILTER, false);
1240 tcf_proto_destroy(tp, NULL);
1245 tcf_chain_put(chain);
1247 /* Replay the request. */
1252 static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
1253 struct netlink_ext_ack *extack)
1255 struct net *net = sock_net(skb->sk);
1256 struct nlattr *tca[TCA_MAX + 1];
1262 struct Qdisc *q = NULL;
1263 struct tcf_chain_info chain_info;
1264 struct tcf_chain *chain = NULL;
1265 struct tcf_block *block;
1266 struct tcf_proto *tp = NULL;
1267 unsigned long cl = 0;
1271 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
1274 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1279 protocol = TC_H_MIN(t->tcm_info);
1280 prio = TC_H_MAJ(t->tcm_info);
1281 parent = t->tcm_parent;
1283 if (prio == 0 && (protocol || t->tcm_handle || tca[TCA_KIND])) {
1284 NL_SET_ERR_MSG(extack, "Cannot flush filters with protocol, handle or kind set");
1288 /* Find head of filter chain. */
1290 block = tcf_block_find(net, &q, &parent, &cl,
1291 t->tcm_ifindex, t->tcm_block_index, extack);
1292 if (IS_ERR(block)) {
1293 err = PTR_ERR(block);
1297 chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
1298 if (chain_index > TC_ACT_EXT_VAL_MASK) {
1299 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
1303 chain = tcf_chain_get(block, chain_index, false);
1305 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
1311 tfilter_notify_chain(net, skb, block, q, parent, n,
1312 chain, RTM_DELTFILTER);
1313 tcf_chain_flush(chain);
1318 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
1320 if (!tp || IS_ERR(tp)) {
1321 NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found");
1322 err = tp ? PTR_ERR(tp) : -ENOENT;
1324 } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
1325 NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one");
1330 fh = tp->ops->get(tp, t->tcm_handle);
1333 if (t->tcm_handle == 0) {
1334 tcf_chain_tp_remove(chain, &chain_info, tp);
1335 tfilter_notify(net, skb, n, tp, block, q, parent, fh,
1336 RTM_DELTFILTER, false);
1337 tcf_proto_destroy(tp, extack);
1340 NL_SET_ERR_MSG(extack, "Specified filter handle not found");
1346 err = tfilter_del_notify(net, skb, n, tp, block,
1347 q, parent, fh, false, &last,
1352 tcf_chain_tp_remove(chain, &chain_info, tp);
1353 tcf_proto_destroy(tp, extack);
1359 tcf_chain_put(chain);
1363 static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
1364 struct netlink_ext_ack *extack)
1366 struct net *net = sock_net(skb->sk);
1367 struct nlattr *tca[TCA_MAX + 1];
1373 struct Qdisc *q = NULL;
1374 struct tcf_chain_info chain_info;
1375 struct tcf_chain *chain = NULL;
1376 struct tcf_block *block;
1377 struct tcf_proto *tp = NULL;
1378 unsigned long cl = 0;
1382 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1387 protocol = TC_H_MIN(t->tcm_info);
1388 prio = TC_H_MAJ(t->tcm_info);
1389 parent = t->tcm_parent;
1392 NL_SET_ERR_MSG(extack, "Invalid filter command with priority of zero");
1396 /* Find head of filter chain. */
1398 block = tcf_block_find(net, &q, &parent, &cl,
1399 t->tcm_ifindex, t->tcm_block_index, extack);
1400 if (IS_ERR(block)) {
1401 err = PTR_ERR(block);
1405 chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
1406 if (chain_index > TC_ACT_EXT_VAL_MASK) {
1407 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
1411 chain = tcf_chain_get(block, chain_index, false);
1413 NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
1418 tp = tcf_chain_tp_find(chain, &chain_info, protocol,
1420 if (!tp || IS_ERR(tp)) {
1421 NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found");
1422 err = tp ? PTR_ERR(tp) : -ENOENT;
1424 } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
1425 NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one");
1430 fh = tp->ops->get(tp, t->tcm_handle);
1433 NL_SET_ERR_MSG(extack, "Specified filter handle not found");
1436 err = tfilter_notify(net, skb, n, tp, block, q, parent,
1437 fh, RTM_NEWTFILTER, true);
1439 NL_SET_ERR_MSG(extack, "Failed to send filter notify message");
1444 tcf_chain_put(chain);
1448 struct tcf_dump_args {
1449 struct tcf_walker w;
1450 struct sk_buff *skb;
1451 struct netlink_callback *cb;
1452 struct tcf_block *block;
1457 static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
1459 struct tcf_dump_args *a = (void *)arg;
1460 struct net *net = sock_net(a->skb->sk);
1462 return tcf_fill_node(net, a->skb, tp, a->block, a->q, a->parent,
1463 n, NETLINK_CB(a->cb->skb).portid,
1464 a->cb->nlh->nlmsg_seq, NLM_F_MULTI,
1468 static bool tcf_chain_dump(struct tcf_chain *chain, struct Qdisc *q, u32 parent,
1469 struct sk_buff *skb, struct netlink_callback *cb,
1470 long index_start, long *p_index)
1472 struct net *net = sock_net(skb->sk);
1473 struct tcf_block *block = chain->block;
1474 struct tcmsg *tcm = nlmsg_data(cb->nlh);
1475 struct tcf_dump_args arg;
1476 struct tcf_proto *tp;
1478 for (tp = rtnl_dereference(chain->filter_chain);
1479 tp; tp = rtnl_dereference(tp->next), (*p_index)++) {
1480 if (*p_index < index_start)
1482 if (TC_H_MAJ(tcm->tcm_info) &&
1483 TC_H_MAJ(tcm->tcm_info) != tp->prio)
1485 if (TC_H_MIN(tcm->tcm_info) &&
1486 TC_H_MIN(tcm->tcm_info) != tp->protocol)
1488 if (*p_index > index_start)
1489 memset(&cb->args[1], 0,
1490 sizeof(cb->args) - sizeof(cb->args[0]));
1491 if (cb->args[1] == 0) {
1492 if (tcf_fill_node(net, skb, tp, block, q, parent, 0,
1493 NETLINK_CB(cb->skb).portid,
1494 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1495 RTM_NEWTFILTER) <= 0)
1502 arg.w.fn = tcf_node_dump;
1507 arg.parent = parent;
1509 arg.w.skip = cb->args[1] - 1;
1511 tp->ops->walk(tp, &arg.w);
1512 cb->args[1] = arg.w.count + 1;
1519 /* called with RTNL */
1520 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
1522 struct net *net = sock_net(skb->sk);
1523 struct nlattr *tca[TCA_MAX + 1];
1524 struct Qdisc *q = NULL;
1525 struct tcf_block *block;
1526 struct tcf_chain *chain;
1527 struct tcmsg *tcm = nlmsg_data(cb->nlh);
1533 if (nlmsg_len(cb->nlh) < sizeof(*tcm))
1536 err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, NULL);
1540 if (tcm->tcm_ifindex == TCM_IFINDEX_MAGIC_BLOCK) {
1541 block = tcf_block_lookup(net, tcm->tcm_block_index);
1544 /* If we work with block index, q is NULL and parent value
1545 * will never be used in the following code. The check
1546 * in tcf_fill_node prevents it. However, compiler does not
1547 * see that far, so set parent to zero to silence the warning
1548 * about parent being uninitialized.
1552 const struct Qdisc_class_ops *cops;
1553 struct net_device *dev;
1554 unsigned long cl = 0;
1556 dev = __dev_get_by_index(net, tcm->tcm_ifindex);
1560 parent = tcm->tcm_parent;
1565 q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
1569 cops = q->ops->cl_ops;
1572 if (!cops->tcf_block)
1574 if (TC_H_MIN(tcm->tcm_parent)) {
1575 cl = cops->find(q, tcm->tcm_parent);
1579 block = cops->tcf_block(q, cl, NULL);
1582 if (tcf_block_shared(block))
1586 index_start = cb->args[0];
1589 list_for_each_entry(chain, &block->chain_list, list) {
1590 if (tca[TCA_CHAIN] &&
1591 nla_get_u32(tca[TCA_CHAIN]) != chain->index)
1593 if (!tcf_chain_dump(chain, q, parent, skb, cb,
1594 index_start, &index)) {
1600 cb->args[0] = index;
1603 /* If we did no progress, the error (EMSGSIZE) is real */
1604 if (skb->len == 0 && err)
1609 void tcf_exts_destroy(struct tcf_exts *exts)
1611 #ifdef CONFIG_NET_CLS_ACT
1614 tcf_exts_to_list(exts, &actions);
1615 tcf_action_destroy(&actions, TCA_ACT_UNBIND);
1616 kfree(exts->actions);
1617 exts->nr_actions = 0;
1620 EXPORT_SYMBOL(tcf_exts_destroy);
1622 int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
1623 struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr,
1624 struct netlink_ext_ack *extack)
1626 #ifdef CONFIG_NET_CLS_ACT
1628 struct tc_action *act;
1629 size_t attr_size = 0;
1631 if (exts->police && tb[exts->police]) {
1632 act = tcf_action_init_1(net, tp, tb[exts->police],
1633 rate_tlv, "police", ovr,
1634 TCA_ACT_BIND, true, extack);
1636 return PTR_ERR(act);
1638 act->type = exts->type = TCA_OLD_COMPAT;
1639 exts->actions[0] = act;
1640 exts->nr_actions = 1;
1641 } else if (exts->action && tb[exts->action]) {
1645 err = tcf_action_init(net, tp, tb[exts->action],
1646 rate_tlv, NULL, ovr, TCA_ACT_BIND,
1647 &actions, &attr_size, true,
1651 list_for_each_entry(act, &actions, list)
1652 exts->actions[i++] = act;
1653 exts->nr_actions = i;
1658 if ((exts->action && tb[exts->action]) ||
1659 (exts->police && tb[exts->police])) {
1660 NL_SET_ERR_MSG(extack, "Classifier actions are not supported per compile options (CONFIG_NET_CLS_ACT)");
1667 EXPORT_SYMBOL(tcf_exts_validate);
1669 void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src)
1671 #ifdef CONFIG_NET_CLS_ACT
1672 struct tcf_exts old = *dst;
1675 tcf_exts_destroy(&old);
1678 EXPORT_SYMBOL(tcf_exts_change);
1680 #ifdef CONFIG_NET_CLS_ACT
1681 static struct tc_action *tcf_exts_first_act(struct tcf_exts *exts)
1683 if (exts->nr_actions == 0)
1686 return exts->actions[0];
1690 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
1692 #ifdef CONFIG_NET_CLS_ACT
1693 struct nlattr *nest;
1695 if (exts->action && tcf_exts_has_actions(exts)) {
1697 * again for backward compatible mode - we want
1698 * to work with both old and new modes of entering
1699 * tc data even if iproute2 was newer - jhs
1701 if (exts->type != TCA_OLD_COMPAT) {
1704 nest = nla_nest_start(skb, exts->action);
1706 goto nla_put_failure;
1708 tcf_exts_to_list(exts, &actions);
1709 if (tcf_action_dump(skb, &actions, 0, 0) < 0)
1710 goto nla_put_failure;
1711 nla_nest_end(skb, nest);
1712 } else if (exts->police) {
1713 struct tc_action *act = tcf_exts_first_act(exts);
1714 nest = nla_nest_start(skb, exts->police);
1715 if (nest == NULL || !act)
1716 goto nla_put_failure;
1717 if (tcf_action_dump_old(skb, act, 0, 0) < 0)
1718 goto nla_put_failure;
1719 nla_nest_end(skb, nest);
1725 nla_nest_cancel(skb, nest);
1731 EXPORT_SYMBOL(tcf_exts_dump);
1734 int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
1736 #ifdef CONFIG_NET_CLS_ACT
1737 struct tc_action *a = tcf_exts_first_act(exts);
1738 if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
1743 EXPORT_SYMBOL(tcf_exts_dump_stats);
1745 static int tc_exts_setup_cb_egdev_call(struct tcf_exts *exts,
1746 enum tc_setup_type type,
1747 void *type_data, bool err_stop)
1750 #ifdef CONFIG_NET_CLS_ACT
1751 const struct tc_action *a;
1752 struct net_device *dev;
1755 if (!tcf_exts_has_actions(exts))
1758 for (i = 0; i < exts->nr_actions; i++) {
1759 a = exts->actions[i];
1760 if (!a->ops->get_dev)
1762 dev = a->ops->get_dev(a);
1765 ret = tc_setup_cb_egdev_call(dev, type, type_data, err_stop);
1774 int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts,
1775 enum tc_setup_type type, void *type_data, bool err_stop)
1780 ret = tcf_block_cb_call(block, type, type_data, err_stop);
1785 if (!exts || ok_count)
1787 ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop);
1794 EXPORT_SYMBOL(tc_setup_cb_call);
1796 static __net_init int tcf_net_init(struct net *net)
1798 struct tcf_net *tn = net_generic(net, tcf_net_id);
1804 static void __net_exit tcf_net_exit(struct net *net)
1806 struct tcf_net *tn = net_generic(net, tcf_net_id);
1808 idr_destroy(&tn->idr);
1811 static struct pernet_operations tcf_net_ops = {
1812 .init = tcf_net_init,
1813 .exit = tcf_net_exit,
1815 .size = sizeof(struct tcf_net),
1818 static int __init tc_filter_init(void)
1822 tc_filter_wq = alloc_ordered_workqueue("tc_filter_workqueue", 0);
1826 err = register_pernet_subsys(&tcf_net_ops);
1828 goto err_register_pernet_subsys;
1830 rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL, 0);
1831 rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL, 0);
1832 rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter,
1833 tc_dump_tfilter, 0);
1837 err_register_pernet_subsys:
1838 destroy_workqueue(tc_filter_wq);
1842 subsys_initcall(tc_filter_init);