Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sched/sch_netem.c Network emulator |
| 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 |
Stephen Hemminger | 798b6b1 | 2006-10-22 20:16:57 -0700 | [diff] [blame] | 7 | * 2 of the License. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Many of the algorithms and ideas for this came from |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 10 | * NIST Net which is not copyrighted. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Authors: Stephen Hemminger <shemminger@osdl.org> |
| 13 | * Catalin(ux aka Dino) BOIE <catab at umbrella dot ro> |
| 14 | */ |
| 15 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 16 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/skbuff.h> |
David S. Miller | 78776d3 | 2011-02-24 22:48:13 -0800 | [diff] [blame] | 23 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/rtnetlink.h> |
| 25 | |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 26 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <net/pkt_sched.h> |
| 28 | |
stephen hemminger | 250a65f | 2011-02-23 13:04:22 +0000 | [diff] [blame] | 29 | #define VERSION "1.3" |
Stephen Hemminger | eb229c4 | 2005-11-03 13:49:01 -0800 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* Network Emulation Queuing algorithm. |
| 32 | ==================================== |
| 33 | |
| 34 | Sources: [1] Mark Carson, Darrin Santay, "NIST Net - A Linux-based |
| 35 | Network Emulation Tool |
| 36 | [2] Luigi Rizzo, DummyNet for FreeBSD |
| 37 | |
| 38 | ---------------------------------------------------------------- |
| 39 | |
| 40 | This started out as a simple way to delay outgoing packets to |
| 41 | test TCP but has grown to include most of the functionality |
| 42 | of a full blown network emulator like NISTnet. It can delay |
| 43 | packets and add random jitter (and correlation). The random |
| 44 | distribution can be loaded from a table as well to provide |
| 45 | normal, Pareto, or experimental curves. Packet loss, |
| 46 | duplication, and reordering can also be emulated. |
| 47 | |
| 48 | This qdisc does not do classification that can be handled in |
| 49 | layering other disciplines. It does not need to do bandwidth |
| 50 | control either since that can be handled by using token |
| 51 | bucket or other rate control. |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 52 | |
| 53 | Correlated Loss Generator models |
| 54 | |
| 55 | Added generation of correlated loss according to the |
| 56 | "Gilbert-Elliot" model, a 4-state markov model. |
| 57 | |
| 58 | References: |
| 59 | [1] NetemCLG Home http://netgroup.uniroma2.it/NetemCLG |
| 60 | [2] S. Salsano, F. Ludovici, A. Ordine, "Definition of a general |
| 61 | and intuitive loss model for packet networks and its implementation |
| 62 | in the Netem module in the Linux kernel", available in [1] |
| 63 | |
| 64 | Authors: Stefano Salsano <stefano.salsano at uniroma2.it |
| 65 | Fabio Ludovici <fabio.ludovici at yahoo.it> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | */ |
| 67 | |
| 68 | struct netem_sched_data { |
| 69 | struct Qdisc *qdisc; |
Patrick McHardy | 59cb5c6 | 2007-03-16 01:20:31 -0700 | [diff] [blame] | 70 | struct qdisc_watchdog watchdog; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Stephen Hemminger | b407621 | 2007-03-22 12:16:21 -0700 | [diff] [blame] | 72 | psched_tdiff_t latency; |
| 73 | psched_tdiff_t jitter; |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | u32 loss; |
| 76 | u32 limit; |
| 77 | u32 counter; |
| 78 | u32 gap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | u32 duplicate; |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 80 | u32 reorder; |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 81 | u32 corrupt; |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 82 | u32 rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | struct crndstate { |
Stephen Hemminger | b407621 | 2007-03-22 12:16:21 -0700 | [diff] [blame] | 85 | u32 last; |
| 86 | u32 rho; |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 87 | } delay_cor, loss_cor, dup_cor, reorder_cor, corrupt_cor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | struct disttable { |
| 90 | u32 size; |
| 91 | s16 table[0]; |
| 92 | } *delay_dist; |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 93 | |
| 94 | enum { |
| 95 | CLG_RANDOM, |
| 96 | CLG_4_STATES, |
| 97 | CLG_GILB_ELL, |
| 98 | } loss_model; |
| 99 | |
| 100 | /* Correlated Loss Generation models */ |
| 101 | struct clgstate { |
| 102 | /* state of the Markov chain */ |
| 103 | u8 state; |
| 104 | |
| 105 | /* 4-states and Gilbert-Elliot models */ |
| 106 | u32 a1; /* p13 for 4-states or p for GE */ |
| 107 | u32 a2; /* p31 for 4-states or r for GE */ |
| 108 | u32 a3; /* p32 for 4-states or h for GE */ |
| 109 | u32 a4; /* p14 for 4-states or 1-k for GE */ |
| 110 | u32 a5; /* p23 used only in 4-states */ |
| 111 | } clg; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* Time stamp put into socket buffer control block */ |
| 116 | struct netem_skb_cb { |
| 117 | psched_time_t time_to_send; |
| 118 | }; |
| 119 | |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 120 | static inline struct netem_skb_cb *netem_skb_cb(struct sk_buff *skb) |
| 121 | { |
Jussi Kivilinna | 175f9c1 | 2008-07-20 00:08:47 -0700 | [diff] [blame] | 122 | BUILD_BUG_ON(sizeof(skb->cb) < |
| 123 | sizeof(struct qdisc_skb_cb) + sizeof(struct netem_skb_cb)); |
| 124 | return (struct netem_skb_cb *)qdisc_skb_cb(skb)->data; |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* init_crandom - initialize correlated random number generator |
| 128 | * Use entropy source for initial seed. |
| 129 | */ |
| 130 | static void init_crandom(struct crndstate *state, unsigned long rho) |
| 131 | { |
| 132 | state->rho = rho; |
| 133 | state->last = net_random(); |
| 134 | } |
| 135 | |
| 136 | /* get_crandom - correlated random number generator |
| 137 | * Next number depends on last value. |
| 138 | * rho is scaled to avoid floating point. |
| 139 | */ |
Stephen Hemminger | b407621 | 2007-03-22 12:16:21 -0700 | [diff] [blame] | 140 | static u32 get_crandom(struct crndstate *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | u64 value, rho; |
| 143 | unsigned long answer; |
| 144 | |
Stephen Hemminger | bb2f8cc | 2007-03-23 00:12:09 -0700 | [diff] [blame] | 145 | if (state->rho == 0) /* no correlation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | return net_random(); |
| 147 | |
| 148 | value = net_random(); |
| 149 | rho = (u64)state->rho + 1; |
| 150 | answer = (value * ((1ull<<32) - rho) + state->last * rho) >> 32; |
| 151 | state->last = answer; |
| 152 | return answer; |
| 153 | } |
| 154 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 155 | /* loss_4state - 4-state model loss generator |
| 156 | * Generates losses according to the 4-state Markov chain adopted in |
| 157 | * the GI (General and Intuitive) loss model. |
| 158 | */ |
| 159 | static bool loss_4state(struct netem_sched_data *q) |
| 160 | { |
| 161 | struct clgstate *clg = &q->clg; |
| 162 | u32 rnd = net_random(); |
| 163 | |
| 164 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 165 | * Makes a comparison between rnd and the transition |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 166 | * probabilities outgoing from the current state, then decides the |
| 167 | * next state and if the next packet has to be transmitted or lost. |
| 168 | * The four states correspond to: |
| 169 | * 1 => successfully transmitted packets within a gap period |
| 170 | * 4 => isolated losses within a gap period |
| 171 | * 3 => lost packets within a burst period |
| 172 | * 2 => successfully transmitted packets within a burst period |
| 173 | */ |
| 174 | switch (clg->state) { |
| 175 | case 1: |
| 176 | if (rnd < clg->a4) { |
| 177 | clg->state = 4; |
| 178 | return true; |
| 179 | } else if (clg->a4 < rnd && rnd < clg->a1) { |
| 180 | clg->state = 3; |
| 181 | return true; |
| 182 | } else if (clg->a1 < rnd) |
| 183 | clg->state = 1; |
| 184 | |
| 185 | break; |
| 186 | case 2: |
| 187 | if (rnd < clg->a5) { |
| 188 | clg->state = 3; |
| 189 | return true; |
| 190 | } else |
| 191 | clg->state = 2; |
| 192 | |
| 193 | break; |
| 194 | case 3: |
| 195 | if (rnd < clg->a3) |
| 196 | clg->state = 2; |
| 197 | else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { |
| 198 | clg->state = 1; |
| 199 | return true; |
| 200 | } else if (clg->a2 + clg->a3 < rnd) { |
| 201 | clg->state = 3; |
| 202 | return true; |
| 203 | } |
| 204 | break; |
| 205 | case 4: |
| 206 | clg->state = 1; |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | /* loss_gilb_ell - Gilbert-Elliot model loss generator |
| 214 | * Generates losses according to the Gilbert-Elliot loss model or |
| 215 | * its special cases (Gilbert or Simple Gilbert) |
| 216 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 217 | * Makes a comparison between random number and the transition |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 218 | * probabilities outgoing from the current state, then decides the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 219 | * next state. A second random number is extracted and the comparison |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 220 | * with the loss probability of the current state decides if the next |
| 221 | * packet will be transmitted or lost. |
| 222 | */ |
| 223 | static bool loss_gilb_ell(struct netem_sched_data *q) |
| 224 | { |
| 225 | struct clgstate *clg = &q->clg; |
| 226 | |
| 227 | switch (clg->state) { |
| 228 | case 1: |
| 229 | if (net_random() < clg->a1) |
| 230 | clg->state = 2; |
| 231 | if (net_random() < clg->a4) |
| 232 | return true; |
| 233 | case 2: |
| 234 | if (net_random() < clg->a2) |
| 235 | clg->state = 1; |
| 236 | if (clg->a3 > net_random()) |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | static bool loss_event(struct netem_sched_data *q) |
| 244 | { |
| 245 | switch (q->loss_model) { |
| 246 | case CLG_RANDOM: |
| 247 | /* Random packet drop 0 => none, ~0 => all */ |
| 248 | return q->loss && q->loss >= get_crandom(&q->loss_cor); |
| 249 | |
| 250 | case CLG_4_STATES: |
| 251 | /* 4state loss model algorithm (used also for GI model) |
| 252 | * Extracts a value from the markov 4 state loss generator, |
| 253 | * if it is 1 drops a packet and if needed writes the event in |
| 254 | * the kernel logs |
| 255 | */ |
| 256 | return loss_4state(q); |
| 257 | |
| 258 | case CLG_GILB_ELL: |
| 259 | /* Gilbert-Elliot loss model algorithm |
| 260 | * Extracts a value from the Gilbert-Elliot loss generator, |
| 261 | * if it is 1 drops a packet and if needed writes the event in |
| 262 | * the kernel logs |
| 263 | */ |
| 264 | return loss_gilb_ell(q); |
| 265 | } |
| 266 | |
| 267 | return false; /* not reached */ |
| 268 | } |
| 269 | |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* tabledist - return a pseudo-randomly distributed value with mean mu and |
| 272 | * std deviation sigma. Uses table lookup to approximate the desired |
| 273 | * distribution, and a uniformly-distributed pseudo-random source. |
| 274 | */ |
Stephen Hemminger | b407621 | 2007-03-22 12:16:21 -0700 | [diff] [blame] | 275 | static psched_tdiff_t tabledist(psched_tdiff_t mu, psched_tdiff_t sigma, |
| 276 | struct crndstate *state, |
| 277 | const struct disttable *dist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Stephen Hemminger | b407621 | 2007-03-22 12:16:21 -0700 | [diff] [blame] | 279 | psched_tdiff_t x; |
| 280 | long t; |
| 281 | u32 rnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | if (sigma == 0) |
| 284 | return mu; |
| 285 | |
| 286 | rnd = get_crandom(state); |
| 287 | |
| 288 | /* default uniform distribution */ |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 289 | if (dist == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return (rnd % (2*sigma)) - sigma + mu; |
| 291 | |
| 292 | t = dist->table[rnd % dist->size]; |
| 293 | x = (sigma % NETEM_DIST_SCALE) * t; |
| 294 | if (x >= 0) |
| 295 | x += NETEM_DIST_SCALE/2; |
| 296 | else |
| 297 | x -= NETEM_DIST_SCALE/2; |
| 298 | |
| 299 | return x / NETEM_DIST_SCALE + (sigma / NETEM_DIST_SCALE) * t + mu; |
| 300 | } |
| 301 | |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 302 | static psched_time_t packet_len_2_sched_time(unsigned int len, u32 rate) |
| 303 | { |
| 304 | return PSCHED_NS2TICKS((u64)len * NSEC_PER_SEC / rate); |
| 305 | } |
| 306 | |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 307 | /* |
| 308 | * Insert one skb into qdisc. |
| 309 | * Note: parent depends on return value to account for queue length. |
| 310 | * NET_XMIT_DROP: queue length didn't change. |
| 311 | * NET_XMIT_SUCCESS: one skb was queued. |
| 312 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
| 314 | { |
| 315 | struct netem_sched_data *q = qdisc_priv(sch); |
Guillaume Chazarain | 89e1df7 | 2006-07-21 14:45:25 -0700 | [diff] [blame] | 316 | /* We don't fill cb now as skb_unshare() may invalidate it */ |
| 317 | struct netem_skb_cb *cb; |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 318 | struct sk_buff *skb2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | int ret; |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 320 | int count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 322 | /* Random duplication */ |
| 323 | if (q->duplicate && q->duplicate >= get_crandom(&q->dup_cor)) |
| 324 | ++count; |
| 325 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 326 | /* Drop packet? */ |
| 327 | if (loss_event(q)) |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 328 | --count; |
| 329 | |
| 330 | if (count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | sch->qstats.drops++; |
| 332 | kfree_skb(skb); |
Jarek Poplawski | c27f339 | 2008-08-04 22:39:11 -0700 | [diff] [blame] | 333 | return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
David S. Miller | 4e8a520 | 2006-10-22 21:00:33 -0700 | [diff] [blame] | 336 | skb_orphan(skb); |
| 337 | |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 338 | /* |
| 339 | * If we need to duplicate packet, then re-insert at top of the |
| 340 | * qdisc tree, since parent queuer expects that only one |
| 341 | * skb will be queued. |
| 342 | */ |
| 343 | if (count > 1 && (skb2 = skb_clone(skb, GFP_ATOMIC)) != NULL) { |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 344 | struct Qdisc *rootq = qdisc_root(sch); |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 345 | u32 dupsave = q->duplicate; /* prevent duplicating a dup... */ |
| 346 | q->duplicate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 348 | qdisc_enqueue_root(skb2, rootq); |
Stephen Hemminger | 0afb51e | 2005-05-26 12:53:49 -0700 | [diff] [blame] | 349 | q->duplicate = dupsave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 352 | /* |
| 353 | * Randomized packet corruption. |
| 354 | * Make copy if needed since we are modifying |
| 355 | * If packet is going to be hardware checksummed, then |
| 356 | * do it now in software before we mangle it. |
| 357 | */ |
| 358 | if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 359 | if (!(skb = skb_unshare(skb, GFP_ATOMIC)) || |
| 360 | (skb->ip_summed == CHECKSUM_PARTIAL && |
| 361 | skb_checksum_help(skb))) { |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 362 | sch->qstats.drops++; |
| 363 | return NET_XMIT_DROP; |
| 364 | } |
| 365 | |
| 366 | skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8); |
| 367 | } |
| 368 | |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 369 | cb = netem_skb_cb(skb); |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 370 | if (q->gap == 0 || /* not doing reordering */ |
| 371 | q->counter < q->gap || /* inside last reordering gap */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 372 | q->reorder < get_crandom(&q->reorder_cor)) { |
Stephen Hemminger | 0f9f32a | 2005-05-26 12:55:01 -0700 | [diff] [blame] | 373 | psched_time_t now; |
Stephen Hemminger | 07aaa11 | 2005-11-03 13:43:07 -0800 | [diff] [blame] | 374 | psched_tdiff_t delay; |
| 375 | |
| 376 | delay = tabledist(q->latency, q->jitter, |
| 377 | &q->delay_cor, q->delay_dist); |
| 378 | |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 379 | now = psched_get_time(); |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 380 | |
| 381 | if (q->rate) { |
| 382 | struct sk_buff_head *list = &q->qdisc->q; |
| 383 | |
| 384 | delay += packet_len_2_sched_time(skb->len, q->rate); |
| 385 | |
| 386 | if (!skb_queue_empty(list)) { |
| 387 | /* |
| 388 | * Last packet in queue is reference point (now). |
| 389 | * First packet in queue is already in flight, |
| 390 | * calculate this time bonus and substract |
| 391 | * from delay. |
| 392 | */ |
| 393 | delay -= now - netem_skb_cb(skb_peek(list))->time_to_send; |
| 394 | now = netem_skb_cb(skb_peek_tail(list))->time_to_send; |
| 395 | } |
| 396 | } |
| 397 | |
Patrick McHardy | 7c59e25 | 2007-03-23 11:27:45 -0700 | [diff] [blame] | 398 | cb->time_to_send = now + delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | ++q->counter; |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 400 | ret = qdisc_enqueue(skb, q->qdisc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } else { |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 402 | /* |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 403 | * Do re-ordering by putting one out of N packets at the front |
| 404 | * of the queue. |
| 405 | */ |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 406 | cb->time_to_send = psched_get_time(); |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 407 | q->counter = 0; |
Jarek Poplawski | 8ba25da | 2008-11-02 00:36:03 -0700 | [diff] [blame] | 408 | |
| 409 | __skb_queue_head(&q->qdisc->q, skb); |
| 410 | q->qdisc->qstats.backlog += qdisc_pkt_len(skb); |
| 411 | q->qdisc->qstats.requeues++; |
| 412 | ret = NET_XMIT_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 415 | if (ret != NET_XMIT_SUCCESS) { |
| 416 | if (net_xmit_drop_count(ret)) { |
| 417 | sch->qstats.drops++; |
| 418 | return ret; |
| 419 | } |
Jarek Poplawski | 378a2f0 | 2008-08-04 22:31:03 -0700 | [diff] [blame] | 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 422 | sch->q.qlen++; |
| 423 | return NET_XMIT_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 426 | static unsigned int netem_drop(struct Qdisc *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
| 428 | struct netem_sched_data *q = qdisc_priv(sch); |
Patrick McHardy | 6d037a2 | 2006-03-20 19:00:49 -0800 | [diff] [blame] | 429 | unsigned int len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Patrick McHardy | 6d037a2 | 2006-03-20 19:00:49 -0800 | [diff] [blame] | 431 | if (q->qdisc->ops->drop && (len = q->qdisc->ops->drop(q->qdisc)) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | sch->q.qlen--; |
| 433 | sch->qstats.drops++; |
| 434 | } |
| 435 | return len; |
| 436 | } |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | static struct sk_buff *netem_dequeue(struct Qdisc *sch) |
| 439 | { |
| 440 | struct netem_sched_data *q = qdisc_priv(sch); |
| 441 | struct sk_buff *skb; |
| 442 | |
Eric Dumazet | fd245a4 | 2011-01-20 05:27:16 +0000 | [diff] [blame] | 443 | if (qdisc_is_throttled(sch)) |
Stephen Hemminger | 11274e5 | 2007-03-22 12:17:42 -0700 | [diff] [blame] | 444 | return NULL; |
| 445 | |
Jarek Poplawski | 03c05f0 | 2008-10-31 00:46:19 -0700 | [diff] [blame] | 446 | skb = q->qdisc->ops->peek(q->qdisc); |
Stephen Hemminger | 771018e | 2005-05-03 16:24:32 -0700 | [diff] [blame] | 447 | if (skb) { |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 448 | const struct netem_skb_cb *cb = netem_skb_cb(skb); |
Patrick McHardy | 3bebcda | 2007-03-23 11:29:25 -0700 | [diff] [blame] | 449 | psched_time_t now = psched_get_time(); |
Stephen Hemminger | 771018e | 2005-05-03 16:24:32 -0700 | [diff] [blame] | 450 | |
Stephen Hemminger | 0f9f32a | 2005-05-26 12:55:01 -0700 | [diff] [blame] | 451 | /* if more time remaining? */ |
Patrick McHardy | 104e087 | 2007-03-23 11:28:07 -0700 | [diff] [blame] | 452 | if (cb->time_to_send <= now) { |
Jarek Poplawski | 77be155 | 2008-10-31 00:47:01 -0700 | [diff] [blame] | 453 | skb = qdisc_dequeue_peeked(q->qdisc); |
| 454 | if (unlikely(!skb)) |
Jarek Poplawski | 03c05f0 | 2008-10-31 00:46:19 -0700 | [diff] [blame] | 455 | return NULL; |
| 456 | |
Jarek Poplawski | 8caf153 | 2009-04-17 10:08:49 +0000 | [diff] [blame] | 457 | #ifdef CONFIG_NET_CLS_ACT |
| 458 | /* |
| 459 | * If it's at ingress let's pretend the delay is |
| 460 | * from the network (tstamp will be updated). |
| 461 | */ |
| 462 | if (G_TC_FROM(skb->tc_verd) & AT_INGRESS) |
| 463 | skb->tstamp.tv64 = 0; |
| 464 | #endif |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 465 | |
Stephen Hemminger | 0f9f32a | 2005-05-26 12:55:01 -0700 | [diff] [blame] | 466 | sch->q.qlen--; |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 467 | qdisc_unthrottled(sch); |
| 468 | qdisc_bstats_update(sch, skb); |
Stephen Hemminger | 0f9f32a | 2005-05-26 12:55:01 -0700 | [diff] [blame] | 469 | return skb; |
| 470 | } |
Stephen Hemminger | 11274e5 | 2007-03-22 12:17:42 -0700 | [diff] [blame] | 471 | |
Stephen Hemminger | 11274e5 | 2007-03-22 12:17:42 -0700 | [diff] [blame] | 472 | qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send); |
Stephen Hemminger | 0f9f32a | 2005-05-26 12:55:01 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | static void netem_reset(struct Qdisc *sch) |
| 479 | { |
| 480 | struct netem_sched_data *q = qdisc_priv(sch); |
| 481 | |
| 482 | qdisc_reset(q->qdisc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | sch->q.qlen = 0; |
Patrick McHardy | 59cb5c6 | 2007-03-16 01:20:31 -0700 | [diff] [blame] | 484 | qdisc_watchdog_cancel(&q->watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 487 | static void dist_free(struct disttable *d) |
| 488 | { |
| 489 | if (d) { |
| 490 | if (is_vmalloc_addr(d)) |
| 491 | vfree(d); |
| 492 | else |
| 493 | kfree(d); |
| 494 | } |
| 495 | } |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | /* |
| 498 | * Distribution data is a variable size payload containing |
| 499 | * signed 16 bit values. |
| 500 | */ |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 501 | static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | struct netem_sched_data *q = qdisc_priv(sch); |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 504 | size_t n = nla_len(attr)/sizeof(__s16); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 505 | const __s16 *data = nla_data(attr); |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 506 | spinlock_t *root_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | struct disttable *d; |
| 508 | int i; |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 509 | size_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
stephen hemminger | df173bd | 2011-02-23 13:04:19 +0000 | [diff] [blame] | 511 | if (n > NETEM_DIST_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | return -EINVAL; |
| 513 | |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 514 | s = sizeof(struct disttable) + n * sizeof(s16); |
| 515 | d = kmalloc(s, GFP_KERNEL); |
| 516 | if (!d) |
| 517 | d = vmalloc(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (!d) |
| 519 | return -ENOMEM; |
| 520 | |
| 521 | d->size = n; |
| 522 | for (i = 0; i < n; i++) |
| 523 | d->table[i] = data[i]; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 524 | |
Jarek Poplawski | 102396a | 2008-08-29 14:21:52 -0700 | [diff] [blame] | 525 | root_lock = qdisc_root_sleeping_lock(sch); |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 526 | |
| 527 | spin_lock_bh(root_lock); |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 528 | dist_free(q->delay_dist); |
Patrick McHardy | b94c8af | 2008-11-20 04:11:36 -0800 | [diff] [blame] | 529 | q->delay_dist = d; |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 530 | spin_unlock_bh(root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 534 | static void get_correlation(struct Qdisc *sch, const struct nlattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
| 536 | struct netem_sched_data *q = qdisc_priv(sch); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 537 | const struct tc_netem_corr *c = nla_data(attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | init_crandom(&q->delay_cor, c->delay_corr); |
| 540 | init_crandom(&q->loss_cor, c->loss_corr); |
| 541 | init_crandom(&q->dup_cor, c->dup_corr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 544 | static void get_reorder(struct Qdisc *sch, const struct nlattr *attr) |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 545 | { |
| 546 | struct netem_sched_data *q = qdisc_priv(sch); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 547 | const struct tc_netem_reorder *r = nla_data(attr); |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 548 | |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 549 | q->reorder = r->probability; |
| 550 | init_crandom(&q->reorder_cor, r->correlation); |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 553 | static void get_corrupt(struct Qdisc *sch, const struct nlattr *attr) |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 554 | { |
| 555 | struct netem_sched_data *q = qdisc_priv(sch); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 556 | const struct tc_netem_corrupt *r = nla_data(attr); |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 557 | |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 558 | q->corrupt = r->probability; |
| 559 | init_crandom(&q->corrupt_cor, r->correlation); |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 562 | static void get_rate(struct Qdisc *sch, const struct nlattr *attr) |
| 563 | { |
| 564 | struct netem_sched_data *q = qdisc_priv(sch); |
| 565 | const struct tc_netem_rate *r = nla_data(attr); |
| 566 | |
| 567 | q->rate = r->rate; |
| 568 | } |
| 569 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 570 | static int get_loss_clg(struct Qdisc *sch, const struct nlattr *attr) |
| 571 | { |
| 572 | struct netem_sched_data *q = qdisc_priv(sch); |
| 573 | const struct nlattr *la; |
| 574 | int rem; |
| 575 | |
| 576 | nla_for_each_nested(la, attr, rem) { |
| 577 | u16 type = nla_type(la); |
| 578 | |
| 579 | switch(type) { |
| 580 | case NETEM_LOSS_GI: { |
| 581 | const struct tc_netem_gimodel *gi = nla_data(la); |
| 582 | |
| 583 | if (nla_len(la) != sizeof(struct tc_netem_gimodel)) { |
| 584 | pr_info("netem: incorrect gi model size\n"); |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | |
| 588 | q->loss_model = CLG_4_STATES; |
| 589 | |
| 590 | q->clg.state = 1; |
| 591 | q->clg.a1 = gi->p13; |
| 592 | q->clg.a2 = gi->p31; |
| 593 | q->clg.a3 = gi->p32; |
| 594 | q->clg.a4 = gi->p14; |
| 595 | q->clg.a5 = gi->p23; |
| 596 | break; |
| 597 | } |
| 598 | |
| 599 | case NETEM_LOSS_GE: { |
| 600 | const struct tc_netem_gemodel *ge = nla_data(la); |
| 601 | |
| 602 | if (nla_len(la) != sizeof(struct tc_netem_gemodel)) { |
| 603 | pr_info("netem: incorrect gi model size\n"); |
| 604 | return -EINVAL; |
| 605 | } |
| 606 | |
| 607 | q->loss_model = CLG_GILB_ELL; |
| 608 | q->clg.state = 1; |
| 609 | q->clg.a1 = ge->p; |
| 610 | q->clg.a2 = ge->r; |
| 611 | q->clg.a3 = ge->h; |
| 612 | q->clg.a4 = ge->k1; |
| 613 | break; |
| 614 | } |
| 615 | |
| 616 | default: |
| 617 | pr_info("netem: unknown loss type %u\n", type); |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
Patrick McHardy | 27a3421 | 2008-01-23 20:35:39 -0800 | [diff] [blame] | 625 | static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = { |
| 626 | [TCA_NETEM_CORR] = { .len = sizeof(struct tc_netem_corr) }, |
| 627 | [TCA_NETEM_REORDER] = { .len = sizeof(struct tc_netem_reorder) }, |
| 628 | [TCA_NETEM_CORRUPT] = { .len = sizeof(struct tc_netem_corrupt) }, |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 629 | [TCA_NETEM_RATE] = { .len = sizeof(struct tc_netem_rate) }, |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 630 | [TCA_NETEM_LOSS] = { .type = NLA_NESTED }, |
Patrick McHardy | 27a3421 | 2008-01-23 20:35:39 -0800 | [diff] [blame] | 631 | }; |
| 632 | |
Thomas Graf | 2c10b32 | 2008-09-02 17:30:27 -0700 | [diff] [blame] | 633 | static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, |
| 634 | const struct nla_policy *policy, int len) |
| 635 | { |
| 636 | int nested_len = nla_len(nla) - NLA_ALIGN(len); |
| 637 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 638 | if (nested_len < 0) { |
| 639 | pr_info("netem: invalid attributes len %d\n", nested_len); |
Thomas Graf | 2c10b32 | 2008-09-02 17:30:27 -0700 | [diff] [blame] | 640 | return -EINVAL; |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Thomas Graf | 2c10b32 | 2008-09-02 17:30:27 -0700 | [diff] [blame] | 643 | if (nested_len >= nla_attr_size(0)) |
| 644 | return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len), |
| 645 | nested_len, policy); |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 646 | |
Thomas Graf | 2c10b32 | 2008-09-02 17:30:27 -0700 | [diff] [blame] | 647 | memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); |
| 648 | return 0; |
| 649 | } |
| 650 | |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 651 | /* Parse netlink message to set options */ |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 652 | static int netem_change(struct Qdisc *sch, struct nlattr *opt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
| 654 | struct netem_sched_data *q = qdisc_priv(sch); |
Patrick McHardy | b03f467 | 2008-01-23 20:32:21 -0800 | [diff] [blame] | 655 | struct nlattr *tb[TCA_NETEM_MAX + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct tc_netem_qopt *qopt; |
| 657 | int ret; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 658 | |
Patrick McHardy | b03f467 | 2008-01-23 20:32:21 -0800 | [diff] [blame] | 659 | if (opt == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | return -EINVAL; |
| 661 | |
Thomas Graf | 2c10b32 | 2008-09-02 17:30:27 -0700 | [diff] [blame] | 662 | qopt = nla_data(opt); |
| 663 | ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt)); |
Patrick McHardy | b03f467 | 2008-01-23 20:32:21 -0800 | [diff] [blame] | 664 | if (ret < 0) |
| 665 | return ret; |
| 666 | |
Patrick McHardy | fb0305c | 2008-07-05 23:40:21 -0700 | [diff] [blame] | 667 | ret = fifo_set_limit(q->qdisc, qopt->limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | if (ret) { |
stephen hemminger | 250a65f | 2011-02-23 13:04:22 +0000 | [diff] [blame] | 669 | pr_info("netem: can't set fifo limit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return ret; |
| 671 | } |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | q->latency = qopt->latency; |
| 674 | q->jitter = qopt->jitter; |
| 675 | q->limit = qopt->limit; |
| 676 | q->gap = qopt->gap; |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 677 | q->counter = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | q->loss = qopt->loss; |
| 679 | q->duplicate = qopt->duplicate; |
| 680 | |
Stephen Hemminger | bb2f8cc | 2007-03-23 00:12:09 -0700 | [diff] [blame] | 681 | /* for compatibility with earlier versions. |
| 682 | * if gap is set, need to assume 100% probability |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 683 | */ |
Stephen Hemminger | a362e0a | 2007-03-22 12:15:45 -0700 | [diff] [blame] | 684 | if (q->gap) |
| 685 | q->reorder = ~0; |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 686 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 687 | if (tb[TCA_NETEM_CORR]) |
| 688 | get_correlation(sch, tb[TCA_NETEM_CORR]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Patrick McHardy | b03f467 | 2008-01-23 20:32:21 -0800 | [diff] [blame] | 690 | if (tb[TCA_NETEM_DELAY_DIST]) { |
| 691 | ret = get_dist_table(sch, tb[TCA_NETEM_DELAY_DIST]); |
| 692 | if (ret) |
| 693 | return ret; |
| 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 696 | if (tb[TCA_NETEM_REORDER]) |
| 697 | get_reorder(sch, tb[TCA_NETEM_REORDER]); |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 698 | |
Stephen Hemminger | 265eb67 | 2008-11-03 21:13:26 -0800 | [diff] [blame] | 699 | if (tb[TCA_NETEM_CORRUPT]) |
| 700 | get_corrupt(sch, tb[TCA_NETEM_CORRUPT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 702 | if (tb[TCA_NETEM_RATE]) |
| 703 | get_rate(sch, tb[TCA_NETEM_RATE]); |
| 704 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 705 | q->loss_model = CLG_RANDOM; |
| 706 | if (tb[TCA_NETEM_LOSS]) |
| 707 | ret = get_loss_clg(sch, tb[TCA_NETEM_LOSS]); |
| 708 | |
| 709 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 712 | /* |
| 713 | * Special case version of FIFO queue for use by netem. |
| 714 | * It queues in order based on timestamps in skb's |
| 715 | */ |
| 716 | struct fifo_sched_data { |
| 717 | u32 limit; |
Stephen Hemminger | 075aa57 | 2007-03-22 12:17:05 -0700 | [diff] [blame] | 718 | psched_time_t oldest; |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 719 | }; |
| 720 | |
| 721 | static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch) |
| 722 | { |
| 723 | struct fifo_sched_data *q = qdisc_priv(sch); |
| 724 | struct sk_buff_head *list = &sch->q; |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 725 | psched_time_t tnext = netem_skb_cb(nskb)->time_to_send; |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 726 | struct sk_buff *skb; |
| 727 | |
| 728 | if (likely(skb_queue_len(list) < q->limit)) { |
Stephen Hemminger | 075aa57 | 2007-03-22 12:17:05 -0700 | [diff] [blame] | 729 | /* Optimize for add at tail */ |
Patrick McHardy | 104e087 | 2007-03-23 11:28:07 -0700 | [diff] [blame] | 730 | if (likely(skb_queue_empty(list) || tnext >= q->oldest)) { |
Stephen Hemminger | 075aa57 | 2007-03-22 12:17:05 -0700 | [diff] [blame] | 731 | q->oldest = tnext; |
| 732 | return qdisc_enqueue_tail(nskb, sch); |
| 733 | } |
| 734 | |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 735 | skb_queue_reverse_walk(list, skb) { |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame] | 736 | const struct netem_skb_cb *cb = netem_skb_cb(skb); |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 737 | |
Patrick McHardy | 104e087 | 2007-03-23 11:28:07 -0700 | [diff] [blame] | 738 | if (tnext >= cb->time_to_send) |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | |
| 742 | __skb_queue_after(list, skb, nskb); |
| 743 | |
Jussi Kivilinna | 0abf77e | 2008-07-20 00:08:27 -0700 | [diff] [blame] | 744 | sch->qstats.backlog += qdisc_pkt_len(nskb); |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 745 | |
| 746 | return NET_XMIT_SUCCESS; |
| 747 | } |
| 748 | |
Stephen Hemminger | 075aa57 | 2007-03-22 12:17:05 -0700 | [diff] [blame] | 749 | return qdisc_reshape_fail(nskb, sch); |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 752 | static int tfifo_init(struct Qdisc *sch, struct nlattr *opt) |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 753 | { |
| 754 | struct fifo_sched_data *q = qdisc_priv(sch); |
| 755 | |
| 756 | if (opt) { |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 757 | struct tc_fifo_qopt *ctl = nla_data(opt); |
| 758 | if (nla_len(opt) < sizeof(*ctl)) |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 759 | return -EINVAL; |
| 760 | |
| 761 | q->limit = ctl->limit; |
| 762 | } else |
David S. Miller | 5ce2d48 | 2008-07-08 17:06:30 -0700 | [diff] [blame] | 763 | q->limit = max_t(u32, qdisc_dev(sch)->tx_queue_len, 1); |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 764 | |
Patrick McHardy | a084980 | 2007-03-23 11:28:30 -0700 | [diff] [blame] | 765 | q->oldest = PSCHED_PASTPERFECT; |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static int tfifo_dump(struct Qdisc *sch, struct sk_buff *skb) |
| 770 | { |
| 771 | struct fifo_sched_data *q = qdisc_priv(sch); |
| 772 | struct tc_fifo_qopt opt = { .limit = q->limit }; |
| 773 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 774 | NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 775 | return skb->len; |
| 776 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 777 | nla_put_failure: |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 778 | return -1; |
| 779 | } |
| 780 | |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 781 | static struct Qdisc_ops tfifo_qdisc_ops __read_mostly = { |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 782 | .id = "tfifo", |
| 783 | .priv_size = sizeof(struct fifo_sched_data), |
| 784 | .enqueue = tfifo_enqueue, |
| 785 | .dequeue = qdisc_dequeue_head, |
Jarek Poplawski | 8e3af97 | 2008-10-31 00:45:55 -0700 | [diff] [blame] | 786 | .peek = qdisc_peek_head, |
Stephen Hemminger | 300ce17 | 2005-10-30 13:47:34 -0800 | [diff] [blame] | 787 | .drop = qdisc_queue_drop, |
| 788 | .init = tfifo_init, |
| 789 | .reset = qdisc_reset_queue, |
| 790 | .change = tfifo_init, |
| 791 | .dump = tfifo_dump, |
| 792 | }; |
| 793 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 794 | static int netem_init(struct Qdisc *sch, struct nlattr *opt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
| 796 | struct netem_sched_data *q = qdisc_priv(sch); |
| 797 | int ret; |
| 798 | |
| 799 | if (!opt) |
| 800 | return -EINVAL; |
| 801 | |
Patrick McHardy | 59cb5c6 | 2007-03-16 01:20:31 -0700 | [diff] [blame] | 802 | qdisc_watchdog_init(&q->watchdog, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 804 | q->loss_model = CLG_RANDOM; |
Changli Gao | 3511c91 | 2010-10-16 13:04:08 +0000 | [diff] [blame] | 805 | q->qdisc = qdisc_create_dflt(sch->dev_queue, &tfifo_qdisc_ops, |
Patrick McHardy | 9f9afec | 2006-11-29 17:35:18 -0800 | [diff] [blame] | 806 | TC_H_MAKE(sch->handle, 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | if (!q->qdisc) { |
stephen hemminger | 250a65f | 2011-02-23 13:04:22 +0000 | [diff] [blame] | 808 | pr_notice("netem: qdisc create tfifo qdisc failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | return -ENOMEM; |
| 810 | } |
| 811 | |
| 812 | ret = netem_change(sch, opt); |
| 813 | if (ret) { |
stephen hemminger | 250a65f | 2011-02-23 13:04:22 +0000 | [diff] [blame] | 814 | pr_info("netem: change failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | qdisc_destroy(q->qdisc); |
| 816 | } |
| 817 | return ret; |
| 818 | } |
| 819 | |
| 820 | static void netem_destroy(struct Qdisc *sch) |
| 821 | { |
| 822 | struct netem_sched_data *q = qdisc_priv(sch); |
| 823 | |
Patrick McHardy | 59cb5c6 | 2007-03-16 01:20:31 -0700 | [diff] [blame] | 824 | qdisc_watchdog_cancel(&q->watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | qdisc_destroy(q->qdisc); |
stephen hemminger | 6373a9a | 2011-02-23 13:04:18 +0000 | [diff] [blame] | 826 | dist_free(q->delay_dist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 829 | static int dump_loss_model(const struct netem_sched_data *q, |
| 830 | struct sk_buff *skb) |
| 831 | { |
| 832 | struct nlattr *nest; |
| 833 | |
| 834 | nest = nla_nest_start(skb, TCA_NETEM_LOSS); |
| 835 | if (nest == NULL) |
| 836 | goto nla_put_failure; |
| 837 | |
| 838 | switch (q->loss_model) { |
| 839 | case CLG_RANDOM: |
| 840 | /* legacy loss model */ |
| 841 | nla_nest_cancel(skb, nest); |
| 842 | return 0; /* no data */ |
| 843 | |
| 844 | case CLG_4_STATES: { |
| 845 | struct tc_netem_gimodel gi = { |
| 846 | .p13 = q->clg.a1, |
| 847 | .p31 = q->clg.a2, |
| 848 | .p32 = q->clg.a3, |
| 849 | .p14 = q->clg.a4, |
| 850 | .p23 = q->clg.a5, |
| 851 | }; |
| 852 | |
| 853 | NLA_PUT(skb, NETEM_LOSS_GI, sizeof(gi), &gi); |
| 854 | break; |
| 855 | } |
| 856 | case CLG_GILB_ELL: { |
| 857 | struct tc_netem_gemodel ge = { |
| 858 | .p = q->clg.a1, |
| 859 | .r = q->clg.a2, |
| 860 | .h = q->clg.a3, |
| 861 | .k1 = q->clg.a4, |
| 862 | }; |
| 863 | |
| 864 | NLA_PUT(skb, NETEM_LOSS_GE, sizeof(ge), &ge); |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | nla_nest_end(skb, nest); |
| 870 | return 0; |
| 871 | |
| 872 | nla_put_failure: |
| 873 | nla_nest_cancel(skb, nest); |
| 874 | return -1; |
| 875 | } |
| 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) |
| 878 | { |
| 879 | const struct netem_sched_data *q = qdisc_priv(sch); |
stephen hemminger | 861d7f7 | 2011-02-23 13:04:17 +0000 | [diff] [blame] | 880 | struct nlattr *nla = (struct nlattr *) skb_tail_pointer(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | struct tc_netem_qopt qopt; |
| 882 | struct tc_netem_corr cor; |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 883 | struct tc_netem_reorder reorder; |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 884 | struct tc_netem_corrupt corrupt; |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 885 | struct tc_netem_rate rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | qopt.latency = q->latency; |
| 888 | qopt.jitter = q->jitter; |
| 889 | qopt.limit = q->limit; |
| 890 | qopt.loss = q->loss; |
| 891 | qopt.gap = q->gap; |
| 892 | qopt.duplicate = q->duplicate; |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 893 | NLA_PUT(skb, TCA_OPTIONS, sizeof(qopt), &qopt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | cor.delay_corr = q->delay_cor.rho; |
| 896 | cor.loss_corr = q->loss_cor.rho; |
| 897 | cor.dup_corr = q->dup_cor.rho; |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 898 | NLA_PUT(skb, TCA_NETEM_CORR, sizeof(cor), &cor); |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 899 | |
| 900 | reorder.probability = q->reorder; |
| 901 | reorder.correlation = q->reorder_cor.rho; |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 902 | NLA_PUT(skb, TCA_NETEM_REORDER, sizeof(reorder), &reorder); |
Stephen Hemminger | 0dca51d | 2005-05-26 12:55:48 -0700 | [diff] [blame] | 903 | |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 904 | corrupt.probability = q->corrupt; |
| 905 | corrupt.correlation = q->corrupt_cor.rho; |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 906 | NLA_PUT(skb, TCA_NETEM_CORRUPT, sizeof(corrupt), &corrupt); |
Stephen Hemminger | c865e5d | 2005-12-21 19:03:44 -0800 | [diff] [blame] | 907 | |
Hagen Paul Pfeifer | 7bc0f28 | 2011-11-30 12:20:26 +0000 | [diff] [blame^] | 908 | rate.rate = q->rate; |
| 909 | NLA_PUT(skb, TCA_NETEM_RATE, sizeof(rate), &rate); |
| 910 | |
stephen hemminger | 661b797 | 2011-02-23 13:04:21 +0000 | [diff] [blame] | 911 | if (dump_loss_model(q, skb) != 0) |
| 912 | goto nla_put_failure; |
| 913 | |
stephen hemminger | 861d7f7 | 2011-02-23 13:04:17 +0000 | [diff] [blame] | 914 | return nla_nest_end(skb, nla); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 916 | nla_put_failure: |
stephen hemminger | 861d7f7 | 2011-02-23 13:04:17 +0000 | [diff] [blame] | 917 | nlmsg_trim(skb, nla); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | return -1; |
| 919 | } |
| 920 | |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 921 | static int netem_dump_class(struct Qdisc *sch, unsigned long cl, |
| 922 | struct sk_buff *skb, struct tcmsg *tcm) |
| 923 | { |
| 924 | struct netem_sched_data *q = qdisc_priv(sch); |
| 925 | |
| 926 | if (cl != 1) /* only one class */ |
| 927 | return -ENOENT; |
| 928 | |
| 929 | tcm->tcm_handle |= TC_H_MIN(1); |
| 930 | tcm->tcm_info = q->qdisc->handle; |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | static int netem_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, |
| 936 | struct Qdisc **old) |
| 937 | { |
| 938 | struct netem_sched_data *q = qdisc_priv(sch); |
| 939 | |
| 940 | if (new == NULL) |
| 941 | new = &noop_qdisc; |
| 942 | |
| 943 | sch_tree_lock(sch); |
| 944 | *old = q->qdisc; |
| 945 | q->qdisc = new; |
| 946 | qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); |
| 947 | qdisc_reset(*old); |
| 948 | sch_tree_unlock(sch); |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | static struct Qdisc *netem_leaf(struct Qdisc *sch, unsigned long arg) |
| 954 | { |
| 955 | struct netem_sched_data *q = qdisc_priv(sch); |
| 956 | return q->qdisc; |
| 957 | } |
| 958 | |
| 959 | static unsigned long netem_get(struct Qdisc *sch, u32 classid) |
| 960 | { |
| 961 | return 1; |
| 962 | } |
| 963 | |
| 964 | static void netem_put(struct Qdisc *sch, unsigned long arg) |
| 965 | { |
| 966 | } |
| 967 | |
| 968 | static void netem_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
| 969 | { |
| 970 | if (!walker->stop) { |
| 971 | if (walker->count >= walker->skip) |
| 972 | if (walker->fn(sch, 1, walker) < 0) { |
| 973 | walker->stop = 1; |
| 974 | return; |
| 975 | } |
| 976 | walker->count++; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | static const struct Qdisc_class_ops netem_class_ops = { |
| 981 | .graft = netem_graft, |
| 982 | .leaf = netem_leaf, |
| 983 | .get = netem_get, |
| 984 | .put = netem_put, |
| 985 | .walk = netem_walk, |
| 986 | .dump = netem_dump_class, |
| 987 | }; |
| 988 | |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 989 | static struct Qdisc_ops netem_qdisc_ops __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | .id = "netem", |
stephen hemminger | 10f6dfc | 2011-02-23 13:04:20 +0000 | [diff] [blame] | 991 | .cl_ops = &netem_class_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | .priv_size = sizeof(struct netem_sched_data), |
| 993 | .enqueue = netem_enqueue, |
| 994 | .dequeue = netem_dequeue, |
Jarek Poplawski | 77be155 | 2008-10-31 00:47:01 -0700 | [diff] [blame] | 995 | .peek = qdisc_peek_dequeued, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | .drop = netem_drop, |
| 997 | .init = netem_init, |
| 998 | .reset = netem_reset, |
| 999 | .destroy = netem_destroy, |
| 1000 | .change = netem_change, |
| 1001 | .dump = netem_dump, |
| 1002 | .owner = THIS_MODULE, |
| 1003 | }; |
| 1004 | |
| 1005 | |
| 1006 | static int __init netem_module_init(void) |
| 1007 | { |
Stephen Hemminger | eb229c4 | 2005-11-03 13:49:01 -0800 | [diff] [blame] | 1008 | pr_info("netem: version " VERSION "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return register_qdisc(&netem_qdisc_ops); |
| 1010 | } |
| 1011 | static void __exit netem_module_exit(void) |
| 1012 | { |
| 1013 | unregister_qdisc(&netem_qdisc_ops); |
| 1014 | } |
| 1015 | module_init(netem_module_init) |
| 1016 | module_exit(netem_module_exit) |
| 1017 | MODULE_LICENSE("GPL"); |