sch_sfb.c 17 KB

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