xref: /freebsd/sys/net/if.h (revision 906f09bca40d980e7ac6deb0534e43e08fe128a0)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1989, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33df8bae1dSRodney W. Grimes  *	@(#)if.h	8.1 (Berkeley) 6/10/93
34906f09bcSGarrett Wollman  *	$Id: if.h,v 1.47 1997/10/12 20:25:11 phk Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37cea1da3bSPaul Richards #ifndef _NET_IF_H_
38cea1da3bSPaul Richards #define	_NET_IF_H_
39cea1da3bSPaul Richards 
40df8bae1dSRodney W. Grimes /*
41a73356a1SBill Fenner  * Structure describing information about an interface
42a73356a1SBill Fenner  * which may be of interest to management entities.
43a73356a1SBill Fenner  */
44df8bae1dSRodney W. Grimes struct if_data {
45df8bae1dSRodney W. Grimes 	/* generic interface information */
46df8bae1dSRodney W. Grimes 	u_char	ifi_type;		/* ethernet, tokenring, etc */
47995add1aSGarrett Wollman 	u_char	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
48df8bae1dSRodney W. Grimes 	u_char	ifi_addrlen;		/* media address length */
49df8bae1dSRodney W. Grimes 	u_char	ifi_hdrlen;		/* media header length */
50bbd17bf8SGarrett Wollman 	u_char	ifi_recvquota;		/* polling quota for receive intrs */
51bbd17bf8SGarrett Wollman 	u_char	ifi_xmitquota;		/* polling quota for xmit intrs */
52df8bae1dSRodney W. Grimes 	u_long	ifi_mtu;		/* maximum transmission unit */
53df8bae1dSRodney W. Grimes 	u_long	ifi_metric;		/* routing metric (external only) */
54df8bae1dSRodney W. Grimes 	u_long	ifi_baudrate;		/* linespeed */
55df8bae1dSRodney W. Grimes 	/* volatile statistics */
56df8bae1dSRodney W. Grimes 	u_long	ifi_ipackets;		/* packets received on interface */
57df8bae1dSRodney W. Grimes 	u_long	ifi_ierrors;		/* input errors on interface */
58df8bae1dSRodney W. Grimes 	u_long	ifi_opackets;		/* packets sent on interface */
59df8bae1dSRodney W. Grimes 	u_long	ifi_oerrors;		/* output errors on interface */
60df8bae1dSRodney W. Grimes 	u_long	ifi_collisions;		/* collisions on csma interfaces */
61df8bae1dSRodney W. Grimes 	u_long	ifi_ibytes;		/* total number of octets received */
62df8bae1dSRodney W. Grimes 	u_long	ifi_obytes;		/* total number of octets sent */
63df8bae1dSRodney W. Grimes 	u_long	ifi_imcasts;		/* packets received via multicast */
64df8bae1dSRodney W. Grimes 	u_long	ifi_omcasts;		/* packets sent via multicast */
65df8bae1dSRodney W. Grimes 	u_long	ifi_iqdrops;		/* dropped on input, this interface */
66df8bae1dSRodney W. Grimes 	u_long	ifi_noproto;		/* destined for unsupported protocol */
67bbd17bf8SGarrett Wollman 	u_long	ifi_recvtiming;		/* usec spent receiving when timing */
68bbd17bf8SGarrett Wollman 	u_long	ifi_xmittiming;		/* usec spent xmitting when timing */
69e39a0280SGary Palmer 	struct	timeval ifi_lastchange;	/* time of last administrative change */
706f64074eSJoerg Wunsch };
716f64074eSJoerg Wunsch 
72df8bae1dSRodney W. Grimes #define	IFF_UP		0x1		/* interface is up */
73df8bae1dSRodney W. Grimes #define	IFF_BROADCAST	0x2		/* broadcast address valid */
74df8bae1dSRodney W. Grimes #define	IFF_DEBUG	0x4		/* turn on debugging */
75df8bae1dSRodney W. Grimes #define	IFF_LOOPBACK	0x8		/* is a loopback net */
76df8bae1dSRodney W. Grimes #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
77233b60ceSGarrett Wollman /*#define IFF_NOTRAILERS 0x20		 * obsolete: avoid use of trailers */
78df8bae1dSRodney W. Grimes #define	IFF_RUNNING	0x40		/* resources allocated */
79df8bae1dSRodney W. Grimes #define	IFF_NOARP	0x80		/* no address resolution protocol */
80df8bae1dSRodney W. Grimes #define	IFF_PROMISC	0x100		/* receive all packets */
81df8bae1dSRodney W. Grimes #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
82df8bae1dSRodney W. Grimes #define	IFF_OACTIVE	0x400		/* transmission in progress */
83df8bae1dSRodney W. Grimes #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
84df8bae1dSRodney W. Grimes #define	IFF_LINK0	0x1000		/* per link layer defined bit */
85df8bae1dSRodney W. Grimes #define	IFF_LINK1	0x2000		/* per link layer defined bit */
86df8bae1dSRodney W. Grimes #define	IFF_LINK2	0x4000		/* per link layer defined bit */
8737be1da8SGarrett Wollman #define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
88df8bae1dSRodney W. Grimes #define	IFF_MULTICAST	0x8000		/* supports multicast */
89df8bae1dSRodney W. Grimes 
90df8bae1dSRodney W. Grimes /* flags set internally only: */
91df8bae1dSRodney W. Grimes #define	IFF_CANTCHANGE \
92df8bae1dSRodney W. Grimes 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
93df8bae1dSRodney W. Grimes 	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
94df8bae1dSRodney W. Grimes 
95df8bae1dSRodney W. Grimes #define	IFQ_MAXLEN	50
96df8bae1dSRodney W. Grimes #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
97df8bae1dSRodney W. Grimes 
98df8bae1dSRodney W. Grimes /*
99df8bae1dSRodney W. Grimes  * Message format for use in obtaining information about interfaces
100df8bae1dSRodney W. Grimes  * from getkerninfo and the routing socket
101df8bae1dSRodney W. Grimes  */
102df8bae1dSRodney W. Grimes struct if_msghdr {
103df8bae1dSRodney W. Grimes 	u_short	ifm_msglen;	/* to skip over non-understood messages */
104df8bae1dSRodney W. Grimes 	u_char	ifm_version;	/* future binary compatability */
105df8bae1dSRodney W. Grimes 	u_char	ifm_type;	/* message type */
106df8bae1dSRodney W. Grimes 	int	ifm_addrs;	/* like rtm_addrs */
107df8bae1dSRodney W. Grimes 	int	ifm_flags;	/* value of if_flags */
108df8bae1dSRodney W. Grimes 	u_short	ifm_index;	/* index for associated ifp */
109df8bae1dSRodney W. Grimes 	struct	if_data ifm_data;/* statistics and other data about if */
110df8bae1dSRodney W. Grimes };
111df8bae1dSRodney W. Grimes 
112df8bae1dSRodney W. Grimes /*
113df8bae1dSRodney W. Grimes  * Message format for use in obtaining information about interface addresses
114df8bae1dSRodney W. Grimes  * from getkerninfo and the routing socket
115df8bae1dSRodney W. Grimes  */
116df8bae1dSRodney W. Grimes struct ifa_msghdr {
117df8bae1dSRodney W. Grimes 	u_short	ifam_msglen;	/* to skip over non-understood messages */
118df8bae1dSRodney W. Grimes 	u_char	ifam_version;	/* future binary compatability */
119df8bae1dSRodney W. Grimes 	u_char	ifam_type;	/* message type */
120df8bae1dSRodney W. Grimes 	int	ifam_addrs;	/* like rtm_addrs */
121df8bae1dSRodney W. Grimes 	int	ifam_flags;	/* value of ifa_flags */
122df8bae1dSRodney W. Grimes 	u_short	ifam_index;	/* index for associated ifp */
123df8bae1dSRodney W. Grimes 	int	ifam_metric;	/* value of ifa_metric */
124df8bae1dSRodney W. Grimes };
125df8bae1dSRodney W. Grimes 
126df8bae1dSRodney W. Grimes /*
127477180fbSGarrett Wollman  * Message format for use in obtaining information about multicast addresses
128477180fbSGarrett Wollman  * from the routing socket
129477180fbSGarrett Wollman  */
130477180fbSGarrett Wollman struct ifma_msghdr {
131477180fbSGarrett Wollman 	u_short	ifmam_msglen;	/* to skip over non-understood messages */
132477180fbSGarrett Wollman 	u_char	ifmam_version;	/* future binary compatability */
133477180fbSGarrett Wollman 	u_char	ifmam_type;	/* message type */
134477180fbSGarrett Wollman 	int	ifmam_addrs;	/* like rtm_addrs */
135477180fbSGarrett Wollman 	int	ifmam_flags;	/* value of ifa_flags */
136477180fbSGarrett Wollman 	u_short	ifmam_index;	/* index for associated ifp */
137477180fbSGarrett Wollman };
138477180fbSGarrett Wollman 
139477180fbSGarrett Wollman /*
140df8bae1dSRodney W. Grimes  * Interface request structure used for socket
141df8bae1dSRodney W. Grimes  * ioctl's.  All interface ioctl's must have parameter
142df8bae1dSRodney W. Grimes  * definitions which begin with ifr_name.  The
143df8bae1dSRodney W. Grimes  * remainder may be interface specific.
144df8bae1dSRodney W. Grimes  */
145df8bae1dSRodney W. Grimes struct	ifreq {
146df8bae1dSRodney W. Grimes #define	IFNAMSIZ	16
147df8bae1dSRodney W. Grimes 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
148df8bae1dSRodney W. Grimes 	union {
149df8bae1dSRodney W. Grimes 		struct	sockaddr ifru_addr;
150df8bae1dSRodney W. Grimes 		struct	sockaddr ifru_dstaddr;
151df8bae1dSRodney W. Grimes 		struct	sockaddr ifru_broadaddr;
152df8bae1dSRodney W. Grimes 		short	ifru_flags;
153df8bae1dSRodney W. Grimes 		int	ifru_metric;
154a7028af7SDavid Greenman 		int	ifru_mtu;
155074c4a4eSGarrett Wollman 		int	ifru_phys;
156a912e453SPeter Wemm 		int	ifru_media;
157df8bae1dSRodney W. Grimes 		caddr_t	ifru_data;
158df8bae1dSRodney W. Grimes 	} ifr_ifru;
159df8bae1dSRodney W. Grimes #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
160df8bae1dSRodney W. Grimes #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
161df8bae1dSRodney W. Grimes #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
162df8bae1dSRodney W. Grimes #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
163df8bae1dSRodney W. Grimes #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
164a7028af7SDavid Greenman #define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
165511cdd16SDavid Greenman #define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
166a912e453SPeter Wemm #define ifr_media	ifr_ifru.ifru_media	/* physical media */
167df8bae1dSRodney W. Grimes #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
168df8bae1dSRodney W. Grimes };
169df8bae1dSRodney W. Grimes 
170906f09bcSGarrett Wollman #define	_SIZEOF_ADDR_IFREQ(ifr) \
171906f09bcSGarrett Wollman 	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
172906f09bcSGarrett Wollman 	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
173906f09bcSGarrett Wollman 	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
174906f09bcSGarrett Wollman 
175df8bae1dSRodney W. Grimes struct ifaliasreq {
176df8bae1dSRodney W. Grimes 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
177df8bae1dSRodney W. Grimes 	struct	sockaddr ifra_addr;
178df8bae1dSRodney W. Grimes 	struct	sockaddr ifra_broadaddr;
179df8bae1dSRodney W. Grimes 	struct	sockaddr ifra_mask;
180df8bae1dSRodney W. Grimes };
181df8bae1dSRodney W. Grimes 
182a912e453SPeter Wemm struct ifmediareq {
183a912e453SPeter Wemm 	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
184a912e453SPeter Wemm 	int	ifm_current;		/* current media options */
185a912e453SPeter Wemm 	int	ifm_mask;		/* don't care mask */
186a912e453SPeter Wemm 	int	ifm_status;		/* media status */
187a912e453SPeter Wemm 	int	ifm_active;		/* active options */
188a912e453SPeter Wemm 	int	ifm_count;		/* # entries in ifm_ulist array */
189a912e453SPeter Wemm 	int	*ifm_ulist;		/* media words */
190a912e453SPeter Wemm };
191df8bae1dSRodney W. Grimes /*
192df8bae1dSRodney W. Grimes  * Structure used in SIOCGIFCONF request.
193df8bae1dSRodney W. Grimes  * Used to retrieve interface configuration
194df8bae1dSRodney W. Grimes  * for machine (useful for programs which
195df8bae1dSRodney W. Grimes  * must know all networks accessible).
196df8bae1dSRodney W. Grimes  */
197df8bae1dSRodney W. Grimes struct	ifconf {
198df8bae1dSRodney W. Grimes 	int	ifc_len;		/* size of associated buffer */
199df8bae1dSRodney W. Grimes 	union {
200df8bae1dSRodney W. Grimes 		caddr_t	ifcu_buf;
201df8bae1dSRodney W. Grimes 		struct	ifreq *ifcu_req;
202df8bae1dSRodney W. Grimes 	} ifc_ifcu;
203df8bae1dSRodney W. Grimes #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
204df8bae1dSRodney W. Grimes #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
205df8bae1dSRodney W. Grimes };
206df8bae1dSRodney W. Grimes 
207a1c995b6SPoul-Henning Kamp #ifdef KERNEL
208a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE
209a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_IFADDR);
210a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_IFMADDR);
211a1c995b6SPoul-Henning Kamp #endif
212a1c995b6SPoul-Henning Kamp #endif
213a1c995b6SPoul-Henning Kamp 
21419ff91c6SGarrett Wollman /* XXX - this should go away soon */
215df8bae1dSRodney W. Grimes #ifdef KERNEL
21619ff91c6SGarrett Wollman #include <net/if_var.h>
217df8bae1dSRodney W. Grimes #endif
218cea1da3bSPaul Richards 
219df708ff1SBruce Evans #endif /* !_NET_IF_H_ */
220