]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/in_var.h
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / netinet / in_var.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
61 * $FreeBSD: src/sys/netinet/in_var.h,v 1.33.2.2 2001/07/17 10:50:01 ru Exp $
62 */
63
64 #ifndef _NETINET_IN_VAR_H_
65 #define _NETINET_IN_VAR_H_
66 #include <sys/appleapiopts.h>
67
68 #include <sys/queue.h>
69 #ifdef __APPLE__
70 #include <sys/kern_event.h>
71 #endif
72
73 #ifdef PRIVATE
74
75 /*
76 * Interface address, Internet version. One of these structures
77 * is allocated for each Internet address on an interface.
78 * The ifaddr structure contains the protocol-independent part
79 * of the structure and is assumed to be first.
80 */
81 struct in_ifaddr {
82 struct ifaddr ia_ifa; /* protocol-independent info */
83 #define ia_ifp ia_ifa.ifa_ifp
84 #define ia_flags ia_ifa.ifa_flags
85 /* ia_{,sub}net{,mask} in host order */
86 u_long ia_net; /* network number of interface */
87 u_long ia_netmask; /* mask of net part */
88 u_long ia_subnet; /* subnet number, including net */
89 u_long ia_subnetmask; /* mask of subnet part */
90 struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
91 TAILQ_ENTRY(in_ifaddr) ia_link; /* tailq macro glue */
92 struct sockaddr_in ia_addr; /* reserve space for interface name */
93 struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
94 #define ia_broadaddr ia_dstaddr
95 struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
96 };
97 #endif /* PRIVATE */
98
99 struct in_aliasreq {
100 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
101 struct sockaddr_in ifra_addr;
102 struct sockaddr_in ifra_broadaddr;
103 #define ifra_dstaddr ifra_broadaddr
104 struct sockaddr_in ifra_mask;
105 #ifdef __APPLE__
106 u_long dlt;
107 #endif
108 };
109
110 /*
111 * Event data, internet style.
112 */
113 struct kev_in_data {
114 struct net_event_data link_data;
115 struct in_addr ia_addr;
116 u_long ia_net; /* network number of interface */
117 u_long ia_netmask; /* mask of net part */
118 u_long ia_subnet; /* subnet number, including net */
119 u_long ia_subnetmask; /* mask of subnet part */
120 struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
121 struct in_addr ia_dstaddr;
122 };
123
124 struct kev_in_collision {
125 struct net_event_data link_data; /* link colliding arp was received on */
126 struct in_addr ia_ipaddr; /* IP address we and another node are using */
127 u_char hw_len; /* length of hardware address */
128 u_char hw_addr[0]; /* variable length hardware address */
129 };
130
131
132 /*
133 * Define inet event subclass and specific inet events.
134 */
135
136 #define KEV_INET_SUBCLASS 1
137
138 #define KEV_INET_NEW_ADDR 1
139 #define KEV_INET_CHANGED_ADDR 2
140 #define KEV_INET_ADDR_DELETED 3
141 #define KEV_INET_SIFDSTADDR 4
142 #define KEV_INET_SIFBRDADDR 5
143 #define KEV_INET_SIFNETMASK 6
144 #define KEV_INET_ARPCOLLISION 7 /* use kev_in_collision */
145
146 #ifdef KERNEL_PRIVATE
147 /*
148 * Given a pointer to an in_ifaddr (ifaddr),
149 * return a pointer to the addr as a sockaddr_in.
150 */
151 #define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
152 #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
153
154 #define IN_LNAOF(in, ifa) \
155 ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
156
157 extern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
158 extern struct ifqueue ipintrq; /* ip packet input queue */
159 extern struct in_addr zeroin_addr;
160 extern u_char inetctlerrmap[];
161 extern lck_mtx_t *rt_mtx;
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 lck_mtx_assert(rt_mtx, LCK_MTX_ASSERT_NOTOWNED); \
174 lck_mtx_lock(rt_mtx); \
175 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) \
176 if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
177 break; \
178 (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
179 lck_mtx_unlock(rt_mtx); \
180 }
181
182 /*
183 * Macro for finding the internet address structure (in_ifaddr) corresponding
184 * to a given interface (ifnet structure).
185 */
186 #define IFP_TO_IA(ifp, ia) \
187 /* struct ifnet *ifp; */ \
188 /* struct in_ifaddr *ia; */ \
189 { \
190 lck_mtx_assert(rt_mtx, LCK_MTX_ASSERT_NOTOWNED); \
191 lck_mtx_lock(rt_mtx); \
192 for ((ia) = TAILQ_FIRST(&in_ifaddrhead); \
193 (ia) != NULL && (ia)->ia_ifp != (ifp); \
194 (ia) = TAILQ_NEXT((ia), ia_link)) \
195 continue; \
196 lck_mtx_unlock(rt_mtx); \
197 }
198
199 /*
200 * This information should be part of the ifnet structure but we don't wish
201 * to change that - as it might break a number of things
202 */
203
204 struct router_info {
205 struct ifnet *rti_ifp;
206 int rti_type; /* type of router which is querier on this interface */
207 int rti_time; /* # of slow timeouts since last old query */
208 struct router_info *rti_next;
209 };
210
211 /*
212 * Internet multicast address structure. There is one of these for each IP
213 * multicast group to which this host belongs on a given network interface.
214 * For every entry on the interface's if_multiaddrs list which represents
215 * an IP multicast group, there is one of these structures. They are also
216 * kept on a system-wide list to make it easier to keep our legacy IGMP code
217 * compatible with the rest of the world (see IN_FIRST_MULTI et al, below).
218 */
219 struct in_multi {
220 LIST_ENTRY(in_multi) inm_link; /* queue macro glue */
221 struct in_addr inm_addr; /* IP multicast address, convenience */
222 struct ifnet *inm_ifp; /* back pointer to ifnet */
223 struct ifmultiaddr *inm_ifma; /* back pointer to ifmultiaddr */
224 u_int inm_timer; /* IGMP membership report timer */
225 u_int inm_state; /* state of the membership */
226 struct router_info *inm_rti; /* router info*/
227 };
228
229 #ifdef SYSCTL_DECL
230 SYSCTL_DECL(_net_inet_ip);
231 SYSCTL_DECL(_net_inet_raw);
232 #endif
233
234 extern LIST_HEAD(in_multihead, in_multi) in_multihead;
235
236 /*
237 * Structure used by macros below to remember position when stepping through
238 * all of the in_multi records.
239 */
240 struct in_multistep {
241 struct in_multi *i_inm;
242 };
243
244 /*
245 * Macro for looking up the in_multi record for a given IP multicast address
246 * on a given interface. If no matching record is found, "inm" is set null.
247 */
248 #define IN_LOOKUP_MULTI(addr, ifp, inm) \
249 /* struct in_addr addr; */ \
250 /* struct ifnet *ifp; */ \
251 /* struct in_multi *inm; */ \
252 do { \
253 struct ifmultiaddr *ifma; \
254 \
255 LIST_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) { \
256 if (ifma->ifma_addr->sa_family == AF_INET \
257 && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \
258 (addr).s_addr) \
259 break; \
260 } \
261 (inm) = ifma ? ifma->ifma_protospec : 0; \
262 } while(0)
263
264 /*
265 * Macro to step through all of the in_multi records, one at a time.
266 * The current position is remembered in "step", which the caller must
267 * provide. IN_FIRST_MULTI(), below, must be called to initialize "step"
268 * and get the first record. Both macros return a NULL "inm" when there
269 * are no remaining records.
270 */
271 #define IN_NEXT_MULTI(step, inm) \
272 /* struct in_multistep step; */ \
273 /* struct in_multi *inm; */ \
274 do { \
275 if (((inm) = (step).i_inm) != NULL) \
276 (step).i_inm = LIST_NEXT((step).i_inm, inm_link); \
277 } while(0)
278
279 #define IN_FIRST_MULTI(step, inm) \
280 /* struct in_multistep step; */ \
281 /* struct in_multi *inm; */ \
282 do { \
283 (step).i_inm = LIST_FIRST(&in_multihead); \
284 IN_NEXT_MULTI((step), (inm)); \
285 } while(0)
286
287 struct route;
288 struct in_multi *in_addmulti(struct in_addr *, struct ifnet *);
289 void in_delmulti(struct in_multi **);
290 int in_control(struct socket *, u_long, caddr_t, struct ifnet *,
291 struct proc *);
292 void in_rtqdrain(void);
293 void ip_input(struct mbuf *);
294 int in_ifadown(struct ifaddr *ifa, int);
295 void in_ifscrub(struct ifnet *, struct in_ifaddr *, int);
296 int ipflow_fastforward(struct mbuf *);
297 void ipflow_create(const struct route *, struct mbuf *);
298 void ipflow_slowtimo(void);
299
300 #endif /* KERNEL_PRIVATE */
301
302 /* INET6 stuff */
303 #include <netinet6/in6_var.h>
304
305 #endif /* _NETINET_IN_VAR_H_ */