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