if.h revision 97289
190075Sobrien/*
2132718Skan * Copyright (c) 1982, 1986, 1989, 1993
3132718Skan *	The Regents of the University of California.  All rights reserved.
490075Sobrien *
590075Sobrien * Redistribution and use in source and binary forms, with or without
690075Sobrien * modification, are permitted provided that the following conditions
790075Sobrien * are met:
890075Sobrien * 1. Redistributions of source code must retain the above copyright
990075Sobrien *    notice, this list of conditions and the following disclaimer.
1090075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1190075Sobrien *    notice, this list of conditions and the following disclaimer in the
1290075Sobrien *    documentation and/or other materials provided with the distribution.
1390075Sobrien * 3. All advertising materials mentioning features or use of this software
1490075Sobrien *    must display the following acknowledgement:
1590075Sobrien *	This product includes software developed by the University of
1690075Sobrien *	California, Berkeley and its contributors.
1790075Sobrien * 4. Neither the name of the University nor the names of its contributors
1890075Sobrien *    may be used to endorse or promote products derived from this software
1990075Sobrien *    without specific prior written permission.
2090075Sobrien *
2190075Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2290075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2390075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2490075Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2590075Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2690075Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27132718Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2890075Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2990075Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30132718Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31117395Skan * SUCH DAMAGE.
32132718Skan *
33132718Skan *	@(#)if.h	8.1 (Berkeley) 6/10/93
34117395Skan * $FreeBSD: head/sys/net/if.h 97289 2002-05-25 20:17:04Z brooks $
35117395Skan */
36117395Skan
37132718Skan#ifndef _NET_IF_H_
38132718Skan#define	_NET_IF_H_
39132718Skan
40132718Skan#ifdef _KERNEL
41132718Skan#include <sys/queue.h>
42132718Skan#endif
43132718Skan
44132718Skan/*
45132718Skan * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
46132718Skan * helps userland compatibility.  (struct timeval ifi_lastchange)
47132718Skan */
48132718Skan#ifndef _KERNEL
49132718Skan#include <sys/time.h>
50117395Skan#endif
51132718Skan
52132718Skanstruct ifnet;
53132718Skan
54132718Skan/*
55132718Skan * Length of interface external name, including terminating '\0'.
56132718Skan * Note: this is the same size as a generic device's external name.
57132718Skan */
58117395Skan#define		IFNAMSIZ	16
59117395Skan#define		IF_NAMESIZE	IFNAMSIZ
60117395Skan#define		IF_MAXUNIT	0x7fff	/* ifp->if_unit is only 15 bits */
61117395Skan
6290075Sobrien#ifdef _KERNEL
6390075Sobrien/*
6490075Sobrien * Structure describing a `cloning' interface.
6590075Sobrien */
66132718Skanstruct if_clone {
6790075Sobrien	LIST_ENTRY(if_clone) ifc_list;	/* on list of cloners */
68132718Skan	const char *ifc_name;		/* name of device, e.g. `gif' */
69132718Skan	size_t ifc_namelen;		/* length of name */
70132718Skan	int ifc_minifs;			/* minimum number of interfaces */
71132718Skan	int ifc_maxunit;		/* maximum unit number */
72132718Skan	unsigned char *ifc_units;	/* bitmap to handle units */
73132718Skan	int ifc_bmlen;			/* bitmap length */
74132718Skan
75132718Skan	int	(*ifc_create)(struct if_clone *, int);
76132718Skan	void	(*ifc_destroy)(struct ifnet *);
77132718Skan};
78132718Skan
7990075Sobrien#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit)	\
8090075Sobrien    { { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
8190075Sobrien#endif
8290075Sobrien
8390075Sobrien/*
84132718Skan * Structure used to query names of interface cloners.
8590075Sobrien */
86117395Skan
8790075Sobrienstruct if_clonereq {
8890075Sobrien	int	ifcr_total;		/* total cloners (out) */
89117395Skan	int	ifcr_count;		/* room for this many in user buffer */
90117395Skan	char	*ifcr_buffer;		/* buffer for cloner names */
91117395Skan};
9290075Sobrien
9390075Sobrien/*
9490075Sobrien * Structure describing information about an interface
9590075Sobrien * which may be of interest to management entities.
9690075Sobrien */
9790075Sobrienstruct if_data {
9890075Sobrien	/* generic interface information */
99132718Skan	u_char	ifi_type;		/* ethernet, tokenring, etc */
10090075Sobrien	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
101117395Skan	u_char	ifi_addrlen;		/* media address length */
102117395Skan	u_char	ifi_hdrlen;		/* media header length */
103117395Skan	u_char	ifi_recvquota;		/* polling quota for receive intrs */
104117395Skan	u_char	ifi_xmitquota;		/* polling quota for xmit intrs */
105117395Skan	u_long	ifi_mtu;		/* maximum transmission unit */
10690075Sobrien	u_long	ifi_metric;		/* routing metric (external only) */
107117395Skan	u_long	ifi_baudrate;		/* linespeed */
108117395Skan	/* volatile statistics */
109117395Skan	u_long	ifi_ipackets;		/* packets received on interface */
110117395Skan	u_long	ifi_ierrors;		/* input errors on interface */
111117395Skan	u_long	ifi_opackets;		/* packets sent on interface */
112117395Skan	u_long	ifi_oerrors;		/* output errors on interface */
113117395Skan	u_long	ifi_collisions;		/* collisions on csma interfaces */
114117395Skan	u_long	ifi_ibytes;		/* total number of octets received */
115117395Skan	u_long	ifi_obytes;		/* total number of octets sent */
116132718Skan	u_long	ifi_imcasts;		/* packets received via multicast */
11790075Sobrien	u_long	ifi_omcasts;		/* packets sent via multicast */
11890075Sobrien	u_long	ifi_iqdrops;		/* dropped on input, this interface */
119117395Skan	u_long	ifi_noproto;		/* destined for unsupported protocol */
120117395Skan	u_long	ifi_hwassist;		/* HW offload capabilities */
121117395Skan	u_long	ifi_unused;		/* XXX was ifi_xmittiming */
122117395Skan	struct	timeval ifi_lastchange;	/* time of last administrative change */
123132718Skan};
124132718Skan
125132718Skan#define	IFF_UP		0x1		/* interface is up */
126132718Skan#define	IFF_BROADCAST	0x2		/* broadcast address valid */
127132718Skan#define	IFF_DEBUG	0x4		/* turn on debugging */
12890075Sobrien#define	IFF_LOOPBACK	0x8		/* is a loopback net */
12990075Sobrien#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
130117395Skan#define	IFF_SMART	0x20		/* interface manages own routes */
131117395Skan#define	IFF_RUNNING	0x40		/* resources allocated */
132132718Skan#define	IFF_NOARP	0x80		/* no address resolution protocol */
13390075Sobrien#define	IFF_PROMISC	0x100		/* receive all packets */
134117395Skan#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
135117395Skan#define	IFF_OACTIVE	0x400		/* transmission in progress */
136117395Skan#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
13796263Sobrien#define	IFF_LINK0	0x1000		/* per link layer defined bit */
13896263Sobrien#define	IFF_LINK1	0x2000		/* per link layer defined bit */
139117395Skan#define	IFF_LINK2	0x4000		/* per link layer defined bit */
140117395Skan#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
141132718Skan#define	IFF_MULTICAST	0x8000		/* supports multicast */
14296263Sobrien
143117395Skan/*
144117395Skan * The following flag(s) ought to go in if_flags, but we cannot change
14590075Sobrien * struct ifnet because of binary compatibility, so we store them in
146117395Skan * if_ipending, which is not used so far.
147117395Skan * If possible, make sure the value is not conflicting with other
14890075Sobrien * IFF flags, so we have an easier time when we want to merge them.
149117395Skan */
150117395Skan#define	IFF_POLLING	0x10000		/* Interface is in polling mode. */
15190075Sobrien
152117395Skan/* flags set internally only: */
153117395Skan#define	IFF_CANTCHANGE \
154117395Skan	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
155117395Skan	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART)
156117395Skan
157117395Skan/* Capabilities that interfaces can advertise. */
158117395Skan#define IFCAP_RXCSUM		0x0001  /* can offload checksum on RX */
159132718Skan#define IFCAP_TXCSUM		0x0002  /* can offload checksum on TX */
160117395Skan#define IFCAP_NETCONS		0x0004  /* can be a network console */
161117395Skan
162117395Skan#define IFCAP_HWCSUM		(IFCAP_RXCSUM | IFCAP_TXCSUM)
163117395Skan
164117395Skan#define	IFQ_MAXLEN	50
165117395Skan#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
16690075Sobrien
16790075Sobrien/*
168117395Skan * Message format for use in obtaining information about interfaces
16990075Sobrien * from getkerninfo and the routing socket
170117395Skan */
171117395Skanstruct if_msghdr {
172117395Skan	u_short	ifm_msglen;	/* to skip over non-understood messages */
173117395Skan	u_char	ifm_version;	/* future binary compatibility */
174117395Skan	u_char	ifm_type;	/* message type */
17590075Sobrien	int	ifm_addrs;	/* like rtm_addrs */
176117395Skan	int	ifm_flags;	/* value of if_flags */
17790075Sobrien	u_short	ifm_index;	/* index for associated ifp */
178117395Skan	struct	if_data ifm_data;/* statistics and other data about if */
179117395Skan};
18090075Sobrien
181117395Skan/*
18290075Sobrien * Message format for use in obtaining information about interface addresses
18390075Sobrien * from getkerninfo and the routing socket
184117395Skan */
18590075Sobrienstruct ifa_msghdr {
186132718Skan	u_short	ifam_msglen;	/* to skip over non-understood messages */
18790075Sobrien	u_char	ifam_version;	/* future binary compatibility */
188117395Skan	u_char	ifam_type;	/* message type */
18990075Sobrien	int	ifam_addrs;	/* like rtm_addrs */
19090075Sobrien	int	ifam_flags;	/* value of ifa_flags */
191132718Skan	u_short	ifam_index;	/* index for associated ifp */
192132718Skan	int	ifam_metric;	/* value of ifa_metric */
193132718Skan};
194132718Skan
195132718Skan/*
196132718Skan * Message format for use in obtaining information about multicast addresses
197132718Skan * from the routing socket
198132718Skan */
199132718Skanstruct ifma_msghdr {
200132718Skan	u_short	ifmam_msglen;	/* to skip over non-understood messages */
201132718Skan	u_char	ifmam_version;	/* future binary compatibility */
202132718Skan	u_char	ifmam_type;	/* message type */
203132718Skan	int	ifmam_addrs;	/* like rtm_addrs */
204132718Skan	int	ifmam_flags;	/* value of ifa_flags */
205132718Skan	u_short	ifmam_index;	/* index for associated ifp */
206132718Skan};
20790075Sobrien
20890075Sobrien/*
20990075Sobrien * Message format announcing the arrival or departure of a network interface.
21090075Sobrien */
21190075Sobrienstruct if_announcemsghdr {
21290075Sobrien	u_short	ifan_msglen;	/* to skip over non-understood messages */
21390075Sobrien	u_char	ifan_version;	/* future binary compatibility */
21490075Sobrien	u_char	ifan_type;	/* message type */
21590075Sobrien	u_short	ifan_index;	/* index for associated ifp */
216132718Skan	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
217132718Skan	u_short	ifan_what;	/* what type of announcement */
21890075Sobrien};
21990075Sobrien
22090075Sobrien#define	IFAN_ARRIVAL	0	/* interface arrival */
22190075Sobrien#define	IFAN_DEPARTURE	1	/* interface departure */
22290075Sobrien
22390075Sobrien/*
22490075Sobrien * Interface request structure used for socket
22590075Sobrien * ioctl's.  All interface ioctl's must have parameter
226132718Skan * definitions which begin with ifr_name.  The
227132718Skan * remainder may be interface specific.
228132718Skan */
229132718Skanstruct	ifreq {
230132718Skan	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
231132718Skan	union {
232132718Skan		struct	sockaddr ifru_addr;
233132718Skan		struct	sockaddr ifru_dstaddr;
234132718Skan		struct	sockaddr ifru_broadaddr;
235132718Skan		short	ifru_flags[2];
236132718Skan		short	ifru_index;
237132718Skan		int	ifru_metric;
238132718Skan		int	ifru_mtu;
239132718Skan		int	ifru_phys;
240132718Skan		int	ifru_media;
241132718Skan		caddr_t	ifru_data;
242132718Skan		int	ifru_cap[2];
243132718Skan	} ifr_ifru;
244132718Skan#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
245132718Skan#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
246132718Skan#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
247132718Skan#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags */
248132718Skan#define	ifr_prevflags	ifr_ifru.ifru_flags[1]	/* flags */
249132718Skan#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
250132718Skan#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
251132718Skan#define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
252132718Skan#define ifr_media	ifr_ifru.ifru_media	/* physical media */
253132718Skan#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
254132718Skan#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
255132718Skan#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
256132718Skan#define	ifr_index	ifr_ifru.ifru_index	/* interface index */
257132718Skan};
258132718Skan
259132718Skan#define	_SIZEOF_ADDR_IFREQ(ifr) \
260132718Skan	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
261132718Skan	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
262132718Skan	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
26390075Sobrien
264132718Skanstruct ifaliasreq {
265132718Skan	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
266132718Skan	struct	sockaddr ifra_addr;
267132718Skan	struct	sockaddr ifra_broadaddr;
26890075Sobrien	struct	sockaddr ifra_mask;
269132718Skan};
270132718Skan
271132718Skanstruct ifmediareq {
272132718Skan	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
273132718Skan	int	ifm_current;		/* current media options */
274132718Skan	int	ifm_mask;		/* don't care mask */
275132718Skan	int	ifm_status;		/* media status */
276132718Skan	int	ifm_active;		/* active options */
277132718Skan	int	ifm_count;		/* # entries in ifm_ulist array */
278132718Skan	int	*ifm_ulist;		/* media words */
279132718Skan};
280132718Skan
281132718Skan/*
282132718Skan * Structure used to retrieve aux status data from interfaces.
283132718Skan * Kernel suppliers to this interface should respect the formatting
284132718Skan * needed by ifconfig(8): each line starts with a TAB and ends with
285132718Skan * a newline.  The canonical example to copy and paste is in if_tun.c.
286132718Skan */
287132718Skan
288132718Skan#define	IFSTATMAX	800		/* 10 lines of text */
289132718Skanstruct ifstat {
290132718Skan	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
291132718Skan	char	ascii[IFSTATMAX + 1];
292132718Skan};
293132718Skan
294132718Skan/*
295132718Skan * Structure used in SIOCGIFCONF request.
296132718Skan * Used to retrieve interface configuration
297132718Skan * for machine (useful for programs which
298132718Skan * must know all networks accessible).
299132718Skan */
300132718Skanstruct	ifconf {
301132718Skan	int	ifc_len;		/* size of associated buffer */
302132718Skan	union {
303132718Skan		caddr_t	ifcu_buf;
304132718Skan		struct	ifreq *ifcu_req;
305132718Skan	} ifc_ifcu;
306132718Skan#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
307132718Skan#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
308132718Skan};
309132718Skan
310132718Skan
311132718Skan/*
312132718Skan * Structure for SIOC[AGD]LIFADDR
313132718Skan */
314132718Skanstruct if_laddrreq {
315132718Skan	char	iflr_name[IFNAMSIZ];
316132718Skan	u_int	flags;
317132718Skan#define	IFLR_PREFIX	0x8000  /* in: prefix given  out: kernel fills id */
318132718Skan	u_int	prefixlen;         /* in/out */
319132718Skan	struct	sockaddr_storage addr;   /* in/out */
320132718Skan	struct	sockaddr_storage dstaddr; /* out */
321132718Skan};
322132718Skan
323132718Skan#ifdef _KERNEL
324132718Skan#ifdef MALLOC_DECLARE
325132718SkanMALLOC_DECLARE(M_IFADDR);
326132718SkanMALLOC_DECLARE(M_IFMADDR);
327132718Skan#endif
328132718Skan#endif
329132718Skan
330132718Skan#ifndef _KERNEL
331132718Skanstruct if_nameindex {
332132718Skan	u_int	if_index;	/* 1, 2, ... */
333132718Skan	char	*if_name;	/* null terminated name: "le0", ... */
334132718Skan};
335132718Skan
336132718Skan__BEGIN_DECLS
337132718Skanu_int	 if_nametoindex(const char *);
338132718Skanchar	*if_indextoname(u_int, char *);
339132718Skanstruct	 if_nameindex *if_nameindex(void);
340132718Skanvoid	 if_freenameindex(struct if_nameindex *);
341132718Skan__END_DECLS
342132718Skan#endif
343132718Skan
344132718Skan#ifdef _KERNEL
345132718Skanstruct thread;
346132718Skan
347132718Skan/* XXX - this should go away soon. */
348132718Skan#include <net/if_var.h>
349132718Skan#endif
350132718Skan
351132718Skan#endif /* !_NET_IF_H_ */
352132718Skan