if.h revision 134609
11541Srgrimes/*
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: head/sys/net/if.h 134609 2004-09-01 18:22:14Z brooks $
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)
4634750Speter */
4755205Speter#ifndef _KERNEL
4834750Speter#include <sys/time.h>
4934750Speter#endif
5034750Speter
5179103Sbrooksstruct ifnet;
52104355Smike#endif
5379103Sbrooks
5434750Speter/*
5579103Sbrooks * Length of interface external name, including terminating '\0'.
5679103Sbrooks * Note: this is the same size as a generic device's external name.
5779103Sbrooks */
58104355Smike#define		IF_NAMESIZE	16
59104355Smike#if __BSD_VISIBLE
60104355Smike#define		IFNAMSIZ	IF_NAMESIZE
61121816Sbrooks#define		IF_MAXUNIT	0x7fff	/* historical value */
62104355Smike#endif
63104355Smike#if __BSD_VISIBLE
64104355Smike
6579103Sbrooks/*
6679103Sbrooks * Structure used to query names of interface cloners.
6779103Sbrooks */
6879103Sbrooks
6979103Sbrooksstruct if_clonereq {
7079103Sbrooks	int	ifcr_total;		/* total cloners (out) */
7179103Sbrooks	int	ifcr_count;		/* room for this many in user buffer */
7279103Sbrooks	char	*ifcr_buffer;		/* buffer for cloner names */
7379103Sbrooks};
7479103Sbrooks
7579103Sbrooks/*
7619079Sfenner * Structure describing information about an interface
7719079Sfenner * which may be of interest to management entities.
7819079Sfenner */
799457Sjoergstruct if_data {
809457Sjoerg	/* generic interface information */
819457Sjoerg	u_char	ifi_type;		/* ethernet, tokenring, etc */
829457Sjoerg	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
839457Sjoerg	u_char	ifi_addrlen;		/* media address length */
849457Sjoerg	u_char	ifi_hdrlen;		/* media header length */
85128871Sandre	u_char	ifi_link_state;		/* current link state */
8617352Swollman	u_char	ifi_recvquota;		/* polling quota for receive intrs */
8717352Swollman	u_char	ifi_xmitquota;		/* polling quota for xmit intrs */
88134609Sbrooks	u_char	ifi_datalen;		/* length of this data struct */
899457Sjoerg	u_long	ifi_mtu;		/* maximum transmission unit */
909457Sjoerg	u_long	ifi_metric;		/* routing metric (external only) */
919457Sjoerg	u_long	ifi_baudrate;		/* linespeed */
929457Sjoerg	/* volatile statistics */
939457Sjoerg	u_long	ifi_ipackets;		/* packets received on interface */
949457Sjoerg	u_long	ifi_ierrors;		/* input errors on interface */
959457Sjoerg	u_long	ifi_opackets;		/* packets sent on interface */
969457Sjoerg	u_long	ifi_oerrors;		/* output errors on interface */
979457Sjoerg	u_long	ifi_collisions;		/* collisions on csma interfaces */
989457Sjoerg	u_long	ifi_ibytes;		/* total number of octets received */
999457Sjoerg	u_long	ifi_obytes;		/* total number of octets sent */
1009457Sjoerg	u_long	ifi_imcasts;		/* packets received via multicast */
1019457Sjoerg	u_long	ifi_omcasts;		/* packets sent via multicast */
1029457Sjoerg	u_long	ifi_iqdrops;		/* dropped on input, this interface */
1039457Sjoerg	u_long	ifi_noproto;		/* destined for unsupported protocol */
10458698Sjlemon	u_long	ifi_hwassist;		/* HW offload capabilities */
10558698Sjlemon	u_long	ifi_unused;		/* XXX was ifi_xmittiming */
10616287Sgpalmer	struct	timeval ifi_lastchange;	/* time of last administrative change */
107134514Sbrooks	struct	timeval ifi_epoch;	/* time of creation or stat reset */
1089457Sjoerg};
1099457Sjoerg
1101541Srgrimes#define	IFF_UP		0x1		/* interface is up */
1111541Srgrimes#define	IFF_BROADCAST	0x2		/* broadcast address valid */
1121541Srgrimes#define	IFF_DEBUG	0x4		/* turn on debugging */
1131541Srgrimes#define	IFF_LOOPBACK	0x8		/* is a loopback net */
1141541Srgrimes#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
11547777Sphk#define	IFF_SMART	0x20		/* interface manages own routes */
1161541Srgrimes#define	IFF_RUNNING	0x40		/* resources allocated */
1171541Srgrimes#define	IFF_NOARP	0x80		/* no address resolution protocol */
1181541Srgrimes#define	IFF_PROMISC	0x100		/* receive all packets */
1191541Srgrimes#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
1201541Srgrimes#define	IFF_OACTIVE	0x400		/* transmission in progress */
1211541Srgrimes#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
1221541Srgrimes#define	IFF_LINK0	0x1000		/* per link layer defined bit */
1231541Srgrimes#define	IFF_LINK1	0x2000		/* per link layer defined bit */
1241541Srgrimes#define	IFF_LINK2	0x4000		/* per link layer defined bit */
1253274Swollman#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
1261541Srgrimes#define	IFF_MULTICAST	0x8000		/* supports multicast */
12787902Sluigi#define	IFF_POLLING	0x10000		/* Interface is in polling mode. */
128102099Ssobomax#define	IFF_PPROMISC	0x20000		/* user-requested promisc mode */
129104044Sphk#define	IFF_MONITOR	0x40000		/* user-requested monitor mode */
130120626Sru#define	IFF_STATICARP	0x80000		/* static ARP */
131132712Srwatson#define	IFF_NEEDSGIANT	0x100000	/* hold Giant over if_start calls */
13287902Sluigi
1331541Srgrimes/* flags set internally only: */
1341541Srgrimes#define	IFF_CANTCHANGE \
1351541Srgrimes	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
136102526Ssobomax	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
137102526Ssobomax	    IFF_POLLING)
1381541Srgrimes
139106925Ssam/*
140128871Sandre * Values for if_link_state.
141128871Sandre */
142128871Sandre#define	LINK_STATE_UNKNOWN	0	/* link invalid/unknown */
143128871Sandre#define	LINK_STATE_DOWN		1	/* link is down */
144128871Sandre#define	LINK_STATE_UP		2	/* link is up */
145128871Sandre
146128871Sandre/*
147106925Ssam * Some convenience macros used for setting ifi_baudrate.
148106925Ssam * XXX 1000 vs. 1024? --thorpej@netbsd.org
149106925Ssam */
150106925Ssam#define	IF_Kbps(x)	((x) * 1000)		/* kilobits/sec. */
151106925Ssam#define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
152106925Ssam#define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
153106925Ssam
15483624Sjlemon/* Capabilities that interfaces can advertise. */
15583636Sjlemon#define IFCAP_RXCSUM		0x0001  /* can offload checksum on RX */
15683636Sjlemon#define IFCAP_TXCSUM		0x0002  /* can offload checksum on TX */
15783636Sjlemon#define IFCAP_NETCONS		0x0004  /* can be a network console */
158106925Ssam#define	IFCAP_VLAN_MTU		0x0008	/* VLAN-compatible MTU */
159106925Ssam#define	IFCAP_VLAN_HWTAGGING	0x0010	/* hardware VLAN tag support */
160106925Ssam#define	IFCAP_JUMBO_MTU		0x0020	/* 9000 byte MTU supported */
161128113Sru#define	IFCAP_POLLING		0x0040	/* driver supports polling */
16283624Sjlemon
16383636Sjlemon#define IFCAP_HWCSUM		(IFCAP_RXCSUM | IFCAP_TXCSUM)
16483636Sjlemon
1651541Srgrimes#define	IFQ_MAXLEN	50
1661541Srgrimes#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1671541Srgrimes
1681541Srgrimes/*
1691541Srgrimes * Message format for use in obtaining information about interfaces
1701541Srgrimes * from getkerninfo and the routing socket
1711541Srgrimes */
1721541Srgrimesstruct if_msghdr {
1731541Srgrimes	u_short	ifm_msglen;	/* to skip over non-understood messages */
17472093Sasmodai	u_char	ifm_version;	/* future binary compatibility */
1751541Srgrimes	u_char	ifm_type;	/* message type */
1761541Srgrimes	int	ifm_addrs;	/* like rtm_addrs */
1771541Srgrimes	int	ifm_flags;	/* value of if_flags */
1781541Srgrimes	u_short	ifm_index;	/* index for associated ifp */
1791541Srgrimes	struct	if_data ifm_data;/* statistics and other data about if */
1801541Srgrimes};
1811541Srgrimes
1821541Srgrimes/*
1831541Srgrimes * Message format for use in obtaining information about interface addresses
1841541Srgrimes * from getkerninfo and the routing socket
1851541Srgrimes */
1861541Srgrimesstruct ifa_msghdr {
1871541Srgrimes	u_short	ifam_msglen;	/* to skip over non-understood messages */
18872093Sasmodai	u_char	ifam_version;	/* future binary compatibility */
1891541Srgrimes	u_char	ifam_type;	/* message type */
1901541Srgrimes	int	ifam_addrs;	/* like rtm_addrs */
1911541Srgrimes	int	ifam_flags;	/* value of ifa_flags */
1921541Srgrimes	u_short	ifam_index;	/* index for associated ifp */
1931541Srgrimes	int	ifam_metric;	/* value of ifa_metric */
1941541Srgrimes};
1951541Srgrimes
1961541Srgrimes/*
19721666Swollman * Message format for use in obtaining information about multicast addresses
19821666Swollman * from the routing socket
19921666Swollman */
20021666Swollmanstruct ifma_msghdr {
20121666Swollman	u_short	ifmam_msglen;	/* to skip over non-understood messages */
20272093Sasmodai	u_char	ifmam_version;	/* future binary compatibility */
20321666Swollman	u_char	ifmam_type;	/* message type */
20421666Swollman	int	ifmam_addrs;	/* like rtm_addrs */
20521666Swollman	int	ifmam_flags;	/* value of ifa_flags */
20621666Swollman	u_short	ifmam_index;	/* index for associated ifp */
20721666Swollman};
20821666Swollman
20921666Swollman/*
21089498Sru * Message format announcing the arrival or departure of a network interface.
21189498Sru */
21289498Srustruct if_announcemsghdr {
21389498Sru	u_short	ifan_msglen;	/* to skip over non-understood messages */
21489498Sru	u_char	ifan_version;	/* future binary compatibility */
21589498Sru	u_char	ifan_type;	/* message type */
21689498Sru	u_short	ifan_index;	/* index for associated ifp */
21789498Sru	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
21889498Sru	u_short	ifan_what;	/* what type of announcement */
21989498Sru};
22089498Sru
22189498Sru#define	IFAN_ARRIVAL	0	/* interface arrival */
22289498Sru#define	IFAN_DEPARTURE	1	/* interface departure */
22389498Sru
22489498Sru/*
2251541Srgrimes * Interface request structure used for socket
2261541Srgrimes * ioctl's.  All interface ioctl's must have parameter
2271541Srgrimes * definitions which begin with ifr_name.  The
2281541Srgrimes * remainder may be interface specific.
2291541Srgrimes */
2301541Srgrimesstruct	ifreq {
2311541Srgrimes	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2321541Srgrimes	union {
2331541Srgrimes		struct	sockaddr ifru_addr;
2341541Srgrimes		struct	sockaddr ifru_dstaddr;
2351541Srgrimes		struct	sockaddr ifru_broadaddr;
23644144Sphk		short	ifru_flags[2];
23785079Sjlemon		short	ifru_index;
2381541Srgrimes		int	ifru_metric;
2391941Sdg		int	ifru_mtu;
2405184Swollman		int	ifru_phys;
24125434Speter		int	ifru_media;
2421541Srgrimes		caddr_t	ifru_data;
24383624Sjlemon		int	ifru_cap[2];
2441541Srgrimes	} ifr_ifru;
2451541Srgrimes#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
2461541Srgrimes#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
2471541Srgrimes#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
248102052Ssobomax#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
249102052Ssobomax#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
2501541Srgrimes#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
2511941Sdg#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
2525187Sdg#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
25325434Speter#define ifr_media	ifr_ifru.ifru_media	/* physical media */
2541541Srgrimes#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
25583624Sjlemon#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
25683624Sjlemon#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
25785079Sjlemon#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
2581541Srgrimes};
2591541Srgrimes
26032491Swollman#define	_SIZEOF_ADDR_IFREQ(ifr) \
26132491Swollman	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
26232491Swollman	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
26332491Swollman	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
26432491Swollman
2651541Srgrimesstruct ifaliasreq {
2661541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2671541Srgrimes	struct	sockaddr ifra_addr;
2681541Srgrimes	struct	sockaddr ifra_broadaddr;
2691541Srgrimes	struct	sockaddr ifra_mask;
2701541Srgrimes};
2711541Srgrimes
27225434Speterstruct ifmediareq {
27325434Speter	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
27425434Speter	int	ifm_current;		/* current media options */
27525434Speter	int	ifm_mask;		/* don't care mask */
27625434Speter	int	ifm_status;		/* media status */
27725434Speter	int	ifm_active;		/* active options */
27825434Speter	int	ifm_count;		/* # entries in ifm_ulist array */
27925434Speter	int	*ifm_ulist;		/* media words */
28025434Speter};
28148021Sphk
28248021Sphk/*
28348021Sphk * Structure used to retrieve aux status data from interfaces.
28448589Sbde * Kernel suppliers to this interface should respect the formatting
28548021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with
28648589Sbde * a newline.  The canonical example to copy and paste is in if_tun.c.
28748021Sphk */
28848021Sphk
28948589Sbde#define	IFSTATMAX	800		/* 10 lines of text */
29048021Sphkstruct ifstat {
29148589Sbde	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
29248589Sbde	char	ascii[IFSTATMAX + 1];
29348021Sphk};
29448021Sphk
2951541Srgrimes/*
2961541Srgrimes * Structure used in SIOCGIFCONF request.
2971541Srgrimes * Used to retrieve interface configuration
2981541Srgrimes * for machine (useful for programs which
2991541Srgrimes * must know all networks accessible).
3001541Srgrimes */
3011541Srgrimesstruct	ifconf {
3021541Srgrimes	int	ifc_len;		/* size of associated buffer */
3031541Srgrimes	union {
3041541Srgrimes		caddr_t	ifcu_buf;
3051541Srgrimes		struct	ifreq *ifcu_req;
3061541Srgrimes	} ifc_ifcu;
3071541Srgrimes#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
3081541Srgrimes#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
3091541Srgrimes};
3101541Srgrimes
31152904Sshin
31252904Sshin/*
31352904Sshin * Structure for SIOC[AGD]LIFADDR
31452904Sshin */
31552904Sshinstruct if_laddrreq {
31652904Sshin	char	iflr_name[IFNAMSIZ];
31752904Sshin	u_int	flags;
31852904Sshin#define	IFLR_PREFIX	0x8000  /* in: prefix given  out: kernel fills id */
31952904Sshin	u_int	prefixlen;         /* in/out */
32052904Sshin	struct	sockaddr_storage addr;   /* in/out */
32152904Sshin	struct	sockaddr_storage dstaddr; /* out */
32252904Sshin};
32352904Sshin
324104355Smike#endif /* __BSD_VISIBLE */
325104355Smike
32655205Speter#ifdef _KERNEL
32730354Sphk#ifdef MALLOC_DECLARE
32830354SphkMALLOC_DECLARE(M_IFADDR);
32930354SphkMALLOC_DECLARE(M_IFMADDR);
33030354Sphk#endif
33130354Sphk#endif
33230354Sphk
33355205Speter#ifndef _KERNEL
33452904Sshinstruct if_nameindex {
335104355Smike	unsigned int	if_index;	/* 1, 2, ... */
336104360Smike	char		*if_name;	/* null terminated name: "le0", ... */
33752904Sshin};
33852904Sshin
33952904Sshin__BEGIN_DECLS
340104360Smikevoid			 if_freenameindex(struct if_nameindex *);
341104360Smikechar			*if_indextoname(unsigned int, char *);
342104360Smikestruct if_nameindex	*if_nameindex(void);
343104360Smikeunsigned int		 if_nametoindex(const char *);
34452904Sshin__END_DECLS
34552904Sshin#endif
34652904Sshin
34755205Speter#ifdef _KERNEL
34883366Sjulianstruct thread;
34948589Sbde
35048589Sbde/* XXX - this should go away soon. */
35121259Swollman#include <net/if_var.h>
3521541Srgrimes#endif
3531541Srgrimes
3544507Sbde#endif /* !_NET_IF_H_ */
355