1a50ffc2imp/*-
24736ccfpfg * SPDX-License-Identifier: BSD-3-Clause
34736ccfpfg *
48fb65cergrimes * Copyright (c) 1982, 1986, 1989, 1993
58fb65cergrimes *	The Regents of the University of California.  All rights reserved.
68fb65cergrimes *
78fb65cergrimes * Redistribution and use in source and binary forms, with or without
88fb65cergrimes * modification, are permitted provided that the following conditions
98fb65cergrimes * are met:
108fb65cergrimes * 1. Redistributions of source code must retain the above copyright
118fb65cergrimes *    notice, this list of conditions and the following disclaimer.
128fb65cergrimes * 2. Redistributions in binary form must reproduce the above copyright
138fb65cergrimes *    notice, this list of conditions and the following disclaimer in the
148fb65cergrimes *    documentation and/or other materials provided with the distribution.
157e6cabdimp * 3. Neither the name of the University nor the names of its contributors
168fb65cergrimes *    may be used to endorse or promote products derived from this software
178fb65cergrimes *    without specific prior written permission.
188fb65cergrimes *
198fb65cergrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fb65cergrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fb65cergrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fb65cergrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fb65cergrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fb65cergrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fb65cergrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fb65cergrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fb65cergrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fb65cergrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fb65cergrimes * SUCH DAMAGE.
308fb65cergrimes *
318fb65cergrimes *	@(#)if.h	8.1 (Berkeley) 6/10/93
323b842d3peter * $FreeBSD$
338fb65cergrimes */
348fb65cergrimes
35be1bed5paul#ifndef _NET_IF_H_
36480097cbde#define	_NET_IF_H_
37be1bed5paul
387849239mike#include <sys/cdefs.h>
397849239mike
407849239mike#if __BSD_VISIBLE
418fb65cergrimes/*
42e4c65b8peter * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
437d76aceasmodai * helps userland compatibility.  (struct timeval ifi_lastchange)
44b18bd11ed * The same holds for <sys/socket.h>.  (struct sockaddr ifru_addr)
45e4c65b8peter */
4615b9bcbpeter#ifndef _KERNEL
47e4c65b8peter#include <sys/time.h>
48b18bd11ed#include <sys/socket.h>
49e4c65b8peter#endif
507849239mike#endif
515da97d8brooks
525da97d8brooks/*
535da97d8brooks * Length of interface external name, including terminating '\0'.
545da97d8brooks * Note: this is the same size as a generic device's external name.
555da97d8brooks */
567849239mike#define		IF_NAMESIZE	16
577849239mike#if __BSD_VISIBLE
587849239mike#define		IFNAMSIZ	IF_NAMESIZE
59f1e94c6brooks#define		IF_MAXUNIT	0x7fff	/* historical value */
607849239mike#endif
617849239mike#if __BSD_VISIBLE
627849239mike
635da97d8brooks/*
645da97d8brooks * Structure used to query names of interface cloners.
655da97d8brooks */
665da97d8brooks
675da97d8brooksstruct if_clonereq {
685da97d8brooks	int	ifcr_total;		/* total cloners (out) */
695da97d8brooks	int	ifcr_count;		/* room for this many in user buffer */
705da97d8brooks	char	*ifcr_buffer;		/* buffer for cloner names */
715da97d8brooks};
725da97d8brooks
73e4c65b8peter/*
74e6dd1aafenner * Structure describing information about an interface
75e6dd1aafenner * which may be of interest to management entities.
76e6dd1aafenner */
7714671cejoergstruct if_data {
7814671cejoerg	/* generic interface information */
79b38edcdglebius	uint8_t	ifi_type;		/* ethernet, tokenring, etc */
80b38edcdglebius	uint8_t	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
81b38edcdglebius	uint8_t	ifi_addrlen;		/* media address length */
82b38edcdglebius	uint8_t	ifi_hdrlen;		/* media header length */
83b38edcdglebius	uint8_t	ifi_link_state;		/* current link state */
84b38edcdglebius	uint8_t	ifi_vhid;		/* carp vhid */
85b38edcdglebius	uint16_t	ifi_datalen;	/* length of this data struct */
86b38edcdglebius	uint32_t	ifi_mtu;	/* maximum transmission unit */
87b38edcdglebius	uint32_t	ifi_metric;	/* routing metric (external only) */
88b38edcdglebius	uint64_t	ifi_baudrate;	/* linespeed */
8914671cejoerg	/* volatile statistics */
90b38edcdglebius	uint64_t	ifi_ipackets;	/* packets received on interface */
91b38edcdglebius	uint64_t	ifi_ierrors;	/* input errors on interface */
92b38edcdglebius	uint64_t	ifi_opackets;	/* packets sent on interface */
93b38edcdglebius	uint64_t	ifi_oerrors;	/* output errors on interface */
94b38edcdglebius	uint64_t	ifi_collisions;	/* collisions on csma interfaces */
95b38edcdglebius	uint64_t	ifi_ibytes;	/* total number of octets received */
96b38edcdglebius	uint64_t	ifi_obytes;	/* total number of octets sent */
97b38edcdglebius	uint64_t	ifi_imcasts;	/* packets received via multicast */
98b38edcdglebius	uint64_t	ifi_omcasts;	/* packets sent via multicast */
99b38edcdglebius	uint64_t	ifi_iqdrops;	/* dropped on input */
100b38edcdglebius	uint64_t	ifi_oqdrops;	/* dropped on output */
101b38edcdglebius	uint64_t	ifi_noproto;	/* destined for unsupported protocol */
102b38edcdglebius	uint64_t	ifi_hwassist;	/* HW offload capabilities, see IFCAP */
103b38edcdglebius
104b38edcdglebius	/* Unions are here to make sizes MI. */
105b38edcdglebius	union {				/* uptime at attach or stat reset */
106b38edcdglebius		time_t		tt;
107b38edcdglebius		uint64_t	ph;
108b38edcdglebius	} __ifi_epoch;
109b38edcdglebius#define	ifi_epoch	__ifi_epoch.tt
110b38edcdglebius	union {				/* time of last administrative change */
111b38edcdglebius		struct timeval	tv;
112b38edcdglebius		struct {
113b38edcdglebius			uint64_t ph1;
114b38edcdglebius			uint64_t ph2;
115b38edcdglebius		} ph;
116b38edcdglebius	} __ifi_lastchange;
117b38edcdglebius#define	ifi_lastchange	__ifi_lastchange.tv
11814671cejoerg};
11914671cejoerg
12076ad033rwatson/*-
12174759aarwatson * Interface flags are of two types: network stack owned flags, and driver
12274759aarwatson * owned flags.  Historically, these values were stored in the same ifnet
12374759aarwatson * flags field, but with the advent of fine-grained locking, they have been
12474759aarwatson * broken out such that the network stack is responsible for synchronizing
12574759aarwatson * the stack-owned fields, and the device driver the device-owned fields.
12674759aarwatson * Both halves can perform lockless reads of the other half's field, subject
12774759aarwatson * to accepting the involved races.
12874759aarwatson *
12974759aarwatson * Both sets of flags come from the same number space, and should not be
13074759aarwatson * permitted to conflict, as they are exposed to user space via a single
13174759aarwatson * field.
13274759aarwatson *
13376ad033rwatson * The following symbols identify read and write requirements for fields:
13476ad033rwatson *
13576ad033rwatson * (i) if_flags field set by device driver before attach, read-only there
13676ad033rwatson *     after.
13776ad033rwatson * (n) if_flags field written only by the network stack, read by either the
13876ad033rwatson *     stack or driver.
13976ad033rwatson * (d) if_drv_flags field written only by the device driver, read by either
14076ad033rwatson *     the stack or driver.
14174759aarwatson */
14276ad033rwatson#define	IFF_UP		0x1		/* (n) interface is up */
14376ad033rwatson#define	IFF_BROADCAST	0x2		/* (i) broadcast address valid */
14476ad033rwatson#define	IFF_DEBUG	0x4		/* (n) turn on debugging */
14576ad033rwatson#define	IFF_LOOPBACK	0x8		/* (i) is a loopback net */
14676ad033rwatson#define	IFF_POINTOPOINT	0x10		/* (i) is a point-to-point link */
147b285612glebius#define	IFF_KNOWSEPOCH	0x20		/* (i) calls if_input in net epoch */
14876ad033rwatson#define	IFF_DRV_RUNNING	0x40		/* (d) resources allocated */
14976ad033rwatson#define	IFF_NOARP	0x80		/* (n) no address resolution protocol */
15076ad033rwatson#define	IFF_PROMISC	0x100		/* (n) receive all packets */
15176ad033rwatson#define	IFF_ALLMULTI	0x200		/* (n) receive all multicast packets */
15276ad033rwatson#define	IFF_DRV_OACTIVE	0x400		/* (d) tx hardware queue is full */
15376ad033rwatson#define	IFF_SIMPLEX	0x800		/* (i) can't hear own transmissions */
1548fb65cergrimes#define	IFF_LINK0	0x1000		/* per link layer defined bit */
1558fb65cergrimes#define	IFF_LINK1	0x2000		/* per link layer defined bit */
1568fb65cergrimes#define	IFF_LINK2	0x4000		/* per link layer defined bit */
1577eee0c2wollman#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
15876ad033rwatson#define	IFF_MULTICAST	0x8000		/* (i) supports multicast */
1593341787weongyo#define	IFF_CANTCONFIG	0x10000		/* (i) unconfigurable using ioctl(2) */
16076ad033rwatson#define	IFF_PPROMISC	0x20000		/* (n) user-requested promisc mode */
16176ad033rwatson#define	IFF_MONITOR	0x40000		/* (n) user-requested monitor mode */
16276ad033rwatson#define	IFF_STATICARP	0x80000		/* (n) static ARP */
163c797841rwatson#define	IFF_DYING	0x200000	/* (n) interface is winding down */
1643ce93dcjhb#define	IFF_RENAMING	0x400000	/* (n) interface is being renamed */
1650a7aab5mmacy#define	IFF_NOGROUP	0x800000	/* (n) interface is not part of any groups */
1660a7aab5mmacy
16774759aarwatson/*
16874759aarwatson * Old names for driver flags so that user space tools can continue to use
16976ad033rwatson * the old (portable) names.
17074759aarwatson */
17174759aarwatson#ifndef _KERNEL
17274759aarwatson#define	IFF_RUNNING	IFF_DRV_RUNNING
17374759aarwatson#define	IFF_OACTIVE	IFF_DRV_OACTIVE
17474759aarwatson#endif
17574759aarwatson
1768fb65cergrimes/* flags set internally only: */
1778fb65cergrimes#define	IFF_CANTCHANGE \
17874759aarwatson	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\
179cb6df3fglebius	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC|\
180b285612glebius	    IFF_DYING|IFF_CANTCONFIG|IFF_KNOWSEPOCH)
1818fb65cergrimes
1827092aeasam/*
18325ae331andre * Values for if_link_state.
18425ae331andre */
18525ae331andre#define	LINK_STATE_UNKNOWN	0	/* link invalid/unknown */
18625ae331andre#define	LINK_STATE_DOWN		1	/* link is down */
18725ae331andre#define	LINK_STATE_UP		2	/* link is up */
18825ae331andre
18925ae331andre/*
1907092aeasam * Some convenience macros used for setting ifi_baudrate.
1917092aeasam * XXX 1000 vs. 1024? --thorpej@netbsd.org
1927092aeasam */
1930dfb309emax#define	IF_Kbps(x)	((uintmax_t)(x) * 1000)	/* kilobits/sec. */
1947092aeasam#define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
1957092aeasam#define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
1967092aeasam
197ae59650andre/*
198ae59650andre * Capabilities that interfaces can advertise.
199ae59650andre *
200ae59650andre * struct ifnet.if_capabilities
201ae59650andre *   contains the optional features & capabilities a particular interface
202ae59650andre *   supports (not only the driver but also the detected hw revision).
203ae59650andre *   Capabilities are defined by IFCAP_* below.
20478898eayar * struct ifnet.if_capenable
205ae59650andre *   contains the enabled (either by default or through ifconfig) optional
206ae59650andre *   features & capabilities on this interface.
207ae59650andre *   Capabilities are defined by IFCAP_* below.
208ae59650andre * struct if_data.ifi_hwassist in mbuf CSUM_ flag form, controlled by above
209ae59650andre *   contains the enabled optional feature & capabilites that can be used
210ae59650andre *   individually per packet and are specified in the mbuf pkthdr.csum_flags
211ae59650andre *   field.  IFCAP_* and CSUM_* do not match one to one and CSUM_* may be
212838e018kib *   more detailed or differentiated than IFCAP_*.
213ae59650andre *   Hwassist features are defined CSUM_* in sys/mbuf.h
2147cd78b9luigi *
2157cd78b9luigi * Capabilities that cannot be arbitrarily changed with ifconfig/ioctl
2167cd78b9luigi * are listed in IFCAP_CANTCHANGE, similar to IFF_CANTCHANGE.
2177cd78b9luigi * This is not strictly necessary because the common code never
2187cd78b9luigi * changes capabilities, and it is left to the individual driver
2197cd78b9luigi * to do the right thing. However, having the filter here
2207cd78b9luigi * avoids replication of the same code in all individual drivers.
221ae59650andre */
222e4ffb4bjfv#define	IFCAP_RXCSUM		0x00001  /* can offload checksum on RX */
223e4ffb4bjfv#define	IFCAP_TXCSUM		0x00002  /* can offload checksum on TX */
224e4ffb4bjfv#define	IFCAP_NETCONS		0x00004  /* can be a network console */
225e4ffb4bjfv#define	IFCAP_VLAN_MTU		0x00008	/* VLAN-compatible MTU */
226e4ffb4bjfv#define	IFCAP_VLAN_HWTAGGING	0x00010	/* hardware VLAN tag support */
227e4ffb4bjfv#define	IFCAP_JUMBO_MTU		0x00020	/* 9000 byte MTU supported */
228e4ffb4bjfv#define	IFCAP_POLLING		0x00040	/* driver supports polling */
229e4ffb4bjfv#define	IFCAP_VLAN_HWCSUM	0x00080	/* can do IFCAP_HWCSUM on VLANs */
230e4ffb4bjfv#define	IFCAP_TSO4		0x00100	/* can do TCP Segmentation Offload */
231e4ffb4bjfv#define	IFCAP_TSO6		0x00200	/* can do TCP6 Segmentation Offload */
232e4ffb4bjfv#define	IFCAP_LRO		0x00400	/* can do Large Receive Offload */
233e4ffb4bjfv#define	IFCAP_WOL_UCAST		0x00800	/* wake on any unicast frame */
234e4ffb4bjfv#define	IFCAP_WOL_MCAST		0x01000	/* wake on any multicast frame */
235e4ffb4bjfv#define	IFCAP_WOL_MAGIC		0x02000	/* wake on any Magic Packet */
236e4ffb4bjfv#define	IFCAP_TOE4		0x04000	/* interface can offload TCP */
237e4ffb4bjfv#define	IFCAP_TOE6		0x08000	/* interface can offload TCP6 */
238e4ffb4bjfv#define	IFCAP_VLAN_HWFILTER	0x10000 /* interface hw can filter vlan tag */
2399c54c9cglebius/* 	available		0x20000 */
240453676ayongari#define	IFCAP_VLAN_HWTSO	0x40000 /* can do IFCAP_TSO on VLANs */
2414ff4954qingli#define	IFCAP_LINKSTATE		0x80000 /* the runtime link state is dynamic */
2427cd78b9luigi#define	IFCAP_NETMAP		0x100000 /* netmap mode supported/enabled */
243ac429c7bz#define	IFCAP_RXCSUM_IPV6	0x200000  /* can offload checksum on IPv6 RX */
244ac429c7bz#define	IFCAP_TXCSUM_IPV6	0x400000  /* can offload checksum on IPv6 TX */
24575528d8glebius#define	IFCAP_HWSTATS		0x800000 /* manages counters internally */
246efa6326hselasky#define	IFCAP_TXRTLMT		0x1000000 /* hardware supports TX rate limiting */
247ce9362dkib#define	IFCAP_HWRXTSTMP		0x2000000 /* hardware rx timestamping */
248520aafejhb#define	IFCAP_NOMAP		0x4000000 /* can TX unmapped mbufs */
2491cf3162jhb#define	IFCAP_TXTLS4		0x8000000 /* can do TLS encryption and segmentation for TCP */
2501cf3162jhb#define	IFCAP_TXTLS6		0x10000000 /* can do TLS encryption and segmentation for TCP6 */
2513706815np#define	IFCAP_VXLAN_HWCSUM	0x20000000 /* can do IFCAN_HWCSUM on VXLANs */
2523706815np#define	IFCAP_VXLAN_HWTSO	0x40000000 /* can do IFCAP_TSO on VXLANs */
253ac429c7bz
254ac429c7bz#define IFCAP_HWCSUM_IPV6	(IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6)
25528193b2jlemon
2560895454sam#define IFCAP_HWCSUM	(IFCAP_RXCSUM | IFCAP_TXCSUM)
2570895454sam#define	IFCAP_TSO	(IFCAP_TSO4 | IFCAP_TSO6)
2580895454sam#define	IFCAP_WOL	(IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC)
25996bf4f5kmacy#define	IFCAP_TOE	(IFCAP_TOE4 | IFCAP_TOE6)
2601cf3162jhb#define	IFCAP_TXTLS	(IFCAP_TXTLS4 | IFCAP_TXTLS6)
261131e3adjlemon
2627cd78b9luigi#define	IFCAP_CANTCHANGE	(IFCAP_NETMAP)
2637cd78b9luigi
2648fb65cergrimes#define	IFQ_MAXLEN	50
2658fb65cergrimes#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
2668fb65cergrimes
2678fb65cergrimes/*
2688fb65cergrimes * Message format for use in obtaining information about interfaces
2698fb65cergrimes * from getkerninfo and the routing socket
270d05091dbz * For the new, extensible interface see struct if_msghdrl below.
2718fb65cergrimes */
2728fb65cergrimesstruct if_msghdr {
2738fb65cergrimes	u_short	ifm_msglen;	/* to skip over non-understood messages */
2747d76aceasmodai	u_char	ifm_version;	/* future binary compatibility */
2758fb65cergrimes	u_char	ifm_type;	/* message type */
2768fb65cergrimes	int	ifm_addrs;	/* like rtm_addrs */
2778fb65cergrimes	int	ifm_flags;	/* value of if_flags */
2788fb65cergrimes	u_short	ifm_index;	/* index for associated ifp */
2794bb7057markj	u_short	_ifm_spare1;
2808fb65cergrimes	struct	if_data ifm_data;/* statistics and other data about if */
2818fb65cergrimes};
2828fb65cergrimes
2838fb65cergrimes/*
284d05091dbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
285d05091dbz * extensible after ifm_data_off or within ifm_data.  Both the if_msghdr and
286d05091dbz * if_data now have a member field detailing the struct length in addition to
287d05091dbz * the routing message length.  Macros are provided to find the start of
288d05091dbz * ifm_data and the start of the socket address strucutres immediately following
289d05091dbz * struct if_msghdrl given a pointer to struct if_msghdrl.
290d05091dbz */
291d05091dbz#define	IF_MSGHDRL_IFM_DATA(_l) \
292d05091dbz    (struct if_data *)((char *)(_l) + (_l)->ifm_data_off)
293d05091dbz#define	IF_MSGHDRL_RTA(_l) \
294d05091dbz    (void *)((uintptr_t)(_l) + (_l)->ifm_len)
295d05091dbzstruct if_msghdrl {
296d05091dbz	u_short	ifm_msglen;	/* to skip over non-understood messages */
297d05091dbz	u_char	ifm_version;	/* future binary compatibility */
298d05091dbz	u_char	ifm_type;	/* message type */
299d05091dbz	int	ifm_addrs;	/* like rtm_addrs */
300d05091dbz	int	ifm_flags;	/* value of if_flags */
301d05091dbz	u_short	ifm_index;	/* index for associated ifp */
302d05091dbz	u_short _ifm_spare1;	/* spare space to grow if_index, see if_var.h */
303d05091dbz	u_short	ifm_len;	/* length of if_msghdrl incl. if_data */
304d05091dbz	u_short	ifm_data_off;	/* offset of if_data from beginning */
3054bb7057markj	int	_ifm_spare2;
306d05091dbz	struct	if_data ifm_data;/* statistics and other data about if */
307d05091dbz};
308d05091dbz
309d05091dbz/*
3108fb65cergrimes * Message format for use in obtaining information about interface addresses
3118fb65cergrimes * from getkerninfo and the routing socket
312d05091dbz * For the new, extensible interface see struct ifa_msghdrl below.
3138fb65cergrimes */
3148fb65cergrimesstruct ifa_msghdr {
3158fb65cergrimes	u_short	ifam_msglen;	/* to skip over non-understood messages */
3167d76aceasmodai	u_char	ifam_version;	/* future binary compatibility */
3178fb65cergrimes	u_char	ifam_type;	/* message type */
3188fb65cergrimes	int	ifam_addrs;	/* like rtm_addrs */
3198fb65cergrimes	int	ifam_flags;	/* value of ifa_flags */
3208fb65cergrimes	u_short	ifam_index;	/* index for associated ifp */
3214bb7057markj	u_short	_ifam_spare1;
322d32e428glebius	int	ifam_metric;	/* value of ifa_ifp->if_metric */
3238fb65cergrimes};
3248fb65cergrimes
3258fb65cergrimes/*
326d05091dbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
327d05091dbz * extensible after ifam_metric or within ifam_data.  Both the ifa_msghdrl and
328d05091dbz * if_data now have a member field detailing the struct length in addition to
329d05091dbz * the routing message length.  Macros are provided to find the start of
330d05091dbz * ifm_data and the start of the socket address strucutres immediately following
331d05091dbz * struct ifa_msghdrl given a pointer to struct ifa_msghdrl.
332d05091dbz */
333d05091dbz#define	IFA_MSGHDRL_IFAM_DATA(_l) \
334d05091dbz    (struct if_data *)((char *)(_l) + (_l)->ifam_data_off)
335d05091dbz#define	IFA_MSGHDRL_RTA(_l) \
336d05091dbz    (void *)((uintptr_t)(_l) + (_l)->ifam_len)
337d05091dbzstruct ifa_msghdrl {
338d05091dbz	u_short	ifam_msglen;	/* to skip over non-understood messages */
339d05091dbz	u_char	ifam_version;	/* future binary compatibility */
340d05091dbz	u_char	ifam_type;	/* message type */
341d05091dbz	int	ifam_addrs;	/* like rtm_addrs */
342d05091dbz	int	ifam_flags;	/* value of ifa_flags */
343d05091dbz	u_short	ifam_index;	/* index for associated ifp */
344d05091dbz	u_short _ifam_spare1;	/* spare space to grow if_index, see if_var.h */
345d05091dbz	u_short	ifam_len;	/* length of ifa_msghdrl incl. if_data */
346d05091dbz	u_short	ifam_data_off;	/* offset of if_data from beginning */
347d32e428glebius	int	ifam_metric;	/* value of ifa_ifp->if_metric */
348d05091dbz	struct	if_data ifam_data;/* statistics and other data about if or
349d05091dbz				 * address */
350d05091dbz};
351d05091dbz
352d05091dbz/*
35319e2ac9wollman * Message format for use in obtaining information about multicast addresses
35419e2ac9wollman * from the routing socket
35519e2ac9wollman */
35619e2ac9wollmanstruct ifma_msghdr {
35719e2ac9wollman	u_short	ifmam_msglen;	/* to skip over non-understood messages */
3587d76aceasmodai	u_char	ifmam_version;	/* future binary compatibility */
35919e2ac9wollman	u_char	ifmam_type;	/* message type */
36019e2ac9wollman	int	ifmam_addrs;	/* like rtm_addrs */
36119e2ac9wollman	int	ifmam_flags;	/* value of ifa_flags */
36219e2ac9wollman	u_short	ifmam_index;	/* index for associated ifp */
3634bb7057markj	u_short	_ifmam_spare1;
36419e2ac9wollman};
36519e2ac9wollman
36619e2ac9wollman/*
3677bbde3fru * Message format announcing the arrival or departure of a network interface.
3687bbde3fru */
3697bbde3frustruct if_announcemsghdr {
3707bbde3fru	u_short	ifan_msglen;	/* to skip over non-understood messages */
3717bbde3fru	u_char	ifan_version;	/* future binary compatibility */
3727bbde3fru	u_char	ifan_type;	/* message type */
3737bbde3fru	u_short	ifan_index;	/* index for associated ifp */
3747bbde3fru	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
3757bbde3fru	u_short	ifan_what;	/* what type of announcement */
3767bbde3fru};
3777bbde3fru
3787bbde3fru#define	IFAN_ARRIVAL	0	/* interface arrival */
3797bbde3fru#define	IFAN_DEPARTURE	1	/* interface departure */
3807bbde3fru
3817bbde3fru/*
382d9a0cd0delphij * Buffer with length to be used in SIOCGIFDESCR/SIOCSIFDESCR requests
383d9a0cd0delphij */
384d9a0cd0delphijstruct ifreq_buffer {
385d9a0cd0delphij	size_t	length;
386d9a0cd0delphij	void	*buffer;
387d9a0cd0delphij};
388d9a0cd0delphij
389d9a0cd0delphij/*
3908fb65cergrimes * Interface request structure used for socket
3918fb65cergrimes * ioctl's.  All interface ioctl's must have parameter
3928fb65cergrimes * definitions which begin with ifr_name.  The
3938fb65cergrimes * remainder may be interface specific.
3948fb65cergrimes */
3958fb65cergrimesstruct	ifreq {
3968fb65cergrimes	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
3978fb65cergrimes	union {
3988fb65cergrimes		struct	sockaddr ifru_addr;
3998fb65cergrimes		struct	sockaddr ifru_dstaddr;
4008fb65cergrimes		struct	sockaddr ifru_broadaddr;
401d9a0cd0delphij		struct	ifreq_buffer ifru_buffer;
40279b9e4ephk		short	ifru_flags[2];
40385e1c08jlemon		short	ifru_index;
4045675a54jamie		int	ifru_jid;
4058fb65cergrimes		int	ifru_metric;
40677ebe22dg		int	ifru_mtu;
4077d587b9wollman		int	ifru_phys;
40897edcdfpeter		int	ifru_media;
4098fb65cergrimes		caddr_t	ifru_data;
410131e3adjlemon		int	ifru_cap[2];
4119cad5bfbz		u_int	ifru_fib;
412af4ff98araujo		u_char	ifru_vlan_pcp;
4138fb65cergrimes	} ifr_ifru;
4148fb65cergrimes#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
4158fb65cergrimes#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
4168fb65cergrimes#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
4170754c52brooks#ifndef _KERNEL
418d9a0cd0delphij#define	ifr_buffer	ifr_ifru.ifru_buffer	/* user supplied buffer with its length */
4190754c52brooks#endif
420f6cebc0sobomax#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
421f6cebc0sobomax#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
4225675a54jamie#define	ifr_jid		ifr_ifru.ifru_jid	/* jail/vnet */
4238fb65cergrimes#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
42477ebe22dg#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
4254022b9ddg#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
42697edcdfpeter#define ifr_media	ifr_ifru.ifru_media	/* physical media */
427ac0325bbrooks#ifndef _KERNEL
4288fb65cergrimes#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
429ac0325bbrooks#endif
430131e3adjlemon#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
431131e3adjlemon#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
43285e1c08jlemon#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
4339cad5bfbz#define	ifr_fib		ifr_ifru.ifru_fib	/* interface fib */
434af4ff98araujo#define	ifr_vlan_pcp	ifr_ifru.ifru_vlan_pcp	/* VLAN priority */
4359de2156kib#define	ifr_lan_pcp	ifr_ifru.ifru_vlan_pcp	/* VLAN priority */
4368fb65cergrimes};
4378fb65cergrimes
4386ce595awollman#define	_SIZEOF_ADDR_IFREQ(ifr) \
4396ce595awollman	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
4406ce595awollman	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
4416ce595awollman	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
4426ce595awollman
4438fb65cergrimesstruct ifaliasreq {
4448fb65cergrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
4458fb65cergrimes	struct	sockaddr ifra_addr;
4468fb65cergrimes	struct	sockaddr ifra_broadaddr;
4478fb65cergrimes	struct	sockaddr ifra_mask;
44827a36f6glebius	int	ifra_vhid;
4498fb65cergrimes};
4508fb65cergrimes
4511dbe949glebius/* 9.x compat */
4521dbe949glebiusstruct oifaliasreq {
4531dbe949glebius	char	ifra_name[IFNAMSIZ];
4541dbe949glebius	struct	sockaddr ifra_addr;
4551dbe949glebius	struct	sockaddr ifra_broadaddr;
4561dbe949glebius	struct	sockaddr ifra_mask;
4571dbe949glebius};
4581dbe949glebius
45997edcdfpeterstruct ifmediareq {
46097edcdfpeter	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
46197edcdfpeter	int	ifm_current;		/* current media options */
46297edcdfpeter	int	ifm_mask;		/* don't care mask */
46397edcdfpeter	int	ifm_status;		/* media status */
46497edcdfpeter	int	ifm_active;		/* active options */
46597edcdfpeter	int	ifm_count;		/* # entries in ifm_ulist array */
46697edcdfpeter	int	*ifm_ulist;		/* media words */
46797edcdfpeter};
4681048fa7phk
4696c5bddathompsastruct  ifdrv {
4706c5bddathompsa	char            ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
4716c5bddathompsa	unsigned long   ifd_cmd;
4726c5bddathompsa	size_t          ifd_len;
4736c5bddathompsa	void            *ifd_data;
4746c5bddathompsa};
4756c5bddathompsa
4761048fa7phk/*
4771048fa7phk * Structure used to retrieve aux status data from interfaces.
478d20b3b0bde * Kernel suppliers to this interface should respect the formatting
4791048fa7phk * needed by ifconfig(8): each line starts with a TAB and ends with
480d20b3b0bde * a newline.  The canonical example to copy and paste is in if_tun.c.
4811048fa7phk */
4821048fa7phk
483d20b3b0bde#define	IFSTATMAX	800		/* 10 lines of text */
4841048fa7phkstruct ifstat {
485d20b3b0bde	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
486d20b3b0bde	char	ascii[IFSTATMAX + 1];
4871048fa7phk};
4881048fa7phk
4898fb65cergrimes/*
4908fb65cergrimes * Structure used in SIOCGIFCONF request.
4918fb65cergrimes * Used to retrieve interface configuration
4928fb65cergrimes * for machine (useful for programs which
4938fb65cergrimes * must know all networks accessible).
4948fb65cergrimes */
4958fb65cergrimesstruct	ifconf {
4968fb65cergrimes	int	ifc_len;		/* size of associated buffer */
4978fb65cergrimes	union {
4988fb65cergrimes		caddr_t	ifcu_buf;
4998fb65cergrimes		struct	ifreq *ifcu_req;
5008fb65cergrimes	} ifc_ifcu;
5018fb65cergrimes#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
5028fb65cergrimes#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
5038fb65cergrimes};
5048fb65cergrimes
5057efc91cshin/*
506f5cde28mlaier * interface groups
507f5cde28mlaier */
508f5cde28mlaier
509f5cde28mlaier#define	IFG_ALL		"all"		/* group contains all interfaces */
510f5cde28mlaier/* XXX: will we implement this? */
511f5cde28mlaier#define	IFG_EGRESS	"egress"	/* if(s) default route(s) point to */
512f5cde28mlaier
513f5cde28mlaierstruct ifg_req {
514f5cde28mlaier	union {
515f5cde28mlaier		char			 ifgrqu_group[IFNAMSIZ];
516f5cde28mlaier		char			 ifgrqu_member[IFNAMSIZ];
517f5cde28mlaier	} ifgrq_ifgrqu;
518f5cde28mlaier#define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
519f5cde28mlaier#define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
520f5cde28mlaier};
521f5cde28mlaier
522f5cde28mlaier/*
523f5cde28mlaier * Used to lookup groups for an interface
524f5cde28mlaier */
525f5cde28mlaierstruct ifgroupreq {
526f5cde28mlaier	char	ifgr_name[IFNAMSIZ];
527f5cde28mlaier	u_int	ifgr_len;
528f5cde28mlaier	union {
529f5cde28mlaier		char	ifgru_group[IFNAMSIZ];
530f5cde28mlaier		struct	ifg_req *ifgru_groups;
531f5cde28mlaier	} ifgr_ifgru;
5320080e81brooks#ifndef _KERNEL
533f5cde28mlaier#define ifgr_group	ifgr_ifgru.ifgru_group
534f5cde28mlaier#define ifgr_groups	ifgr_ifgru.ifgru_groups
5350080e81brooks#endif
536f5cde28mlaier};
537f5cde28mlaier
53869a7deamelifaro/*
53969a7deamelifaro * Structure used to request i2c data
54069a7deamelifaro * from interface transceivers.
54169a7deamelifaro */
54269a7deamelifarostruct ifi2creq {
54369a7deamelifaro	uint8_t dev_addr;	/* i2c address (0xA0, 0xA2) */
54469a7deamelifaro	uint8_t offset;		/* read offset */
54569a7deamelifaro	uint8_t len;		/* read length */
54669a7deamelifaro	uint8_t spare0;
54769a7deamelifaro	uint32_t spare1;
54869a7deamelifaro	uint8_t data[8];	/* read buffer */
54969a7deamelifaro};
55069a7deamelifaro
5517d1e282sephe/*
5527d1e282sephe * RSS hash.
5537d1e282sephe */
5547d1e282sephe
5557d1e282sephe#define	RSS_FUNC_NONE		0		/* RSS disabled */
5567d1e282sephe#define	RSS_FUNC_PRIVATE	1		/* non-standard */
5577d1e282sephe#define	RSS_FUNC_TOEPLITZ	2
5587d1e282sephe
5597d1e282sephe#define	RSS_TYPE_IPV4		0x00000001
5607d1e282sephe#define	RSS_TYPE_TCP_IPV4	0x00000002
5617d1e282sephe#define	RSS_TYPE_IPV6		0x00000004
5627d1e282sephe#define	RSS_TYPE_IPV6_EX	0x00000008
5637d1e282sephe#define	RSS_TYPE_TCP_IPV6	0x00000010
5647d1e282sephe#define	RSS_TYPE_TCP_IPV6_EX	0x00000020
5657d1e282sephe#define	RSS_TYPE_UDP_IPV4	0x00000040
5667d1e282sephe#define	RSS_TYPE_UDP_IPV6	0x00000080
5677d1e282sephe#define	RSS_TYPE_UDP_IPV6_EX	0x00000100
5687d1e282sephe
5697d1e282sephe#define	RSS_KEYLEN		128
5707d1e282sephe
5717d1e282sephestruct ifrsskey {
5727d1e282sephe	char		ifrk_name[IFNAMSIZ];	/* if name, e.g. "en0" */
5737d1e282sephe	uint8_t		ifrk_func;		/* RSS_FUNC_ */
5747d1e282sephe	uint8_t		ifrk_spare0;
5757d1e282sephe	uint16_t	ifrk_keylen;
5767d1e282sephe	uint8_t		ifrk_key[RSS_KEYLEN];
5777d1e282sephe};
5787d1e282sephe
5797d1e282sephestruct ifrsshash {
5807d1e282sephe	char		ifrh_name[IFNAMSIZ];	/* if name, e.g. "en0" */
5817d1e282sephe	uint8_t		ifrh_func;		/* RSS_FUNC_ */
5827d1e282sephe	uint8_t		ifrh_spare0;
5837d1e282sephe	uint16_t	ifrh_spare1;
5847d1e282sephe	uint32_t	ifrh_types;		/* RSS_TYPE_ */
5857d1e282sephe};
5867d1e282sephe
5879de2156kib#define	IFNET_PCP_NONE	0xff	/* PCP disabled */
5889de2156kib
589465bfaekib#define	IFDR_MSG_SIZE		64
590465bfaekib#define	IFDR_REASON_MSG		1
591465bfaekib#define	IFDR_REASON_VENDOR	2
592465bfaekibstruct ifdownreason {
593465bfaekib	char		ifdr_name[IFNAMSIZ];
594465bfaekib	uint32_t	ifdr_reason;
595465bfaekib	uint32_t	ifdr_vendor;
596465bfaekib	char		ifdr_msg[IFDR_MSG_SIZE];
597465bfaekib};
598465bfaekib
5997849239mike#endif /* __BSD_VISIBLE */
6007849239mike
60115b9bcbpeter#ifdef _KERNEL
60236e7a51phk#ifdef MALLOC_DECLARE
60336e7a51phkMALLOC_DECLARE(M_IFADDR);
60436e7a51phkMALLOC_DECLARE(M_IFMADDR);
60536e7a51phk#endif
60636e7a51phk#endif
60736e7a51phk
60815b9bcbpeter#ifndef _KERNEL
6097efc91cshinstruct if_nameindex {
6107849239mike	unsigned int	if_index;	/* 1, 2, ... */
61173d2354mike	char		*if_name;	/* null terminated name: "le0", ... */
6127efc91cshin};
6137efc91cshin
6147efc91cshin__BEGIN_DECLS
61573d2354mikevoid			 if_freenameindex(struct if_nameindex *);
61673d2354mikechar			*if_indextoname(unsigned int, char *);
61773d2354mikestruct if_nameindex	*if_nameindex(void);
61873d2354mikeunsigned int		 if_nametoindex(const char *);
6197efc91cshin__END_DECLS
6207efc91cshin#endif
621480097cbde#endif /* !_NET_IF_H_ */
622