VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/tcp_input.c@ 14577

Last change on this file since 14577 was 14577, checked in by vboxsync, 16 years ago

slirp: attempt to fix memory corruption

  • Property svn:eol-style set to native
File size: 73.0 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994
3 * The Regents of the University of California. 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 * @(#)tcp_input.c 8.5 (Berkeley) 4/10/94
34 * tcp_input.c,v 1.10 1994/10/13 18:36:32 wollman Exp
35 */
36
37/*
38 * Changes and additions relating to SLiRP
39 * Copyright (c) 1995 Danny Gasparovski.
40 *
41 * Please read the file COPYRIGHT for the
42 * terms and conditions of the copyright.
43 */
44
45#include <slirp.h>
46#include "ip_icmp.h"
47
48
49#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ)
50
51/* for modulo comparisons of timestamps */
52#define TSTMP_LT(a,b) ((int)((a)-(b)) < 0)
53#define TSTMP_GEQ(a,b) ((int)((a)-(b)) >= 0)
54
55#ifndef VBOX_WITH_BSD_TCP_REASS
56/*
57 * Insert segment ti into reassembly queue of tcp with
58 * control block tp. Return TH_FIN if reassembly now includes
59 * a segment with FIN. The macro form does the common case inline
60 * (segment is the next to be received on an established connection,
61 * and the queue is empty), avoiding linkage into and removal
62 * from the queue and repetition of various conversions.
63 * Set DELACK for segments received in order, but ack immediately
64 * when segments are out of order (so fast retransmit can work).
65 */
66#ifdef TCP_ACK_HACK
67#define TCP_REASS(pData, tp, ti, m, so, flags) {\
68 if ((ti)->ti_seq == (tp)->rcv_nxt && \
69 u32_to_ptr((pData), (tp)->seg_next, struct tcpcb *) == (tp) && \
70 (tp)->t_state == TCPS_ESTABLISHED) {\
71 if (ti->ti_flags & TH_PUSH) \
72 tp->t_flags |= TF_ACKNOW; \
73 else \
74 tp->t_flags |= TF_DELACK; \
75 (tp)->rcv_nxt += (ti)->ti_len; \
76 flags = (ti)->ti_flags & TH_FIN; \
77 tcpstat.tcps_rcvpack++;\
78 tcpstat.tcps_rcvbyte += (ti)->ti_len;\
79 if (so->so_emu) { \
80 if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \
81 } else \
82 sbappend((pData), (so), (m)); \
83/* sorwakeup(so); */ \
84 } else {\
85 (flags) = tcp_reass((pData), (tp), (ti), (m)); \
86 tp->t_flags |= TF_ACKNOW; \
87 } \
88}
89#else
90#define TCP_REASS(pData, tp, ti, m, so, flags) { \
91 if ((ti)->ti_seq == (tp)->rcv_nxt && \
92 u32_to_ptr((pData), (tp)->seg_next, struct tcpcb *) == (tp) && \
93 (tp)->t_state == TCPS_ESTABLISHED) { \
94 tp->t_flags |= TF_DELACK; \
95 (tp)->rcv_nxt += (ti)->ti_len; \
96 flags = (ti)->ti_flags & TH_FIN; \
97 tcpstat.tcps_rcvpack++;\
98 tcpstat.tcps_rcvbyte += (ti)->ti_len;\
99 if (so->so_emu) { \
100 if (tcp_emu((pData), (so),(m))) sbappend((pData), (so), (m)); \
101 } else \
102 sbappend((pData), (so), (m)); \
103/* sorwakeup(so); */ \
104 } else { \
105 (flags) = tcp_reass((pData), (tp), (ti), (m)); \
106 tp->t_flags |= TF_ACKNOW; \
107 } \
108}
109#endif
110
111int
112tcp_reass(PNATState pData, register struct tcpcb *tp, register struct tcpiphdr *ti, struct mbuf *m)
113{
114 register struct tcpiphdr *q;
115 struct socket *so = tp->t_socket;
116 int flags;
117
118 /*
119 * Call with ti==0 after become established to
120 * force pre-ESTABLISHED data up to user socket.
121 */
122 if (ti == 0)
123 goto present;
124
125 /*
126 * Find a segment which begins after this one does.
127 */
128 for (q = u32_to_ptr(pData, tp->seg_next, struct tcpiphdr *); q != (struct tcpiphdr *)tp;
129 q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *))
130 if (SEQ_GT(q->ti_seq, ti->ti_seq))
131 break;
132
133 /*
134 * If there is a preceding segment, it may provide some of
135 * our data already. If so, drop the data from the incoming
136 * segment. If it provides all of our data, drop us.
137 */
138 if (u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *) != (struct tcpiphdr *)tp) {
139 register int i;
140 q = u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *);
141 /* conversion to int (in i) handles seq wraparound */
142 i = q->ti_seq + q->ti_len - ti->ti_seq;
143 if (i > 0) {
144 if (i >= ti->ti_len) {
145 tcpstat.tcps_rcvduppack++;
146 tcpstat.tcps_rcvdupbyte += ti->ti_len;
147 m_freem(pData, m);
148 /*
149 * Try to present any queued data
150 * at the left window edge to the user.
151 * This is needed after the 3-WHS
152 * completes.
153 */
154 goto present; /* ??? */
155 }
156 m_adj(m, i);
157 ti->ti_len -= i;
158 ti->ti_seq += i;
159 }
160 q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *);
161 }
162 tcpstat.tcps_rcvoopack++;
163 tcpstat.tcps_rcvoobyte += ti->ti_len;
164 REASS_MBUF_SET(ti, m); /* XXX */
165
166 /*
167 * While we overlap succeeding segments trim them or,
168 * if they are completely covered, dequeue them.
169 */
170 while (q != (struct tcpiphdr *)tp) {
171 register int i = (ti->ti_seq + ti->ti_len) - q->ti_seq;
172 if (i <= 0)
173 break;
174 if (i < q->ti_len) {
175 q->ti_seq += i;
176 q->ti_len -= i;
177 m_adj(REASS_MBUF_GET(q), i);
178 break;
179 }
180 q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *);
181 m = REASS_MBUF_GET(u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
182 remque_32(pData, u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
183 m_freem(pData, m);
184 }
185
186 /*
187 * Stick new segment in its place.
188 */
189 insque_32(pData, ti, u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
190
191present:
192 /*
193 * Present data to user, advancing rcv_nxt through
194 * completed sequence space.
195 */
196 if (!TCPS_HAVEESTABLISHED(tp->t_state))
197 return (0);
198 ti = u32_to_ptr(pData, tp->seg_next, struct tcpiphdr *);
199 if (ti == (struct tcpiphdr *)tp || ti->ti_seq != tp->rcv_nxt)
200 return (0);
201 if (tp->t_state == TCPS_SYN_RECEIVED && ti->ti_len)
202 return (0);
203 do {
204 tp->rcv_nxt += ti->ti_len;
205 flags = ti->ti_flags & TH_FIN;
206 remque_32(pData, ti);
207 m = REASS_MBUF_GET(ti); /* XXX */
208 ti = u32_to_ptr(pData, ti->ti_next, struct tcpiphdr *);
209/* if (so->so_state & SS_FCANTRCVMORE) */
210 if (so->so_state & SS_FCANTSENDMORE)
211 m_freem(pData, m);
212 else {
213 if (so->so_emu) {
214 if (tcp_emu(pData, so,m)) sbappend(pData, so, m);
215 } else
216 sbappend(pData, so, m);
217 }
218 } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt);
219/* sorwakeup(so); */
220 return (flags);
221}
222
223#else /* VBOX_WITH_BSD_TCP_REASS */
224
225#ifndef TCP_ACK_HACK
226#define DELAY_ACK(tp, ti) \
227 if (ti->ti_flags & TH_PUSH) \
228 tp->t_flags |= TF_ACKNOW; \
229 else \
230 tp->t_flags |= TF_DELACK;
231#else /* !TCP_ACK_HACK */
232#define DELAY_ACK(tp, ign) \
233 tp->t_flags |= TF_DELACK;
234#endif /* TCP_ACK_HACK */
235
236
237/*
238 * deps: netinet/tcp_reass.c
239 * tcp_reass_maxqlen = 48 (deafault)
240 * tcp_reass_maxseg = nmbclusters/16 (nmbclusters = 1024 + maxusers * 64 from kern/kern_mbuf.c let's say 256)
241 */
242int
243tcp_reass(PNATState pData, struct tcpcb *tp, struct tcphdr *th, int *tlenp, struct mbuf *m)
244{
245 struct tseg_qent *q;
246 struct tseg_qent *p = NULL;
247 struct tseg_qent *nq;
248 struct tseg_qent *te = NULL;
249 struct socket *so = tp->t_socket;
250 int flags;
251
252 /*
253 * XXX: tcp_reass() is rather inefficient with its data structures
254 * and should be rewritten (see NetBSD for optimizations). While
255 * doing that it should move to its own file tcp_reass.c.
256 */
257
258 /*
259 * Call with th==NULL after become established to
260 * force pre-ESTABLISHED data up to user socket.
261 */
262 if (th == NULL)
263 goto present;
264
265 /*
266 * Limit the number of segments in the reassembly queue to prevent
267 * holding on to too many segments (and thus running out of mbufs).
268 * Make sure to let the missing segment through which caused this
269 * queue. Always keep one global queue entry spare to be able to
270 * process the missing segment.
271 */
272 if (th->th_seq != tp->rcv_nxt &&
273 (tcp_reass_qsize + 1 >= tcp_reass_maxseg ||
274 tp->t_segqlen >= tcp_reass_maxqlen)) {
275 tcp_reass_overflows++;
276 tcpstat.tcps_rcvmemdrop++;
277 m_freem(pData, m);
278 *tlenp = 0;
279 return (0);
280 }
281
282 /*
283 * Allocate a new queue entry. If we can't, or hit the zone limit
284 * just drop the pkt.
285 */
286 te = malloc(sizeof(struct tseg_qent));
287 if (te == NULL) {
288 tcpstat.tcps_rcvmemdrop++;
289 m_freem(pData, m);
290 *tlenp = 0;
291 return (0);
292 }
293 tp->t_segqlen++;
294 tcp_reass_qsize++;
295
296 /*
297 * Find a segment which begins after this one does.
298 */
299 LIST_FOREACH(q, &tp->t_segq, tqe_q) {
300 if (SEQ_GT(q->tqe_th->th_seq, th->th_seq))
301 break;
302 p = q;
303 }
304
305 /*
306 * If there is a preceding segment, it may provide some of
307 * our data already. If so, drop the data from the incoming
308 * segment. If it provides all of our data, drop us.
309 */
310 if (p != NULL) {
311 int i;
312 /* conversion to int (in i) handles seq wraparound */
313 i = p->tqe_th->th_seq + p->tqe_len - th->th_seq;
314 if (i > 0) {
315 if (i >= *tlenp) {
316 tcpstat.tcps_rcvduppack++;
317 tcpstat.tcps_rcvdupbyte += *tlenp;
318 m_freem(pData, m);
319 free(te);
320 tp->t_segqlen--;
321 tcp_reass_qsize--;
322 /*
323 * Try to present any queued data
324 * at the left window edge to the user.
325 * This is needed after the 3-WHS
326 * completes.
327 */
328 goto present; /* ??? */
329 }
330 m_adj(m, i);
331 *tlenp -= i;
332 th->th_seq += i;
333 }
334 }
335 tcpstat.tcps_rcvoopack++;
336 tcpstat.tcps_rcvoobyte += *tlenp;
337
338 /*
339 * While we overlap succeeding segments trim them or,
340 * if they are completely covered, dequeue them.
341 */
342 while (q) {
343 int i = (th->th_seq + *tlenp) - q->tqe_th->th_seq;
344 if (i <= 0)
345 break;
346 if (i < q->tqe_len) {
347 q->tqe_th->th_seq += i;
348 q->tqe_len -= i;
349 m_adj(q->tqe_m, i);
350 break;
351 }
352
353 nq = LIST_NEXT(q, tqe_q);
354 LIST_REMOVE(q, tqe_q);
355 m_freem(pData, q->tqe_m);
356 free(q);
357 tp->t_segqlen--;
358 tcp_reass_qsize--;
359 q = nq;
360 }
361
362 /* Insert the new segment queue entry into place. */
363 te->tqe_m = m;
364 te->tqe_th = th;
365 te->tqe_len = *tlenp;
366
367 if (p == NULL) {
368 LIST_INSERT_HEAD(&tp->t_segq, te, tqe_q);
369 } else {
370 LIST_INSERT_AFTER(p, te, tqe_q);
371 }
372
373present:
374 /*
375 * Present data to user, advancing rcv_nxt through
376 * completed sequence space.
377 */
378 if (!TCPS_HAVEESTABLISHED(tp->t_state))
379 return (0);
380 q = LIST_FIRST(&tp->t_segq);
381 if (!q || q->tqe_th->th_seq != tp->rcv_nxt)
382 return (0);
383 do {
384 tp->rcv_nxt += q->tqe_len;
385 flags = q->tqe_th->th_flags & TH_FIN;
386 nq = LIST_NEXT(q, tqe_q);
387 LIST_REMOVE(q, tqe_q);
388 /* XXX: This place should be checked for the same code in
389 * original BSD code for Slirp and current BSD used SS_FCANTRCVMORE
390 */
391 if (so->so_state & SS_FCANTSENDMORE)
392 m_freem(pData, q->tqe_m);
393 else
394 sbappend(pData, so, q->tqe_m);
395 free(q);
396 tp->t_segqlen--;
397 tcp_reass_qsize--;
398 q = nq;
399 } while (q && q->tqe_th->th_seq == tp->rcv_nxt);
400 return (flags);
401}
402#endif /* VBOX_WITH_BSD_TCP_REASS */
403
404/*
405 * TCP input routine, follows pages 65-76 of the
406 * protocol specification dated September, 1981 very closely.
407 */
408void
409tcp_input(PNATState pData, register struct mbuf *m, int iphlen, struct socket *inso)
410{
411 struct ip save_ip, *ip;
412 register struct tcpiphdr *ti;
413 caddr_t optp = NULL;
414 int optlen = 0;
415 int len, tlen, off;
416 register struct tcpcb *tp = 0;
417 register int tiflags;
418 struct socket *so = 0;
419 int todrop, acked, ourfinisacked, needoutput = 0;
420/* int dropsocket = 0; */
421 int iss = 0;
422 u_long tiwin;
423/* int ts_present = 0; */
424
425 DEBUG_CALL("tcp_input");
426 DEBUG_ARGS((dfd," m = %8lx iphlen = %2d inso = %lx\n",
427 (long )m, iphlen, (long )inso ));
428
429 /*
430 * If called with m == 0, then we're continuing the connect
431 */
432 if (m == NULL) {
433 so = inso;
434
435 /* Re-set a few variables */
436 tp = sototcpcb(so);
437 m = so->so_m;
438 so->so_m = 0;
439 ti = so->so_ti;
440 tiwin = ti->ti_win;
441 tiflags = ti->ti_flags;
442
443 goto cont_conn;
444 }
445
446
447 tcpstat.tcps_rcvtotal++;
448 /*
449 * Get IP and TCP header together in first mbuf.
450 * Note: IP leaves IP header in first mbuf.
451 */
452 ti = mtod(m, struct tcpiphdr *);
453 if (iphlen > sizeof(struct ip )) {
454 ip_stripoptions(m, (struct mbuf *)0);
455 iphlen=sizeof(struct ip );
456 }
457 /* XXX Check if too short */
458
459
460 /*
461 * Save a copy of the IP header in case we want restore it
462 * for sending an ICMP error message in response.
463 */
464 ip=mtod(m, struct ip *);
465 save_ip = *ip;
466 save_ip.ip_len+= iphlen;
467
468 /*
469 * Checksum extended TCP header and data.
470 */
471 tlen = ((struct ip *)ti)->ip_len;
472 ti->ti_next = ti->ti_prev = 0;
473 ti->ti_x1 = 0;
474 ti->ti_len = htons((u_int16_t)tlen);
475 len = sizeof(struct ip ) + tlen;
476 /* keep checksum for ICMP reply
477 * ti->ti_sum = cksum(m, len);
478 * if (ti->ti_sum) { */
479 if(cksum(m, len)) {
480 tcpstat.tcps_rcvbadsum++;
481 goto drop;
482 }
483
484 /*
485 * Check that TCP offset makes sense,
486 * pull out TCP options and adjust length. XXX
487 */
488 off = ti->ti_off << 2;
489 if (off < sizeof (struct tcphdr) || off > tlen) {
490 tcpstat.tcps_rcvbadoff++;
491 goto drop;
492 }
493 tlen -= off;
494 ti->ti_len = tlen;
495 if (off > sizeof (struct tcphdr)) {
496 optlen = off - sizeof (struct tcphdr);
497 optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
498
499 /*
500 * Do quick retrieval of timestamp options ("options
501 * prediction?"). If timestamp is the only option and it's
502 * formatted as recommended in RFC 1323 appendix A, we
503 * quickly get the values now and not bother calling
504 * tcp_dooptions(), etc.
505 */
506/* if ((optlen == TCPOLEN_TSTAMP_APPA ||
507 * (optlen > TCPOLEN_TSTAMP_APPA &&
508 * optp[TCPOLEN_TSTAMP_APPA] == TCPOPT_EOL)) &&
509 * *(u_int32_t *)optp == htonl(TCPOPT_TSTAMP_HDR) &&
510 * (ti->ti_flags & TH_SYN) == 0) {
511 * ts_present = 1;
512 * ts_val = ntohl(*(u_int32_t *)(optp + 4));
513 * ts_ecr = ntohl(*(u_int32_t *)(optp + 8));
514 * optp = NULL; / * we've parsed the options * /
515 * }
516 */
517 }
518 tiflags = ti->ti_flags;
519
520 /*
521 * Convert TCP protocol specific fields to host format.
522 */
523 NTOHL(ti->ti_seq);
524 NTOHL(ti->ti_ack);
525 NTOHS(ti->ti_win);
526 NTOHS(ti->ti_urp);
527
528 /*
529 * Drop TCP, IP headers and TCP options.
530 */
531 m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
532 m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
533
534 /*
535 * Locate pcb for segment.
536 */
537findso:
538 so = tcp_last_so;
539 if (so->so_fport != ti->ti_dport ||
540 so->so_lport != ti->ti_sport ||
541 so->so_laddr.s_addr != ti->ti_src.s_addr ||
542 so->so_faddr.s_addr != ti->ti_dst.s_addr) {
543 so = solookup(&tcb, ti->ti_src, ti->ti_sport,
544 ti->ti_dst, ti->ti_dport);
545 if (so)
546 tcp_last_so = so;
547 ++tcpstat.tcps_socachemiss;
548 }
549
550 /*
551 * If the state is CLOSED (i.e., TCB does not exist) then
552 * all data in the incoming segment is discarded.
553 * If the TCB exists but is in CLOSED state, it is embryonic,
554 * but should either do a listen or a connect soon.
555 *
556 * state == CLOSED means we've done socreate() but haven't
557 * attached it to a protocol yet...
558 *
559 * XXX If a TCB does not exist, and the TH_SYN flag is
560 * the only flag set, then create a session, mark it
561 * as if it was LISTENING, and continue...
562 */
563 if (so == 0) {
564 if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN)
565 goto dropwithreset;
566
567 if ((so = socreate()) == NULL)
568 goto dropwithreset;
569 if (tcp_attach(pData, so) < 0) {
570 free(so); /* Not sofree (if it failed, it's not insqued) */
571 goto dropwithreset;
572 }
573
574 sbreserve(&so->so_snd, tcp_sndspace);
575 sbreserve(&so->so_rcv, tcp_rcvspace);
576
577 /* tcp_last_so = so; */ /* XXX ? */
578 /* tp = sototcpcb(so); */
579
580 so->so_laddr = ti->ti_src;
581 so->so_lport = ti->ti_sport;
582 so->so_faddr = ti->ti_dst;
583 so->so_fport = ti->ti_dport;
584
585 if ((so->so_iptos = tcp_tos(so)) == 0)
586 so->so_iptos = ((struct ip *)ti)->ip_tos;
587
588 tp = sototcpcb(so);
589 tp->t_state = TCPS_LISTEN;
590 }
591
592 /*
593 * If this is a still-connecting socket, this probably
594 * a retransmit of the SYN. Whether it's a retransmit SYN
595 * or something else, we nuke it.
596 */
597 if (so->so_state & SS_ISFCONNECTING)
598 goto drop;
599
600 tp = sototcpcb(so);
601
602 /* XXX Should never fail */
603 if (tp == 0)
604 goto dropwithreset;
605 if (tp->t_state == TCPS_CLOSED)
606 goto drop;
607
608 /* Unscale the window into a 32-bit value. */
609/* if ((tiflags & TH_SYN) == 0)
610 * tiwin = ti->ti_win << tp->snd_scale;
611 * else
612 */
613 tiwin = ti->ti_win;
614
615 /*
616 * Segment received on connection.
617 * Reset idle time and keep-alive timer.
618 */
619 tp->t_idle = 0;
620 if (so_options)
621 tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
622 else
623 tp->t_timer[TCPT_KEEP] = tcp_keepidle;
624
625 /*
626 * Process options if not in LISTEN state,
627 * else do it below (after getting remote address).
628 */
629 if (optp && tp->t_state != TCPS_LISTEN)
630 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
631/* , */
632/* &ts_present, &ts_val, &ts_ecr); */
633
634 /*
635 * Header prediction: check for the two common cases
636 * of a uni-directional data xfer. If the packet has
637 * no control flags, is in-sequence, the window didn't
638 * change and we're not retransmitting, it's a
639 * candidate. If the length is zero and the ack moved
640 * forward, we're the sender side of the xfer. Just
641 * free the data acked & wake any higher level process
642 * that was blocked waiting for space. If the length
643 * is non-zero and the ack didn't move, we're the
644 * receiver side. If we're getting packets in-order
645 * (the reassembly queue is empty), add the data to
646 * the socket buffer and note that we need a delayed ack.
647 *
648 * XXX Some of these tests are not needed
649 * eg: the tiwin == tp->snd_wnd prevents many more
650 * predictions.. with no *real* advantage..
651 */
652 if (tp->t_state == TCPS_ESTABLISHED &&
653 (tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK &&
654/* (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) && */
655 ti->ti_seq == tp->rcv_nxt &&
656 tiwin && tiwin == tp->snd_wnd &&
657 tp->snd_nxt == tp->snd_max) {
658 /*
659 * If last ACK falls within this segment's sequence numbers,
660 * record the timestamp.
661 */
662/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
663 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len)) {
664 * tp->ts_recent_age = tcp_now;
665 * tp->ts_recent = ts_val;
666 * }
667 */
668 if (ti->ti_len == 0) {
669 if (SEQ_GT(ti->ti_ack, tp->snd_una) &&
670 SEQ_LEQ(ti->ti_ack, tp->snd_max) &&
671 tp->snd_cwnd >= tp->snd_wnd) {
672 /*
673 * this is a pure ack for outstanding data.
674 */
675 ++tcpstat.tcps_predack;
676/* if (ts_present)
677 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
678 * else
679 */ if (tp->t_rtt &&
680 SEQ_GT(ti->ti_ack, tp->t_rtseq))
681 tcp_xmit_timer(pData, tp, tp->t_rtt);
682 acked = ti->ti_ack - tp->snd_una;
683 tcpstat.tcps_rcvackpack++;
684 tcpstat.tcps_rcvackbyte += acked;
685 sbdrop(&so->so_snd, acked);
686 tp->snd_una = ti->ti_ack;
687 m_freem(pData, m);
688
689 /*
690 * If all outstanding data are acked, stop
691 * retransmit timer, otherwise restart timer
692 * using current (possibly backed-off) value.
693 * If process is waiting for space,
694 * wakeup/selwakeup/signal. If data
695 * are ready to send, let tcp_output
696 * decide between more output or persist.
697 */
698 if (tp->snd_una == tp->snd_max)
699 tp->t_timer[TCPT_REXMT] = 0;
700 else if (tp->t_timer[TCPT_PERSIST] == 0)
701 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
702
703 /*
704 * There's room in so_snd, sowwakup will read()
705 * from the socket if we can
706 */
707/* if (so->so_snd.sb_flags & SB_NOTIFY)
708 * sowwakeup(so);
709 */
710 /*
711 * This is called because sowwakeup might have
712 * put data into so_snd. Since we don't so sowwakeup,
713 * we don't need this.. XXX???
714 */
715 if (so->so_snd.sb_cc)
716 (void) tcp_output(pData, tp);
717
718 return;
719 }
720 } else if (ti->ti_ack == tp->snd_una &&
721#ifndef VBOX_WITH_BSD_TCP_REASS
722 u32_to_ptr(pData, tp->seg_next, struct tcpcb *) == tp &&
723#else /* VBOX_WITH_BSD_TCP_REASS */
724 LIST_FIRST(&tp->t_segq) &&
725#endif /* VBOX_WITH_BSD_TCP_REASS */
726 ti->ti_len <= sbspace(&so->so_rcv)) {
727 /*
728 * this is a pure, in-sequence data packet
729 * with nothing on the reassembly queue and
730 * we have enough buffer space to take it.
731 */
732 ++tcpstat.tcps_preddat;
733 tp->rcv_nxt += ti->ti_len;
734 tcpstat.tcps_rcvpack++;
735 tcpstat.tcps_rcvbyte += ti->ti_len;
736 /*
737 * Add data to socket buffer.
738 */
739 if (so->so_emu) {
740 if (tcp_emu(pData, so,m)) sbappend(pData, so, m);
741 } else
742 sbappend(pData, so, m);
743
744 /*
745 * XXX This is called when data arrives. Later, check
746 * if we can actually write() to the socket
747 * XXX Need to check? It's be NON_BLOCKING
748 */
749/* sorwakeup(so); */
750
751 /*
752 * If this is a short packet, then ACK now - with Nagel
753 * congestion avoidance sender won't send more until
754 * he gets an ACK.
755 *
756 * It is better to not delay acks at all to maximize
757 * TCP throughput. See RFC 2581.
758 */
759 tp->t_flags |= TF_ACKNOW;
760 tcp_output(pData, tp);
761 return;
762 }
763 } /* header prediction */
764 /*
765 * Calculate amount of space in receive window,
766 * and then do TCP input processing.
767 * Receive window is amount of space in rcv queue,
768 * but not less than advertised window.
769 */
770 { int win;
771 win = sbspace(&so->so_rcv);
772 if (win < 0)
773 win = 0;
774 tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
775 }
776
777 switch (tp->t_state) {
778
779 /*
780 * If the state is LISTEN then ignore segment if it contains an RST.
781 * If the segment contains an ACK then it is bad and send a RST.
782 * If it does not contain a SYN then it is not interesting; drop it.
783 * Don't bother responding if the destination was a broadcast.
784 * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
785 * tp->iss, and send a segment:
786 * <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
787 * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
788 * Fill in remote peer address fields if not previously specified.
789 * Enter SYN_RECEIVED state, and process any other fields of this
790 * segment in this state.
791 */
792 case TCPS_LISTEN: {
793
794 if (tiflags & TH_RST)
795 goto drop;
796 if (tiflags & TH_ACK)
797 goto dropwithreset;
798 if ((tiflags & TH_SYN) == 0)
799 goto drop;
800
801 /*
802 * This has way too many gotos...
803 * But a bit of spaghetti code never hurt anybody :)
804 */
805
806 if (so->so_emu & EMU_NOCONNECT) {
807 so->so_emu &= ~EMU_NOCONNECT;
808 goto cont_input;
809 }
810
811 if((tcp_fconnect(pData, so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
812 u_char code=ICMP_UNREACH_NET;
813 DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n",
814 errno,strerror(errno)));
815 if(errno == ECONNREFUSED) {
816 /* ACK the SYN, send RST to refuse the connection */
817 tcp_respond(pData, tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
818 TH_RST|TH_ACK);
819 } else {
820 if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
821 HTONL(ti->ti_seq); /* restore tcp header */
822 HTONL(ti->ti_ack);
823 HTONS(ti->ti_win);
824 HTONS(ti->ti_urp);
825 m->m_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
826 m->m_len += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
827 *ip=save_ip;
828 icmp_error(pData, m, ICMP_UNREACH,code, 0,strerror(errno));
829 }
830 tp = tcp_close(pData, tp);
831 m_free(pData, m);
832 } else {
833 /*
834 * Haven't connected yet, save the current mbuf
835 * and ti, and return
836 * XXX Some OS's don't tell us whether the connect()
837 * succeeded or not. So we must time it out.
838 */
839 so->so_m = m;
840 so->so_ti = ti;
841 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
842 tp->t_state = TCPS_SYN_RECEIVED;
843 }
844 return;
845
846 cont_conn:
847 /* m==NULL
848 * Check if the connect succeeded
849 */
850 if (so->so_state & SS_NOFDREF) {
851 tp = tcp_close(pData, tp);
852 goto dropwithreset;
853 }
854 cont_input:
855 tcp_template(tp);
856
857 if (optp)
858 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
859 /* , */
860 /* &ts_present, &ts_val, &ts_ecr); */
861
862 if (iss)
863 tp->iss = iss;
864 else
865 tp->iss = tcp_iss;
866 tcp_iss += TCP_ISSINCR/2;
867 tp->irs = ti->ti_seq;
868 tcp_sendseqinit(tp);
869 tcp_rcvseqinit(tp);
870 tp->t_flags |= TF_ACKNOW;
871 tp->t_state = TCPS_SYN_RECEIVED;
872 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
873 tcpstat.tcps_accepts++;
874 goto trimthenstep6;
875 } /* case TCPS_LISTEN */
876
877 /*
878 * If the state is SYN_SENT:
879 * if seg contains an ACK, but not for our SYN, drop the input.
880 * if seg contains a RST, then drop the connection.
881 * if seg does not contain SYN, then drop it.
882 * Otherwise this is an acceptable SYN segment
883 * initialize tp->rcv_nxt and tp->irs
884 * if seg contains ack then advance tp->snd_una
885 * if SYN has been acked change to ESTABLISHED else SYN_RCVD state
886 * arrange for segment to be acked (eventually)
887 * continue processing rest of data/controls, beginning with URG
888 */
889 case TCPS_SYN_SENT:
890 if ((tiflags & TH_ACK) &&
891 (SEQ_LEQ(ti->ti_ack, tp->iss) ||
892 SEQ_GT(ti->ti_ack, tp->snd_max)))
893 goto dropwithreset;
894
895 if (tiflags & TH_RST) {
896 if (tiflags & TH_ACK)
897 tp = tcp_drop(pData, tp,0); /* XXX Check t_softerror! */
898 goto drop;
899 }
900
901 if ((tiflags & TH_SYN) == 0)
902 goto drop;
903 if (tiflags & TH_ACK) {
904 tp->snd_una = ti->ti_ack;
905 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
906 tp->snd_nxt = tp->snd_una;
907 }
908
909 tp->t_timer[TCPT_REXMT] = 0;
910 tp->irs = ti->ti_seq;
911 tcp_rcvseqinit(tp);
912 tp->t_flags |= TF_ACKNOW;
913 if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) {
914 tcpstat.tcps_connects++;
915 soisfconnected(so);
916 tp->t_state = TCPS_ESTABLISHED;
917
918 /* Do window scaling on this connection? */
919/* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
920 * (TF_RCVD_SCALE|TF_REQ_SCALE)) {
921 * tp->snd_scale = tp->requested_s_scale;
922 * tp->rcv_scale = tp->request_r_scale;
923 * }
924 */
925#ifndef VBOX_WITH_BSD_TCP_REASS
926 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0,
927 (struct mbuf *)0);
928#else /* VBOX_WITH_BSD_TCP_REASS */
929 (void) tcp_reass(pData, tp, (struct tcphdr *)0, NULL, (struct mbuf *)0);
930#endif /* VBOX_WITH_BSD_TCP_REASS */
931 /*
932 * if we didn't have to retransmit the SYN,
933 * use its rtt as our initial srtt & rtt var.
934 */
935 if (tp->t_rtt)
936 tcp_xmit_timer(pData, tp, tp->t_rtt);
937 } else
938 tp->t_state = TCPS_SYN_RECEIVED;
939
940trimthenstep6:
941 /*
942 * Advance ti->ti_seq to correspond to first data byte.
943 * If data, trim to stay within window,
944 * dropping FIN if necessary.
945 */
946 ti->ti_seq++;
947 if (ti->ti_len > tp->rcv_wnd) {
948 todrop = ti->ti_len - tp->rcv_wnd;
949 m_adj(m, -todrop);
950 ti->ti_len = tp->rcv_wnd;
951 tiflags &= ~TH_FIN;
952 tcpstat.tcps_rcvpackafterwin++;
953 tcpstat.tcps_rcvbyteafterwin += todrop;
954 }
955 tp->snd_wl1 = ti->ti_seq - 1;
956 tp->rcv_up = ti->ti_seq;
957 goto step6;
958 } /* switch tp->t_state */
959 /*
960 * States other than LISTEN or SYN_SENT.
961 * First check timestamp, if present.
962 * Then check that at least some bytes of segment are within
963 * receive window. If segment begins before rcv_nxt,
964 * drop leading data (and SYN); if nothing left, just ack.
965 *
966 * RFC 1323 PAWS: If we have a timestamp reply on this segment
967 * and it's less than ts_recent, drop it.
968 */
969/* if (ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent &&
970 * TSTMP_LT(ts_val, tp->ts_recent)) {
971 *
972 */ /* Check to see if ts_recent is over 24 days old. */
973/* if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
974 */ /*
975 * * Invalidate ts_recent. If this segment updates
976 * * ts_recent, the age will be reset later and ts_recent
977 * * will get a valid value. If it does not, setting
978 * * ts_recent to zero will at least satisfy the
979 * * requirement that zero be placed in the timestamp
980 * * echo reply when ts_recent isn't valid. The
981 * * age isn't reset until we get a valid ts_recent
982 * * because we don't want out-of-order segments to be
983 * * dropped when ts_recent is old.
984 * */
985/* tp->ts_recent = 0;
986 * } else {
987 * tcpstat.tcps_rcvduppack++;
988 * tcpstat.tcps_rcvdupbyte += ti->ti_len;
989 * tcpstat.tcps_pawsdrop++;
990 * goto dropafterack;
991 * }
992 * }
993 */
994
995 todrop = tp->rcv_nxt - ti->ti_seq;
996 if (todrop > 0) {
997 if (tiflags & TH_SYN) {
998 tiflags &= ~TH_SYN;
999 ti->ti_seq++;
1000 if (ti->ti_urp > 1)
1001 ti->ti_urp--;
1002 else
1003 tiflags &= ~TH_URG;
1004 todrop--;
1005 }
1006 /*
1007 * Following if statement from Stevens, vol. 2, p. 960.
1008 */
1009 if (todrop > ti->ti_len
1010 || (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) {
1011 /*
1012 * Any valid FIN must be to the left of the window.
1013 * At this point the FIN must be a duplicate or out
1014 * of sequence; drop it.
1015 */
1016 tiflags &= ~TH_FIN;
1017
1018 /*
1019 * Send an ACK to resynchronize and drop any data.
1020 * But keep on processing for RST or ACK.
1021 */
1022 tp->t_flags |= TF_ACKNOW;
1023 todrop = ti->ti_len;
1024 tcpstat.tcps_rcvduppack++;
1025 tcpstat.tcps_rcvdupbyte += todrop;
1026 } else {
1027 tcpstat.tcps_rcvpartduppack++;
1028 tcpstat.tcps_rcvpartdupbyte += todrop;
1029 }
1030 m_adj(m, todrop);
1031 ti->ti_seq += todrop;
1032 ti->ti_len -= todrop;
1033 if (ti->ti_urp > todrop)
1034 ti->ti_urp -= todrop;
1035 else {
1036 tiflags &= ~TH_URG;
1037 ti->ti_urp = 0;
1038 }
1039 }
1040 /*
1041 * If new data are received on a connection after the
1042 * user processes are gone, then RST the other end.
1043 */
1044 if ((so->so_state & SS_NOFDREF) &&
1045 tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
1046 tp = tcp_close(pData, tp);
1047 tcpstat.tcps_rcvafterclose++;
1048 goto dropwithreset;
1049 }
1050
1051 /*
1052 * If segment ends after window, drop trailing data
1053 * (and PUSH and FIN); if nothing left, just ACK.
1054 */
1055 todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
1056 if (todrop > 0) {
1057 tcpstat.tcps_rcvpackafterwin++;
1058 if (todrop >= ti->ti_len) {
1059 tcpstat.tcps_rcvbyteafterwin += ti->ti_len;
1060 /*
1061 * If a new connection request is received
1062 * while in TIME_WAIT, drop the old connection
1063 * and start over if the sequence numbers
1064 * are above the previous ones.
1065 */
1066 if (tiflags & TH_SYN &&
1067 tp->t_state == TCPS_TIME_WAIT &&
1068 SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
1069 iss = tp->rcv_nxt + TCP_ISSINCR;
1070 tp = tcp_close(pData, tp);
1071 goto findso;
1072 }
1073 /*
1074 * If window is closed can only take segments at
1075 * window edge, and have to drop data and PUSH from
1076 * incoming segments. Continue processing, but
1077 * remember to ack. Otherwise, drop segment
1078 * and ack.
1079 */
1080 if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) {
1081 tp->t_flags |= TF_ACKNOW;
1082 tcpstat.tcps_rcvwinprobe++;
1083 } else
1084 goto dropafterack;
1085 } else
1086 tcpstat.tcps_rcvbyteafterwin += todrop;
1087 m_adj(m, -todrop);
1088 ti->ti_len -= todrop;
1089 tiflags &= ~(TH_PUSH|TH_FIN);
1090 }
1091
1092 /*
1093 * If last ACK falls within this segment's sequence numbers,
1094 * record its timestamp.
1095 */
1096/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
1097 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len +
1098 * ((tiflags & (TH_SYN|TH_FIN)) != 0))) {
1099 * tp->ts_recent_age = tcp_now;
1100 * tp->ts_recent = ts_val;
1101 * }
1102 */
1103
1104 /*
1105 * If the RST bit is set examine the state:
1106 * SYN_RECEIVED STATE:
1107 * If passive open, return to LISTEN state.
1108 * If active open, inform user that connection was refused.
1109 * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
1110 * Inform user that connection was reset, and close tcb.
1111 * CLOSING, LAST_ACK, TIME_WAIT STATES
1112 * Close the tcb.
1113 */
1114 if (tiflags&TH_RST) switch (tp->t_state) {
1115
1116 case TCPS_SYN_RECEIVED:
1117/* so->so_error = ECONNREFUSED; */
1118 goto close;
1119
1120 case TCPS_ESTABLISHED:
1121 case TCPS_FIN_WAIT_1:
1122 case TCPS_FIN_WAIT_2:
1123 case TCPS_CLOSE_WAIT:
1124/* so->so_error = ECONNRESET; */
1125 close:
1126 tp->t_state = TCPS_CLOSED;
1127 tcpstat.tcps_drops++;
1128 tp = tcp_close(pData, tp);
1129 goto drop;
1130
1131 case TCPS_CLOSING:
1132 case TCPS_LAST_ACK:
1133 case TCPS_TIME_WAIT:
1134 tp = tcp_close(pData, tp);
1135 goto drop;
1136 }
1137
1138 /*
1139 * If a SYN is in the window, then this is an
1140 * error and we send an RST and drop the connection.
1141 */
1142 if (tiflags & TH_SYN) {
1143 tp = tcp_drop(pData, tp,0);
1144 goto dropwithreset;
1145 }
1146
1147 /*
1148 * If the ACK bit is off we drop the segment and return.
1149 */
1150 if ((tiflags & TH_ACK) == 0) goto drop;
1151
1152 /*
1153 * Ack processing.
1154 */
1155 switch (tp->t_state) {
1156 /*
1157 * In SYN_RECEIVED state if the ack ACKs our SYN then enter
1158 * ESTABLISHED state and continue processing, otherwise
1159 * send an RST. una<=ack<=max
1160 */
1161 case TCPS_SYN_RECEIVED:
1162
1163 if (SEQ_GT(tp->snd_una, ti->ti_ack) ||
1164 SEQ_GT(ti->ti_ack, tp->snd_max))
1165 goto dropwithreset;
1166 tcpstat.tcps_connects++;
1167 tp->t_state = TCPS_ESTABLISHED;
1168 /*
1169 * The sent SYN is ack'ed with our sequence number +1
1170 * The first data byte already in the buffer will get
1171 * lost if no correction is made. This is only needed for
1172 * SS_CTL since the buffer is empty otherwise.
1173 * tp->snd_una++; or:
1174 */
1175 tp->snd_una=ti->ti_ack;
1176 soisfconnected(so);
1177
1178 /* Do window scaling? */
1179/* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
1180 * (TF_RCVD_SCALE|TF_REQ_SCALE)) {
1181 * tp->snd_scale = tp->requested_s_scale;
1182 * tp->rcv_scale = tp->request_r_scale;
1183 * }
1184 */
1185#ifndef VBOX_WITH_BSD_TCP_REASS
1186 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0, (struct mbuf *)0);
1187#else /* VBOX_WITH_BSD_TCP_REASS */
1188 (void) tcp_reass(pData, tp, (struct tcphdr *)0, (int *)0, (struct mbuf *)0);
1189#endif /*VBOX_WITH_BSD_TCP_REASS*/
1190 tp->snd_wl1 = ti->ti_seq - 1;
1191 /* Avoid ack processing; snd_una==ti_ack => dup ack */
1192 goto synrx_to_est;
1193 /* fall into ... */
1194
1195 /*
1196 * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
1197 * ACKs. If the ack is in the range
1198 * tp->snd_una < ti->ti_ack <= tp->snd_max
1199 * then advance tp->snd_una to ti->ti_ack and drop
1200 * data from the retransmission queue. If this ACK reflects
1201 * more up to date window information we update our window information.
1202 */
1203 case TCPS_ESTABLISHED:
1204 case TCPS_FIN_WAIT_1:
1205 case TCPS_FIN_WAIT_2:
1206 case TCPS_CLOSE_WAIT:
1207 case TCPS_CLOSING:
1208 case TCPS_LAST_ACK:
1209 case TCPS_TIME_WAIT:
1210
1211 if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
1212 if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
1213 tcpstat.tcps_rcvdupack++;
1214 DEBUG_MISC((dfd," dup ack m = %lx so = %lx \n",
1215 (long )m, (long )so));
1216 /*
1217 * If we have outstanding data (other than
1218 * a window probe), this is a completely
1219 * duplicate ack (ie, window info didn't
1220 * change), the ack is the biggest we've
1221 * seen and we've seen exactly our rexmt
1222 * threshold of them, assume a packet
1223 * has been dropped and retransmit it.
1224 * Kludge snd_nxt & the congestion
1225 * window so we send only this one
1226 * packet.
1227 *
1228 * We know we're losing at the current
1229 * window size so do congestion avoidance
1230 * (set ssthresh to half the current window
1231 * and pull our congestion window back to
1232 * the new ssthresh).
1233 *
1234 * Dup acks mean that packets have left the
1235 * network (they're now cached at the receiver)
1236 * so bump cwnd by the amount in the receiver
1237 * to keep a constant cwnd packets in the
1238 * network.
1239 */
1240 if (tp->t_timer[TCPT_REXMT] == 0 ||
1241 ti->ti_ack != tp->snd_una)
1242 tp->t_dupacks = 0;
1243 else if (++tp->t_dupacks == tcprexmtthresh) {
1244 tcp_seq onxt = tp->snd_nxt;
1245 u_int win =
1246 min(tp->snd_wnd, tp->snd_cwnd) / 2 /
1247 tp->t_maxseg;
1248
1249 if (win < 2)
1250 win = 2;
1251 tp->snd_ssthresh = win * tp->t_maxseg;
1252 tp->t_timer[TCPT_REXMT] = 0;
1253 tp->t_rtt = 0;
1254 tp->snd_nxt = ti->ti_ack;
1255 tp->snd_cwnd = tp->t_maxseg;
1256 (void) tcp_output(pData, tp);
1257 tp->snd_cwnd = tp->snd_ssthresh +
1258 tp->t_maxseg * tp->t_dupacks;
1259 if (SEQ_GT(onxt, tp->snd_nxt))
1260 tp->snd_nxt = onxt;
1261 goto drop;
1262 } else if (tp->t_dupacks > tcprexmtthresh) {
1263 tp->snd_cwnd += tp->t_maxseg;
1264 (void) tcp_output(pData, tp);
1265 goto drop;
1266 }
1267 } else
1268 tp->t_dupacks = 0;
1269 break;
1270 }
1271 synrx_to_est:
1272 /*
1273 * If the congestion window was inflated to account
1274 * for the other side's cached packets, retract it.
1275 */
1276 if (tp->t_dupacks > tcprexmtthresh &&
1277 tp->snd_cwnd > tp->snd_ssthresh)
1278 tp->snd_cwnd = tp->snd_ssthresh;
1279 tp->t_dupacks = 0;
1280 if (SEQ_GT(ti->ti_ack, tp->snd_max)) {
1281 tcpstat.tcps_rcvacktoomuch++;
1282 goto dropafterack;
1283 }
1284 acked = ti->ti_ack - tp->snd_una;
1285 tcpstat.tcps_rcvackpack++;
1286 tcpstat.tcps_rcvackbyte += acked;
1287
1288 /*
1289 * If we have a timestamp reply, update smoothed
1290 * round trip time. If no timestamp is present but
1291 * transmit timer is running and timed sequence
1292 * number was acked, update smoothed round trip time.
1293 * Since we now have an rtt measurement, cancel the
1294 * timer backoff (cf., Phil Karn's retransmit alg.).
1295 * Recompute the initial retransmit timer.
1296 */
1297/* if (ts_present)
1298 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
1299 * else
1300 */
1301 if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
1302 tcp_xmit_timer(pData, tp,tp->t_rtt);
1303
1304 /*
1305 * If all outstanding data is acked, stop retransmit
1306 * timer and remember to restart (more output or persist).
1307 * If there is more data to be acked, restart retransmit
1308 * timer, using current (possibly backed-off) value.
1309 */
1310 if (ti->ti_ack == tp->snd_max) {
1311 tp->t_timer[TCPT_REXMT] = 0;
1312 needoutput = 1;
1313 } else if (tp->t_timer[TCPT_PERSIST] == 0)
1314 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1315 /*
1316 * When new data is acked, open the congestion window.
1317 * If the window gives us less than ssthresh packets
1318 * in flight, open exponentially (maxseg per packet).
1319 * Otherwise open linearly: maxseg per window
1320 * (maxseg^2 / cwnd per packet).
1321 */
1322 {
1323 register u_int cw = tp->snd_cwnd;
1324 register u_int incr = tp->t_maxseg;
1325
1326 if (cw > tp->snd_ssthresh)
1327 incr = incr * incr / cw;
1328 tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
1329 }
1330 if (acked > so->so_snd.sb_cc) {
1331 tp->snd_wnd -= so->so_snd.sb_cc;
1332 sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
1333 ourfinisacked = 1;
1334 } else {
1335 sbdrop(&so->so_snd, acked);
1336 tp->snd_wnd -= acked;
1337 ourfinisacked = 0;
1338 }
1339 /*
1340 * XXX sowwakup is called when data is acked and there's room for
1341 * for more data... it should read() the socket
1342 */
1343/* if (so->so_snd.sb_flags & SB_NOTIFY)
1344 * sowwakeup(so);
1345 */
1346 tp->snd_una = ti->ti_ack;
1347 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
1348 tp->snd_nxt = tp->snd_una;
1349
1350 switch (tp->t_state) {
1351
1352 /*
1353 * In FIN_WAIT_1 STATE in addition to the processing
1354 * for the ESTABLISHED state if our FIN is now acknowledged
1355 * then enter FIN_WAIT_2.
1356 */
1357 case TCPS_FIN_WAIT_1:
1358 if (ourfinisacked) {
1359 /*
1360 * If we can't receive any more
1361 * data, then closing user can proceed.
1362 * Starting the timer is contrary to the
1363 * specification, but if we don't get a FIN
1364 * we'll hang forever.
1365 */
1366 if (so->so_state & SS_FCANTRCVMORE) {
1367 soisfdisconnected(so);
1368 tp->t_timer[TCPT_2MSL] = tcp_maxidle;
1369 }
1370 tp->t_state = TCPS_FIN_WAIT_2;
1371 }
1372 break;
1373
1374 /*
1375 * In CLOSING STATE in addition to the processing for
1376 * the ESTABLISHED state if the ACK acknowledges our FIN
1377 * then enter the TIME-WAIT state, otherwise ignore
1378 * the segment.
1379 */
1380 case TCPS_CLOSING:
1381 if (ourfinisacked) {
1382 tp->t_state = TCPS_TIME_WAIT;
1383 tcp_canceltimers(tp);
1384 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1385 soisfdisconnected(so);
1386 }
1387 break;
1388
1389 /*
1390 * In LAST_ACK, we may still be waiting for data to drain
1391 * and/or to be acked, as well as for the ack of our FIN.
1392 * If our FIN is now acknowledged, delete the TCB,
1393 * enter the closed state and return.
1394 */
1395 case TCPS_LAST_ACK:
1396 if (ourfinisacked) {
1397 tp = tcp_close(pData, tp);
1398 goto drop;
1399 }
1400 break;
1401
1402 /*
1403 * In TIME_WAIT state the only thing that should arrive
1404 * is a retransmission of the remote FIN. Acknowledge
1405 * it and restart the finack timer.
1406 */
1407 case TCPS_TIME_WAIT:
1408 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1409 goto dropafterack;
1410 }
1411 } /* switch(tp->t_state) */
1412
1413step6:
1414 /*
1415 * Update window information.
1416 * Don't look at window if no ACK: TAC's send garbage on first SYN.
1417 */
1418 if ((tiflags & TH_ACK) &&
1419 (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
1420 (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
1421 (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
1422 /* keep track of pure window updates */
1423 if (ti->ti_len == 0 &&
1424 tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)
1425 tcpstat.tcps_rcvwinupd++;
1426 tp->snd_wnd = tiwin;
1427 tp->snd_wl1 = ti->ti_seq;
1428 tp->snd_wl2 = ti->ti_ack;
1429 if (tp->snd_wnd > tp->max_sndwnd)
1430 tp->max_sndwnd = tp->snd_wnd;
1431 needoutput = 1;
1432 }
1433
1434 /*
1435 * Process segments with URG.
1436 */
1437 if ((tiflags & TH_URG) && ti->ti_urp &&
1438 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1439 /*
1440 * This is a kludge, but if we receive and accept
1441 * random urgent pointers, we'll crash in
1442 * soreceive. It's hard to imagine someone
1443 * actually wanting to send this much urgent data.
1444 */
1445 if (ti->ti_urp + so->so_rcv.sb_cc > so->so_rcv.sb_datalen) {
1446 ti->ti_urp = 0;
1447 tiflags &= ~TH_URG;
1448 goto dodata;
1449 }
1450 /*
1451 * If this segment advances the known urgent pointer,
1452 * then mark the data stream. This should not happen
1453 * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
1454 * a FIN has been received from the remote side.
1455 * In these states we ignore the URG.
1456 *
1457 * According to RFC961 (Assigned Protocols),
1458 * the urgent pointer points to the last octet
1459 * of urgent data. We continue, however,
1460 * to consider it to indicate the first octet
1461 * of data past the urgent section as the original
1462 * spec states (in one of two places).
1463 */
1464 if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) {
1465 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1466 so->so_urgc = so->so_rcv.sb_cc +
1467 (tp->rcv_up - tp->rcv_nxt); /* -1; */
1468 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1469
1470 }
1471 } else
1472 /*
1473 * If no out of band data is expected,
1474 * pull receive urgent pointer along
1475 * with the receive window.
1476 */
1477 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
1478 tp->rcv_up = tp->rcv_nxt;
1479dodata:
1480
1481 /*
1482 * If this is a small packet, then ACK now - with Nagel
1483 * congestion avoidance sender won't send more until
1484 * he gets an ACK.
1485 *
1486 * See above.
1487 */
1488 if (ti->ti_len && (unsigned)ti->ti_len <= 5 &&
1489 ((struct tcpiphdr_2 *)ti)->first_char == (char)27) {
1490 tp->t_flags |= TF_ACKNOW;
1491 }
1492
1493 /*
1494 * Process the segment text, merging it into the TCP sequencing queue,
1495 * and arranging for acknowledgment of receipt if necessary.
1496 * This process logically involves adjusting tp->rcv_wnd as data
1497 * is presented to the user (this happens in tcp_usrreq.c,
1498 * case PRU_RCVD). If a FIN has already been received on this
1499 * connection then we just ignore the text.
1500 */
1501 if ((ti->ti_len || (tiflags&TH_FIN)) &&
1502 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1503#ifndef VBOX_WITH_BSD_TCP_REASS
1504 TCP_REASS(pData, tp, ti, m, so, tiflags);
1505#else /* VBOX_WITH_BSD_TCP_REASS */
1506 if (ti->ti_seq == tp->rcv_nxt
1507 && LIST_EMPTY(&tp->t_segq)
1508 && tp->t_state == TCPS_ESTABLISHED) {
1509 DELAY_ACK(tp, ti); /* little bit different from BSD declaration see netinet/tcp_input.c */
1510 tp->rcv_nxt += tlen;
1511 tiflags = ti->ti_t.th_flags & TH_FIN;
1512 tcpstat.tcps_rcvpack++;
1513 tcpstat.tcps_rcvbyte += tlen;
1514 if (so->so_state & SS_FCANTRCVMORE)
1515 m_freem(pData, m);
1516 else
1517 sbappend(pData, so, m);
1518 }
1519 else {
1520 tiflags = tcp_reass(pData, tp, &ti->ti_t, &tlen, m);
1521 tiflags |= TF_ACKNOW;
1522 }
1523#endif /* VBOX_WITH_BSD_TCP_REASS */
1524 /*
1525 * Note the amount of data that peer has sent into
1526 * our window, in order to estimate the sender's
1527 * buffer size.
1528 */
1529 len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt);
1530 } else {
1531 m_free(pData, m);
1532 tiflags &= ~TH_FIN;
1533 }
1534
1535 /*
1536 * If FIN is received ACK the FIN and let the user know
1537 * that the connection is closing.
1538 */
1539 if (tiflags & TH_FIN) {
1540 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1541 /*
1542 * If we receive a FIN we can't send more data,
1543 * set it SS_FDRAIN
1544 * Shutdown the socket if there is no rx data in the
1545 * buffer.
1546 * soread() is called on completion of shutdown() and
1547 * will got to TCPS_LAST_ACK, and use tcp_output()
1548 * to send the FIN.
1549 */
1550/* sofcantrcvmore(so); */
1551 sofwdrain(so);
1552
1553 tp->t_flags |= TF_ACKNOW;
1554 tp->rcv_nxt++;
1555 }
1556 switch (tp->t_state) {
1557
1558 /*
1559 * In SYN_RECEIVED and ESTABLISHED STATES
1560 * enter the CLOSE_WAIT state.
1561 */
1562 case TCPS_SYN_RECEIVED:
1563 case TCPS_ESTABLISHED:
1564 if(so->so_emu == EMU_CTL) /* no shutdown on socket */
1565 tp->t_state = TCPS_LAST_ACK;
1566 else
1567 tp->t_state = TCPS_CLOSE_WAIT;
1568 break;
1569
1570 /*
1571 * If still in FIN_WAIT_1 STATE FIN has not been acked so
1572 * enter the CLOSING state.
1573 */
1574 case TCPS_FIN_WAIT_1:
1575 tp->t_state = TCPS_CLOSING;
1576 break;
1577
1578 /*
1579 * In FIN_WAIT_2 state enter the TIME_WAIT state,
1580 * starting the time-wait timer, turning off the other
1581 * standard timers.
1582 */
1583 case TCPS_FIN_WAIT_2:
1584 tp->t_state = TCPS_TIME_WAIT;
1585 tcp_canceltimers(tp);
1586 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1587 soisfdisconnected(so);
1588 break;
1589
1590 /*
1591 * In TIME_WAIT state restart the 2 MSL time_wait timer.
1592 */
1593 case TCPS_TIME_WAIT:
1594 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1595 break;
1596 }
1597 }
1598
1599 /*
1600 * Return any desired output.
1601 */
1602 if (needoutput || (tp->t_flags & TF_ACKNOW)) {
1603 (void) tcp_output(pData, tp);
1604 }
1605 return;
1606
1607dropafterack:
1608 /*
1609 * Generate an ACK dropping incoming segment if it occupies
1610 * sequence space, where the ACK reflects our state.
1611 */
1612 if (tiflags & TH_RST)
1613 goto drop;
1614 m_freem(pData, m);
1615 tp->t_flags |= TF_ACKNOW;
1616 (void) tcp_output(pData, tp);
1617 return;
1618
1619dropwithreset:
1620 /* reuses m if m!=NULL, m_free() unnecessary */
1621 if (tiflags & TH_ACK)
1622 tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
1623 else {
1624 if (tiflags & TH_SYN) ti->ti_len++;
1625 tcp_respond(pData, tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
1626 TH_RST|TH_ACK);
1627 }
1628
1629 return;
1630
1631drop:
1632 /*
1633 * Drop space held by incoming segment and return.
1634 */
1635 m_free(pData, m);
1636
1637 return;
1638}
1639
1640 /* , ts_present, ts_val, ts_ecr) */
1641/* int *ts_present;
1642 * u_int32_t *ts_val, *ts_ecr;
1643 */
1644void
1645tcp_dooptions(PNATState pData, struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
1646{
1647 u_int16_t mss;
1648 int opt, optlen;
1649
1650 DEBUG_CALL("tcp_dooptions");
1651 DEBUG_ARGS((dfd," tp = %lx cnt=%i \n", (long )tp, cnt));
1652
1653 for (; cnt > 0; cnt -= optlen, cp += optlen) {
1654 opt = cp[0];
1655 if (opt == TCPOPT_EOL)
1656 break;
1657 if (opt == TCPOPT_NOP)
1658 optlen = 1;
1659 else {
1660 optlen = cp[1];
1661 if (optlen <= 0)
1662 break;
1663 }
1664 switch (opt) {
1665
1666 default:
1667 continue;
1668
1669 case TCPOPT_MAXSEG:
1670 if (optlen != TCPOLEN_MAXSEG)
1671 continue;
1672 if (!(ti->ti_flags & TH_SYN))
1673 continue;
1674 memcpy((char *) &mss, (char *) cp + 2, sizeof(mss));
1675 NTOHS(mss);
1676 (void) tcp_mss(pData, tp, mss); /* sets t_maxseg */
1677 break;
1678
1679/* case TCPOPT_WINDOW:
1680 * if (optlen != TCPOLEN_WINDOW)
1681 * continue;
1682 * if (!(ti->ti_flags & TH_SYN))
1683 * continue;
1684 * tp->t_flags |= TF_RCVD_SCALE;
1685 * tp->requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
1686 * break;
1687 */
1688/* case TCPOPT_TIMESTAMP:
1689 * if (optlen != TCPOLEN_TIMESTAMP)
1690 * continue;
1691 * *ts_present = 1;
1692 * memcpy((char *) ts_val, (char *)cp + 2, sizeof(*ts_val));
1693 * NTOHL(*ts_val);
1694 * memcpy((char *) ts_ecr, (char *)cp + 6, sizeof(*ts_ecr));
1695 * NTOHL(*ts_ecr);
1696 *
1697 */ /*
1698 * * A timestamp received in a SYN makes
1699 * * it ok to send timestamp requests and replies.
1700 * */
1701/* if (ti->ti_flags & TH_SYN) {
1702 * tp->t_flags |= TF_RCVD_TSTMP;
1703 * tp->ts_recent = *ts_val;
1704 * tp->ts_recent_age = tcp_now;
1705 * }
1706 */ break;
1707 }
1708 }
1709}
1710
1711
1712/*
1713 * Pull out of band byte out of a segment so
1714 * it doesn't appear in the user's data queue.
1715 * It is still reflected in the segment length for
1716 * sequencing purposes.
1717 */
1718
1719#ifdef notdef
1720
1721void
1722tcp_pulloutofband(so, ti, m)
1723 struct socket *so;
1724 struct tcpiphdr *ti;
1725 register struct mbuf *m;
1726{
1727 int cnt = ti->ti_urp - 1;
1728
1729 while (cnt >= 0) {
1730 if (m->m_len > cnt) {
1731 char *cp = mtod(m, caddr_t) + cnt;
1732 struct tcpcb *tp = sototcpcb(so);
1733
1734 tp->t_iobc = *cp;
1735 tp->t_oobflags |= TCPOOB_HAVEDATA;
1736 memcpy(sp, cp+1, (unsigned)(m->m_len - cnt - 1));
1737 m->m_len--;
1738 return;
1739 }
1740 cnt -= m->m_len;
1741 m = m->m_next; /* XXX WRONG! Fix it! */
1742 if (m == 0)
1743 break;
1744 }
1745 panic("tcp_pulloutofband");
1746}
1747
1748#endif /* notdef */
1749
1750/*
1751 * Collect new round-trip time estimate
1752 * and update averages and current timeout.
1753 */
1754
1755void
1756tcp_xmit_timer(PNATState pData, register struct tcpcb *tp, int rtt)
1757{
1758 register short delta;
1759
1760 DEBUG_CALL("tcp_xmit_timer");
1761 DEBUG_ARG("tp = %lx", (long)tp);
1762 DEBUG_ARG("rtt = %d", rtt);
1763
1764 tcpstat.tcps_rttupdated++;
1765 if (tp->t_srtt != 0) {
1766 /*
1767 * srtt is stored as fixed point with 3 bits after the
1768 * binary point (i.e., scaled by 8). The following magic
1769 * is equivalent to the smoothing algorithm in rfc793 with
1770 * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
1771 * point). Adjust rtt to origin 0.
1772 */
1773 delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT);
1774 if ((tp->t_srtt += delta) <= 0)
1775 tp->t_srtt = 1;
1776 /*
1777 * We accumulate a smoothed rtt variance (actually, a
1778 * smoothed mean difference), then set the retransmit
1779 * timer to smoothed rtt + 4 times the smoothed variance.
1780 * rttvar is stored as fixed point with 2 bits after the
1781 * binary point (scaled by 4). The following is
1782 * equivalent to rfc793 smoothing with an alpha of .75
1783 * (rttvar = rttvar*3/4 + |delta| / 4). This replaces
1784 * rfc793's wired-in beta.
1785 */
1786 if (delta < 0)
1787 delta = -delta;
1788 delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT);
1789 if ((tp->t_rttvar += delta) <= 0)
1790 tp->t_rttvar = 1;
1791 } else {
1792 /*
1793 * No rtt measurement yet - use the unsmoothed rtt.
1794 * Set the variance to half the rtt (so our first
1795 * retransmit happens at 3*rtt).
1796 */
1797 tp->t_srtt = rtt << TCP_RTT_SHIFT;
1798 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
1799 }
1800 tp->t_rtt = 0;
1801 tp->t_rxtshift = 0;
1802
1803 /*
1804 * the retransmit should happen at rtt + 4 * rttvar.
1805 * Because of the way we do the smoothing, srtt and rttvar
1806 * will each average +1/2 tick of bias. When we compute
1807 * the retransmit timer, we want 1/2 tick of rounding and
1808 * 1 extra tick because of +-1/2 tick uncertainty in the
1809 * firing of the timer. The bias will give us exactly the
1810 * 1.5 tick we need. But, because the bias is
1811 * statistical, we have to test that we don't drop below
1812 * the minimum feasible timer (which is 2 ticks).
1813 */
1814 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
1815 (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */
1816
1817 /*
1818 * We received an ack for a packet that wasn't retransmitted;
1819 * it is probably safe to discard any error indications we've
1820 * received recently. This isn't quite right, but close enough
1821 * for now (a route might have failed after we sent a segment,
1822 * and the return path might not be symmetrical).
1823 */
1824 tp->t_softerror = 0;
1825}
1826
1827/*
1828 * Determine a reasonable value for maxseg size.
1829 * If the route is known, check route for mtu.
1830 * If none, use an mss that can be handled on the outgoing
1831 * interface without forcing IP to fragment; if bigger than
1832 * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES
1833 * to utilize large mbufs. If no route is found, route has no mtu,
1834 * or the destination isn't local, use a default, hopefully conservative
1835 * size (usually 512 or the default IP max size, but no more than the mtu
1836 * of the interface), as we can't discover anything about intervening
1837 * gateways or networks. We also initialize the congestion/slow start
1838 * window to be a single segment if the destination isn't local.
1839 * While looking at the routing entry, we also initialize other path-dependent
1840 * parameters from pre-set or cached values in the routing entry.
1841 */
1842
1843int
1844tcp_mss(PNATState pData, register struct tcpcb *tp, u_int offer)
1845{
1846 struct socket *so = tp->t_socket;
1847 int mss;
1848
1849 DEBUG_CALL("tcp_mss");
1850 DEBUG_ARG("tp = %lx", (long)tp);
1851 DEBUG_ARG("offer = %d", offer);
1852
1853 mss = min(if_mtu, if_mru) - sizeof(struct tcpiphdr);
1854 if (offer)
1855 mss = min(mss, offer);
1856 mss = max(mss, 32);
1857 if (mss < tp->t_maxseg || offer != 0)
1858 tp->t_maxseg = mss;
1859
1860 tp->snd_cwnd = mss;
1861
1862 sbreserve(&so->so_snd, tcp_sndspace+((tcp_sndspace%mss)?(mss-(tcp_sndspace%mss)):0));
1863 sbreserve(&so->so_rcv, tcp_rcvspace+((tcp_rcvspace%mss)?(mss-(tcp_rcvspace%mss)):0));
1864
1865 DEBUG_MISC((dfd, " returning mss = %d\n", mss));
1866
1867 return mss;
1868}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette