tc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * netlink/route/tc.h Traffic Control
  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. */
  11. #ifndef NETLINK_TC_H_
  12. #define NETLINK_TC_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/cache.h>
  15. #include <netlink/data.h>
  16. #include <netlink/route/link.h>
  17. #include <linux/pkt_sched.h>
  18. #include <linux/pkt_cls.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. enum rtnl_tc_type {
  23. RTNL_TC_TYPE_QDISC,
  24. RTNL_TC_TYPE_CLASS,
  25. RTNL_TC_TYPE_CLS,
  26. __RTNL_TC_TYPE_MAX,
  27. };
  28. #define RTNL_TC_TYPE_MAX (__RTNL_TC_TYPE_MAX - 1)
  29. /**
  30. * Compute tc handle based on major and minor parts
  31. * @ingroup tc
  32. */
  33. #define TC_HANDLE(maj, min) (TC_H_MAJ((maj) << 16) | TC_H_MIN(min))
  34. /**
  35. * Traffic control object
  36. * @ingroup tc
  37. */
  38. struct rtnl_tc;
  39. /**
  40. * Macro to cast qdisc/class/classifier to tc object
  41. * @ingroup tc
  42. *
  43. * @code
  44. * rtnl_tc_set_mpu(TC_CAST(qdisc), 40);
  45. * @endcode
  46. */
  47. #define TC_CAST(ptr) ((struct rtnl_tc *) (ptr))
  48. /**
  49. * Traffic control statistical identifier
  50. * @ingroup tc
  51. *
  52. * @code
  53. * uint64_t n = rtnl_tc_get_stat(TC_CAST(class), RTNL_TC_PACKETS);
  54. * @endcode
  55. */
  56. enum rtnl_tc_stat {
  57. RTNL_TC_PACKETS, /**< Number of packets seen */
  58. RTNL_TC_BYTES, /**< Total bytes seen */
  59. RTNL_TC_RATE_BPS, /**< Current bits/s (rate estimator) */
  60. RTNL_TC_RATE_PPS, /**< Current packet/s (rate estimator) */
  61. RTNL_TC_QLEN, /**< Current queue length */
  62. RTNL_TC_BACKLOG, /**< Current backlog length */
  63. RTNL_TC_DROPS, /**< Total number of packets dropped */
  64. RTNL_TC_REQUEUES, /**< Total number of requeues */
  65. RTNL_TC_OVERLIMITS, /**< Total number of overlimits */
  66. __RTNL_TC_STATS_MAX,
  67. };
  68. #define RTNL_TC_STATS_MAX (__RTNL_TC_STATS_MAX - 1)
  69. extern void rtnl_tc_set_ifindex(struct rtnl_tc *, int);
  70. extern int rtnl_tc_get_ifindex(struct rtnl_tc *);
  71. extern void rtnl_tc_set_link(struct rtnl_tc *, struct rtnl_link *);
  72. extern struct rtnl_link *rtnl_tc_get_link(struct rtnl_tc *);
  73. extern void rtnl_tc_set_mtu(struct rtnl_tc *, uint32_t);
  74. extern uint32_t rtnl_tc_get_mtu(struct rtnl_tc *);
  75. extern void rtnl_tc_set_mpu(struct rtnl_tc *, uint32_t);
  76. extern uint32_t rtnl_tc_get_mpu(struct rtnl_tc *);
  77. extern void rtnl_tc_set_overhead(struct rtnl_tc *, uint32_t);
  78. extern uint32_t rtnl_tc_get_overhead(struct rtnl_tc *);
  79. extern void rtnl_tc_set_linktype(struct rtnl_tc *, uint32_t);
  80. extern uint32_t rtnl_tc_get_linktype(struct rtnl_tc *);
  81. extern void rtnl_tc_set_handle(struct rtnl_tc *, uint32_t);
  82. extern uint32_t rtnl_tc_get_handle(struct rtnl_tc *);
  83. extern void rtnl_tc_set_parent(struct rtnl_tc *, uint32_t);
  84. extern uint32_t rtnl_tc_get_parent(struct rtnl_tc *);
  85. extern int rtnl_tc_set_kind(struct rtnl_tc *, const char *);
  86. extern char * rtnl_tc_get_kind(struct rtnl_tc *);
  87. extern uint64_t rtnl_tc_get_stat(struct rtnl_tc *, enum rtnl_tc_stat);
  88. extern int rtnl_tc_calc_txtime(int, int);
  89. extern int rtnl_tc_calc_bufsize(int, int);
  90. extern int rtnl_tc_calc_cell_log(int);
  91. extern int rtnl_tc_read_classid_file(void);
  92. extern char * rtnl_tc_handle2str(uint32_t, char *, size_t);
  93. extern int rtnl_tc_str2handle(const char *, uint32_t *);
  94. extern int rtnl_classid_generate(const char *, uint32_t *,
  95. uint32_t);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif