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