xref: /freebsd/sys/net/if_var.h (revision 90d9802f)
119ff91c6SGarrett Wollman /*
219ff91c6SGarrett Wollman  * Copyright (c) 1982, 1986, 1989, 1993
319ff91c6SGarrett Wollman  *	The Regents of the University of California.  All rights reserved.
419ff91c6SGarrett Wollman  *
519ff91c6SGarrett Wollman  * Redistribution and use in source and binary forms, with or without
619ff91c6SGarrett Wollman  * modification, are permitted provided that the following conditions
719ff91c6SGarrett Wollman  * are met:
819ff91c6SGarrett Wollman  * 1. Redistributions of source code must retain the above copyright
919ff91c6SGarrett Wollman  *    notice, this list of conditions and the following disclaimer.
1019ff91c6SGarrett Wollman  * 2. Redistributions in binary form must reproduce the above copyright
1119ff91c6SGarrett Wollman  *    notice, this list of conditions and the following disclaimer in the
1219ff91c6SGarrett Wollman  *    documentation and/or other materials provided with the distribution.
1319ff91c6SGarrett Wollman  * 3. All advertising materials mentioning features or use of this software
1419ff91c6SGarrett Wollman  *    must display the following acknowledgement:
1519ff91c6SGarrett Wollman  *	This product includes software developed by the University of
1619ff91c6SGarrett Wollman  *	California, Berkeley and its contributors.
1719ff91c6SGarrett Wollman  * 4. Neither the name of the University nor the names of its contributors
1819ff91c6SGarrett Wollman  *    may be used to endorse or promote products derived from this software
1919ff91c6SGarrett Wollman  *    without specific prior written permission.
2019ff91c6SGarrett Wollman  *
2119ff91c6SGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2219ff91c6SGarrett Wollman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2319ff91c6SGarrett Wollman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2419ff91c6SGarrett Wollman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2519ff91c6SGarrett Wollman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2619ff91c6SGarrett Wollman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2719ff91c6SGarrett Wollman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2819ff91c6SGarrett Wollman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2919ff91c6SGarrett Wollman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3019ff91c6SGarrett Wollman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3119ff91c6SGarrett Wollman  * SUCH DAMAGE.
3219ff91c6SGarrett Wollman  *
3319ff91c6SGarrett Wollman  *	From: @(#)if.h	8.1 (Berkeley) 6/10/93
34c3aac50fSPeter Wemm  * $FreeBSD$
3519ff91c6SGarrett Wollman  */
3619ff91c6SGarrett Wollman 
3719ff91c6SGarrett Wollman #ifndef	_NET_IF_VAR_H_
3819ff91c6SGarrett Wollman #define	_NET_IF_VAR_H_
3919ff91c6SGarrett Wollman 
4019ff91c6SGarrett Wollman /*
4119ff91c6SGarrett Wollman  * Structures defining a network interface, providing a packet
4219ff91c6SGarrett Wollman  * transport mechanism (ala level 0 of the PUP protocols).
4319ff91c6SGarrett Wollman  *
4419ff91c6SGarrett Wollman  * Each interface accepts output datagrams of a specified maximum
4519ff91c6SGarrett Wollman  * length, and provides higher level routines with input datagrams
4619ff91c6SGarrett Wollman  * received from its medium.
4719ff91c6SGarrett Wollman  *
4819ff91c6SGarrett Wollman  * Output occurs when the routine if_output is called, with three parameters:
4919ff91c6SGarrett Wollman  *	(*ifp->if_output)(ifp, m, dst, rt)
5019ff91c6SGarrett Wollman  * Here m is the mbuf chain to be sent and dst is the destination address.
5119ff91c6SGarrett Wollman  * The output routine encapsulates the supplied datagram if necessary,
5219ff91c6SGarrett Wollman  * and then transmits it on its medium.
5319ff91c6SGarrett Wollman  *
5419ff91c6SGarrett Wollman  * On input, each interface unwraps the data received by it, and either
5519ff91c6SGarrett Wollman  * places it on the input queue of a internetwork datagram routine
5619ff91c6SGarrett Wollman  * and posts the associated software interrupt, or passes the datagram to a raw
5719ff91c6SGarrett Wollman  * packet input routine.
5819ff91c6SGarrett Wollman  *
5919ff91c6SGarrett Wollman  * Routines exist for locating interfaces by their addresses
6019ff91c6SGarrett Wollman  * or for locating a interface on a certain network, as well as more general
6119ff91c6SGarrett Wollman  * routing and gateway routines maintaining information used to locate
6219ff91c6SGarrett Wollman  * interfaces.  These routines live in the files if.c and route.c
6319ff91c6SGarrett Wollman  */
6419ff91c6SGarrett Wollman 
6519ff91c6SGarrett Wollman #ifdef __STDC__
6619ff91c6SGarrett Wollman /*
6719ff91c6SGarrett Wollman  * Forward structure declarations for function prototypes [sic].
6819ff91c6SGarrett Wollman  */
6919ff91c6SGarrett Wollman struct	mbuf;
7019ff91c6SGarrett Wollman struct	proc;
7119ff91c6SGarrett Wollman struct	rtentry;
7219ff91c6SGarrett Wollman struct	socket;
7319ff91c6SGarrett Wollman struct	ether_header;
7419ff91c6SGarrett Wollman #endif
7519ff91c6SGarrett Wollman 
7619ff91c6SGarrett Wollman #include <sys/queue.h>		/* get TAILQ macros */
7719ff91c6SGarrett Wollman 
789ba20c31SJonathan Lemon #ifdef _KERNEL
79df5e1987SJonathan Lemon #include <sys/mbuf.h>
809ba20c31SJonathan Lemon #endif /* _KERNEL */
819ba20c31SJonathan Lemon #include <sys/mutex.h>
82df5e1987SJonathan Lemon 
83e3975643SJake Burkholder TAILQ_HEAD(ifnethead, ifnet);	/* we use TAILQs so that the order of */
84e3975643SJake Burkholder TAILQ_HEAD(ifaddrhead, ifaddr);	/* instantiation is preserved in the list */
85e3975643SJake Burkholder TAILQ_HEAD(ifprefixhead, ifprefix);
86e3975643SJake Burkholder LIST_HEAD(ifmultihead, ifmultiaddr);
8719ff91c6SGarrett Wollman 
8819ff91c6SGarrett Wollman /*
8919ff91c6SGarrett Wollman  * Structure defining a queue for a network interface.
9019ff91c6SGarrett Wollman  */
9119ff91c6SGarrett Wollman struct	ifqueue {
9219ff91c6SGarrett Wollman 	struct	mbuf *ifq_head;
9319ff91c6SGarrett Wollman 	struct	mbuf *ifq_tail;
9419ff91c6SGarrett Wollman 	int	ifq_len;
9519ff91c6SGarrett Wollman 	int	ifq_maxlen;
9619ff91c6SGarrett Wollman 	int	ifq_drops;
97df5e1987SJonathan Lemon 	struct	mtx ifq_mtx;
9819ff91c6SGarrett Wollman };
9919ff91c6SGarrett Wollman 
10019ff91c6SGarrett Wollman /*
10119ff91c6SGarrett Wollman  * Structure defining a network interface.
10219ff91c6SGarrett Wollman  *
10319ff91c6SGarrett Wollman  * (Would like to call this struct ``if'', but C isn't PL/1.)
10419ff91c6SGarrett Wollman  */
10519ff91c6SGarrett Wollman struct ifnet {
10619ff91c6SGarrett Wollman 	void	*if_softc;		/* pointer to driver state */
10719ff91c6SGarrett Wollman 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
108e3975643SJake Burkholder 	TAILQ_ENTRY(ifnet) if_link; 	/* all struct ifnets are chained */
10919ff91c6SGarrett Wollman 	struct	ifaddrhead if_addrhead;	/* linked list of addresses per if */
11019ff91c6SGarrett Wollman         int	if_pcount;		/* number of promiscuous listeners */
11119ff91c6SGarrett Wollman 	struct	bpf_if *if_bpf;		/* packet filter structure */
11219ff91c6SGarrett Wollman 	u_short	if_index;		/* numeric abbreviation for this if  */
11319ff91c6SGarrett Wollman 	short	if_unit;		/* sub-unit for lower level driver */
11419ff91c6SGarrett Wollman 	short	if_timer;		/* time 'til if_watchdog called */
11519ff91c6SGarrett Wollman 	short	if_flags;		/* up/down, broadcast, etc. */
116df5e1987SJonathan Lemon 	int	if_mpsafe;		/* XXX TEMPORARY */
11719ff91c6SGarrett Wollman 	int	if_ipending;		/* interrupts pending */
11819ff91c6SGarrett Wollman 	void	*if_linkmib;		/* link-type-specific MIB data */
11919ff91c6SGarrett Wollman 	size_t	if_linkmiblen;		/* length of above data */
12019ff91c6SGarrett Wollman 	struct	if_data if_data;
1211158dfb7SGarrett Wollman 	struct	ifmultihead if_multiaddrs; /* multicast addresses configured */
1221158dfb7SGarrett Wollman 	int	if_amcount;		/* number of all-multicast requests */
12319ff91c6SGarrett Wollman /* procedure handles */
12419ff91c6SGarrett Wollman 	int	(*if_output)		/* output routine (enqueue) */
12519ff91c6SGarrett Wollman 		__P((struct ifnet *, struct mbuf *, struct sockaddr *,
12619ff91c6SGarrett Wollman 		     struct rtentry *));
12719ff91c6SGarrett Wollman 	void	(*if_start)		/* initiate output routine */
12819ff91c6SGarrett Wollman 		__P((struct ifnet *));
12919ff91c6SGarrett Wollman 	int	(*if_done)		/* output complete routine */
13019ff91c6SGarrett Wollman 		__P((struct ifnet *));	/* (XXX not used; fake prototype) */
13119ff91c6SGarrett Wollman 	int	(*if_ioctl)		/* ioctl routine */
132ecbb00a2SDoug Rabson 		__P((struct ifnet *, u_long, caddr_t));
13319ff91c6SGarrett Wollman 	void	(*if_watchdog)		/* timer routine */
13419ff91c6SGarrett Wollman 		__P((struct ifnet *));
13519ff91c6SGarrett Wollman 	int	(*if_poll_recv)		/* polled receive routine */
13619ff91c6SGarrett Wollman 		__P((struct ifnet *, int *));
13719ff91c6SGarrett Wollman 	int	(*if_poll_xmit)		/* polled transmit routine */
13819ff91c6SGarrett Wollman 		__P((struct ifnet *, int *));
13919ff91c6SGarrett Wollman 	void	(*if_poll_intren)	/* polled interrupt reenable routine */
14019ff91c6SGarrett Wollman 		__P((struct ifnet *));
14119ff91c6SGarrett Wollman 	void	(*if_poll_slowinput)	/* input routine for slow devices */
14219ff91c6SGarrett Wollman 		__P((struct ifnet *, struct mbuf *));
14319ff91c6SGarrett Wollman 	void	(*if_init)		/* Init routine */
14419ff91c6SGarrett Wollman 		__P((void *));
1451158dfb7SGarrett Wollman 	int	(*if_resolvemulti)	/* validate/resolve multicast */
1461158dfb7SGarrett Wollman 		__P((struct ifnet *, struct sockaddr **, struct sockaddr *));
14719ff91c6SGarrett Wollman 	struct	ifqueue if_snd;		/* output queue */
14819ff91c6SGarrett Wollman 	struct	ifqueue *if_poll_slowq;	/* input queue for slow devices */
14976429de4SYoshinobu Inoue 	struct	ifprefixhead if_prefixhead; /* list of prefixes per if */
15019ff91c6SGarrett Wollman };
151df5e1987SJonathan Lemon 
15219ff91c6SGarrett Wollman typedef void if_init_f_t __P((void *));
15319ff91c6SGarrett Wollman 
15419ff91c6SGarrett Wollman #define	if_mtu		if_data.ifi_mtu
15519ff91c6SGarrett Wollman #define	if_type		if_data.ifi_type
15619ff91c6SGarrett Wollman #define if_physical	if_data.ifi_physical
15719ff91c6SGarrett Wollman #define	if_addrlen	if_data.ifi_addrlen
15819ff91c6SGarrett Wollman #define	if_hdrlen	if_data.ifi_hdrlen
15919ff91c6SGarrett Wollman #define	if_metric	if_data.ifi_metric
16019ff91c6SGarrett Wollman #define	if_baudrate	if_data.ifi_baudrate
161db4f9cc7SJonathan Lemon #define	if_hwassist	if_data.ifi_hwassist
16219ff91c6SGarrett Wollman #define	if_ipackets	if_data.ifi_ipackets
16319ff91c6SGarrett Wollman #define	if_ierrors	if_data.ifi_ierrors
16419ff91c6SGarrett Wollman #define	if_opackets	if_data.ifi_opackets
16519ff91c6SGarrett Wollman #define	if_oerrors	if_data.ifi_oerrors
16619ff91c6SGarrett Wollman #define	if_collisions	if_data.ifi_collisions
16719ff91c6SGarrett Wollman #define	if_ibytes	if_data.ifi_ibytes
16819ff91c6SGarrett Wollman #define	if_obytes	if_data.ifi_obytes
16919ff91c6SGarrett Wollman #define	if_imcasts	if_data.ifi_imcasts
17019ff91c6SGarrett Wollman #define	if_omcasts	if_data.ifi_omcasts
17119ff91c6SGarrett Wollman #define	if_iqdrops	if_data.ifi_iqdrops
17219ff91c6SGarrett Wollman #define	if_noproto	if_data.ifi_noproto
17319ff91c6SGarrett Wollman #define	if_lastchange	if_data.ifi_lastchange
17419ff91c6SGarrett Wollman #define if_recvquota	if_data.ifi_recvquota
17519ff91c6SGarrett Wollman #define	if_xmitquota	if_data.ifi_xmitquota
17619ff91c6SGarrett Wollman #define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)
17719ff91c6SGarrett Wollman 
17882cd038dSYoshinobu Inoue /* for compatibility with other BSDs */
17982cd038dSYoshinobu Inoue #define	if_addrlist	if_addrhead
18082cd038dSYoshinobu Inoue #define	if_list		if_link
18182cd038dSYoshinobu Inoue 
18219ff91c6SGarrett Wollman /*
18319ff91c6SGarrett Wollman  * Bit values in if_ipending
18419ff91c6SGarrett Wollman  */
18519ff91c6SGarrett Wollman #define	IFI_RECV	1	/* I want to receive */
18619ff91c6SGarrett Wollman #define	IFI_XMIT	2	/* I want to transmit */
18719ff91c6SGarrett Wollman 
18819ff91c6SGarrett Wollman /*
18919ff91c6SGarrett Wollman  * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
19019ff91c6SGarrett Wollman  * are queues of messages stored on ifqueue structures
19119ff91c6SGarrett Wollman  * (defined above).  Entries are added to and deleted from these structures
19219ff91c6SGarrett Wollman  * by these macros, which should be called with ipl raised to splimp().
19319ff91c6SGarrett Wollman  */
194df5e1987SJonathan Lemon #define IF_LOCK(ifq)		mtx_enter(&(ifq)->ifq_mtx, MTX_DEF)
195df5e1987SJonathan Lemon #define IF_UNLOCK(ifq)		mtx_exit(&(ifq)->ifq_mtx, MTX_DEF)
196df5e1987SJonathan Lemon #define	_IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
197df5e1987SJonathan Lemon #define	_IF_DROP(ifq)		((ifq)->ifq_drops++)
198df5e1987SJonathan Lemon #define	_IF_QLEN(ifq)		((ifq)->ifq_len)
199df5e1987SJonathan Lemon 
200df5e1987SJonathan Lemon #define	_IF_ENQUEUE(ifq, m) do { 				\
201df5e1987SJonathan Lemon 	(m)->m_nextpkt = NULL;					\
202df5e1987SJonathan Lemon 	if ((ifq)->ifq_tail == NULL) 				\
20319ff91c6SGarrett Wollman 		(ifq)->ifq_head = m; 				\
20419ff91c6SGarrett Wollman 	else 							\
20519ff91c6SGarrett Wollman 		(ifq)->ifq_tail->m_nextpkt = m; 		\
20619ff91c6SGarrett Wollman 	(ifq)->ifq_tail = m; 					\
20719ff91c6SGarrett Wollman 	(ifq)->ifq_len++; 					\
208df5e1987SJonathan Lemon } while (0)
209df5e1987SJonathan Lemon 
210df5e1987SJonathan Lemon #define IF_ENQUEUE(ifq, m) do {					\
211df5e1987SJonathan Lemon 	IF_LOCK(ifq); 						\
212df5e1987SJonathan Lemon 	_IF_ENQUEUE(ifq, m); 					\
213df5e1987SJonathan Lemon 	IF_UNLOCK(ifq); 					\
214df5e1987SJonathan Lemon } while (0)
215df5e1987SJonathan Lemon 
216df5e1987SJonathan Lemon #define	_IF_PREPEND(ifq, m) do {				\
21719ff91c6SGarrett Wollman 	(m)->m_nextpkt = (ifq)->ifq_head; 			\
218df5e1987SJonathan Lemon 	if ((ifq)->ifq_tail == NULL) 				\
21919ff91c6SGarrett Wollman 		(ifq)->ifq_tail = (m); 				\
22019ff91c6SGarrett Wollman 	(ifq)->ifq_head = (m); 					\
22119ff91c6SGarrett Wollman 	(ifq)->ifq_len++; 					\
222df5e1987SJonathan Lemon } while (0)
223df5e1987SJonathan Lemon 
224df5e1987SJonathan Lemon #define IF_PREPEND(ifq, m) do {		 			\
225df5e1987SJonathan Lemon 	IF_LOCK(ifq); 						\
226df5e1987SJonathan Lemon 	_IF_PREPEND(ifq, m); 					\
227df5e1987SJonathan Lemon 	IF_UNLOCK(ifq); 					\
228df5e1987SJonathan Lemon } while (0)
229df5e1987SJonathan Lemon 
230df5e1987SJonathan Lemon #define	_IF_DEQUEUE(ifq, m) do { 				\
23119ff91c6SGarrett Wollman 	(m) = (ifq)->ifq_head; 					\
23219ff91c6SGarrett Wollman 	if (m) { 						\
23319ff91c6SGarrett Wollman 		if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) 	\
234df5e1987SJonathan Lemon 			(ifq)->ifq_tail = NULL; 		\
235df5e1987SJonathan Lemon 		(m)->m_nextpkt = NULL; 				\
23619ff91c6SGarrett Wollman 		(ifq)->ifq_len--; 				\
23719ff91c6SGarrett Wollman 	} 							\
238df5e1987SJonathan Lemon } while (0)
239df5e1987SJonathan Lemon 
240df5e1987SJonathan Lemon #define IF_DEQUEUE(ifq, m) do { 				\
241df5e1987SJonathan Lemon 	IF_LOCK(ifq); 						\
242df5e1987SJonathan Lemon 	_IF_DEQUEUE(ifq, m); 					\
243df5e1987SJonathan Lemon 	IF_UNLOCK(ifq); 					\
244df5e1987SJonathan Lemon } while (0)
245df5e1987SJonathan Lemon 
246df5e1987SJonathan Lemon #define IF_DRAIN(ifq) do { 					\
247df5e1987SJonathan Lemon 	struct mbuf *m; 					\
248df5e1987SJonathan Lemon 	IF_LOCK(ifq); 						\
249df5e1987SJonathan Lemon 	for (;;) { 						\
250df5e1987SJonathan Lemon 		_IF_DEQUEUE(ifq, m); 				\
251df5e1987SJonathan Lemon 		if (m == NULL) 					\
252df5e1987SJonathan Lemon 			break; 					\
253df5e1987SJonathan Lemon 		m_freem(m); 					\
254df5e1987SJonathan Lemon 	} 							\
255df5e1987SJonathan Lemon 	IF_UNLOCK(ifq); 					\
256df5e1987SJonathan Lemon } while (0)
25719ff91c6SGarrett Wollman 
258664a31e4SPeter Wemm #ifdef _KERNEL
259df5e1987SJonathan Lemon #define	IF_HANDOFF(ifq, m, ifp)			if_handoff(ifq, m, ifp, 0)
260df5e1987SJonathan Lemon #define	IF_HANDOFF_ADJ(ifq, m, ifp, adj)	if_handoff(ifq, m, ifp, adj)
26119ff91c6SGarrett Wollman 
262c1087c13SBruce Evans static __inline int
263df5e1987SJonathan Lemon if_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust)
26419ff91c6SGarrett Wollman {
265df5e1987SJonathan Lemon 	int active = 0;
266df5e1987SJonathan Lemon 
267df5e1987SJonathan Lemon 	IF_LOCK(ifq);
268df5e1987SJonathan Lemon 	if (_IF_QFULL(ifq)) {
269df5e1987SJonathan Lemon 		_IF_DROP(ifq);
270df5e1987SJonathan Lemon 		IF_UNLOCK(ifq);
271df5e1987SJonathan Lemon 		m_freem(m);
272df5e1987SJonathan Lemon 		return (0);
27319ff91c6SGarrett Wollman 	}
274df5e1987SJonathan Lemon 	if (ifp != NULL) {
275df5e1987SJonathan Lemon 		ifp->if_obytes += m->m_pkthdr.len + adjust;
276df5e1987SJonathan Lemon 		if (m->m_flags & M_MCAST)
277df5e1987SJonathan Lemon 			ifp->if_omcasts++;
278df5e1987SJonathan Lemon 		active = ifp->if_flags & IFF_OACTIVE;
279df5e1987SJonathan Lemon 	}
280df5e1987SJonathan Lemon 	_IF_ENQUEUE(ifq, m);
281df5e1987SJonathan Lemon 	IF_UNLOCK(ifq);
282df5e1987SJonathan Lemon 	if (ifp != NULL && !active) {
283df5e1987SJonathan Lemon 		if (ifp->if_mpsafe) {
284df5e1987SJonathan Lemon 			DROP_GIANT_NOSWITCH();
285df5e1987SJonathan Lemon 			(*ifp->if_start)(ifp);
286df5e1987SJonathan Lemon 			PICKUP_GIANT();
287df5e1987SJonathan Lemon 		} else {
288df5e1987SJonathan Lemon 			(*ifp->if_start)(ifp);
289df5e1987SJonathan Lemon 		}
290df5e1987SJonathan Lemon 	}
291df5e1987SJonathan Lemon 	return (1);
292df5e1987SJonathan Lemon }
293aab3beeeSBrian Somers 
294aab3beeeSBrian Somers /*
295aab3beeeSBrian Somers  * 72 was chosen below because it is the size of a TCP/IP
296aab3beeeSBrian Somers  * header (40) + the minimum mss (32).
297aab3beeeSBrian Somers  */
298aab3beeeSBrian Somers #define	IF_MINMTU	72
299aab3beeeSBrian Somers #define	IF_MAXMTU	65535
300aab3beeeSBrian Somers 
301664a31e4SPeter Wemm #endif /* _KERNEL */
30219ff91c6SGarrett Wollman 
30319ff91c6SGarrett Wollman /*
30419ff91c6SGarrett Wollman  * The ifaddr structure contains information about one address
30519ff91c6SGarrett Wollman  * of an interface.  They are maintained by the different address families,
30619ff91c6SGarrett Wollman  * are allocated and attached when an address is set, and are linked
30719ff91c6SGarrett Wollman  * together so all addresses for an interface can be located.
30819ff91c6SGarrett Wollman  */
30919ff91c6SGarrett Wollman struct ifaddr {
31019ff91c6SGarrett Wollman 	struct	sockaddr *ifa_addr;	/* address of interface */
31119ff91c6SGarrett Wollman 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
31219ff91c6SGarrett Wollman #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
31319ff91c6SGarrett Wollman 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
3145da9f8faSJosef Karthauser 	struct	if_data if_data;	/* not all members are meaningful */
31519ff91c6SGarrett Wollman 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
316e3975643SJake Burkholder 	TAILQ_ENTRY(ifaddr) ifa_link;	/* queue macro glue */
31719ff91c6SGarrett Wollman 	void	(*ifa_rtrequest)	/* check or clean routes (+ or -)'d */
31819ff91c6SGarrett Wollman 		__P((int, struct rtentry *, struct sockaddr *));
31919ff91c6SGarrett Wollman 	u_short	ifa_flags;		/* mostly rt_flags for cloning */
320e3c1388bSPierre Beyssac 	u_int	ifa_refcnt;		/* references to this structure */
32119ff91c6SGarrett Wollman 	int	ifa_metric;		/* cost of going out this interface */
32219ff91c6SGarrett Wollman #ifdef notdef
32319ff91c6SGarrett Wollman 	struct	rtentry *ifa_rt;	/* XXXX for ROUTETOIF ????? */
32419ff91c6SGarrett Wollman #endif
3257ed8f465SJulian Elischer 	int (*ifa_claim_addr)		/* check if an addr goes to this if */
3267ed8f465SJulian Elischer 		__P((struct ifaddr *, struct sockaddr *));
3277ed8f465SJulian Elischer 
32819ff91c6SGarrett Wollman };
32919ff91c6SGarrett Wollman #define	IFA_ROUTE	RTF_UP		/* route installed */
33019ff91c6SGarrett Wollman 
33182cd038dSYoshinobu Inoue /* for compatibility with other BSDs */
33282cd038dSYoshinobu Inoue #define	ifa_list	ifa_link
33382cd038dSYoshinobu Inoue 
3341158dfb7SGarrett Wollman /*
33576429de4SYoshinobu Inoue  * The prefix structure contains information about one prefix
33676429de4SYoshinobu Inoue  * of an interface.  They are maintained by the different address families,
33776429de4SYoshinobu Inoue  * are allocated and attached when an prefix or an address is set,
33882cd038dSYoshinobu Inoue  * and are linked together so all prefixes for an interface can be located.
33976429de4SYoshinobu Inoue  */
34076429de4SYoshinobu Inoue struct ifprefix {
34176429de4SYoshinobu Inoue 	struct	sockaddr *ifpr_prefix;	/* prefix of interface */
34276429de4SYoshinobu Inoue 	struct	ifnet *ifpr_ifp;	/* back-pointer to interface */
343e3975643SJake Burkholder 	TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
34476429de4SYoshinobu Inoue 	u_char	ifpr_plen;		/* prefix length in bits */
34576429de4SYoshinobu Inoue 	u_char	ifpr_type;		/* protocol dependent prefix type */
34676429de4SYoshinobu Inoue };
34776429de4SYoshinobu Inoue 
34876429de4SYoshinobu Inoue /*
3491158dfb7SGarrett Wollman  * Multicast address structure.  This is analogous to the ifaddr
3501158dfb7SGarrett Wollman  * structure except that it keeps track of multicast addresses.
3511158dfb7SGarrett Wollman  * Also, the reference count here is a count of requests for this
3521158dfb7SGarrett Wollman  * address, not a count of pointers to this structure.
3531158dfb7SGarrett Wollman  */
3541158dfb7SGarrett Wollman struct ifmultiaddr {
355e3975643SJake Burkholder 	LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
356373f88edSGarrett Wollman 	struct	sockaddr *ifma_addr; 	/* address this membership is for */
357373f88edSGarrett Wollman 	struct	sockaddr *ifma_lladdr;	/* link-layer translation, if any */
358373f88edSGarrett Wollman 	struct	ifnet *ifma_ifp;	/* back-pointer to interface */
359373f88edSGarrett Wollman 	u_int	ifma_refcount;		/* reference count */
360373f88edSGarrett Wollman 	void	*ifma_protospec;	/* protocol-specific state, if any */
3611158dfb7SGarrett Wollman };
3621158dfb7SGarrett Wollman 
363664a31e4SPeter Wemm #ifdef _KERNEL
36419ff91c6SGarrett Wollman #define	IFAFREE(ifa) \
365dfd5dee1SPeter Wemm 	do { \
36619ff91c6SGarrett Wollman 		if ((ifa)->ifa_refcnt <= 0) \
36719ff91c6SGarrett Wollman 			ifafree(ifa); \
36819ff91c6SGarrett Wollman 		else \
369dfd5dee1SPeter Wemm 			(ifa)->ifa_refcnt--; \
370dfd5dee1SPeter Wemm 	} while (0)
37119ff91c6SGarrett Wollman 
37219ff91c6SGarrett Wollman extern	struct ifnethead ifnet;
37376429de4SYoshinobu Inoue extern struct	ifnet	**ifindex2ifnet;
37419ff91c6SGarrett Wollman extern	int ifqmaxlen;
37590d9802fSPeter Wemm extern	struct ifnet *loif;	/* first loopback interface */
37619ff91c6SGarrett Wollman extern	int if_index;
37719ff91c6SGarrett Wollman extern	struct ifaddr **ifnet_addrs;
37819ff91c6SGarrett Wollman 
37921b8ebd9SArchie Cobbs void	ether_ifattach __P((struct ifnet *, int));
38021b8ebd9SArchie Cobbs void	ether_ifdetach __P((struct ifnet *, int));
38119ff91c6SGarrett Wollman void	ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
382e1e1452dSArchie Cobbs void	ether_demux __P((struct ifnet *, struct ether_header *, struct mbuf *));
38319ff91c6SGarrett Wollman int	ether_output __P((struct ifnet *,
38419ff91c6SGarrett Wollman 	   struct mbuf *, struct sockaddr *, struct rtentry *));
385e1e1452dSArchie Cobbs int	ether_output_frame __P((struct ifnet *, struct mbuf *));
38619ff91c6SGarrett Wollman int	ether_ioctl __P((struct ifnet *, int, caddr_t));
38719ff91c6SGarrett Wollman 
388373f88edSGarrett Wollman int	if_addmulti __P((struct ifnet *, struct sockaddr *,
389373f88edSGarrett Wollman 			 struct ifmultiaddr **));
3901158dfb7SGarrett Wollman int	if_allmulti __P((struct ifnet *, int));
39119ff91c6SGarrett Wollman void	if_attach __P((struct ifnet *));
3921158dfb7SGarrett Wollman int	if_delmulti __P((struct ifnet *, struct sockaddr *));
3936182fdbdSPeter Wemm void	if_detach __P((struct ifnet *));
39419ff91c6SGarrett Wollman void	if_down __P((struct ifnet *));
395e8c2601dSPoul-Henning Kamp void	if_route __P((struct ifnet *, int flag, int fam));
39666ce51ceSArchie Cobbs int	if_setlladdr __P((struct ifnet *, const u_char *, int));
397e8c2601dSPoul-Henning Kamp void	if_unroute __P((struct ifnet *, int flag, int fam));
39819ff91c6SGarrett Wollman void	if_up __P((struct ifnet *));
39919ff91c6SGarrett Wollman /*void	ifinit __P((void));*/ /* declared in systm.h for main() */
400ecbb00a2SDoug Rabson int	ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
40119ff91c6SGarrett Wollman int	ifpromisc __P((struct ifnet *, int));
40219ff91c6SGarrett Wollman struct	ifnet *ifunit __P((char *));
40376429de4SYoshinobu Inoue struct	ifnet *if_withname __P((struct sockaddr *));
40419ff91c6SGarrett Wollman 
40519ff91c6SGarrett Wollman int	if_poll_recv_slow __P((struct ifnet *ifp, int *quotap));
40619ff91c6SGarrett Wollman void	if_poll_xmit_slow __P((struct ifnet *ifp, int *quotap));
40719ff91c6SGarrett Wollman void	if_poll_throttle __P((void));
40819ff91c6SGarrett Wollman void	if_poll_unthrottle __P((void *));
40919ff91c6SGarrett Wollman void	if_poll_init __P((void));
41019ff91c6SGarrett Wollman void	if_poll __P((void));
41119ff91c6SGarrett Wollman 
41219ff91c6SGarrett Wollman struct	ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
41319ff91c6SGarrett Wollman struct	ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
41419ff91c6SGarrett Wollman struct	ifaddr *ifa_ifwithnet __P((struct sockaddr *));
41519ff91c6SGarrett Wollman struct	ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
41619ff91c6SGarrett Wollman 					struct sockaddr *));
41719ff91c6SGarrett Wollman struct	ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
41819ff91c6SGarrett Wollman void	ifafree __P((struct ifaddr *));
41919ff91c6SGarrett Wollman 
420373f88edSGarrett Wollman struct	ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *,
421373f88edSGarrett Wollman 					    struct ifnet *));
42206a429a3SArchie Cobbs int	if_simloop __P((struct ifnet *ifp, struct mbuf *m, int af, int hlen));
423373f88edSGarrett Wollman 
424664a31e4SPeter Wemm #endif /* _KERNEL */
42519ff91c6SGarrett Wollman 
42619ff91c6SGarrett Wollman #endif /* !_NET_IF_VAR_H_ */
427