sch_sfb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * net/sched/sch_sfb.c Stochastic Fair Blue
  3. *
  4. * Copyright (c) 2008-2011 Juliusz Chroboczek <jch@pps.jussieu.fr>
  5. * Copyright (c) 2011 Eric Dumazet <eric.dumazet@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * W. Feng, D. Kandlur, D. Saha, K. Shin. Blue:
  12. * A New Class of Active Queue Management Algorithms.
  13. * U. Michigan CSE-TR-387-99, April 1999.
  14. *
  15. * http://www.thefengs.com/wuchang/blue/CSE-TR-387-99.pdf
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/random.h>
  24. #include <linux/jhash.h>
  25. #include <net/ip.h>
  26. #include <net/pkt_sched.h>
  27. #include <net/inet_ecn.h>
  28. #include <net/flow_keys.h>
  29. /*
  30. * SFB uses two B[l][n] : L x N arrays of bins (L levels, N bins per level)
  31. * This implementation uses L = 8 and N = 16
  32. * This permits us to split one 32bit hash (provided per packet by rxhash or
  33. * external classifier) into 8 subhashes of 4 bits.
  34. */
  35. #define SFB_BUCKET_SHIFT 4
  36. #define SFB_NUMBUCKETS (1 << SFB_BUCKET_SHIFT) /* N bins per Level */
  37. #define SFB_BUCKET_MASK (SFB_NUMBUCKETS - 1)
  38. #define SFB_LEVELS (32 / SFB_BUCKET_SHIFT) /* L */
  39. /* SFB algo uses a virtual queue, named "bin" */
  40. struct sfb_bucket {
  41. u16 qlen; /* length of virtual queue */
  42. u16 p_mark; /* marking probability */
  43. };
  44. /* We use a double buffering right before hash change
  45. * (Section 4.4 of SFB reference : moving hash functions)
  46. */
  47. struct sfb_bins {
  48. u32 perturbation; /* jhash perturbation */
  49. struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS];
  50. };
  51. struct sfb_sched_data {
  52. struct Qdisc *qdisc;
  53. struct tcf_proto *filter_list;
  54. unsigned long rehash_interval;
  55. unsigned long warmup_time; /* double buffering warmup time in jiffies */
  56. u32 max;
  57. u32 bin_size; /* maximum queue length per bin */
  58. u32 increment; /* d1 */
  59. u32 decrement; /* d2 */
  60. u32 limit; /* HARD maximal queue length */
  61. u32 penalty_rate;
  62. u32 penalty_burst;
  63. u32 tokens_avail;
  64. unsigned long rehash_time;
  65. unsigned long token_time;
  66. u8 slot; /* current active bins (0 or 1) */
  67. bool double_buffering;
  68. struct sfb_bins bins[2];
  69. struct {
  70. u32 earlydrop;
  71. u32 penaltydrop;
  72. u32 bucketdrop;
  73. u32 queuedrop;
  74. u32 childdrop; /* drops in child qdisc */
  75. u32 marked; /* ECN mark */
  76. } stats;
  77. };
  78. /*
  79. * Each queued skb might be hashed on one or two bins
  80. * We store in skb_cb the two hash values.
  81. * (A zero value means double buffering was not used)
  82. */
  83. struct sfb_skb_cb {
  84. u32 hashes[2];
  85. };
  86. static inline struct sfb_skb_cb *sfb_skb_cb(const struct sk_buff *skb)
  87. {
  88. qdisc_cb_private_validate(skb, sizeof(struct sfb_skb_cb));
  89. return (struct sfb_skb_cb *)qdisc_skb_cb(skb)->data;
  90. }
  91. /*
  92. * If using 'internal' SFB flow classifier, hash comes from skb rxhash
  93. * If using external classifier, hash comes from the classid.
  94. */
  95. static u32 sfb_hash(const struct sk_buff *skb, u32 slot)
  96. {
  97. return sfb_skb_cb(skb)->hashes[slot];
  98. }
  99. /* Probabilities are coded as Q0.16 fixed-point values,
  100. * with 0xFFFF representing 65535/65536 (almost 1.0)
  101. * Addition and subtraction are saturating in [0, 65535]
  102. */
  103. static u32 prob_plus(u32 p1, u32 p2)
  104. {
  105. u32 res = p1 + p2;
  106. return min_t(u32, res, SFB_MAX_PROB);
  107. }
  108. static u32 prob_minus(u32 p1, u32 p2)
  109. {
  110. return p1 > p2 ? p1 - p2 : 0;
  111. }
  112. static void increment_one_qlen(u32 sfbhash, u32 slot, struct sfb_sched_data *q)
  113. {
  114. int i;
  115. struct sfb_bucket *b = &q->bins[slot].bins[0][0];
  116. for (i = 0; i < SFB_LEVELS; i++) {
  117. u32 hash = sfbhash & SFB_BUCKET_MASK;
  118. sfbhash >>= SFB_BUCKET_SHIFT;
  119. if (b[hash].qlen < 0xFFFF)
  120. b[hash].qlen++;
  121. b += SFB_NUMBUCKETS; /* next level */
  122. }
  123. }
  124. static void increment_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)
  125. {
  126. u32 sfbhash;
  127. sfbhash = sfb_hash(skb, 0);
  128. if (sfbhash)
  129. increment_one_qlen(sfbhash, 0, q);
  130. sfbhash = sfb_hash(skb, 1);
  131. if (sfbhash)
  132. increment_one_qlen(sfbhash, 1, q);
  133. }
  134. static void decrement_one_qlen(u32 sfbhash, u32 slot,
  135. struct sfb_sched_data *q)
  136. {
  137. int i;
  138. struct sfb_bucket *b = &q->bins[slot].bins[0][0];
  139. for (i = 0; i < SFB_LEVELS; i++) {
  140. u32 hash = sfbhash & SFB_BUCKET_MASK;
  141. sfbhash >>= SFB_BUCKET_SHIFT;
  142. if (b[hash].qlen > 0)
  143. b[hash].qlen--;
  144. b += SFB_NUMBUCKETS; /* next level */
  145. }
  146. }
  147. static void decrement_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)
  148. {
  149. u32 sfbhash;
  150. sfbhash = sfb_hash(skb, 0);
  151. if (sfbhash)
  152. decrement_one_qlen(sfbhash, 0, q);
  153. sfbhash = sfb_hash(skb, 1);
  154. if (sfbhash)
  155. decrement_one_qlen(sfbhash, 1, q);
  156. }
  157. static void decrement_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
  158. {
  159. b->p_mark = prob_minus(b->p_mark, q->decrement);
  160. }
  161. static void increment_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
  162. {
  163. b->p_mark = prob_plus(b->p_mark, q->increment);
  164. }
  165. static void sfb_zero_all_buckets(struct sfb_sched_data *q)
  166. {
  167. memset(&q->bins, 0, sizeof(q->bins));
  168. }
  169. /*
  170. * compute max qlen, max p_mark, and avg p_mark
  171. */
  172. static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_data *q)
  173. {
  174. int i;
  175. u32 qlen = 0, prob = 0, totalpm = 0;
  176. const struct sfb_bucket *b = &q->bins[q->slot].bins[0][0];
  177. for (i = 0; i < SFB_LEVELS * SFB_NUMBUCKETS; i++) {
  178. if (qlen < b->qlen)
  179. qlen = b->qlen;
  180. totalpm += b->p_mark;
  181. if (prob < b->p_mark)
  182. prob = b->p_mark;
  183. b++;
  184. }
  185. *prob_r = prob;
  186. *avgpm_r = totalpm / (SFB_LEVELS * SFB_NUMBUCKETS);
  187. return qlen;
  188. }
  189. static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
  190. {
  191. q->bins[slot].perturbation = net_random();
  192. }
  193. static void sfb_swap_slot(struct sfb_sched_data *q)
  194. {
  195. sfb_init_perturbation(q->slot, q);
  196. q->slot ^= 1;
  197. q->double_buffering = false;
  198. }
  199. /* Non elastic flows are allowed to use part of the bandwidth, expressed
  200. * in "penalty_rate" packets per second, with "penalty_burst" burst
  201. */
  202. static bool sfb_rate_limit(struct sk_buff *skb, struct sfb_sched_data *q)
  203. {
  204. if (q->penalty_rate == 0 || q->penalty_burst == 0)
  205. return true;
  206. if (q->tokens_avail < 1) {
  207. unsigned long age = min(10UL * HZ, jiffies - q->token_time);
  208. q->tokens_avail = (age * q->penalty_rate) / HZ;
  209. if (q->tokens_avail > q->penalty_burst)
  210. q->tokens_avail = q->penalty_burst;
  211. q->token_time = jiffies;
  212. if (q->tokens_avail < 1)
  213. return true;
  214. }
  215. q->tokens_avail--;
  216. return false;
  217. }
  218. static bool sfb_classify(struct sk_buff *skb, struct sfb_sched_data *q,
  219. int *qerr, u32 *salt)
  220. {
  221. struct tcf_result res;
  222. int result;
  223. result = tc_classify(skb, q->filter_list, &res);
  224. if (result >= 0) {
  225. #ifdef CONFIG_NET_CLS_ACT
  226. switch (result) {
  227. case TC_ACT_STOLEN:
  228. case TC_ACT_QUEUED:
  229. *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
  230. case TC_ACT_SHOT:
  231. return false;
  232. }
  233. #endif
  234. *salt = TC_H_MIN(res.classid);
  235. return true;
  236. }
  237. return false;
  238. }
  239. static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  240. {
  241. struct sfb_sched_data *q = qdisc_priv(sch);
  242. struct Qdisc *child = q->qdisc;
  243. int i;
  244. u32 p_min = ~0;
  245. u32 minqlen = ~0;
  246. u32 r, slot, salt, sfbhash;
  247. int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
  248. struct flow_keys keys;
  249. if (unlikely(sch->q.qlen >= q->limit)) {
  250. sch->qstats.overlimits++;
  251. q->stats.queuedrop++;
  252. goto drop;
  253. }
  254. if (q->rehash_interval > 0) {
  255. unsigned long limit = q->rehash_time + q->rehash_interval;
  256. if (unlikely(time_after(jiffies, limit))) {
  257. sfb_swap_slot(q);
  258. q->rehash_time = jiffies;
  259. } else if (unlikely(!q->double_buffering && q->warmup_time > 0 &&
  260. time_after(jiffies, limit - q->warmup_time))) {
  261. q->double_buffering = true;
  262. }
  263. }
  264. if (q->filter_list) {
  265. /* If using external classifiers, get result and record it. */
  266. if (!sfb_classify(skb, q, &ret, &salt))
  267. goto other_drop;
  268. keys.src = salt;
  269. keys.dst = 0;
  270. keys.ports = 0;
  271. } else {
  272. skb_flow_dissect(skb, &keys);
  273. }
  274. slot = q->slot;
  275. sfbhash = jhash_3words((__force u32)keys.dst,
  276. (__force u32)keys.src,
  277. (__force u32)keys.ports,
  278. q->bins[slot].perturbation);
  279. if (!sfbhash)
  280. sfbhash = 1;
  281. sfb_skb_cb(skb)->hashes[slot] = sfbhash;
  282. for (i = 0; i < SFB_LEVELS; i++) {
  283. u32 hash = sfbhash & SFB_BUCKET_MASK;
  284. struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
  285. sfbhash >>= SFB_BUCKET_SHIFT;
  286. if (b->qlen == 0)
  287. decrement_prob(b, q);
  288. else if (b->qlen >= q->bin_size)
  289. increment_prob(b, q);
  290. if (minqlen > b->qlen)
  291. minqlen = b->qlen;
  292. if (p_min > b->p_mark)
  293. p_min = b->p_mark;
  294. }
  295. slot ^= 1;
  296. sfb_skb_cb(skb)->hashes[slot] = 0;
  297. if (unlikely(minqlen >= q->max)) {
  298. sch->qstats.overlimits++;
  299. q->stats.bucketdrop++;
  300. goto drop;
  301. }
  302. if (unlikely(p_min >= SFB_MAX_PROB)) {
  303. /* Inelastic flow */
  304. if (q->double_buffering) {
  305. sfbhash = jhash_3words((__force u32)keys.dst,
  306. (__force u32)keys.src,
  307. (__force u32)keys.ports,
  308. q->bins[slot].perturbation);
  309. if (!sfbhash)
  310. sfbhash = 1;
  311. sfb_skb_cb(skb)->hashes[slot] = sfbhash;
  312. for (i = 0; i < SFB_LEVELS; i++) {
  313. u32 hash = sfbhash & SFB_BUCKET_MASK;
  314. struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
  315. sfbhash >>= SFB_BUCKET_SHIFT;
  316. if (b->qlen == 0)
  317. decrement_prob(b, q);
  318. else if (b->qlen >= q->bin_size)
  319. increment_prob(b, q);
  320. }
  321. }
  322. if (sfb_rate_limit(skb, q)) {
  323. sch->qstats.overlimits++;
  324. q->stats.penaltydrop++;
  325. goto drop;
  326. }
  327. goto enqueue;
  328. }
  329. r = net_random() & SFB_MAX_PROB;
  330. if (unlikely(r < p_min)) {
  331. if (unlikely(p_min > SFB_MAX_PROB / 2)) {
  332. /* If we're marking that many packets, then either
  333. * this flow is unresponsive, or we're badly congested.
  334. * In either case, we want to start dropping packets.
  335. */
  336. if (r < (p_min - SFB_MAX_PROB / 2) * 2) {
  337. q->stats.earlydrop++;
  338. goto drop;
  339. }
  340. }
  341. if (INET_ECN_set_ce(skb)) {
  342. q->stats.marked++;
  343. } else {
  344. q->stats.earlydrop++;
  345. goto drop;
  346. }
  347. }
  348. enqueue:
  349. ret = qdisc_enqueue(skb, child);
  350. if (likely(ret == NET_XMIT_SUCCESS)) {
  351. sch->q.qlen++;
  352. increment_qlen(skb, q);
  353. } else if (net_xmit_drop_count(ret)) {
  354. q->stats.childdrop++;
  355. sch->qstats.drops++;
  356. }
  357. return ret;
  358. drop:
  359. qdisc_drop(skb, sch);
  360. return NET_XMIT_CN;
  361. other_drop:
  362. if (ret & __NET_XMIT_BYPASS)
  363. sch->qstats.drops++;
  364. kfree_skb(skb);
  365. return ret;
  366. }
  367. static struct sk_buff *sfb_dequeue(struct Qdisc *sch)
  368. {
  369. struct sfb_sched_data *q = qdisc_priv(sch);
  370. struct Qdisc *child = q->qdisc;
  371. struct sk_buff *skb;
  372. skb = child->dequeue(q->qdisc);
  373. if (skb) {
  374. qdisc_bstats_update(sch, skb);
  375. sch->q.qlen--;
  376. decrement_qlen(skb, q);
  377. }
  378. return skb;
  379. }
  380. static struct sk_buff *sfb_peek(struct Qdisc *sch)
  381. {
  382. struct sfb_sched_data *q = qdisc_priv(sch);
  383. struct Qdisc *child = q->qdisc;
  384. return child->ops->peek(child);
  385. }
  386. /* No sfb_drop -- impossible since the child doesn't return the dropped skb. */
  387. static void sfb_reset(struct Qdisc *sch)
  388. {
  389. struct sfb_sched_data *q = qdisc_priv(sch);
  390. qdisc_reset(q->qdisc);
  391. sch->q.qlen = 0;
  392. q->slot = 0;
  393. q->double_buffering = false;
  394. sfb_zero_all_buckets(q);
  395. sfb_init_perturbation(0, q);
  396. }
  397. static void sfb_destroy(struct Qdisc *sch)
  398. {
  399. struct sfb_sched_data *q = qdisc_priv(sch);
  400. tcf_destroy_chain(&q->filter_list);
  401. qdisc_destroy(q->qdisc);
  402. }
  403. static const struct nla_policy sfb_policy[TCA_SFB_MAX + 1] = {
  404. [TCA_SFB_PARMS] = { .len = sizeof(struct tc_sfb_qopt) },
  405. };
  406. static const struct tc_sfb_qopt sfb_default_ops = {
  407. .rehash_interval = 600 * MSEC_PER_SEC,
  408. .warmup_time = 60 * MSEC_PER_SEC,
  409. .limit = 0,
  410. .max = 25,
  411. .bin_size = 20,
  412. .increment = (SFB_MAX_PROB + 500) / 1000, /* 0.1 % */
  413. .decrement = (SFB_MAX_PROB + 3000) / 6000,
  414. .penalty_rate = 10,
  415. .penalty_burst = 20,
  416. };
  417. static int sfb_change(struct Qdisc *sch, struct nlattr *opt)
  418. {
  419. struct sfb_sched_data *q = qdisc_priv(sch);
  420. struct Qdisc *child;
  421. struct nlattr *tb[TCA_SFB_MAX + 1];
  422. const struct tc_sfb_qopt *ctl = &sfb_default_ops;
  423. u32 limit;
  424. int err;
  425. if (opt) {
  426. err = nla_parse_nested(tb, TCA_SFB_MAX, opt, sfb_policy);
  427. if (err < 0)
  428. return -EINVAL;
  429. if (tb[TCA_SFB_PARMS] == NULL)
  430. return -EINVAL;
  431. ctl = nla_data(tb[TCA_SFB_PARMS]);
  432. }
  433. limit = ctl->limit;
  434. if (limit == 0)
  435. limit = max_t(u32, qdisc_dev(sch)->tx_queue_len, 1);
  436. child = fifo_create_dflt(sch, &pfifo_qdisc_ops, limit);
  437. if (IS_ERR(child))
  438. return PTR_ERR(child);
  439. sch_tree_lock(sch);
  440. qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
  441. qdisc_destroy(q->qdisc);
  442. q->qdisc = child;
  443. q->rehash_interval = msecs_to_jiffies(ctl->rehash_interval);
  444. q->warmup_time = msecs_to_jiffies(ctl->warmup_time);
  445. q->rehash_time = jiffies;
  446. q->limit = limit;
  447. q->increment = ctl->increment;
  448. q->decrement = ctl->decrement;
  449. q->max = ctl->max;
  450. q->bin_size = ctl->bin_size;
  451. q->penalty_rate = ctl->penalty_rate;
  452. q->penalty_burst = ctl->penalty_burst;
  453. q->tokens_avail = ctl->penalty_burst;
  454. q->token_time = jiffies;
  455. q->slot = 0;
  456. q->double_buffering = false;
  457. sfb_zero_all_buckets(q);
  458. sfb_init_perturbation(0, q);
  459. sfb_init_perturbation(1, q);
  460. sch_tree_unlock(sch);
  461. return 0;
  462. }
  463. static int sfb_init(struct Qdisc *sch, struct nlattr *opt)
  464. {
  465. struct sfb_sched_data *q = qdisc_priv(sch);
  466. q->qdisc = &noop_qdisc;
  467. return sfb_change(sch, opt);
  468. }
  469. static int sfb_dump(struct Qdisc *sch, struct sk_buff *skb)
  470. {
  471. struct sfb_sched_data *q = qdisc_priv(sch);
  472. struct nlattr *opts;
  473. struct tc_sfb_qopt opt = {
  474. .rehash_interval = jiffies_to_msecs(q->rehash_interval),
  475. .warmup_time = jiffies_to_msecs(q->warmup_time),
  476. .limit = q->limit,
  477. .max = q->max,
  478. .bin_size = q->bin_size,
  479. .increment = q->increment,
  480. .decrement = q->decrement,
  481. .penalty_rate = q->penalty_rate,
  482. .penalty_burst = q->penalty_burst,
  483. };
  484. sch->qstats.backlog = q->qdisc->qstats.backlog;
  485. opts = nla_nest_start(skb, TCA_OPTIONS);
  486. if (opts == NULL)
  487. goto nla_put_failure;
  488. NLA_PUT(skb, TCA_SFB_PARMS, sizeof(opt), &opt);
  489. return nla_nest_end(skb, opts);
  490. nla_put_failure:
  491. nla_nest_cancel(skb, opts);
  492. return -EMSGSIZE;
  493. }
  494. static int sfb_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
  495. {
  496. struct sfb_sched_data *q = qdisc_priv(sch);
  497. struct tc_sfb_xstats st = {
  498. .earlydrop = q->stats.earlydrop,
  499. .penaltydrop = q->stats.penaltydrop,
  500. .bucketdrop = q->stats.bucketdrop,
  501. .queuedrop = q->stats.queuedrop,
  502. .childdrop = q->stats.childdrop,
  503. .marked = q->stats.marked,
  504. };
  505. st.maxqlen = sfb_compute_qlen(&st.maxprob, &st.avgprob, q);
  506. return gnet_stats_copy_app(d, &st, sizeof(st));
  507. }
  508. static int sfb_dump_class(struct Qdisc *sch, unsigned long cl,
  509. struct sk_buff *skb, struct tcmsg *tcm)
  510. {
  511. return -ENOSYS;
  512. }
  513. static int sfb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
  514. struct Qdisc **old)
  515. {
  516. struct sfb_sched_data *q = qdisc_priv(sch);
  517. if (new == NULL)
  518. new = &noop_qdisc;
  519. sch_tree_lock(sch);
  520. *old = q->qdisc;
  521. q->qdisc = new;
  522. qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
  523. qdisc_reset(*old);
  524. sch_tree_unlock(sch);
  525. return 0;
  526. }
  527. static struct Qdisc *sfb_leaf(struct Qdisc *sch, unsigned long arg)
  528. {
  529. struct sfb_sched_data *q = qdisc_priv(sch);
  530. return q->qdisc;
  531. }
  532. static unsigned long sfb_get(struct Qdisc *sch, u32 classid)
  533. {
  534. return 1;
  535. }
  536. static void sfb_put(struct Qdisc *sch, unsigned long arg)
  537. {
  538. }
  539. static int sfb_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
  540. struct nlattr **tca, unsigned long *arg)
  541. {
  542. return -ENOSYS;
  543. }
  544. static int sfb_delete(struct Qdisc *sch, unsigned long cl)
  545. {
  546. return -ENOSYS;
  547. }
  548. static void sfb_walk(struct Qdisc *sch, struct qdisc_walker *walker)
  549. {
  550. if (!walker->stop) {
  551. if (walker->count >= walker->skip)
  552. if (walker->fn(sch, 1, walker) < 0) {
  553. walker->stop = 1;
  554. return;
  555. }
  556. walker->count++;
  557. }
  558. }
  559. static struct tcf_proto **sfb_find_tcf(struct Qdisc *sch, unsigned long cl)
  560. {
  561. struct sfb_sched_data *q = qdisc_priv(sch);
  562. if (cl)
  563. return NULL;
  564. return &q->filter_list;
  565. }
  566. static unsigned long sfb_bind(struct Qdisc *sch, unsigned long parent,
  567. u32 classid)
  568. {
  569. return 0;
  570. }
  571. static const struct Qdisc_class_ops sfb_class_ops = {
  572. .graft = sfb_graft,
  573. .leaf = sfb_leaf,
  574. .get = sfb_get,
  575. .put = sfb_put,
  576. .change = sfb_change_class,
  577. .delete = sfb_delete,
  578. .walk = sfb_walk,
  579. .tcf_chain = sfb_find_tcf,
  580. .bind_tcf = sfb_bind,
  581. .unbind_tcf = sfb_put,
  582. .dump = sfb_dump_class,
  583. };
  584. static struct Qdisc_ops sfb_qdisc_ops __read_mostly = {
  585. .id = "sfb",
  586. .priv_size = sizeof(struct sfb_sched_data),
  587. .cl_ops = &sfb_class_ops,
  588. .enqueue = sfb_enqueue,
  589. .dequeue = sfb_dequeue,
  590. .peek = sfb_peek,
  591. .init = sfb_init,
  592. .reset = sfb_reset,
  593. .destroy = sfb_destroy,
  594. .change = sfb_change,
  595. .dump = sfb_dump,
  596. .dump_stats = sfb_dump_stats,
  597. .owner = THIS_MODULE,
  598. };
  599. static int __init sfb_module_init(void)
  600. {
  601. return register_qdisc(&sfb_qdisc_ops);
  602. }
  603. static void __exit sfb_module_exit(void)
  604. {
  605. unregister_qdisc(&sfb_qdisc_ops);
  606. }
  607. module_init(sfb_module_init)
  608. module_exit(sfb_module_exit)
  609. MODULE_DESCRIPTION("Stochastic Fair Blue queue discipline");
  610. MODULE_AUTHOR("Juliusz Chroboczek");
  611. MODULE_AUTHOR("Eric Dumazet");
  612. MODULE_LICENSE("GPL");