^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/sched/sch_skbprio.c SKB Priority Queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Nishanth Devarajan, <ndev2021@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Cody Doucette, <doucette@bu.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * original idea by Michel Machado, Cody Doucette, and Qiaobin Fu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/sch_generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* SKB Priority Queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * =================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Skbprio (SKB Priority Queue) is a queueing discipline that prioritizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * packets according to their skb->priority field. Under congestion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Skbprio drops already-enqueued lower priority packets to make space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * available for higher priority packets; it was conceived as a solution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * for denial-of-service defenses that need to route packets with different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * priorities as a mean to overcome DoS attacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct skbprio_sched_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Queue state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct sk_buff_head qdiscs[SKBPRIO_MAX_PRIORITY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct gnet_stats_queue qstats[SKBPRIO_MAX_PRIORITY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u16 highest_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u16 lowest_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static u16 calc_new_high_prio(const struct skbprio_sched_data *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) for (prio = q->highest_prio - 1; prio >= q->lowest_prio; prio--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (!skb_queue_empty(&q->qdiscs[prio]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* SKB queue is empty, return 0 (default highest priority setting). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static u16 calc_new_low_prio(const struct skbprio_sched_data *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) for (prio = q->lowest_prio + 1; prio <= q->highest_prio; prio++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!skb_queue_empty(&q->qdiscs[prio]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* SKB queue is empty, return SKBPRIO_MAX_PRIORITY - 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * (default lowest priority setting).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return SKBPRIO_MAX_PRIORITY - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int skbprio_enqueue(struct sk_buff *skb, struct Qdisc *sch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) const unsigned int max_priority = SKBPRIO_MAX_PRIORITY - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct sk_buff_head *qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct sk_buff_head *lp_qdisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct sk_buff *to_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u16 prio, lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Obtain the priority of @skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) prio = min(skb->priority, max_priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) qdisc = &q->qdiscs[prio];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (sch->q.qlen < sch->limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __skb_queue_tail(qdisc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) qdisc_qstats_backlog_inc(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) q->qstats[prio].backlog += qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* Check to update highest and lowest priorities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (prio > q->highest_prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) q->highest_prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (prio < q->lowest_prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) q->lowest_prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sch->q.qlen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* If this packet has the lowest priority, drop it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) lp = q->lowest_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (prio <= lp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) q->qstats[prio].drops++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) q->qstats[prio].overlimits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return qdisc_drop(skb, sch, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __skb_queue_tail(qdisc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) qdisc_qstats_backlog_inc(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) q->qstats[prio].backlog += qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* Drop the packet at the tail of the lowest priority qdisc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) lp_qdisc = &q->qdiscs[lp];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) to_drop = __skb_dequeue_tail(lp_qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) BUG_ON(!to_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) qdisc_qstats_backlog_dec(sch, to_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) qdisc_drop(to_drop, sch, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) q->qstats[lp].backlog -= qdisc_pkt_len(to_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) q->qstats[lp].drops++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) q->qstats[lp].overlimits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Check to update highest and lowest priorities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (skb_queue_empty(lp_qdisc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (q->lowest_prio == q->highest_prio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* The incoming packet is the only packet in queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) BUG_ON(sch->q.qlen != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) q->lowest_prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) q->highest_prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) q->lowest_prio = calc_new_low_prio(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (prio > q->highest_prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) q->highest_prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return NET_XMIT_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static struct sk_buff *skbprio_dequeue(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct sk_buff_head *hpq = &q->qdiscs[q->highest_prio];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct sk_buff *skb = __skb_dequeue(hpq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sch->q.qlen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) qdisc_qstats_backlog_dec(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) qdisc_bstats_update(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) q->qstats[q->highest_prio].backlog -= qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Update highest priority field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (skb_queue_empty(hpq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (q->lowest_prio == q->highest_prio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) BUG_ON(sch->q.qlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) q->highest_prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) q->lowest_prio = SKBPRIO_MAX_PRIORITY - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) q->highest_prio = calc_new_high_prio(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int skbprio_change(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct tc_skbprio_qopt *ctl = nla_data(opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (opt->nla_len != nla_attr_size(sizeof(*ctl)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) sch->limit = ctl->limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int skbprio_init(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Initialise all queues, one for each possible priority. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) for (prio = 0; prio < SKBPRIO_MAX_PRIORITY; prio++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __skb_queue_head_init(&q->qdiscs[prio]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) memset(&q->qstats, 0, sizeof(q->qstats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) q->highest_prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) q->lowest_prio = SKBPRIO_MAX_PRIORITY - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sch->limit = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return skbprio_change(sch, opt, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int skbprio_dump(struct Qdisc *sch, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct tc_skbprio_qopt opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) opt.limit = sch->limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void skbprio_reset(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) sch->qstats.backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) sch->q.qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) for (prio = 0; prio < SKBPRIO_MAX_PRIORITY; prio++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) __skb_queue_purge(&q->qdiscs[prio]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) memset(&q->qstats, 0, sizeof(q->qstats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) q->highest_prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) q->lowest_prio = SKBPRIO_MAX_PRIORITY - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static void skbprio_destroy(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) for (prio = 0; prio < SKBPRIO_MAX_PRIORITY; prio++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) __skb_queue_purge(&q->qdiscs[prio]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static struct Qdisc *skbprio_leaf(struct Qdisc *sch, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static unsigned long skbprio_find(struct Qdisc *sch, u32 classid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int skbprio_dump_class(struct Qdisc *sch, unsigned long cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct sk_buff *skb, struct tcmsg *tcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) tcm->tcm_handle |= TC_H_MIN(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int skbprio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct gnet_dump *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct skbprio_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (gnet_stats_copy_queue(d, NULL, &q->qstats[cl - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) q->qstats[cl - 1].qlen) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static void skbprio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (arg->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) for (i = 0; i < SKBPRIO_MAX_PRIORITY; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (arg->count < arg->skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (arg->fn(sch, i + 1, arg) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) arg->stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) arg->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static const struct Qdisc_class_ops skbprio_class_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .leaf = skbprio_leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .find = skbprio_find,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .dump = skbprio_dump_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .dump_stats = skbprio_dump_class_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .walk = skbprio_walk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static struct Qdisc_ops skbprio_qdisc_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .cl_ops = &skbprio_class_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .id = "skbprio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .priv_size = sizeof(struct skbprio_sched_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .enqueue = skbprio_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .dequeue = skbprio_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .peek = qdisc_peek_dequeued,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .init = skbprio_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .reset = skbprio_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .change = skbprio_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .dump = skbprio_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .destroy = skbprio_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int __init skbprio_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return register_qdisc(&skbprio_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void __exit skbprio_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) unregister_qdisc(&skbprio_qdisc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) module_init(skbprio_module_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) module_exit(skbprio_module_exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) MODULE_LICENSE("GPL");