xref: /386bsd/usr/src/kernel/include/domain/if.h (revision dc8b130e)
1 /*
2  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	$Id$
34  */
35 
36 /*
37  * Structures defining a network interface, providing a packet
38  * transport mechanism (ala level 0 of the PUP protocols).
39  *
40  * Each interface accepts output datagrams of a specified maximum
41  * length, and provides higher level routines with input datagrams
42  * received from its medium.
43  *
44  * Output occurs when the routine if_output is called, with three parameters:
45  *	(*ifp->if_output)(ifp, m, dst)
46  * Here m is the mbuf chain to be sent and dst is the destination address.
47  * The output routine encapsulates the supplied datagram if necessary,
48  * and then transmits it on its medium.
49  *
50  * On input, each interface unwraps the data received by it, and either
51  * places it on the input queue of a internetwork datagram routine
52  * and posts the associated software interrupt, or passes the datagram to a raw
53  * packet input routine.
54  *
55  * Routines exist for locating interfaces by their addresses
56  * or for locating a interface on a certain network, as well as more general
57  * routing and gateway routines maintaining information used to locate
58  * interfaces.  These routines live in the files if.c and route.c
59  */
60 #ifdef KERNEL
61 #include "sys/time.h"
62 #else
63 #include <sys/time.h>
64 #endif
65 
66 /*
67  * Structure defining a queue for a network interface.
68  *
69  * (Would like to call this struct ``if'', but C isn't PL/1.)
70  */
71 
72 struct ifnet {
73 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
74 	short	if_unit;		/* sub-unit for lower level driver */
75 	u_short	if_mtu;			/* maximum transmission unit */
76 	short	if_flags;		/* up/down, broadcast, etc. */
77 	u_short	if_timer;		/* time 'til if_watchdog called */
78 	int	if_metric;		/* routing metric (external only) */
79 	struct	ifaddr *if_addrlist;	/* linked list of addresses per if */
80 	struct	ifqueue {
81 		struct	mbuf *ifq_head;
82 		struct	mbuf *ifq_tail;
83 		int	ifq_len;
84 		int	ifq_maxlen;
85 		int	ifq_drops;
86 	} if_snd;			/* output queue */
87 /* procedure handles */
88 	void	(*if_init)(int);	/* init routine */
89 	int	(*if_output)();		/* output routine (enqueue) */
90 	void	(*if_start)		/* initiate output routine */
91 		(struct ifnet *);
92 	int	(*if_done)();		/* output complete routine */
93 	int	(*if_ioctl)		/* ioctl routine */
94 		(struct ifnet *, int, caddr_t);
95 	void	(*if_reset)(int, int);	/* bus reset routine */
96 	void	(*if_watchdog)(int);	/* timer routine */
97 /* generic interface statistics */
98 	int	if_ipackets;		/* packets received on interface */
99 	int	if_ierrors;		/* input errors on interface */
100 	int	if_opackets;		/* packets sent on interface */
101 	int	if_oerrors;		/* output errors on interface */
102 	int	if_collisions;		/* collisions on csma interfaces */
103 /* end statistics */
104 	struct	ifnet *if_next;
105 	u_char	if_type;		/* ethernet, tokenring, etc */
106 	u_char	if_addrlen;		/* media address length */
107 	u_char	if_hdrlen;		/* media header length */
108 	u_char	if_index;		/* numeric abbreviation for this if  */
109 /* more statistics here to avoid recompiling netstat */
110 	struct	timeval if_lastchange;	/* last updated */
111 	int	if_ibytes;		/* total number of octets received */
112 	int	if_obytes;		/* total number of octets sent */
113 	int	if_imcasts;		/* packets received via multicast */
114 	int	if_omcasts;		/* packets sent via multicast */
115 	int	if_iqdrops;		/* dropped on input, this interface */
116 	int	if_noproto;		/* destined for unsupported protocol */
117 	int	if_baudrate;		/* linespeed */
118         int	if_pcount;		/* number of promiscuous listeners */
119 };
120 
121 #define	IFF_UP		0x1		/* interface is up */
122 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
123 #define	IFF_DEBUG	0x4		/* turn on debugging */
124 #define	IFF_LOOPBACK	0x8		/* is a loopback net */
125 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
126 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
127 #define	IFF_RUNNING	0x40		/* resources allocated */
128 #define	IFF_NOARP	0x80		/* no address resolution protocol */
129 /* next two not supported now, but reserved: */
130 #define	IFF_PROMISC	0x100		/* receive all packets */
131 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
132 #define	IFF_OACTIVE	0x400		/* transmission in progress */
133 #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
134 #define	IFF_LLC0	0x1000		/* interface driver control/status */
135 #define	IFF_LLC1	0x2000		/* interface driver control/status */
136 #define	IFF_LLC2	0x4000		/* interface driver control/status */
137 
138 /* flags set internally only: */
139 #define	IFF_CANTCHANGE \
140 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX)
141 
142 /*
143  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
144  * input routines have queues of messages stored on ifqueue structures
145  * (defined above).  Entries are added to and deleted from these structures
146  * by these macros, which should be called with ipl raised to splimp().
147  */
148 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
149 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
150 #define	IF_ENQUEUE(ifq, m) { \
151 	(m)->m_nextpkt = 0; \
152 	if ((ifq)->ifq_tail == 0) \
153 		(ifq)->ifq_head = m; \
154 	else \
155 		(ifq)->ifq_tail->m_nextpkt = m; \
156 	(ifq)->ifq_tail = m; \
157 	(ifq)->ifq_len++; \
158 }
159 #define	IF_PREPEND(ifq, m) { \
160 	(m)->m_nextpkt = (ifq)->ifq_head; \
161 	if ((ifq)->ifq_tail == 0) \
162 		(ifq)->ifq_tail = (m); \
163 	(ifq)->ifq_head = (m); \
164 	(ifq)->ifq_len++; \
165 }
166 #define	IF_DEQUEUE(ifq, m) { \
167 	(m) = (ifq)->ifq_head; \
168 	if (m) { \
169 		if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
170 			(ifq)->ifq_tail = 0; \
171 		(m)->m_nextpkt = 0; \
172 		(ifq)->ifq_len--; \
173 	} \
174 }
175 
176 #define	IFQ_MAXLEN	50
177 #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
178 
179 /*
180  * The ifaddr structure contains information about one address
181  * of an interface.  They are maintained by the different address families,
182  * are allocated and attached when an address is set, and are linked
183  * together so all addresses for an interface can be located.
184  */
185 struct ifaddr {
186 	struct	sockaddr *ifa_addr;	/* address of interface */
187 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
188 #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
189 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
190 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
191 	struct	ifaddr *ifa_next;	/* next address for interface */
192 	int	(*ifa_rtrequest)();	/* check or clean routes (+ or -)'d */
193 	struct 	rtentry *ifa_rt;	/* ??? for ROUTETOIF */
194 	u_short	ifa_flags;		/* mostly rt_flags for cloning */
195 	u_short	ifa_llinfolen;		/* extra to malloc for link info */
196 };
197 #define IFA_ROUTE	RTF_UP		/* route installed */
198 /*
199  * Interface request structure used for socket
200  * ioctl's.  All interface ioctl's must have parameter
201  * definitions which begin with ifr_name.  The
202  * remainder may be interface specific.
203  */
204 struct	ifreq {
205 #define	IFNAMSIZ	16
206 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
207 	union {
208 		struct	sockaddr ifru_addr;
209 		struct	sockaddr ifru_dstaddr;
210 		struct	sockaddr ifru_broadaddr;
211 		short	ifru_flags;
212 		int	ifru_metric;
213 		caddr_t	ifru_data;
214 	} ifr_ifru;
215 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
216 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
217 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
218 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
219 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
220 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
221 };
222 
223 struct ifaliasreq {
224 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
225 	struct	sockaddr ifra_addr;
226 	struct	sockaddr ifra_broadaddr;
227 	struct	sockaddr ifra_mask;
228 };
229 
230 /*
231  * Structure used in SIOCGIFCONF request.
232  * Used to retrieve interface configuration
233  * for machine (useful for programs which
234  * must know all networks accessible).
235  */
236 struct	ifconf {
237 	int	ifc_len;		/* size of associated buffer */
238 	union {
239 		caddr_t	ifcu_buf;
240 		struct	ifreq *ifcu_req;
241 	} ifc_ifcu;
242 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
243 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
244 };
245 
246 #include "if_arp.h"
247 #ifdef KERNEL
248 #ifdef nope
249 extern struct	ifqueue rawintrq;		/* raw packet input queue */
250 extern struct	ifnet *ifnet;
251 struct	ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
252 struct	ifaddr *ifa_ifwithdstaddr();
253 #endif
254 
255 /* interface symbols */
256 #define	__ISYM_VERSION__ "1"	/* XXX RCS major revision number of hdr file */
257 #include "isym.h"		/* this header has interface symbols */
258 
259 /* global variables used in core kernel and other modules */
260 __ISYM__(int, if_index,)	/* */
261 __ISYM__(struct	ifqueue, rawintrq,)		/* raw packet input queue */
262 __ISYM__(struct	ifnet *, ifnet,)
263 
264 /* functions used in modules */
265 __ISYM__(int, if_attach, (struct ifnet *))	/* XXX void */
266 __ISYM__(struct	ifaddr *, ifa_ifwithaddr, (struct sockaddr *))
267 __ISYM__(struct	ifaddr *, ifa_ifwithnet, (struct sockaddr *))
268 __ISYM__(struct	ifaddr *, ifa_ifwithdstaddr, (struct sockaddr *))
269 __ISYM__(int, ifioctl, (struct socket *so, int cmd, caddr_t data, struct proc *p))
270 
271 #undef __ISYM__
272 #undef __ISYM_ALIAS__
273 #undef __ISYM_VERSION__
274 
275 #endif KERNEL
276