]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/in_var.h
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / netinet / in_var.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
58 * $FreeBSD: src/sys/netinet/in_var.h,v 1.33.2.2 2001/07/17 10:50:01 ru Exp $
59 */
60
61 #ifndef _NETINET_IN_VAR_H_
62 #define _NETINET_IN_VAR_H_
63 #include <sys/appleapiopts.h>
64
65 #include <sys/queue.h>
66 #ifdef __APPLE__
67 #include <sys/kern_event.h>
68 #endif
69
70 #ifdef __APPLE_API_UNSTABLE
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 */
78 struct 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
95 struct 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;
101 #ifdef __APPLE__
102 u_long dlt;
103 #endif
104 };
105
106 #ifdef __APPLE__
107 /*
108 * Event data, internet style.
109 */
110 struct 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
121 struct 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
128
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
141 #define KEV_INET_ARPCOLLISION 7 /* use kev_in_collision */
142 #endif /* __APPLE__ */
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
154 #endif /* __APPLE_API_UNSTABLE */
155
156 #ifdef KERNEL
157 #ifdef __APPLE_API_PRIVATE
158 extern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
159 extern struct ifqueue ipintrq; /* ip packet input queue */
160 extern struct in_addr zeroin_addr;
161 extern 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 { \
171 struct in_ifaddr *ia; \
172 \
173 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) \
174 if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
175 break; \
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 { \
187 for ((ia) = TAILQ_FIRST(&in_ifaddrhead); \
188 (ia) != NULL && (ia)->ia_ifp != (ifp); \
189 (ia) = TAILQ_NEXT((ia), ia_link)) \
190 continue; \
191 }
192 #endif /* __APPLE_API_PRIVATE */
193 #endif
194
195 #ifdef __APPLE_API_UNSTABLE
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
201 struct 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 */
216 struct 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 };
225 #endif /* __APPLE_API_UNSTABLE */
226
227 #ifdef KERNEL
228 #ifdef __APPLE_API_PRIVATE
229
230 #ifdef SYSCTL_DECL
231 SYSCTL_DECL(_net_inet_ip);
232 SYSCTL_DECL(_net_inet_raw);
233 #endif
234
235 extern 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 */
241 struct 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; */ \
253 do { \
254 struct ifmultiaddr *ifma; \
255 \
256 LIST_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) { \
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; */ \
275 do { \
276 if (((inm) = (step).i_inm) != NULL) \
277 (step).i_inm = LIST_NEXT((step).i_inm, inm_link); \
278 } while(0)
279
280 #define IN_FIRST_MULTI(step, inm) \
281 /* struct in_multistep step; */ \
282 /* struct in_multi *inm; */ \
283 do { \
284 (step).i_inm = LIST_FIRST(&in_multihead); \
285 IN_NEXT_MULTI((step), (inm)); \
286 } while(0)
287
288 struct route;
289 struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
290 void in_delmulti __P((struct in_multi *));
291 int in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
292 struct proc *));
293 void in_rtqdrain __P((void));
294 void ip_input __P((struct mbuf *));
295 int in_ifadown __P((struct ifaddr *ifa, int));
296 void in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
297 int ipflow_fastforward __P((struct mbuf *));
298 void ipflow_create __P((const struct route *, struct mbuf *));
299 void ipflow_slowtimo __P((void));
300
301 #endif /* __APPLE_API_PRIVATE */
302 #endif /* _KERNEL */
303
304 /* INET6 stuff */
305 #include <netinet6/in6_var.h>
306
307 #endif /* _NETINET_IN_VAR_H_ */