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