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 /* We know handle. Find qdisc among all qdisc's attached to device
204 (root qdisc, all its children, children of children etc.)
207 static struct Qdisc
*qdisc_match_from_root(struct Qdisc
*root
, u32 handle
)
211 if (!(root
->flags
& TCQ_F_BUILTIN
) &&
212 root
->handle
== handle
)
215 list_for_each_entry(q
, &root
->list
, list
) {
216 if (q
->handle
== handle
)
222 static void qdisc_list_add(struct Qdisc
*q
)
224 if ((q
->parent
!= TC_H_ROOT
) && !(q
->flags
& TCQ_F_INGRESS
))
225 list_add_tail(&q
->list
, &qdisc_dev(q
)->qdisc
->list
);
228 void qdisc_list_del(struct Qdisc
*q
)
230 if ((q
->parent
!= TC_H_ROOT
) && !(q
->flags
& TCQ_F_INGRESS
))
233 EXPORT_SYMBOL(qdisc_list_del
);
235 struct Qdisc
*qdisc_lookup(struct net_device
*dev
, u32 handle
)
239 q
= qdisc_match_from_root(dev
->qdisc
, handle
);
243 q
= qdisc_match_from_root(dev
->rx_queue
.qdisc_sleeping
, handle
);
248 static struct Qdisc
*qdisc_leaf(struct Qdisc
*p
, u32 classid
)
252 const struct Qdisc_class_ops
*cops
= p
->ops
->cl_ops
;
256 cl
= cops
->get(p
, classid
);
260 leaf
= cops
->leaf(p
, cl
);
265 /* Find queueing discipline by name */
267 static struct Qdisc_ops
*qdisc_lookup_ops(struct nlattr
*kind
)
269 struct Qdisc_ops
*q
= NULL
;
272 read_lock(&qdisc_mod_lock
);
273 for (q
= qdisc_base
; q
; q
= q
->next
) {
274 if (nla_strcmp(kind
, q
->id
) == 0) {
275 if (!try_module_get(q
->owner
))
280 read_unlock(&qdisc_mod_lock
);
285 static struct qdisc_rate_table
*qdisc_rtab_list
;
287 struct qdisc_rate_table
*qdisc_get_rtab(struct tc_ratespec
*r
, struct nlattr
*tab
)
289 struct qdisc_rate_table
*rtab
;
291 for (rtab
= qdisc_rtab_list
; rtab
; rtab
= rtab
->next
) {
292 if (memcmp(&rtab
->rate
, r
, sizeof(struct tc_ratespec
)) == 0) {
298 if (tab
== NULL
|| r
->rate
== 0 || r
->cell_log
== 0 ||
299 nla_len(tab
) != TC_RTAB_SIZE
)
302 rtab
= kmalloc(sizeof(*rtab
), GFP_KERNEL
);
306 memcpy(rtab
->data
, nla_data(tab
), 1024);
307 rtab
->next
= qdisc_rtab_list
;
308 qdisc_rtab_list
= rtab
;
312 EXPORT_SYMBOL(qdisc_get_rtab
);
314 void qdisc_put_rtab(struct qdisc_rate_table
*tab
)
316 struct qdisc_rate_table
*rtab
, **rtabp
;
318 if (!tab
|| --tab
->refcnt
)
321 for (rtabp
= &qdisc_rtab_list
; (rtab
=*rtabp
) != NULL
; rtabp
= &rtab
->next
) {
329 EXPORT_SYMBOL(qdisc_put_rtab
);
331 static LIST_HEAD(qdisc_stab_list
);
332 static DEFINE_SPINLOCK(qdisc_stab_lock
);
334 static const struct nla_policy stab_policy
[TCA_STAB_MAX
+ 1] = {
335 [TCA_STAB_BASE
] = { .len
= sizeof(struct tc_sizespec
) },
336 [TCA_STAB_DATA
] = { .type
= NLA_BINARY
},
339 static struct qdisc_size_table
*qdisc_get_stab(struct nlattr
*opt
)
341 struct nlattr
*tb
[TCA_STAB_MAX
+ 1];
342 struct qdisc_size_table
*stab
;
343 struct tc_sizespec
*s
;
344 unsigned int tsize
= 0;
348 err
= nla_parse_nested(tb
, TCA_STAB_MAX
, opt
, stab_policy
);
351 if (!tb
[TCA_STAB_BASE
])
352 return ERR_PTR(-EINVAL
);
354 s
= nla_data(tb
[TCA_STAB_BASE
]);
357 if (!tb
[TCA_STAB_DATA
])
358 return ERR_PTR(-EINVAL
);
359 tab
= nla_data(tb
[TCA_STAB_DATA
]);
360 tsize
= nla_len(tb
[TCA_STAB_DATA
]) / sizeof(u16
);
363 if (!s
|| tsize
!= s
->tsize
|| (!tab
&& tsize
> 0))
364 return ERR_PTR(-EINVAL
);
366 spin_lock(&qdisc_stab_lock
);
368 list_for_each_entry(stab
, &qdisc_stab_list
, list
) {
369 if (memcmp(&stab
->szopts
, s
, sizeof(*s
)))
371 if (tsize
> 0 && memcmp(stab
->data
, tab
, tsize
* sizeof(u16
)))
374 spin_unlock(&qdisc_stab_lock
);
378 spin_unlock(&qdisc_stab_lock
);
380 stab
= kmalloc(sizeof(*stab
) + tsize
* sizeof(u16
), GFP_KERNEL
);
382 return ERR_PTR(-ENOMEM
);
387 memcpy(stab
->data
, tab
, tsize
* sizeof(u16
));
389 spin_lock(&qdisc_stab_lock
);
390 list_add_tail(&stab
->list
, &qdisc_stab_list
);
391 spin_unlock(&qdisc_stab_lock
);
396 void qdisc_put_stab(struct qdisc_size_table
*tab
)
401 spin_lock(&qdisc_stab_lock
);
403 if (--tab
->refcnt
== 0) {
404 list_del(&tab
->list
);
408 spin_unlock(&qdisc_stab_lock
);
410 EXPORT_SYMBOL(qdisc_put_stab
);
412 static int qdisc_dump_stab(struct sk_buff
*skb
, struct qdisc_size_table
*stab
)
416 nest
= nla_nest_start(skb
, TCA_STAB
);
418 goto nla_put_failure
;
419 NLA_PUT(skb
, TCA_STAB_BASE
, sizeof(stab
->szopts
), &stab
->szopts
);
420 nla_nest_end(skb
, nest
);
428 void qdisc_calculate_pkt_len(struct sk_buff
*skb
, struct qdisc_size_table
*stab
)
432 pkt_len
= skb
->len
+ stab
->szopts
.overhead
;
433 if (unlikely(!stab
->szopts
.tsize
))
436 slot
= pkt_len
+ stab
->szopts
.cell_align
;
437 if (unlikely(slot
< 0))
440 slot
>>= stab
->szopts
.cell_log
;
441 if (likely(slot
< stab
->szopts
.tsize
))
442 pkt_len
= stab
->data
[slot
];
444 pkt_len
= stab
->data
[stab
->szopts
.tsize
- 1] *
445 (slot
/ stab
->szopts
.tsize
) +
446 stab
->data
[slot
% stab
->szopts
.tsize
];
448 pkt_len
<<= stab
->szopts
.size_log
;
450 if (unlikely(pkt_len
< 1))
452 qdisc_skb_cb(skb
)->pkt_len
= pkt_len
;
454 EXPORT_SYMBOL(qdisc_calculate_pkt_len
);
456 void qdisc_warn_nonwc(char *txt
, struct Qdisc
*qdisc
)
458 if (!(qdisc
->flags
& TCQ_F_WARN_NONWC
)) {
460 "%s: %s qdisc %X: is non-work-conserving?\n",
461 txt
, qdisc
->ops
->id
, qdisc
->handle
>> 16);
462 qdisc
->flags
|= TCQ_F_WARN_NONWC
;
465 EXPORT_SYMBOL(qdisc_warn_nonwc
);
467 static enum hrtimer_restart
qdisc_watchdog(struct hrtimer
*timer
)
469 struct qdisc_watchdog
*wd
= container_of(timer
, struct qdisc_watchdog
,
472 wd
->qdisc
->flags
&= ~TCQ_F_THROTTLED
;
473 __netif_schedule(qdisc_root(wd
->qdisc
));
475 return HRTIMER_NORESTART
;
478 void qdisc_watchdog_init(struct qdisc_watchdog
*wd
, struct Qdisc
*qdisc
)
480 hrtimer_init(&wd
->timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_ABS
);
481 wd
->timer
.function
= qdisc_watchdog
;
484 EXPORT_SYMBOL(qdisc_watchdog_init
);
486 void qdisc_watchdog_schedule(struct qdisc_watchdog
*wd
, psched_time_t expires
)
490 if (test_bit(__QDISC_STATE_DEACTIVATED
,
491 &qdisc_root_sleeping(wd
->qdisc
)->state
))
494 wd
->qdisc
->flags
|= TCQ_F_THROTTLED
;
495 time
= ktime_set(0, 0);
496 time
= ktime_add_ns(time
, PSCHED_TICKS2NS(expires
));
497 hrtimer_start(&wd
->timer
, time
, HRTIMER_MODE_ABS
);
499 EXPORT_SYMBOL(qdisc_watchdog_schedule
);
501 void qdisc_watchdog_cancel(struct qdisc_watchdog
*wd
)
503 hrtimer_cancel(&wd
->timer
);
504 wd
->qdisc
->flags
&= ~TCQ_F_THROTTLED
;
506 EXPORT_SYMBOL(qdisc_watchdog_cancel
);
508 static struct hlist_head
*qdisc_class_hash_alloc(unsigned int n
)
510 unsigned int size
= n
* sizeof(struct hlist_head
), i
;
511 struct hlist_head
*h
;
513 if (size
<= PAGE_SIZE
)
514 h
= kmalloc(size
, GFP_KERNEL
);
516 h
= (struct hlist_head
*)
517 __get_free_pages(GFP_KERNEL
, get_order(size
));
520 for (i
= 0; i
< n
; i
++)
521 INIT_HLIST_HEAD(&h
[i
]);
526 static void qdisc_class_hash_free(struct hlist_head
*h
, unsigned int n
)
528 unsigned int size
= n
* sizeof(struct hlist_head
);
530 if (size
<= PAGE_SIZE
)
533 free_pages((unsigned long)h
, get_order(size
));
536 void qdisc_class_hash_grow(struct Qdisc
*sch
, struct Qdisc_class_hash
*clhash
)
538 struct Qdisc_class_common
*cl
;
539 struct hlist_node
*n
, *next
;
540 struct hlist_head
*nhash
, *ohash
;
541 unsigned int nsize
, nmask
, osize
;
544 /* Rehash when load factor exceeds 0.75 */
545 if (clhash
->hashelems
* 4 <= clhash
->hashsize
* 3)
547 nsize
= clhash
->hashsize
* 2;
549 nhash
= qdisc_class_hash_alloc(nsize
);
553 ohash
= clhash
->hash
;
554 osize
= clhash
->hashsize
;
557 for (i
= 0; i
< osize
; i
++) {
558 hlist_for_each_entry_safe(cl
, n
, next
, &ohash
[i
], hnode
) {
559 h
= qdisc_class_hash(cl
->classid
, nmask
);
560 hlist_add_head(&cl
->hnode
, &nhash
[h
]);
563 clhash
->hash
= nhash
;
564 clhash
->hashsize
= nsize
;
565 clhash
->hashmask
= nmask
;
566 sch_tree_unlock(sch
);
568 qdisc_class_hash_free(ohash
, osize
);
570 EXPORT_SYMBOL(qdisc_class_hash_grow
);
572 int qdisc_class_hash_init(struct Qdisc_class_hash
*clhash
)
574 unsigned int size
= 4;
576 clhash
->hash
= qdisc_class_hash_alloc(size
);
577 if (clhash
->hash
== NULL
)
579 clhash
->hashsize
= size
;
580 clhash
->hashmask
= size
- 1;
581 clhash
->hashelems
= 0;
584 EXPORT_SYMBOL(qdisc_class_hash_init
);
586 void qdisc_class_hash_destroy(struct Qdisc_class_hash
*clhash
)
588 qdisc_class_hash_free(clhash
->hash
, clhash
->hashsize
);
590 EXPORT_SYMBOL(qdisc_class_hash_destroy
);
592 void qdisc_class_hash_insert(struct Qdisc_class_hash
*clhash
,
593 struct Qdisc_class_common
*cl
)
597 INIT_HLIST_NODE(&cl
->hnode
);
598 h
= qdisc_class_hash(cl
->classid
, clhash
->hashmask
);
599 hlist_add_head(&cl
->hnode
, &clhash
->hash
[h
]);
602 EXPORT_SYMBOL(qdisc_class_hash_insert
);
604 void qdisc_class_hash_remove(struct Qdisc_class_hash
*clhash
,
605 struct Qdisc_class_common
*cl
)
607 hlist_del(&cl
->hnode
);
610 EXPORT_SYMBOL(qdisc_class_hash_remove
);
612 /* Allocate an unique handle from space managed by kernel */
614 static u32
qdisc_alloc_handle(struct net_device
*dev
)
617 static u32 autohandle
= TC_H_MAKE(0x80000000U
, 0);
620 autohandle
+= TC_H_MAKE(0x10000U
, 0);
621 if (autohandle
== TC_H_MAKE(TC_H_ROOT
, 0))
622 autohandle
= TC_H_MAKE(0x80000000U
, 0);
623 } while (qdisc_lookup(dev
, autohandle
) && --i
> 0);
625 return i
>0 ? autohandle
: 0;
628 void qdisc_tree_decrease_qlen(struct Qdisc
*sch
, unsigned int n
)
630 const struct Qdisc_class_ops
*cops
;
636 while ((parentid
= sch
->parent
)) {
637 if (TC_H_MAJ(parentid
) == TC_H_MAJ(TC_H_INGRESS
))
640 sch
= qdisc_lookup(qdisc_dev(sch
), TC_H_MAJ(parentid
));
642 WARN_ON(parentid
!= TC_H_ROOT
);
645 cops
= sch
->ops
->cl_ops
;
646 if (cops
->qlen_notify
) {
647 cl
= cops
->get(sch
, parentid
);
648 cops
->qlen_notify(sch
, cl
);
654 EXPORT_SYMBOL(qdisc_tree_decrease_qlen
);
656 static void notify_and_destroy(struct net
*net
, struct sk_buff
*skb
,
657 struct nlmsghdr
*n
, u32 clid
,
658 struct Qdisc
*old
, struct Qdisc
*new)
661 qdisc_notify(net
, skb
, n
, clid
, old
, new);
667 /* Graft qdisc "new" to class "classid" of qdisc "parent" or
670 * When appropriate send a netlink notification using 'skb'
673 * On success, destroy old qdisc.
676 static int qdisc_graft(struct net_device
*dev
, struct Qdisc
*parent
,
677 struct sk_buff
*skb
, struct nlmsghdr
*n
, u32 classid
,
678 struct Qdisc
*new, struct Qdisc
*old
)
680 struct Qdisc
*q
= old
;
681 struct net
*net
= dev_net(dev
);
684 if (parent
== NULL
) {
685 unsigned int i
, num_q
, ingress
;
688 num_q
= dev
->num_tx_queues
;
689 if ((q
&& q
->flags
& TCQ_F_INGRESS
) ||
690 (new && new->flags
& TCQ_F_INGRESS
)) {
695 if (dev
->flags
& IFF_UP
)
698 if (new && new->ops
->attach
) {
699 new->ops
->attach(new);
703 for (i
= 0; i
< num_q
; i
++) {
704 struct netdev_queue
*dev_queue
= &dev
->rx_queue
;
707 dev_queue
= netdev_get_tx_queue(dev
, i
);
709 old
= dev_graft_qdisc(dev_queue
, new);
711 atomic_inc(&new->refcnt
);
718 notify_and_destroy(net
, skb
, n
, classid
,
720 if (new && !new->ops
->attach
)
721 atomic_inc(&new->refcnt
);
722 dev
->qdisc
= new ? : &noop_qdisc
;
724 notify_and_destroy(net
, skb
, n
, classid
, old
, new);
727 if (dev
->flags
& IFF_UP
)
730 const struct Qdisc_class_ops
*cops
= parent
->ops
->cl_ops
;
733 if (cops
&& cops
->graft
) {
734 unsigned long cl
= cops
->get(parent
, classid
);
736 err
= cops
->graft(parent
, cl
, new, &old
);
737 cops
->put(parent
, cl
);
742 notify_and_destroy(net
, skb
, n
, classid
, old
, new);
747 /* lockdep annotation is needed for ingress; egress gets it only for name */
748 static struct lock_class_key qdisc_tx_lock
;
749 static struct lock_class_key qdisc_rx_lock
;
752 Allocate and initialize new qdisc.
754 Parameters are passed via opt.
757 static struct Qdisc
*
758 qdisc_create(struct net_device
*dev
, struct netdev_queue
*dev_queue
,
759 struct Qdisc
*p
, u32 parent
, u32 handle
,
760 struct nlattr
**tca
, int *errp
)
763 struct nlattr
*kind
= tca
[TCA_KIND
];
765 struct Qdisc_ops
*ops
;
766 struct qdisc_size_table
*stab
;
768 ops
= qdisc_lookup_ops(kind
);
769 #ifdef CONFIG_MODULES
770 if (ops
== NULL
&& kind
!= NULL
) {
772 if (nla_strlcpy(name
, kind
, IFNAMSIZ
) < IFNAMSIZ
) {
773 /* We dropped the RTNL semaphore in order to
774 * perform the module load. So, even if we
775 * succeeded in loading the module we have to
776 * tell the caller to replay the request. We
777 * indicate this using -EAGAIN.
778 * We replay the request because the device may
779 * go away in the mean time.
782 request_module("sch_%s", name
);
784 ops
= qdisc_lookup_ops(kind
);
786 /* We will try again qdisc_lookup_ops,
787 * so don't keep a reference.
789 module_put(ops
->owner
);
801 sch
= qdisc_alloc(dev_queue
, ops
);
807 sch
->parent
= parent
;
809 if (handle
== TC_H_INGRESS
) {
810 sch
->flags
|= TCQ_F_INGRESS
;
811 handle
= TC_H_MAKE(TC_H_INGRESS
, 0);
812 lockdep_set_class(qdisc_lock(sch
), &qdisc_rx_lock
);
815 handle
= qdisc_alloc_handle(dev
);
820 lockdep_set_class(qdisc_lock(sch
), &qdisc_tx_lock
);
823 sch
->handle
= handle
;
825 if (!ops
->init
|| (err
= ops
->init(sch
, tca
[TCA_OPTIONS
])) == 0) {
827 stab
= qdisc_get_stab(tca
[TCA_STAB
]);
835 spinlock_t
*root_lock
;
838 if (sch
->flags
& TCQ_F_MQROOT
)
841 if ((sch
->parent
!= TC_H_ROOT
) &&
842 !(sch
->flags
& TCQ_F_INGRESS
) &&
843 (!p
|| !(p
->flags
& TCQ_F_MQROOT
)))
844 root_lock
= qdisc_root_sleeping_lock(sch
);
846 root_lock
= qdisc_lock(sch
);
848 err
= gen_new_estimator(&sch
->bstats
, &sch
->rate_est
,
849 root_lock
, tca
[TCA_RATE
]);
860 kfree((char *) sch
- sch
->padded
);
862 module_put(ops
->owner
);
869 * Any broken qdiscs that would require a ops->reset() here?
870 * The qdisc was never in action so it shouldn't be necessary.
872 qdisc_put_stab(sch
->stab
);
878 static int qdisc_change(struct Qdisc
*sch
, struct nlattr
**tca
)
880 struct qdisc_size_table
*stab
= NULL
;
883 if (tca
[TCA_OPTIONS
]) {
884 if (sch
->ops
->change
== NULL
)
886 err
= sch
->ops
->change(sch
, tca
[TCA_OPTIONS
]);
892 stab
= qdisc_get_stab(tca
[TCA_STAB
]);
894 return PTR_ERR(stab
);
897 qdisc_put_stab(sch
->stab
);
901 /* NB: ignores errors from replace_estimator
902 because change can't be undone. */
903 if (sch
->flags
& TCQ_F_MQROOT
)
905 gen_replace_estimator(&sch
->bstats
, &sch
->rate_est
,
906 qdisc_root_sleeping_lock(sch
),
913 struct check_loop_arg
915 struct qdisc_walker w
;
920 static int check_loop_fn(struct Qdisc
*q
, unsigned long cl
, struct qdisc_walker
*w
);
922 static int check_loop(struct Qdisc
*q
, struct Qdisc
*p
, int depth
)
924 struct check_loop_arg arg
;
926 if (q
->ops
->cl_ops
== NULL
)
929 arg
.w
.stop
= arg
.w
.skip
= arg
.w
.count
= 0;
930 arg
.w
.fn
= check_loop_fn
;
933 q
->ops
->cl_ops
->walk(q
, &arg
.w
);
934 return arg
.w
.stop
? -ELOOP
: 0;
938 check_loop_fn(struct Qdisc
*q
, unsigned long cl
, struct qdisc_walker
*w
)
941 const struct Qdisc_class_ops
*cops
= q
->ops
->cl_ops
;
942 struct check_loop_arg
*arg
= (struct check_loop_arg
*)w
;
944 leaf
= cops
->leaf(q
, cl
);
946 if (leaf
== arg
->p
|| arg
->depth
> 7)
948 return check_loop(leaf
, arg
->p
, arg
->depth
+ 1);
957 static int tc_get_qdisc(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
959 struct net
*net
= sock_net(skb
->sk
);
960 struct tcmsg
*tcm
= NLMSG_DATA(n
);
961 struct nlattr
*tca
[TCA_MAX
+ 1];
962 struct net_device
*dev
;
963 u32 clid
= tcm
->tcm_parent
;
964 struct Qdisc
*q
= NULL
;
965 struct Qdisc
*p
= NULL
;
968 if ((dev
= __dev_get_by_index(net
, tcm
->tcm_ifindex
)) == NULL
)
971 err
= nlmsg_parse(n
, sizeof(*tcm
), tca
, TCA_MAX
, NULL
);
976 if (clid
!= TC_H_ROOT
) {
977 if (TC_H_MAJ(clid
) != TC_H_MAJ(TC_H_INGRESS
)) {
978 if ((p
= qdisc_lookup(dev
, TC_H_MAJ(clid
))) == NULL
)
980 q
= qdisc_leaf(p
, clid
);
981 } else { /* ingress */
982 q
= dev
->rx_queue
.qdisc_sleeping
;
990 if (tcm
->tcm_handle
&& q
->handle
!= tcm
->tcm_handle
)
993 if ((q
= qdisc_lookup(dev
, tcm
->tcm_handle
)) == NULL
)
997 if (tca
[TCA_KIND
] && nla_strcmp(tca
[TCA_KIND
], q
->ops
->id
))
1000 if (n
->nlmsg_type
== RTM_DELQDISC
) {
1005 if ((err
= qdisc_graft(dev
, p
, skb
, n
, clid
, NULL
, q
)) != 0)
1008 qdisc_notify(net
, skb
, n
, clid
, NULL
, q
);
1014 Create/change qdisc.
1017 static int tc_modify_qdisc(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
1019 struct net
*net
= sock_net(skb
->sk
);
1021 struct nlattr
*tca
[TCA_MAX
+ 1];
1022 struct net_device
*dev
;
1024 struct Qdisc
*q
, *p
;
1028 /* Reinit, just in case something touches this. */
1029 tcm
= NLMSG_DATA(n
);
1030 clid
= tcm
->tcm_parent
;
1033 if ((dev
= __dev_get_by_index(net
, tcm
->tcm_ifindex
)) == NULL
)
1036 err
= nlmsg_parse(n
, sizeof(*tcm
), tca
, TCA_MAX
, NULL
);
1041 if (clid
!= TC_H_ROOT
) {
1042 if (clid
!= TC_H_INGRESS
) {
1043 if ((p
= qdisc_lookup(dev
, TC_H_MAJ(clid
))) == NULL
)
1045 q
= qdisc_leaf(p
, clid
);
1046 } else { /*ingress */
1047 q
= dev
->rx_queue
.qdisc_sleeping
;
1053 /* It may be default qdisc, ignore it */
1054 if (q
&& q
->handle
== 0)
1057 if (!q
|| !tcm
->tcm_handle
|| q
->handle
!= tcm
->tcm_handle
) {
1058 if (tcm
->tcm_handle
) {
1059 if (q
&& !(n
->nlmsg_flags
&NLM_F_REPLACE
))
1061 if (TC_H_MIN(tcm
->tcm_handle
))
1063 if ((q
= qdisc_lookup(dev
, tcm
->tcm_handle
)) == NULL
)
1064 goto create_n_graft
;
1065 if (n
->nlmsg_flags
&NLM_F_EXCL
)
1067 if (tca
[TCA_KIND
] && nla_strcmp(tca
[TCA_KIND
], q
->ops
->id
))
1070 (p
&& check_loop(q
, p
, 0)))
1072 atomic_inc(&q
->refcnt
);
1076 goto create_n_graft
;
1078 /* This magic test requires explanation.
1080 * We know, that some child q is already
1081 * attached to this parent and have choice:
1082 * either to change it or to create/graft new one.
1084 * 1. We are allowed to create/graft only
1085 * if CREATE and REPLACE flags are set.
1087 * 2. If EXCL is set, requestor wanted to say,
1088 * that qdisc tcm_handle is not expected
1089 * to exist, so that we choose create/graft too.
1091 * 3. The last case is when no flags are set.
1092 * Alas, it is sort of hole in API, we
1093 * cannot decide what to do unambiguously.
1094 * For now we select create/graft, if
1095 * user gave KIND, which does not match existing.
1097 if ((n
->nlmsg_flags
&NLM_F_CREATE
) &&
1098 (n
->nlmsg_flags
&NLM_F_REPLACE
) &&
1099 ((n
->nlmsg_flags
&NLM_F_EXCL
) ||
1101 nla_strcmp(tca
[TCA_KIND
], q
->ops
->id
))))
1102 goto create_n_graft
;
1106 if (!tcm
->tcm_handle
)
1108 q
= qdisc_lookup(dev
, tcm
->tcm_handle
);
1111 /* Change qdisc parameters */
1114 if (n
->nlmsg_flags
&NLM_F_EXCL
)
1116 if (tca
[TCA_KIND
] && nla_strcmp(tca
[TCA_KIND
], q
->ops
->id
))
1118 err
= qdisc_change(q
, tca
);
1120 qdisc_notify(net
, skb
, n
, clid
, NULL
, q
);
1124 if (!(n
->nlmsg_flags
&NLM_F_CREATE
))
1126 if (clid
== TC_H_INGRESS
)
1127 q
= qdisc_create(dev
, &dev
->rx_queue
, p
,
1128 tcm
->tcm_parent
, tcm
->tcm_parent
,
1131 struct netdev_queue
*dev_queue
;
1133 if (p
&& p
->ops
->cl_ops
&& p
->ops
->cl_ops
->select_queue
)
1134 dev_queue
= p
->ops
->cl_ops
->select_queue(p
, tcm
);
1136 dev_queue
= p
->dev_queue
;
1138 dev_queue
= netdev_get_tx_queue(dev
, 0);
1140 q
= qdisc_create(dev
, dev_queue
, p
,
1141 tcm
->tcm_parent
, tcm
->tcm_handle
,
1151 err
= qdisc_graft(dev
, p
, skb
, n
, clid
, q
, NULL
);
1161 static int tc_fill_qdisc(struct sk_buff
*skb
, struct Qdisc
*q
, u32 clid
,
1162 u32 pid
, u32 seq
, u16 flags
, int event
)
1165 struct nlmsghdr
*nlh
;
1166 unsigned char *b
= skb_tail_pointer(skb
);
1169 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*tcm
), flags
);
1170 tcm
= NLMSG_DATA(nlh
);
1171 tcm
->tcm_family
= AF_UNSPEC
;
1174 tcm
->tcm_ifindex
= qdisc_dev(q
)->ifindex
;
1175 tcm
->tcm_parent
= clid
;
1176 tcm
->tcm_handle
= q
->handle
;
1177 tcm
->tcm_info
= atomic_read(&q
->refcnt
);
1178 NLA_PUT_STRING(skb
, TCA_KIND
, q
->ops
->id
);
1179 if (q
->ops
->dump
&& q
->ops
->dump(q
, skb
) < 0)
1180 goto nla_put_failure
;
1181 q
->qstats
.qlen
= q
->q
.qlen
;
1183 if (q
->stab
&& qdisc_dump_stab(skb
, q
->stab
) < 0)
1184 goto nla_put_failure
;
1186 if (gnet_stats_start_copy_compat(skb
, TCA_STATS2
, TCA_STATS
, TCA_XSTATS
,
1187 qdisc_root_sleeping_lock(q
), &d
) < 0)
1188 goto nla_put_failure
;
1190 if (q
->ops
->dump_stats
&& q
->ops
->dump_stats(q
, &d
) < 0)
1191 goto nla_put_failure
;
1193 if (gnet_stats_copy_basic(&d
, &q
->bstats
) < 0 ||
1194 gnet_stats_copy_rate_est(&d
, &q
->bstats
, &q
->rate_est
) < 0 ||
1195 gnet_stats_copy_queue(&d
, &q
->qstats
) < 0)
1196 goto nla_put_failure
;
1198 if (gnet_stats_finish_copy(&d
) < 0)
1199 goto nla_put_failure
;
1201 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1210 static bool tc_qdisc_dump_ignore(struct Qdisc
*q
)
1212 return (q
->flags
& TCQ_F_BUILTIN
) ? true : false;
1215 static int qdisc_notify(struct net
*net
, struct sk_buff
*oskb
,
1216 struct nlmsghdr
*n
, u32 clid
,
1217 struct Qdisc
*old
, struct Qdisc
*new)
1219 struct sk_buff
*skb
;
1220 u32 pid
= oskb
? NETLINK_CB(oskb
).pid
: 0;
1222 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
1226 if (old
&& !tc_qdisc_dump_ignore(old
)) {
1227 if (tc_fill_qdisc(skb
, old
, clid
, pid
, n
->nlmsg_seq
, 0, RTM_DELQDISC
) < 0)
1230 if (new && !tc_qdisc_dump_ignore(new)) {
1231 if (tc_fill_qdisc(skb
, new, clid
, pid
, n
->nlmsg_seq
, old
? NLM_F_REPLACE
: 0, RTM_NEWQDISC
) < 0)
1236 return rtnetlink_send(skb
, net
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
1243 static int tc_dump_qdisc_root(struct Qdisc
*root
, struct sk_buff
*skb
,
1244 struct netlink_callback
*cb
,
1245 int *q_idx_p
, int s_q_idx
)
1247 int ret
= 0, q_idx
= *q_idx_p
;
1254 if (q_idx
< s_q_idx
) {
1257 if (!tc_qdisc_dump_ignore(q
) &&
1258 tc_fill_qdisc(skb
, q
, q
->parent
, NETLINK_CB(cb
->skb
).pid
,
1259 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
, RTM_NEWQDISC
) <= 0)
1263 list_for_each_entry(q
, &root
->list
, list
) {
1264 if (q_idx
< s_q_idx
) {
1268 if (!tc_qdisc_dump_ignore(q
) &&
1269 tc_fill_qdisc(skb
, q
, q
->parent
, NETLINK_CB(cb
->skb
).pid
,
1270 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
, RTM_NEWQDISC
) <= 0)
1283 static int tc_dump_qdisc(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1285 struct net
*net
= sock_net(skb
->sk
);
1288 struct net_device
*dev
;
1290 s_idx
= cb
->args
[0];
1291 s_q_idx
= q_idx
= cb
->args
[1];
1295 for_each_netdev_rcu(net
, dev
) {
1296 struct netdev_queue
*dev_queue
;
1304 if (tc_dump_qdisc_root(dev
->qdisc
, skb
, cb
, &q_idx
, s_q_idx
) < 0)
1307 dev_queue
= &dev
->rx_queue
;
1308 if (tc_dump_qdisc_root(dev_queue
->qdisc_sleeping
, skb
, cb
, &q_idx
, s_q_idx
) < 0)
1319 cb
->args
[1] = q_idx
;
1326 /************************************************
1327 * Traffic classes manipulation. *
1328 ************************************************/
1332 static int tc_ctl_tclass(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
1334 struct net
*net
= sock_net(skb
->sk
);
1335 struct tcmsg
*tcm
= NLMSG_DATA(n
);
1336 struct nlattr
*tca
[TCA_MAX
+ 1];
1337 struct net_device
*dev
;
1338 struct Qdisc
*q
= NULL
;
1339 const struct Qdisc_class_ops
*cops
;
1340 unsigned long cl
= 0;
1341 unsigned long new_cl
;
1342 u32 pid
= tcm
->tcm_parent
;
1343 u32 clid
= tcm
->tcm_handle
;
1344 u32 qid
= TC_H_MAJ(clid
);
1347 if ((dev
= __dev_get_by_index(net
, tcm
->tcm_ifindex
)) == NULL
)
1350 err
= nlmsg_parse(n
, sizeof(*tcm
), tca
, TCA_MAX
, NULL
);
1355 parent == TC_H_UNSPEC - unspecified parent.
1356 parent == TC_H_ROOT - class is root, which has no parent.
1357 parent == X:0 - parent is root class.
1358 parent == X:Y - parent is a node in hierarchy.
1359 parent == 0:Y - parent is X:Y, where X:0 is qdisc.
1361 handle == 0:0 - generate handle from kernel pool.
1362 handle == 0:Y - class is X:Y, where X:0 is qdisc.
1363 handle == X:Y - clear.
1364 handle == X:0 - root class.
1367 /* Step 1. Determine qdisc handle X:0 */
1369 if (pid
!= TC_H_ROOT
) {
1370 u32 qid1
= TC_H_MAJ(pid
);
1373 /* If both majors are known, they must be identical. */
1378 } else if (qid
== 0)
1379 qid
= dev
->qdisc
->handle
;
1381 /* Now qid is genuine qdisc handle consistent
1382 both with parent and child.
1384 TC_H_MAJ(pid) still may be unspecified, complete it now.
1387 pid
= TC_H_MAKE(qid
, pid
);
1390 qid
= dev
->qdisc
->handle
;
1393 /* OK. Locate qdisc */
1394 if ((q
= qdisc_lookup(dev
, qid
)) == NULL
)
1397 /* An check that it supports classes */
1398 cops
= q
->ops
->cl_ops
;
1402 /* Now try to get class */
1404 if (pid
== TC_H_ROOT
)
1407 clid
= TC_H_MAKE(qid
, clid
);
1410 cl
= cops
->get(q
, clid
);
1414 if (n
->nlmsg_type
!= RTM_NEWTCLASS
|| !(n
->nlmsg_flags
&NLM_F_CREATE
))
1417 switch (n
->nlmsg_type
) {
1420 if (n
->nlmsg_flags
&NLM_F_EXCL
)
1426 err
= cops
->delete(q
, cl
);
1428 tclass_notify(net
, skb
, n
, q
, cl
, RTM_DELTCLASS
);
1431 err
= tclass_notify(net
, skb
, n
, q
, cl
, RTM_NEWTCLASS
);
1442 err
= cops
->change(q
, clid
, pid
, tca
, &new_cl
);
1444 tclass_notify(net
, skb
, n
, q
, new_cl
, RTM_NEWTCLASS
);
1454 static int tc_fill_tclass(struct sk_buff
*skb
, struct Qdisc
*q
,
1456 u32 pid
, u32 seq
, u16 flags
, int event
)
1459 struct nlmsghdr
*nlh
;
1460 unsigned char *b
= skb_tail_pointer(skb
);
1462 const struct Qdisc_class_ops
*cl_ops
= q
->ops
->cl_ops
;
1464 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*tcm
), flags
);
1465 tcm
= NLMSG_DATA(nlh
);
1466 tcm
->tcm_family
= AF_UNSPEC
;
1469 tcm
->tcm_ifindex
= qdisc_dev(q
)->ifindex
;
1470 tcm
->tcm_parent
= q
->handle
;
1471 tcm
->tcm_handle
= q
->handle
;
1473 NLA_PUT_STRING(skb
, TCA_KIND
, q
->ops
->id
);
1474 if (cl_ops
->dump
&& cl_ops
->dump(q
, cl
, skb
, tcm
) < 0)
1475 goto nla_put_failure
;
1477 if (gnet_stats_start_copy_compat(skb
, TCA_STATS2
, TCA_STATS
, TCA_XSTATS
,
1478 qdisc_root_sleeping_lock(q
), &d
) < 0)
1479 goto nla_put_failure
;
1481 if (cl_ops
->dump_stats
&& cl_ops
->dump_stats(q
, cl
, &d
) < 0)
1482 goto nla_put_failure
;
1484 if (gnet_stats_finish_copy(&d
) < 0)
1485 goto nla_put_failure
;
1487 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1496 static int tclass_notify(struct net
*net
, struct sk_buff
*oskb
,
1497 struct nlmsghdr
*n
, struct Qdisc
*q
,
1498 unsigned long cl
, int event
)
1500 struct sk_buff
*skb
;
1501 u32 pid
= oskb
? NETLINK_CB(oskb
).pid
: 0;
1503 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
1507 if (tc_fill_tclass(skb
, q
, cl
, pid
, n
->nlmsg_seq
, 0, event
) < 0) {
1512 return rtnetlink_send(skb
, net
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
1515 struct qdisc_dump_args
1517 struct qdisc_walker w
;
1518 struct sk_buff
*skb
;
1519 struct netlink_callback
*cb
;
1522 static int qdisc_class_dump(struct Qdisc
*q
, unsigned long cl
, struct qdisc_walker
*arg
)
1524 struct qdisc_dump_args
*a
= (struct qdisc_dump_args
*)arg
;
1526 return tc_fill_tclass(a
->skb
, q
, cl
, NETLINK_CB(a
->cb
->skb
).pid
,
1527 a
->cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
, RTM_NEWTCLASS
);
1530 static int tc_dump_tclass_qdisc(struct Qdisc
*q
, struct sk_buff
*skb
,
1531 struct tcmsg
*tcm
, struct netlink_callback
*cb
,
1534 struct qdisc_dump_args arg
;
1536 if (tc_qdisc_dump_ignore(q
) ||
1537 *t_p
< s_t
|| !q
->ops
->cl_ops
||
1539 TC_H_MAJ(tcm
->tcm_parent
) != q
->handle
)) {
1544 memset(&cb
->args
[1], 0, sizeof(cb
->args
)-sizeof(cb
->args
[0]));
1545 arg
.w
.fn
= qdisc_class_dump
;
1549 arg
.w
.skip
= cb
->args
[1];
1551 q
->ops
->cl_ops
->walk(q
, &arg
.w
);
1552 cb
->args
[1] = arg
.w
.count
;
1559 static int tc_dump_tclass_root(struct Qdisc
*root
, struct sk_buff
*skb
,
1560 struct tcmsg
*tcm
, struct netlink_callback
*cb
,
1568 if (tc_dump_tclass_qdisc(root
, skb
, tcm
, cb
, t_p
, s_t
) < 0)
1571 list_for_each_entry(q
, &root
->list
, list
) {
1572 if (tc_dump_tclass_qdisc(q
, skb
, tcm
, cb
, t_p
, s_t
) < 0)
1579 static int tc_dump_tclass(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1581 struct tcmsg
*tcm
= (struct tcmsg
*)NLMSG_DATA(cb
->nlh
);
1582 struct net
*net
= sock_net(skb
->sk
);
1583 struct netdev_queue
*dev_queue
;
1584 struct net_device
*dev
;
1587 if (cb
->nlh
->nlmsg_len
< NLMSG_LENGTH(sizeof(*tcm
)))
1589 if ((dev
= dev_get_by_index(net
, tcm
->tcm_ifindex
)) == NULL
)
1595 if (tc_dump_tclass_root(dev
->qdisc
, skb
, tcm
, cb
, &t
, s_t
) < 0)
1598 dev_queue
= &dev
->rx_queue
;
1599 if (tc_dump_tclass_root(dev_queue
->qdisc_sleeping
, skb
, tcm
, cb
, &t
, s_t
) < 0)
1609 /* Main classifier routine: scans classifier chain attached
1610 to this qdisc, (optionally) tests for protocol and asks
1611 specific classifiers.
1613 int tc_classify_compat(struct sk_buff
*skb
, struct tcf_proto
*tp
,
1614 struct tcf_result
*res
)
1616 __be16 protocol
= skb
->protocol
;
1619 for (; tp
; tp
= tp
->next
) {
1620 if ((tp
->protocol
== protocol
||
1621 tp
->protocol
== htons(ETH_P_ALL
)) &&
1622 (err
= tp
->classify(skb
, tp
, res
)) >= 0) {
1623 #ifdef CONFIG_NET_CLS_ACT
1624 if (err
!= TC_ACT_RECLASSIFY
&& skb
->tc_verd
)
1625 skb
->tc_verd
= SET_TC_VERD(skb
->tc_verd
, 0);
1632 EXPORT_SYMBOL(tc_classify_compat
);
1634 int tc_classify(struct sk_buff
*skb
, struct tcf_proto
*tp
,
1635 struct tcf_result
*res
)
1639 #ifdef CONFIG_NET_CLS_ACT
1640 struct tcf_proto
*otp
= tp
;
1643 protocol
= skb
->protocol
;
1645 err
= tc_classify_compat(skb
, tp
, res
);
1646 #ifdef CONFIG_NET_CLS_ACT
1647 if (err
== TC_ACT_RECLASSIFY
) {
1648 u32 verd
= G_TC_VERD(skb
->tc_verd
);
1651 if (verd
++ >= MAX_REC_LOOP
) {
1652 if (net_ratelimit())
1654 "%s: packet reclassify loop"
1655 " rule prio %u protocol %02x\n",
1657 tp
->prio
& 0xffff, ntohs(tp
->protocol
));
1660 skb
->tc_verd
= SET_TC_VERD(skb
->tc_verd
, verd
);
1666 EXPORT_SYMBOL(tc_classify
);
1668 void tcf_destroy(struct tcf_proto
*tp
)
1670 tp
->ops
->destroy(tp
);
1671 module_put(tp
->ops
->owner
);
1675 void tcf_destroy_chain(struct tcf_proto
**fl
)
1677 struct tcf_proto
*tp
;
1679 while ((tp
= *fl
) != NULL
) {
1684 EXPORT_SYMBOL(tcf_destroy_chain
);
1686 #ifdef CONFIG_PROC_FS
1687 static int psched_show(struct seq_file
*seq
, void *v
)
1691 hrtimer_get_res(CLOCK_MONOTONIC
, &ts
);
1692 seq_printf(seq
, "%08x %08x %08x %08x\n",
1693 (u32
)NSEC_PER_USEC
, (u32
)PSCHED_TICKS2NS(1),
1695 (u32
)NSEC_PER_SEC
/(u32
)ktime_to_ns(timespec_to_ktime(ts
)));
1700 static int psched_open(struct inode
*inode
, struct file
*file
)
1702 return single_open(file
, psched_show
, NULL
);
1705 static const struct file_operations psched_fops
= {
1706 .owner
= THIS_MODULE
,
1707 .open
= psched_open
,
1709 .llseek
= seq_lseek
,
1710 .release
= single_release
,
1713 static int __net_init
psched_net_init(struct net
*net
)
1715 struct proc_dir_entry
*e
;
1717 e
= proc_net_fops_create(net
, "psched", 0, &psched_fops
);
1724 static void __net_exit
psched_net_exit(struct net
*net
)
1726 proc_net_remove(net
, "psched");
1729 static int __net_init
psched_net_init(struct net
*net
)
1734 static void __net_exit
psched_net_exit(struct net
*net
)
1739 static struct pernet_operations psched_net_ops
= {
1740 .init
= psched_net_init
,
1741 .exit
= psched_net_exit
,
1744 static int __init
pktsched_init(void)
1748 err
= register_pernet_subsys(&psched_net_ops
);
1750 printk(KERN_ERR
"pktsched_init: "
1751 "cannot initialize per netns operations\n");
1755 register_qdisc(&pfifo_qdisc_ops
);
1756 register_qdisc(&bfifo_qdisc_ops
);
1757 register_qdisc(&pfifo_head_drop_qdisc_ops
);
1758 register_qdisc(&mq_qdisc_ops
);
1760 rtnl_register(PF_UNSPEC
, RTM_NEWQDISC
, tc_modify_qdisc
, NULL
);
1761 rtnl_register(PF_UNSPEC
, RTM_DELQDISC
, tc_get_qdisc
, NULL
);
1762 rtnl_register(PF_UNSPEC
, RTM_GETQDISC
, tc_get_qdisc
, tc_dump_qdisc
);
1763 rtnl_register(PF_UNSPEC
, RTM_NEWTCLASS
, tc_ctl_tclass
, NULL
);
1764 rtnl_register(PF_UNSPEC
, RTM_DELTCLASS
, tc_ctl_tclass
, NULL
);
1765 rtnl_register(PF_UNSPEC
, RTM_GETTCLASS
, tc_ctl_tclass
, tc_dump_tclass
);
1770 subsys_initcall(pktsched_init
);