libnl  3.3.0
htb.c
1 /*
2  * lib/route/qdisc/htb.c HTB Qdisc
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
10  * Copyright (c) 2005-2006 Petr Gotthard <petr.gotthard@siemens.com>
11  * Copyright (c) 2005-2006 Siemens AG Oesterreich
12  */
13 
14 /**
15  * @ingroup qdisc
16  * @ingroup class
17  * @defgroup qdisc_htb Hierachical Token Bucket (HTB)
18  * @{
19  */
20 
21 #include <netlink-private/netlink.h>
22 #include <netlink-private/tc.h>
23 #include <netlink/netlink.h>
24 #include <netlink/cache.h>
25 #include <netlink/utils.h>
26 #include <netlink-private/route/tc-api.h>
27 #include <netlink/route/qdisc.h>
28 #include <netlink/route/class.h>
29 #include <netlink/route/link.h>
30 #include <netlink/route/qdisc/htb.h>
31 
32 /** @cond SKIP */
33 #define SCH_HTB_HAS_RATE2QUANTUM 0x01
34 #define SCH_HTB_HAS_DEFCLS 0x02
35 
36 #define SCH_HTB_HAS_PRIO 0x001
37 #define SCH_HTB_HAS_RATE 0x002
38 #define SCH_HTB_HAS_CEIL 0x004
39 #define SCH_HTB_HAS_RBUFFER 0x008
40 #define SCH_HTB_HAS_CBUFFER 0x010
41 #define SCH_HTB_HAS_QUANTUM 0x020
42 #define SCH_HTB_HAS_LEVEL 0x040
43 /** @endcond */
44 
45 static struct nla_policy htb_policy[TCA_HTB_MAX+1] = {
46  [TCA_HTB_INIT] = { .minlen = sizeof(struct tc_htb_glob) },
47  [TCA_HTB_PARMS] = { .minlen = sizeof(struct tc_htb_opt) },
48 };
49 
50 static int htb_qdisc_msg_parser(struct rtnl_tc *tc, void *data)
51 {
52  struct nlattr *tb[TCA_HTB_MAX + 1];
53  struct rtnl_htb_qdisc *htb = data;
54  int err;
55 
56  if ((err = tca_parse(tb, TCA_HTB_MAX, tc, htb_policy)) < 0)
57  return err;
58 
59  if (tb[TCA_HTB_INIT]) {
60  struct tc_htb_glob opts;
61 
62  nla_memcpy(&opts, tb[TCA_HTB_INIT], sizeof(opts));
63  htb->qh_rate2quantum = opts.rate2quantum;
64  htb->qh_defcls = opts.defcls;
65  htb->qh_direct_pkts = opts.direct_pkts;
66 
67  htb->qh_mask = (SCH_HTB_HAS_RATE2QUANTUM | SCH_HTB_HAS_DEFCLS);
68  }
69 
70  return 0;
71 }
72 
73 static int htb_class_msg_parser(struct rtnl_tc *tc, void *data)
74 {
75  struct nlattr *tb[TCA_HTB_MAX + 1];
76  struct rtnl_htb_class *htb = data;
77  int err;
78 
79  if ((err = tca_parse(tb, TCA_HTB_MAX, tc, htb_policy)) < 0)
80  return err;
81 
82  if (tb[TCA_HTB_PARMS]) {
83  struct tc_htb_opt opts;
84 
85  nla_memcpy(&opts, tb[TCA_HTB_PARMS], sizeof(opts));
86  htb->ch_prio = opts.prio;
87  rtnl_copy_ratespec(&htb->ch_rate, &opts.rate);
88  rtnl_copy_ratespec(&htb->ch_ceil, &opts.ceil);
89  htb->ch_rbuffer = rtnl_tc_calc_bufsize(nl_ticks2us(opts.buffer),
90  opts.rate.rate);
91  htb->ch_cbuffer = rtnl_tc_calc_bufsize(nl_ticks2us(opts.cbuffer),
92  opts.ceil.rate);
93  htb->ch_quantum = opts.quantum;
94  htb->ch_level = opts.level;
95 
96  rtnl_tc_set_mpu(tc, htb->ch_rate.rs_mpu);
97  rtnl_tc_set_overhead(tc, htb->ch_rate.rs_overhead);
98 
99  htb->ch_mask = (SCH_HTB_HAS_PRIO | SCH_HTB_HAS_RATE |
100  SCH_HTB_HAS_CEIL | SCH_HTB_HAS_RBUFFER |
101  SCH_HTB_HAS_CBUFFER | SCH_HTB_HAS_QUANTUM |
102  SCH_HTB_HAS_LEVEL);
103  }
104 
105  return 0;
106 }
107 
108 static void htb_qdisc_dump_line(struct rtnl_tc *tc, void *data,
109  struct nl_dump_params *p)
110 {
111  struct rtnl_htb_qdisc *htb = data;
112 
113  if (!htb)
114  return;
115 
116  if (htb->qh_mask & SCH_HTB_HAS_RATE2QUANTUM)
117  nl_dump(p, " r2q %u", htb->qh_rate2quantum);
118 
119  if (htb->qh_mask & SCH_HTB_HAS_DEFCLS) {
120  char buf[64];
121  nl_dump(p, " default-class %s",
122  rtnl_tc_handle2str(htb->qh_defcls, buf, sizeof(buf)));
123  }
124 }
125 
126 static void htb_class_dump_line(struct rtnl_tc *tc, void *data,
127  struct nl_dump_params *p)
128 {
129  struct rtnl_htb_class *htb = data;
130 
131  if (!htb)
132  return;
133 
134  if (htb->ch_mask & SCH_HTB_HAS_RATE) {
135  double r, rbit;
136  char *ru, *rubit;
137 
138  r = nl_cancel_down_bytes(htb->ch_rate.rs_rate, &ru);
139  rbit = nl_cancel_down_bits(htb->ch_rate.rs_rate*8, &rubit);
140 
141  nl_dump(p, " rate %.2f%s/s (%.0f%s) log %u",
142  r, ru, rbit, rubit, 1<<htb->ch_rate.rs_cell_log);
143  }
144 }
145 
146 static void htb_class_dump_details(struct rtnl_tc *tc, void *data,
147  struct nl_dump_params *p)
148 {
149  struct rtnl_htb_class *htb = data;
150 
151  if (!htb)
152  return;
153 
154  /* line 1 */
155  if (htb->ch_mask & SCH_HTB_HAS_CEIL) {
156  double r, rbit;
157  char *ru, *rubit;
158 
159  r = nl_cancel_down_bytes(htb->ch_ceil.rs_rate, &ru);
160  rbit = nl_cancel_down_bits(htb->ch_ceil.rs_rate*8, &rubit);
161 
162  nl_dump(p, " ceil %.2f%s/s (%.0f%s) log %u",
163  r, ru, rbit, rubit, 1<<htb->ch_ceil.rs_cell_log);
164  }
165 
166  if (htb->ch_mask & SCH_HTB_HAS_PRIO)
167  nl_dump(p, " prio %u", htb->ch_prio);
168 
169  if (htb->ch_mask & SCH_HTB_HAS_RBUFFER) {
170  double b;
171  char *bu;
172 
173  b = nl_cancel_down_bytes(htb->ch_rbuffer, &bu);
174  nl_dump(p, " rbuffer %.2f%s", b, bu);
175  }
176 
177  if (htb->ch_mask & SCH_HTB_HAS_CBUFFER) {
178  double b;
179  char *bu;
180 
181  b = nl_cancel_down_bytes(htb->ch_cbuffer, &bu);
182  nl_dump(p, " cbuffer %.2f%s", b, bu);
183  }
184 
185  if (htb->ch_mask & SCH_HTB_HAS_QUANTUM)
186  nl_dump(p, " quantum %u", htb->ch_quantum);
187 }
188 
189 static int htb_qdisc_msg_fill(struct rtnl_tc *tc, void *data,
190  struct nl_msg *msg)
191 {
192  struct rtnl_htb_qdisc *htb = data;
193  struct tc_htb_glob opts = {
194  .version = TC_HTB_PROTOVER,
195  .rate2quantum = 10,
196  };
197 
198  if (htb) {
199  if (htb->qh_mask & SCH_HTB_HAS_RATE2QUANTUM)
200  opts.rate2quantum = htb->qh_rate2quantum;
201 
202  if (htb->qh_mask & SCH_HTB_HAS_DEFCLS)
203  opts.defcls = htb->qh_defcls;
204  }
205 
206  return nla_put(msg, TCA_HTB_INIT, sizeof(opts), &opts);
207 }
208 
209 static int htb_class_msg_fill(struct rtnl_tc *tc, void *data,
210  struct nl_msg *msg)
211 {
212  struct rtnl_htb_class *htb = data;
213  uint32_t mtu, rtable[RTNL_TC_RTABLE_SIZE], ctable[RTNL_TC_RTABLE_SIZE];
214  struct tc_htb_opt opts;
215  int buffer, cbuffer;
216 
217  if (!htb || !(htb->ch_mask & SCH_HTB_HAS_RATE))
218  BUG();
219 
220  memset(&opts, 0, sizeof(opts));
221 
222  /* if not set, zero (0) is used as priority */
223  if (htb->ch_mask & SCH_HTB_HAS_PRIO)
224  opts.prio = htb->ch_prio;
225 
226  mtu = rtnl_tc_get_mtu(tc);
227 
228  rtnl_tc_build_rate_table(tc, &htb->ch_rate, rtable);
229  rtnl_rcopy_ratespec(&opts.rate, &htb->ch_rate);
230 
231  if (htb->ch_mask & SCH_HTB_HAS_CEIL) {
232  rtnl_tc_build_rate_table(tc, &htb->ch_ceil, ctable);
233  rtnl_rcopy_ratespec(&opts.ceil, &htb->ch_ceil);
234  } else {
235  /*
236  * If not set, configured rate is used as ceil, which implies
237  * no borrowing.
238  */
239  memcpy(&opts.ceil, &opts.rate, sizeof(struct tc_ratespec));
240  }
241 
242  if (htb->ch_mask & SCH_HTB_HAS_RBUFFER)
243  buffer = htb->ch_rbuffer;
244  else
245  buffer = opts.rate.rate / nl_get_psched_hz() + mtu; /* XXX */
246 
247  opts.buffer = nl_us2ticks(rtnl_tc_calc_txtime(buffer, opts.rate.rate));
248 
249  if (htb->ch_mask & SCH_HTB_HAS_CBUFFER)
250  cbuffer = htb->ch_cbuffer;
251  else
252  cbuffer = opts.ceil.rate / nl_get_psched_hz() + mtu; /* XXX */
253 
254  opts.cbuffer = nl_us2ticks(rtnl_tc_calc_txtime(cbuffer, opts.ceil.rate));
255 
256  if (htb->ch_mask & SCH_HTB_HAS_QUANTUM)
257  opts.quantum = htb->ch_quantum;
258 
259  NLA_PUT(msg, TCA_HTB_PARMS, sizeof(opts), &opts);
260  NLA_PUT(msg, TCA_HTB_RTAB, sizeof(rtable), &rtable);
261  NLA_PUT(msg, TCA_HTB_CTAB, sizeof(ctable), &ctable);
262 
263  return 0;
264 
265 nla_put_failure:
266  return -NLE_MSGSIZE;
267 }
268 
269 static struct rtnl_tc_ops htb_qdisc_ops;
270 static struct rtnl_tc_ops htb_class_ops;
271 
272 static struct rtnl_htb_qdisc *htb_qdisc_data(struct rtnl_qdisc *qdisc, int *err)
273 {
274  return rtnl_tc_data_check(TC_CAST(qdisc), &htb_qdisc_ops, err);
275 }
276 
277 static struct rtnl_htb_class *htb_class_data(struct rtnl_class *class, int *err)
278 {
279  return rtnl_tc_data_check(TC_CAST(class), &htb_class_ops, err);
280 }
281 
282 /**
283  * @name Attribute Modifications
284  * @{
285  */
286 
287 /**
288  * Return rate/quantum ratio of HTB qdisc
289  * @arg qdisc htb qdisc object
290  *
291  * @return rate/quantum ratio or 0 if unspecified
292  */
293 uint32_t rtnl_htb_get_rate2quantum(struct rtnl_qdisc *qdisc)
294 {
295  struct rtnl_htb_qdisc *htb;
296 
297  if ((htb = htb_qdisc_data(qdisc, NULL)) &&
298  (htb->qh_mask & SCH_HTB_HAS_RATE2QUANTUM))
299  return htb->qh_rate2quantum;
300 
301  return 0;
302 }
303 
304 int rtnl_htb_set_rate2quantum(struct rtnl_qdisc *qdisc, uint32_t rate2quantum)
305 {
306  struct rtnl_htb_qdisc *htb;
307  int err;
308 
309  if (!(htb = htb_qdisc_data(qdisc, &err)))
310  return err;
311 
312  htb->qh_rate2quantum = rate2quantum;
313  htb->qh_mask |= SCH_HTB_HAS_RATE2QUANTUM;
314 
315  return 0;
316 }
317 
318 /**
319  * Return default class of HTB qdisc
320  * @arg qdisc htb qdisc object
321  *
322  * Returns the classid of the class where all unclassified traffic
323  * goes to.
324  *
325  * @return classid or TC_H_UNSPEC if unspecified.
326  */
327 uint32_t rtnl_htb_get_defcls(struct rtnl_qdisc *qdisc)
328 {
329  struct rtnl_htb_qdisc *htb;
330 
331  if ((htb = htb_qdisc_data(qdisc, NULL)) &&
332  htb->qh_mask & SCH_HTB_HAS_DEFCLS)
333  return htb->qh_defcls;
334 
335  return TC_H_UNSPEC;
336 }
337 
338 /**
339  * Set default class of the htb qdisc to the specified value
340  * @arg qdisc qdisc to change
341  * @arg defcls new default class
342  */
343 int rtnl_htb_set_defcls(struct rtnl_qdisc *qdisc, uint32_t defcls)
344 {
345  struct rtnl_htb_qdisc *htb;
346  int err;
347 
348  if (!(htb = htb_qdisc_data(qdisc, &err)))
349  return err;
350 
351  htb->qh_defcls = defcls;
352  htb->qh_mask |= SCH_HTB_HAS_DEFCLS;
353 
354  return 0;
355 }
356 
357 uint32_t rtnl_htb_get_prio(struct rtnl_class *class)
358 {
359  struct rtnl_htb_class *htb;
360 
361  if ((htb = htb_class_data(class, NULL)) &&
362  (htb->ch_mask & SCH_HTB_HAS_PRIO))
363  return htb->ch_prio;
364 
365  return 0;
366 }
367 
368 int rtnl_htb_set_prio(struct rtnl_class *class, uint32_t prio)
369 {
370  struct rtnl_htb_class *htb;
371  int err;
372 
373  if (!(htb = htb_class_data(class, &err)))
374  return err;
375 
376  htb->ch_prio = prio;
377  htb->ch_mask |= SCH_HTB_HAS_PRIO;
378 
379  return 0;
380 }
381 
382 /**
383  * Return rate of HTB class
384  * @arg class htb class object
385  *
386  * @return Rate in bytes/s or 0 if unspecified.
387  */
388 uint32_t rtnl_htb_get_rate(struct rtnl_class *class)
389 {
390  struct rtnl_htb_class *htb;
391 
392  if ((htb = htb_class_data(class, NULL)) &&
393  (htb->ch_mask & SCH_HTB_HAS_RATE))
394  return htb->ch_rate.rs_rate;
395 
396  return 0;
397 }
398 
399 /**
400  * Set rate of HTB class
401  * @arg class htb class object
402  * @arg rate new rate in bytes per second
403  *
404  * @return 0 on success or a negative error code.
405  */
406 int rtnl_htb_set_rate(struct rtnl_class *class, uint32_t rate)
407 {
408  struct rtnl_htb_class *htb;
409  int err;
410 
411  if (!(htb = htb_class_data(class, &err)))
412  return err;
413 
414  htb->ch_rate.rs_cell_log = UINT8_MAX; /* use default value */
415  htb->ch_rate.rs_rate = rate;
416  htb->ch_mask |= SCH_HTB_HAS_RATE;
417 
418  return 0;
419 }
420 
421 /**
422  * Return ceil rate of HTB class
423  * @arg class htb class object
424  *
425  * @return Ceil rate in bytes/s or 0 if unspecified
426  */
427 uint32_t rtnl_htb_get_ceil(struct rtnl_class *class)
428 {
429  struct rtnl_htb_class *htb;
430 
431  if ((htb = htb_class_data(class, NULL)) &&
432  (htb->ch_mask & SCH_HTB_HAS_CEIL))
433  return htb->ch_ceil.rs_rate;
434 
435  return 0;
436 }
437 
438 /**
439  * Set ceil rate of HTB class
440  * @arg class htb class object
441  * @arg ceil new ceil rate number of bytes per second
442  *
443  * @return 0 on success or a negative error code.
444  */
445 int rtnl_htb_set_ceil(struct rtnl_class *class, uint32_t ceil)
446 {
447  struct rtnl_htb_class *htb;
448  int err;
449 
450  if (!(htb = htb_class_data(class, &err)))
451  return err;
452 
453  htb->ch_ceil.rs_cell_log = UINT8_MAX; /* use default value */
454  htb->ch_ceil.rs_rate = ceil;
455  htb->ch_mask |= SCH_HTB_HAS_CEIL;
456 
457  return 0;
458 }
459 
460 /**
461  * Return burst buffer size of HTB class
462  * @arg class htb class object
463  *
464  * @return Burst buffer size or 0 if unspecified
465  */
466 uint32_t rtnl_htb_get_rbuffer(struct rtnl_class *class)
467 {
468  struct rtnl_htb_class *htb;
469 
470  if ((htb = htb_class_data(class, NULL)) &&
471  htb->ch_mask & SCH_HTB_HAS_RBUFFER)
472  return htb->ch_rbuffer;
473 
474  return 0;
475 }
476 
477 /**
478  * Set size of the rate bucket of HTB class.
479  * @arg class HTB class to be modified.
480  * @arg rbuffer New size in bytes.
481  */
482 int rtnl_htb_set_rbuffer(struct rtnl_class *class, uint32_t rbuffer)
483 {
484  struct rtnl_htb_class *htb;
485  int err;
486 
487  if (!(htb = htb_class_data(class, &err)))
488  return err;
489 
490  htb->ch_rbuffer = rbuffer;
491  htb->ch_mask |= SCH_HTB_HAS_RBUFFER;
492 
493  return 0;
494 }
495 
496 /**
497  * Return ceil burst buffer size of HTB class
498  * @arg class htb class object
499  *
500  * @return Ceil burst buffer size or 0 if unspecified
501  */
502 uint32_t rtnl_htb_get_cbuffer(struct rtnl_class *class)
503 {
504  struct rtnl_htb_class *htb;
505 
506  if ((htb = htb_class_data(class, NULL)) &&
507  htb->ch_mask & SCH_HTB_HAS_CBUFFER)
508  return htb->ch_cbuffer;
509 
510  return 0;
511 }
512 
513 /**
514  * Set size of the ceil bucket of HTB class.
515  * @arg class HTB class to be modified.
516  * @arg cbuffer New size in bytes.
517  */
518 int rtnl_htb_set_cbuffer(struct rtnl_class *class, uint32_t cbuffer)
519 {
520  struct rtnl_htb_class *htb;
521  int err;
522 
523  if (!(htb = htb_class_data(class, &err)))
524  return err;
525 
526  htb->ch_cbuffer = cbuffer;
527  htb->ch_mask |= SCH_HTB_HAS_CBUFFER;
528 
529  return 0;
530 }
531 
532 /**
533  * Return quantum of HTB class
534  * @arg class htb class object
535  *
536  * See XXX[quantum def]
537  *
538  * @return Quantum or 0 if unspecified.
539  */
540 uint32_t rtnl_htb_get_quantum(struct rtnl_class *class)
541 {
542  struct rtnl_htb_class *htb;
543 
544  if ((htb = htb_class_data(class, NULL)) &&
545  htb->ch_mask & SCH_HTB_HAS_QUANTUM)
546  return htb->ch_quantum;
547 
548  return 0;
549 }
550 
551 /**
552  * Set quantum of HTB class (overwrites value calculated based on r2q)
553  * @arg class htb class object
554  * @arg quantum new quantum in number of bytes
555  *
556  * See XXX[quantum def]
557  *
558  * @return 0 on success or a negative error code.
559  */
560 int rtnl_htb_set_quantum(struct rtnl_class *class, uint32_t quantum)
561 {
562  struct rtnl_htb_class *htb;
563  int err;
564 
565  if (!(htb = htb_class_data(class, &err)))
566  return err;
567 
568  htb->ch_quantum = quantum;
569  htb->ch_mask |= SCH_HTB_HAS_QUANTUM;
570 
571  return 0;
572 }
573 
574 /**
575  * Return level of HTB class
576  * @arg class htb class object
577  *
578  * Returns the level of the HTB class. Leaf classes are assigned level
579  * 0, root classes have level (TC_HTB_MAXDEPTH - 1). Interior classes
580  * have a level of one less than their parent.
581  *
582  * @return Level or a negative error code.
583  */
584 int rtnl_htb_get_level(struct rtnl_class *class)
585 {
586  struct rtnl_htb_class *htb;
587  int err = -NLE_OPNOTSUPP;
588 
589  if ((htb = htb_class_data(class, &err)) &&
590  (htb->ch_mask & SCH_HTB_HAS_LEVEL))
591  return htb->ch_level;
592 
593  return err;
594 }
595 
596 /**
597  * Set level of HTB class
598  * @arg class htb class object
599  * @arg level new level of HTB class
600  *
601  * Sets the level of a HTB class. Note that changing the level of a HTB
602  * class does not change the level of its in kernel counterpart. This
603  * function is provided only to create HTB objects which can be compared
604  * against or filtered upon.
605  *
606  * @return 0 on success or a negative error code.
607  */
608 int rtnl_htb_set_level(struct rtnl_class *class, int level)
609 {
610  struct rtnl_htb_class *htb;
611  int err;
612 
613  if (!(htb = htb_class_data(class, &err)))
614  return err;
615 
616  htb->ch_level = level;
617  htb->ch_mask |= SCH_HTB_HAS_LEVEL;
618 
619  return 0;
620 }
621 
622 /** @} */
623 
624 static struct rtnl_tc_ops htb_qdisc_ops = {
625  .to_kind = "htb",
626  .to_type = RTNL_TC_TYPE_QDISC,
627  .to_size = sizeof(struct rtnl_htb_qdisc),
628  .to_msg_parser = htb_qdisc_msg_parser,
629  .to_dump[NL_DUMP_LINE] = htb_qdisc_dump_line,
630  .to_msg_fill = htb_qdisc_msg_fill,
631 };
632 
633 static struct rtnl_tc_ops htb_class_ops = {
634  .to_kind = "htb",
635  .to_type = RTNL_TC_TYPE_CLASS,
636  .to_size = sizeof(struct rtnl_htb_class),
637  .to_msg_parser = htb_class_msg_parser,
638  .to_dump = {
639  [NL_DUMP_LINE] = htb_class_dump_line,
640  [NL_DUMP_DETAILS] = htb_class_dump_details,
641  },
642  .to_msg_fill = htb_class_msg_fill,
643 };
644 
645 static void __init htb_init(void)
646 {
647  rtnl_tc_register(&htb_qdisc_ops);
648  rtnl_tc_register(&htb_class_ops);
649 }
650 
651 static void __exit htb_exit(void)
652 {
653  rtnl_tc_unregister(&htb_qdisc_ops);
654  rtnl_tc_unregister(&htb_class_ops);
655 }
656 
657 /** @} */
int rtnl_htb_get_level(struct rtnl_class *class)
Return level of HTB class.
Definition: htb.c:584
int rtnl_htb_set_rbuffer(struct rtnl_class *class, uint32_t rbuffer)
Set size of the rate bucket of HTB class.
Definition: htb.c:482
Dump object briefly on one line.
Definition: types.h:22
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Definition: tc.c:977
int rtnl_tc_calc_txtime(int bufsize, int rate)
Calculate time required to transmit buffer at a specific rate.
Definition: tc.c:597
int rtnl_htb_set_cbuffer(struct rtnl_class *class, uint32_t cbuffer)
Set size of the ceil bucket of HTB class.
Definition: htb.c:518
uint32_t rtnl_htb_get_rate(struct rtnl_class *class)
Return rate of HTB class.
Definition: htb.c:388
int rtnl_htb_set_level(struct rtnl_class *class, int level)
Set level of HTB class.
Definition: htb.c:608
uint32_t rtnl_htb_get_quantum(struct rtnl_class *class)
Return quantum of HTB class.
Definition: htb.c:540
Attribute validation policy.
Definition: attr.h:69
double nl_cancel_down_bits(unsigned long long l, char **unit)
Cancel down a bit counter.
Definition: utils.c:200
uint32_t rtnl_htb_get_defcls(struct rtnl_qdisc *qdisc)
Return default class of HTB qdisc.
Definition: htb.c:327
Dump all attributes but no statistics.
Definition: types.h:23
void * rtnl_tc_data_check(struct rtnl_tc *tc, struct rtnl_tc_ops *ops, int *err)
Check traffic control object type and return private data section.
Definition: tc.c:1073
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
Definition: tc.c:1011
uint32_t rtnl_htb_get_rbuffer(struct rtnl_class *class)
Return burst buffer size of HTB class.
Definition: htb.c:466
int rtnl_tc_calc_bufsize(int txtime, int rate)
Calculate buffer size able to transmit in a specific time and rate.
Definition: tc.c:620
uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
Return the MTU of traffic control object.
Definition: tc.c:361
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
Definition: utils.c:169
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
Definition: attr.c:353
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
Definition: tc.h:56
uint32_t rtnl_htb_get_cbuffer(struct rtnl_class *class)
Return ceil burst buffer size of HTB class.
Definition: htb.c:502
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
Definition: attr.h:164
int nl_get_psched_hz(void)
Return the value of packet scheduler HZ.
Definition: utils.c:517
int rtnl_htb_set_ceil(struct rtnl_class *class, uint32_t ceil)
Set ceil rate of HTB class.
Definition: htb.c:445
uint32_t nl_ticks2us(uint32_t ticks)
Convert ticks to micro seconds.
Definition: utils.c:540
int rtnl_htb_set_rate(struct rtnl_class *class, uint32_t rate)
Set rate of HTB class.
Definition: htb.c:406
uint16_t minlen
Minimal length of payload required.
Definition: attr.h:74
void rtnl_tc_set_mpu(struct rtnl_tc *tc, uint32_t mpu)
Set the Minimum Packet Unit (MPU) of a traffic control object.
Definition: tc.c:381
int rtnl_htb_set_quantum(struct rtnl_class *class, uint32_t quantum)
Set quantum of HTB class (overwrites value calculated based on r2q)
Definition: htb.c:560
int rtnl_htb_set_defcls(struct rtnl_qdisc *qdisc, uint32_t defcls)
Set default class of the htb qdisc to the specified value.
Definition: htb.c:343
uint32_t nl_us2ticks(uint32_t us)
Convert micro seconds to ticks.
Definition: utils.c:528
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
Definition: classid.c:109
int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *spec, uint32_t *dst)
Compute a transmission time lookup table.
Definition: tc.c:708
Dumping parameters.
Definition: types.h:33
void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
Set per packet overhead of a traffic control object.
Definition: tc.c:410
uint32_t rtnl_htb_get_rate2quantum(struct rtnl_qdisc *qdisc)
Return rate/quantum ratio of HTB qdisc.
Definition: htb.c:293
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition: utils.c:961
uint32_t rtnl_htb_get_ceil(struct rtnl_class *class)
Return ceil rate of HTB class.
Definition: htb.c:427
int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
Add a unspecific attribute to netlink message.
Definition: attr.c:500