xref: /freebsd/sys/netlink/route/interface.h (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
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 /*
29  * Interface-related (RTM_<NEW|DEL|GET|SET>LINK) message header and attributes.
30  */
31 
32 #ifndef _NETLINK_ROUTE_INTERFACE_H_
33 #define _NETLINK_ROUTE_INTERFACE_H_
34 
35 /* Base header for all of the relevant messages */
36 struct ifinfomsg {
37 	unsigned char	ifi_family;	/* not used */
38 	unsigned char	__ifi_pad;
39 	unsigned short	ifi_type;	/* IFT_* (net/if_types.h) */
40 	int		ifi_index;	/* Interface index */
41 	unsigned	ifi_flags;	/* IFF_* flags */
42 	unsigned	ifi_change;	/* IFF_* change mask */
43 };
44 
45 /* Linux-specific link-level state flag */
46 #define	IFF_LOWER_UP	IFF_NETLINK_1
47 
48 #ifndef _KERNEL
49 /* Compatilbility helpers */
50 #define	_IFINFO_HDRLEN		((int)sizeof(struct ifinfomsg))
51 #define	IFLA_RTA(_ifi)		((struct rtattr *)NL_ITEM_DATA(_ifi, _IFINFO_HDRLEN))
52 #define	IFLA_PAYLOAD(_ifi)	NLMSG_PAYLOAD(_ifi, _IFINFO_HDRLEN)
53 #endif
54 
55 enum {
56 	IFLA_UNSPEC	= 0,
57 	IFLA_ADDRESS	= 1,	/* binary: Link-level address (MAC) */
58 #define	IFLA_ADDRESS IFLA_ADDRESS
59 	IFLA_BROADCAST	= 2,	/* binary: link-level broadcast address */
60 #define	IFLA_BROADCAST IFLA_BROADCAST
61 	IFLA_IFNAME	= 3,	/* string: Interface name */
62 #define	IFLA_IFNAME IFLA_IFNAME
63 	IFLA_MTU	= 4,	/* u32: Current interface L3 mtu */
64 #define	IFLA_MTU IFLA_MTU
65 	IFLA_LINK	= 5,	/* u32: interface index */
66 #define	IFLA_LINK IFLA_LINK
67 	IFLA_QDISC	= 6,	/* string: Queing policy (not supported) */
68 #define	IFLA_QDISC IFLA_QDISC
69 	IFLA_STATS	= 7,	/* Interface counters */
70 #define	IFLA_STATS IFLA_STATS
71 	IFLA_COST	= 8,	/* not supported */
72 #define IFLA_COST IFLA_COST
73 	IFLA_PRIORITY	= 9,	/* not supported */
74 #define IFLA_PRIORITY IFLA_PRIORITY
75 	IFLA_MASTER	= 10,	/* u32: parent interface ifindex */
76 #define IFLA_MASTER IFLA_MASTER
77 	IFLA_WIRELESS	= 11,	/* not supported */
78 #define IFLA_WIRELESS IFLA_WIRELESS
79 	IFLA_PROTINFO	= 12,	/* protocol-specific data */
80 #define IFLA_PROTINFO IFLA_PROTINFO
81 	IFLA_TXQLEN	= 13,	/* u32: transmit queue length */
82 #define IFLA_TXQLEN IFLA_TXQLEN
83 	IFLA_MAP	= 14,	/* not supported */
84 #define IFLA_MAP IFLA_MAP
85 	IFLA_WEIGHT	= 15,	/* not supported */
86 #define IFLA_WEIGHT IFLA_WEIGHT
87 	IFLA_OPERSTATE	= 16,	/* u8: ifOperStatus per RFC 2863 */
88 #define	IFLA_OPERSTATE IFLA_OPERSTATE
89 	IFLA_LINKMODE	= 17,	/* u8: ifmedia (not supported) */
90 #define	IFLA_LINKMODE IFLA_LINKMODE
91 	IFLA_LINKINFO	= 18,	/* nested: IFLA_INFO_ */
92 #define IFLA_LINKINFO IFLA_LINKINFO
93 	IFLA_NET_NS_PID	= 19,	/* u32: vnet id (not supported) */
94 #define	IFLA_NET_NS_PID IFLA_NET_NS_PID
95 	IFLA_IFALIAS	= 20,	/* string: interface description */
96 #define	IFLA_IFALIAS IFLA_IFALIAS
97 	IFLA_NUM_VF	= 21,	/* u32: VF records, when requested */
98 #define	IFLA_NUM_VF IFLA_NUM_VF
99 	IFLA_VFINFO_LIST= 22,	/* not supported */
100 #define	IFLA_VFINFO_LIST IFLA_VFINFO_LIST
101 	IFLA_STATS64	= 23,	/* rtnl_link_stats64: iface stats */
102 #define	IFLA_STATS64 IFLA_STATS64
103 	IFLA_VF_PORTS,
104 	IFLA_PORT_SELF,
105 	IFLA_AF_SPEC,
106 	IFLA_GROUP, /* Group the device belongs to */
107 	IFLA_NET_NS_FD,
108 	IFLA_EXT_MASK,	  /* Extended info mask, VFs, etc */
109 	IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */
110 #define IFLA_PROMISCUITY IFLA_PROMISCUITY
111 	IFLA_NUM_TX_QUEUES,
112 	IFLA_NUM_RX_QUEUES,
113 	IFLA_CARRIER,
114 	IFLA_PHYS_PORT_ID,
115 	IFLA_CARRIER_CHANGES,
116 	IFLA_PHYS_SWITCH_ID,
117 	IFLA_LINK_NETNSID,
118 	IFLA_PHYS_PORT_NAME,
119 	IFLA_PROTO_DOWN,
120 	IFLA_GSO_MAX_SEGS,
121 	IFLA_GSO_MAX_SIZE,
122 	IFLA_PAD,
123 	IFLA_XDP,
124 	IFLA_EVENT,
125 	IFLA_NEW_NETNSID,
126 	IFLA_IF_NETNSID,
127 	IFLA_TARGET_NETNSID = IFLA_IF_NETNSID, /* new alias */
128 	IFLA_CARRIER_UP_COUNT,
129 	IFLA_CARRIER_DOWN_COUNT,
130 	IFLA_NEW_IFINDEX,
131 	IFLA_MIN_MTU,
132 	IFLA_MAX_MTU,
133 	IFLA_PROP_LIST,
134 	IFLA_ALT_IFNAME, /* Alternative ifname */
135 	IFLA_PERM_ADDRESS,
136 	IFLA_PROTO_DOWN_REASON,
137 	IFLA_PARENT_DEV_NAME,
138 	IFLA_PARENT_DEV_BUS_NAME,
139 	IFLA_GRO_MAX_SIZE,
140 	IFLA_TSO_MAX_SEGS,
141 	IFLA_ALLMULTI,
142 	IFLA_DEVLINK_PORT,
143 	IFLA_GSO_IPV4_MAX_SIZE,
144 	IFLA_GRO_IPV4_MAX_SIZE,
145 	IFLA_FREEBSD,
146 	IFLA_FREEBSD_VF,	/* nested, IFLAF_VF_*; repeated */
147 	__IFLA_MAX
148 };
149 #define IFLA_MAX (__IFLA_MAX - 1)
150 
151 /* IFLA_EXT_MASK values. */
152 #define	RTEXT_FILTER_VF		(1U << 0)
153 
154 enum {
155 	IFLAF_UNSPEC		= 0,
156 	IFLAF_ORIG_IFNAME	= 1,	/* string, original interface name at creation */
157 	IFLAF_ORIG_HWADDR	= 2,	/* binary, original hardware address */
158 	IFLAF_CAPS		= 3,	/* bitset, interface capabilities */
159 	IFLAF_GROUP		= 4,	/* string, interface group name (multi-attr) */
160 	IFLAF_VF_STATUS		= 5,	/* nested, IFLAF_VFS_* */
161 	__IFLAF_MAX
162 };
163 #define IFLAF_MAX (__IFLAF_MAX - 1)
164 
165 /* IFLAF_VF_STATUS attributes. */
166 enum {
167 	IFLAF_VFS_UNSPEC	= 0,
168 	IFLAF_VFS_ERROR		= 1,	/* u32: errno from requested query */
169 	IFLAF_VFS_PF_LINK_STATE	= 2,	/* u8: IFLAF_VF_LINK_* */
170 	IFLAF_VFS_PF_LINK_SPEED	= 3,	/* u64: bits per second */
171 	__IFLAF_VFS_MAX
172 };
173 #define	IFLAF_VFS_MAX	(__IFLAF_VFS_MAX - 1)
174 
175 /* IFLA_FREEBSD_VF attributes. */
176 enum {
177 	IFLAF_VF_UNSPEC			= 0,
178 	IFLAF_VF_INDEX			= 1,	/* u32 */
179 	IFLAF_VF_CONFIGURED		= 2,	/* bool */
180 	IFLAF_VF_INITIALIZED		= 3,	/* bool */
181 	IFLAF_VF_MAC			= 4,	/* binary */
182 	IFLAF_VF_VLAN_MODE		= 5,	/* u8: IFLAF_VF_VLAN_* */
183 	IFLAF_VF_VLAN			= 6,	/* u16 */
184 	IFLAF_VF_VLAN_PCP		= 7,	/* u8: IEEE 802.1p PCP */
185 	IFLAF_VF_VLAN_PROTO		= 8,	/* u16: host-order EtherType */
186 	IFLAF_VF_VLAN_COUNT		= 9,	/* u32 */
187 	IFLAF_VF_VLAN_LIMIT		= 10,	/* u32 */
188 	IFLAF_VF_NUM_TX_QUEUES		= 11,	/* u16 */
189 	IFLAF_VF_NUM_RX_QUEUES		= 12,	/* u16 */
190 	IFLAF_VF_MIN_TX_RATE		= 13,	/* u64: minimum bits per second */
191 	IFLAF_VF_MAX_TX_RATE		= 14,	/* u64: maximum bits per second */
192 	IFLAF_VF_ALLOW_SET_MAC		= 15,	/* bool */
193 	IFLAF_VF_ALLOW_SET_VLAN		= 16,	/* bool */
194 	IFLAF_VF_MAC_ANTI_SPOOF		= 17,	/* bool */
195 	IFLAF_VF_ALLOW_PROMISC		= 18,	/* bool */
196 	IFLAF_VF_TRAFFIC_ALLOWED	= 19,	/* bool */
197 	IFLAF_VF_FAULT_BLOCKED		= 20,	/* bool */
198 	IFLAF_VF_QUARANTINED		= 21,	/* bool */
199 	IFLAF_VF_API_VERSION		= 22,	/* string */
200 	IFLAF_VF_LINK_STATE_POLICY	= 23,	/* u8: IFLAF_VF_LINK_* */
201 	IFLAF_VF_DRIVER			= 24,	/* nested; repeated */
202 	__IFLAF_VF_MAX
203 };
204 #define	IFLAF_VF_MAX	(__IFLAF_VF_MAX - 1)
205 
206 /* IFLAF_VF_DRIVER attributes. */
207 enum {
208 	IFLAF_VFD_UNSPEC	= 0,
209 	IFLAF_VFD_NAME		= 1,	/* string: stable namespace */
210 	IFLAF_VFD_VERSION	= 2,	/* u32: namespace version */
211 	IFLAF_VFD_FIELD		= 3,	/* nested, IFLAF_VFDF_*; repeated */
212 	__IFLAF_VFD_MAX
213 };
214 #define	IFLAF_VFD_MAX	(__IFLAF_VFD_MAX - 1)
215 
216 /* IFLAF_VFD_FIELD attributes; exactly one value attribute is present. */
217 enum {
218 	IFLAF_VFDF_UNSPEC	= 0,
219 	IFLAF_VFDF_NAME		= 1,	/* string: namespace-local name */
220 	IFLAF_VFDF_BOOL		= 2,	/* bool */
221 	IFLAF_VFDF_NUMBER	= 3,	/* u64 */
222 	IFLAF_VFDF_STRING	= 4,	/* string */
223 	IFLAF_VFDF_BINARY	= 5,	/* binary */
224 	__IFLAF_VFDF_MAX
225 };
226 #define	IFLAF_VFDF_MAX	(__IFLAF_VFDF_MAX - 1)
227 
228 enum {
229 	IFLAF_VF_LINK_UNKNOWN	= 0,
230 	IFLAF_VF_LINK_DOWN	= 1,
231 	IFLAF_VF_LINK_UP	= 2,
232 	IFLAF_VF_LINK_AUTO	= 3,
233 };
234 
235 enum {
236 	IFLAF_VF_VLAN_UNKNOWN	= 0,
237 	IFLAF_VF_VLAN_ACCESS	= 1,
238 	IFLAF_VF_VLAN_TRUNK	= 2,
239 };
240 
241 /*
242  * Attributes that can be used as filters:
243  *  IFLA_IFNAME, IFLA_GROUP, IFLA_ALT_IFNAME
244  * Headers that can be used as filters:
245  *  ifi_index, ifi_type
246  */
247 
248 /*
249  * IFLA_OPERSTATE.
250  * The values below represent the possible
251  * states of ifOperStatus defined by RFC 2863
252  */
253 enum {
254 	IF_OPER_UNKNOWN		= 0, /* status can not be determined */
255 	IF_OPER_NOTPRESENT	= 1, /* some (hardware) component not present */
256 	IF_OPER_DOWN		= 2, /* down */
257 	IF_OPER_LOWERLAYERDOWN	= 3, /* some lower-level interface is down */
258 	IF_OPER_TESTING		= 4, /* in some test mode */
259 	IF_OPER_DORMANT		= 5, /* "up" but waiting for some condition (802.1X) */
260 	IF_OPER_UP		= 6, /* ready to pass packets */
261 };
262 
263 /* IFLA_STATS */
264 struct rtnl_link_stats {
265 	uint32_t rx_packets;	/* total RX packets (IFCOUNTER_IPACKETS) */
266 	uint32_t tx_packets;	/* total TX packets (IFCOUNTER_OPACKETS) */
267 	uint32_t rx_bytes;	/* total RX bytes (IFCOUNTER_IBYTES) */
268 	uint32_t tx_bytes;	/* total TX bytes (IFCOUNTER_OBYTES) */
269 	uint32_t rx_errors;	/* RX errors (IFCOUNTER_IERRORS) */
270 	uint32_t tx_errors;	/* RX errors (IFCOUNTER_OERRORS) */
271 	uint32_t rx_dropped;	/* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
272 	uint32_t tx_dropped;	/* TX drop (IFCOUNTER_OQDROPS) */
273 	uint32_t multicast;	/* RX multicast packets (IFCOUNTER_IMCASTS) */
274 	uint32_t collisions;	/* not supported */
275 	uint32_t rx_length_errors;	/* not supported */
276 	uint32_t rx_over_errors;	/* not supported */
277 	uint32_t rx_crc_errors;		/* not supported */
278 	uint32_t rx_frame_errors;	/* not supported */
279 	uint32_t rx_fifo_errors;	/* not supported */
280 	uint32_t rx_missed_errors;	/* not supported */
281 	uint32_t tx_aborted_errors;	/* not supported */
282 	uint32_t tx_carrier_errors;	/* not supported */
283 	uint32_t tx_fifo_errors;	/* not supported */
284 	uint32_t tx_heartbeat_errors;	/* not supported */
285 	uint32_t tx_window_errors;	/* not supported */
286 	uint32_t rx_compressed;		/* not supported */
287 	uint32_t tx_compressed;		/* not supported */
288 	uint32_t rx_nohandler;	/* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
289 };
290 
291 /* IFLA_STATS64 */
292 struct rtnl_link_stats64 {
293 	uint64_t rx_packets;	/* total RX packets (IFCOUNTER_IPACKETS) */
294 	uint64_t tx_packets;	/* total TX packets (IFCOUNTER_OPACKETS) */
295 	uint64_t rx_bytes;	/* total RX bytes (IFCOUNTER_IBYTES) */
296 	uint64_t tx_bytes;	/* total TX bytes (IFCOUNTER_OBYTES) */
297 	uint64_t rx_errors;	/* RX errors (IFCOUNTER_IERRORS) */
298 	uint64_t tx_errors;	/* RX errors (IFCOUNTER_OERRORS) */
299 	uint64_t rx_dropped;	/* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
300 	uint64_t tx_dropped;	/* TX drop (IFCOUNTER_OQDROPS) */
301 	uint64_t multicast;	/* RX multicast packets (IFCOUNTER_IMCASTS) */
302 	uint64_t collisions;	/* not supported */
303 	uint64_t rx_length_errors;	/* not supported */
304 	uint64_t rx_over_errors;	/* not supported */
305 	uint64_t rx_crc_errors;		/* not supported */
306 	uint64_t rx_frame_errors;	/* not supported */
307 	uint64_t rx_fifo_errors;	/* not supported */
308 	uint64_t rx_missed_errors;	/* not supported */
309 	uint64_t tx_aborted_errors;	/* not supported */
310 	uint64_t tx_carrier_errors;	/* not supported */
311 	uint64_t tx_fifo_errors;	/* not supported */
312 	uint64_t tx_heartbeat_errors;	/* not supported */
313 	uint64_t tx_window_errors;	/* not supported */
314 	uint64_t rx_compressed;		/* not supported */
315 	uint64_t tx_compressed;		/* not supported */
316 	uint64_t rx_nohandler;	/* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
317 };
318 
319 /* IFLA_LINKINFO child nlattr types */
320 enum {
321 	IFLA_INFO_UNSPEC,
322 	IFLA_INFO_KIND		= 1, /* string, link type ("vlan") */
323 	IFLA_INFO_DATA		= 2, /* Per-link-type custom data */
324 	IFLA_INFO_XSTATS	= 3,
325 	IFLA_INFO_SLAVE_KIND	= 4,
326 	IFLA_INFO_SLAVE_DATA	= 5,
327 	__IFLA_INFO_MAX,
328 };
329 #define IFLA_INFO_MAX	(__IFLA_INFO_MAX - 1)
330 
331 /* Encapsulation Types */
332 enum {
333 	IFLA_TUNNEL_NONE,
334 	IFLA_TUNNEL_GRE_UDP,	/* GRE UDP Encapsulation */
335 	__IFLA_TUNNEL_MAX,
336 };
337 
338 #define IFLA_TUNNEL_MAX	(__IFLA_TUNNEL_MAX - 1)
339 
340 /* IFLA_INFO_DATA vlan attributes */
341 enum {
342 	IFLA_VLAN_UNSPEC,
343 	IFLA_VLAN_ID,
344 	IFLA_VLAN_FLAGS,
345 	IFLA_VLAN_EGRESS_QOS,
346 	IFLA_VLAN_INGRESS_QOS,
347 	IFLA_VLAN_PROTOCOL,
348 	__IFLA_VLAN_MAX,
349 };
350 
351 #define IFLA_VLAN_MAX	(__IFLA_VLAN_MAX - 1)
352 struct ifla_vlan_flags {
353 	uint32_t flags;
354 	uint32_t mask;
355 };
356 
357 /* IFLA_INFO_DATA gif attributes */
358 enum {
359 	IFLA_IPTUN_UNSPEC,
360 	IFLA_IPTUN_LOCAL,
361 	IFLA_IPTUN_REMOTE,
362 	IFLA_IPTUN_FLAGS,
363 	__IFLA_IPTUN_MAX,
364 };
365 #define IFLA_IPTUN_MAX	(__IFLA_IPTUN_MAX - 1)
366 
367 /* IFLA_INFO_DATA gre attributes */
368 enum {
369 	IFLA_GRE_UNSPEC,
370 	IFLA_GRE_LOCAL,
371 	IFLA_GRE_REMOTE,
372 	IFLA_GRE_FLAGS,
373 	IFLA_GRE_OKEY,
374 	IFLA_GRE_ENCAP_TYPE,
375 	IFLA_GRE_ENCAP_SPORT,
376 	__IFLA_GRE_MAX,
377 };
378 
379 #define IFLA_GRE_MAX	(__IFLA_GRE_MAX - 1)
380 
381 /* IFLA_INFO_DATA geneve attributes */
382 enum {
383 	IFLA_GENEVE_UNSPEC,
384 	IFLA_GENEVE_ID,
385 	IFLA_GENEVE_PROTOCOL,
386 	IFLA_GENEVE_LOCAL,
387 	IFLA_GENEVE_REMOTE,
388 	IFLA_GENEVE_LOCAL_PORT,
389 	IFLA_GENEVE_PORT,
390 	IFLA_GENEVE_PORT_RANGE,
391 	IFLA_GENEVE_DF,
392 	IFLA_GENEVE_TTL,
393 	IFLA_GENEVE_TTL_INHERIT,
394 	IFLA_GENEVE_DSCP_INHERIT,
395 	IFLA_GENEVE_COLLECT_METADATA,
396 	IFLA_GENEVE_FTABLE_LEARN,
397 	IFLA_GENEVE_FTABLE_FLUSH,
398 	IFLA_GENEVE_FTABLE_MAX,
399 	IFLA_GENEVE_FTABLE_TIMEOUT,
400 	IFLA_GENEVE_FTABLE_COUNT,
401 	IFLA_GENEVE_FTABLE_NOSPACE_CNT,
402 	IFLA_GENEVE_FTABLE_LOCK_UP_FAIL_CNT,
403 	IFLA_GENEVE_MC_IFNAME,
404 	IFLA_GENEVE_MC_IFINDEX,
405 	IFLA_GENEVE_TXCSUM_CNT,
406 	IFLA_GENEVE_TSO_CNT,
407 	IFLA_GENEVE_RXCSUM_CNT,
408 	__IFLA_GENEVE_MAX,
409 };
410 #define IFLA_GENEVE_MAX	(__IFLA_GENEVE_MAX - 1)
411 
412 enum ifla_geneve_df {
413 	IFLA_GENEVE_DF_UNSET,
414 	IFLA_GENEVE_DF_SET,
415 	IFLA_GENEVE_DF_INHERIT,
416 	__IFLA_GENEVE_DF_MAX,
417 };
418 #define IFLA_GENEVE_DF_MAX	(__IFLA_GENEVE_DF_MAX - 1)
419 
420 struct ifla_geneve_port_range {
421 	uint16_t low;
422 	uint16_t high;
423 };
424 
425 #endif
426