• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * netlink/route/link.h		Links (Interfaces)
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_LINK_H_
13 #define NETLINK_LINK_H_
14 
15 #include <netlink/netlink.h>
16 #include <netlink/cache.h>
17 #include <netlink/addr.h>
18 #include <linux/if.h>
19 #include <sys/types.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @struct rtnl_link link.h "netlink/route/link.h"
27  * @brief Link object
28  * @implements nl_object
29  * @ingroup link
30  *
31  * @copydoc private_struct
32  */
33 struct rtnl_link;
34 
35 /**
36  * @ingroup link
37  */
38 typedef enum {
39 	RTNL_LINK_RX_PACKETS,		/*!< Packets received */
40 	RTNL_LINK_TX_PACKETS,		/*!< Packets sent */
41 	RTNL_LINK_RX_BYTES,		/*!< Bytes received */
42 	RTNL_LINK_TX_BYTES,		/*!< Bytes sent */
43 	RTNL_LINK_RX_ERRORS,		/*!< Receive errors */
44 	RTNL_LINK_TX_ERRORS,		/*!< Send errors */
45 	RTNL_LINK_RX_DROPPED,		/*!< Received packets dropped */
46 	RTNL_LINK_TX_DROPPED,		/*!< Packets dropped during transmit */
47 	RTNL_LINK_RX_COMPRESSED,	/*!< Compressed packets received */
48 	RTNL_LINK_TX_COMPRESSED,	/*!< Compressed packets sent */
49 	RTNL_LINK_RX_FIFO_ERR,		/*!< Receive FIFO errors */
50 	RTNL_LINK_TX_FIFO_ERR,		/*!< Send FIFO errors */
51 	RTNL_LINK_RX_LEN_ERR,		/*!< Length errors */
52 	RTNL_LINK_RX_OVER_ERR,		/*!< Over errors */
53 	RTNL_LINK_RX_CRC_ERR,		/*!< CRC errors */
54 	RTNL_LINK_RX_FRAME_ERR,		/*!< Frame errors */
55 	RTNL_LINK_RX_MISSED_ERR,	/*!< Missed errors */
56 	RTNL_LINK_TX_ABORT_ERR,		/*!< Aborted errors */
57 	RTNL_LINK_TX_CARRIER_ERR,	/*!< Carrier errors */
58 	RTNL_LINK_TX_HBEAT_ERR,		/*!< Heartbeat errors */
59 	RTNL_LINK_TX_WIN_ERR,		/*!< Window errors */
60 	RTNL_LINK_COLLISIONS,		/*!< Send collisions */
61 	RTNL_LINK_MULTICAST,		/*!< Multicast */
62 	RTNL_LINK_IP6_INPKTS,		/*!< IPv6 SNMP InReceives */
63 	RTNL_LINK_IP6_INHDRERRORS,	/*!< IPv6 SNMP InHdrErrors */
64 	RTNL_LINK_IP6_INTOOBIGERRORS,	/*!< IPv6 SNMP InTooBigErrors */
65 	RTNL_LINK_IP6_INNOROUTES,	/*!< IPv6 SNMP InNoRoutes */
66 	RTNL_LINK_IP6_INADDRERRORS,	/*!< IPv6 SNMP InAddrErrors */
67 	RTNL_LINK_IP6_INUNKNOWNPROTOS,	/*!< IPv6 SNMP InUnknownProtos */
68 	RTNL_LINK_IP6_INTRUNCATEDPKTS,	/*!< IPv6 SNMP InTruncatedPkts */
69 	RTNL_LINK_IP6_INDISCARDS,	/*!< IPv6 SNMP InDiscards */
70 	RTNL_LINK_IP6_INDELIVERS,	/*!< IPv6 SNMP InDelivers */
71 	RTNL_LINK_IP6_OUTFORWDATAGRAMS,	/*!< IPv6 SNMP OutForwDatagrams */
72 	RTNL_LINK_IP6_OUTPKTS,		/*!< IPv6 SNMP OutRequests */
73 	RTNL_LINK_IP6_OUTDISCARDS,	/*!< IPv6 SNMP OutDiscards */
74 	RTNL_LINK_IP6_OUTNOROUTES,	/*!< IPv6 SNMP OutNoRoutes */
75 	RTNL_LINK_IP6_REASMTIMEOUT,	/*!< IPv6 SNMP ReasmTimeout */
76 	RTNL_LINK_IP6_REASMREQDS,	/*!< IPv6 SNMP ReasmReqds */
77 	RTNL_LINK_IP6_REASMOKS,		/*!< IPv6 SNMP ReasmOKs */
78 	RTNL_LINK_IP6_REASMFAILS,	/*!< IPv6 SNMP ReasmFails */
79 	RTNL_LINK_IP6_FRAGOKS,		/*!< IPv6 SNMP FragOKs */
80 	RTNL_LINK_IP6_FRAGFAILS,	/*!< IPv6 SNMP FragFails */
81 	RTNL_LINK_IP6_FRAGCREATES,	/*!< IPv6 SNMP FragCreates */
82 	RTNL_LINK_IP6_INMCASTPKTS,	/*!< IPv6 SNMP InMcastPkts */
83 	RTNL_LINK_IP6_OUTMCASTPKTS,	/*!< IPv6 SNMP OutMcastPkts */
84 	RTNL_LINK_IP6_INBCASTPKTS,	/*!< IPv6 SNMP InBcastPkts */
85 	RTNL_LINK_IP6_OUTBCASTPKTS,	/*!< IPv6 SNMP OutBcastPkts */
86 	RTNL_LINK_IP6_INOCTETS,		/*!< IPv6 SNMP InOctets */
87 	RTNL_LINK_IP6_OUTOCTETS,	/*!< IPv6 SNMP OutOctets */
88 	RTNL_LINK_IP6_INMCASTOCTETS,	/*!< IPv6 SNMP InMcastOctets */
89 	RTNL_LINK_IP6_OUTMCASTOCTETS,	/*!< IPv6 SNMP OutMcastOctets */
90 	RTNL_LINK_IP6_INBCASTOCTETS,	/*!< IPv6 SNMP InBcastOctets */
91 	RTNL_LINK_IP6_OUTBCASTOCTETS,	/*!< IPv6 SNMP OutBcastOctets */
92 	RTNL_LINK_ICMP6_INMSGS,		/*!< ICMPv6 SNMP InMsgs */
93 	RTNL_LINK_ICMP6_INERRORS,	/*!< ICMPv6 SNMP InErrors */
94 	RTNL_LINK_ICMP6_OUTMSGS,	/*!< ICMPv6 SNMP OutMsgs */
95 	RTNL_LINK_ICMP6_OUTERRORS,	/*!< ICMPv6 SNMP OutErrors */
96 	RTNL_LINK_ICMP6_CSUMERRORS,	/*!< ICMPv6 SNMP InCsumErrors */
97 	RTNL_LINK_IP6_CSUMERRORS,	/*!< IPv6 SNMP InCsumErrors */
98 	RTNL_LINK_IP6_NOECTPKTS,	/*!< IPv6 SNMP InNoECTPkts */
99 	RTNL_LINK_IP6_ECT1PKTS,		/*!< IPv6 SNMP InECT1Pkts */
100 	RTNL_LINK_IP6_ECT0PKTS,		/*!< IPv6 SNMP InECT0Pkts */
101 	RTNL_LINK_IP6_CEPKTS,		/*!< IPv6 SNMP InCEPkts */
102 	__RTNL_LINK_STATS_MAX,
103 } rtnl_link_stat_id_t;
104 
105 #define RTNL_LINK_STATS_MAX (__RTNL_LINK_STATS_MAX - 1)
106 
107 extern struct nla_policy rtln_link_policy[];
108 
109 extern struct rtnl_link *rtnl_link_alloc(void);
110 extern void	rtnl_link_put(struct rtnl_link *);
111 
112 extern int	rtnl_link_alloc_cache(struct nl_sock *, int, struct nl_cache **);
113 extern struct rtnl_link *rtnl_link_get(struct nl_cache *, int);
114 extern struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *, const char *);
115 
116 
117 extern int	rtnl_link_build_add_request(struct rtnl_link *, int,
118 					    struct nl_msg **);
119 extern int	rtnl_link_add(struct nl_sock *, struct rtnl_link *, int);
120 extern int	rtnl_link_build_change_request(struct rtnl_link *,
121 					       struct rtnl_link *, int,
122 					       struct nl_msg **);
123 extern int	rtnl_link_change(struct nl_sock *, struct rtnl_link *,
124 				 struct rtnl_link *, int);
125 
126 extern int	rtnl_link_build_delete_request(const struct rtnl_link *,
127 					       struct nl_msg **);
128 extern int	rtnl_link_delete(struct nl_sock *, const struct rtnl_link *);
129 extern int	rtnl_link_build_get_request(int, const char *,
130 					    struct nl_msg **);
131 extern int	rtnl_link_get_kernel(struct nl_sock *, int, const char *,
132 				     struct rtnl_link **);
133 
134 /* Name <-> Index Translations */
135 extern char * 	rtnl_link_i2name(struct nl_cache *, int, char *, size_t);
136 extern int	rtnl_link_name2i(struct nl_cache *, const char *);
137 
138 /* Name <-> Statistic Translations */
139 extern char *	rtnl_link_stat2str(int, char *, size_t);
140 extern int	rtnl_link_str2stat(const char *);
141 
142 /* Link Flags Translations */
143 extern char *	rtnl_link_flags2str(int, char *, size_t);
144 extern int	rtnl_link_str2flags(const char *);
145 
146 extern char *	rtnl_link_operstate2str(uint8_t, char *, size_t);
147 extern int	rtnl_link_str2operstate(const char *);
148 
149 extern char *	rtnl_link_mode2str(uint8_t, char *, size_t);
150 extern int	rtnl_link_str2mode(const char *);
151 
152 /* Carrier State Translations */
153 extern char *	rtnl_link_carrier2str(uint8_t, char *, size_t);
154 extern int	rtnl_link_str2carrier(const char *);
155 
156 /* Access Functions */
157 extern void	rtnl_link_set_qdisc(struct rtnl_link *, const char *);
158 extern char *	rtnl_link_get_qdisc(struct rtnl_link *);
159 
160 extern void	rtnl_link_set_name(struct rtnl_link *, const char *);
161 extern char *	rtnl_link_get_name(struct rtnl_link *);
162 
163 extern void	rtnl_link_set_group(struct rtnl_link *, uint32_t);
164 extern uint32_t	rtnl_link_get_group(struct rtnl_link *);
165 
166 extern void	rtnl_link_set_flags(struct rtnl_link *, unsigned int);
167 extern void	rtnl_link_unset_flags(struct rtnl_link *, unsigned int);
168 extern unsigned int rtnl_link_get_flags(struct rtnl_link *);
169 
170 extern void	rtnl_link_set_mtu(struct rtnl_link *, unsigned int);
171 extern unsigned int rtnl_link_get_mtu(struct rtnl_link *);
172 
173 extern void	rtnl_link_set_txqlen(struct rtnl_link *, unsigned int);
174 extern unsigned int rtnl_link_get_txqlen(struct rtnl_link *);
175 
176 extern void	rtnl_link_set_ifindex(struct rtnl_link *, int);
177 extern int	rtnl_link_get_ifindex(struct rtnl_link *);
178 
179 extern void	rtnl_link_set_family(struct rtnl_link *, int);
180 extern int	rtnl_link_get_family(struct rtnl_link *);
181 
182 extern void	rtnl_link_set_arptype(struct rtnl_link *, unsigned int);
183 extern unsigned int rtnl_link_get_arptype(struct rtnl_link *);
184 
185 extern void	rtnl_link_set_addr(struct rtnl_link *, struct nl_addr *);
186 extern struct nl_addr *rtnl_link_get_addr(struct rtnl_link *);
187 
188 extern void	rtnl_link_set_broadcast(struct rtnl_link *, struct nl_addr *);
189 extern struct nl_addr *rtnl_link_get_broadcast(struct rtnl_link *);
190 
191 extern void	rtnl_link_set_link(struct rtnl_link *, int);
192 extern int	rtnl_link_get_link(struct rtnl_link *);
193 
194 extern void	rtnl_link_set_master(struct rtnl_link *, int);
195 extern int	rtnl_link_get_master(struct rtnl_link *);
196 
197 extern void	rtnl_link_set_carrier(struct rtnl_link *, uint8_t);
198 extern uint8_t	rtnl_link_get_carrier(struct rtnl_link *);
199 
200 extern void	rtnl_link_set_operstate(struct rtnl_link *, uint8_t);
201 extern uint8_t	rtnl_link_get_operstate(struct rtnl_link *);
202 
203 extern void	rtnl_link_set_linkmode(struct rtnl_link *, uint8_t);
204 extern uint8_t	rtnl_link_get_linkmode(struct rtnl_link *);
205 
206 extern const char *	rtnl_link_get_ifalias(struct rtnl_link *);
207 extern void		rtnl_link_set_ifalias(struct rtnl_link *, const char *);
208 
209 extern int		rtnl_link_get_num_vf(struct rtnl_link *, uint32_t *);
210 
211 extern uint64_t rtnl_link_get_stat(struct rtnl_link *, rtnl_link_stat_id_t);
212 extern int	rtnl_link_set_stat(struct rtnl_link *, rtnl_link_stat_id_t,
213 				   const uint64_t);
214 
215 extern int	rtnl_link_set_type(struct rtnl_link *, const char *);
216 extern char *	rtnl_link_get_type(struct rtnl_link *);
217 
218 extern void	rtnl_link_set_promiscuity(struct rtnl_link *, uint32_t);
219 extern uint32_t	rtnl_link_get_promiscuity(struct rtnl_link *);
220 
221 extern void	rtnl_link_set_num_tx_queues(struct rtnl_link *, uint32_t);
222 extern uint32_t	rtnl_link_get_num_tx_queues(struct rtnl_link *);
223 
224 extern void	rtnl_link_set_num_rx_queues(struct rtnl_link *, uint32_t);
225 extern uint32_t	rtnl_link_get_num_rx_queues(struct rtnl_link *);
226 
227 extern struct nl_data *	rtnl_link_get_phys_port_id(struct rtnl_link *);
228 
229 extern void	rtnl_link_set_ns_fd(struct rtnl_link *, int);
230 extern int	rtnl_link_get_ns_fd(struct rtnl_link *);
231 extern void	rtnl_link_set_ns_pid(struct rtnl_link *, pid_t);
232 extern pid_t	rtnl_link_get_ns_pid(struct rtnl_link *);
233 
234 extern int	rtnl_link_enslave_ifindex(struct nl_sock *, int, int);
235 extern int	rtnl_link_enslave(struct nl_sock *, struct rtnl_link *,
236 				  struct rtnl_link *);
237 extern int	rtnl_link_release_ifindex(struct nl_sock *, int);
238 extern int	rtnl_link_release(struct nl_sock *, struct rtnl_link *);
239 extern int	rtnl_link_fill_info(struct nl_msg *, struct rtnl_link *);
240 extern int	rtnl_link_info_parse(struct rtnl_link *, struct nlattr **);
241 
242 
243 /* deprecated */
244 extern int	rtnl_link_set_info_type(struct rtnl_link *, const char *) __attribute__((deprecated));
245 extern char *	rtnl_link_get_info_type(struct rtnl_link *) __attribute__((deprecated));
246 extern void	rtnl_link_set_weight(struct rtnl_link *, unsigned int) __attribute__((deprecated));
247 extern unsigned int rtnl_link_get_weight(struct rtnl_link *) __attribute__((deprecated));
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif
255