xref: /freebsd/sys/netinet/in_var.h (revision ffa5b11ab5baf4cd1b1d6e7a8d8cd3fe618f530a)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1985, 1986, 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  *	@(#)in_var.h	8.1 (Berkeley) 6/10/93
34ffa5b11aSGarrett Wollman  * $Id: in_var.h,v 1.8 1995/03/16 18:14:53 bde Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37707f139eSPaul Richards #ifndef _NETINET_IN_VAR_H_
38707f139eSPaul Richards #define _NETINET_IN_VAR_H_
39707f139eSPaul Richards 
40ffa5b11aSGarrett Wollman #include <sys/queue.h>
41ffa5b11aSGarrett Wollman 
42df8bae1dSRodney W. Grimes /*
43df8bae1dSRodney W. Grimes  * Interface address, Internet version.  One of these structures
44df8bae1dSRodney W. Grimes  * is allocated for each interface with an Internet address.
45df8bae1dSRodney W. Grimes  * The ifaddr structure contains the protocol-independent part
46df8bae1dSRodney W. Grimes  * of the structure and is assumed to be first.
47df8bae1dSRodney W. Grimes  */
48df8bae1dSRodney W. Grimes struct in_ifaddr {
49df8bae1dSRodney W. Grimes 	struct	ifaddr ia_ifa;		/* protocol-independent info */
50df8bae1dSRodney W. Grimes #define	ia_ifp		ia_ifa.ifa_ifp
51df8bae1dSRodney W. Grimes #define ia_flags	ia_ifa.ifa_flags
52df8bae1dSRodney W. Grimes 					/* ia_{,sub}net{,mask} in host order */
53df8bae1dSRodney W. Grimes 	u_long	ia_net;			/* network number of interface */
54df8bae1dSRodney W. Grimes 	u_long	ia_netmask;		/* mask of net part */
55df8bae1dSRodney W. Grimes 	u_long	ia_subnet;		/* subnet number, including net */
56df8bae1dSRodney W. Grimes 	u_long	ia_subnetmask;		/* mask of subnet part */
57df8bae1dSRodney W. Grimes 	struct	in_addr ia_netbroadcast; /* to recognize net broadcasts */
58df8bae1dSRodney W. Grimes 	struct	in_ifaddr *ia_next;	/* next in list of internet addresses */
59df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_addr;	/* reserve space for interface name */
60df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
61df8bae1dSRodney W. Grimes #define	ia_broadaddr	ia_dstaddr
62df8bae1dSRodney W. Grimes 	struct	sockaddr_in ia_sockmask; /* reserve space for general netmask */
63ffa5b11aSGarrett Wollman 	LIST_HEAD(in_multihead, in_multi) ia_multiaddrs;
64ffa5b11aSGarrett Wollman 					/* list of multicast addresses */
65df8bae1dSRodney W. Grimes };
66df8bae1dSRodney W. Grimes 
67df8bae1dSRodney W. Grimes struct	in_aliasreq {
68df8bae1dSRodney W. Grimes 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
69df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_addr;
70df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_broadaddr;
71df8bae1dSRodney W. Grimes #define ifra_dstaddr ifra_broadaddr
72df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_mask;
73df8bae1dSRodney W. Grimes };
74df8bae1dSRodney W. Grimes /*
75df8bae1dSRodney W. Grimes  * Given a pointer to an in_ifaddr (ifaddr),
76df8bae1dSRodney W. Grimes  * return a pointer to the addr as a sockaddr_in.
77df8bae1dSRodney W. Grimes  */
78df8bae1dSRodney W. Grimes #define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
791bc8a809SSteven Wallace #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
80df8bae1dSRodney W. Grimes 
81df8bae1dSRodney W. Grimes #define IN_LNAOF(in, ifa) \
82df8bae1dSRodney W. Grimes 	((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
83df8bae1dSRodney W. Grimes 
84df8bae1dSRodney W. Grimes 
85df8bae1dSRodney W. Grimes #ifdef	KERNEL
86df8bae1dSRodney W. Grimes extern	struct	in_ifaddr *in_ifaddr;
87df8bae1dSRodney W. Grimes extern	struct	ifqueue	ipintrq;		/* ip packet input queue */
88b5e8ce9fSBruce Evans extern	struct	in_addr zeroin_addr;
89b5e8ce9fSBruce Evans extern	u_char	inetctlerrmap[];
90b5e8ce9fSBruce Evans extern	int rtq_reallyold;	/* XXX */
91b5e8ce9fSBruce Evans extern	int rtq_minreallyold;	/* XXX */
92b5e8ce9fSBruce Evans extern	int rtq_toomany;	/* XXX */
93df8bae1dSRodney W. Grimes 
94df8bae1dSRodney W. Grimes /*
95df8bae1dSRodney W. Grimes  * Macro for finding the interface (ifnet structure) corresponding to one
96df8bae1dSRodney W. Grimes  * of our IP addresses.
97df8bae1dSRodney W. Grimes  */
98df8bae1dSRodney W. Grimes #define INADDR_TO_IFP(addr, ifp) \
99df8bae1dSRodney W. Grimes 	/* struct in_addr addr; */ \
100df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
101df8bae1dSRodney W. Grimes { \
102df8bae1dSRodney W. Grimes 	register struct in_ifaddr *ia; \
103df8bae1dSRodney W. Grimes \
104df8bae1dSRodney W. Grimes 	for (ia = in_ifaddr; \
1051bc8a809SSteven Wallace 	    ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \
1061bc8a809SSteven Wallace 		IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \
107df8bae1dSRodney W. Grimes 	    ia = ia->ia_next) \
108df8bae1dSRodney W. Grimes 		 continue; \
109df8bae1dSRodney W. Grimes 	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
110df8bae1dSRodney W. Grimes }
111df8bae1dSRodney W. Grimes 
112df8bae1dSRodney W. Grimes /*
113df8bae1dSRodney W. Grimes  * Macro for finding the internet address structure (in_ifaddr) corresponding
114df8bae1dSRodney W. Grimes  * to a given interface (ifnet structure).
115df8bae1dSRodney W. Grimes  */
116df8bae1dSRodney W. Grimes #define IFP_TO_IA(ifp, ia) \
117df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
118df8bae1dSRodney W. Grimes 	/* struct in_ifaddr *ia; */ \
119df8bae1dSRodney W. Grimes { \
120df8bae1dSRodney W. Grimes 	for ((ia) = in_ifaddr; \
121df8bae1dSRodney W. Grimes 	    (ia) != NULL && (ia)->ia_ifp != (ifp); \
122df8bae1dSRodney W. Grimes 	    (ia) = (ia)->ia_next) \
123df8bae1dSRodney W. Grimes 		continue; \
124df8bae1dSRodney W. Grimes }
125df8bae1dSRodney W. Grimes #endif
126df8bae1dSRodney W. Grimes 
127df8bae1dSRodney W. Grimes /*
128f0068c4aSGarrett Wollman  * This information should be part of the ifnet structure but we don't wish
129f0068c4aSGarrett Wollman  * to change that - as it might break a number of things
130f0068c4aSGarrett Wollman  */
131f0068c4aSGarrett Wollman 
132f0068c4aSGarrett Wollman struct router_info {
133f0068c4aSGarrett Wollman 	struct ifnet *ifp;
134f0068c4aSGarrett Wollman 	int    type; /* type of router which is querier on this interface */
135f0068c4aSGarrett Wollman 	int    time; /* # of slow timeouts since last old query */
136f0068c4aSGarrett Wollman 	struct router_info *next;
137f0068c4aSGarrett Wollman };
138f0068c4aSGarrett Wollman 
139f0068c4aSGarrett Wollman /*
140df8bae1dSRodney W. Grimes  * Internet multicast address structure.  There is one of these for each IP
141df8bae1dSRodney W. Grimes  * multicast group to which this host belongs on a given network interface.
142df8bae1dSRodney W. Grimes  * They are kept in a linked list, rooted in the interface's in_ifaddr
143df8bae1dSRodney W. Grimes  * structure.
144df8bae1dSRodney W. Grimes  */
145df8bae1dSRodney W. Grimes struct in_multi {
146ffa5b11aSGarrett Wollman 	LIST_ENTRY(in_multi) inm_entry; /* list glue */
147df8bae1dSRodney W. Grimes 	struct	in_addr inm_addr;	/* IP multicast address */
148df8bae1dSRodney W. Grimes 	struct	ifnet *inm_ifp;		/* back pointer to ifnet */
149df8bae1dSRodney W. Grimes 	struct	in_ifaddr *inm_ia;	/* back pointer to in_ifaddr */
150df8bae1dSRodney W. Grimes 	u_int	inm_refcount;		/* no. membership claims by sockets */
151df8bae1dSRodney W. Grimes 	u_int	inm_timer;		/* IGMP membership report timer */
152f0068c4aSGarrett Wollman 	u_int	inm_state;		/*  state of the membership */
153f0068c4aSGarrett Wollman 	struct	router_info *inm_rti;	/* router info*/
154df8bae1dSRodney W. Grimes };
155df8bae1dSRodney W. Grimes 
156df8bae1dSRodney W. Grimes #ifdef KERNEL
157df8bae1dSRodney W. Grimes /*
158df8bae1dSRodney W. Grimes  * Structure used by macros below to remember position when stepping through
159df8bae1dSRodney W. Grimes  * all of the in_multi records.
160df8bae1dSRodney W. Grimes  */
161df8bae1dSRodney W. Grimes struct in_multistep {
162df8bae1dSRodney W. Grimes 	struct in_ifaddr *i_ia;
163df8bae1dSRodney W. Grimes 	struct in_multi *i_inm;
164df8bae1dSRodney W. Grimes };
165df8bae1dSRodney W. Grimes 
166df8bae1dSRodney W. Grimes /*
167df8bae1dSRodney W. Grimes  * Macro for looking up the in_multi record for a given IP multicast address
168df8bae1dSRodney W. Grimes  * on a given interface.  If no matching record is found, "inm" returns NULL.
169df8bae1dSRodney W. Grimes  */
170df8bae1dSRodney W. Grimes #define IN_LOOKUP_MULTI(addr, ifp, inm) \
171df8bae1dSRodney W. Grimes 	/* struct in_addr addr; */ \
172df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
173df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
174df8bae1dSRodney W. Grimes { \
175df8bae1dSRodney W. Grimes 	register struct in_ifaddr *ia; \
176df8bae1dSRodney W. Grimes \
177df8bae1dSRodney W. Grimes 	IFP_TO_IA((ifp), ia); \
178df8bae1dSRodney W. Grimes 	if (ia == NULL) \
179df8bae1dSRodney W. Grimes 		(inm) = NULL; \
180df8bae1dSRodney W. Grimes 	else \
181ffa5b11aSGarrett Wollman 		for ((inm) = ia->ia_multiaddrs.lh_first; \
182df8bae1dSRodney W. Grimes 		    (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr; \
183ffa5b11aSGarrett Wollman 		     (inm) = inm->inm_entry.le_next) \
184df8bae1dSRodney W. Grimes 			 continue; \
185df8bae1dSRodney W. Grimes }
186df8bae1dSRodney W. Grimes 
187df8bae1dSRodney W. Grimes /*
188df8bae1dSRodney W. Grimes  * Macro to step through all of the in_multi records, one at a time.
189df8bae1dSRodney W. Grimes  * The current position is remembered in "step", which the caller must
190df8bae1dSRodney W. Grimes  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
191df8bae1dSRodney W. Grimes  * and get the first record.  Both macros return a NULL "inm" when there
192df8bae1dSRodney W. Grimes  * are no remaining records.
193df8bae1dSRodney W. Grimes  */
194df8bae1dSRodney W. Grimes #define IN_NEXT_MULTI(step, inm) \
195df8bae1dSRodney W. Grimes 	/* struct in_multistep  step; */ \
196df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
197df8bae1dSRodney W. Grimes { \
198df8bae1dSRodney W. Grimes 	if (((inm) = (step).i_inm) != NULL) \
199ffa5b11aSGarrett Wollman 		(step).i_inm = (inm)->inm_entry.le_next; \
200df8bae1dSRodney W. Grimes 	else \
201df8bae1dSRodney W. Grimes 		while ((step).i_ia != NULL) { \
202ffa5b11aSGarrett Wollman 			(inm) = (step).i_ia->ia_multiaddrs.lh_first; \
203df8bae1dSRodney W. Grimes 			(step).i_ia = (step).i_ia->ia_next; \
204df8bae1dSRodney W. Grimes 			if ((inm) != NULL) { \
205ffa5b11aSGarrett Wollman 				(step).i_inm = (inm)->inm_entry.le_next; \
206df8bae1dSRodney W. Grimes 				break; \
207df8bae1dSRodney W. Grimes 			} \
208df8bae1dSRodney W. Grimes 		} \
209df8bae1dSRodney W. Grimes }
210df8bae1dSRodney W. Grimes 
211df8bae1dSRodney W. Grimes #define IN_FIRST_MULTI(step, inm) \
212df8bae1dSRodney W. Grimes 	/* struct in_multistep step; */ \
213df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
214df8bae1dSRodney W. Grimes { \
215df8bae1dSRodney W. Grimes 	(step).i_ia = in_ifaddr; \
216df8bae1dSRodney W. Grimes 	(step).i_inm = NULL; \
217df8bae1dSRodney W. Grimes 	IN_NEXT_MULTI((step), (inm)); \
218df8bae1dSRodney W. Grimes }
219df8bae1dSRodney W. Grimes 
220df8bae1dSRodney W. Grimes int	in_ifinit __P((struct ifnet *,
221df8bae1dSRodney W. Grimes 	    struct in_ifaddr *, struct sockaddr_in *, int));
222df8bae1dSRodney W. Grimes struct	in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
22326f9a767SRodney W. Grimes void	in_delmulti __P((struct in_multi *));
224df8bae1dSRodney W. Grimes void	in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
225df8bae1dSRodney W. Grimes int	in_control __P((struct socket *, int, caddr_t, struct ifnet *));
226707f139eSPaul Richards 
227707f139eSPaul Richards #endif
228df8bae1dSRodney W. Grimes #endif
229