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