libnl  3.2.26
utils.h
1 /*
2  * netlink/utils.h Utility Functions
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-2012 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #ifndef NETLINK_UTILS_H_
13 #define NETLINK_UTILS_H_
14 
15 #include <netlink/netlink.h>
16 #include <netlink/list.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @name Probability Constants
24  * @{
25  */
26 
27 /**
28  * Lower probability limit
29  * @ingroup utils
30  */
31 #define NL_PROB_MIN 0x0
32 
33 /**
34  * Upper probability limit nl_dump_type
35  * @ingroup utils
36  */
37 #define NL_PROB_MAX 0xffffffff
38 
39 /** @} */
40 
41 enum {
42  NL_BYTE_RATE,
43  NL_BIT_RATE,
44 };
45 
46 /* unit pretty-printing */
47 extern double nl_cancel_down_bytes(unsigned long long, char **);
48 extern double nl_cancel_down_bits(unsigned long long, char **);
49 extern int nl_rate2str(unsigned long long, int, char *, size_t);
50 extern double nl_cancel_down_us(uint32_t, char **);
51 
52 /* generic unit translations */
53 extern long nl_size2int(const char *);
54 extern char * nl_size2str(const size_t, char *, const size_t);
55 extern long nl_prob2int(const char *);
56 
57 /* time translations */
58 extern int nl_get_user_hz(void);
59 extern int nl_get_psched_hz(void);
60 extern uint32_t nl_us2ticks(uint32_t);
61 extern uint32_t nl_ticks2us(uint32_t);
62 extern int nl_str2msec(const char *, uint64_t *);
63 extern char * nl_msec2str(uint64_t, char *, size_t);
64 
65 /* link layer protocol translations */
66 extern char * nl_llproto2str(int, char *, size_t);
67 extern int nl_str2llproto(const char *);
68 
69 /* ethernet protocol translations */
70 extern char * nl_ether_proto2str(int, char *, size_t);
71 extern int nl_str2ether_proto(const char *);
72 
73 /* IP protocol translations */
74 extern char * nl_ip_proto2str(int, char *, size_t);
75 extern int nl_str2ip_proto(const char *);
76 
77 /* Dumping helpers */
78 extern void nl_new_line(struct nl_dump_params *);
79 extern void nl_dump(struct nl_dump_params *, const char *, ...);
80 extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
81 
82 enum {
83  NL_CAPABILITY_NONE,
84 
85  /**
86  * rtnl_route_build_msg() no longer guesses the route scope
87  * if explicitly set to RT_SCOPE_NOWHERE.
88  * @ingroup utils
89  */
91 #define NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE
92 
93  /**
94  * rtnl_link_veth_get_peer() now returns a reference that is owned by the
95  * caller and must be released by the caller with rtnl_link_put().
96  */
97  NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE = 2,
98 #define NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE
99 
100  /**
101  * rtnl_u32_add_action() and rtnl_basic_add_action() now grab a reference to act
102  * caller are free to release its own
103  */
104  NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE = 3,
105 #define NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE
106 
107  /**
108  * Indicate that the local port is unspecified until the user accesses
109  * it (via nl_socket_get_local_port()) or until nl_connect(). More importantly,
110  * if the port is left unspecified, nl_connect() will retry generating another
111  * port when bind() fails with ADDRINUSE.
112  */
113  NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE = 4,
114 #define NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE
115 
116  /**
117  * Indicate that rtnl_link_get_kernel() fails with -NLE_OPNOTSUPP in case
118  * of older kernals not supporting lookup by ifname. This changes behavior
119  * from returning -NLE_INVAL to return -NLE_OPNOTSUPP.
120  */
121  NL_CAPABILITY_ROUTE_LINK_GET_KERNEL_FAIL_OPNOTSUPP = 5,
122 #define NL_CAPABILITY_ROUTE_LINK_GET_KERNEL_FAIL_OPNOTSUPP NL_CAPABILITY_ROUTE_LINK_GET_KERNEL_FAIL_OPNOTSUPP
123 
124  /**
125  * Also consider the a_cacheinfo field (ADDR_ATTR_CACHEINFO) that contains the
126  * address timestamps and expiry when comparing struct rtnl_addr objects with
127  * nl_object_diff().
128  */
129  NL_CAPABILITY_ROUTE_ADDR_COMPARE_CACHEINFO = 6,
130 #define NL_CAPABILITY_ROUTE_ADDR_COMPARE_CACHEINFO NL_CAPABILITY_ROUTE_ADDR_COMPARE_CACHEINFO
131 
132  /**
133  * The library version is libnl3 3.2.26 or newer. This capability should never be backported.
134  */
135  NL_CAPABILITY_VERSION_3_2_26 = 7,
136 #define NL_CAPABILITY_VERSION_3_2_26 NL_CAPABILITY_VERSION_3_2_26
137 
138  __NL_CAPABILITY_MAX,
139  NL_CAPABILITY_MAX = (__NL_CAPABILITY_MAX - 1),
140 #define NL_CAPABILITY_MAX NL_CAPABILITY_MAX
141 
142  /**
143  * The range 0x7000 to 0x7FFF is reserved for private capabilities. Upstream libnl3 will
144  * not register capabilities in this range. However, instead of adding private capabilities,
145  * better register their number with upstream libnl3. */
146 #define NL_CAPABILITY_IS_USER_RESERVED(cap) ( ((cap) & ~0x0FFF) == 0x7000 )
147 };
148 int nl_has_capability (int capability);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif
int nl_get_user_hz(void)
Return the value of HZ.
Definition: utils.c:465
void nl_new_line(struct nl_dump_params *)
Handle a new line while dumping.
Definition: utils.c:866
rtnl_route_build_msg() no longer guesses the route scope if explicitly set to RT_SCOPE_NOWHERE.
Definition: utils.h:90
long nl_size2int(const char *)
Convert a character string to a size.
Definition: utils.c:264
double nl_cancel_down_bits(unsigned long long, char **)
Cancel down a bit counter.
Definition: utils.c:170
char * nl_msec2str(uint64_t, char *, size_t)
Convert milliseconds to a character string.
Definition: utils.c:547
char * nl_size2str(const size_t, char *, const size_t)
Convert a size toa character string.
Definition: utils.c:327
double nl_cancel_down_bytes(unsigned long long, char **)
Cancel down a byte counter.
Definition: utils.c:139
double nl_cancel_down_us(uint32_t, char **)
Cancel down a micro second value.
Definition: utils.c:227
int nl_get_psched_hz(void)
Return the value of packet scheduler HZ.
Definition: utils.c:473
uint32_t nl_ticks2us(uint32_t)
Convert ticks to micro seconds.
Definition: utils.c:494
long nl_prob2int(const char *)
Convert a character string to a probability.
Definition: utils.c:361
uint32_t nl_us2ticks(uint32_t)
Convert micro seconds to ticks.
Definition: utils.c:483
Dumping parameters.
Definition: types.h:33
void nl_dump(struct nl_dump_params *, const char *,...)
Dump a formatted character string.
Definition: utils.c:915