| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * net/sched/sch_red.c	Random Early Detection queue. | 
|  | 3 | * | 
|  | 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. | 
|  | 8 | * | 
|  | 9 | * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | 
|  | 10 | * | 
|  | 11 | * Changes: | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 12 | * J Hadi Salim 980914:	computation fixes | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Alexey Makarenko <makar@phoenix.kharkov.ua> 990814: qave on idle link was calculated incorrectly. | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 14 | * J Hadi Salim 980816:  ECN support | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ | 
|  | 16 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/types.h> | 
|  | 19 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/netdevice.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/skbuff.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <net/pkt_sched.h> | 
|  | 23 | #include <net/inet_ecn.h> | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 24 | #include <net/red.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 |  | 
|  | 26 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 27 | /*	Parameters, settable by user: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | ----------------------------- | 
|  | 29 |  | 
|  | 30 | limit		- bytes (must be > qth_max + burst) | 
|  | 31 |  | 
|  | 32 | Hard limit on queue length, should be chosen >qth_max | 
|  | 33 | to allow packet bursts. This parameter does not | 
|  | 34 | affect the algorithms behaviour and can be chosen | 
|  | 35 | arbitrarily high (well, less than ram size) | 
|  | 36 | Really, this limit will never be reached | 
|  | 37 | if RED works correctly. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ | 
|  | 39 |  | 
|  | 40 | struct red_sched_data | 
|  | 41 | { | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 42 | u32			limit;		/* HARD maximal queue length */ | 
|  | 43 | unsigned char		flags; | 
|  | 44 | struct red_parms	parms; | 
|  | 45 | struct red_stats	stats; | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 46 | struct Qdisc		*qdisc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | }; | 
|  | 48 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 49 | static inline int red_use_ecn(struct red_sched_data *q) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 51 | return q->flags & TC_RED_ECN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Thomas Graf | bdc450a | 2005-11-05 21:14:28 +0100 | [diff] [blame] | 54 | static inline int red_use_harddrop(struct red_sched_data *q) | 
|  | 55 | { | 
|  | 56 | return q->flags & TC_RED_HARDDROP; | 
|  | 57 | } | 
|  | 58 |  | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 59 | static int red_enqueue(struct sk_buff *skb, struct Qdisc* sch) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { | 
|  | 61 | struct red_sched_data *q = qdisc_priv(sch); | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 62 | struct Qdisc *child = q->qdisc; | 
|  | 63 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 65 | q->parms.qavg = red_calc_qavg(&q->parms, child->qstats.backlog); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 67 | if (red_is_idling(&q->parms)) | 
|  | 68 | red_end_of_idle_period(&q->parms); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 70 | switch (red_action(&q->parms, q->parms.qavg)) { | 
|  | 71 | case RED_DONT_MARK: | 
|  | 72 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 74 | case RED_PROB_MARK: | 
|  | 75 | sch->qstats.overlimits++; | 
|  | 76 | if (!red_use_ecn(q) || !INET_ECN_set_ce(skb)) { | 
|  | 77 | q->stats.prob_drop++; | 
|  | 78 | goto congestion_drop; | 
|  | 79 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 81 | q->stats.prob_mark++; | 
|  | 82 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 84 | case RED_HARD_MARK: | 
|  | 85 | sch->qstats.overlimits++; | 
| Thomas Graf | bdc450a | 2005-11-05 21:14:28 +0100 | [diff] [blame] | 86 | if (red_use_harddrop(q) || !red_use_ecn(q) || | 
|  | 87 | !INET_ECN_set_ce(skb)) { | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 88 | q->stats.forced_drop++; | 
|  | 89 | goto congestion_drop; | 
|  | 90 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 92 | q->stats.forced_mark++; | 
|  | 93 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } | 
|  | 95 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 96 | ret = child->enqueue(skb, child); | 
|  | 97 | if (likely(ret == NET_XMIT_SUCCESS)) { | 
|  | 98 | sch->bstats.bytes += skb->len; | 
|  | 99 | sch->bstats.packets++; | 
|  | 100 | sch->q.qlen++; | 
|  | 101 | } else { | 
|  | 102 | q->stats.pdrop++; | 
|  | 103 | sch->qstats.drops++; | 
|  | 104 | } | 
|  | 105 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 107 | congestion_drop: | 
| Thomas Graf | 9e178ff | 2005-11-05 21:14:06 +0100 | [diff] [blame] | 108 | qdisc_drop(skb, sch); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return NET_XMIT_CN; | 
|  | 110 | } | 
|  | 111 |  | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 112 | static int red_requeue(struct sk_buff *skb, struct Qdisc* sch) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { | 
|  | 114 | struct red_sched_data *q = qdisc_priv(sch); | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 115 | struct Qdisc *child = q->qdisc; | 
|  | 116 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 118 | if (red_is_idling(&q->parms)) | 
|  | 119 | red_end_of_idle_period(&q->parms); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 121 | ret = child->ops->requeue(skb, child); | 
|  | 122 | if (likely(ret == NET_XMIT_SUCCESS)) { | 
|  | 123 | sch->qstats.requeues++; | 
|  | 124 | sch->q.qlen++; | 
|  | 125 | } | 
|  | 126 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } | 
|  | 128 |  | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 129 | static struct sk_buff * red_dequeue(struct Qdisc* sch) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { | 
|  | 131 | struct sk_buff *skb; | 
|  | 132 | struct red_sched_data *q = qdisc_priv(sch); | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 133 | struct Qdisc *child = q->qdisc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 135 | skb = child->dequeue(child); | 
|  | 136 | if (skb) | 
|  | 137 | sch->q.qlen--; | 
|  | 138 | else if (!red_is_idling(&q->parms)) | 
| Thomas Graf | 9e178ff | 2005-11-05 21:14:06 +0100 | [diff] [blame] | 139 | red_start_of_idle_period(&q->parms); | 
|  | 140 |  | 
|  | 141 | return skb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
|  | 144 | static unsigned int red_drop(struct Qdisc* sch) | 
|  | 145 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | struct red_sched_data *q = qdisc_priv(sch); | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 147 | struct Qdisc *child = q->qdisc; | 
|  | 148 | unsigned int len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 150 | if (child->ops->drop && (len = child->ops->drop(child)) > 0) { | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 151 | q->stats.other++; | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 152 | sch->qstats.drops++; | 
|  | 153 | sch->q.qlen--; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | return len; | 
|  | 155 | } | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 156 |  | 
| Thomas Graf | 6a1b63d | 2005-11-05 21:14:07 +0100 | [diff] [blame] | 157 | if (!red_is_idling(&q->parms)) | 
|  | 158 | red_start_of_idle_period(&q->parms); | 
|  | 159 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return 0; | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | static void red_reset(struct Qdisc* sch) | 
|  | 164 | { | 
|  | 165 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 166 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 167 | qdisc_reset(q->qdisc); | 
|  | 168 | sch->q.qlen = 0; | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 169 | red_restart(&q->parms); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 172 | static void red_destroy(struct Qdisc *sch) | 
|  | 173 | { | 
|  | 174 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 175 | qdisc_destroy(q->qdisc); | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | static struct Qdisc *red_create_dflt(struct net_device *dev, u32 limit) | 
|  | 179 | { | 
|  | 180 | struct Qdisc *q = qdisc_create_dflt(dev, &bfifo_qdisc_ops); | 
|  | 181 | struct rtattr *rta; | 
|  | 182 | int ret; | 
|  | 183 |  | 
|  | 184 | if (q) { | 
|  | 185 | rta = kmalloc(RTA_LENGTH(sizeof(struct tc_fifo_qopt)), | 
|  | 186 | GFP_KERNEL); | 
|  | 187 | if (rta) { | 
|  | 188 | rta->rta_type = RTM_NEWQDISC; | 
|  | 189 | rta->rta_len = RTA_LENGTH(sizeof(struct tc_fifo_qopt)); | 
|  | 190 | ((struct tc_fifo_qopt *)RTA_DATA(rta))->limit = limit; | 
|  | 191 |  | 
|  | 192 | ret = q->ops->change(q, rta); | 
|  | 193 | kfree(rta); | 
|  | 194 |  | 
|  | 195 | if (ret == 0) | 
|  | 196 | return q; | 
|  | 197 | } | 
|  | 198 | qdisc_destroy(q); | 
|  | 199 | } | 
|  | 200 | return NULL; | 
|  | 201 | } | 
|  | 202 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | static int red_change(struct Qdisc *sch, struct rtattr *opt) | 
|  | 204 | { | 
|  | 205 | struct red_sched_data *q = qdisc_priv(sch); | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 206 | struct rtattr *tb[TCA_RED_MAX]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | struct tc_red_qopt *ctl; | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 208 | struct Qdisc *child = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 |  | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 210 | if (opt == NULL || rtattr_parse_nested(tb, TCA_RED_MAX, opt)) | 
|  | 211 | return -EINVAL; | 
|  | 212 |  | 
|  | 213 | if (tb[TCA_RED_PARMS-1] == NULL || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | RTA_PAYLOAD(tb[TCA_RED_PARMS-1]) < sizeof(*ctl) || | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 215 | tb[TCA_RED_STAB-1] == NULL || | 
|  | 216 | RTA_PAYLOAD(tb[TCA_RED_STAB-1]) < RED_STAB_SIZE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return -EINVAL; | 
|  | 218 |  | 
|  | 219 | ctl = RTA_DATA(tb[TCA_RED_PARMS-1]); | 
|  | 220 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 221 | if (ctl->limit > 0) { | 
|  | 222 | child = red_create_dflt(sch->dev, ctl->limit); | 
|  | 223 | if (child == NULL) | 
|  | 224 | return -ENOMEM; | 
|  | 225 | } | 
|  | 226 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | sch_tree_lock(sch); | 
|  | 228 | q->flags = ctl->flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | q->limit = ctl->limit; | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 230 | if (child) | 
|  | 231 | qdisc_destroy(xchg(&q->qdisc, child)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 233 | red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog, | 
|  | 234 | ctl->Plog, ctl->Scell_log, | 
|  | 235 | RTA_DATA(tb[TCA_RED_STAB-1])); | 
|  | 236 |  | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 237 | if (skb_queue_empty(&sch->q)) | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 238 | red_end_of_idle_period(&q->parms); | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 239 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | sch_tree_unlock(sch); | 
|  | 241 | return 0; | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | static int red_init(struct Qdisc* sch, struct rtattr *opt) | 
|  | 245 | { | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 246 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 247 |  | 
|  | 248 | q->qdisc = &noop_qdisc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return red_change(sch, opt); | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 | static int red_dump(struct Qdisc *sch, struct sk_buff *skb) | 
|  | 253 | { | 
|  | 254 | struct red_sched_data *q = qdisc_priv(sch); | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 255 | struct rtattr *opts = NULL; | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 256 | struct tc_red_qopt opt = { | 
|  | 257 | .limit		= q->limit, | 
|  | 258 | .flags		= q->flags, | 
|  | 259 | .qth_min	= q->parms.qth_min >> q->parms.Wlog, | 
|  | 260 | .qth_max	= q->parms.qth_max >> q->parms.Wlog, | 
|  | 261 | .Wlog		= q->parms.Wlog, | 
|  | 262 | .Plog		= q->parms.Plog, | 
|  | 263 | .Scell_log	= q->parms.Scell_log, | 
|  | 264 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 |  | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 266 | opts = RTA_NEST(skb, TCA_OPTIONS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | RTA_PUT(skb, TCA_RED_PARMS, sizeof(opt), &opt); | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 268 | return RTA_NEST_END(skb, opts); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 |  | 
|  | 270 | rtattr_failure: | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 271 | return RTA_NEST_CANCEL(skb, opts); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } | 
|  | 273 |  | 
|  | 274 | static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d) | 
|  | 275 | { | 
|  | 276 | struct red_sched_data *q = qdisc_priv(sch); | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 277 | struct tc_red_xstats st = { | 
|  | 278 | .early	= q->stats.prob_drop + q->stats.forced_drop, | 
|  | 279 | .pdrop	= q->stats.pdrop, | 
|  | 280 | .other	= q->stats.other, | 
|  | 281 | .marked	= q->stats.prob_mark + q->stats.forced_mark, | 
|  | 282 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 |  | 
| Thomas Graf | 6b31b28 | 2005-11-05 21:14:05 +0100 | [diff] [blame] | 284 | return gnet_stats_copy_app(d, &st, sizeof(st)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } | 
|  | 286 |  | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 287 | static int red_dump_class(struct Qdisc *sch, unsigned long cl, | 
|  | 288 | struct sk_buff *skb, struct tcmsg *tcm) | 
|  | 289 | { | 
|  | 290 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 291 |  | 
|  | 292 | if (cl != 1) | 
|  | 293 | return -ENOENT; | 
|  | 294 | tcm->tcm_handle |= TC_H_MIN(1); | 
|  | 295 | tcm->tcm_info = q->qdisc->handle; | 
|  | 296 | return 0; | 
|  | 297 | } | 
|  | 298 |  | 
|  | 299 | static int red_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, | 
|  | 300 | struct Qdisc **old) | 
|  | 301 | { | 
|  | 302 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 303 |  | 
|  | 304 | if (new == NULL) | 
|  | 305 | new = &noop_qdisc; | 
|  | 306 |  | 
|  | 307 | sch_tree_lock(sch); | 
|  | 308 | *old = xchg(&q->qdisc, new); | 
|  | 309 | qdisc_reset(*old); | 
|  | 310 | sch->q.qlen = 0; | 
|  | 311 | sch_tree_unlock(sch); | 
|  | 312 | return 0; | 
|  | 313 | } | 
|  | 314 |  | 
|  | 315 | static struct Qdisc *red_leaf(struct Qdisc *sch, unsigned long arg) | 
|  | 316 | { | 
|  | 317 | struct red_sched_data *q = qdisc_priv(sch); | 
|  | 318 | return q->qdisc; | 
|  | 319 | } | 
|  | 320 |  | 
|  | 321 | static unsigned long red_get(struct Qdisc *sch, u32 classid) | 
|  | 322 | { | 
|  | 323 | return 1; | 
|  | 324 | } | 
|  | 325 |  | 
|  | 326 | static void red_put(struct Qdisc *sch, unsigned long arg) | 
|  | 327 | { | 
|  | 328 | return; | 
|  | 329 | } | 
|  | 330 |  | 
|  | 331 | static int red_change_class(struct Qdisc *sch, u32 classid, u32 parentid, | 
|  | 332 | struct rtattr **tca, unsigned long *arg) | 
|  | 333 | { | 
|  | 334 | return -ENOSYS; | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | static int red_delete(struct Qdisc *sch, unsigned long cl) | 
|  | 338 | { | 
|  | 339 | return -ENOSYS; | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | static void red_walk(struct Qdisc *sch, struct qdisc_walker *walker) | 
|  | 343 | { | 
|  | 344 | if (!walker->stop) { | 
|  | 345 | if (walker->count >= walker->skip) | 
|  | 346 | if (walker->fn(sch, 1, walker) < 0) { | 
|  | 347 | walker->stop = 1; | 
|  | 348 | return; | 
|  | 349 | } | 
|  | 350 | walker->count++; | 
|  | 351 | } | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | static struct tcf_proto **red_find_tcf(struct Qdisc *sch, unsigned long cl) | 
|  | 355 | { | 
|  | 356 | return NULL; | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | static struct Qdisc_class_ops red_class_ops = { | 
|  | 360 | .graft		=	red_graft, | 
|  | 361 | .leaf		=	red_leaf, | 
|  | 362 | .get		=	red_get, | 
|  | 363 | .put		=	red_put, | 
|  | 364 | .change		=	red_change_class, | 
|  | 365 | .delete		=	red_delete, | 
|  | 366 | .walk		=	red_walk, | 
|  | 367 | .tcf_chain	=	red_find_tcf, | 
|  | 368 | .dump		=	red_dump_class, | 
|  | 369 | }; | 
|  | 370 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | static struct Qdisc_ops red_qdisc_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | .id		=	"red", | 
|  | 373 | .priv_size	=	sizeof(struct red_sched_data), | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 374 | .cl_ops		=	&red_class_ops, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | .enqueue	=	red_enqueue, | 
|  | 376 | .dequeue	=	red_dequeue, | 
|  | 377 | .requeue	=	red_requeue, | 
|  | 378 | .drop		=	red_drop, | 
|  | 379 | .init		=	red_init, | 
|  | 380 | .reset		=	red_reset, | 
| Patrick McHardy | f38c39d | 2006-03-20 19:20:44 -0800 | [diff] [blame] | 381 | .destroy	=	red_destroy, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | .change		=	red_change, | 
|  | 383 | .dump		=	red_dump, | 
|  | 384 | .dump_stats	=	red_dump_stats, | 
|  | 385 | .owner		=	THIS_MODULE, | 
|  | 386 | }; | 
|  | 387 |  | 
|  | 388 | static int __init red_module_init(void) | 
|  | 389 | { | 
|  | 390 | return register_qdisc(&red_qdisc_ops); | 
|  | 391 | } | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 392 |  | 
|  | 393 | static void __exit red_module_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { | 
|  | 395 | unregister_qdisc(&red_qdisc_ops); | 
|  | 396 | } | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 397 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | module_init(red_module_init) | 
|  | 399 | module_exit(red_module_exit) | 
| Thomas Graf | dba051f | 2005-11-05 21:14:08 +0100 | [diff] [blame] | 400 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | MODULE_LICENSE("GPL"); |