xref: /freebsd/sys/netlink/route/interface.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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;	/* ARPHRD_* */
40 	int		ifi_index;	/* Inteface index */
41 	unsigned	ifi_flags;	/* IFF_* flags */
42 	unsigned	ifi_change;	/* IFF_* change mask */
43 };
44 
45 #ifndef _KERNEL
46 /* Compatilbility helpers */
47 #define	_IFINFO_HDRLEN		((int)sizeof(struct ifinfomsg))
48 #define	IFLA_RTA(_ifi)		((struct rtattr *)NL_ITEM_DATA(_ifi, _IFINFO_HDRLEN))
49 #define	IFLA_PAYLOAD(_ifi)	NLMSG_PAYLOAD(_ifi, _IFINFO_HDRLEN)
50 #endif
51 
52 enum {
53 	IFLA_UNSPEC	= 0,
54 	IFLA_ADDRESS	= 1,	/* binary: Link-level address (MAC) */
55 #define	IFLA_ADDRESS IFLA_ADDRESS
56 	IFLA_BROADCAST	= 2,	/* binary: link-level broadcast address */
57 #define	IFLA_BROADCAST IFLA_BROADCAST
58 	IFLA_IFNAME	= 3,	/* string: Interface name */
59 #define	IFLA_IFNAME IFLA_IFNAME
60 	IFLA_MTU	= 4,	/* u32: Current interface L3 mtu */
61 #define	IFLA_MTU IFLA_MTU
62 	IFLA_LINK	= 5,	/* u32: interface index */
63 #define	IFLA_LINK IFLA_LINK
64 	IFLA_QDISC	= 6,	/* string: Queing policy (not supported) */
65 #define	IFLA_QDISC IFLA_QDISC
66 	IFLA_STATS	= 7,	/* Interface counters */
67 #define	IFLA_STATS IFLA_STATS
68 	IFLA_COST	= 8,	/* not supported */
69 #define IFLA_COST IFLA_COST
70 	IFLA_PRIORITY	= 9,	/* not supported */
71 #define IFLA_PRIORITY IFLA_PRIORITY
72 	IFLA_MASTER	= 10,	/* u32: parent interface ifindex */
73 #define IFLA_MASTER IFLA_MASTER
74 	IFLA_WIRELESS	= 11,	/* not supported */
75 #define IFLA_WIRELESS IFLA_WIRELESS
76 	IFLA_PROTINFO	= 12,	/* protocol-specific data */
77 #define IFLA_PROTINFO IFLA_PROTINFO
78 	IFLA_TXQLEN	= 13,	/* u32: transmit queue length */
79 #define IFLA_TXQLEN IFLA_TXQLEN
80 	IFLA_MAP	= 14,	/* not supported */
81 #define IFLA_MAP IFLA_MAP
82 	IFLA_WEIGHT	= 15,	/* not supported */
83 #define IFLA_WEIGHT IFLA_WEIGHT
84 	IFLA_OPERSTATE	= 16,	/* u8: ifOperStatus per RFC 2863 */
85 #define	IFLA_OPERSTATE IFLA_OPERSTATE
86 	IFLA_LINKMODE	= 17,	/* u8: ifmedia (not supported) */
87 #define	IFLA_LINKMODE IFLA_LINKMODE
88 	IFLA_LINKINFO	= 18,	/* nested: IFLA_INFO_ */
89 #define IFLA_LINKINFO IFLA_LINKINFO
90 	IFLA_NET_NS_PID	= 19,	/* u32: vnet id (not supported) */
91 #define	IFLA_NET_NS_PID IFLA_NET_NS_PID
92 	IFLA_IFALIAS	= 20,	/* not supported */
93 #define	IFLA_IFALIAS IFLA_IFALIAS
94 	IFLA_NUM_VF	= 21,	/* not supported */
95 #define	IFLA_NUM_VF IFLA_NUM_VF
96 	IFLA_VFINFO_LIST= 22,	/* not supported */
97 #define	IFLA_VFINFO_LIST IFLA_VFINFO_LIST
98 	IFLA_STATS64	= 23,	/* rtnl_link_stats64: iface stats */
99 #define	IFLA_STATS64 IFLA_STATS64
100 	IFLA_VF_PORTS,
101 	IFLA_PORT_SELF,
102 	IFLA_AF_SPEC,
103 	IFLA_GROUP, /* Group the device belongs to */
104 	IFLA_NET_NS_FD,
105 	IFLA_EXT_MASK,	  /* Extended info mask, VFs, etc */
106 	IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */
107 #define IFLA_PROMISCUITY IFLA_PROMISCUITY
108 	IFLA_NUM_TX_QUEUES,
109 	IFLA_NUM_RX_QUEUES,
110 	IFLA_CARRIER,
111 	IFLA_PHYS_PORT_ID,
112 	IFLA_CARRIER_CHANGES,
113 	IFLA_PHYS_SWITCH_ID,
114 	IFLA_LINK_NETNSID,
115 	IFLA_PHYS_PORT_NAME,
116 	IFLA_PROTO_DOWN,
117 	IFLA_GSO_MAX_SEGS,
118 	IFLA_GSO_MAX_SIZE,
119 	IFLA_PAD,
120 	IFLA_XDP,
121 	IFLA_EVENT,
122 	IFLA_NEW_NETNSID,
123 	IFLA_IF_NETNSID,
124 	IFLA_TARGET_NETNSID = IFLA_IF_NETNSID, /* new alias */
125 	IFLA_CARRIER_UP_COUNT,
126 	IFLA_CARRIER_DOWN_COUNT,
127 	IFLA_NEW_IFINDEX,
128 	IFLA_MIN_MTU,
129 	IFLA_MAX_MTU,
130 	IFLA_PROP_LIST,
131 	IFLA_ALT_IFNAME, /* Alternative ifname */
132 	IFLA_PERM_ADDRESS,
133 	IFLA_PROTO_DOWN_REASON,
134 	__IFLA_MAX
135 };
136 #define IFLA_MAX (__IFLA_MAX - 1)
137 
138 /*
139  * Attributes that can be used as filters:
140  *  IFLA_IFNAME, IFLA_GROUP, IFLA_ALT_IFNAME
141  * Headers that can be used as filters:
142  *  ifi_index, ifi_type
143  */
144 
145 /*
146  * IFLA_OPERSTATE.
147  * The values below represent the possible
148  * states of ifOperStatus defined by RFC 2863
149  */
150 enum {
151 	IF_OPER_UNKNOWN		= 0, /* status can not be determined */
152 	IF_OPER_NOTPRESENT	= 1, /* some (hardware) component not present */
153 	IF_OPER_DOWN		= 2, /* down */
154 	IF_OPER_LOWERLAYERDOWN	= 3, /* some lower-level interface is down */
155 	IF_OPER_TESTING		= 4, /* in some test mode */
156 	IF_OPER_DORMANT		= 5, /* "up" but waiting for some condition (802.1X) */
157 	IF_OPER_UP		= 6, /* ready to pass packets */
158 };
159 
160 /* IFLA_STATS */
161 struct rtnl_link_stats {
162 	uint32_t rx_packets;	/* total RX packets (IFCOUNTER_IPACKETS) */
163 	uint32_t tx_packets;	/* total TX packets (IFCOUNTER_OPACKETS) */
164 	uint32_t rx_bytes;	/* total RX bytes (IFCOUNTER_IBYTES) */
165 	uint32_t tx_bytes;	/* total TX bytes (IFCOUNTER_OBYTES) */
166 	uint32_t rx_errors;	/* RX errors (IFCOUNTER_IERRORS) */
167 	uint32_t tx_errors;	/* RX errors (IFCOUNTER_OERRORS) */
168 	uint32_t rx_dropped;	/* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
169 	uint32_t tx_dropped;	/* TX drop (IFCOUNTER_OQDROPS) */
170 	uint32_t multicast;	/* RX multicast packets (IFCOUNTER_IMCASTS) */
171 	uint32_t collisions;	/* not supported */
172 	uint32_t rx_length_errors;	/* not supported */
173 	uint32_t rx_over_errors;	/* not supported */
174 	uint32_t rx_crc_errors;		/* not supported */
175 	uint32_t rx_frame_errors;	/* not supported */
176 	uint32_t rx_fifo_errors;	/* not supported */
177 	uint32_t rx_missed_errors;	/* not supported */
178 	uint32_t tx_aborted_errors;	/* not supported */
179 	uint32_t tx_carrier_errors;	/* not supported */
180 	uint32_t tx_fifo_errors;	/* not supported */
181 	uint32_t tx_heartbeat_errors;	/* not supported */
182 	uint32_t tx_window_errors;	/* not supported */
183 	uint32_t rx_compressed;		/* not supported */
184 	uint32_t tx_compressed;		/* not supported */
185 	uint32_t rx_nohandler;	/* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
186 };
187 
188 /* IFLA_STATS64 */
189 struct rtnl_link_stats64 {
190 	uint64_t rx_packets;	/* total RX packets (IFCOUNTER_IPACKETS) */
191 	uint64_t tx_packets;	/* total TX packets (IFCOUNTER_OPACKETS) */
192 	uint64_t rx_bytes;	/* total RX bytes (IFCOUNTER_IBYTES) */
193 	uint64_t tx_bytes;	/* total TX bytes (IFCOUNTER_OBYTES) */
194 	uint64_t rx_errors;	/* RX errors (IFCOUNTER_IERRORS) */
195 	uint64_t tx_errors;	/* RX errors (IFCOUNTER_OERRORS) */
196 	uint64_t rx_dropped;	/* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
197 	uint64_t tx_dropped;	/* TX drop (IFCOUNTER_OQDROPS) */
198 	uint64_t multicast;	/* RX multicast packets (IFCOUNTER_IMCASTS) */
199 	uint64_t collisions;	/* not supported */
200 	uint64_t rx_length_errors;	/* not supported */
201 	uint64_t rx_over_errors;	/* not supported */
202 	uint64_t rx_crc_errors;		/* not supported */
203 	uint64_t rx_frame_errors;	/* not supported */
204 	uint64_t rx_fifo_errors;	/* not supported */
205 	uint64_t rx_missed_errors;	/* not supported */
206 	uint64_t tx_aborted_errors;	/* not supported */
207 	uint64_t tx_carrier_errors;	/* not supported */
208 	uint64_t tx_fifo_errors;	/* not supported */
209 	uint64_t tx_heartbeat_errors;	/* not supported */
210 	uint64_t tx_window_errors;	/* not supported */
211 	uint64_t rx_compressed;		/* not supported */
212 	uint64_t tx_compressed;		/* not supported */
213 	uint64_t rx_nohandler;	/* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
214 };
215 
216 /* IFLA_LINKINFO child nlattr types */
217 enum {
218 	IFLA_INFO_UNSPEC,
219 	IFLA_INFO_KIND		= 1, /* string, link type ("vlan") */
220 	IFLA_INFO_DATA		= 2, /* Per-link-type custom data */
221 	IFLA_INFO_XSTATS	= 3,
222 	IFLA_INFO_SLAVE_KIND	= 4,
223 	IFLA_INFO_SLAVE_DATA	= 5,
224 	__IFLA_INFO_MAX,
225 };
226 #define IFLA_INFO_MAX	(__IFLA_INFO_MAX - 1)
227 
228 /* IFLA_INFO_DATA vlan attributes */
229 enum {
230 	IFLA_VLAN_UNSPEC,
231 	IFLA_VLAN_ID,
232 	IFLA_VLAN_FLAGS,
233 	IFLA_VLAN_EGRESS_QOS,
234 	IFLA_VLAN_INGRESS_QOS,
235 	IFLA_VLAN_PROTOCOL,
236 	__IFLA_VLAN_MAX,
237 };
238 
239 #define IFLA_VLAN_MAX	(__IFLA_VLAN_MAX - 1)
240 struct ifla_vlan_flags {
241 	uint32_t flags;
242 	uint32_t mask;
243 };
244 
245 #endif
246