interface.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. /*
  28. * Interface-related (RTM_<NEW|DEL|GET|SET>LINK) message header and attributes.
  29. */
  30. #ifndef _NETLINK_ROUTE_INTERFACE_H_
  31. #define _NETLINK_ROUTE_INTERFACE_H_
  32. /* Base header for all of the relevant messages */
  33. struct ifinfomsg {
  34. unsigned char ifi_family; /* not used */
  35. unsigned char __ifi_pad;
  36. unsigned short ifi_type; /* ARPHRD_* */
  37. int ifi_index; /* Inteface index */
  38. unsigned ifi_flags; /* IFF_* flags */
  39. unsigned ifi_change; /* IFF_* change mask */
  40. };
  41. /* Linux-specific link-level state flag */
  42. #define IFF_LOWER_UP IFF_NETLINK_1
  43. #ifndef _KERNEL
  44. /* Compatilbility helpers */
  45. #define _IFINFO_HDRLEN ((int)sizeof(struct ifinfomsg))
  46. #define IFLA_RTA(_ifi) ((struct rtattr *)NL_ITEM_DATA(_ifi, _IFINFO_HDRLEN))
  47. #define IFLA_PAYLOAD(_ifi) NLMSG_PAYLOAD(_ifi, _IFINFO_HDRLEN)
  48. #endif
  49. enum {
  50. IFLA_UNSPEC = 0,
  51. IFLA_ADDRESS = 1, /* binary: Link-level address (MAC) */
  52. #define IFLA_ADDRESS IFLA_ADDRESS
  53. IFLA_BROADCAST = 2, /* binary: link-level broadcast address */
  54. #define IFLA_BROADCAST IFLA_BROADCAST
  55. IFLA_IFNAME = 3, /* string: Interface name */
  56. #define IFLA_IFNAME IFLA_IFNAME
  57. IFLA_MTU = 4, /* u32: Current interface L3 mtu */
  58. #define IFLA_MTU IFLA_MTU
  59. IFLA_LINK = 5, /* u32: interface index */
  60. #define IFLA_LINK IFLA_LINK
  61. IFLA_QDISC = 6, /* string: Queing policy (not supported) */
  62. #define IFLA_QDISC IFLA_QDISC
  63. IFLA_STATS = 7, /* Interface counters */
  64. #define IFLA_STATS IFLA_STATS
  65. IFLA_COST = 8, /* not supported */
  66. #define IFLA_COST IFLA_COST
  67. IFLA_PRIORITY = 9, /* not supported */
  68. #define IFLA_PRIORITY IFLA_PRIORITY
  69. IFLA_MASTER = 10, /* u32: parent interface ifindex */
  70. #define IFLA_MASTER IFLA_MASTER
  71. IFLA_WIRELESS = 11, /* not supported */
  72. #define IFLA_WIRELESS IFLA_WIRELESS
  73. IFLA_PROTINFO = 12, /* protocol-specific data */
  74. #define IFLA_PROTINFO IFLA_PROTINFO
  75. IFLA_TXQLEN = 13, /* u32: transmit queue length */
  76. #define IFLA_TXQLEN IFLA_TXQLEN
  77. IFLA_MAP = 14, /* not supported */
  78. #define IFLA_MAP IFLA_MAP
  79. IFLA_WEIGHT = 15, /* not supported */
  80. #define IFLA_WEIGHT IFLA_WEIGHT
  81. IFLA_OPERSTATE = 16, /* u8: ifOperStatus per RFC 2863 */
  82. #define IFLA_OPERSTATE IFLA_OPERSTATE
  83. IFLA_LINKMODE = 17, /* u8: ifmedia (not supported) */
  84. #define IFLA_LINKMODE IFLA_LINKMODE
  85. IFLA_LINKINFO = 18, /* nested: IFLA_INFO_ */
  86. #define IFLA_LINKINFO IFLA_LINKINFO
  87. IFLA_NET_NS_PID = 19, /* u32: vnet id (not supported) */
  88. #define IFLA_NET_NS_PID IFLA_NET_NS_PID
  89. IFLA_IFALIAS = 20, /* string: interface description */
  90. #define IFLA_IFALIAS IFLA_IFALIAS
  91. IFLA_NUM_VF = 21, /* not supported */
  92. #define IFLA_NUM_VF IFLA_NUM_VF
  93. IFLA_VFINFO_LIST= 22, /* not supported */
  94. #define IFLA_VFINFO_LIST IFLA_VFINFO_LIST
  95. IFLA_STATS64 = 23, /* rtnl_link_stats64: iface stats */
  96. #define IFLA_STATS64 IFLA_STATS64
  97. IFLA_VF_PORTS,
  98. IFLA_PORT_SELF,
  99. IFLA_AF_SPEC,
  100. IFLA_GROUP, /* Group the device belongs to */
  101. IFLA_NET_NS_FD,
  102. IFLA_EXT_MASK, /* Extended info mask, VFs, etc */
  103. IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */
  104. #define IFLA_PROMISCUITY IFLA_PROMISCUITY
  105. IFLA_NUM_TX_QUEUES,
  106. IFLA_NUM_RX_QUEUES,
  107. IFLA_CARRIER,
  108. IFLA_PHYS_PORT_ID,
  109. IFLA_CARRIER_CHANGES,
  110. IFLA_PHYS_SWITCH_ID,
  111. IFLA_LINK_NETNSID,
  112. IFLA_PHYS_PORT_NAME,
  113. IFLA_PROTO_DOWN,
  114. IFLA_GSO_MAX_SEGS,
  115. IFLA_GSO_MAX_SIZE,
  116. IFLA_PAD,
  117. IFLA_XDP,
  118. IFLA_EVENT,
  119. IFLA_NEW_NETNSID,
  120. IFLA_IF_NETNSID,
  121. IFLA_TARGET_NETNSID = IFLA_IF_NETNSID, /* new alias */
  122. IFLA_CARRIER_UP_COUNT,
  123. IFLA_CARRIER_DOWN_COUNT,
  124. IFLA_NEW_IFINDEX,
  125. IFLA_MIN_MTU,
  126. IFLA_MAX_MTU,
  127. IFLA_PROP_LIST,
  128. IFLA_ALT_IFNAME, /* Alternative ifname */
  129. IFLA_PERM_ADDRESS,
  130. IFLA_PROTO_DOWN_REASON,
  131. IFLA_PARENT_DEV_NAME,
  132. IFLA_PARENT_DEV_BUS_NAME,
  133. IFLA_GRO_MAX_SIZE,
  134. IFLA_TSO_MAX_SEGS,
  135. IFLA_ALLMULTI,
  136. IFLA_DEVLINK_PORT,
  137. IFLA_GSO_IPV4_MAX_SIZE,
  138. IFLA_GRO_IPV4_MAX_SIZE,
  139. IFLA_FREEBSD,
  140. __IFLA_MAX
  141. };
  142. #define IFLA_MAX (__IFLA_MAX - 1)
  143. enum {
  144. IFLAF_UNSPEC = 0,
  145. IFLAF_ORIG_IFNAME = 1, /* string, original interface name at creation */
  146. IFLAF_ORIG_HWADDR = 2, /* binary, original hardware address */
  147. IFLAF_CAPS = 3, /* bitset, interface capabilities */
  148. __IFLAF_MAX
  149. };
  150. #define IFLAF_MAX (__IFLAF_MAX - 1)
  151. /*
  152. * Attributes that can be used as filters:
  153. * IFLA_IFNAME, IFLA_GROUP, IFLA_ALT_IFNAME
  154. * Headers that can be used as filters:
  155. * ifi_index, ifi_type
  156. */
  157. /*
  158. * IFLA_OPERSTATE.
  159. * The values below represent the possible
  160. * states of ifOperStatus defined by RFC 2863
  161. */
  162. enum {
  163. IF_OPER_UNKNOWN = 0, /* status can not be determined */
  164. IF_OPER_NOTPRESENT = 1, /* some (hardware) component not present */
  165. IF_OPER_DOWN = 2, /* down */
  166. IF_OPER_LOWERLAYERDOWN = 3, /* some lower-level interface is down */
  167. IF_OPER_TESTING = 4, /* in some test mode */
  168. IF_OPER_DORMANT = 5, /* "up" but waiting for some condition (802.1X) */
  169. IF_OPER_UP = 6, /* ready to pass packets */
  170. };
  171. /* IFLA_STATS */
  172. struct rtnl_link_stats {
  173. uint32_t rx_packets; /* total RX packets (IFCOUNTER_IPACKETS) */
  174. uint32_t tx_packets; /* total TX packets (IFCOUNTER_OPACKETS) */
  175. uint32_t rx_bytes; /* total RX bytes (IFCOUNTER_IBYTES) */
  176. uint32_t tx_bytes; /* total TX bytes (IFCOUNTER_OBYTES) */
  177. uint32_t rx_errors; /* RX errors (IFCOUNTER_IERRORS) */
  178. uint32_t tx_errors; /* RX errors (IFCOUNTER_OERRORS) */
  179. uint32_t rx_dropped; /* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
  180. uint32_t tx_dropped; /* TX drop (IFCOUNTER_OQDROPS) */
  181. uint32_t multicast; /* RX multicast packets (IFCOUNTER_IMCASTS) */
  182. uint32_t collisions; /* not supported */
  183. uint32_t rx_length_errors; /* not supported */
  184. uint32_t rx_over_errors; /* not supported */
  185. uint32_t rx_crc_errors; /* not supported */
  186. uint32_t rx_frame_errors; /* not supported */
  187. uint32_t rx_fifo_errors; /* not supported */
  188. uint32_t rx_missed_errors; /* not supported */
  189. uint32_t tx_aborted_errors; /* not supported */
  190. uint32_t tx_carrier_errors; /* not supported */
  191. uint32_t tx_fifo_errors; /* not supported */
  192. uint32_t tx_heartbeat_errors; /* not supported */
  193. uint32_t tx_window_errors; /* not supported */
  194. uint32_t rx_compressed; /* not supported */
  195. uint32_t tx_compressed; /* not supported */
  196. uint32_t rx_nohandler; /* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
  197. };
  198. /* IFLA_STATS64 */
  199. struct rtnl_link_stats64 {
  200. uint64_t rx_packets; /* total RX packets (IFCOUNTER_IPACKETS) */
  201. uint64_t tx_packets; /* total TX packets (IFCOUNTER_OPACKETS) */
  202. uint64_t rx_bytes; /* total RX bytes (IFCOUNTER_IBYTES) */
  203. uint64_t tx_bytes; /* total TX bytes (IFCOUNTER_OBYTES) */
  204. uint64_t rx_errors; /* RX errors (IFCOUNTER_IERRORS) */
  205. uint64_t tx_errors; /* RX errors (IFCOUNTER_OERRORS) */
  206. uint64_t rx_dropped; /* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
  207. uint64_t tx_dropped; /* TX drop (IFCOUNTER_OQDROPS) */
  208. uint64_t multicast; /* RX multicast packets (IFCOUNTER_IMCASTS) */
  209. uint64_t collisions; /* not supported */
  210. uint64_t rx_length_errors; /* not supported */
  211. uint64_t rx_over_errors; /* not supported */
  212. uint64_t rx_crc_errors; /* not supported */
  213. uint64_t rx_frame_errors; /* not supported */
  214. uint64_t rx_fifo_errors; /* not supported */
  215. uint64_t rx_missed_errors; /* not supported */
  216. uint64_t tx_aborted_errors; /* not supported */
  217. uint64_t tx_carrier_errors; /* not supported */
  218. uint64_t tx_fifo_errors; /* not supported */
  219. uint64_t tx_heartbeat_errors; /* not supported */
  220. uint64_t tx_window_errors; /* not supported */
  221. uint64_t rx_compressed; /* not supported */
  222. uint64_t tx_compressed; /* not supported */
  223. uint64_t rx_nohandler; /* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
  224. };
  225. /* IFLA_LINKINFO child nlattr types */
  226. enum {
  227. IFLA_INFO_UNSPEC,
  228. IFLA_INFO_KIND = 1, /* string, link type ("vlan") */
  229. IFLA_INFO_DATA = 2, /* Per-link-type custom data */
  230. IFLA_INFO_XSTATS = 3,
  231. IFLA_INFO_SLAVE_KIND = 4,
  232. IFLA_INFO_SLAVE_DATA = 5,
  233. __IFLA_INFO_MAX,
  234. };
  235. #define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
  236. /* IFLA_INFO_DATA vlan attributes */
  237. enum {
  238. IFLA_VLAN_UNSPEC,
  239. IFLA_VLAN_ID,
  240. IFLA_VLAN_FLAGS,
  241. IFLA_VLAN_EGRESS_QOS,
  242. IFLA_VLAN_INGRESS_QOS,
  243. IFLA_VLAN_PROTOCOL,
  244. __IFLA_VLAN_MAX,
  245. };
  246. #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
  247. struct ifla_vlan_flags {
  248. uint32_t flags;
  249. uint32_t mask;
  250. };
  251. #endif