xref: /openbsd-src/sys/net/if.h (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: if.h,v 1.157 2014/07/14 03:45:43 dlg Exp $	*/
2 /*	$NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $	*/
3 
4 /*
5  * Copyright (c) 1982, 1986, 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)if.h	8.1 (Berkeley) 6/10/93
33  */
34 
35 #ifndef _NET_IF_H_
36 #define _NET_IF_H_
37 
38 #include <sys/cdefs.h>
39 
40 /*
41  * Length of interface external name, including terminating '\0'.
42  * Note: this is the same size as a generic device's external name.
43  */
44 #define	IF_NAMESIZE	16
45 
46 struct if_nameindex {
47 	unsigned int	if_index;
48 	char		*if_name;
49 };
50 
51 #ifndef _KERNEL
52 __BEGIN_DECLS
53 unsigned int if_nametoindex(const char *);
54 char	*if_indextoname(unsigned int, char *);
55 struct	if_nameindex *if_nameindex(void);
56 void	if_freenameindex(struct if_nameindex *);
57 __END_DECLS
58 #endif
59 
60 #if __BSD_VISIBLE
61 
62 /*
63  * Structure used to query names of interface cloners.
64  */
65 struct if_clonereq {
66 	int	ifcr_total;		/* total cloners (out) */
67 	int	ifcr_count;		/* room for this many in user buffer */
68 	char	*ifcr_buffer;		/* buffer for cloner names */
69 };
70 
71 #define MCLPOOLS	7		/* number of cluster pools */
72 
73 struct if_rxring {
74 	int     rxr_adjusted;
75 	u_int	rxr_alive;
76 	u_int	rxr_cwm;
77 	u_int	rxr_lwm;
78 	u_int	rxr_hwm;
79 };
80 
81 struct if_rxring_info {
82 	char	ifr_name[16];		/* name of the ring */
83 	u_int	ifr_size;		/* size of the packets on the ring */
84 	struct if_rxring ifr_info;
85 };
86 
87 /* Structure used in SIOCGIFRXR request. */
88 struct if_rxrinfo {
89 	u_int	ifri_total;
90 	struct if_rxring_info *ifri_entries;
91 };
92 
93 /*
94  * Structure defining statistics and other data kept regarding a network
95  * interface.
96  */
97 struct	if_data {
98 	/* generic interface information */
99 	u_char		ifi_type;		/* ethernet, tokenring, etc. */
100 	u_char		ifi_addrlen;		/* media address length */
101 	u_char		ifi_hdrlen;		/* media header length */
102 	u_char		ifi_link_state;		/* current link state */
103 	u_int32_t	ifi_mtu;		/* maximum transmission unit */
104 	u_int32_t	ifi_metric;		/* routing metric (external only) */
105 	u_int32_t	ifi_pad;
106 	u_int64_t	ifi_baudrate;		/* linespeed */
107 	/* volatile statistics */
108 	u_int64_t	ifi_ipackets;		/* packets received on interface */
109 	u_int64_t	ifi_ierrors;		/* input errors on interface */
110 	u_int64_t	ifi_opackets;		/* packets sent on interface */
111 	u_int64_t	ifi_oerrors;		/* output errors on interface */
112 	u_int64_t	ifi_collisions;		/* collisions on csma interfaces */
113 	u_int64_t	ifi_ibytes;		/* total number of octets received */
114 	u_int64_t	ifi_obytes;		/* total number of octets sent */
115 	u_int64_t	ifi_imcasts;		/* packets received via multicast */
116 	u_int64_t	ifi_omcasts;		/* packets sent via multicast */
117 	u_int64_t	ifi_iqdrops;		/* dropped on input, this interface */
118 	u_int64_t	ifi_noproto;		/* destined for unsupported protocol */
119 	u_int32_t	ifi_capabilities;	/* interface capabilities */
120 	struct	timeval ifi_lastchange;	/* last operational state change */
121 };
122 
123 #define IFQ_NQUEUES	8
124 #define IFQ_MAXPRIO	IFQ_NQUEUES - 1
125 #define IFQ_DEFPRIO	3
126 
127 /*
128  * Values for if_link_state.
129  */
130 #define LINK_STATE_UNKNOWN	0	/* link unknown */
131 #define LINK_STATE_INVALID	1	/* link invalid */
132 #define LINK_STATE_DOWN		2	/* link is down */
133 #define LINK_STATE_KALIVE_DOWN	3	/* keepalive reports down */
134 #define LINK_STATE_UP		4	/* link is up */
135 #define LINK_STATE_HALF_DUPLEX	5	/* link is up and half duplex */
136 #define LINK_STATE_FULL_DUPLEX	6	/* link is up and full duplex */
137 
138 #define LINK_STATE_IS_UP(_s)	\
139 		((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN)
140 
141 /*
142  * Status bit descriptions for the various interface types.
143  */
144 struct if_status_description {
145 	u_char	ifs_type;
146 	u_char	ifs_state;
147 	const char *ifs_string;
148 };
149 
150 #define LINK_STATE_DESC_MATCH(_ifs, _t, _s)				\
151 	(((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) &&		\
152 	    (_ifs)->ifs_state == (_s))
153 
154 
155 #define LINK_STATE_DESCRIPTIONS {					\
156 	{ IFT_ETHER, LINK_STATE_DOWN, "no carrier" },			\
157 									\
158 	{ IFT_IEEE80211, LINK_STATE_DOWN, "no network" },		\
159 									\
160 	{ IFT_PPP, LINK_STATE_DOWN, "no carrier" },			\
161 									\
162 	{ IFT_CARP, LINK_STATE_DOWN, "backup" },			\
163 	{ IFT_CARP, LINK_STATE_UP, "master" },				\
164 	{ IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" },			\
165 	{ IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" },			\
166 									\
167 	{ 0, LINK_STATE_UP, "active" },					\
168 	{ 0, LINK_STATE_HALF_DUPLEX, "active" },			\
169 	{ 0, LINK_STATE_FULL_DUPLEX, "active" },			\
170 									\
171 	{ 0, LINK_STATE_UNKNOWN, "unknown" },				\
172 	{ 0, LINK_STATE_INVALID, "invalid" },				\
173 	{ 0, LINK_STATE_DOWN, "down" },					\
174 	{ 0, LINK_STATE_KALIVE_DOWN, "keepalive down" },		\
175 	{ 0, 0, NULL }							\
176 }
177 
178 /* Traditional BSD name for length of interface external name. */
179 #define	IFNAMSIZ	IF_NAMESIZE
180 
181 /*
182  * Length of interface description, including terminating '\0'.
183  */
184 #define	IFDESCRSIZE	64
185 
186 #define	IFF_UP		0x1		/* interface is up */
187 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
188 #define	IFF_DEBUG	0x4		/* turn on debugging */
189 #define	IFF_LOOPBACK	0x8		/* is a loopback net */
190 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
191 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
192 #define	IFF_RUNNING	0x40		/* resources allocated */
193 #define	IFF_NOARP	0x80		/* no address resolution protocol */
194 #define	IFF_PROMISC	0x100		/* receive all packets */
195 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
196 #define	IFF_OACTIVE	0x400		/* transmission in progress */
197 #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
198 #define	IFF_LINK0	0x1000		/* per link layer defined bit */
199 #define	IFF_LINK1	0x2000		/* per link layer defined bit */
200 #define	IFF_LINK2	0x4000		/* per link layer defined bit */
201 #define	IFF_MULTICAST	0x8000		/* supports multicast */
202 
203 /* flags set internally only: */
204 #define	IFF_CANTCHANGE \
205 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
206 	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
207 
208 #define IFXF_TXREADY		0x1		/* interface is ready to tx */
209 #define	IFXF_NOINET6		0x2		/* don't do inet6 */
210 #define	IFXF_INET6_NOPRIVACY	0x4		/* don't autoconf privacy */
211 #define	IFXF_MPLS		0x8		/* supports MPLS */
212 #define	IFXF_WOL		0x10		/* wake on lan enabled */
213 #define	IFXF_AUTOCONF6		0x20		/* v6 autoconf enabled */
214 
215 #define	IFXF_CANTCHANGE \
216 	(IFXF_TXREADY)
217 
218 /*
219  * Some convenience macros used for setting ifi_baudrate.
220  */
221 #define	IF_Kbps(x)	((x) * 1000ULL)			/* kilobits/sec. */
222 #define	IF_Mbps(x)	(IF_Kbps((x) * 1000ULL))	/* megabits/sec. */
223 #define	IF_Gbps(x)	(IF_Mbps((x) * 1000ULL))	/* gigabits/sec. */
224 
225 /* Capabilities that interfaces can advertise. */
226 #define	IFCAP_CSUM_IPv4		0x00000001	/* can do IPv4 header csum */
227 #define	IFCAP_CSUM_TCPv4	0x00000002	/* can do IPv4/TCP csum */
228 #define	IFCAP_CSUM_UDPv4	0x00000004	/* can do IPv4/UDP csum */
229 #define	IFCAP_VLAN_MTU		0x00000010	/* VLAN-compatible MTU */
230 #define	IFCAP_VLAN_HWTAGGING	0x00000020	/* hardware VLAN tag support */
231 #define	IFCAP_CSUM_TCPv6	0x00000080	/* can do IPv6/TCP checksums */
232 #define	IFCAP_CSUM_UDPv6	0x00000100	/* can do IPv6/UDP checksums */
233 #define	IFCAP_WOL		0x00008000	/* can do wake on lan */
234 
235 #define IFCAP_CSUM_MASK		(IFCAP_CSUM_IPv4 | IFCAP_CSUM_TCPv4 | \
236     IFCAP_CSUM_UDPv4 | IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6)
237 
238 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
239 #define IFQCTL_LEN 1
240 #define IFQCTL_MAXLEN 2
241 #define IFQCTL_DROPS 3
242 #define IFQCTL_CONGESTION 4
243 #define IFQCTL_MAXID 5
244 
245 /* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */
246 #define CTL_IFQ_NAMES  { \
247 	{ 0, 0 }, \
248 	{ "len", CTLTYPE_INT }, \
249 	{ "maxlen", CTLTYPE_INT }, \
250 	{ "drops", CTLTYPE_INT }, \
251 	{ "congestion", CTLTYPE_INT }, \
252 }
253 
254 /*
255  * Message format for use in obtaining information about interfaces
256  * from sysctl and the routing socket.
257  */
258 struct if_msghdr {
259 	u_short	ifm_msglen;	/* to skip over non-understood messages */
260 	u_char	ifm_version;	/* future binary compatibility */
261 	u_char	ifm_type;	/* message type */
262 	u_short ifm_hdrlen;	/* sizeof(if_msghdr) to skip over the header */
263 	u_short	ifm_index;	/* index for associated ifp */
264 	u_short	ifm_tableid;	/* routing table id */
265 	u_char	ifm_pad1;
266 	u_char	ifm_pad2;
267 	int	ifm_addrs;	/* like rtm_addrs */
268 	int	ifm_flags;	/* value of if_flags */
269 	int	ifm_xflags;
270 	struct	if_data ifm_data;/* statistics and other data about if */
271 };
272 
273 /*
274  * Message format for use in obtaining information about interface addresses
275  * from sysctl and the routing socket.
276  */
277 struct ifa_msghdr {
278 	u_short	ifam_msglen;	/* to skip over non-understood messages */
279 	u_char	ifam_version;	/* future binary compatibility */
280 	u_char	ifam_type;	/* message type */
281 	u_short ifam_hdrlen;	/* sizeof(ifa_msghdr) to skip over the header */
282 	u_short	ifam_index;	/* index for associated ifp */
283 	u_short	ifam_tableid;	/* routing table id */
284 	u_char	ifam_pad1;
285 	u_char	ifam_pad2;
286 	int	ifam_addrs;	/* like rtm_addrs */
287 	int	ifam_flags;	/* value of ifa_flags */
288 	int	ifam_metric;	/* value of ifa_metric */
289 };
290 
291 /*
292  * Message format announcing the arrival or departure of a network interface.
293  */
294 struct if_announcemsghdr {
295 	u_short	ifan_msglen;	/* to skip over non-understood messages */
296 	u_char	ifan_version;	/* future binary compatibility */
297 	u_char	ifan_type;	/* message type */
298 	u_short ifan_hdrlen;	/* sizeof(ifa_msghdr) to skip over the header */
299 	u_short	ifan_index;	/* index for associated ifp */
300 	u_short	ifan_what;	/* what type of announcement */
301 	char	ifan_name[IFNAMSIZ];	/* if name, e.g. "en0" */
302 };
303 
304 #define IFAN_ARRIVAL	0	/* interface arrival */
305 #define IFAN_DEPARTURE	1	/* interface departure */
306 
307 /*
308  * interface groups
309  */
310 
311 #define	IFG_ALL		"all"		/* group contains all interfaces */
312 #define	IFG_EGRESS	"egress"	/* if(s) default route(s) point to */
313 
314 struct ifg_req {
315 	union {
316 		char			 ifgrqu_group[IFNAMSIZ];
317 		char			 ifgrqu_member[IFNAMSIZ];
318 	} ifgrq_ifgrqu;
319 #define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
320 #define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
321 };
322 
323 struct ifg_attrib {
324 	int	ifg_carp_demoted;
325 };
326 
327 /*
328  * Used to lookup groups for an interface
329  */
330 struct ifgroupreq {
331 	char	ifgr_name[IFNAMSIZ];
332 	u_int	ifgr_len;
333 	union {
334 		char			 ifgru_group[IFNAMSIZ];
335 		struct	ifg_req		*ifgru_groups;
336 		struct	ifg_attrib	 ifgru_attrib;
337 	} ifgr_ifgru;
338 #define ifgr_group	ifgr_ifgru.ifgru_group
339 #define ifgr_groups	ifgr_ifgru.ifgru_groups
340 #define ifgr_attrib	ifgr_ifgru.ifgru_attrib
341 };
342 
343 /*
344  * Interface request structure used for socket
345  * ioctl's.  All interface ioctl's must have parameter
346  * definitions which begin with ifr_name.  The
347  * remainder may be interface specific.
348  */
349 struct	ifreq {
350 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
351 	union {
352 		struct	sockaddr ifru_addr;
353 		struct	sockaddr ifru_dstaddr;
354 		struct	sockaddr ifru_broadaddr;
355 		short	ifru_flags;
356 		int	ifru_metric;
357 		caddr_t	ifru_data;
358 	} ifr_ifru;
359 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
360 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
361 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
362 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
363 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
364 #define	ifr_mtu		ifr_ifru.ifru_metric	/* mtu (overload) */
365 #define	ifr_hardmtu	ifr_ifru.ifru_metric	/* hardmtu (overload) */
366 #define	ifr_media	ifr_ifru.ifru_metric	/* media options (overload) */
367 #define	ifr_rdomainid	ifr_ifru.ifru_metric	/* VRF instance (overload) */
368 #define ifr_vnetid	ifr_ifru.ifru_metric	/* Virtual Net Id (overload) */
369 #define ifr_ttl		ifr_ifru.ifru_metric	/* tunnel TTL (overload) */
370 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
371 };
372 
373 struct ifaliasreq {
374 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
375 	union {
376 		struct	sockaddr ifrau_addr;
377 		int	ifrau_align;
378 	 } ifra_ifrau;
379 #ifndef ifra_addr
380 #define ifra_addr	ifra_ifrau.ifrau_addr
381 #endif
382 	struct	sockaddr ifra_dstaddr;
383 #define	ifra_broadaddr	ifra_dstaddr
384 	struct	sockaddr ifra_mask;
385 };
386 
387 struct ifmediareq {
388 	char	ifm_name[IFNAMSIZ];		/* if name, e.g. "en0" */
389 	int	ifm_current;			/* current media options */
390 	int	ifm_mask;			/* don't care mask */
391 	int	ifm_status;			/* media status */
392 	int	ifm_active;			/* active options */
393 	int	ifm_count;			/* # entries in ifm_ulist
394 							array */
395 	int	*ifm_ulist;			/* media words */
396 };
397 
398 struct ifkalivereq {
399 	char	ikar_name[IFNAMSIZ];		/* if name, e.g. "en0" */
400 	int	ikar_timeo;
401 	int	ikar_cnt;
402 };
403 
404 /*
405  * Structure used in SIOCGIFCONF request.
406  * Used to retrieve interface configuration
407  * for machine (useful for programs which
408  * must know all networks accessible).
409  */
410 struct	ifconf {
411 	int	ifc_len;		/* size of associated buffer */
412 	union {
413 		caddr_t	ifcu_buf;
414 		struct	ifreq *ifcu_req;
415 	} ifc_ifcu;
416 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
417 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
418 };
419 
420 /*
421  * Structure for SIOC[AGD]LIFADDR
422  */
423 struct if_laddrreq {
424 	char iflr_name[IFNAMSIZ];
425 	unsigned int flags;
426 #define IFLR_PREFIX	0x8000	/* in: prefix given  out: kernel fills id */
427 	unsigned int prefixlen;		/* in/out */
428 	struct sockaddr_storage addr;	/* in/out */
429 	struct sockaddr_storage dstaddr; /* out */
430 };
431 
432 #include <net/if_arp.h>
433 
434 #ifdef _KERNEL
435 #include <net/if_var.h>
436 #endif
437 
438 #endif /* __BSD_VISIBLE */
439 
440 #endif /* _NET_IF_H_ */
441