ip_var.h revision 1.101 1 /* $NetBSD: ip_var.h,v 1.101 2014/05/22 22:01:12 rmind 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
32 */
33
34 #ifndef _NETINET_IP_VAR_H_
35 #define _NETINET_IP_VAR_H_
36
37 #include <sys/queue.h>
38 #include <net/route.h>
39
40 /*
41 * Overlay for ip header used by other protocols (tcp, udp).
42 */
43 struct ipovly {
44 u_int8_t ih_x1[9]; /* (unused) */
45 u_int8_t ih_pr; /* protocol */
46 u_int16_t ih_len; /* protocol length */
47 struct in_addr ih_src; /* source internet address */
48 struct in_addr ih_dst; /* destination internet address */
49 } __packed;
50
51 /*
52 * IP Flow structure
53 */
54 struct ipflow {
55 LIST_ENTRY(ipflow) ipf_list; /* next in active list */
56 LIST_ENTRY(ipflow) ipf_hash; /* next ipflow in bucket */
57 struct in_addr ipf_dst; /* destination address */
58 struct in_addr ipf_src; /* source address */
59 uint8_t ipf_tos; /* type-of-service */
60 struct route ipf_ro; /* associated route entry */
61 u_long ipf_uses; /* number of uses in this period */
62 u_long ipf_last_uses; /* number of uses in last period */
63 u_long ipf_dropped; /* ENOBUFS retured by if_output */
64 u_long ipf_errors; /* other errors returned by if_output */
65 u_int ipf_timer; /* lifetime timer */
66 };
67
68 /*
69 * IP sequence queue structure.
70 *
71 * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
72 * We want to avoid doing m_pullup on incoming packets but that
73 * means avoiding dtom on the tcp reassembly code. That in turn means
74 * keeping an mbuf pointer in the reassembly queue (since we might
75 * have a cluster). As a quick hack, the source & destination
76 * port numbers (which are no longer needed once we've located the
77 * tcpcb) are overlayed with an mbuf pointer.
78 */
79 TAILQ_HEAD(ipqehead, ipqent);
80 struct ipqent {
81 TAILQ_ENTRY(ipqent) ipqe_q;
82 union {
83 struct ip *_ip;
84 struct tcpiphdr *_tcp;
85 } _ipqe_u1;
86 struct mbuf *ipqe_m; /* point to first mbuf */
87 struct mbuf *ipre_mlast; /* point to last mbuf */
88 u_int8_t ipqe_mff; /* for IP fragmentation */
89 /*
90 * The following are used in TCP reassembly
91 */
92 TAILQ_ENTRY(ipqent) ipqe_timeq;
93 u_int32_t ipqe_seq;
94 u_int32_t ipqe_len;
95 u_int32_t ipqe_flags;
96 };
97 #define ipqe_tcp _ipqe_u1._tcp
98
99 /*
100 * Structure stored in mbuf in inpcb.ip_options
101 * and passed to ip_output when ip options are in use.
102 * The actual length of the options (including ipopt_dst)
103 * is in m_len.
104 */
105 #define MAX_IPOPTLEN 40
106
107 struct ipoption {
108 struct in_addr ipopt_dst; /* first-hop dst if source routed */
109 int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
110 };
111
112 /*
113 * Structure attached to inpcb.ip_moptions and
114 * passed to ip_output when IP multicast options are in use.
115 */
116 struct ip_moptions {
117 struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
118 struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
119 u_int8_t imo_multicast_ttl; /* TTL for outgoing multicasts */
120 u_int8_t imo_multicast_loop; /* 1 => hear sends if a member */
121 u_int16_t imo_num_memberships; /* no. memberships this socket */
122 struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
123 };
124
125 /*
126 * IP statistics.
127 * Each counter is an unsigned 64-bit value.
128 */
129 #define IP_STAT_TOTAL 0 /* total packets received */
130 #define IP_STAT_BADSUM 1 /* checksum bad */
131 #define IP_STAT_TOOSHORT 2 /* packet too short */
132 #define IP_STAT_TOOSMALL 3 /* not enough data */
133 #define IP_STAT_BADHLEN 4 /* ip header length < data size */
134 #define IP_STAT_BADLEN 5 /* ip length < ip header length */
135 #define IP_STAT_FRAGMENTS 6 /* fragments received */
136 #define IP_STAT_FRAGDROPPED 7 /* frags dropped (dups, out of space) */
137 #define IP_STAT_FRAGTIMEOUT 8 /* fragments timed out */
138 #define IP_STAT_FORWARD 9 /* packets forwarded */
139 #define IP_STAT_FASTFORWARD 10 /* packets fast forwarded */
140 #define IP_STAT_CANTFORWARD 11 /* packets rcvd for unreachable dest */
141 #define IP_STAT_REDIRECTSENT 12 /* packets forwareded on same net */
142 #define IP_STAT_NOPROTO 13 /* unknown or unsupported protocol */
143 #define IP_STAT_DELIVERED 14 /* datagrams delivered to upper level */
144 #define IP_STAT_LOCALOUT 15 /* total ip packets generated here */
145 #define IP_STAT_ODROPPED 16 /* lost packets due to nobufs, etc. */
146 #define IP_STAT_REASSEMBLED 17 /* total packets reassembled ok */
147 #define IP_STAT_FRAGMENTED 18 /* datagrams successfully fragmented */
148 #define IP_STAT_OFRAGMENTS 19 /* output fragments created */
149 #define IP_STAT_CANTFRAG 20 /* don't fragment flag was set, etc. */
150 #define IP_STAT_BADOPTIONS 21 /* error in option processing */
151 #define IP_STAT_NOROUTE 22 /* packets discarded due to no route */
152 #define IP_STAT_BADVERS 23 /* ip version != 4 */
153 #define IP_STAT_RAWOUT 24 /* total raw ip packets generated */
154 #define IP_STAT_BADFRAGS 25 /* malformed fragments (bad length) */
155 #define IP_STAT_RCVMEMDROP 26 /* frags dropped for lack of memory */
156 #define IP_STAT_TOOLONG 27 /* ip length > max ip packet size */
157 #define IP_STAT_NOGIF 28 /* no match gif found */
158 #define IP_STAT_BADADDR 29 /* invalid address on header */
159
160 #define IP_NSTATS 30
161
162 #ifdef _KERNEL
163
164 #ifdef _KERNEL_OPT
165 #include "opt_gateway.h"
166 #include "opt_mbuftrace.h"
167 #endif
168
169 /* flags passed to ip_output as last parameter */
170 #define IP_FORWARDING 0x1 /* most of ip header exists */
171 #define IP_RAWOUTPUT 0x2 /* raw ip header exists */
172 #define IP_RETURNMTU 0x4 /* pass back mtu on EMSGSIZE */
173 #define IP_NOIPNEWID 0x8 /* don't fill in ip_id */
174 #define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */
175 #define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
176 #define IP_MTUDISC 0x0400 /* Path MTU Discovery; set DF */
177
178 extern struct domain inetdomain;
179 extern const struct pr_usrreqs rip_usrreqs;
180
181 extern int ip_defttl; /* default IP ttl */
182 extern int ipforwarding; /* ip forwarding */
183 extern int ip_mtudisc; /* mtu discovery */
184 extern int ip_mtudisc_timeout; /* seconds to timeout mtu discovery */
185 extern int anonportmin; /* minimum ephemeral port */
186 extern int anonportmax; /* maximum ephemeral port */
187 extern int lowportmin; /* minimum reserved port */
188 extern int lowportmax; /* maximum reserved port */
189 extern int ip_do_loopback_cksum; /* do IP checksum on loopback? */
190 extern struct rttimer_queue *ip_mtudisc_timeout_q;
191 #ifdef MBUFTRACE
192 extern struct mowner ip_rx_mowner;
193 extern struct mowner ip_tx_mowner;
194 #endif
195 struct inpcb;
196 struct sockopt;
197
198 void ip_init(void);
199 void in_init(void);
200
201 int ip_ctloutput(int, struct socket *, struct sockopt *);
202 void ip_drain(void);
203 void ip_drainstub(void);
204 void ip_forward(struct mbuf *, int);
205 void ip_freemoptions(struct ip_moptions *);
206 int ip_getmoptions(struct ip_moptions *, struct sockopt *);
207 int ip_optcopy(struct ip *, struct ip *);
208 u_int ip_optlen(struct inpcb *);
209 int ip_output(struct mbuf *, ...);
210 int ip_fragment(struct mbuf *, struct ifnet *, u_long);
211 int ip_pcbopts(struct mbuf **, const struct sockopt *);
212
213 void ip_reass_init(void);
214 int ip_reass_packet(struct mbuf **, struct ip *);
215 void ip_reass_slowtimo(void);
216 void ip_reass_drain(void);
217
218 void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
219 struct mbuf *);
220 int ip_setmoptions(struct ip_moptions **, const struct sockopt *);
221 void ip_slowtimo(void);
222 void ip_fasttimo(void);
223 struct mbuf *
224 ip_srcroute(void);
225 int ip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
226 void ip_statinc(u_int);
227 void ipintr(void);
228 void * rip_ctlinput(int, const struct sockaddr *, void *);
229 int rip_ctloutput(int, struct socket *, struct sockopt *);
230 void rip_init(void);
231 void rip_input(struct mbuf *, ...);
232 int rip_output(struct mbuf *, ...);
233 int rip_usrreq(struct socket *,
234 int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
235
236 /* IP Flow interface. */
237 void ipflow_init(void);
238 void ipflow_poolinit(void);
239 struct ipflow *ipflow_reap(bool);
240 void ipflow_create(const struct route *, struct mbuf *);
241 void ipflow_slowtimo(void);
242 int ipflow_invalidate_all(int);
243
244 #endif /* _KERNEL */
245
246 #endif /* !_NETINET_IP_VAR_H_ */
247