]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/ip_var.h
422c95c1a3ffd7acfb886c7d8fe2e144a1cbcfc5
[apple/xnu.git] / bsd / netinet / ip_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) 1982, 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 * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
58 */
59
60 #ifndef _NETINET_IP_VAR_H_
61 #define _NETINET_IP_VAR_H_
62 #include <sys/appleapiopts.h>
63
64 #ifdef __APPLE_API_PRIVATE
65 /*
66 * Overlay for ip header used by other protocols (tcp, udp).
67 */
68 struct ipovly {
69 u_char ih_x1[9]; /* (unused) */
70 u_char ih_pr; /* protocol */
71 u_short ih_len; /* protocol length */
72 struct in_addr ih_src; /* source internet address */
73 struct in_addr ih_dst; /* destination internet address */
74 };
75
76 /*
77 * Ip reassembly queue structure. Each fragment
78 * being reassembled is attached to one of these structures.
79 * They are timed out after ipq_ttl drops to 0, and may also
80 * be reclaimed if memory becomes tight.
81 */
82 struct ipq {
83 struct ipq *next,*prev; /* to other reass headers */
84 u_char ipq_ttl; /* time for reass q to live */
85 u_char ipq_p; /* protocol of this fragment */
86 u_short ipq_id; /* sequence id for reassembly */
87 struct mbuf *ipq_frags; /* to ip headers of fragments */
88 struct in_addr ipq_src,ipq_dst;
89 u_long reserved[4]; /* for future use */
90 #if IPDIVERT
91 #ifdef IPDIVERT_44
92 u_int32_t ipq_div_info; /* ipfw divert port & flags */
93 #else
94 u_int16_t ipq_divert; /* ipfw divert port (Maintain backward compat.) */
95 #endif
96 u_int16_t ipq_div_cookie; /* ipfw divert cookie */
97 #endif
98 };
99
100 /*
101 * Structure stored in mbuf in inpcb.ip_options
102 * and passed to ip_output when ip options are in use.
103 * The actual length of the options (including ipopt_dst)
104 * is in m_len.
105 */
106 #define MAX_IPOPTLEN 40
107
108 struct ipoption {
109 struct in_addr ipopt_dst; /* first-hop dst if source routed */
110 char ipopt_list[MAX_IPOPTLEN]; /* options proper */
111 };
112
113 /*
114 * Structure attached to inpcb.ip_moptions and
115 * passed to ip_output when IP multicast options are in use.
116 */
117 struct ip_moptions {
118 struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
119 u_char imo_multicast_ttl; /* TTL for outgoing multicasts */
120 u_char imo_multicast_loop; /* 1 => hear sends if a member */
121 u_short imo_num_memberships; /* no. memberships this socket */
122 struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
123 u_long imo_multicast_vif; /* vif num outgoing multicasts */
124 struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
125 };
126 #endif /* __APPLE_API_PRIVATE */
127
128 #ifdef __APPLE_API_UNSTABLE
129 struct ipstat {
130 u_long ips_total; /* total packets received */
131 u_long ips_badsum; /* checksum bad */
132 u_long ips_tooshort; /* packet too short */
133 u_long ips_toosmall; /* not enough data */
134 u_long ips_badhlen; /* ip header length < data size */
135 u_long ips_badlen; /* ip length < ip header length */
136 u_long ips_fragments; /* fragments received */
137 u_long ips_fragdropped; /* frags dropped (dups, out of space) */
138 u_long ips_fragtimeout; /* fragments timed out */
139 u_long ips_forward; /* packets forwarded */
140 u_long ips_fastforward; /* packets fast forwarded */
141 u_long ips_cantforward; /* packets rcvd for unreachable dest */
142 u_long ips_redirectsent; /* packets forwarded on same net */
143 u_long ips_noproto; /* unknown or unsupported protocol */
144 u_long ips_delivered; /* datagrams delivered to upper level*/
145 u_long ips_localout; /* total ip packets generated here */
146 u_long ips_odropped; /* lost packets due to nobufs, etc. */
147 u_long ips_reassembled; /* total packets reassembled ok */
148 u_long ips_fragmented; /* datagrams successfully fragmented */
149 u_long ips_ofragments; /* output fragments created */
150 u_long ips_cantfrag; /* don't fragment flag was set, etc. */
151 u_long ips_badoptions; /* error in option processing */
152 u_long ips_noroute; /* packets discarded due to no route */
153 u_long ips_badvers; /* ip version != 4 */
154 u_long ips_rawout; /* total raw ip packets generated */
155 u_long ips_toolong; /* ip length > max ip packet size */
156 u_long ips_notmember; /* multicasts for unregistered grps */
157 u_long ips_nogif; /* no match gif found */
158 u_long ips_badaddr; /* invalid address on header */
159 };
160 #endif /* __APPLE_API_UNSTABLE */
161
162 #ifdef __APPLE_API_PRIVATE
163 #ifdef KERNEL
164
165 struct ip_linklocal_stat {
166 u_long iplls_in_total;
167 u_long iplls_in_badttl;
168 u_long iplls_out_total;
169 u_long iplls_out_badttl;
170 };
171
172 /* flags passed to ip_output as last parameter */
173 #define IP_FORWARDING 0x1 /* most of ip header exists */
174 #define IP_RAWOUTPUT 0x2 /* raw ip header exists */
175 #define IP_NOIPSEC 0x4 /* No IPSec processing */
176 #define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables (0x0010) */
177 #define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets (0x0020) */
178
179 struct ip;
180 struct inpcb;
181 struct route;
182 struct sockopt;
183
184 extern struct ipstat ipstat;
185 #if !defined(RANDOM_IP_ID) || RANDOM_IP_ID == 0
186 extern u_short ip_id; /* ip packet ctr, for ids */
187 #endif
188 extern int ip_defttl; /* default IP ttl */
189 extern int ipforwarding; /* ip forwarding */
190 extern struct protosw *ip_protox[];
191 extern struct socket *ip_rsvpd; /* reservation protocol daemon */
192 extern struct socket *ip_mrouter; /* multicast routing daemon */
193 extern int (*legal_vif_num) __P((int));
194 extern u_long (*ip_mcast_src) __P((int));
195 extern int rsvp_on;
196 extern struct pr_usrreqs rip_usrreqs;
197
198 int ip_ctloutput __P((struct socket *, struct sockopt *sopt));
199 void ip_drain __P((void));
200 void ip_freemoptions __P((struct ip_moptions *));
201 void ip_init __P((void));
202 extern int (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *,
203 struct ip_moptions *));
204 int ip_output __P((struct mbuf *,
205 struct mbuf *, struct route *, int, struct ip_moptions *));
206 void ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *,
207 struct mbuf *));
208 void ip_slowtimo __P((void));
209 struct mbuf *
210 ip_srcroute __P((void));
211 void ip_stripoptions __P((struct mbuf *, struct mbuf *));
212 #if RANDOM_IP_ID
213 u_int16_t
214 ip_randomid __P((void));
215 #endif
216 int rip_ctloutput __P((struct socket *, struct sockopt *));
217 void rip_ctlinput __P((int, struct sockaddr *, void *));
218 void rip_init __P((void));
219 void rip_input __P((struct mbuf *, int));
220 int rip_output __P((struct mbuf *, struct socket *, u_long));
221 void ipip_input __P((struct mbuf *, int));
222 void rsvp_input __P((struct mbuf *, int));
223 int ip_rsvp_init __P((struct socket *));
224 int ip_rsvp_done __P((void));
225 int ip_rsvp_vif_init __P((struct socket *, struct sockopt *));
226 int ip_rsvp_vif_done __P((struct socket *, struct sockopt *));
227 void ip_rsvp_force_done __P((struct socket *));
228
229 #if IPDIVERT
230 void div_init __P((void));
231 void div_input __P((struct mbuf *, int));
232 void divert_packet __P((struct mbuf *, int, int));
233 extern struct pr_usrreqs div_usrreqs;
234 extern u_int16_t ip_divert_cookie;
235 #endif
236
237 extern struct sockaddr_in *ip_fw_fwd_addr;
238
239 void in_delayed_cksum(struct mbuf *m);
240
241 #endif /* _KERNEL */
242 #endif /* __APPLE_API_PRIVATE */
243
244 #endif /* !_NETINET_IP_VAR_H_ */