1139823Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)if.h	8.1 (Berkeley) 6/10/93
3050477Speter * $FreeBSD: stable/10/sys/net/if.h 324462 2017-10-10 02:35:04Z sephe $
311541Srgrimes */
321541Srgrimes
332168Spaul#ifndef _NET_IF_H_
344507Sbde#define	_NET_IF_H_
352168Spaul
36104355Smike#include <sys/cdefs.h>
37104355Smike
3897024Siedowse#ifdef _KERNEL
3979103Sbrooks#include <sys/queue.h>
4097024Siedowse#endif
4179103Sbrooks
42104355Smike#if __BSD_VISIBLE
431541Srgrimes/*
4434750Speter * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
4572093Sasmodai * helps userland compatibility.  (struct timeval ifi_lastchange)
46226610Sed * The same holds for <sys/socket.h>.  (struct sockaddr ifru_addr)
4734750Speter */
4855205Speter#ifndef _KERNEL
4934750Speter#include <sys/time.h>
50226610Sed#include <sys/socket.h>
5134750Speter#endif
5234750Speter
5379103Sbrooksstruct ifnet;
54104355Smike#endif
5579103Sbrooks
5634750Speter/*
5779103Sbrooks * Length of interface external name, including terminating '\0'.
5879103Sbrooks * Note: this is the same size as a generic device's external name.
5979103Sbrooks */
60104355Smike#define		IF_NAMESIZE	16
61104355Smike#if __BSD_VISIBLE
62104355Smike#define		IFNAMSIZ	IF_NAMESIZE
63121816Sbrooks#define		IF_MAXUNIT	0x7fff	/* historical value */
64104355Smike#endif
65104355Smike#if __BSD_VISIBLE
66104355Smike
6779103Sbrooks/*
6879103Sbrooks * Structure used to query names of interface cloners.
6979103Sbrooks */
7079103Sbrooks
7179103Sbrooksstruct if_clonereq {
7279103Sbrooks	int	ifcr_total;		/* total cloners (out) */
7379103Sbrooks	int	ifcr_count;		/* room for this many in user buffer */
7479103Sbrooks	char	*ifcr_buffer;		/* buffer for cloner names */
7579103Sbrooks};
7679103Sbrooks
7779103Sbrooks/*
7819079Sfenner * Structure describing information about an interface
7919079Sfenner * which may be of interest to management entities.
8019079Sfenner */
819457Sjoergstruct if_data {
829457Sjoerg	/* generic interface information */
839457Sjoerg	u_char	ifi_type;		/* ethernet, tokenring, etc */
849457Sjoerg	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
859457Sjoerg	u_char	ifi_addrlen;		/* media address length */
869457Sjoerg	u_char	ifi_hdrlen;		/* media header length */
87128871Sandre	u_char	ifi_link_state;		/* current link state */
88228571Sglebius	u_char	ifi_vhid;		/* carp vhid */
89241616Semax	u_char	ifi_baudrate_pf;	/* baudrate power factor */
90134609Sbrooks	u_char	ifi_datalen;		/* length of this data struct */
919457Sjoerg	u_long	ifi_mtu;		/* maximum transmission unit */
929457Sjoerg	u_long	ifi_metric;		/* routing metric (external only) */
939457Sjoerg	u_long	ifi_baudrate;		/* linespeed */
949457Sjoerg	/* volatile statistics */
959457Sjoerg	u_long	ifi_ipackets;		/* packets received on interface */
969457Sjoerg	u_long	ifi_ierrors;		/* input errors on interface */
979457Sjoerg	u_long	ifi_opackets;		/* packets sent on interface */
989457Sjoerg	u_long	ifi_oerrors;		/* output errors on interface */
999457Sjoerg	u_long	ifi_collisions;		/* collisions on csma interfaces */
1009457Sjoerg	u_long	ifi_ibytes;		/* total number of octets received */
1019457Sjoerg	u_long	ifi_obytes;		/* total number of octets sent */
1029457Sjoerg	u_long	ifi_imcasts;		/* packets received via multicast */
1039457Sjoerg	u_long	ifi_omcasts;		/* packets sent via multicast */
1049457Sjoerg	u_long	ifi_iqdrops;		/* dropped on input, this interface */
1059457Sjoerg	u_long	ifi_noproto;		/* destined for unsupported protocol */
106254804Sandre	uint64_t ifi_hwassist;		/* HW offload capabilities, see IFCAP */
107142501Sbrooks	time_t	ifi_epoch;		/* uptime at attach or stat reset */
10816287Sgpalmer	struct	timeval ifi_lastchange;	/* time of last administrative change */
109264076Sglebius#ifdef _IFI_OQDROPS
110264076Sglebius	u_long	ifi_oqdrops;		/* dropped on output */
111264076Sglebius#endif
1129457Sjoerg};
1139457Sjoerg
114148894Srwatson/*-
115148886Srwatson * Interface flags are of two types: network stack owned flags, and driver
116148886Srwatson * owned flags.  Historically, these values were stored in the same ifnet
117148886Srwatson * flags field, but with the advent of fine-grained locking, they have been
118148886Srwatson * broken out such that the network stack is responsible for synchronizing
119148886Srwatson * the stack-owned fields, and the device driver the device-owned fields.
120148886Srwatson * Both halves can perform lockless reads of the other half's field, subject
121148886Srwatson * to accepting the involved races.
122148886Srwatson *
123148886Srwatson * Both sets of flags come from the same number space, and should not be
124148886Srwatson * permitted to conflict, as they are exposed to user space via a single
125148886Srwatson * field.
126148886Srwatson *
127148894Srwatson * The following symbols identify read and write requirements for fields:
128148894Srwatson *
129148894Srwatson * (i) if_flags field set by device driver before attach, read-only there
130148894Srwatson *     after.
131148894Srwatson * (n) if_flags field written only by the network stack, read by either the
132148894Srwatson *     stack or driver.
133148894Srwatson * (d) if_drv_flags field written only by the device driver, read by either
134148894Srwatson *     the stack or driver.
135148886Srwatson */
136148894Srwatson#define	IFF_UP		0x1		/* (n) interface is up */
137148894Srwatson#define	IFF_BROADCAST	0x2		/* (i) broadcast address valid */
138148894Srwatson#define	IFF_DEBUG	0x4		/* (n) turn on debugging */
139148894Srwatson#define	IFF_LOOPBACK	0x8		/* (i) is a loopback net */
140148894Srwatson#define	IFF_POINTOPOINT	0x10		/* (i) is a point-to-point link */
141148894Srwatson#define	IFF_SMART	0x20		/* (i) interface manages own routes */
142148894Srwatson#define	IFF_DRV_RUNNING	0x40		/* (d) resources allocated */
143148894Srwatson#define	IFF_NOARP	0x80		/* (n) no address resolution protocol */
144148894Srwatson#define	IFF_PROMISC	0x100		/* (n) receive all packets */
145148894Srwatson#define	IFF_ALLMULTI	0x200		/* (n) receive all multicast packets */
146148894Srwatson#define	IFF_DRV_OACTIVE	0x400		/* (d) tx hardware queue is full */
147148894Srwatson#define	IFF_SIMPLEX	0x800		/* (i) can't hear own transmissions */
1481541Srgrimes#define	IFF_LINK0	0x1000		/* per link layer defined bit */
1491541Srgrimes#define	IFF_LINK1	0x2000		/* per link layer defined bit */
1501541Srgrimes#define	IFF_LINK2	0x4000		/* per link layer defined bit */
1513274Swollman#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
152148894Srwatson#define	IFF_MULTICAST	0x8000		/* (i) supports multicast */
153216267Sweongyo#define	IFF_CANTCONFIG	0x10000		/* (i) unconfigurable using ioctl(2) */
154148894Srwatson#define	IFF_PPROMISC	0x20000		/* (n) user-requested promisc mode */
155148894Srwatson#define	IFF_MONITOR	0x40000		/* (n) user-requested monitor mode */
156148894Srwatson#define	IFF_STATICARP	0x80000		/* (n) static ARP */
157191416Srwatson#define	IFF_DYING	0x200000	/* (n) interface is winding down */
158201196Sjhb#define	IFF_RENAMING	0x400000	/* (n) interface is being renamed */
159148886Srwatson/*
160148886Srwatson * Old names for driver flags so that user space tools can continue to use
161148894Srwatson * the old (portable) names.
162148886Srwatson */
163148886Srwatson#ifndef _KERNEL
164148886Srwatson#define	IFF_RUNNING	IFF_DRV_RUNNING
165148886Srwatson#define	IFF_OACTIVE	IFF_DRV_OACTIVE
166148886Srwatson#endif
167148886Srwatson
1681541Srgrimes/* flags set internally only: */
1691541Srgrimes#define	IFF_CANTCHANGE \
170148886Srwatson	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\
171191416Srwatson	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
172216268Sweongyo	    IFF_DYING|IFF_CANTCONFIG)
1731541Srgrimes
174106925Ssam/*
175128871Sandre * Values for if_link_state.
176128871Sandre */
177128871Sandre#define	LINK_STATE_UNKNOWN	0	/* link invalid/unknown */
178128871Sandre#define	LINK_STATE_DOWN		1	/* link is down */
179128871Sandre#define	LINK_STATE_UP		2	/* link is up */
180128871Sandre
181128871Sandre/*
182106925Ssam * Some convenience macros used for setting ifi_baudrate.
183106925Ssam * XXX 1000 vs. 1024? --thorpej@netbsd.org
184106925Ssam */
185241646Semax#define	IF_Kbps(x)	((uintmax_t)(x) * 1000)	/* kilobits/sec. */
186106925Ssam#define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
187106925Ssam#define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
188106925Ssam
189162070Sandre/*
190162070Sandre * Capabilities that interfaces can advertise.
191162070Sandre *
192162070Sandre * struct ifnet.if_capabilities
193162070Sandre *   contains the optional features & capabilities a particular interface
194162070Sandre *   supports (not only the driver but also the detected hw revision).
195162070Sandre *   Capabilities are defined by IFCAP_* below.
196169207Syar * struct ifnet.if_capenable
197162070Sandre *   contains the enabled (either by default or through ifconfig) optional
198162070Sandre *   features & capabilities on this interface.
199162070Sandre *   Capabilities are defined by IFCAP_* below.
200162070Sandre * struct if_data.ifi_hwassist in mbuf CSUM_ flag form, controlled by above
201162070Sandre *   contains the enabled optional feature & capabilites that can be used
202162070Sandre *   individually per packet and are specified in the mbuf pkthdr.csum_flags
203162070Sandre *   field.  IFCAP_* and CSUM_* do not match one to one and CSUM_* may be
204169207Syar *   more detailed or differenciated than IFCAP_*.
205162070Sandre *   Hwassist features are defined CSUM_* in sys/mbuf.h
206223078Sluigi *
207223078Sluigi * Capabilities that cannot be arbitrarily changed with ifconfig/ioctl
208223078Sluigi * are listed in IFCAP_CANTCHANGE, similar to IFF_CANTCHANGE.
209223078Sluigi * This is not strictly necessary because the common code never
210223078Sluigi * changes capabilities, and it is left to the individual driver
211223078Sluigi * to do the right thing. However, having the filter here
212223078Sluigi * avoids replication of the same code in all individual drivers.
213162070Sandre */
214182413Sjfv#define	IFCAP_RXCSUM		0x00001  /* can offload checksum on RX */
215182413Sjfv#define	IFCAP_TXCSUM		0x00002  /* can offload checksum on TX */
216182413Sjfv#define	IFCAP_NETCONS		0x00004  /* can be a network console */
217182413Sjfv#define	IFCAP_VLAN_MTU		0x00008	/* VLAN-compatible MTU */
218182413Sjfv#define	IFCAP_VLAN_HWTAGGING	0x00010	/* hardware VLAN tag support */
219182413Sjfv#define	IFCAP_JUMBO_MTU		0x00020	/* 9000 byte MTU supported */
220182413Sjfv#define	IFCAP_POLLING		0x00040	/* driver supports polling */
221182413Sjfv#define	IFCAP_VLAN_HWCSUM	0x00080	/* can do IFCAP_HWCSUM on VLANs */
222182413Sjfv#define	IFCAP_TSO4		0x00100	/* can do TCP Segmentation Offload */
223182413Sjfv#define	IFCAP_TSO6		0x00200	/* can do TCP6 Segmentation Offload */
224182413Sjfv#define	IFCAP_LRO		0x00400	/* can do Large Receive Offload */
225182413Sjfv#define	IFCAP_WOL_UCAST		0x00800	/* wake on any unicast frame */
226182413Sjfv#define	IFCAP_WOL_MCAST		0x01000	/* wake on any multicast frame */
227182413Sjfv#define	IFCAP_WOL_MAGIC		0x02000	/* wake on any Magic Packet */
228182413Sjfv#define	IFCAP_TOE4		0x04000	/* interface can offload TCP */
229182413Sjfv#define	IFCAP_TOE6		0x08000	/* interface can offload TCP6 */
230182413Sjfv#define	IFCAP_VLAN_HWFILTER	0x10000 /* interface hw can filter vlan tag */
231193096Sattilio#define	IFCAP_POLLING_NOCOUNT	0x20000 /* polling ticks cannot be fragmented */
232204149Syongari#define	IFCAP_VLAN_HWTSO	0x40000 /* can do IFCAP_TSO on VLANs */
233205222Sqingli#define	IFCAP_LINKSTATE		0x80000 /* the runtime link state is dynamic */
234223078Sluigi#define	IFCAP_NETMAP		0x100000 /* netmap mode supported/enabled */
235236170Sbz#define	IFCAP_RXCSUM_IPV6	0x200000  /* can offload checksum on IPv6 RX */
236236170Sbz#define	IFCAP_TXCSUM_IPV6	0x400000  /* can offload checksum on IPv6 TX */
237256218Sglebius#define	IFCAP_HWSTATS		0x800000 /* manages counters internally */
23883624Sjlemon
239236170Sbz#define IFCAP_HWCSUM_IPV6	(IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6)
240236170Sbz
241174505Ssam#define IFCAP_HWCSUM	(IFCAP_RXCSUM | IFCAP_TXCSUM)
242174505Ssam#define	IFCAP_TSO	(IFCAP_TSO4 | IFCAP_TSO6)
243174505Ssam#define	IFCAP_WOL	(IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC)
244174628Skmacy#define	IFCAP_TOE	(IFCAP_TOE4 | IFCAP_TOE6)
24583636Sjlemon
246223078Sluigi#define	IFCAP_CANTCHANGE	(IFCAP_NETMAP)
247223078Sluigi
2481541Srgrimes#define	IFQ_MAXLEN	50
2491541Srgrimes#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
2501541Srgrimes
2511541Srgrimes/*
2521541Srgrimes * Message format for use in obtaining information about interfaces
2531541Srgrimes * from getkerninfo and the routing socket
254231505Sbz * For the new, extensible interface see struct if_msghdrl below.
2551541Srgrimes */
2561541Srgrimesstruct if_msghdr {
2571541Srgrimes	u_short	ifm_msglen;	/* to skip over non-understood messages */
25872093Sasmodai	u_char	ifm_version;	/* future binary compatibility */
2591541Srgrimes	u_char	ifm_type;	/* message type */
2601541Srgrimes	int	ifm_addrs;	/* like rtm_addrs */
2611541Srgrimes	int	ifm_flags;	/* value of if_flags */
2621541Srgrimes	u_short	ifm_index;	/* index for associated ifp */
2631541Srgrimes	struct	if_data ifm_data;/* statistics and other data about if */
2641541Srgrimes};
2651541Srgrimes
2661541Srgrimes/*
267231505Sbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
268231505Sbz * extensible after ifm_data_off or within ifm_data.  Both the if_msghdr and
269231505Sbz * if_data now have a member field detailing the struct length in addition to
270231505Sbz * the routing message length.  Macros are provided to find the start of
271231505Sbz * ifm_data and the start of the socket address strucutres immediately following
272231505Sbz * struct if_msghdrl given a pointer to struct if_msghdrl.
273231505Sbz */
274231505Sbz#define	IF_MSGHDRL_IFM_DATA(_l) \
275231505Sbz    (struct if_data *)((char *)(_l) + (_l)->ifm_data_off)
276231505Sbz#define	IF_MSGHDRL_RTA(_l) \
277231505Sbz    (void *)((uintptr_t)(_l) + (_l)->ifm_len)
278231505Sbzstruct if_msghdrl {
279231505Sbz	u_short	ifm_msglen;	/* to skip over non-understood messages */
280231505Sbz	u_char	ifm_version;	/* future binary compatibility */
281231505Sbz	u_char	ifm_type;	/* message type */
282231505Sbz	int	ifm_addrs;	/* like rtm_addrs */
283231505Sbz	int	ifm_flags;	/* value of if_flags */
284231505Sbz	u_short	ifm_index;	/* index for associated ifp */
285231505Sbz	u_short _ifm_spare1;	/* spare space to grow if_index, see if_var.h */
286231505Sbz	u_short	ifm_len;	/* length of if_msghdrl incl. if_data */
287231505Sbz	u_short	ifm_data_off;	/* offset of if_data from beginning */
288231505Sbz	struct	if_data ifm_data;/* statistics and other data about if */
289264076Sglebius#ifdef _IN_NET_RTSOCK_C
290264076Sglebius	u_long	ifi_oqdrops;
291264076Sglebius#endif
292231505Sbz};
293231505Sbz
294231505Sbz/*
2951541Srgrimes * Message format for use in obtaining information about interface addresses
2961541Srgrimes * from getkerninfo and the routing socket
297231505Sbz * For the new, extensible interface see struct ifa_msghdrl below.
2981541Srgrimes */
2991541Srgrimesstruct ifa_msghdr {
3001541Srgrimes	u_short	ifam_msglen;	/* to skip over non-understood messages */
30172093Sasmodai	u_char	ifam_version;	/* future binary compatibility */
3021541Srgrimes	u_char	ifam_type;	/* message type */
3031541Srgrimes	int	ifam_addrs;	/* like rtm_addrs */
3041541Srgrimes	int	ifam_flags;	/* value of ifa_flags */
3051541Srgrimes	u_short	ifam_index;	/* index for associated ifp */
3061541Srgrimes	int	ifam_metric;	/* value of ifa_metric */
3071541Srgrimes};
3081541Srgrimes
3091541Srgrimes/*
310231505Sbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
311231505Sbz * extensible after ifam_metric or within ifam_data.  Both the ifa_msghdrl and
312231505Sbz * if_data now have a member field detailing the struct length in addition to
313231505Sbz * the routing message length.  Macros are provided to find the start of
314231505Sbz * ifm_data and the start of the socket address strucutres immediately following
315231505Sbz * struct ifa_msghdrl given a pointer to struct ifa_msghdrl.
316231505Sbz */
317231505Sbz#define	IFA_MSGHDRL_IFAM_DATA(_l) \
318231505Sbz    (struct if_data *)((char *)(_l) + (_l)->ifam_data_off)
319231505Sbz#define	IFA_MSGHDRL_RTA(_l) \
320231505Sbz    (void *)((uintptr_t)(_l) + (_l)->ifam_len)
321231505Sbzstruct ifa_msghdrl {
322231505Sbz	u_short	ifam_msglen;	/* to skip over non-understood messages */
323231505Sbz	u_char	ifam_version;	/* future binary compatibility */
324231505Sbz	u_char	ifam_type;	/* message type */
325231505Sbz	int	ifam_addrs;	/* like rtm_addrs */
326231505Sbz	int	ifam_flags;	/* value of ifa_flags */
327231505Sbz	u_short	ifam_index;	/* index for associated ifp */
328231505Sbz	u_short _ifam_spare1;	/* spare space to grow if_index, see if_var.h */
329231505Sbz	u_short	ifam_len;	/* length of ifa_msghdrl incl. if_data */
330231505Sbz	u_short	ifam_data_off;	/* offset of if_data from beginning */
331231505Sbz	int	ifam_metric;	/* value of ifa_metric */
332231505Sbz	struct	if_data ifam_data;/* statistics and other data about if or
333231505Sbz				 * address */
334231505Sbz};
335231505Sbz
336231505Sbz/*
33721666Swollman * Message format for use in obtaining information about multicast addresses
33821666Swollman * from the routing socket
33921666Swollman */
34021666Swollmanstruct ifma_msghdr {
34121666Swollman	u_short	ifmam_msglen;	/* to skip over non-understood messages */
34272093Sasmodai	u_char	ifmam_version;	/* future binary compatibility */
34321666Swollman	u_char	ifmam_type;	/* message type */
34421666Swollman	int	ifmam_addrs;	/* like rtm_addrs */
34521666Swollman	int	ifmam_flags;	/* value of ifa_flags */
34621666Swollman	u_short	ifmam_index;	/* index for associated ifp */
34721666Swollman};
34821666Swollman
34921666Swollman/*
35089498Sru * Message format announcing the arrival or departure of a network interface.
35189498Sru */
35289498Srustruct if_announcemsghdr {
35389498Sru	u_short	ifan_msglen;	/* to skip over non-understood messages */
35489498Sru	u_char	ifan_version;	/* future binary compatibility */
35589498Sru	u_char	ifan_type;	/* message type */
35689498Sru	u_short	ifan_index;	/* index for associated ifp */
35789498Sru	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
35889498Sru	u_short	ifan_what;	/* what type of announcement */
35989498Sru};
36089498Sru
36189498Sru#define	IFAN_ARRIVAL	0	/* interface arrival */
36289498Sru#define	IFAN_DEPARTURE	1	/* interface departure */
36389498Sru
36489498Sru/*
365203052Sdelphij * Buffer with length to be used in SIOCGIFDESCR/SIOCSIFDESCR requests
366203052Sdelphij */
367203052Sdelphijstruct ifreq_buffer {
368203052Sdelphij	size_t	length;
369203052Sdelphij	void	*buffer;
370203052Sdelphij};
371203052Sdelphij
372203052Sdelphij/*
3731541Srgrimes * Interface request structure used for socket
3741541Srgrimes * ioctl's.  All interface ioctl's must have parameter
3751541Srgrimes * definitions which begin with ifr_name.  The
3761541Srgrimes * remainder may be interface specific.
3771541Srgrimes */
3781541Srgrimesstruct	ifreq {
3791541Srgrimes	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
3801541Srgrimes	union {
3811541Srgrimes		struct	sockaddr ifru_addr;
3821541Srgrimes		struct	sockaddr ifru_dstaddr;
3831541Srgrimes		struct	sockaddr ifru_broadaddr;
384203052Sdelphij		struct	ifreq_buffer ifru_buffer;
38544144Sphk		short	ifru_flags[2];
38685079Sjlemon		short	ifru_index;
387194251Sjamie		int	ifru_jid;
3881541Srgrimes		int	ifru_metric;
3891941Sdg		int	ifru_mtu;
3905184Swollman		int	ifru_phys;
39125434Speter		int	ifru_media;
3921541Srgrimes		caddr_t	ifru_data;
39383624Sjlemon		int	ifru_cap[2];
394223735Sbz		u_int	ifru_fib;
3951541Srgrimes	} ifr_ifru;
3961541Srgrimes#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
3971541Srgrimes#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
3981541Srgrimes#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
399203052Sdelphij#define	ifr_buffer	ifr_ifru.ifru_buffer	/* user supplied buffer with its length */
400102052Ssobomax#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
401102052Ssobomax#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
402194251Sjamie#define	ifr_jid		ifr_ifru.ifru_jid	/* jail/vnet */
4031541Srgrimes#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
4041941Sdg#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
4055187Sdg#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
40625434Speter#define ifr_media	ifr_ifru.ifru_media	/* physical media */
4071541Srgrimes#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
40883624Sjlemon#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
40983624Sjlemon#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
41085079Sjlemon#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
411223735Sbz#define	ifr_fib		ifr_ifru.ifru_fib	/* interface fib */
4121541Srgrimes};
4131541Srgrimes
41432491Swollman#define	_SIZEOF_ADDR_IFREQ(ifr) \
41532491Swollman	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
41632491Swollman	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
41732491Swollman	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
41832491Swollman
4191541Srgrimesstruct ifaliasreq {
4201541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
4211541Srgrimes	struct	sockaddr ifra_addr;
4221541Srgrimes	struct	sockaddr ifra_broadaddr;
4231541Srgrimes	struct	sockaddr ifra_mask;
424228571Sglebius	int	ifra_vhid;
4251541Srgrimes};
4261541Srgrimes
427228768Sglebius/* Compat with pre-10.x */
428228768Sglebiusstruct oifaliasreq {
429228768Sglebius	char	ifra_name[IFNAMSIZ];
430228768Sglebius	struct	sockaddr ifra_addr;
431228768Sglebius	struct	sockaddr ifra_broadaddr;
432228768Sglebius	struct	sockaddr ifra_mask;
433228768Sglebius};
434228768Sglebius
43525434Speterstruct ifmediareq {
43625434Speter	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
43725434Speter	int	ifm_current;		/* current media options */
43825434Speter	int	ifm_mask;		/* don't care mask */
43925434Speter	int	ifm_status;		/* media status */
44025434Speter	int	ifm_active;		/* active options */
44125434Speter	int	ifm_count;		/* # entries in ifm_ulist array */
44225434Speter	int	*ifm_ulist;		/* media words */
44325434Speter};
44448021Sphk
445146986Sthompsastruct  ifdrv {
446146986Sthompsa	char            ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
447146986Sthompsa	unsigned long   ifd_cmd;
448146986Sthompsa	size_t          ifd_len;
449146986Sthompsa	void            *ifd_data;
450146986Sthompsa};
451146986Sthompsa
45248021Sphk/*
45348021Sphk * Structure used to retrieve aux status data from interfaces.
45448589Sbde * Kernel suppliers to this interface should respect the formatting
45548021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with
45648589Sbde * a newline.  The canonical example to copy and paste is in if_tun.c.
45748021Sphk */
45848021Sphk
45948589Sbde#define	IFSTATMAX	800		/* 10 lines of text */
46048021Sphkstruct ifstat {
46148589Sbde	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
46248589Sbde	char	ascii[IFSTATMAX + 1];
46348021Sphk};
46448021Sphk
4651541Srgrimes/*
4661541Srgrimes * Structure used in SIOCGIFCONF request.
4671541Srgrimes * Used to retrieve interface configuration
4681541Srgrimes * for machine (useful for programs which
4691541Srgrimes * must know all networks accessible).
4701541Srgrimes */
4711541Srgrimesstruct	ifconf {
4721541Srgrimes	int	ifc_len;		/* size of associated buffer */
4731541Srgrimes	union {
4741541Srgrimes		caddr_t	ifcu_buf;
4751541Srgrimes		struct	ifreq *ifcu_req;
4761541Srgrimes	} ifc_ifcu;
4771541Srgrimes#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
4781541Srgrimes#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
4791541Srgrimes};
4801541Srgrimes
48152904Sshin/*
482159781Smlaier * interface groups
483159781Smlaier */
484159781Smlaier
485159781Smlaier#define	IFG_ALL		"all"		/* group contains all interfaces */
486159781Smlaier/* XXX: will we implement this? */
487159781Smlaier#define	IFG_EGRESS	"egress"	/* if(s) default route(s) point to */
488159781Smlaier
489159781Smlaierstruct ifg_req {
490159781Smlaier	union {
491159781Smlaier		char			 ifgrqu_group[IFNAMSIZ];
492159781Smlaier		char			 ifgrqu_member[IFNAMSIZ];
493159781Smlaier	} ifgrq_ifgrqu;
494159781Smlaier#define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
495159781Smlaier#define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
496159781Smlaier};
497159781Smlaier
498159781Smlaier/*
499159781Smlaier * Used to lookup groups for an interface
500159781Smlaier */
501159781Smlaierstruct ifgroupreq {
502159781Smlaier	char	ifgr_name[IFNAMSIZ];
503159781Smlaier	u_int	ifgr_len;
504159781Smlaier	union {
505159781Smlaier		char	ifgru_group[IFNAMSIZ];
506159781Smlaier		struct	ifg_req *ifgru_groups;
507159781Smlaier	} ifgr_ifgru;
508159781Smlaier#define ifgr_group	ifgr_ifgru.ifgru_group
509159781Smlaier#define ifgr_groups	ifgr_ifgru.ifgru_groups
510159781Smlaier};
511159781Smlaier
512159781Smlaier/*
51352904Sshin * Structure for SIOC[AGD]LIFADDR
51452904Sshin */
51552904Sshinstruct if_laddrreq {
51652904Sshin	char	iflr_name[IFNAMSIZ];
51752904Sshin	u_int	flags;
51852904Sshin#define	IFLR_PREFIX	0x8000  /* in: prefix given  out: kernel fills id */
51952904Sshin	u_int	prefixlen;         /* in/out */
52052904Sshin	struct	sockaddr_storage addr;   /* in/out */
52152904Sshin	struct	sockaddr_storage dstaddr; /* out */
52252904Sshin};
52352904Sshin
524286810Smelifaro/*
525286810Smelifaro * Structure used to request i2c data
526286810Smelifaro * from interface transceivers.
527286810Smelifaro */
528286810Smelifarostruct ifi2creq {
529286810Smelifaro	uint8_t dev_addr;	/* i2c address (0xA0, 0xA2) */
530286810Smelifaro	uint8_t offset;		/* read offset */
531286810Smelifaro	uint8_t len;		/* read length */
532286810Smelifaro	uint8_t spare0;
533286810Smelifaro	uint32_t spare1;
534286810Smelifaro	uint8_t data[8];	/* read buffer */
535286810Smelifaro};
536286810Smelifaro
537324462Ssephe/*
538324462Ssephe * RSS hash.
539324462Ssephe */
540324462Ssephe
541324462Ssephe#define	RSS_FUNC_NONE		0		/* RSS disabled */
542324462Ssephe#define	RSS_FUNC_PRIVATE	1		/* non-standard */
543324462Ssephe#define	RSS_FUNC_TOEPLITZ	2
544324462Ssephe
545324462Ssephe#define	RSS_TYPE_IPV4		0x00000001
546324462Ssephe#define	RSS_TYPE_TCP_IPV4	0x00000002
547324462Ssephe#define	RSS_TYPE_IPV6		0x00000004
548324462Ssephe#define	RSS_TYPE_IPV6_EX	0x00000008
549324462Ssephe#define	RSS_TYPE_TCP_IPV6	0x00000010
550324462Ssephe#define	RSS_TYPE_TCP_IPV6_EX	0x00000020
551324462Ssephe#define	RSS_TYPE_UDP_IPV4	0x00000040
552324462Ssephe#define	RSS_TYPE_UDP_IPV6	0x00000080
553324462Ssephe#define	RSS_TYPE_UDP_IPV6_EX	0x00000100
554324462Ssephe
555324462Ssephe#define	RSS_KEYLEN		128
556324462Ssephe
557324462Ssephestruct ifrsskey {
558324462Ssephe	char		ifrk_name[IFNAMSIZ];	/* if name, e.g. "en0" */
559324462Ssephe	uint8_t		ifrk_func;		/* RSS_FUNC_ */
560324462Ssephe	uint8_t		ifrk_spare0;
561324462Ssephe	uint16_t	ifrk_keylen;
562324462Ssephe	uint8_t		ifrk_key[RSS_KEYLEN];
563324462Ssephe};
564324462Ssephe
565324462Ssephestruct ifrsshash {
566324462Ssephe	char		ifrh_name[IFNAMSIZ];	/* if name, e.g. "en0" */
567324462Ssephe	uint8_t		ifrh_func;		/* RSS_FUNC_ */
568324462Ssephe	uint8_t		ifrh_spare0;
569324462Ssephe	uint16_t	ifrh_spare1;
570324462Ssephe	uint32_t	ifrh_types;		/* RSS_TYPE_ */
571324462Ssephe};
572324462Ssephe
573104355Smike#endif /* __BSD_VISIBLE */
574104355Smike
57555205Speter#ifdef _KERNEL
57630354Sphk#ifdef MALLOC_DECLARE
57730354SphkMALLOC_DECLARE(M_IFADDR);
57830354SphkMALLOC_DECLARE(M_IFMADDR);
57930354Sphk#endif
58030354Sphk#endif
58130354Sphk
58255205Speter#ifndef _KERNEL
58352904Sshinstruct if_nameindex {
584104355Smike	unsigned int	if_index;	/* 1, 2, ... */
585104360Smike	char		*if_name;	/* null terminated name: "le0", ... */
58652904Sshin};
58752904Sshin
58852904Sshin__BEGIN_DECLS
589104360Smikevoid			 if_freenameindex(struct if_nameindex *);
590104360Smikechar			*if_indextoname(unsigned int, char *);
591104360Smikestruct if_nameindex	*if_nameindex(void);
592104360Smikeunsigned int		 if_nametoindex(const char *);
59352904Sshin__END_DECLS
59452904Sshin#endif
59552904Sshin
59655205Speter#ifdef _KERNEL
59748589Sbde/* XXX - this should go away soon. */
59821259Swollman#include <net/if_var.h>
5991541Srgrimes#endif
6001541Srgrimes
6014507Sbde#endif /* !_NET_IF_H_ */
602