xref: /freebsd/sys/netinet/in_var.h (revision 664a31e4967a61ec61870f45adc2f1400617993e)
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  *
332180b925SGarrett Wollman  *	@(#)in_var.h	8.2 (Berkeley) 1/9/95
34c3aac50fSPeter Wemm  * $FreeBSD$
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
44477180fbSGarrett Wollman  * is allocated for each Internet address on an interface.
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 */
5859562606SGarrett Wollman 	TAILQ_ENTRY(in_ifaddr) ia_link;	/* tailq macro glue */
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 */
63df8bae1dSRodney W. Grimes };
64df8bae1dSRodney W. Grimes 
65df8bae1dSRodney W. Grimes struct	in_aliasreq {
66df8bae1dSRodney W. Grimes 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
67df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_addr;
68df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_broadaddr;
69df8bae1dSRodney W. Grimes #define ifra_dstaddr ifra_broadaddr
70df8bae1dSRodney W. Grimes 	struct	sockaddr_in ifra_mask;
71df8bae1dSRodney W. Grimes };
72df8bae1dSRodney W. Grimes /*
73df8bae1dSRodney W. Grimes  * Given a pointer to an in_ifaddr (ifaddr),
74df8bae1dSRodney W. Grimes  * return a pointer to the addr as a sockaddr_in.
75df8bae1dSRodney W. Grimes  */
76df8bae1dSRodney W. Grimes #define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
771bc8a809SSteven Wallace #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
78df8bae1dSRodney W. Grimes 
79df8bae1dSRodney W. Grimes #define IN_LNAOF(in, ifa) \
80df8bae1dSRodney W. Grimes 	((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
81df8bae1dSRodney W. Grimes 
82df8bae1dSRodney W. Grimes 
83664a31e4SPeter Wemm #ifdef	_KERNEL
8459562606SGarrett Wollman extern	TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
85df8bae1dSRodney W. Grimes extern	struct	ifqueue	ipintrq;		/* ip packet input queue */
86b5e8ce9fSBruce Evans extern	struct	in_addr zeroin_addr;
87b5e8ce9fSBruce Evans extern	u_char	inetctlerrmap[];
88df8bae1dSRodney W. Grimes 
89df8bae1dSRodney W. Grimes /*
90df8bae1dSRodney W. Grimes  * Macro for finding the interface (ifnet structure) corresponding to one
91df8bae1dSRodney W. Grimes  * of our IP addresses.
92df8bae1dSRodney W. Grimes  */
93df8bae1dSRodney W. Grimes #define INADDR_TO_IFP(addr, ifp) \
94df8bae1dSRodney W. Grimes 	/* struct in_addr addr; */ \
95df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
96df8bae1dSRodney W. Grimes { \
97df8bae1dSRodney W. Grimes 	register struct in_ifaddr *ia; \
98df8bae1dSRodney W. Grimes \
9959562606SGarrett Wollman 	for (ia = in_ifaddrhead.tqh_first; \
1001bc8a809SSteven Wallace 	    ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \
1011bc8a809SSteven Wallace 		IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \
10259562606SGarrett Wollman 	    ia = ia->ia_link.tqe_next) \
103df8bae1dSRodney W. Grimes 		 continue; \
10433d06b43SGarrett Wollman 	if (ia == NULL) \
10559562606SGarrett Wollman 	    for (ia = in_ifaddrhead.tqh_first; \
10633d06b43SGarrett Wollman 		ia != NULL; \
10759562606SGarrett Wollman 		ia = ia->ia_link.tqe_next) \
10833d06b43SGarrett Wollman 		    if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \
109ce00153cSDavid Greenman 			IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
11033d06b43SGarrett Wollman 			    break; \
111df8bae1dSRodney W. Grimes 	(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
112df8bae1dSRodney W. Grimes }
113df8bae1dSRodney W. Grimes 
114df8bae1dSRodney W. Grimes /*
115df8bae1dSRodney W. Grimes  * Macro for finding the internet address structure (in_ifaddr) corresponding
116df8bae1dSRodney W. Grimes  * to a given interface (ifnet structure).
117df8bae1dSRodney W. Grimes  */
118df8bae1dSRodney W. Grimes #define IFP_TO_IA(ifp, ia) \
119df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
120df8bae1dSRodney W. Grimes 	/* struct in_ifaddr *ia; */ \
121df8bae1dSRodney W. Grimes { \
12259562606SGarrett Wollman 	for ((ia) = in_ifaddrhead.tqh_first; \
123df8bae1dSRodney W. Grimes 	    (ia) != NULL && (ia)->ia_ifp != (ifp); \
12459562606SGarrett Wollman 	    (ia) = (ia)->ia_link.tqe_next) \
125df8bae1dSRodney W. Grimes 		continue; \
126df8bae1dSRodney W. Grimes }
127df8bae1dSRodney W. Grimes #endif
128df8bae1dSRodney W. Grimes 
129df8bae1dSRodney W. Grimes /*
130f0068c4aSGarrett Wollman  * This information should be part of the ifnet structure but we don't wish
131f0068c4aSGarrett Wollman  * to change that - as it might break a number of things
132f0068c4aSGarrett Wollman  */
133f0068c4aSGarrett Wollman 
134f0068c4aSGarrett Wollman struct router_info {
13549fa849bSBill Fenner 	struct ifnet *rti_ifp;
13649fa849bSBill Fenner 	int    rti_type; /* type of router which is querier on this interface */
13749fa849bSBill Fenner 	int    rti_time; /* # of slow timeouts since last old query */
13849fa849bSBill Fenner 	struct router_info *rti_next;
139f0068c4aSGarrett Wollman };
140f0068c4aSGarrett Wollman 
141f0068c4aSGarrett Wollman /*
142df8bae1dSRodney W. Grimes  * Internet multicast address structure.  There is one of these for each IP
143df8bae1dSRodney W. Grimes  * multicast group to which this host belongs on a given network interface.
144477180fbSGarrett Wollman  * For every entry on the interface's if_multiaddrs list which represents
145477180fbSGarrett Wollman  * an IP multicast group, there is one of these structures.  They are also
146477180fbSGarrett Wollman  * kept on a system-wide list to make it easier to keep our legacy IGMP code
147477180fbSGarrett Wollman  * compatible with the rest of the world (see IN_FIRST_MULTI et al, below).
148df8bae1dSRodney W. Grimes  */
149df8bae1dSRodney W. Grimes struct in_multi {
150477180fbSGarrett Wollman 	LIST_ENTRY(in_multi) inm_link;	/* queue macro glue */
151477180fbSGarrett Wollman 	struct	in_addr inm_addr;	/* IP multicast address, convenience */
152df8bae1dSRodney W. Grimes 	struct	ifnet *inm_ifp;		/* back pointer to ifnet */
153477180fbSGarrett Wollman 	struct	ifmultiaddr *inm_ifma;	/* back pointer to ifmultiaddr */
154df8bae1dSRodney W. Grimes 	u_int	inm_timer;		/* IGMP membership report timer */
155f0068c4aSGarrett Wollman 	u_int	inm_state;		/*  state of the membership */
156f0068c4aSGarrett Wollman 	struct	router_info *inm_rti;	/* router info*/
157df8bae1dSRodney W. Grimes };
158df8bae1dSRodney W. Grimes 
159664a31e4SPeter Wemm #ifdef _KERNEL
160ce02431fSDoug Rabson 
161ce02431fSDoug Rabson #ifdef SYSCTL_DECL
162ce02431fSDoug Rabson SYSCTL_DECL(_net_inet_ip);
163ce02431fSDoug Rabson SYSCTL_DECL(_net_inet_raw);
164ce02431fSDoug Rabson #endif
165ce02431fSDoug Rabson 
166477180fbSGarrett Wollman extern LIST_HEAD(in_multihead, in_multi) in_multihead;
167477180fbSGarrett Wollman 
168df8bae1dSRodney W. Grimes /*
169df8bae1dSRodney W. Grimes  * Structure used by macros below to remember position when stepping through
170df8bae1dSRodney W. Grimes  * all of the in_multi records.
171df8bae1dSRodney W. Grimes  */
172df8bae1dSRodney W. Grimes struct in_multistep {
173df8bae1dSRodney W. Grimes 	struct in_multi *i_inm;
174df8bae1dSRodney W. Grimes };
175df8bae1dSRodney W. Grimes 
176df8bae1dSRodney W. Grimes /*
177df8bae1dSRodney W. Grimes  * Macro for looking up the in_multi record for a given IP multicast address
178477180fbSGarrett Wollman  * on a given interface.  If no matching record is found, "inm" is set null.
179df8bae1dSRodney W. Grimes  */
180df8bae1dSRodney W. Grimes #define IN_LOOKUP_MULTI(addr, ifp, inm) \
181df8bae1dSRodney W. Grimes 	/* struct in_addr addr; */ \
182df8bae1dSRodney W. Grimes 	/* struct ifnet *ifp; */ \
183df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
18459562606SGarrett Wollman do { \
185477180fbSGarrett Wollman 	register struct ifmultiaddr *ifma; \
186df8bae1dSRodney W. Grimes \
187477180fbSGarrett Wollman 	for (ifma = (ifp)->if_multiaddrs.lh_first; ifma; \
188477180fbSGarrett Wollman 	     ifma = ifma->ifma_link.le_next) { \
189477180fbSGarrett Wollman 		if (ifma->ifma_addr->sa_family == AF_INET \
19093e808cdSGarrett Wollman 		    && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \
191477180fbSGarrett Wollman 		    (addr).s_addr) \
192477180fbSGarrett Wollman 			break; \
193477180fbSGarrett Wollman 	} \
194477180fbSGarrett Wollman 	(inm) = ifma ? ifma->ifma_protospec : 0; \
19559562606SGarrett Wollman } while(0)
196df8bae1dSRodney W. Grimes 
197df8bae1dSRodney W. Grimes /*
198df8bae1dSRodney W. Grimes  * Macro to step through all of the in_multi records, one at a time.
199df8bae1dSRodney W. Grimes  * The current position is remembered in "step", which the caller must
200df8bae1dSRodney W. Grimes  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
201df8bae1dSRodney W. Grimes  * and get the first record.  Both macros return a NULL "inm" when there
202df8bae1dSRodney W. Grimes  * are no remaining records.
203df8bae1dSRodney W. Grimes  */
204df8bae1dSRodney W. Grimes #define IN_NEXT_MULTI(step, inm) \
205df8bae1dSRodney W. Grimes 	/* struct in_multistep  step; */ \
206df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
20759562606SGarrett Wollman do { \
208df8bae1dSRodney W. Grimes 	if (((inm) = (step).i_inm) != NULL) \
209477180fbSGarrett Wollman 		(step).i_inm = (step).i_inm->inm_link.le_next; \
21059562606SGarrett Wollman } while(0)
211df8bae1dSRodney W. Grimes 
212df8bae1dSRodney W. Grimes #define IN_FIRST_MULTI(step, inm) \
213df8bae1dSRodney W. Grimes 	/* struct in_multistep step; */ \
214df8bae1dSRodney W. Grimes 	/* struct in_multi *inm; */ \
21559562606SGarrett Wollman do { \
216477180fbSGarrett Wollman 	(step).i_inm = in_multihead.lh_first; \
217df8bae1dSRodney W. Grimes 	IN_NEXT_MULTI((step), (inm)); \
21859562606SGarrett Wollman } while(0)
219df8bae1dSRodney W. Grimes 
2201f91d8c5SDavid Greenman struct	route;
221df8bae1dSRodney W. Grimes struct	in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
22226f9a767SRodney W. Grimes void	in_delmulti __P((struct in_multi *));
223ecbb00a2SDoug Rabson int	in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
224a29f300eSGarrett Wollman 			struct proc *));
225ce29ab3aSGarrett Wollman void	in_rtqdrain __P((void));
226c67b1d17SGarrett Wollman void	ip_input __P((struct mbuf *));
22739191c8eSGarrett Wollman int	in_ifadown __P((struct ifaddr *ifa));
22839191c8eSGarrett Wollman void	in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
2291f91d8c5SDavid Greenman int	ipflow_fastforward __P((struct mbuf *));
2301f91d8c5SDavid Greenman void	ipflow_create __P((const struct route *, struct mbuf *));
2311f91d8c5SDavid Greenman void	ipflow_slowtimo __P((void));
232707f139eSPaul Richards 
233664a31e4SPeter Wemm #endif /* _KERNEL */
2342180b925SGarrett Wollman 
23576429de4SYoshinobu Inoue /* INET6 stuff */
23676429de4SYoshinobu Inoue #include <netinet6/in6_var.h>
23776429de4SYoshinobu Inoue 
2382180b925SGarrett Wollman #endif /* _NETINET_IN_VAR_H_ */
239