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