if.h revision 121816
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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)if.h	8.1 (Berkeley) 6/10/93
3450477Speter * $FreeBSD: head/sys/net/if.h 121816 2003-10-31 18:32:15Z brooks $
351541Srgrimes */
361541Srgrimes
372168Spaul#ifndef _NET_IF_H_
384507Sbde#define	_NET_IF_H_
392168Spaul
40104355Smike#include <sys/cdefs.h>
41104355Smike
4297024Siedowse#ifdef _KERNEL
4379103Sbrooks#include <sys/queue.h>
4497024Siedowse#endif
4579103Sbrooks
46104355Smike#if __BSD_VISIBLE
471541Srgrimes/*
4834750Speter * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
4972093Sasmodai * helps userland compatibility.  (struct timeval ifi_lastchange)
5034750Speter */
5155205Speter#ifndef _KERNEL
5234750Speter#include <sys/time.h>
5334750Speter#endif
5434750Speter
5579103Sbrooksstruct ifnet;
56104355Smike#endif
5779103Sbrooks
5834750Speter/*
5979103Sbrooks * Length of interface external name, including terminating '\0'.
6079103Sbrooks * Note: this is the same size as a generic device's external name.
6179103Sbrooks */
62104355Smike#define		IF_NAMESIZE	16
63104355Smike#if __BSD_VISIBLE
64104355Smike#define		IFNAMSIZ	IF_NAMESIZE
65121816Sbrooks#define		IF_MAXUNIT	0x7fff	/* historical value */
66104355Smike#endif
6779103Sbrooks
6897024Siedowse#ifdef _KERNEL
6979103Sbrooks/*
7079103Sbrooks * Structure describing a `cloning' interface.
7179103Sbrooks */
7279103Sbrooksstruct if_clone {
7379103Sbrooks	LIST_ENTRY(if_clone) ifc_list;	/* on list of cloners */
7479103Sbrooks	const char *ifc_name;		/* name of device, e.g. `gif' */
7579103Sbrooks	size_t ifc_namelen;		/* length of name */
7697289Sbrooks	int ifc_minifs;			/* minimum number of interfaces */
7792081Smux	int ifc_maxunit;		/* maximum unit number */
7892081Smux	unsigned char *ifc_units;	/* bitmap to handle units */
7992081Smux	int ifc_bmlen;			/* bitmap length */
8079103Sbrooks
8192081Smux	int	(*ifc_create)(struct if_clone *, int);
8297289Sbrooks	void	(*ifc_destroy)(struct ifnet *);
8379103Sbrooks};
8479103Sbrooks
8597289Sbrooks#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit)	\
8697289Sbrooks    { { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
8797024Siedowse#endif
8879103Sbrooks
89104355Smike#if __BSD_VISIBLE
90104355Smike
9179103Sbrooks/*
9279103Sbrooks * Structure used to query names of interface cloners.
9379103Sbrooks */
9479103Sbrooks
9579103Sbrooksstruct if_clonereq {
9679103Sbrooks	int	ifcr_total;		/* total cloners (out) */
9779103Sbrooks	int	ifcr_count;		/* room for this many in user buffer */
9879103Sbrooks	char	*ifcr_buffer;		/* buffer for cloner names */
9979103Sbrooks};
10079103Sbrooks
10179103Sbrooks/*
10219079Sfenner * Structure describing information about an interface
10319079Sfenner * which may be of interest to management entities.
10419079Sfenner */
1059457Sjoergstruct if_data {
1069457Sjoerg	/* generic interface information */
1079457Sjoerg	u_char	ifi_type;		/* ethernet, tokenring, etc */
1089457Sjoerg	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
1099457Sjoerg	u_char	ifi_addrlen;		/* media address length */
1109457Sjoerg	u_char	ifi_hdrlen;		/* media header length */
11117352Swollman	u_char	ifi_recvquota;		/* polling quota for receive intrs */
11217352Swollman	u_char	ifi_xmitquota;		/* polling quota for xmit intrs */
1139457Sjoerg	u_long	ifi_mtu;		/* maximum transmission unit */
1149457Sjoerg	u_long	ifi_metric;		/* routing metric (external only) */
1159457Sjoerg	u_long	ifi_baudrate;		/* linespeed */
1169457Sjoerg	/* volatile statistics */
1179457Sjoerg	u_long	ifi_ipackets;		/* packets received on interface */
1189457Sjoerg	u_long	ifi_ierrors;		/* input errors on interface */
1199457Sjoerg	u_long	ifi_opackets;		/* packets sent on interface */
1209457Sjoerg	u_long	ifi_oerrors;		/* output errors on interface */
1219457Sjoerg	u_long	ifi_collisions;		/* collisions on csma interfaces */
1229457Sjoerg	u_long	ifi_ibytes;		/* total number of octets received */
1239457Sjoerg	u_long	ifi_obytes;		/* total number of octets sent */
1249457Sjoerg	u_long	ifi_imcasts;		/* packets received via multicast */
1259457Sjoerg	u_long	ifi_omcasts;		/* packets sent via multicast */
1269457Sjoerg	u_long	ifi_iqdrops;		/* dropped on input, this interface */
1279457Sjoerg	u_long	ifi_noproto;		/* destined for unsupported protocol */
12858698Sjlemon	u_long	ifi_hwassist;		/* HW offload capabilities */
12958698Sjlemon	u_long	ifi_unused;		/* XXX was ifi_xmittiming */
13016287Sgpalmer	struct	timeval ifi_lastchange;	/* time of last administrative change */
1319457Sjoerg};
1329457Sjoerg
1331541Srgrimes#define	IFF_UP		0x1		/* interface is up */
1341541Srgrimes#define	IFF_BROADCAST	0x2		/* broadcast address valid */
1351541Srgrimes#define	IFF_DEBUG	0x4		/* turn on debugging */
1361541Srgrimes#define	IFF_LOOPBACK	0x8		/* is a loopback net */
1371541Srgrimes#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
13847777Sphk#define	IFF_SMART	0x20		/* interface manages own routes */
1391541Srgrimes#define	IFF_RUNNING	0x40		/* resources allocated */
1401541Srgrimes#define	IFF_NOARP	0x80		/* no address resolution protocol */
1411541Srgrimes#define	IFF_PROMISC	0x100		/* receive all packets */
1421541Srgrimes#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
1431541Srgrimes#define	IFF_OACTIVE	0x400		/* transmission in progress */
1441541Srgrimes#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
1451541Srgrimes#define	IFF_LINK0	0x1000		/* per link layer defined bit */
1461541Srgrimes#define	IFF_LINK1	0x2000		/* per link layer defined bit */
1471541Srgrimes#define	IFF_LINK2	0x4000		/* per link layer defined bit */
1483274Swollman#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
1491541Srgrimes#define	IFF_MULTICAST	0x8000		/* supports multicast */
15087902Sluigi#define	IFF_POLLING	0x10000		/* Interface is in polling mode. */
151102099Ssobomax#define	IFF_PPROMISC	0x20000		/* user-requested promisc mode */
152104044Sphk#define	IFF_MONITOR	0x40000		/* user-requested monitor mode */
153120626Sru#define	IFF_STATICARP	0x80000		/* static ARP */
15487902Sluigi
1551541Srgrimes/* flags set internally only: */
1561541Srgrimes#define	IFF_CANTCHANGE \
1571541Srgrimes	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
158102526Ssobomax	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
159102526Ssobomax	    IFF_POLLING)
1601541Srgrimes
161106925Ssam/*
162106925Ssam * Some convenience macros used for setting ifi_baudrate.
163106925Ssam * XXX 1000 vs. 1024? --thorpej@netbsd.org
164106925Ssam */
165106925Ssam#define	IF_Kbps(x)	((x) * 1000)		/* kilobits/sec. */
166106925Ssam#define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
167106925Ssam#define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
168106925Ssam
16983624Sjlemon/* Capabilities that interfaces can advertise. */
17083636Sjlemon#define IFCAP_RXCSUM		0x0001  /* can offload checksum on RX */
17183636Sjlemon#define IFCAP_TXCSUM		0x0002  /* can offload checksum on TX */
17283636Sjlemon#define IFCAP_NETCONS		0x0004  /* can be a network console */
173106925Ssam#define	IFCAP_VLAN_MTU		0x0008	/* VLAN-compatible MTU */
174106925Ssam#define	IFCAP_VLAN_HWTAGGING	0x0010	/* hardware VLAN tag support */
175106925Ssam#define	IFCAP_JUMBO_MTU		0x0020	/* 9000 byte MTU supported */
17683624Sjlemon
17783636Sjlemon#define IFCAP_HWCSUM		(IFCAP_RXCSUM | IFCAP_TXCSUM)
17883636Sjlemon
1791541Srgrimes#define	IFQ_MAXLEN	50
1801541Srgrimes#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1811541Srgrimes
1821541Srgrimes/*
1831541Srgrimes * Message format for use in obtaining information about interfaces
1841541Srgrimes * from getkerninfo and the routing socket
1851541Srgrimes */
1861541Srgrimesstruct if_msghdr {
1871541Srgrimes	u_short	ifm_msglen;	/* to skip over non-understood messages */
18872093Sasmodai	u_char	ifm_version;	/* future binary compatibility */
1891541Srgrimes	u_char	ifm_type;	/* message type */
1901541Srgrimes	int	ifm_addrs;	/* like rtm_addrs */
1911541Srgrimes	int	ifm_flags;	/* value of if_flags */
1921541Srgrimes	u_short	ifm_index;	/* index for associated ifp */
1931541Srgrimes	struct	if_data ifm_data;/* statistics and other data about if */
1941541Srgrimes};
1951541Srgrimes
1961541Srgrimes/*
1971541Srgrimes * Message format for use in obtaining information about interface addresses
1981541Srgrimes * from getkerninfo and the routing socket
1991541Srgrimes */
2001541Srgrimesstruct ifa_msghdr {
2011541Srgrimes	u_short	ifam_msglen;	/* to skip over non-understood messages */
20272093Sasmodai	u_char	ifam_version;	/* future binary compatibility */
2031541Srgrimes	u_char	ifam_type;	/* message type */
2041541Srgrimes	int	ifam_addrs;	/* like rtm_addrs */
2051541Srgrimes	int	ifam_flags;	/* value of ifa_flags */
2061541Srgrimes	u_short	ifam_index;	/* index for associated ifp */
2071541Srgrimes	int	ifam_metric;	/* value of ifa_metric */
2081541Srgrimes};
2091541Srgrimes
2101541Srgrimes/*
21121666Swollman * Message format for use in obtaining information about multicast addresses
21221666Swollman * from the routing socket
21321666Swollman */
21421666Swollmanstruct ifma_msghdr {
21521666Swollman	u_short	ifmam_msglen;	/* to skip over non-understood messages */
21672093Sasmodai	u_char	ifmam_version;	/* future binary compatibility */
21721666Swollman	u_char	ifmam_type;	/* message type */
21821666Swollman	int	ifmam_addrs;	/* like rtm_addrs */
21921666Swollman	int	ifmam_flags;	/* value of ifa_flags */
22021666Swollman	u_short	ifmam_index;	/* index for associated ifp */
22121666Swollman};
22221666Swollman
22321666Swollman/*
22489498Sru * Message format announcing the arrival or departure of a network interface.
22589498Sru */
22689498Srustruct if_announcemsghdr {
22789498Sru	u_short	ifan_msglen;	/* to skip over non-understood messages */
22889498Sru	u_char	ifan_version;	/* future binary compatibility */
22989498Sru	u_char	ifan_type;	/* message type */
23089498Sru	u_short	ifan_index;	/* index for associated ifp */
23189498Sru	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
23289498Sru	u_short	ifan_what;	/* what type of announcement */
23389498Sru};
23489498Sru
23589498Sru#define	IFAN_ARRIVAL	0	/* interface arrival */
23689498Sru#define	IFAN_DEPARTURE	1	/* interface departure */
23789498Sru
23889498Sru/*
2391541Srgrimes * Interface request structure used for socket
2401541Srgrimes * ioctl's.  All interface ioctl's must have parameter
2411541Srgrimes * definitions which begin with ifr_name.  The
2421541Srgrimes * remainder may be interface specific.
2431541Srgrimes */
2441541Srgrimesstruct	ifreq {
2451541Srgrimes	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2461541Srgrimes	union {
2471541Srgrimes		struct	sockaddr ifru_addr;
2481541Srgrimes		struct	sockaddr ifru_dstaddr;
2491541Srgrimes		struct	sockaddr ifru_broadaddr;
25044144Sphk		short	ifru_flags[2];
25185079Sjlemon		short	ifru_index;
2521541Srgrimes		int	ifru_metric;
2531941Sdg		int	ifru_mtu;
2545184Swollman		int	ifru_phys;
25525434Speter		int	ifru_media;
2561541Srgrimes		caddr_t	ifru_data;
25783624Sjlemon		int	ifru_cap[2];
2581541Srgrimes	} ifr_ifru;
2591541Srgrimes#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
2601541Srgrimes#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
2611541Srgrimes#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
262102052Ssobomax#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
263102052Ssobomax#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
2641541Srgrimes#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
2651941Sdg#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
2665187Sdg#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
26725434Speter#define ifr_media	ifr_ifru.ifru_media	/* physical media */
2681541Srgrimes#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
26983624Sjlemon#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
27083624Sjlemon#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
27185079Sjlemon#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
2721541Srgrimes};
2731541Srgrimes
27432491Swollman#define	_SIZEOF_ADDR_IFREQ(ifr) \
27532491Swollman	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
27632491Swollman	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
27732491Swollman	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
27832491Swollman
2791541Srgrimesstruct ifaliasreq {
2801541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2811541Srgrimes	struct	sockaddr ifra_addr;
2821541Srgrimes	struct	sockaddr ifra_broadaddr;
2831541Srgrimes	struct	sockaddr ifra_mask;
2841541Srgrimes};
2851541Srgrimes
28625434Speterstruct ifmediareq {
28725434Speter	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
28825434Speter	int	ifm_current;		/* current media options */
28925434Speter	int	ifm_mask;		/* don't care mask */
29025434Speter	int	ifm_status;		/* media status */
29125434Speter	int	ifm_active;		/* active options */
29225434Speter	int	ifm_count;		/* # entries in ifm_ulist array */
29325434Speter	int	*ifm_ulist;		/* media words */
29425434Speter};
29548021Sphk
29648021Sphk/*
29748021Sphk * Structure used to retrieve aux status data from interfaces.
29848589Sbde * Kernel suppliers to this interface should respect the formatting
29948021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with
30048589Sbde * a newline.  The canonical example to copy and paste is in if_tun.c.
30148021Sphk */
30248021Sphk
30348589Sbde#define	IFSTATMAX	800		/* 10 lines of text */
30448021Sphkstruct ifstat {
30548589Sbde	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
30648589Sbde	char	ascii[IFSTATMAX + 1];
30748021Sphk};
30848021Sphk
3091541Srgrimes/*
3101541Srgrimes * Structure used in SIOCGIFCONF request.
3111541Srgrimes * Used to retrieve interface configuration
3121541Srgrimes * for machine (useful for programs which
3131541Srgrimes * must know all networks accessible).
3141541Srgrimes */
3151541Srgrimesstruct	ifconf {
3161541Srgrimes	int	ifc_len;		/* size of associated buffer */
3171541Srgrimes	union {
3181541Srgrimes		caddr_t	ifcu_buf;
3191541Srgrimes		struct	ifreq *ifcu_req;
3201541Srgrimes	} ifc_ifcu;
3211541Srgrimes#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
3221541Srgrimes#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
3231541Srgrimes};
3241541Srgrimes
32552904Sshin
32652904Sshin/*
32752904Sshin * Structure for SIOC[AGD]LIFADDR
32852904Sshin */
32952904Sshinstruct if_laddrreq {
33052904Sshin	char	iflr_name[IFNAMSIZ];
33152904Sshin	u_int	flags;
33252904Sshin#define	IFLR_PREFIX	0x8000  /* in: prefix given  out: kernel fills id */
33352904Sshin	u_int	prefixlen;         /* in/out */
33452904Sshin	struct	sockaddr_storage addr;   /* in/out */
33552904Sshin	struct	sockaddr_storage dstaddr; /* out */
33652904Sshin};
33752904Sshin
338104355Smike#endif /* __BSD_VISIBLE */
339104355Smike
34055205Speter#ifdef _KERNEL
34130354Sphk#ifdef MALLOC_DECLARE
34230354SphkMALLOC_DECLARE(M_IFADDR);
34330354SphkMALLOC_DECLARE(M_IFMADDR);
34430354Sphk#endif
34530354Sphk#endif
34630354Sphk
34755205Speter#ifndef _KERNEL
34852904Sshinstruct if_nameindex {
349104355Smike	unsigned int	if_index;	/* 1, 2, ... */
350104360Smike	char		*if_name;	/* null terminated name: "le0", ... */
35152904Sshin};
35252904Sshin
35352904Sshin__BEGIN_DECLS
354104360Smikevoid			 if_freenameindex(struct if_nameindex *);
355104360Smikechar			*if_indextoname(unsigned int, char *);
356104360Smikestruct if_nameindex	*if_nameindex(void);
357104360Smikeunsigned int		 if_nametoindex(const char *);
35852904Sshin__END_DECLS
35952904Sshin#endif
36052904Sshin
36155205Speter#ifdef _KERNEL
36283366Sjulianstruct thread;
36348589Sbde
36448589Sbde/* XXX - this should go away soon. */
36521259Swollman#include <net/if_var.h>
3661541Srgrimes#endif
3671541Srgrimes
3684507Sbde#endif /* !_NET_IF_H_ */
369