ip_var.h revision 1.53 1 /* $NetBSD: ip_var.h,v 1.53 2003/06/23 11:02:15 martin Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
36 */
37
38 #ifndef _NETINET_IP_VAR_H_
39 #define _NETINET_IP_VAR_H_
40
41 #include "opt_gateway.h"
42 #include "opt_mbuftrace.h"
43
44 #include <sys/queue.h>
45 #include <net/route.h>
46
47 /*
48 * Overlay for ip header used by other protocols (tcp, udp).
49 */
50 struct ipovly {
51 u_int8_t ih_x1[9]; /* (unused) */
52 u_int8_t ih_pr; /* protocol */
53 u_int16_t ih_len; /* protocol length */
54 struct in_addr ih_src; /* source internet address */
55 struct in_addr ih_dst; /* destination internet address */
56 } __attribute__((__packed__));
57
58 /*
59 * Ip (reassembly or sequence) queue structures.
60 *
61 * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
62 * We want to avoid doing m_pullup on incoming packets but that
63 * means avoiding dtom on the tcp reassembly code. That in turn means
64 * keeping an mbuf pointer in the reassembly queue (since we might
65 * have a cluster). As a quick hack, the source & destination
66 * port numbers (which are no longer needed once we've located the
67 * tcpcb) are overlayed with an mbuf pointer.
68 */
69 TAILQ_HEAD(ipqehead, ipqent);
70 struct ipqent {
71 TAILQ_ENTRY(ipqent) ipqe_q;
72 union {
73 struct ip *_ip;
74 struct tcpiphdr *_tcp;
75 } _ipqe_u1;
76 struct mbuf *ipqe_m; /* point to first mbuf */
77 struct mbuf *ipre_mlast; /* point to last mbuf */
78 u_int8_t ipqe_mff; /* for IP fragmentation */
79 /*
80 * The following are used in TCP reassembly
81 */
82 TAILQ_ENTRY(ipqent) ipqe_timeq;
83 u_int32_t ipqe_seq;
84 u_int32_t ipqe_len;
85 u_int32_t ipqe_flags;
86 };
87 #define ipqe_ip _ipqe_u1._ip
88 #define ipqe_tcp _ipqe_u1._tcp
89
90 /*
91 * Ip reassembly queue structure. Each fragment
92 * being reassembled is attached to one of these structures.
93 * They are timed out after ipq_ttl drops to 0, and may also
94 * be reclaimed if memory becomes tight.
95 */
96 struct ipq {
97 LIST_ENTRY(ipq) ipq_q; /* to other reass headers */
98 u_int8_t ipq_ttl; /* time for reass q to live */
99 u_int8_t ipq_p; /* protocol of this fragment */
100 u_int16_t ipq_id; /* sequence id for reassembly */
101 struct ipqehead ipq_fragq; /* to ip fragment queue */
102 struct in_addr ipq_src, ipq_dst;
103 };
104
105 /*
106 * Structure stored in mbuf in inpcb.ip_options
107 * and passed to ip_output when ip options are in use.
108 * The actual length of the options (including ipopt_dst)
109 * is in m_len.
110 */
111 #define MAX_IPOPTLEN 40
112
113 struct ipoption {
114 struct in_addr ipopt_dst; /* first-hop dst if source routed */
115 int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
116 };
117
118 /*
119 * Structure attached to inpcb.ip_moptions and
120 * passed to ip_output when IP multicast options are in use.
121 */
122 struct ip_moptions {
123 struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
124 struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
125 u_int8_t imo_multicast_ttl; /* TTL for outgoing multicasts */
126 u_int8_t imo_multicast_loop; /* 1 => hear sends if a member */
127 u_int16_t imo_num_memberships; /* no. memberships this socket */
128 struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
129 };
130
131 struct ipstat {
132 u_quad_t ips_total; /* total packets received */
133 u_quad_t ips_badsum; /* checksum bad */
134 u_quad_t ips_tooshort; /* packet too short */
135 u_quad_t ips_toosmall; /* not enough data */
136 u_quad_t ips_badhlen; /* ip header length < data size */
137 u_quad_t ips_badlen; /* ip length < ip header length */
138 u_quad_t ips_fragments; /* fragments received */
139 u_quad_t ips_fragdropped; /* frags dropped (dups, out of space) */
140 u_quad_t ips_fragtimeout; /* fragments timed out */
141 u_quad_t ips_forward; /* packets forwarded */
142 u_quad_t ips_fastforward; /* packets fast forwarded */
143 u_quad_t ips_cantforward; /* packets rcvd for unreachable dest */
144 u_quad_t ips_redirectsent; /* packets forwarded on same net */
145 u_quad_t ips_noproto; /* unknown or unsupported protocol */
146 u_quad_t ips_delivered; /* datagrams delivered to upper level*/
147 u_quad_t ips_localout; /* total ip packets generated here */
148 u_quad_t ips_odropped; /* lost packets due to nobufs, etc. */
149 u_quad_t ips_reassembled; /* total packets reassembled ok */
150 u_quad_t ips_fragmented; /* datagrams successfully fragmented */
151 u_quad_t ips_ofragments; /* output fragments created */
152 u_quad_t ips_cantfrag; /* don't fragment flag was set, etc. */
153 u_quad_t ips_badoptions; /* error in option processing */
154 u_quad_t ips_noroute; /* packets discarded due to no route */
155 u_quad_t ips_badvers; /* ip version != 4 */
156 u_quad_t ips_rawout; /* total raw ip packets generated */
157 u_quad_t ips_badfrags; /* malformed fragments (bad length) */
158 u_quad_t ips_rcvmemdrop; /* frags dropped for lack of memory */
159 u_quad_t ips_toolong; /* ip length > max ip packet size */
160 u_quad_t ips_nogif; /* no match gif found */
161 u_quad_t ips_badaddr; /* invalid address on header */
162 };
163
164 #define IPFLOW_HASHBITS 6 /* should not be a multiple of 8 */
165 struct ipflow {
166 LIST_ENTRY(ipflow) ipf_list; /* next in active list */
167 LIST_ENTRY(ipflow) ipf_hash; /* next ipflow in bucket */
168 struct in_addr ipf_dst; /* destination address */
169 struct in_addr ipf_src; /* source address */
170 u_int8_t ipf_tos; /* type-of-service */
171 struct route ipf_ro; /* associated route entry */
172 u_long ipf_uses; /* number of uses in this period */
173 u_long ipf_last_uses; /* number of uses in last period */
174 u_long ipf_dropped; /* ENOBUFS returned by if_output */
175 u_long ipf_errors; /* other errors returned by if_output */
176 u_int ipf_timer; /* lifetime timer */
177 time_t ipf_start; /* creation time */
178 };
179
180 #ifdef _KERNEL
181 /* flags passed to ip_output as last parameter */
182 #define IP_FORWARDING 0x1 /* most of ip header exists */
183 #define IP_RAWOUTPUT 0x2 /* raw ip header exists */
184 #define IP_RETURNMTU 0x4 /* pass back mtu on EMSGSIZE */
185 #define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */
186 #define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
187 #define IP_MTUDISC 0x0400 /* Path MTU Discovery; set DF */
188
189 #ifdef __NO_STRICT_ALIGNMENT
190 #define IP_HDR_ALIGNED_P(ip) 1
191 #else
192 #define IP_HDR_ALIGNED_P(ip) ((((vaddr_t) (ip)) & 3) == 0)
193 #endif
194
195 extern struct ipstat ipstat; /* ip statistics */
196 extern LIST_HEAD(ipqhead, ipq) ipq; /* ip reass. queue */
197 extern u_int16_t ip_id; /* ip packet ctr, for ids */
198 extern int ip_defttl; /* default IP ttl */
199 extern int ipforwarding; /* ip forwarding */
200 extern int ip_mtudisc; /* mtu discovery */
201 extern int ip_mtudisc_timeout; /* seconds to timeout mtu discovery */
202 extern int anonportmin; /* minimum ephemeral port */
203 extern int anonportmax; /* maximum ephemeral port */
204 extern int lowportmin; /* minimum reserved port */
205 extern int lowportmax; /* maximum reserved port */
206 extern struct rttimer_queue *ip_mtudisc_timeout_q;
207 #ifdef MBUFTRACE
208 extern struct mowner ip_rx_mowner;
209 extern struct mowner ip_tx_mowner;
210 #endif
211 #ifdef GATEWAY
212 extern int ip_maxflows;
213 #endif
214 extern struct pool inmulti_pool;
215 extern struct pool ipqent_pool;
216 struct inpcb;
217
218 int ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
219 int ip_dooptions __P((struct mbuf *));
220 void ip_drain __P((void));
221 void ip_forward __P((struct mbuf *, int));
222 void ip_freef __P((struct ipq *));
223 void ip_freemoptions __P((struct ip_moptions *));
224 int ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **));
225 void ip_init __P((void));
226 int ip_optcopy __P((struct ip *, struct ip *));
227 u_int ip_optlen __P((struct inpcb *));
228 int ip_output __P((struct mbuf *, ...));
229 int ip_pcbopts __P((struct mbuf **, struct mbuf *));
230 struct mbuf *
231 ip_reass __P((struct ipqent *, struct ipq *));
232 struct in_ifaddr *
233 ip_rtaddr __P((struct in_addr));
234 void ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *,
235 struct mbuf *));
236 int ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *));
237 void ip_slowtimo __P((void));
238 struct mbuf *
239 ip_srcroute __P((void));
240 void ip_stripoptions __P((struct mbuf *, struct mbuf *));
241 int ip_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
242 void ipintr __P((void));
243 void * rip_ctlinput __P((int, struct sockaddr *, void *));
244 int rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
245 void rip_init __P((void));
246 void rip_input __P((struct mbuf *, ...));
247 int rip_output __P((struct mbuf *, ...));
248 int rip_usrreq __P((struct socket *,
249 int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
250 void ipflow_init __P((void));
251 struct ipflow *ipflow_reap __P((int));
252 void ipflow_create __P((const struct route *, struct mbuf *));
253 void ipflow_slowtimo __P((void));
254 #endif
255
256 #endif /* _NETINET_IP_VAR_H_ */
257