#ifdef'ed out definition of sleep() now that nothing uses it. This will
[unix-history] / sys / netinet / in_var.c
CommitLineData
afc905cd
GW
1/*
2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $Id$
34 */
35
36/*
37 * This file attempts to centralize all the various variables that have
38 * a hand in controlling the operation of IP and its ULPs.
39 */
40
41#include "param.h"
42#include "systm.h"
43#include "mbuf.h"
44#include "domain.h"
45#include "protosw.h"
46#include "socket.h"
47#include "time.h"
48#include "net/if.h"
49#include "net/route.h"
50
51#include "in.h"
52#include "in_systm.h"
53#include "ip.h"
54#include "in_pcb.h"
55#include "in_var.h"
56#include "ip_var.h"
57#include "ip_icmp.h"
58#include "icmp_var.h"
59
60
61/*
62 * IPFORWARDING controls whether the IP layer will forward packets received
63 * by us but not addressed to one of our addresses.
64 *
65 * IPSENDREDIRECTS controls whether the IP layer will send ICMP Redirect
66 * messages.
67 *
68 * GATEWAY turns both of these on, and also allocates more memory for some
69 * networking functions.
70 */
71
72#ifndef IPFORWARDING
73#ifdef GATEWAY
74#define IPFORWARDING 1 /* forward IP packets not for us */
75#else /* not GATEWAY */
76#define IPFORWARDING 0 /* don't forward IP packets not for us */
77#endif /* not GATEWAY */
78#endif /* not IPFORWARDING */
79
80/*
81 * NB: RFC 1122, ``Requirements for Internet Hosts: Communication Layers'',
82 * absolutely forbids hosts (which are not acting as gateways) from sending
83 * ICMP redirects.
84 */
85#ifndef IPSENDREDIRECTS
86#ifdef GATEWAY
87#define IPSENDREDIRECTS 1
88#else /* not GATEWAY */
89#define IPSENDREDIRECTS 0
90#endif /* not GATEWAY */
91#endif /* not IPSENDREDIRECTS */
92
93int ipforwarding = IPFORWARDING;
94int ipsendredirects = IPSENDREDIRECTS;
95#ifdef DIAGNOSTIC
96int ipprintfs = 0;
97#endif
98
99/*
100 * ip_protox[] maps from IP protocol number to an index in inetsw[].
101 */
102u_char ip_protox[IPPROTO_MAX];
103
104/*
105 * ipqmaxlen is the maximum length of the IP input queue.
106 * ipintrq is the queue itself.
107 */
108struct ifqueue ipintrq;
109int ipqmaxlen = IFQ_MAXLEN;
110
111/*
112 * the IP reassembly queue
113 */
114struct ipq ipq;
115
116/*
117 * in_ifaddr points to a linked list of IP interface addresses, managed
118 * by the code in in.c.
119 */
120struct in_ifaddr *in_ifaddr; /* first inet address */
121
122/*
123 * statistics for netstat and management
124 */
125struct ipstat ipstat;
126
127/*
128 * ip_id is the next IP packet id number to be assigned (used in fragmentation
129 * and reassembly).
130 */
131u_short ip_id;
132
133/*
134 * When acting as a gateway, the IP layer keeps track of how many packets
135 * are forwarded for each (in-ifp, out-ifp) pair. This code needs to get
136 * updated or junked now that interfaces can come and go like the wind.
137 * (in ip_input.c)
138 */
139#ifdef GATEWAY
140u_long *ip_ifmatrix;
141#endif
142
143/*
144 * ipaddr is a sockaddr_in used by various bits of code when they
145 * need to convert a `struct in_addr' to a `struct sockaddr_in'.
146 *
147 * ipforward_rt is a route used when forwarding packets. It functions
148 * as a route cache of order one, if you want to think of it that way.
149 */
150struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
151struct route ipforward_rt;
152
153/*
154 * inetctlerrmap[] maps control input commands to errno values. 0 means
155 * don't signal error.
156 */
157u_char inetctlerrmap[PRC_NCMDS] = {
158 0, /* ifdown */
159 0, /* routedead */
160 0, /* #2 */
161 0, /* quench2 */
162 0, /* quench */
163 EMSGSIZE, /* msgsize */
164 EHOSTDOWN, /* hostdead */
165 EHOSTUNREACH, /* hostunreach */
166 EHOSTUNREACH, /* unreachnet */
167 EHOSTUNREACH, /* unreachhost */
168 ECONNREFUSED, /* unreachproto */
169 ECONNREFUSED, /* unreachport */
170 EMSGSIZE, /* old needfrag */
171 EHOSTUNREACH, /* srcfail */
172 EHOSTUNREACH, /* netunknown */
173 EHOSTUNREACH, /* hostunknown */
174 EHOSTUNREACH, /* isolated */
175 ECONNREFUSED, /* net admin. prohibited */
176 ECONNREFUSED, /* host admin. prohibited */
177 EHOSTUNREACH, /* tos net unreachable */
178 EHOSTUNREACH, /* tos host unreachable */
179 0, /* redirect net */
180 0, /* redirect host */
181 0, /* redirect tosnet */
182 0, /* redirect toshost */
183 0, /* time exceeded */
184 0, /* reassembly timeout */
185 ENOPROTOOPT, /* parameter problem */
186 ENOPROTOOPT, /* required option missing */
187 0, /* MTU changed */
188 /* NB: this means that this error will only
189 get propagated by in_mtunotify(), which
190 doesn't bother to check. */
191};
192
193/*
194 * SUBNETSARELOCAL determines where IP subnets are considered to be ``local''
195 * or not. This option is obsolete.
196 */
197#ifndef SUBNETSARELOCAL
198#define SUBNETSARELOCAL 1
199#endif
200int subnetsarelocal = SUBNETSARELOCAL;
201
202#ifdef MTUDISC
203/*
204 * MTUTIMER1 is the number of minutes to wait after having incremented
205 * the MTU estimate before trying again. MTUTIMER2 is the number
206 * of minutes to wait after having decremented the MTU estimate
207 * before trying to increment it.
208 */
209#ifndef MTUTIMER1
210#define MTUTIMER1 2
211#endif
212int in_mtutimer1 = MTUTIMER1;
213
214#ifndef MTUTIMER2
215#define MTUTIMER2 10
216#endif
217int in_mtutimer2 = MTUTIMER2;
218#endif /* MTUDISC */
219
220/*
221 * and a zero in_addr to make some code happy...
222 */
223struct in_addr zeroin_addr;
224
225/*
226 * ICMPPRINTFS enables some debugging printfs in ip_icmp.c.
227 *
228 * IPBROADCASTECHO controls whether ICMP Echo Reply packets are sent
229 * in response to ICMP Echo packets which were addressed to a multicast
230 * or broadcast address.
231 *
232 * IPMASKAGENT controls whether ICMP Mask Reply packets are sent.
233 * It should only be enabled on the machine which is the authoritative
234 * mask agent for a subnet.
235 */
236#ifdef ICMPPRINTFS
237int icmpprintfs = 0;
238#endif
239
240#ifndef IPBROADCASTECHO
241#define IPBROADCASTECHO 0
242#endif
243int ipbroadcastecho = IPBROADCASTECHO;
244
245#ifndef IPMASKAGENT
246#define IPMASKAGENT 0
247#endif
248int ipmaskagent = IPMASKAGENT;
249
250/*
251 * ICMP statistics
252 */
253struct icmpstat icmpstat;
254
255/*
256 * Yet Another sockaddr_in filled in by various routines when convenient.
257 */
258struct sockaddr_in icmpmask = { 8, 0 };
259
260/*
261 * Print out TCP debugging messages on the console.
262 */
263#ifdef TCPDEBUG
264int tcpconsdebug = 0;
265#endif
266
267#include "tcp.h"
268#include "tcp_fsm.h"
269#include "tcp_seq.h"
270#include "tcp_timer.h"
271#include "tcp_var.h"
272#include "tcpip.h"
273
274/*
275 * tcp_ttl is the default IP TTL for TCP segments.
276 * tcp_mssdflt is the default max segment size.
277 * tcp_rttdflt is the initial round trip time estimate when there is no RTT
278 * in the route.
279 */
280int tcp_ttl = TCP_TTL;
281int tcp_mssdflt = TCP_MSS;
282int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
283
284/*
285 * When KPROF is defined (god only knows why), TCP keeps track of
286 * protocol requests in this matrix.
287 */
288#ifdef KPROF
289int tcp_acounts[TCP_NSTATES][PRU_NREQ];
290#endif
291
292/*
293 * tcp_keepidle is the a fraction of the length of non-response time in a
294 * in a keepalive situation after which TCP abandons the connection.
295 *
296 * tcp_keepintvl is the interval between keepalives.
297 *
298 * tcp_maxidle is the time after which a connection will be dropped in
299 * certain states. It is computed as `TCPTV_KEEPCNT * tcp_keepintvl'.
300 */
301int tcp_keepidle = TCPTV_KEEP_IDLE;
302int tcp_keepintvl = TCPTV_KEEPINTVL;
303int tcp_maxidle;
304
305/*
306 * tcp_sendspace and tcp_recvspace are the default send and receive window
307 * sizes, respectively. These are obsolescent (this information should
308 * be set by the route).
309 */
310#ifdef TCP_SMALLSPACE
311u_long tcp_sendspace = 1024*4;
312u_long tcp_recvspace = 1024*4;
313#else
314u_long tcp_sendspace = 1024*16;
315u_long tcp_recvspace = 1024*16;
316#endif /* TCP_SMALLSPACE */
317
318#include "udp.h"
319#include "udp_var.h"
320
321/*
322 * udpcksum tells whether to do UDP checksums. It should always be
323 * turned on, except as required for compatibility with ancient
324 * 4.2-based systems like SunOS 3.5 and Ultrix 2.0.
325 */
326#ifndef COMPAT_42
327int udpcksum = 1;
328#else
329int udpcksum = 0; /* XXX */
330#endif
331
332
333/*
334 * udp_ttl is the default IP TTL for UDP packets.
335 */
336int udp_ttl = UDP_TTL;
337
338/*
339 * UDP statistics for netstat.
340 */
341struct udpstat udpstat;
342
343/*
344 * udp_sendspace is the maximum datagram size the UDP layer is willing to
345 * attempt to transmit.
346 *
347 * udp_recvspace is the amount of buffer space the UDP layer will
348 * reserve for holding received packets.
349 */
350u_long udp_sendspace = 9216; /* really max datagram size */
351u_long udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
352 /* 40 1K datagrams */
353
354