11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * net/sched/sch_prio.c Simple 3-band priority "scheduler". 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 51da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 61da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 71da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 101da177e4SLinus Torvalds * Fixes: 19990609: J Hadi Salim <hadi@nortelnetworks.com>: 111da177e4SLinus Torvalds * Init -- EINVAL when opt undefined 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds 141da177e4SLinus Torvalds #include <linux/module.h> 151da177e4SLinus Torvalds #include <asm/uaccess.h> 161da177e4SLinus Torvalds #include <asm/system.h> 171da177e4SLinus Torvalds #include <linux/bitops.h> 181da177e4SLinus Torvalds #include <linux/types.h> 191da177e4SLinus Torvalds #include <linux/kernel.h> 201da177e4SLinus Torvalds #include <linux/string.h> 211da177e4SLinus Torvalds #include <linux/mm.h> 221da177e4SLinus Torvalds #include <linux/socket.h> 231da177e4SLinus Torvalds #include <linux/sockios.h> 241da177e4SLinus Torvalds #include <linux/in.h> 251da177e4SLinus Torvalds #include <linux/errno.h> 261da177e4SLinus Torvalds #include <linux/interrupt.h> 271da177e4SLinus Torvalds #include <linux/if_ether.h> 281da177e4SLinus Torvalds #include <linux/inet.h> 291da177e4SLinus Torvalds #include <linux/netdevice.h> 301da177e4SLinus Torvalds #include <linux/etherdevice.h> 311da177e4SLinus Torvalds #include <linux/notifier.h> 321da177e4SLinus Torvalds #include <net/ip.h> 331da177e4SLinus Torvalds #include <net/route.h> 341da177e4SLinus Torvalds #include <linux/skbuff.h> 35*dc5fc579SArnaldo Carvalho de Melo #include <net/netlink.h> 361da177e4SLinus Torvalds #include <net/sock.h> 371da177e4SLinus Torvalds #include <net/pkt_sched.h> 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds struct prio_sched_data 411da177e4SLinus Torvalds { 421da177e4SLinus Torvalds int bands; 431da177e4SLinus Torvalds struct tcf_proto *filter_list; 441da177e4SLinus Torvalds u8 prio2band[TC_PRIO_MAX+1]; 451da177e4SLinus Torvalds struct Qdisc *queues[TCQ_PRIO_BANDS]; 461da177e4SLinus Torvalds }; 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds static struct Qdisc * 501da177e4SLinus Torvalds prio_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr) 511da177e4SLinus Torvalds { 521da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 531da177e4SLinus Torvalds u32 band = skb->priority; 541da177e4SLinus Torvalds struct tcf_result res; 551da177e4SLinus Torvalds 5629f1df6cSJamal Hadi Salim *qerr = NET_XMIT_BYPASS; 571da177e4SLinus Torvalds if (TC_H_MAJ(skb->priority) != sch->handle) { 581da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT 591da177e4SLinus Torvalds switch (tc_classify(skb, q->filter_list, &res)) { 601da177e4SLinus Torvalds case TC_ACT_STOLEN: 611da177e4SLinus Torvalds case TC_ACT_QUEUED: 621da177e4SLinus Torvalds *qerr = NET_XMIT_SUCCESS; 631da177e4SLinus Torvalds case TC_ACT_SHOT: 641da177e4SLinus Torvalds return NULL; 651da177e4SLinus Torvalds }; 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds if (!q->filter_list ) { 681da177e4SLinus Torvalds #else 691da177e4SLinus Torvalds if (!q->filter_list || tc_classify(skb, q->filter_list, &res)) { 701da177e4SLinus Torvalds #endif 711da177e4SLinus Torvalds if (TC_H_MAJ(band)) 721da177e4SLinus Torvalds band = 0; 731da177e4SLinus Torvalds return q->queues[q->prio2band[band&TC_PRIO_MAX]]; 741da177e4SLinus Torvalds } 751da177e4SLinus Torvalds band = res.classid; 761da177e4SLinus Torvalds } 771da177e4SLinus Torvalds band = TC_H_MIN(band) - 1; 781da177e4SLinus Torvalds if (band > q->bands) 791da177e4SLinus Torvalds return q->queues[q->prio2band[0]]; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds return q->queues[band]; 821da177e4SLinus Torvalds } 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds static int 851da177e4SLinus Torvalds prio_enqueue(struct sk_buff *skb, struct Qdisc *sch) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds struct Qdisc *qdisc; 881da177e4SLinus Torvalds int ret; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds qdisc = prio_classify(skb, sch, &ret); 911da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT 921da177e4SLinus Torvalds if (qdisc == NULL) { 9329f1df6cSJamal Hadi Salim 9429f1df6cSJamal Hadi Salim if (ret == NET_XMIT_BYPASS) 951da177e4SLinus Torvalds sch->qstats.drops++; 961da177e4SLinus Torvalds kfree_skb(skb); 971da177e4SLinus Torvalds return ret; 981da177e4SLinus Torvalds } 991da177e4SLinus Torvalds #endif 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds if ((ret = qdisc->enqueue(skb, qdisc)) == NET_XMIT_SUCCESS) { 1021da177e4SLinus Torvalds sch->bstats.bytes += skb->len; 1031da177e4SLinus Torvalds sch->bstats.packets++; 1041da177e4SLinus Torvalds sch->q.qlen++; 1051da177e4SLinus Torvalds return NET_XMIT_SUCCESS; 1061da177e4SLinus Torvalds } 1071da177e4SLinus Torvalds sch->qstats.drops++; 1081da177e4SLinus Torvalds return ret; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds static int 1131da177e4SLinus Torvalds prio_requeue(struct sk_buff *skb, struct Qdisc* sch) 1141da177e4SLinus Torvalds { 1151da177e4SLinus Torvalds struct Qdisc *qdisc; 1161da177e4SLinus Torvalds int ret; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds qdisc = prio_classify(skb, sch, &ret); 1191da177e4SLinus Torvalds #ifdef CONFIG_NET_CLS_ACT 1201da177e4SLinus Torvalds if (qdisc == NULL) { 12129f1df6cSJamal Hadi Salim if (ret == NET_XMIT_BYPASS) 1221da177e4SLinus Torvalds sch->qstats.drops++; 1231da177e4SLinus Torvalds kfree_skb(skb); 1241da177e4SLinus Torvalds return ret; 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds #endif 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds if ((ret = qdisc->ops->requeue(skb, qdisc)) == NET_XMIT_SUCCESS) { 1291da177e4SLinus Torvalds sch->q.qlen++; 1301da177e4SLinus Torvalds sch->qstats.requeues++; 1311da177e4SLinus Torvalds return 0; 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds sch->qstats.drops++; 1341da177e4SLinus Torvalds return NET_XMIT_DROP; 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds static struct sk_buff * 1391da177e4SLinus Torvalds prio_dequeue(struct Qdisc* sch) 1401da177e4SLinus Torvalds { 1411da177e4SLinus Torvalds struct sk_buff *skb; 1421da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 1431da177e4SLinus Torvalds int prio; 1441da177e4SLinus Torvalds struct Qdisc *qdisc; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds for (prio = 0; prio < q->bands; prio++) { 1471da177e4SLinus Torvalds qdisc = q->queues[prio]; 1481da177e4SLinus Torvalds skb = qdisc->dequeue(qdisc); 1491da177e4SLinus Torvalds if (skb) { 1501da177e4SLinus Torvalds sch->q.qlen--; 1511da177e4SLinus Torvalds return skb; 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds return NULL; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds } 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds static unsigned int prio_drop(struct Qdisc* sch) 1591da177e4SLinus Torvalds { 1601da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 1611da177e4SLinus Torvalds int prio; 1621da177e4SLinus Torvalds unsigned int len; 1631da177e4SLinus Torvalds struct Qdisc *qdisc; 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds for (prio = q->bands-1; prio >= 0; prio--) { 1661da177e4SLinus Torvalds qdisc = q->queues[prio]; 1676d037a26SPatrick McHardy if (qdisc->ops->drop && (len = qdisc->ops->drop(qdisc)) != 0) { 1681da177e4SLinus Torvalds sch->q.qlen--; 1691da177e4SLinus Torvalds return len; 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds return 0; 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds static void 1771da177e4SLinus Torvalds prio_reset(struct Qdisc* sch) 1781da177e4SLinus Torvalds { 1791da177e4SLinus Torvalds int prio; 1801da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds for (prio=0; prio<q->bands; prio++) 1831da177e4SLinus Torvalds qdisc_reset(q->queues[prio]); 1841da177e4SLinus Torvalds sch->q.qlen = 0; 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds static void 1881da177e4SLinus Torvalds prio_destroy(struct Qdisc* sch) 1891da177e4SLinus Torvalds { 1901da177e4SLinus Torvalds int prio; 1911da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 1921da177e4SLinus Torvalds struct tcf_proto *tp; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds while ((tp = q->filter_list) != NULL) { 1951da177e4SLinus Torvalds q->filter_list = tp->next; 1961da177e4SLinus Torvalds tcf_destroy(tp); 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds for (prio=0; prio<q->bands; prio++) 2001da177e4SLinus Torvalds qdisc_destroy(q->queues[prio]); 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds static int prio_tune(struct Qdisc *sch, struct rtattr *opt) 2041da177e4SLinus Torvalds { 2051da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 2061da177e4SLinus Torvalds struct tc_prio_qopt *qopt = RTA_DATA(opt); 2071da177e4SLinus Torvalds int i; 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds if (opt->rta_len < RTA_LENGTH(sizeof(*qopt))) 2101da177e4SLinus Torvalds return -EINVAL; 2111da177e4SLinus Torvalds if (qopt->bands > TCQ_PRIO_BANDS || qopt->bands < 2) 2121da177e4SLinus Torvalds return -EINVAL; 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds for (i=0; i<=TC_PRIO_MAX; i++) { 2151da177e4SLinus Torvalds if (qopt->priomap[i] >= qopt->bands) 2161da177e4SLinus Torvalds return -EINVAL; 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds sch_tree_lock(sch); 2201da177e4SLinus Torvalds q->bands = qopt->bands; 2211da177e4SLinus Torvalds memcpy(q->prio2band, qopt->priomap, TC_PRIO_MAX+1); 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds for (i=q->bands; i<TCQ_PRIO_BANDS; i++) { 2241da177e4SLinus Torvalds struct Qdisc *child = xchg(&q->queues[i], &noop_qdisc); 2255e50da01SPatrick McHardy if (child != &noop_qdisc) { 2265e50da01SPatrick McHardy qdisc_tree_decrease_qlen(child, child->q.qlen); 2271da177e4SLinus Torvalds qdisc_destroy(child); 2281da177e4SLinus Torvalds } 2295e50da01SPatrick McHardy } 2301da177e4SLinus Torvalds sch_tree_unlock(sch); 2311da177e4SLinus Torvalds 232dd914b40SAmnon Aaronsohn for (i=0; i<q->bands; i++) { 233dd914b40SAmnon Aaronsohn if (q->queues[i] == &noop_qdisc) { 2341da177e4SLinus Torvalds struct Qdisc *child; 2359f9afec4SPatrick McHardy child = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, 2369f9afec4SPatrick McHardy TC_H_MAKE(sch->handle, i + 1)); 2371da177e4SLinus Torvalds if (child) { 2381da177e4SLinus Torvalds sch_tree_lock(sch); 239dd914b40SAmnon Aaronsohn child = xchg(&q->queues[i], child); 2401da177e4SLinus Torvalds 2415e50da01SPatrick McHardy if (child != &noop_qdisc) { 2425e50da01SPatrick McHardy qdisc_tree_decrease_qlen(child, 2435e50da01SPatrick McHardy child->q.qlen); 2441da177e4SLinus Torvalds qdisc_destroy(child); 2455e50da01SPatrick McHardy } 2461da177e4SLinus Torvalds sch_tree_unlock(sch); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds } 2491da177e4SLinus Torvalds } 2501da177e4SLinus Torvalds return 0; 2511da177e4SLinus Torvalds } 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds static int prio_init(struct Qdisc *sch, struct rtattr *opt) 2541da177e4SLinus Torvalds { 2551da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 2561da177e4SLinus Torvalds int i; 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds for (i=0; i<TCQ_PRIO_BANDS; i++) 2591da177e4SLinus Torvalds q->queues[i] = &noop_qdisc; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds if (opt == NULL) { 2621da177e4SLinus Torvalds return -EINVAL; 2631da177e4SLinus Torvalds } else { 2641da177e4SLinus Torvalds int err; 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds if ((err= prio_tune(sch, opt)) != 0) 2671da177e4SLinus Torvalds return err; 2681da177e4SLinus Torvalds } 2691da177e4SLinus Torvalds return 0; 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds static int prio_dump(struct Qdisc *sch, struct sk_buff *skb) 2731da177e4SLinus Torvalds { 2741da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 27527a884dcSArnaldo Carvalho de Melo unsigned char *b = skb_tail_pointer(skb); 2761da177e4SLinus Torvalds struct tc_prio_qopt opt; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds opt.bands = q->bands; 2791da177e4SLinus Torvalds memcpy(&opt.priomap, q->prio2band, TC_PRIO_MAX+1); 2801da177e4SLinus Torvalds RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); 2811da177e4SLinus Torvalds return skb->len; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds rtattr_failure: 284*dc5fc579SArnaldo Carvalho de Melo nlmsg_trim(skb, b); 2851da177e4SLinus Torvalds return -1; 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, 2891da177e4SLinus Torvalds struct Qdisc **old) 2901da177e4SLinus Torvalds { 2911da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 2921da177e4SLinus Torvalds unsigned long band = arg - 1; 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds if (band >= q->bands) 2951da177e4SLinus Torvalds return -EINVAL; 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds if (new == NULL) 2981da177e4SLinus Torvalds new = &noop_qdisc; 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds sch_tree_lock(sch); 3011da177e4SLinus Torvalds *old = q->queues[band]; 3021da177e4SLinus Torvalds q->queues[band] = new; 3035e50da01SPatrick McHardy qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 3041da177e4SLinus Torvalds qdisc_reset(*old); 3051da177e4SLinus Torvalds sch_tree_unlock(sch); 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds return 0; 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds static struct Qdisc * 3111da177e4SLinus Torvalds prio_leaf(struct Qdisc *sch, unsigned long arg) 3121da177e4SLinus Torvalds { 3131da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3141da177e4SLinus Torvalds unsigned long band = arg - 1; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds if (band >= q->bands) 3171da177e4SLinus Torvalds return NULL; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds return q->queues[band]; 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds static unsigned long prio_get(struct Qdisc *sch, u32 classid) 3231da177e4SLinus Torvalds { 3241da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3251da177e4SLinus Torvalds unsigned long band = TC_H_MIN(classid); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds if (band - 1 >= q->bands) 3281da177e4SLinus Torvalds return 0; 3291da177e4SLinus Torvalds return band; 3301da177e4SLinus Torvalds } 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvalds static unsigned long prio_bind(struct Qdisc *sch, unsigned long parent, u32 classid) 3331da177e4SLinus Torvalds { 3341da177e4SLinus Torvalds return prio_get(sch, classid); 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds static void prio_put(struct Qdisc *q, unsigned long cl) 3391da177e4SLinus Torvalds { 3401da177e4SLinus Torvalds return; 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds static int prio_change(struct Qdisc *sch, u32 handle, u32 parent, struct rtattr **tca, unsigned long *arg) 3441da177e4SLinus Torvalds { 3451da177e4SLinus Torvalds unsigned long cl = *arg; 3461da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds if (cl - 1 > q->bands) 3491da177e4SLinus Torvalds return -ENOENT; 3501da177e4SLinus Torvalds return 0; 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds static int prio_delete(struct Qdisc *sch, unsigned long cl) 3541da177e4SLinus Torvalds { 3551da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3561da177e4SLinus Torvalds if (cl - 1 > q->bands) 3571da177e4SLinus Torvalds return -ENOENT; 3581da177e4SLinus Torvalds return 0; 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds static int prio_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb, 3631da177e4SLinus Torvalds struct tcmsg *tcm) 3641da177e4SLinus Torvalds { 3651da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds if (cl - 1 > q->bands) 3681da177e4SLinus Torvalds return -ENOENT; 3691da177e4SLinus Torvalds tcm->tcm_handle |= TC_H_MIN(cl); 3701da177e4SLinus Torvalds if (q->queues[cl-1]) 3711da177e4SLinus Torvalds tcm->tcm_info = q->queues[cl-1]->handle; 3721da177e4SLinus Torvalds return 0; 3731da177e4SLinus Torvalds } 3741da177e4SLinus Torvalds 3752cf6c36cSJarek Poplawski static int prio_dump_class_stats(struct Qdisc *sch, unsigned long cl, 3762cf6c36cSJarek Poplawski struct gnet_dump *d) 3772cf6c36cSJarek Poplawski { 3782cf6c36cSJarek Poplawski struct prio_sched_data *q = qdisc_priv(sch); 3792cf6c36cSJarek Poplawski struct Qdisc *cl_q; 3802cf6c36cSJarek Poplawski 3812cf6c36cSJarek Poplawski cl_q = q->queues[cl - 1]; 3822cf6c36cSJarek Poplawski if (gnet_stats_copy_basic(d, &cl_q->bstats) < 0 || 3832cf6c36cSJarek Poplawski gnet_stats_copy_queue(d, &cl_q->qstats) < 0) 3842cf6c36cSJarek Poplawski return -1; 3852cf6c36cSJarek Poplawski 3862cf6c36cSJarek Poplawski return 0; 3872cf6c36cSJarek Poplawski } 3882cf6c36cSJarek Poplawski 3891da177e4SLinus Torvalds static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg) 3901da177e4SLinus Torvalds { 3911da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 3921da177e4SLinus Torvalds int prio; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds if (arg->stop) 3951da177e4SLinus Torvalds return; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds for (prio = 0; prio < q->bands; prio++) { 3981da177e4SLinus Torvalds if (arg->count < arg->skip) { 3991da177e4SLinus Torvalds arg->count++; 4001da177e4SLinus Torvalds continue; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds if (arg->fn(sch, prio+1, arg) < 0) { 4031da177e4SLinus Torvalds arg->stop = 1; 4041da177e4SLinus Torvalds break; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds arg->count++; 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds static struct tcf_proto ** prio_find_tcf(struct Qdisc *sch, unsigned long cl) 4111da177e4SLinus Torvalds { 4121da177e4SLinus Torvalds struct prio_sched_data *q = qdisc_priv(sch); 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds if (cl) 4151da177e4SLinus Torvalds return NULL; 4161da177e4SLinus Torvalds return &q->filter_list; 4171da177e4SLinus Torvalds } 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds static struct Qdisc_class_ops prio_class_ops = { 4201da177e4SLinus Torvalds .graft = prio_graft, 4211da177e4SLinus Torvalds .leaf = prio_leaf, 4221da177e4SLinus Torvalds .get = prio_get, 4231da177e4SLinus Torvalds .put = prio_put, 4241da177e4SLinus Torvalds .change = prio_change, 4251da177e4SLinus Torvalds .delete = prio_delete, 4261da177e4SLinus Torvalds .walk = prio_walk, 4271da177e4SLinus Torvalds .tcf_chain = prio_find_tcf, 4281da177e4SLinus Torvalds .bind_tcf = prio_bind, 4291da177e4SLinus Torvalds .unbind_tcf = prio_put, 4301da177e4SLinus Torvalds .dump = prio_dump_class, 4312cf6c36cSJarek Poplawski .dump_stats = prio_dump_class_stats, 4321da177e4SLinus Torvalds }; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds static struct Qdisc_ops prio_qdisc_ops = { 4351da177e4SLinus Torvalds .next = NULL, 4361da177e4SLinus Torvalds .cl_ops = &prio_class_ops, 4371da177e4SLinus Torvalds .id = "prio", 4381da177e4SLinus Torvalds .priv_size = sizeof(struct prio_sched_data), 4391da177e4SLinus Torvalds .enqueue = prio_enqueue, 4401da177e4SLinus Torvalds .dequeue = prio_dequeue, 4411da177e4SLinus Torvalds .requeue = prio_requeue, 4421da177e4SLinus Torvalds .drop = prio_drop, 4431da177e4SLinus Torvalds .init = prio_init, 4441da177e4SLinus Torvalds .reset = prio_reset, 4451da177e4SLinus Torvalds .destroy = prio_destroy, 4461da177e4SLinus Torvalds .change = prio_tune, 4471da177e4SLinus Torvalds .dump = prio_dump, 4481da177e4SLinus Torvalds .owner = THIS_MODULE, 4491da177e4SLinus Torvalds }; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds static int __init prio_module_init(void) 4521da177e4SLinus Torvalds { 4531da177e4SLinus Torvalds return register_qdisc(&prio_qdisc_ops); 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds static void __exit prio_module_exit(void) 4571da177e4SLinus Torvalds { 4581da177e4SLinus Torvalds unregister_qdisc(&prio_qdisc_ops); 4591da177e4SLinus Torvalds } 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds module_init(prio_module_init) 4621da177e4SLinus Torvalds module_exit(prio_module_exit) 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 465