libnl  3.6.0
tc.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
4  */
5 
6 /**
7  * @ingroup rtnl
8  * @defgroup tc Traffic Control
9  * @{
10  */
11 
12 #include <netlink-private/netlink.h>
13 #include <netlink-private/tc.h>
14 #include <netlink/netlink.h>
15 #include <netlink/utils.h>
16 #include <netlink/route/rtnl.h>
17 #include <netlink/route/link.h>
18 #include <netlink/route/tc.h>
19 #include <netlink-private/route/tc-api.h>
20 
21 #include "netlink-private/utils.h"
22 
23 /** @cond SKIP */
24 
25 static struct nl_list_head tc_ops_list[__RTNL_TC_TYPE_MAX];
26 static struct rtnl_tc_type_ops *tc_type_ops[__RTNL_TC_TYPE_MAX];
27 
28 static struct nla_policy tc_policy[TCA_MAX+1] = {
29  [TCA_KIND] = { .type = NLA_STRING,
30  .maxlen = TCKINDSIZ },
31  [TCA_CHAIN] = { .type = NLA_U32 },
32  [TCA_STATS] = { .minlen = sizeof(struct tc_stats) },
33  [TCA_STATS2] = { .type = NLA_NESTED },
34 };
35 
36 int tca_parse(struct nlattr **tb, int maxattr, struct rtnl_tc *g,
37  const struct nla_policy *policy)
38 {
39 
40  if (g->ce_mask & TCA_ATTR_OPTS)
41  return nla_parse(tb, maxattr,
42  (struct nlattr *) g->tc_opts->d_data,
43  g->tc_opts->d_size, policy);
44  else {
45  /* Ugly but tb[] must be in a defined state even if no
46  * attributes can be found. */
47  memset(tb, 0, sizeof(struct nlattr *) * (maxattr + 1));
48  return 0;
49  }
50 }
51 
52 static struct nla_policy tc_stats2_policy[TCA_STATS_MAX+1] = {
53  [TCA_STATS_BASIC] = { .minlen = sizeof(struct gnet_stats_basic) },
54  [TCA_STATS_RATE_EST] = { .minlen = sizeof(struct gnet_stats_rate_est) },
55  [TCA_STATS_QUEUE] = { .minlen = sizeof(struct gnet_stats_queue) },
56 };
57 
58 int rtnl_tc_msg_parse(struct nlmsghdr *n, struct rtnl_tc *tc)
59 {
60  struct nl_cache *link_cache;
61  struct rtnl_tc_ops *ops;
62  struct nlattr *tb[TCA_MAX + 1];
63  char kind[TCKINDSIZ];
64  struct tcmsg *tm;
65  int err;
66 
67  tc->ce_msgtype = n->nlmsg_type;
68 
69  err = nlmsg_parse(n, sizeof(*tm), tb, TCA_MAX, tc_policy);
70  if (err < 0)
71  return err;
72 
73  if (tb[TCA_KIND] == NULL)
74  return -NLE_MISSING_ATTR;
75 
76  nla_strlcpy(kind, tb[TCA_KIND], sizeof(kind));
77  rtnl_tc_set_kind(tc, kind);
78 
79  if (tb[TCA_CHAIN])
80  rtnl_tc_set_chain(tc, nla_get_u32(tb[TCA_CHAIN]));
81 
82  tm = nlmsg_data(n);
83  tc->tc_family = tm->tcm_family;
84  tc->tc_ifindex = tm->tcm_ifindex;
85  tc->tc_handle = tm->tcm_handle;
86  tc->tc_parent = tm->tcm_parent;
87  tc->tc_info = tm->tcm_info;
88 
89  tc->ce_mask |= (TCA_ATTR_FAMILY | TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE|
90  TCA_ATTR_PARENT | TCA_ATTR_INFO);
91 
92  if (tb[TCA_OPTIONS]) {
93  tc->tc_opts = nl_data_alloc_attr(tb[TCA_OPTIONS]);
94  if (!tc->tc_opts)
95  return -NLE_NOMEM;
96  tc->ce_mask |= TCA_ATTR_OPTS;
97  }
98 
99  if (tb[TCA_STATS2]) {
100  struct nlattr *tbs[TCA_STATS_MAX + 1];
101 
102  err = nla_parse_nested(tbs, TCA_STATS_MAX, tb[TCA_STATS2],
103  tc_stats2_policy);
104  if (err < 0)
105  return err;
106 
107  if (tbs[TCA_STATS_BASIC]) {
108  struct gnet_stats_basic *bs;
109 
110  bs = nla_data(tbs[TCA_STATS_BASIC]);
111  tc->tc_stats[RTNL_TC_BYTES] = bs->bytes;
112  tc->tc_stats[RTNL_TC_PACKETS] = bs->packets;
113  }
114 
115  if (tbs[TCA_STATS_RATE_EST]) {
116  struct gnet_stats_rate_est *re;
117 
118  re = nla_data(tbs[TCA_STATS_RATE_EST]);
119  tc->tc_stats[RTNL_TC_RATE_BPS] = re->bps;
120  tc->tc_stats[RTNL_TC_RATE_PPS] = re->pps;
121  }
122 
123  if (tbs[TCA_STATS_QUEUE]) {
124  struct gnet_stats_queue *q;
125 
126  q = nla_data(tbs[TCA_STATS_QUEUE]);
127  tc->tc_stats[RTNL_TC_QLEN] = q->qlen;
128  tc->tc_stats[RTNL_TC_BACKLOG] = q->backlog;
129  tc->tc_stats[RTNL_TC_DROPS] = q->drops;
130  tc->tc_stats[RTNL_TC_REQUEUES] = q->requeues;
131  tc->tc_stats[RTNL_TC_OVERLIMITS] = q->overlimits;
132  }
133 
134  tc->ce_mask |= TCA_ATTR_STATS;
135 
136  if (tbs[TCA_STATS_APP]) {
137  tc->tc_xstats = nl_data_alloc_attr(tbs[TCA_STATS_APP]);
138  if (tc->tc_xstats == NULL)
139  return -NLE_NOMEM;
140  tc->ce_mask |= TCA_ATTR_XSTATS;
141  } else
142  goto compat_xstats;
143  } else {
144  if (tb[TCA_STATS]) {
145  struct tc_stats *st = nla_data(tb[TCA_STATS]);
146 
147  tc->tc_stats[RTNL_TC_BYTES] = st->bytes;
148  tc->tc_stats[RTNL_TC_PACKETS] = st->packets;
149  tc->tc_stats[RTNL_TC_RATE_BPS] = st->bps;
150  tc->tc_stats[RTNL_TC_RATE_PPS] = st->pps;
151  tc->tc_stats[RTNL_TC_QLEN] = st->qlen;
152  tc->tc_stats[RTNL_TC_BACKLOG] = st->backlog;
153  tc->tc_stats[RTNL_TC_DROPS] = st->drops;
154  tc->tc_stats[RTNL_TC_OVERLIMITS]= st->overlimits;
155 
156  tc->ce_mask |= TCA_ATTR_STATS;
157  }
158 
159 compat_xstats:
160  if (tb[TCA_XSTATS]) {
161  tc->tc_xstats = nl_data_alloc_attr(tb[TCA_XSTATS]);
162  if (tc->tc_xstats == NULL)
163  return -NLE_NOMEM;
164  tc->ce_mask |= TCA_ATTR_XSTATS;
165  }
166  }
167 
168  ops = rtnl_tc_get_ops(tc);
169  if (ops && ops->to_msg_parser) {
170  void *data = rtnl_tc_data(tc);
171 
172  if (!data)
173  return -NLE_NOMEM;
174 
175  err = ops->to_msg_parser(tc, data);
176  if (err < 0)
177  return err;
178  }
179 
180  if ((link_cache = __nl_cache_mngt_require("route/link"))) {
181  struct rtnl_link *link;
182 
183  if ((link = rtnl_link_get(link_cache, tc->tc_ifindex))) {
184  rtnl_tc_set_link(tc, link);
185 
186  /* rtnl_tc_set_link incs refcnt */
187  rtnl_link_put(link);
188  }
189  }
190 
191  return 0;
192 }
193 
194 int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
195  struct nl_msg **result)
196 {
197  struct nl_msg *msg;
198  struct rtnl_tc_ops *ops;
199  struct tcmsg tchdr = {
200  .tcm_family = AF_UNSPEC,
201  .tcm_ifindex = tc->tc_ifindex,
202  .tcm_handle = tc->tc_handle,
203  .tcm_parent = tc->tc_parent,
204  };
205  int err;
206 
207  msg = nlmsg_alloc_simple(type, flags);
208  if (!msg)
209  return -NLE_NOMEM;
210 
211  if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0) {
212  err = -NLE_MSGSIZE;
213  goto out_err;
214  }
215 
216  if (tc->ce_mask & TCA_ATTR_KIND)
217  NLA_PUT_STRING(msg, TCA_KIND, tc->tc_kind);
218 
219  if (tc->ce_mask & TCA_ATTR_CHAIN)
220  NLA_PUT_U32(msg, TCA_CHAIN, tc->tc_chain);
221 
222  ops = rtnl_tc_get_ops(tc);
223  if (ops && (ops->to_msg_fill || ops->to_msg_fill_raw)) {
224  struct nlattr *opts;
225  void *data = rtnl_tc_data(tc);
226 
227  if (ops->to_msg_fill) {
228  if (!(opts = nla_nest_start(msg, TCA_OPTIONS))) {
229  err = -NLE_NOMEM;
230  goto out_err;
231  }
232 
233  if ((err = ops->to_msg_fill(tc, data, msg)) < 0)
234  goto out_err;
235 
236  if (strcmp("cgroup", tc->tc_kind))
237  nla_nest_end(msg, opts);
238  else
239  nla_nest_end_keep_empty(msg, opts);
240  } else if ((err = ops->to_msg_fill_raw(tc, data, msg)) < 0)
241  goto out_err;
242  }
243 
244  *result = msg;
245  return 0;
246 
247 nla_put_failure:
248  err = -NLE_NOMEM;
249 out_err:
250  nlmsg_free(msg);
251  return err;
252 }
253 
254 
255 /** @endcond */
256 
257 /**
258  * @name Attributes
259  * @{
260  */
261 
262 /**
263  * Set interface index of traffic control object
264  * @arg tc traffic control object
265  * @arg ifindex interface index.
266  *
267  * Sets the interface index of a traffic control object. The interface
268  * index defines the network device which this tc object is attached to.
269  * This function will overwrite any network device assigned with previous
270  * calls to rtnl_tc_set_ifindex() or rtnl_tc_set_link().
271  */
272 void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
273 {
274  /* Obsolete possible old link reference */
275  rtnl_link_put(tc->tc_link);
276  tc->tc_link = NULL;
277  tc->ce_mask &= ~TCA_ATTR_LINK;
278 
279  tc->tc_ifindex = ifindex;
280  tc->ce_mask |= TCA_ATTR_IFINDEX;
281 }
282 
283 /**
284  * Return interface index of traffic control object
285  * @arg tc traffic control object
286  */
287 int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
288 {
289  return tc->tc_ifindex;
290 }
291 
292 /**
293  * Set link of traffic control object
294  * @arg tc traffic control object
295  * @arg link link object
296  *
297  * Sets the link of a traffic control object. This function serves
298  * the same purpose as rtnl_tc_set_ifindex() but due to the continued
299  * allowed access to the link object it gives it the possibility to
300  * retrieve sane default values for the the MTU and the linktype.
301  * Always prefer this function over rtnl_tc_set_ifindex() if you can
302  * spare to have an additional link object around.
303  */
304 void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
305 {
306  rtnl_link_put(tc->tc_link);
307 
308  if (!link)
309  return;
310  if (!link->l_index)
311  BUG();
312 
313  nl_object_get(OBJ_CAST(link));
314  tc->tc_link = link;
315  tc->tc_ifindex = link->l_index;
316  tc->ce_mask |= TCA_ATTR_LINK | TCA_ATTR_IFINDEX;
317 }
318 
319 /**
320  * Get link of traffic control object
321  * @arg tc traffic control object
322  *
323  * Returns the link of a traffic control object. The link is only
324  * returned if it has been set before via rtnl_tc_set_link() or
325  * if a link cache was available while parsing the tc object. This
326  * function may still return NULL even if an ifindex is assigned to
327  * the tc object. It will _not_ look up the link by itself.
328  *
329  * @note The returned link will have its reference counter incremented.
330  * It is in the responsibility of the caller to return the
331  * reference.
332  *
333  * @return link object or NULL if not set.
334  */
335 struct rtnl_link *rtnl_tc_get_link(struct rtnl_tc *tc)
336 {
337  if (tc->tc_link) {
338  nl_object_get(OBJ_CAST(tc->tc_link));
339  return tc->tc_link;
340  }
341 
342  return NULL;
343 }
344 
345 /**
346  * Set the Maximum Transmission Unit (MTU) of traffic control object
347  * @arg tc traffic control object
348  * @arg mtu largest packet size expected
349  *
350  * Sets the MTU of a traffic control object. Not all traffic control
351  * objects will make use of this but it helps while calculating rate
352  * tables. This value is typically derived directly from the link
353  * the tc object is attached to if the link has been assigned via
354  * rtnl_tc_set_link(). It is usually not necessary to set the MTU
355  * manually, this function is provided to allow overwriting the derived
356  * value.
357  */
358 void rtnl_tc_set_mtu(struct rtnl_tc *tc, uint32_t mtu)
359 {
360  tc->tc_mtu = mtu;
361  tc->ce_mask |= TCA_ATTR_MTU;
362 }
363 
364 /**
365  * Return the MTU of traffic control object
366  * @arg tc traffic control object
367  *
368  * Returns the MTU of a traffic control object which has been set via:
369  * -# User specified value set via rtnl_tc_set_mtu()
370  * -# Dervied from link set via rtnl_tc_set_link()
371  * -# Fall back to default: ethernet = 1500
372  */
373 uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
374 {
375  if (tc->ce_mask & TCA_ATTR_MTU)
376  return tc->tc_mtu;
377  else if (tc->ce_mask & TCA_ATTR_LINK)
378  return tc->tc_link->l_mtu;
379  else
380  return 1500; /* default to ethernet */
381 }
382 
383 /**
384  * Set the Minimum Packet Unit (MPU) of a traffic control object
385  * @arg tc traffic control object
386  * @arg mpu minimum packet size expected
387  *
388  * Sets the MPU of a traffic contorl object. It specifies the minimum
389  * packet size to ever hit this traffic control object. Not all traffic
390  * control objects will make use of this but it helps while calculating
391  * rate tables.
392  */
393 void rtnl_tc_set_mpu(struct rtnl_tc *tc, uint32_t mpu)
394 {
395  tc->tc_mpu = mpu;
396  tc->ce_mask |= TCA_ATTR_MPU;
397 }
398 
399 /**
400  * Return the Minimum Packet Unit (MPU) of a traffic control object
401  * @arg tc traffic control object
402  *
403  * @return The MPU previously set via rtnl_tc_set_mpu() or 0.
404  */
405 uint32_t rtnl_tc_get_mpu(struct rtnl_tc *tc)
406 {
407  return tc->tc_mpu;
408 }
409 
410 /**
411  * Set per packet overhead of a traffic control object
412  * @arg tc traffic control object
413  * @arg overhead overhead per packet in bytes
414  *
415  * Sets the per packet overhead in bytes occuring on the link not seen
416  * by the kernel. This value can be used to correct size calculations
417  * if the packet size on the wire does not match the packet sizes seen
418  * in the network stack. Not all traffic control objects will make use
419  * this but it helps while calculating accurate packet sizes in the
420  * kernel.
421  */
422 void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
423 {
424  tc->tc_overhead = overhead;
425  tc->ce_mask |= TCA_ATTR_OVERHEAD;
426 }
427 
428 /**
429  * Return per packet overhead of a traffic control object
430  * @arg tc traffic control object
431  *
432  * @return The overhead previously set by rtnl_tc_set_overhead() or 0.
433  */
434 uint32_t rtnl_tc_get_overhead(struct rtnl_tc *tc)
435 {
436  return tc->tc_overhead;
437 }
438 
439 /**
440  * Set the linktype of a traffic control object
441  * @arg tc traffic control object
442  * @arg type type of link (e.g. ARPHRD_ATM, ARPHRD_ETHER)
443  *
444  * Overwrites the type of link this traffic control object is attached to.
445  * This value is typically derived from the link this tc object is attached
446  * if the link has been assigned via rtnl_tc_set_link(). It is usually not
447  * necessary to set the linktype manually. This function is provided to
448  * allow overwriting the linktype.
449  */
450 void rtnl_tc_set_linktype(struct rtnl_tc *tc, uint32_t type)
451 {
452  tc->tc_linktype = type;
453  tc->ce_mask |= TCA_ATTR_LINKTYPE;
454 }
455 
456 /**
457  * Return the linktype of a traffic control object
458  * @arg tc traffic control object
459  *
460  * Returns the linktype of the link the traffic control object is attached to:
461  * -# User specified value via rtnl_tc_set_linktype()
462  * -# Value derived from link set via rtnl_tc_set_link()
463  * -# Default fall-back: ARPHRD_ETHER
464  */
465 uint32_t rtnl_tc_get_linktype(struct rtnl_tc *tc)
466 {
467  if (tc->ce_mask & TCA_ATTR_LINKTYPE)
468  return tc->tc_linktype;
469  else if (tc->ce_mask & TCA_ATTR_LINK)
470  return tc->tc_link->l_arptype;
471  else
472  return ARPHRD_ETHER; /* default to ethernet */
473 }
474 
475 /**
476  * Set identifier of traffic control object
477  * @arg tc traffic control object
478  * @arg id unique identifier
479  */
480 void rtnl_tc_set_handle(struct rtnl_tc *tc, uint32_t id)
481 {
482  tc->tc_handle = id;
483  tc->ce_mask |= TCA_ATTR_HANDLE;
484 }
485 
486 /**
487  * Return identifier of a traffic control object
488  * @arg tc traffic control object
489  */
490 uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
491 {
492  return tc->tc_handle;
493 }
494 
495 /**
496  * Set the parent identifier of a traffic control object
497  * @arg tc traffic control object
498  * @arg parent identifier of parent traffif control object
499  *
500  */
501 void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
502 {
503  tc->tc_parent = parent;
504  tc->ce_mask |= TCA_ATTR_PARENT;
505 }
506 
507 /**
508  * Return parent identifier of a traffic control object
509  * @arg tc traffic control object
510  */
511 uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
512 {
513  return tc->tc_parent;
514 }
515 
516 /**
517  * Define the type of traffic control object
518  * @arg tc traffic control object
519  * @arg kind name of the tc object type
520  *
521  * @return 0 on success or a negative error code
522  */
523 int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
524 {
525  if (tc->ce_mask & TCA_ATTR_KIND)
526  return -NLE_EXIST;
527 
528  if ( !kind
529  || strlen (kind) >= sizeof (tc->tc_kind))
530  return -NLE_INVAL;
531 
532  _nl_strncpy_assert(tc->tc_kind, kind, sizeof(tc->tc_kind));
533 
534  tc->ce_mask |= TCA_ATTR_KIND;
535 
536  /* Force allocation of data */
537  rtnl_tc_data(tc);
538 
539  return 0;
540 }
541 
542 /**
543  * Return kind of traffic control object
544  * @arg tc traffic control object
545  *
546  * @return Kind of traffic control object or NULL if not set.
547  */
548 char *rtnl_tc_get_kind(struct rtnl_tc *tc)
549 {
550  if (tc->ce_mask & TCA_ATTR_KIND)
551  return tc->tc_kind;
552  else
553  return NULL;
554 }
555 
556 /**
557  * Return value of a statistical counter of a traffic control object
558  * @arg tc traffic control object
559  * @arg id identifier of statistical counter
560  *
561  * @return Value of requested statistic counter or 0.
562  */
563 uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
564 {
565  if ((unsigned int) id > RTNL_TC_STATS_MAX)
566  return 0;
567 
568  return tc->tc_stats[id];
569 }
570 
571 /**
572  * Set the chain index of a traffic control object
573  * @arg tc traffic control object
574  * @arg chain chain index of traffic control object
575  *
576  */
577 void rtnl_tc_set_chain(struct rtnl_tc *tc, uint32_t chain)
578 {
579  tc->tc_chain = chain;
580  tc->ce_mask |= TCA_ATTR_CHAIN;
581 }
582 
583 /**
584  * Return chain index of traffic control object
585  * @arg tc traffic control object
586  * @arg out_value output argument.
587  *
588  * @return 0 of the output value was successfully returned, or a negative
589  * error code on failure.
590  */
591 int rtnl_tc_get_chain(struct rtnl_tc *tc, uint32_t *out_value)
592 {
593  if (!(tc->ce_mask & TCA_ATTR_CHAIN))
594  return -NLE_MISSING_ATTR;
595  *out_value = tc->tc_chain;
596  return 0;
597 }
598 
599 /** @} */
600 
601 /**
602  * @name Utilities
603  * @{
604  */
605 
606 static const struct trans_tbl tc_stats[] = {
607  __ADD(RTNL_TC_PACKETS, packets),
608  __ADD(RTNL_TC_BYTES, bytes),
609  __ADD(RTNL_TC_RATE_BPS, rate_bps),
610  __ADD(RTNL_TC_RATE_PPS, rate_pps),
611  __ADD(RTNL_TC_QLEN, qlen),
612  __ADD(RTNL_TC_BACKLOG, backlog),
613  __ADD(RTNL_TC_DROPS, drops),
614  __ADD(RTNL_TC_REQUEUES, requeues),
615  __ADD(RTNL_TC_OVERLIMITS, overlimits),
616 };
617 
618 char *rtnl_tc_stat2str(enum rtnl_tc_stat st, char *buf, size_t len)
619 {
620  return __type2str(st, buf, len, tc_stats, ARRAY_SIZE(tc_stats));
621 }
622 
623 int rtnl_tc_str2stat(const char *name)
624 {
625  return __str2type(name, tc_stats, ARRAY_SIZE(tc_stats));
626 }
627 
628 /**
629  * Calculate time required to transmit buffer at a specific rate
630  * @arg bufsize Size of buffer to be transmited in bytes.
631  * @arg rate Transmit rate in bytes per second.
632  *
633  * Calculates the number of micro seconds required to transmit a
634  * specific buffer at a specific transmit rate.
635  *
636  * @f[
637  * txtime=\frac{bufsize}{rate}10^6
638  * @f]
639  *
640  * @return Required transmit time in micro seconds.
641  */
642 int rtnl_tc_calc_txtime(int bufsize, int rate)
643 {
644  return ((double) bufsize / (double) rate) * 1000000.0;
645 }
646 
647 /**
648  * Calculate buffer size able to transmit in a specific time and rate.
649  * @arg txtime Available transmit time in micro seconds.
650  * @arg rate Transmit rate in bytes per second.
651  *
652  * Calculates the size of the buffer that can be transmitted in a
653  * specific time period at a specific transmit rate.
654  *
655  * @f[
656  * bufsize=\frac{{txtime} \times {rate}}{10^6}
657  * @f]
658  *
659  * @return Size of buffer in bytes.
660  */
661 int rtnl_tc_calc_bufsize(int txtime, int rate)
662 {
663  return ((double) txtime * (double) rate) / 1000000.0;
664 }
665 
666 /**
667  * Calculate the binary logarithm for a specific cell size
668  * @arg cell_size Size of cell, must be a power of two.
669  * @return Binary logirhtm of cell size or a negative error code.
670  */
671 int rtnl_tc_calc_cell_log(int cell_size)
672 {
673  int i;
674 
675  for (i = 0; i < 32; i++)
676  if ((1 << i) == cell_size)
677  return i;
678 
679  return -NLE_INVAL;
680 }
681 
682 
683 /** @} */
684 
685 /**
686  * @name Rate Tables
687  * @{
688  */
689 
690 /*
691  * COPYRIGHT NOTE:
692  * align_to_atm() and adjust_size() derived/coped from iproute2 source.
693  */
694 
695 /*
696  * The align to ATM cells is used for determining the (ATM) SAR
697  * alignment overhead at the ATM layer. (SAR = Segmentation And
698  * Reassembly). This is for example needed when scheduling packet on
699  * an ADSL connection. Note that the extra ATM-AAL overhead is _not_
700  * included in this calculation. This overhead is added in the kernel
701  * before doing the rate table lookup, as this gives better precision
702  * (as the table will always be aligned for 48 bytes).
703  * --Hawk, d.7/11-2004. <hawk@diku.dk>
704  */
705 static unsigned int align_to_atm(unsigned int size)
706 {
707  int linksize, cells;
708  cells = size / ATM_CELL_PAYLOAD;
709  if ((size % ATM_CELL_PAYLOAD) > 0)
710  cells++;
711 
712  linksize = cells * ATM_CELL_SIZE; /* Use full cell size to add ATM tax */
713  return linksize;
714 }
715 
716 static unsigned int adjust_size(unsigned int size, unsigned int mpu,
717  uint32_t linktype)
718 {
719  if (size < mpu)
720  size = mpu;
721 
722  switch (linktype) {
723  case ARPHRD_ATM:
724  return align_to_atm(size);
725 
726  case ARPHRD_ETHER:
727  default:
728  return size;
729  }
730 }
731 
732 /**
733  * Compute a transmission time lookup table
734  * @arg tc traffic control object
735  * @arg spec Rate specification
736  * @arg dst Destination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
737  *
738  * Computes a table of RTNL_TC_RTABLE_SIZE entries specyfing the
739  * transmission times for various packet sizes, e.g. the transmission
740  * time for a packet of size \c pktsize could be looked up:
741  * @code
742  * txtime = table[pktsize >> log2(mtu)];
743  * @endcode
744  */
745 int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *spec,
746  uint32_t *dst)
747 {
748  uint32_t mtu = rtnl_tc_get_mtu(tc);
749  uint32_t linktype = rtnl_tc_get_linktype(tc);
750  uint8_t cell_log = spec->rs_cell_log;
751  unsigned int size, i;
752 
753  spec->rs_mpu = rtnl_tc_get_mpu(tc);
754  spec->rs_overhead = rtnl_tc_get_overhead(tc);
755 
756  if (mtu == 0)
757  mtu = 2047;
758 
759  if (cell_log == UINT8_MAX) {
760  /*
761  * cell_log not specified, calculate it. It has to specify the
762  * minimum number of rshifts required to break the MTU to below
763  * RTNL_TC_RTABLE_SIZE.
764  */
765  cell_log = 0;
766  while ((mtu >> cell_log) >= RTNL_TC_RTABLE_SIZE)
767  cell_log++;
768  }
769 
770  for (i = 0; i < RTNL_TC_RTABLE_SIZE; i++) {
771  size = adjust_size((i + 1) << cell_log, spec->rs_mpu, linktype);
772  dst[i] = nl_us2ticks(rtnl_tc_calc_txtime64(size, spec->rs_rate64));
773  }
774 
775  spec->rs_cell_align = -1;
776  spec->rs_cell_log = cell_log;
777 
778  return 0;
779 }
780 
781 /** @} */
782 
783 /**
784  * @name TC implementation of cache functions
785  */
786 
787 void rtnl_tc_free_data(struct nl_object *obj)
788 {
789  struct rtnl_tc *tc = TC_CAST(obj);
790  struct rtnl_tc_ops *ops;
791 
792  rtnl_link_put(tc->tc_link);
793  nl_data_free(tc->tc_opts);
794  nl_data_free(tc->tc_xstats);
795 
796  if (tc->tc_subdata) {
797  ops = rtnl_tc_get_ops(tc);
798  if (ops && ops->to_free_data)
799  ops->to_free_data(tc, nl_data_get(tc->tc_subdata));
800 
801  nl_data_free(tc->tc_subdata);
802  }
803 }
804 
805 int rtnl_tc_clone(struct nl_object *dstobj, struct nl_object *srcobj)
806 {
807  struct rtnl_tc *dst = TC_CAST(dstobj);
808  struct rtnl_tc *src = TC_CAST(srcobj);
809  struct rtnl_tc_ops *ops;
810 
811  dst->tc_opts = NULL;
812  dst->tc_xstats = NULL;
813  dst->tc_subdata = NULL;
814  dst->tc_link = NULL;
815  dst->tc_ops = NULL;
816 
817  if (src->tc_link) {
818  nl_object_get(OBJ_CAST(src->tc_link));
819  dst->tc_link = src->tc_link;
820  }
821 
822  dst->ce_mask &= ~(TCA_ATTR_OPTS |
823  TCA_ATTR_XSTATS);
824 
825  if (src->tc_opts) {
826  dst->tc_opts = nl_data_clone(src->tc_opts);
827  if (!dst->tc_opts)
828  return -NLE_NOMEM;
829  dst->ce_mask |= TCA_ATTR_OPTS;
830  }
831 
832  if (src->tc_xstats) {
833  dst->tc_xstats = nl_data_clone(src->tc_xstats);
834  if (!dst->tc_xstats)
835  return -NLE_NOMEM;
836  dst->ce_mask |= TCA_ATTR_XSTATS;
837  }
838 
839  if (src->tc_subdata) {
840  if (!(dst->tc_subdata = nl_data_clone(src->tc_subdata))) {
841  return -NLE_NOMEM;
842  }
843 
844  /* Warning: if the data contains pointer, then at this point, dst->tc_subdata
845  * will alias those pointers.
846  *
847  * ops->to_clone() MUST fix that.
848  *
849  * If the type is actually "struct rtnl_act", then to_clone() must also
850  * fix dangling "a_next" pointer. */
851 
852  ops = rtnl_tc_get_ops(src);
853  if (ops && ops->to_clone) {
854  return ops->to_clone(rtnl_tc_data(dst), rtnl_tc_data(src));
855  }
856  }
857 
858  return 0;
859 }
860 
861 static int tc_dump(struct rtnl_tc *tc, enum nl_dump_type type,
862  struct nl_dump_params *p)
863 {
864  struct rtnl_tc_type_ops *type_ops;
865  struct rtnl_tc_ops *ops;
866  void *data = rtnl_tc_data(tc);
867 
868  type_ops = tc_type_ops[tc->tc_type];
869  if (type_ops && type_ops->tt_dump[type])
870  type_ops->tt_dump[type](tc, p);
871 
872  ops = rtnl_tc_get_ops(tc);
873  if (ops && ops->to_dump[type]) {
874  ops->to_dump[type](tc, data, p);
875  return 1;
876  }
877 
878  return 0;
879 }
880 
881 void rtnl_tc_dump_line(struct nl_object *obj, struct nl_dump_params *p)
882 {
883  struct rtnl_tc_type_ops *type_ops;
884  struct rtnl_tc *tc = TC_CAST(obj);
885  struct nl_cache *link_cache;
886  char buf[32];
887 
888  nl_new_line(p);
889 
890  type_ops = tc_type_ops[tc->tc_type];
891  if (type_ops && type_ops->tt_dump_prefix)
892  nl_dump(p, "%s ", type_ops->tt_dump_prefix);
893 
894  nl_dump(p, "%s ", tc->tc_kind);
895 
896  if ((link_cache = nl_cache_mngt_require_safe("route/link"))) {
897  nl_dump(p, "dev %s ",
898  rtnl_link_i2name(link_cache, tc->tc_ifindex,
899  buf, sizeof(buf)));
900  } else
901  nl_dump(p, "dev %u ", tc->tc_ifindex);
902 
903  nl_dump(p, "id %s ",
904  rtnl_tc_handle2str(tc->tc_handle, buf, sizeof(buf)));
905 
906  nl_dump(p, "parent %s",
907  rtnl_tc_handle2str(tc->tc_parent, buf, sizeof(buf)));
908 
909  tc_dump(tc, NL_DUMP_LINE, p);
910  nl_dump(p, "\n");
911 
912  if (link_cache)
913  nl_cache_put(link_cache);
914 }
915 
916 void rtnl_tc_dump_details(struct nl_object *obj, struct nl_dump_params *p)
917 {
918  struct rtnl_tc *tc = TC_CAST(obj);
919 
920  rtnl_tc_dump_line(OBJ_CAST(tc), p);
921 
922  nl_dump_line(p, " ");
923 
924  if (tc->ce_mask & TCA_ATTR_MTU)
925  nl_dump(p, " mtu %u", tc->tc_mtu);
926 
927  if (tc->ce_mask & TCA_ATTR_MPU)
928  nl_dump(p, " mpu %u", tc->tc_mpu);
929 
930  if (tc->ce_mask & TCA_ATTR_OVERHEAD)
931  nl_dump(p, " overhead %u", tc->tc_overhead);
932 
933  if (!tc_dump(tc, NL_DUMP_DETAILS, p))
934  nl_dump(p, "no options");
935  nl_dump(p, "\n");
936 }
937 
938 void rtnl_tc_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
939 {
940  struct rtnl_tc *tc = TC_CAST(obj);
941  char *unit;
942  float res;
943 
944  rtnl_tc_dump_details(OBJ_CAST(tc), p);
945 
946  nl_dump_line(p,
947  " stats: %-14s %-10s %-10s %-10s %-10s %-10s\n",
948  "bytes", "packets", "drops", "overlimits", "qlen", "backlog");
949 
950  res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_BYTES], &unit);
951 
952  nl_dump_line(p,
953  " %10.2f %3s %10u %-10u %-10u %-10u %-10u\n",
954  res, unit,
955  tc->tc_stats[RTNL_TC_PACKETS],
956  tc->tc_stats[RTNL_TC_DROPS],
957  tc->tc_stats[RTNL_TC_OVERLIMITS],
958  tc->tc_stats[RTNL_TC_QLEN],
959  tc->tc_stats[RTNL_TC_BACKLOG]);
960 
961  res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_RATE_BPS], &unit);
962 
963  nl_dump_line(p,
964  " %10.2f %3s/s %10u/s\n",
965  res,
966  unit,
967  tc->tc_stats[RTNL_TC_RATE_PPS]);
968 }
969 
970 uint64_t rtnl_tc_compare(struct nl_object *aobj, struct nl_object *bobj,
971  uint64_t attrs, int flags)
972 {
973  struct rtnl_tc *a = TC_CAST(aobj);
974  struct rtnl_tc *b = TC_CAST(bobj);
975  uint64_t diff = 0;
976 
977 #define TC_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, TCA_ATTR_##ATTR, a, b, EXPR)
978 
979  diff |= TC_DIFF(HANDLE, a->tc_handle != b->tc_handle);
980  diff |= TC_DIFF(PARENT, a->tc_parent != b->tc_parent);
981  diff |= TC_DIFF(IFINDEX, a->tc_ifindex != b->tc_ifindex);
982  diff |= TC_DIFF(KIND, strcmp(a->tc_kind, b->tc_kind));
983 
984 #undef TC_DIFF
985 
986  return diff;
987 }
988 
989 /** @} */
990 
991 /**
992  * @name Modules API
993  */
994 
995 struct rtnl_tc_ops *rtnl_tc_lookup_ops(enum rtnl_tc_type type, const char *kind)
996 {
997  struct rtnl_tc_ops *ops;
998 
999  nl_list_for_each_entry(ops, &tc_ops_list[type], to_list)
1000  if (!strcmp(kind, ops->to_kind))
1001  return ops;
1002 
1003  return NULL;
1004 }
1005 
1006 struct rtnl_tc_ops *rtnl_tc_get_ops(struct rtnl_tc *tc)
1007 {
1008  if (!tc->tc_ops)
1009  tc->tc_ops = rtnl_tc_lookup_ops(tc->tc_type, tc->tc_kind);
1010 
1011  return tc->tc_ops;
1012 }
1013 
1014 /**
1015  * Register a traffic control module
1016  * @arg ops traffic control module operations
1017  */
1018 int rtnl_tc_register(struct rtnl_tc_ops *ops)
1019 {
1020  static int init = 0;
1021 
1022  /*
1023  * Initialiation hack, make sure list is initialized when
1024  * the first tc module registers. Putting this in a
1025  * separate __init would required correct ordering of init
1026  * functions
1027  */
1028  if (!init) {
1029  int i;
1030 
1031  for (i = 0; i < __RTNL_TC_TYPE_MAX; i++)
1032  nl_init_list_head(&tc_ops_list[i]);
1033 
1034  init = 1;
1035  }
1036 
1037  if (!ops->to_kind || ops->to_type > RTNL_TC_TYPE_MAX)
1038  BUG();
1039 
1040  if (rtnl_tc_lookup_ops(ops->to_type, ops->to_kind))
1041  return -NLE_EXIST;
1042 
1043  nl_list_add_tail(&ops->to_list, &tc_ops_list[ops->to_type]);
1044 
1045  return 0;
1046 }
1047 
1048 /**
1049  * Unregister a traffic control module
1050  * @arg ops traffic control module operations
1051  */
1052 void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
1053 {
1054  nl_list_del(&ops->to_list);
1055 }
1056 
1057 /**
1058  * Returns the private data of the traffic control object.
1059  * Contrary to rtnl_tc_data(), this returns NULL if the data is
1060  * not yet allocated
1061  * @arg tc traffic control object
1062  *
1063  * @return pointer to the private data or NULL if not allocated.
1064  */
1065 void *rtnl_tc_data_peek(struct rtnl_tc *tc)
1066 {
1067  return tc->tc_subdata ? nl_data_get(tc->tc_subdata) : NULL;
1068 }
1069 
1070 /**
1071  * Return pointer to private data of traffic control object
1072  * @arg tc traffic control object
1073  *
1074  * Allocates the private traffic control object data section
1075  * as necessary and returns it.
1076  *
1077  * @return Pointer to private tc data or NULL if allocation failed.
1078  */
1079 void *rtnl_tc_data(struct rtnl_tc *tc)
1080 {
1081  if (!tc->tc_subdata) {
1082  size_t size;
1083 
1084  if (!tc->tc_ops) {
1085  if (!rtnl_tc_get_ops(tc))
1086  return NULL;
1087  }
1088 
1089  if (!(size = tc->tc_ops->to_size))
1090  BUG();
1091 
1092  if (!(tc->tc_subdata = nl_data_alloc(NULL, size)))
1093  return NULL;
1094  }
1095 
1096  return nl_data_get(tc->tc_subdata);
1097 }
1098 
1099 /**
1100  * Check traffic control object type and return private data section
1101  * @arg tc traffic control object
1102  * @arg ops expected traffic control object operations
1103  * @arg err the place where saves the error code if fails
1104  *
1105  * Checks whether the traffic control object matches the type
1106  * specified with the traffic control object operations. If the
1107  * type matches, the private tc object data is returned. If type
1108  * mismatches, APPBUG() will print a application bug warning.
1109  *
1110  * @see rtnl_tc_data()
1111  *
1112  * @return Pointer to private tc data or NULL if type mismatches.
1113  */
1114 void *rtnl_tc_data_check(struct rtnl_tc *tc, struct rtnl_tc_ops *ops, int *err)
1115 {
1116  void *ret;
1117 
1118  if (tc->tc_ops != ops) {
1119  char buf[64];
1120 
1121  snprintf(buf, sizeof(buf),
1122  "tc object %p used in %s context but is of type %s",
1123  tc, ops->to_kind, tc->tc_ops->to_kind);
1124  APPBUG(buf);
1125 
1126  if (err)
1127  *err = -NLE_OPNOTSUPP;
1128  return NULL;
1129  }
1130 
1131  ret = rtnl_tc_data(tc);
1132  if (ret == NULL) {
1133  if (err)
1134  *err = -NLE_NOMEM;
1135  }
1136 
1137  return ret;
1138 }
1139 
1140 struct nl_af_group tc_groups[] = {
1141  { AF_UNSPEC, RTNLGRP_TC },
1142  { END_OF_GROUP_LIST },
1143 };
1144 
1145 
1146 void rtnl_tc_type_register(struct rtnl_tc_type_ops *ops)
1147 {
1148  if (ops->tt_type > RTNL_TC_TYPE_MAX)
1149  BUG();
1150 
1151  tc_type_ops[ops->tt_type] = ops;
1152 }
1153 
1154 void rtnl_tc_type_unregister(struct rtnl_tc_type_ops *ops)
1155 {
1156  if (ops->tt_type > RTNL_TC_TYPE_MAX)
1157  BUG();
1158 
1159  tc_type_ops[ops->tt_type] = NULL;
1160 }
1161 
1162 /** @} */
1163 
1164 /** @} */
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
Definition: attr.c:699
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, const struct nla_policy *policy)
Create attribute index based on a stream of attributes.
Definition: attr.c:236
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
Definition: attr.h:230
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
Definition: attr.c:895
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload to a buffer.
Definition: attr.c:371
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
Definition: attr.c:1013
#define NLA_PUT_STRING(msg, attrtype, value)
Add string attribute to netlink message.
Definition: attr.h:257
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
Definition: attr.c:958
int nla_nest_end_keep_empty(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes without stripping off empty attributes.
Definition: attr.c:973
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
Definition: attr.c:114
@ NLA_STRING
NUL terminated character string.
Definition: attr.h:39
@ NLA_NESTED
Nested attributes.
Definition: attr.h:42
@ NLA_U32
32 bit integer
Definition: attr.h:37
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
Definition: cache_mngt.c:424
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:103
struct nl_data * nl_data_alloc(const void *buf, size_t size)
Allocate a new abstract data object.
Definition: data.c:44
struct nl_data * nl_data_clone(const struct nl_data *src)
Clone an abstract data object.
Definition: data.c:89
void nl_data_free(struct nl_data *data)
Free an abstract data object.
Definition: data.c:128
void * nl_data_get(const struct nl_data *data)
Get data buffer of abstract data object.
Definition: data.c:148
struct nl_data * nl_data_alloc_attr(const struct nlattr *nla)
Allocate abstract data object based on netlink attribute.
Definition: data.c:78
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
Definition: msg.c:341
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
Definition: msg.c:558
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, const struct nla_policy *policy)
parse attributes of a netlink message
Definition: msg.c:208
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition: msg.c:442
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
Definition: msg.c:100
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:203
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:393
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
Definition: tc.c:511
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
Definition: tc.c:1079
void rtnl_tc_set_linktype(struct rtnl_tc *tc, uint32_t type)
Set the linktype of a traffic control object.
Definition: tc.c:450
int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
Define the type of traffic control object.
Definition: tc.c:523
int rtnl_tc_calc_cell_log(int cell_size)
Calculate the binary logarithm for a specific cell size.
Definition: tc.c:671
int rtnl_tc_get_chain(struct rtnl_tc *tc, uint32_t *out_value)
Return chain index of traffic control object.
Definition: tc.c:591
void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
Set interface index of traffic control object.
Definition: tc.c:272
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:745
void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
Set per packet overhead of a traffic control object.
Definition: tc.c:422
int rtnl_tc_calc_bufsize(int txtime, int rate)
Calculate buffer size able to transmit in a specific time and rate.
Definition: tc.c:661
void * rtnl_tc_data_peek(struct rtnl_tc *tc)
Returns the private data of the traffic control object.
Definition: tc.c:1065
uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
Return the MTU of traffic control object.
Definition: tc.c:373
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
Definition: tc.c:287
void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
Set link of traffic control object.
Definition: tc.c:304
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
Definition: tc.c:490
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
Definition: tc.h:50
char * rtnl_tc_get_kind(struct rtnl_tc *tc)
Return kind of traffic control object.
Definition: tc.c:548
uint32_t rtnl_tc_get_overhead(struct rtnl_tc *tc)
Return per packet overhead of a traffic control object.
Definition: tc.c:434
struct rtnl_link * rtnl_tc_get_link(struct rtnl_tc *tc)
Get link of traffic control object.
Definition: tc.c:335
void rtnl_tc_set_handle(struct rtnl_tc *tc, uint32_t id)
Set identifier of traffic control object.
Definition: tc.c:480
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
Set the parent identifier of a traffic control object.
Definition: tc.c:501
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Definition: tc.c:1018
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
Definition: tc.c:1052
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:1114
void rtnl_tc_set_mtu(struct rtnl_tc *tc, uint32_t mtu)
Set the Maximum Transmission Unit (MTU) of traffic control object.
Definition: tc.c:358
void rtnl_tc_set_chain(struct rtnl_tc *tc, uint32_t chain)
Set the chain index of a traffic control object.
Definition: tc.c:577
uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
Return value of a statistical counter of a traffic control object.
Definition: tc.c:563
rtnl_tc_stat
Traffic control statistical identifier.
Definition: tc.h:60
uint32_t rtnl_tc_get_linktype(struct rtnl_tc *tc)
Return the linktype of a traffic control object.
Definition: tc.c:465
uint32_t rtnl_tc_get_mpu(struct rtnl_tc *tc)
Return the Minimum Packet Unit (MPU) of a traffic control object.
Definition: tc.c:405
int rtnl_tc_calc_txtime(int bufsize, int rate)
Calculate time required to transmit buffer at a specific rate.
Definition: tc.c:642
@ RTNL_TC_PACKETS
Number of packets seen.
Definition: tc.h:61
@ RTNL_TC_BYTES
Total bytes seen.
Definition: tc.h:62
@ RTNL_TC_QLEN
Current queue length.
Definition: tc.h:65
@ RTNL_TC_OVERLIMITS
Total number of overlimits.
Definition: tc.h:69
@ RTNL_TC_DROPS
Total number of packets dropped.
Definition: tc.h:67
@ RTNL_TC_RATE_PPS
Current packet/s (rate estimator)
Definition: tc.h:64
@ RTNL_TC_REQUEUES
Total number of requeues.
Definition: tc.h:68
@ RTNL_TC_BACKLOG
Current backlog length.
Definition: tc.h:66
@ RTNL_TC_RATE_BPS
Current bits/s (rate estimator)
Definition: tc.h:63
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition: utils.c:955
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
Definition: utils.c:163
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
Definition: utils.c:906
nl_dump_type
Enumeration of dumping variations (dp_type)
Definition: types.h:15
uint32_t nl_us2ticks(uint32_t us)
Convert micro seconds to ticks.
Definition: utils.c:522
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition: types.h:16
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Definition: types.h:17
Dumping parameters.
Definition: types.h:28
Attribute validation policy.
Definition: attr.h:63
uint16_t minlen
Minimal length of payload required.
Definition: attr.h:68
uint16_t type
Type of attribute or NLA_UNSPEC.
Definition: attr.h:65