if.h revision 102099
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 102099 2002-08-19 15:16:38Z sobomax $
351541Srgrimes */
361541Srgrimes
372168Spaul#ifndef _NET_IF_H_
384507Sbde#define	_NET_IF_H_
392168Spaul
4097024Siedowse#ifdef _KERNEL
4179103Sbrooks#include <sys/queue.h>
4297024Siedowse#endif
4379103Sbrooks
441541Srgrimes/*
4534750Speter * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
4672093Sasmodai * helps userland compatibility.  (struct timeval ifi_lastchange)
4734750Speter */
4855205Speter#ifndef _KERNEL
4934750Speter#include <sys/time.h>
5034750Speter#endif
5134750Speter
5279103Sbrooksstruct ifnet;
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 */
5879103Sbrooks#define		IFNAMSIZ	16
5979103Sbrooks#define		IF_NAMESIZE	IFNAMSIZ
6092081Smux#define		IF_MAXUNIT	0x7fff	/* ifp->if_unit is only 15 bits */
6179103Sbrooks
6297024Siedowse#ifdef _KERNEL
6379103Sbrooks/*
6479103Sbrooks * Structure describing a `cloning' interface.
6579103Sbrooks */
6679103Sbrooksstruct if_clone {
6779103Sbrooks	LIST_ENTRY(if_clone) ifc_list;	/* on list of cloners */
6879103Sbrooks	const char *ifc_name;		/* name of device, e.g. `gif' */
6979103Sbrooks	size_t ifc_namelen;		/* length of name */
7097289Sbrooks	int ifc_minifs;			/* minimum number of interfaces */
7192081Smux	int ifc_maxunit;		/* maximum unit number */
7292081Smux	unsigned char *ifc_units;	/* bitmap to handle units */
7392081Smux	int ifc_bmlen;			/* bitmap length */
7479103Sbrooks
7592081Smux	int	(*ifc_create)(struct if_clone *, int);
7697289Sbrooks	void	(*ifc_destroy)(struct ifnet *);
7779103Sbrooks};
7879103Sbrooks
7997289Sbrooks#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit)	\
8097289Sbrooks    { { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
8197024Siedowse#endif
8279103Sbrooks
8379103Sbrooks/*
8479103Sbrooks * Structure used to query names of interface cloners.
8579103Sbrooks */
8679103Sbrooks
8779103Sbrooksstruct if_clonereq {
8879103Sbrooks	int	ifcr_total;		/* total cloners (out) */
8979103Sbrooks	int	ifcr_count;		/* room for this many in user buffer */
9079103Sbrooks	char	*ifcr_buffer;		/* buffer for cloner names */
9179103Sbrooks};
9279103Sbrooks
9379103Sbrooks/*
9419079Sfenner * Structure describing information about an interface
9519079Sfenner * which may be of interest to management entities.
9619079Sfenner */
979457Sjoergstruct if_data {
989457Sjoerg	/* generic interface information */
999457Sjoerg	u_char	ifi_type;		/* ethernet, tokenring, etc */
1009457Sjoerg	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
1019457Sjoerg	u_char	ifi_addrlen;		/* media address length */
1029457Sjoerg	u_char	ifi_hdrlen;		/* media header length */
10317352Swollman	u_char	ifi_recvquota;		/* polling quota for receive intrs */
10417352Swollman	u_char	ifi_xmitquota;		/* polling quota for xmit intrs */
1059457Sjoerg	u_long	ifi_mtu;		/* maximum transmission unit */
1069457Sjoerg	u_long	ifi_metric;		/* routing metric (external only) */
1079457Sjoerg	u_long	ifi_baudrate;		/* linespeed */
1089457Sjoerg	/* volatile statistics */
1099457Sjoerg	u_long	ifi_ipackets;		/* packets received on interface */
1109457Sjoerg	u_long	ifi_ierrors;		/* input errors on interface */
1119457Sjoerg	u_long	ifi_opackets;		/* packets sent on interface */
1129457Sjoerg	u_long	ifi_oerrors;		/* output errors on interface */
1139457Sjoerg	u_long	ifi_collisions;		/* collisions on csma interfaces */
1149457Sjoerg	u_long	ifi_ibytes;		/* total number of octets received */
1159457Sjoerg	u_long	ifi_obytes;		/* total number of octets sent */
1169457Sjoerg	u_long	ifi_imcasts;		/* packets received via multicast */
1179457Sjoerg	u_long	ifi_omcasts;		/* packets sent via multicast */
1189457Sjoerg	u_long	ifi_iqdrops;		/* dropped on input, this interface */
1199457Sjoerg	u_long	ifi_noproto;		/* destined for unsupported protocol */
12058698Sjlemon	u_long	ifi_hwassist;		/* HW offload capabilities */
12158698Sjlemon	u_long	ifi_unused;		/* XXX was ifi_xmittiming */
12216287Sgpalmer	struct	timeval ifi_lastchange;	/* time of last administrative change */
1239457Sjoerg};
1249457Sjoerg
1251541Srgrimes#define	IFF_UP		0x1		/* interface is up */
1261541Srgrimes#define	IFF_BROADCAST	0x2		/* broadcast address valid */
1271541Srgrimes#define	IFF_DEBUG	0x4		/* turn on debugging */
1281541Srgrimes#define	IFF_LOOPBACK	0x8		/* is a loopback net */
1291541Srgrimes#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
13047777Sphk#define	IFF_SMART	0x20		/* interface manages own routes */
1311541Srgrimes#define	IFF_RUNNING	0x40		/* resources allocated */
1321541Srgrimes#define	IFF_NOARP	0x80		/* no address resolution protocol */
1331541Srgrimes#define	IFF_PROMISC	0x100		/* receive all packets */
1341541Srgrimes#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
1351541Srgrimes#define	IFF_OACTIVE	0x400		/* transmission in progress */
1361541Srgrimes#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
1371541Srgrimes#define	IFF_LINK0	0x1000		/* per link layer defined bit */
1381541Srgrimes#define	IFF_LINK1	0x2000		/* per link layer defined bit */
1391541Srgrimes#define	IFF_LINK2	0x4000		/* per link layer defined bit */
1403274Swollman#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
1411541Srgrimes#define	IFF_MULTICAST	0x8000		/* supports multicast */
14287902Sluigi#define	IFF_POLLING	0x10000		/* Interface is in polling mode. */
143102099Ssobomax#define	IFF_PPROMISC	0x20000		/* user-requested promisc mode */
14487902Sluigi
1451541Srgrimes/* flags set internally only: */
1461541Srgrimes#define	IFF_CANTCHANGE \
1471541Srgrimes	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
148102099Ssobomax	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC)
1491541Srgrimes
15083624Sjlemon/* Capabilities that interfaces can advertise. */
15183636Sjlemon#define IFCAP_RXCSUM		0x0001  /* can offload checksum on RX */
15283636Sjlemon#define IFCAP_TXCSUM		0x0002  /* can offload checksum on TX */
15383636Sjlemon#define IFCAP_NETCONS		0x0004  /* can be a network console */
15483624Sjlemon
15583636Sjlemon#define IFCAP_HWCSUM		(IFCAP_RXCSUM | IFCAP_TXCSUM)
15683636Sjlemon
1571541Srgrimes#define	IFQ_MAXLEN	50
1581541Srgrimes#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1591541Srgrimes
1601541Srgrimes/*
1611541Srgrimes * Message format for use in obtaining information about interfaces
1621541Srgrimes * from getkerninfo and the routing socket
1631541Srgrimes */
1641541Srgrimesstruct if_msghdr {
1651541Srgrimes	u_short	ifm_msglen;	/* to skip over non-understood messages */
16672093Sasmodai	u_char	ifm_version;	/* future binary compatibility */
1671541Srgrimes	u_char	ifm_type;	/* message type */
1681541Srgrimes	int	ifm_addrs;	/* like rtm_addrs */
1691541Srgrimes	int	ifm_flags;	/* value of if_flags */
1701541Srgrimes	u_short	ifm_index;	/* index for associated ifp */
1711541Srgrimes	struct	if_data ifm_data;/* statistics and other data about if */
1721541Srgrimes};
1731541Srgrimes
1741541Srgrimes/*
1751541Srgrimes * Message format for use in obtaining information about interface addresses
1761541Srgrimes * from getkerninfo and the routing socket
1771541Srgrimes */
1781541Srgrimesstruct ifa_msghdr {
1791541Srgrimes	u_short	ifam_msglen;	/* to skip over non-understood messages */
18072093Sasmodai	u_char	ifam_version;	/* future binary compatibility */
1811541Srgrimes	u_char	ifam_type;	/* message type */
1821541Srgrimes	int	ifam_addrs;	/* like rtm_addrs */
1831541Srgrimes	int	ifam_flags;	/* value of ifa_flags */
1841541Srgrimes	u_short	ifam_index;	/* index for associated ifp */
1851541Srgrimes	int	ifam_metric;	/* value of ifa_metric */
1861541Srgrimes};
1871541Srgrimes
1881541Srgrimes/*
18921666Swollman * Message format for use in obtaining information about multicast addresses
19021666Swollman * from the routing socket
19121666Swollman */
19221666Swollmanstruct ifma_msghdr {
19321666Swollman	u_short	ifmam_msglen;	/* to skip over non-understood messages */
19472093Sasmodai	u_char	ifmam_version;	/* future binary compatibility */
19521666Swollman	u_char	ifmam_type;	/* message type */
19621666Swollman	int	ifmam_addrs;	/* like rtm_addrs */
19721666Swollman	int	ifmam_flags;	/* value of ifa_flags */
19821666Swollman	u_short	ifmam_index;	/* index for associated ifp */
19921666Swollman};
20021666Swollman
20121666Swollman/*
20289498Sru * Message format announcing the arrival or departure of a network interface.
20389498Sru */
20489498Srustruct if_announcemsghdr {
20589498Sru	u_short	ifan_msglen;	/* to skip over non-understood messages */
20689498Sru	u_char	ifan_version;	/* future binary compatibility */
20789498Sru	u_char	ifan_type;	/* message type */
20889498Sru	u_short	ifan_index;	/* index for associated ifp */
20989498Sru	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
21089498Sru	u_short	ifan_what;	/* what type of announcement */
21189498Sru};
21289498Sru
21389498Sru#define	IFAN_ARRIVAL	0	/* interface arrival */
21489498Sru#define	IFAN_DEPARTURE	1	/* interface departure */
21589498Sru
21689498Sru/*
2171541Srgrimes * Interface request structure used for socket
2181541Srgrimes * ioctl's.  All interface ioctl's must have parameter
2191541Srgrimes * definitions which begin with ifr_name.  The
2201541Srgrimes * remainder may be interface specific.
2211541Srgrimes */
2221541Srgrimesstruct	ifreq {
2231541Srgrimes	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2241541Srgrimes	union {
2251541Srgrimes		struct	sockaddr ifru_addr;
2261541Srgrimes		struct	sockaddr ifru_dstaddr;
2271541Srgrimes		struct	sockaddr ifru_broadaddr;
22844144Sphk		short	ifru_flags[2];
22985079Sjlemon		short	ifru_index;
2301541Srgrimes		int	ifru_metric;
2311941Sdg		int	ifru_mtu;
2325184Swollman		int	ifru_phys;
23325434Speter		int	ifru_media;
2341541Srgrimes		caddr_t	ifru_data;
23583624Sjlemon		int	ifru_cap[2];
2361541Srgrimes	} ifr_ifru;
2371541Srgrimes#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
2381541Srgrimes#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
2391541Srgrimes#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
240102052Ssobomax#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
241102052Ssobomax#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
2421541Srgrimes#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
2431941Sdg#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
2445187Sdg#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
24525434Speter#define ifr_media	ifr_ifru.ifru_media	/* physical media */
2461541Srgrimes#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
24783624Sjlemon#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
24883624Sjlemon#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
24985079Sjlemon#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
2501541Srgrimes};
2511541Srgrimes
25232491Swollman#define	_SIZEOF_ADDR_IFREQ(ifr) \
25332491Swollman	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
25432491Swollman	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
25532491Swollman	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
25632491Swollman
2571541Srgrimesstruct ifaliasreq {
2581541Srgrimes	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
2591541Srgrimes	struct	sockaddr ifra_addr;
2601541Srgrimes	struct	sockaddr ifra_broadaddr;
2611541Srgrimes	struct	sockaddr ifra_mask;
2621541Srgrimes};
2631541Srgrimes
26425434Speterstruct ifmediareq {
26525434Speter	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
26625434Speter	int	ifm_current;		/* current media options */
26725434Speter	int	ifm_mask;		/* don't care mask */
26825434Speter	int	ifm_status;		/* media status */
26925434Speter	int	ifm_active;		/* active options */
27025434Speter	int	ifm_count;		/* # entries in ifm_ulist array */
27125434Speter	int	*ifm_ulist;		/* media words */
27225434Speter};
27348021Sphk
27448021Sphk/*
27548021Sphk * Structure used to retrieve aux status data from interfaces.
27648589Sbde * Kernel suppliers to this interface should respect the formatting
27748021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with
27848589Sbde * a newline.  The canonical example to copy and paste is in if_tun.c.
27948021Sphk */
28048021Sphk
28148589Sbde#define	IFSTATMAX	800		/* 10 lines of text */
28248021Sphkstruct ifstat {
28348589Sbde	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
28448589Sbde	char	ascii[IFSTATMAX + 1];
28548021Sphk};
28648021Sphk
2871541Srgrimes/*
2881541Srgrimes * Structure used in SIOCGIFCONF request.
2891541Srgrimes * Used to retrieve interface configuration
2901541Srgrimes * for machine (useful for programs which
2911541Srgrimes * must know all networks accessible).
2921541Srgrimes */
2931541Srgrimesstruct	ifconf {
2941541Srgrimes	int	ifc_len;		/* size of associated buffer */
2951541Srgrimes	union {
2961541Srgrimes		caddr_t	ifcu_buf;
2971541Srgrimes		struct	ifreq *ifcu_req;
2981541Srgrimes	} ifc_ifcu;
2991541Srgrimes#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
3001541Srgrimes#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
3011541Srgrimes};
3021541Srgrimes
30352904Sshin
30452904Sshin/*
30552904Sshin * Structure for SIOC[AGD]LIFADDR
30652904Sshin */
30752904Sshinstruct if_laddrreq {
30852904Sshin	char	iflr_name[IFNAMSIZ];
30952904Sshin	u_int	flags;
31052904Sshin#define	IFLR_PREFIX	0x8000  /* in: prefix given  out: kernel fills id */
31152904Sshin	u_int	prefixlen;         /* in/out */
31252904Sshin	struct	sockaddr_storage addr;   /* in/out */
31352904Sshin	struct	sockaddr_storage dstaddr; /* out */
31452904Sshin};
31552904Sshin
31655205Speter#ifdef _KERNEL
31730354Sphk#ifdef MALLOC_DECLARE
31830354SphkMALLOC_DECLARE(M_IFADDR);
31930354SphkMALLOC_DECLARE(M_IFMADDR);
32030354Sphk#endif
32130354Sphk#endif
32230354Sphk
32355205Speter#ifndef _KERNEL
32452904Sshinstruct if_nameindex {
32552904Sshin	u_int	if_index;	/* 1, 2, ... */
32652904Sshin	char	*if_name;	/* null terminated name: "le0", ... */
32752904Sshin};
32852904Sshin
32952904Sshin__BEGIN_DECLS
33092725Salfredu_int	 if_nametoindex(const char *);
33192725Salfredchar	*if_indextoname(u_int, char *);
33292725Salfredstruct	 if_nameindex *if_nameindex(void);
33392725Salfredvoid	 if_freenameindex(struct if_nameindex *);
33452904Sshin__END_DECLS
33552904Sshin#endif
33652904Sshin
33755205Speter#ifdef _KERNEL
33883366Sjulianstruct thread;
33948589Sbde
34048589Sbde/* XXX - this should go away soon. */
34121259Swollman#include <net/if_var.h>
3421541Srgrimes#endif
3431541Srgrimes
3444507Sbde#endif /* !_NET_IF_H_ */
345