2 * net/sched/sch_api.c Packet scheduler 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 * Rani Assaf <rani@magic.metawire.com> :980802: JIFFIES and CPU clock sources are repaired.
14 * Eduardo J. Blanco <ejbs@netlabs.com.uy> :990222: kmod support
15 * Jamal Hadi Salim <hadi@nortelnetworks.com>: 990601: ingress support
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/errno.h>
23 #include <linux/skbuff.h>
24 #include <linux/init.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27 #include <linux/kmod.h>
28 #include <linux/list.h>
29 #include <linux/hrtimer.h>
30 #include <linux/lockdep.h>
31 #include <linux/slab.h>
33 #include <net/net_namespace.h>
35 #include <net/netlink.h>
36 #include <net/pkt_sched.h>
38 static int qdisc_notify(struct net *net, struct sk_buff *oskb,
39 struct nlmsghdr *n, u32 clid,
40 struct Qdisc *old, struct Qdisc *new);
41 static int tclass_notify(struct net *net, struct sk_buff *oskb,
42 struct nlmsghdr *n, struct Qdisc *q,
43 unsigned long cl, int event);
50 This file consists of two interrelated parts:
52 1. queueing disciplines manager frontend.
53 2. traffic classes manager frontend.
55 Generally, queueing discipline ("qdisc") is a black box,
56 which is able to enqueue packets and to dequeue them (when
57 device is ready to send something) in order and at times
58 determined by algorithm hidden in it.
60 qdisc's are divided to two categories:
61 - "queues", which have no internal structure visible from outside.
62 - "schedulers", which split all the packets to "traffic classes",
63 using "packet classifiers" (look at cls_api.c)
65 In turn, classes may have child qdiscs (as rule, queues)
66 attached to them etc. etc. etc.
68 The goal of the routines in this file is to translate
69 information supplied by user in the form of handles
70 to more intelligible for kernel form, to make some sanity
71 checks and part of work, which is common to all qdiscs
72 and to provide rtnetlink notifications.
74 All real intelligent work is done inside qdisc modules.
78 Every discipline has two major routines: enqueue and dequeue.
82 dequeue usually returns a skb to send. It is allowed to return NULL,
83 but it does not mean that queue is empty, it just means that
84 discipline does not want to send anything this time.
85 Queue is really empty if q->q.qlen == 0.
86 For complicated disciplines with multiple queues q->q is not
87 real packet queue, but however q->q.qlen must be valid.
91 enqueue returns 0, if packet was enqueued successfully.
92 If packet (this one or another one) was dropped, it returns
94 NET_XMIT_DROP - this packet dropped
95 Expected action: do not backoff, but wait until queue will clear.
96 NET_XMIT_CN - probably this packet enqueued, but another one dropped.
97 Expected action: backoff or ignore
98 NET_XMIT_POLICED - dropped by police.
99 Expected action: backoff or error to real-time apps.
105 like dequeue but without removing a packet from the queue
109 returns qdisc to initial state: purge all buffers, clear all
110 timers, counters (except for statistics) etc.
114 initializes newly created qdisc.
118 destroys resources allocated by init and during lifetime of qdisc.
122 changes qdisc parameters.
125 /* Protects list of registered TC modules. It is pure SMP lock. */
126 static DEFINE_RWLOCK(qdisc_mod_lock);
129 /************************************************
130 * Queueing disciplines manipulation. *
131 ************************************************/
134 /* The list of all installed queueing disciplines. */
136 static struct Qdisc_ops *qdisc_base;
138 /* Register/uregister queueing discipline */
140 int register_qdisc(struct Qdisc_ops *qops)
142 struct Qdisc_ops *q, **qp;
145 write_lock(&qdisc_mod_lock);
146 for (qp = &qdisc_base; (q = *qp) != NULL; qp = &q->next)
147 if (!strcmp(qops->id, q->id))
150 if (qops->enqueue == NULL)
151 qops->enqueue = noop_qdisc_ops.enqueue;
152 if (qops->peek == NULL) {
153 if (qops->dequeue == NULL)
154 qops->peek = noop_qdisc_ops.peek;
158 if (qops->dequeue == NULL)
159 qops->dequeue = noop_qdisc_ops.dequeue;
162 const struct Qdisc_class_ops *cops = qops->cl_ops;
164 if (!(cops->get && cops->put && cops->walk && cops->leaf))
167 if (cops->tcf_chain && !(cops->bind_tcf && cops->unbind_tcf))
175 write_unlock(&qdisc_mod_lock);
182 EXPORT_SYMBOL(register_qdisc);
184 int unregister_qdisc(struct Qdisc_ops *qops)
186 struct Qdisc_ops *q, **qp;
189 write_lock(&qdisc_mod_lock);
190 for (qp = &qdisc_base; (q = *qp) != NULL; qp = &q->next)
198 write_unlock(&qdisc_mod_lock);
201 EXPORT_SYMBOL(unregister_qdisc);
203 /* Get default qdisc if not otherwise specified */
204 void qdisc_get_default(char *name, size_t len)
206 read_lock(&qdisc_mod_lock);
207 strlcpy(name, default_qdisc_ops->id, len);
208 read_unlock(&qdisc_mod_lock);
211 static struct Qdisc_ops *qdisc_lookup_default(const char *name)
213 struct Qdisc_ops *q = NULL;
215 for (q = qdisc_base; q; q = q->next) {
216 if (!strcmp(name, q->id)) {
217 if (!try_module_get(q->owner))
226 /* Set new default qdisc to use */
227 int qdisc_set_default(const char *name)
229 const struct Qdisc_ops *ops;
231 if (!capable(CAP_NET_ADMIN))
234 write_lock(&qdisc_mod_lock);
235 ops = qdisc_lookup_default(name);
237 /* Not found, drop lock and try to load module */
238 write_unlock(&qdisc_mod_lock);
239 request_module("sch_%s", name);
240 write_lock(&qdisc_mod_lock);
242 ops = qdisc_lookup_default(name);
246 /* Set new default */
247 module_put(default_qdisc_ops->owner);
248 default_qdisc_ops = ops;
250 write_unlock(&qdisc_mod_lock);
252 return ops ? 0 : -ENOENT;
255 /* We know handle. Find qdisc among all qdisc's attached to device
256 (root qdisc, all its children, children of children etc.)
259 static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
263 if (!(root->flags & TCQ_F_BUILTIN) &&
264 root->handle == handle)
267 list_for_each_entry(q, &root->list, list) {
268 if (q->handle == handle)
274 void qdisc_list_add(struct Qdisc *q)
276 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
277 list_add_tail(&q->list, &qdisc_dev(q)->qdisc->list);
279 EXPORT_SYMBOL(qdisc_list_add);
281 void qdisc_list_del(struct Qdisc *q)
283 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
286 EXPORT_SYMBOL(qdisc_list_del);
288 struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle)
292 q = qdisc_match_from_root(dev->qdisc, handle);
296 if (dev_ingress_queue(dev))
297 q = qdisc_match_from_root(
298 dev_ingress_queue(dev)->qdisc_sleeping,
304 static struct Qdisc *qdisc_leaf(struct Qdisc *p, u32 classid)
308 const struct Qdisc_class_ops *cops = p->ops->cl_ops;
312 cl = cops->get(p, classid);
316 leaf = cops->leaf(p, cl);
321 /* Find queueing discipline by name */
323 static struct Qdisc_ops *qdisc_lookup_ops(struct nlattr *kind)
325 struct Qdisc_ops *q = NULL;
328 read_lock(&qdisc_mod_lock);
329 for (q = qdisc_base; q; q = q->next) {
330 if (nla_strcmp(kind, q->id) == 0) {
331 if (!try_module_get(q->owner))
336 read_unlock(&qdisc_mod_lock);
341 /* The linklayer setting were not transferred from iproute2, in older
342 * versions, and the rate tables lookup systems have been dropped in
343 * the kernel. To keep backward compatible with older iproute2 tc
344 * utils, we detect the linklayer setting by detecting if the rate
345 * table were modified.
347 * For linklayer ATM table entries, the rate table will be aligned to
348 * 48 bytes, thus some table entries will contain the same value. The
349 * mpu (min packet unit) is also encoded into the old rate table, thus
350 * starting from the mpu, we find low and high table entries for
351 * mapping this cell. If these entries contain the same value, when
352 * the rate tables have been modified for linklayer ATM.
354 * This is done by rounding mpu to the nearest 48 bytes cell/entry,
355 * and then roundup to the next cell, calc the table entry one below,
358 static __u8 __detect_linklayer(struct tc_ratespec *r, __u32 *rtab)
360 int low = roundup(r->mpu, 48);
361 int high = roundup(low+1, 48);
362 int cell_low = low >> r->cell_log;
363 int cell_high = (high >> r->cell_log) - 1;
365 /* rtab is too inaccurate at rates > 100Mbit/s */
366 if ((r->rate > (100000000/8)) || (rtab[0] == 0)) {
367 pr_debug("TC linklayer: Giving up ATM detection\n");
368 return TC_LINKLAYER_ETHERNET;
371 if ((cell_high > cell_low) && (cell_high < 256)
372 && (rtab[cell_low] == rtab[cell_high])) {
373 pr_debug("TC linklayer: Detected ATM, low(%d)=high(%d)=%u\n",
374 cell_low, cell_high, rtab[cell_high]);
375 return TC_LINKLAYER_ATM;
377 return TC_LINKLAYER_ETHERNET;
380 static struct qdisc_rate_table *qdisc_rtab_list;
382 struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r, struct nlattr *tab)
384 struct qdisc_rate_table *rtab;
386 if (tab == NULL || r->rate == 0 || r->cell_log == 0 ||
387 nla_len(tab) != TC_RTAB_SIZE)
390 for (rtab = qdisc_rtab_list; rtab; rtab = rtab->next) {
391 if (!memcmp(&rtab->rate, r, sizeof(struct tc_ratespec)) &&
392 !memcmp(&rtab->data, nla_data(tab), 1024)) {
398 rtab = kmalloc(sizeof(*rtab), GFP_KERNEL);
402 memcpy(rtab->data, nla_data(tab), 1024);
403 if (r->linklayer == TC_LINKLAYER_UNAWARE)
404 r->linklayer = __detect_linklayer(r, rtab->data);
405 rtab->next = qdisc_rtab_list;
406 qdisc_rtab_list = rtab;
410 EXPORT_SYMBOL(qdisc_get_rtab);
412 void qdisc_put_rtab(struct qdisc_rate_table *tab)
414 struct qdisc_rate_table *rtab, **rtabp;
416 if (!tab || --tab->refcnt)
419 for (rtabp = &qdisc_rtab_list;
420 (rtab = *rtabp) != NULL;
421 rtabp = &rtab->next) {
429 EXPORT_SYMBOL(qdisc_put_rtab);
431 static LIST_HEAD(qdisc_stab_list);
432 static DEFINE_SPINLOCK(qdisc_stab_lock);
434 static const struct nla_policy stab_policy[TCA_STAB_MAX + 1] = {
435 [TCA_STAB_BASE] = { .len = sizeof(struct tc_sizespec) },
436 [TCA_STAB_DATA] = { .type = NLA_BINARY },
439 static struct qdisc_size_table *qdisc_get_stab(struct nlattr *opt)
441 struct nlattr *tb[TCA_STAB_MAX + 1];
442 struct qdisc_size_table *stab;
443 struct tc_sizespec *s;
444 unsigned int tsize = 0;
448 err = nla_parse_nested(tb, TCA_STAB_MAX, opt, stab_policy);
451 if (!tb[TCA_STAB_BASE])
452 return ERR_PTR(-EINVAL);
454 s = nla_data(tb[TCA_STAB_BASE]);
457 if (!tb[TCA_STAB_DATA])
458 return ERR_PTR(-EINVAL);
459 tab = nla_data(tb[TCA_STAB_DATA]);
460 tsize = nla_len(tb[TCA_STAB_DATA]) / sizeof(u16);
463 if (tsize != s->tsize || (!tab && tsize > 0))
464 return ERR_PTR(-EINVAL);
466 spin_lock(&qdisc_stab_lock);
468 list_for_each_entry(stab, &qdisc_stab_list, list) {
469 if (memcmp(&stab->szopts, s, sizeof(*s)))
471 if (tsize > 0 && memcmp(stab->data, tab, tsize * sizeof(u16)))
474 spin_unlock(&qdisc_stab_lock);
478 spin_unlock(&qdisc_stab_lock);
480 stab = kmalloc(sizeof(*stab) + tsize * sizeof(u16), GFP_KERNEL);
482 return ERR_PTR(-ENOMEM);
487 memcpy(stab->data, tab, tsize * sizeof(u16));
489 spin_lock(&qdisc_stab_lock);
490 list_add_tail(&stab->list, &qdisc_stab_list);
491 spin_unlock(&qdisc_stab_lock);
496 static void stab_kfree_rcu(struct rcu_head *head)
498 kfree(container_of(head, struct qdisc_size_table, rcu));
501 void qdisc_put_stab(struct qdisc_size_table *tab)
506 spin_lock(&qdisc_stab_lock);
508 if (--tab->refcnt == 0) {
509 list_del(&tab->list);
510 call_rcu_bh(&tab->rcu, stab_kfree_rcu);
513 spin_unlock(&qdisc_stab_lock);
515 EXPORT_SYMBOL(qdisc_put_stab);
517 static int qdisc_dump_stab(struct sk_buff *skb, struct qdisc_size_table *stab)
521 nest = nla_nest_start(skb, TCA_STAB);
523 goto nla_put_failure;
524 if (nla_put(skb, TCA_STAB_BASE, sizeof(stab->szopts), &stab->szopts))
525 goto nla_put_failure;
526 nla_nest_end(skb, nest);
534 void __qdisc_calculate_pkt_len(struct sk_buff *skb, const struct qdisc_size_table *stab)
538 pkt_len = skb->len + stab->szopts.overhead;
539 if (unlikely(!stab->szopts.tsize))
542 slot = pkt_len + stab->szopts.cell_align;
543 if (unlikely(slot < 0))
546 slot >>= stab->szopts.cell_log;
547 if (likely(slot < stab->szopts.tsize))
548 pkt_len = stab->data[slot];
550 pkt_len = stab->data[stab->szopts.tsize - 1] *
551 (slot / stab->szopts.tsize) +
552 stab->data[slot % stab->szopts.tsize];
554 pkt_len <<= stab->szopts.size_log;
556 if (unlikely(pkt_len < 1))
558 qdisc_skb_cb(skb)->pkt_len = pkt_len;
560 EXPORT_SYMBOL(__qdisc_calculate_pkt_len);
562 void qdisc_warn_nonwc(char *txt, struct Qdisc *qdisc)
564 if (!(qdisc->flags & TCQ_F_WARN_NONWC)) {
565 pr_warn("%s: %s qdisc %X: is non-work-conserving?\n",
566 txt, qdisc->ops->id, qdisc->handle >> 16);
567 qdisc->flags |= TCQ_F_WARN_NONWC;
570 EXPORT_SYMBOL(qdisc_warn_nonwc);
572 static enum hrtimer_restart qdisc_watchdog(struct hrtimer *timer)
574 struct qdisc_watchdog *wd = container_of(timer, struct qdisc_watchdog,
577 qdisc_unthrottled(wd->qdisc);
578 __netif_schedule(qdisc_root(wd->qdisc));
580 return HRTIMER_NORESTART;
583 void qdisc_watchdog_init(struct qdisc_watchdog *wd, struct Qdisc *qdisc)
585 hrtimer_init(&wd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
586 wd->timer.function = qdisc_watchdog;
589 EXPORT_SYMBOL(qdisc_watchdog_init);
591 void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd, u64 expires)
593 if (test_bit(__QDISC_STATE_DEACTIVATED,
594 &qdisc_root_sleeping(wd->qdisc)->state))
597 qdisc_throttled(wd->qdisc);
599 hrtimer_start(&wd->timer,
600 ns_to_ktime(expires),
603 EXPORT_SYMBOL(qdisc_watchdog_schedule_ns);
605 void qdisc_watchdog_cancel(struct qdisc_watchdog *wd)
607 hrtimer_cancel(&wd->timer);
608 qdisc_unthrottled(wd->qdisc);
610 EXPORT_SYMBOL(qdisc_watchdog_cancel);
612 static struct hlist_head *qdisc_class_hash_alloc(unsigned int n)
614 unsigned int size = n * sizeof(struct hlist_head), i;
615 struct hlist_head *h;
617 if (size <= PAGE_SIZE)
618 h = kmalloc(size, GFP_KERNEL);
620 h = (struct hlist_head *)
621 __get_free_pages(GFP_KERNEL, get_order(size));
624 for (i = 0; i < n; i++)
625 INIT_HLIST_HEAD(&h[i]);
630 static void qdisc_class_hash_free(struct hlist_head *h, unsigned int n)
632 unsigned int size = n * sizeof(struct hlist_head);
634 if (size <= PAGE_SIZE)
637 free_pages((unsigned long)h, get_order(size));
640 void qdisc_class_hash_grow(struct Qdisc *sch, struct Qdisc_class_hash *clhash)
642 struct Qdisc_class_common *cl;
643 struct hlist_node *next;
644 struct hlist_head *nhash, *ohash;
645 unsigned int nsize, nmask, osize;
648 /* Rehash when load factor exceeds 0.75 */
649 if (clhash->hashelems * 4 <= clhash->hashsize * 3)
651 nsize = clhash->hashsize * 2;
653 nhash = qdisc_class_hash_alloc(nsize);
657 ohash = clhash->hash;
658 osize = clhash->hashsize;
661 for (i = 0; i < osize; i++) {
662 hlist_for_each_entry_safe(cl, next, &ohash[i], hnode) {
663 h = qdisc_class_hash(cl->classid, nmask);
664 hlist_add_head(&cl->hnode, &nhash[h]);
667 clhash->hash = nhash;
668 clhash->hashsize = nsize;
669 clhash->hashmask = nmask;
670 sch_tree_unlock(sch);
672 qdisc_class_hash_free(ohash, osize);
674 EXPORT_SYMBOL(qdisc_class_hash_grow);
676 int qdisc_class_hash_init(struct Qdisc_class_hash *clhash)
678 unsigned int size = 4;
680 clhash->hash = qdisc_class_hash_alloc(size);
681 if (clhash->hash == NULL)
683 clhash->hashsize = size;
684 clhash->hashmask = size - 1;
685 clhash->hashelems = 0;
688 EXPORT_SYMBOL(qdisc_class_hash_init);
690 void qdisc_class_hash_destroy(struct Qdisc_class_hash *clhash)
692 qdisc_class_hash_free(clhash->hash, clhash->hashsize);
694 EXPORT_SYMBOL(qdisc_class_hash_destroy);
696 void qdisc_class_hash_insert(struct Qdisc_class_hash *clhash,
697 struct Qdisc_class_common *cl)
701 INIT_HLIST_NODE(&cl->hnode);
702 h = qdisc_class_hash(cl->classid, clhash->hashmask);
703 hlist_add_head(&cl->hnode, &clhash->hash[h]);
706 EXPORT_SYMBOL(qdisc_class_hash_insert);
708 void qdisc_class_hash_remove(struct Qdisc_class_hash *clhash,
709 struct Qdisc_class_common *cl)
711 hlist_del(&cl->hnode);
714 EXPORT_SYMBOL(qdisc_class_hash_remove);
716 /* Allocate an unique handle from space managed by kernel
717 * Possible range is [8000-FFFF]:0000 (0x8000 values)
719 static u32 qdisc_alloc_handle(struct net_device *dev)
722 static u32 autohandle = TC_H_MAKE(0x80000000U, 0);
725 autohandle += TC_H_MAKE(0x10000U, 0);
726 if (autohandle == TC_H_MAKE(TC_H_ROOT, 0))
727 autohandle = TC_H_MAKE(0x80000000U, 0);
728 if (!qdisc_lookup(dev, autohandle))
736 void qdisc_tree_decrease_qlen(struct Qdisc *sch, unsigned int n)
738 const struct Qdisc_class_ops *cops;
745 drops = max_t(int, n, 0);
746 while ((parentid = sch->parent)) {
747 if (TC_H_MAJ(parentid) == TC_H_MAJ(TC_H_INGRESS))
750 sch = qdisc_lookup(qdisc_dev(sch), TC_H_MAJ(parentid));
752 WARN_ON(parentid != TC_H_ROOT);
755 cops = sch->ops->cl_ops;
756 if (cops->qlen_notify) {
757 cl = cops->get(sch, parentid);
758 cops->qlen_notify(sch, cl);
762 sch->qstats.drops += drops;
765 EXPORT_SYMBOL(qdisc_tree_decrease_qlen);
767 static void notify_and_destroy(struct net *net, struct sk_buff *skb,
768 struct nlmsghdr *n, u32 clid,
769 struct Qdisc *old, struct Qdisc *new)
772 qdisc_notify(net, skb, n, clid, old, new);
778 /* Graft qdisc "new" to class "classid" of qdisc "parent" or
781 * When appropriate send a netlink notification using 'skb'
784 * On success, destroy old qdisc.
787 static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
788 struct sk_buff *skb, struct nlmsghdr *n, u32 classid,
789 struct Qdisc *new, struct Qdisc *old)
791 struct Qdisc *q = old;
792 struct net *net = dev_net(dev);
795 if (parent == NULL) {
796 unsigned int i, num_q, ingress;
799 num_q = dev->num_tx_queues;
800 if ((q && q->flags & TCQ_F_INGRESS) ||
801 (new && new->flags & TCQ_F_INGRESS)) {
804 if (!dev_ingress_queue(dev))
808 if (dev->flags & IFF_UP)
811 if (new && new->ops->attach) {
812 new->ops->attach(new);
816 for (i = 0; i < num_q; i++) {
817 struct netdev_queue *dev_queue = dev_ingress_queue(dev);
820 dev_queue = netdev_get_tx_queue(dev, i);
822 old = dev_graft_qdisc(dev_queue, new);
824 atomic_inc(&new->refcnt);
831 notify_and_destroy(net, skb, n, classid,
833 if (new && !new->ops->attach)
834 atomic_inc(&new->refcnt);
835 dev->qdisc = new ? : &noop_qdisc;
837 notify_and_destroy(net, skb, n, classid, old, new);
840 if (dev->flags & IFF_UP)
843 const struct Qdisc_class_ops *cops = parent->ops->cl_ops;
846 if (cops && cops->graft) {
847 unsigned long cl = cops->get(parent, classid);
849 err = cops->graft(parent, cl, new, &old);
850 cops->put(parent, cl);
855 notify_and_destroy(net, skb, n, classid, old, new);
860 /* lockdep annotation is needed for ingress; egress gets it only for name */
861 static struct lock_class_key qdisc_tx_lock;
862 static struct lock_class_key qdisc_rx_lock;
865 Allocate and initialize new qdisc.
867 Parameters are passed via opt.
870 static struct Qdisc *
871 qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
872 struct Qdisc *p, u32 parent, u32 handle,
873 struct nlattr **tca, int *errp)
876 struct nlattr *kind = tca[TCA_KIND];
878 struct Qdisc_ops *ops;
879 struct qdisc_size_table *stab;
881 ops = qdisc_lookup_ops(kind);
882 #ifdef CONFIG_MODULES
883 if (ops == NULL && kind != NULL) {
885 if (nla_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {
886 /* We dropped the RTNL semaphore in order to
887 * perform the module load. So, even if we
888 * succeeded in loading the module we have to
889 * tell the caller to replay the request. We
890 * indicate this using -EAGAIN.
891 * We replay the request because the device may
892 * go away in the mean time.
895 request_module("sch_%s", name);
897 ops = qdisc_lookup_ops(kind);
899 /* We will try again qdisc_lookup_ops,
900 * so don't keep a reference.
902 module_put(ops->owner);
914 sch = qdisc_alloc(dev_queue, ops);
920 sch->parent = parent;
922 if (handle == TC_H_INGRESS) {
923 sch->flags |= TCQ_F_INGRESS;
924 handle = TC_H_MAKE(TC_H_INGRESS, 0);
925 lockdep_set_class(qdisc_lock(sch), &qdisc_rx_lock);
928 handle = qdisc_alloc_handle(dev);
933 lockdep_set_class(qdisc_lock(sch), &qdisc_tx_lock);
934 if (!netif_is_multiqueue(dev))
935 sch->flags |= TCQ_F_ONETXQUEUE;
938 sch->handle = handle;
940 if (!ops->init || (err = ops->init(sch, tca[TCA_OPTIONS])) == 0) {
942 stab = qdisc_get_stab(tca[TCA_STAB]);
947 rcu_assign_pointer(sch->stab, stab);
950 spinlock_t *root_lock;
953 if (sch->flags & TCQ_F_MQROOT)
956 if ((sch->parent != TC_H_ROOT) &&
957 !(sch->flags & TCQ_F_INGRESS) &&
958 (!p || !(p->flags & TCQ_F_MQROOT)))
959 root_lock = qdisc_root_sleeping_lock(sch);
961 root_lock = qdisc_lock(sch);
963 err = gen_new_estimator(&sch->bstats, &sch->rate_est,
964 root_lock, tca[TCA_RATE]);
975 kfree((char *) sch - sch->padded);
977 module_put(ops->owner);
984 * Any broken qdiscs that would require a ops->reset() here?
985 * The qdisc was never in action so it shouldn't be necessary.
987 qdisc_put_stab(rtnl_dereference(sch->stab));
993 static int qdisc_change(struct Qdisc *sch, struct nlattr **tca)
995 struct qdisc_size_table *ostab, *stab = NULL;
998 if (tca[TCA_OPTIONS]) {
999 if (sch->ops->change == NULL)
1001 err = sch->ops->change(sch, tca[TCA_OPTIONS]);
1006 if (tca[TCA_STAB]) {
1007 stab = qdisc_get_stab(tca[TCA_STAB]);
1009 return PTR_ERR(stab);
1012 ostab = rtnl_dereference(sch->stab);
1013 rcu_assign_pointer(sch->stab, stab);
1014 qdisc_put_stab(ostab);
1016 if (tca[TCA_RATE]) {
1017 /* NB: ignores errors from replace_estimator
1018 because change can't be undone. */
1019 if (sch->flags & TCQ_F_MQROOT)
1021 gen_replace_estimator(&sch->bstats, &sch->rate_est,
1022 qdisc_root_sleeping_lock(sch),
1029 struct check_loop_arg {
1030 struct qdisc_walker w;
1035 static int check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w);
1037 static int check_loop(struct Qdisc *q, struct Qdisc *p, int depth)
1039 struct check_loop_arg arg;
1041 if (q->ops->cl_ops == NULL)
1044 arg.w.stop = arg.w.skip = arg.w.count = 0;
1045 arg.w.fn = check_loop_fn;
1048 q->ops->cl_ops->walk(q, &arg.w);
1049 return arg.w.stop ? -ELOOP : 0;
1053 check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w)
1056 const struct Qdisc_class_ops *cops = q->ops->cl_ops;
1057 struct check_loop_arg *arg = (struct check_loop_arg *)w;
1059 leaf = cops->leaf(q, cl);
1061 if (leaf == arg->p || arg->depth > 7)
1063 return check_loop(leaf, arg->p, arg->depth + 1);
1072 static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n)
1074 struct net *net = sock_net(skb->sk);
1075 struct tcmsg *tcm = nlmsg_data(n);
1076 struct nlattr *tca[TCA_MAX + 1];
1077 struct net_device *dev;
1079 struct Qdisc *q = NULL;
1080 struct Qdisc *p = NULL;
1083 if ((n->nlmsg_type != RTM_GETQDISC) && !capable(CAP_NET_ADMIN))
1086 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL);
1090 dev = __dev_get_by_index(net, tcm->tcm_ifindex);
1094 clid = tcm->tcm_parent;
1096 if (clid != TC_H_ROOT) {
1097 if (TC_H_MAJ(clid) != TC_H_MAJ(TC_H_INGRESS)) {
1098 p = qdisc_lookup(dev, TC_H_MAJ(clid));
1101 q = qdisc_leaf(p, clid);
1102 } else if (dev_ingress_queue(dev)) {
1103 q = dev_ingress_queue(dev)->qdisc_sleeping;
1111 if (tcm->tcm_handle && q->handle != tcm->tcm_handle)
1114 q = qdisc_lookup(dev, tcm->tcm_handle);
1119 if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], q->ops->id))
1122 if (n->nlmsg_type == RTM_DELQDISC) {
1127 err = qdisc_graft(dev, p, skb, n, clid, NULL, q);
1131 qdisc_notify(net, skb, n, clid, NULL, q);
1137 * Create/change qdisc.
1140 static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n)
1142 struct net *net = sock_net(skb->sk);
1144 struct nlattr *tca[TCA_MAX + 1];
1145 struct net_device *dev;
1147 struct Qdisc *q, *p;
1150 if (!capable(CAP_NET_ADMIN))
1154 /* Reinit, just in case something touches this. */
1155 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL);
1159 tcm = nlmsg_data(n);
1160 clid = tcm->tcm_parent;
1163 dev = __dev_get_by_index(net, tcm->tcm_ifindex);
1169 if (clid != TC_H_ROOT) {
1170 if (clid != TC_H_INGRESS) {
1171 p = qdisc_lookup(dev, TC_H_MAJ(clid));
1174 q = qdisc_leaf(p, clid);
1175 } else if (dev_ingress_queue_create(dev)) {
1176 q = dev_ingress_queue(dev)->qdisc_sleeping;
1182 /* It may be default qdisc, ignore it */
1183 if (q && q->handle == 0)
1186 if (!q || !tcm->tcm_handle || q->handle != tcm->tcm_handle) {
1187 if (tcm->tcm_handle) {
1188 if (q && !(n->nlmsg_flags & NLM_F_REPLACE))
1190 if (TC_H_MIN(tcm->tcm_handle))
1192 q = qdisc_lookup(dev, tcm->tcm_handle);
1194 goto create_n_graft;
1195 if (n->nlmsg_flags & NLM_F_EXCL)
1197 if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], q->ops->id))
1200 (p && check_loop(q, p, 0)))
1202 atomic_inc(&q->refcnt);
1206 goto create_n_graft;
1208 /* This magic test requires explanation.
1210 * We know, that some child q is already
1211 * attached to this parent and have choice:
1212 * either to change it or to create/graft new one.
1214 * 1. We are allowed to create/graft only
1215 * if CREATE and REPLACE flags are set.
1217 * 2. If EXCL is set, requestor wanted to say,
1218 * that qdisc tcm_handle is not expected
1219 * to exist, so that we choose create/graft too.
1221 * 3. The last case is when no flags are set.
1222 * Alas, it is sort of hole in API, we
1223 * cannot decide what to do unambiguously.
1224 * For now we select create/graft, if
1225 * user gave KIND, which does not match existing.
1227 if ((n->nlmsg_flags & NLM_F_CREATE) &&
1228 (n->nlmsg_flags & NLM_F_REPLACE) &&
1229 ((n->nlmsg_flags & NLM_F_EXCL) ||
1231 nla_strcmp(tca[TCA_KIND], q->ops->id))))
1232 goto create_n_graft;
1236 if (!tcm->tcm_handle)
1238 q = qdisc_lookup(dev, tcm->tcm_handle);
1241 /* Change qdisc parameters */
1244 if (n->nlmsg_flags & NLM_F_EXCL)
1246 if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], q->ops->id))
1248 err = qdisc_change(q, tca);
1250 qdisc_notify(net, skb, n, clid, NULL, q);
1254 if (!(n->nlmsg_flags & NLM_F_CREATE))
1256 if (clid == TC_H_INGRESS) {
1257 if (dev_ingress_queue(dev))
1258 q = qdisc_create(dev, dev_ingress_queue(dev), p,
1259 tcm->tcm_parent, tcm->tcm_parent,
1264 struct netdev_queue *dev_queue;
1266 if (p && p->ops->cl_ops && p->ops->cl_ops->select_queue)
1267 dev_queue = p->ops->cl_ops->select_queue(p, tcm);
1269 dev_queue = p->dev_queue;
1271 dev_queue = netdev_get_tx_queue(dev, 0);
1273 q = qdisc_create(dev, dev_queue, p,
1274 tcm->tcm_parent, tcm->tcm_handle,
1284 err = qdisc_graft(dev, p, skb, n, clid, q, NULL);
1294 static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
1295 u32 portid, u32 seq, u16 flags, int event)
1298 struct nlmsghdr *nlh;
1299 unsigned char *b = skb_tail_pointer(skb);
1301 struct qdisc_size_table *stab;
1303 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
1305 goto out_nlmsg_trim;
1306 tcm = nlmsg_data(nlh);
1307 tcm->tcm_family = AF_UNSPEC;
1310 tcm->tcm_ifindex = qdisc_dev(q)->ifindex;
1311 tcm->tcm_parent = clid;
1312 tcm->tcm_handle = q->handle;
1313 tcm->tcm_info = atomic_read(&q->refcnt);
1314 if (nla_put_string(skb, TCA_KIND, q->ops->id))
1315 goto nla_put_failure;
1316 if (q->ops->dump && q->ops->dump(q, skb) < 0)
1317 goto nla_put_failure;
1318 q->qstats.qlen = q->q.qlen;
1320 stab = rtnl_dereference(q->stab);
1321 if (stab && qdisc_dump_stab(skb, stab) < 0)
1322 goto nla_put_failure;
1324 if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS,
1325 qdisc_root_sleeping_lock(q), &d) < 0)
1326 goto nla_put_failure;
1328 if (q->ops->dump_stats && q->ops->dump_stats(q, &d) < 0)
1329 goto nla_put_failure;
1331 if (gnet_stats_copy_basic(&d, &q->bstats) < 0 ||
1332 gnet_stats_copy_rate_est(&d, &q->bstats, &q->rate_est) < 0 ||
1333 gnet_stats_copy_queue(&d, &q->qstats) < 0)
1334 goto nla_put_failure;
1336 if (gnet_stats_finish_copy(&d) < 0)
1337 goto nla_put_failure;
1339 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1348 static bool tc_qdisc_dump_ignore(struct Qdisc *q)
1350 return (q->flags & TCQ_F_BUILTIN) ? true : false;
1353 static int qdisc_notify(struct net *net, struct sk_buff *oskb,
1354 struct nlmsghdr *n, u32 clid,
1355 struct Qdisc *old, struct Qdisc *new)
1357 struct sk_buff *skb;
1358 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1360 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1364 if (old && !tc_qdisc_dump_ignore(old)) {
1365 if (tc_fill_qdisc(skb, old, clid, portid, n->nlmsg_seq,
1366 0, RTM_DELQDISC) < 0)
1369 if (new && !tc_qdisc_dump_ignore(new)) {
1370 if (tc_fill_qdisc(skb, new, clid, portid, n->nlmsg_seq,
1371 old ? NLM_F_REPLACE : 0, RTM_NEWQDISC) < 0)
1376 return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1377 n->nlmsg_flags & NLM_F_ECHO);
1384 static int tc_dump_qdisc_root(struct Qdisc *root, struct sk_buff *skb,
1385 struct netlink_callback *cb,
1386 int *q_idx_p, int s_q_idx)
1388 int ret = 0, q_idx = *q_idx_p;
1395 if (q_idx < s_q_idx) {
1398 if (!tc_qdisc_dump_ignore(q) &&
1399 tc_fill_qdisc(skb, q, q->parent, NETLINK_CB(cb->skb).portid,
1400 cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWQDISC) <= 0)
1404 list_for_each_entry(q, &root->list, list) {
1405 if (q_idx < s_q_idx) {
1409 if (!tc_qdisc_dump_ignore(q) &&
1410 tc_fill_qdisc(skb, q, q->parent, NETLINK_CB(cb->skb).portid,
1411 cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWQDISC) <= 0)
1424 static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
1426 struct net *net = sock_net(skb->sk);
1429 struct net_device *dev;
1431 s_idx = cb->args[0];
1432 s_q_idx = q_idx = cb->args[1];
1436 for_each_netdev_rcu(net, dev) {
1437 struct netdev_queue *dev_queue;
1445 if (tc_dump_qdisc_root(dev->qdisc, skb, cb, &q_idx, s_q_idx) < 0)
1448 dev_queue = dev_ingress_queue(dev);
1450 tc_dump_qdisc_root(dev_queue->qdisc_sleeping, skb, cb,
1451 &q_idx, s_q_idx) < 0)
1462 cb->args[1] = q_idx;
1469 /************************************************
1470 * Traffic classes manipulation. *
1471 ************************************************/
1475 static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n)
1477 struct net *net = sock_net(skb->sk);
1478 struct tcmsg *tcm = nlmsg_data(n);
1479 struct nlattr *tca[TCA_MAX + 1];
1480 struct net_device *dev;
1481 struct Qdisc *q = NULL;
1482 const struct Qdisc_class_ops *cops;
1483 unsigned long cl = 0;
1484 unsigned long new_cl;
1490 if ((n->nlmsg_type != RTM_GETTCLASS) && !capable(CAP_NET_ADMIN))
1493 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL);
1497 dev = __dev_get_by_index(net, tcm->tcm_ifindex);
1502 parent == TC_H_UNSPEC - unspecified parent.
1503 parent == TC_H_ROOT - class is root, which has no parent.
1504 parent == X:0 - parent is root class.
1505 parent == X:Y - parent is a node in hierarchy.
1506 parent == 0:Y - parent is X:Y, where X:0 is qdisc.
1508 handle == 0:0 - generate handle from kernel pool.
1509 handle == 0:Y - class is X:Y, where X:0 is qdisc.
1510 handle == X:Y - clear.
1511 handle == X:0 - root class.
1514 /* Step 1. Determine qdisc handle X:0 */
1516 portid = tcm->tcm_parent;
1517 clid = tcm->tcm_handle;
1518 qid = TC_H_MAJ(clid);
1520 if (portid != TC_H_ROOT) {
1521 u32 qid1 = TC_H_MAJ(portid);
1524 /* If both majors are known, they must be identical. */
1529 } else if (qid == 0)
1530 qid = dev->qdisc->handle;
1532 /* Now qid is genuine qdisc handle consistent
1533 * both with parent and child.
1535 * TC_H_MAJ(portid) still may be unspecified, complete it now.
1538 portid = TC_H_MAKE(qid, portid);
1541 qid = dev->qdisc->handle;
1544 /* OK. Locate qdisc */
1545 q = qdisc_lookup(dev, qid);
1549 /* An check that it supports classes */
1550 cops = q->ops->cl_ops;
1554 /* Now try to get class */
1556 if (portid == TC_H_ROOT)
1559 clid = TC_H_MAKE(qid, clid);
1562 cl = cops->get(q, clid);
1566 if (n->nlmsg_type != RTM_NEWTCLASS ||
1567 !(n->nlmsg_flags & NLM_F_CREATE))
1570 switch (n->nlmsg_type) {
1573 if (n->nlmsg_flags & NLM_F_EXCL)
1579 err = cops->delete(q, cl);
1581 tclass_notify(net, skb, n, q, cl, RTM_DELTCLASS);
1584 err = tclass_notify(net, skb, n, q, cl, RTM_NEWTCLASS);
1595 err = cops->change(q, clid, portid, tca, &new_cl);
1597 tclass_notify(net, skb, n, q, new_cl, RTM_NEWTCLASS);
1607 static int tc_fill_tclass(struct sk_buff *skb, struct Qdisc *q,
1609 u32 portid, u32 seq, u16 flags, int event)
1612 struct nlmsghdr *nlh;
1613 unsigned char *b = skb_tail_pointer(skb);
1615 const struct Qdisc_class_ops *cl_ops = q->ops->cl_ops;
1617 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
1619 goto out_nlmsg_trim;
1620 tcm = nlmsg_data(nlh);
1621 tcm->tcm_family = AF_UNSPEC;
1624 tcm->tcm_ifindex = qdisc_dev(q)->ifindex;
1625 tcm->tcm_parent = q->handle;
1626 tcm->tcm_handle = q->handle;
1628 if (nla_put_string(skb, TCA_KIND, q->ops->id))
1629 goto nla_put_failure;
1630 if (cl_ops->dump && cl_ops->dump(q, cl, skb, tcm) < 0)
1631 goto nla_put_failure;
1633 if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS,
1634 qdisc_root_sleeping_lock(q), &d) < 0)
1635 goto nla_put_failure;
1637 if (cl_ops->dump_stats && cl_ops->dump_stats(q, cl, &d) < 0)
1638 goto nla_put_failure;
1640 if (gnet_stats_finish_copy(&d) < 0)
1641 goto nla_put_failure;
1643 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1652 static int tclass_notify(struct net *net, struct sk_buff *oskb,
1653 struct nlmsghdr *n, struct Qdisc *q,
1654 unsigned long cl, int event)
1656 struct sk_buff *skb;
1657 u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1659 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1663 if (tc_fill_tclass(skb, q, cl, portid, n->nlmsg_seq, 0, event) < 0) {
1668 return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1669 n->nlmsg_flags & NLM_F_ECHO);
1672 struct qdisc_dump_args {
1673 struct qdisc_walker w;
1674 struct sk_buff *skb;
1675 struct netlink_callback *cb;
1678 static int qdisc_class_dump(struct Qdisc *q, unsigned long cl, struct qdisc_walker *arg)
1680 struct qdisc_dump_args *a = (struct qdisc_dump_args *)arg;
1682 return tc_fill_tclass(a->skb, q, cl, NETLINK_CB(a->cb->skb).portid,
1683 a->cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWTCLASS);
1686 static int tc_dump_tclass_qdisc(struct Qdisc *q, struct sk_buff *skb,
1687 struct tcmsg *tcm, struct netlink_callback *cb,
1690 struct qdisc_dump_args arg;
1692 if (tc_qdisc_dump_ignore(q) ||
1693 *t_p < s_t || !q->ops->cl_ops ||
1695 TC_H_MAJ(tcm->tcm_parent) != q->handle)) {
1700 memset(&cb->args[1], 0, sizeof(cb->args)-sizeof(cb->args[0]));
1701 arg.w.fn = qdisc_class_dump;
1705 arg.w.skip = cb->args[1];
1707 q->ops->cl_ops->walk(q, &arg.w);
1708 cb->args[1] = arg.w.count;
1715 static int tc_dump_tclass_root(struct Qdisc *root, struct sk_buff *skb,
1716 struct tcmsg *tcm, struct netlink_callback *cb,
1724 if (tc_dump_tclass_qdisc(root, skb, tcm, cb, t_p, s_t) < 0)
1727 list_for_each_entry(q, &root->list, list) {
1728 if (tc_dump_tclass_qdisc(q, skb, tcm, cb, t_p, s_t) < 0)
1735 static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb)
1737 struct tcmsg *tcm = nlmsg_data(cb->nlh);
1738 struct net *net = sock_net(skb->sk);
1739 struct netdev_queue *dev_queue;
1740 struct net_device *dev;
1743 if (nlmsg_len(cb->nlh) < sizeof(*tcm))
1745 dev = dev_get_by_index(net, tcm->tcm_ifindex);
1752 if (tc_dump_tclass_root(dev->qdisc, skb, tcm, cb, &t, s_t) < 0)
1755 dev_queue = dev_ingress_queue(dev);
1757 tc_dump_tclass_root(dev_queue->qdisc_sleeping, skb, tcm, cb,
1768 /* Main classifier routine: scans classifier chain attached
1769 * to this qdisc, (optionally) tests for protocol and asks
1770 * specific classifiers.
1772 int tc_classify_compat(struct sk_buff *skb, const struct tcf_proto *tp,
1773 struct tcf_result *res)
1775 __be16 protocol = skb->protocol;
1778 for (; tp; tp = tp->next) {
1779 if (tp->protocol != protocol &&
1780 tp->protocol != htons(ETH_P_ALL))
1782 err = tp->classify(skb, tp, res);
1785 #ifdef CONFIG_NET_CLS_ACT
1786 if (err != TC_ACT_RECLASSIFY && skb->tc_verd)
1787 skb->tc_verd = SET_TC_VERD(skb->tc_verd, 0);
1794 EXPORT_SYMBOL(tc_classify_compat);
1796 int tc_classify(struct sk_buff *skb, const struct tcf_proto *tp,
1797 struct tcf_result *res)
1800 #ifdef CONFIG_NET_CLS_ACT
1801 const struct tcf_proto *otp = tp;
1805 err = tc_classify_compat(skb, tp, res);
1806 #ifdef CONFIG_NET_CLS_ACT
1807 if (err == TC_ACT_RECLASSIFY) {
1808 u32 verd = G_TC_VERD(skb->tc_verd);
1811 if (verd++ >= MAX_REC_LOOP) {
1812 net_notice_ratelimited("%s: packet reclassify loop rule prio %u protocol %02x\n",
1815 ntohs(tp->protocol));
1818 skb->tc_verd = SET_TC_VERD(skb->tc_verd, verd);
1824 EXPORT_SYMBOL(tc_classify);
1826 void tcf_destroy(struct tcf_proto *tp)
1828 tp->ops->destroy(tp);
1829 module_put(tp->ops->owner);
1833 void tcf_destroy_chain(struct tcf_proto **fl)
1835 struct tcf_proto *tp;
1837 while ((tp = *fl) != NULL) {
1842 EXPORT_SYMBOL(tcf_destroy_chain);
1844 #ifdef CONFIG_PROC_FS
1845 static int psched_show(struct seq_file *seq, void *v)
1849 hrtimer_get_res(CLOCK_MONOTONIC, &ts);
1850 seq_printf(seq, "%08x %08x %08x %08x\n",
1851 (u32)NSEC_PER_USEC, (u32)PSCHED_TICKS2NS(1),
1853 (u32)NSEC_PER_SEC/(u32)ktime_to_ns(timespec_to_ktime(ts)));
1858 static int psched_open(struct inode *inode, struct file *file)
1860 return single_open(file, psched_show, NULL);
1863 static const struct file_operations psched_fops = {
1864 .owner = THIS_MODULE,
1865 .open = psched_open,
1867 .llseek = seq_lseek,
1868 .release = single_release,
1871 static int __net_init psched_net_init(struct net *net)
1873 struct proc_dir_entry *e;
1875 e = proc_create("psched", 0, net->proc_net, &psched_fops);
1882 static void __net_exit psched_net_exit(struct net *net)
1884 remove_proc_entry("psched", net->proc_net);
1887 static int __net_init psched_net_init(struct net *net)
1892 static void __net_exit psched_net_exit(struct net *net)
1897 static struct pernet_operations psched_net_ops = {
1898 .init = psched_net_init,
1899 .exit = psched_net_exit,
1902 static int __init pktsched_init(void)
1906 err = register_pernet_subsys(&psched_net_ops);
1908 pr_err("pktsched_init: "
1909 "cannot initialize per netns operations\n");
1913 register_qdisc(&pfifo_fast_ops);
1914 register_qdisc(&pfifo_qdisc_ops);
1915 register_qdisc(&bfifo_qdisc_ops);
1916 register_qdisc(&pfifo_head_drop_qdisc_ops);
1917 register_qdisc(&mq_qdisc_ops);
1919 rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, NULL);
1920 rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, NULL);
1921 rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc, NULL);
1922 rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, NULL);
1923 rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, NULL);
1924 rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass, NULL);
1929 subsys_initcall(pktsched_init);