]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/in_var.h
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / netinet / in_var.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1985, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 * @(#)in_var.h 8.2 (Berkeley) 1/9/95
9bccf70c 58 * $FreeBSD: src/sys/netinet/in_var.h,v 1.33.2.2 2001/07/17 10:50:01 ru Exp $
1c79356b
A
59 */
60
61#ifndef _NETINET_IN_VAR_H_
62#define _NETINET_IN_VAR_H_
9bccf70c 63#include <sys/appleapiopts.h>
1c79356b
A
64
65#include <sys/queue.h>
9bccf70c 66#ifdef __APPLE__
1c79356b 67#include <sys/kern_event.h>
9bccf70c
A
68#endif
69
70#ifdef __APPLE_API_UNSTABLE
1c79356b
A
71
72/*
73 * Interface address, Internet version. One of these structures
74 * is allocated for each Internet address on an interface.
75 * The ifaddr structure contains the protocol-independent part
76 * of the structure and is assumed to be first.
77 */
78struct in_ifaddr {
79 struct ifaddr ia_ifa; /* protocol-independent info */
80#define ia_ifp ia_ifa.ifa_ifp
81#define ia_flags ia_ifa.ifa_flags
82 /* ia_{,sub}net{,mask} in host order */
83 u_long ia_net; /* network number of interface */
84 u_long ia_netmask; /* mask of net part */
85 u_long ia_subnet; /* subnet number, including net */
86 u_long ia_subnetmask; /* mask of subnet part */
87 struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
88 TAILQ_ENTRY(in_ifaddr) ia_link; /* tailq macro glue */
89 struct sockaddr_in ia_addr; /* reserve space for interface name */
90 struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
91#define ia_broadaddr ia_dstaddr
92 struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
93};
94
95struct in_aliasreq {
96 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
97 struct sockaddr_in ifra_addr;
98 struct sockaddr_in ifra_broadaddr;
99#define ifra_dstaddr ifra_broadaddr
100 struct sockaddr_in ifra_mask;
9bccf70c 101#ifdef __APPLE__
1c79356b 102 u_long dlt;
9bccf70c 103#endif
1c79356b
A
104};
105
9bccf70c 106#ifdef __APPLE__
1c79356b
A
107/*
108 * Event data, internet style.
109 */
1c79356b
A
110struct kev_in_data {
111 struct net_event_data link_data;
112 struct in_addr ia_addr;
113 u_long ia_net; /* network number of interface */
114 u_long ia_netmask; /* mask of net part */
115 u_long ia_subnet; /* subnet number, including net */
116 u_long ia_subnetmask; /* mask of subnet part */
117 struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
118 struct in_addr ia_dstaddr;
119};
120
90556fb8
A
121struct kev_in_collision {
122 struct net_event_data link_data; /* link colliding arp was received on */
123 struct in_addr ia_ipaddr; /* IP address we and another node are using */
124 u_char hw_len; /* length of hardware address */
125 u_char hw_addr[0]; /* variable length hardware address */
126};
127
1c79356b 128
1c79356b
A
129/*
130 * Define inet event subclass and specific inet events.
131 */
132
133#define KEV_INET_SUBCLASS 1
134
135#define KEV_INET_NEW_ADDR 1
136#define KEV_INET_CHANGED_ADDR 2
137#define KEV_INET_ADDR_DELETED 3
138#define KEV_INET_SIFDSTADDR 4
139#define KEV_INET_SIFBRDADDR 5
140#define KEV_INET_SIFNETMASK 6
90556fb8 141#define KEV_INET_ARPCOLLISION 7 /* use kev_in_collision */
9bccf70c 142#endif /* __APPLE__ */
1c79356b
A
143
144/*
145 * Given a pointer to an in_ifaddr (ifaddr),
146 * return a pointer to the addr as a sockaddr_in.
147 */
148#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
149#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
150
151#define IN_LNAOF(in, ifa) \
152 ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
153
9bccf70c 154#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
155
156#ifdef KERNEL
9bccf70c 157#ifdef __APPLE_API_PRIVATE
1c79356b
A
158extern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
159extern struct ifqueue ipintrq; /* ip packet input queue */
160extern struct in_addr zeroin_addr;
161extern u_char inetctlerrmap[];
162
163/*
164 * Macro for finding the interface (ifnet structure) corresponding to one
165 * of our IP addresses.
166 */
167#define INADDR_TO_IFP(addr, ifp) \
168 /* struct in_addr addr; */ \
169 /* struct ifnet *ifp; */ \
170{ \
9bccf70c 171 struct in_ifaddr *ia; \
1c79356b 172\
9bccf70c
A
173 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) \
174 if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
175 break; \
1c79356b
A
176 (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
177}
178
179/*
180 * Macro for finding the internet address structure (in_ifaddr) corresponding
181 * to a given interface (ifnet structure).
182 */
183#define IFP_TO_IA(ifp, ia) \
184 /* struct ifnet *ifp; */ \
185 /* struct in_ifaddr *ia; */ \
186{ \
9bccf70c 187 for ((ia) = TAILQ_FIRST(&in_ifaddrhead); \
1c79356b 188 (ia) != NULL && (ia)->ia_ifp != (ifp); \
9bccf70c 189 (ia) = TAILQ_NEXT((ia), ia_link)) \
1c79356b
A
190 continue; \
191}
9bccf70c 192#endif /* __APPLE_API_PRIVATE */
1c79356b
A
193#endif
194
9bccf70c 195#ifdef __APPLE_API_UNSTABLE
1c79356b
A
196/*
197 * This information should be part of the ifnet structure but we don't wish
198 * to change that - as it might break a number of things
199 */
200
201struct router_info {
202 struct ifnet *rti_ifp;
203 int rti_type; /* type of router which is querier on this interface */
204 int rti_time; /* # of slow timeouts since last old query */
205 struct router_info *rti_next;
206};
207
208/*
209 * Internet multicast address structure. There is one of these for each IP
210 * multicast group to which this host belongs on a given network interface.
211 * For every entry on the interface's if_multiaddrs list which represents
212 * an IP multicast group, there is one of these structures. They are also
213 * kept on a system-wide list to make it easier to keep our legacy IGMP code
214 * compatible with the rest of the world (see IN_FIRST_MULTI et al, below).
215 */
216struct in_multi {
217 LIST_ENTRY(in_multi) inm_link; /* queue macro glue */
218 struct in_addr inm_addr; /* IP multicast address, convenience */
219 struct ifnet *inm_ifp; /* back pointer to ifnet */
220 struct ifmultiaddr *inm_ifma; /* back pointer to ifmultiaddr */
221 u_int inm_timer; /* IGMP membership report timer */
222 u_int inm_state; /* state of the membership */
223 struct router_info *inm_rti; /* router info*/
224};
9bccf70c 225#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
226
227#ifdef KERNEL
9bccf70c 228#ifdef __APPLE_API_PRIVATE
1c79356b
A
229
230#ifdef SYSCTL_DECL
231SYSCTL_DECL(_net_inet_ip);
232SYSCTL_DECL(_net_inet_raw);
233#endif
234
235extern LIST_HEAD(in_multihead, in_multi) in_multihead;
236
237/*
238 * Structure used by macros below to remember position when stepping through
239 * all of the in_multi records.
240 */
241struct in_multistep {
242 struct in_multi *i_inm;
243};
244
245/*
246 * Macro for looking up the in_multi record for a given IP multicast address
247 * on a given interface. If no matching record is found, "inm" is set null.
248 */
249#define IN_LOOKUP_MULTI(addr, ifp, inm) \
250 /* struct in_addr addr; */ \
251 /* struct ifnet *ifp; */ \
252 /* struct in_multi *inm; */ \
253do { \
9bccf70c 254 struct ifmultiaddr *ifma; \
1c79356b 255\
9bccf70c 256 LIST_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) { \
1c79356b
A
257 if (ifma->ifma_addr->sa_family == AF_INET \
258 && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \
259 (addr).s_addr) \
260 break; \
261 } \
262 (inm) = ifma ? ifma->ifma_protospec : 0; \
263} while(0)
264
265/*
266 * Macro to step through all of the in_multi records, one at a time.
267 * The current position is remembered in "step", which the caller must
268 * provide. IN_FIRST_MULTI(), below, must be called to initialize "step"
269 * and get the first record. Both macros return a NULL "inm" when there
270 * are no remaining records.
271 */
272#define IN_NEXT_MULTI(step, inm) \
273 /* struct in_multistep step; */ \
274 /* struct in_multi *inm; */ \
275do { \
276 if (((inm) = (step).i_inm) != NULL) \
9bccf70c 277 (step).i_inm = LIST_NEXT((step).i_inm, inm_link); \
1c79356b
A
278} while(0)
279
280#define IN_FIRST_MULTI(step, inm) \
281 /* struct in_multistep step; */ \
282 /* struct in_multi *inm; */ \
283do { \
9bccf70c 284 (step).i_inm = LIST_FIRST(&in_multihead); \
1c79356b
A
285 IN_NEXT_MULTI((step), (inm)); \
286} while(0)
287
288struct route;
289struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
290void in_delmulti __P((struct in_multi *));
291int in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
292 struct proc *));
293void in_rtqdrain __P((void));
294void ip_input __P((struct mbuf *));
9bccf70c 295int in_ifadown __P((struct ifaddr *ifa, int));
1c79356b
A
296void in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
297int ipflow_fastforward __P((struct mbuf *));
298void ipflow_create __P((const struct route *, struct mbuf *));
299void ipflow_slowtimo __P((void));
300
9bccf70c
A
301#endif /* __APPLE_API_PRIVATE */
302#endif /* _KERNEL */
303
1c79356b
A
304/* INET6 stuff */
305#include <netinet6/in6_var.h>
1c79356b
A
306
307#endif /* _NETINET_IN_VAR_H_ */