VirtualBox

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

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

NAT: some reformatting for better readability; merged VBOX_WITH_BSD_TCP_REASS with VBOX_WITH_BSD_REASS

  • 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_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_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_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#if !defined(VBOX_WITH_BSD_REASS)
473 ti->ti_next = ti->ti_prev = 0;
474 ti->ti_x1 = 0;
475#else
476 memset(ti->ti_x1, 0, 9);
477#endif
478 ti->ti_len = htons((u_int16_t)tlen);
479 len = sizeof(struct ip ) + tlen;
480 /* keep checksum for ICMP reply
481 * ti->ti_sum = cksum(m, len);
482 * if (ti->ti_sum) { */
483 if(cksum(m, len)) {
484 tcpstat.tcps_rcvbadsum++;
485 goto drop;
486 }
487
488 /*
489 * Check that TCP offset makes sense,
490 * pull out TCP options and adjust length. XXX
491 */
492 off = ti->ti_off << 2;
493 if (off < sizeof (struct tcphdr) || off > tlen) {
494 tcpstat.tcps_rcvbadoff++;
495 goto drop;
496 }
497 tlen -= off;
498 ti->ti_len = tlen;
499 if (off > sizeof (struct tcphdr)) {
500 optlen = off - sizeof (struct tcphdr);
501 optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
502
503 /*
504 * Do quick retrieval of timestamp options ("options
505 * prediction?"). If timestamp is the only option and it's
506 * formatted as recommended in RFC 1323 appendix A, we
507 * quickly get the values now and not bother calling
508 * tcp_dooptions(), etc.
509 */
510/* if ((optlen == TCPOLEN_TSTAMP_APPA ||
511 * (optlen > TCPOLEN_TSTAMP_APPA &&
512 * optp[TCPOLEN_TSTAMP_APPA] == TCPOPT_EOL)) &&
513 * *(u_int32_t *)optp == htonl(TCPOPT_TSTAMP_HDR) &&
514 * (ti->ti_flags & TH_SYN) == 0) {
515 * ts_present = 1;
516 * ts_val = ntohl(*(u_int32_t *)(optp + 4));
517 * ts_ecr = ntohl(*(u_int32_t *)(optp + 8));
518 * optp = NULL; / * we've parsed the options * /
519 * }
520 */
521 }
522 tiflags = ti->ti_flags;
523
524 /*
525 * Convert TCP protocol specific fields to host format.
526 */
527 NTOHL(ti->ti_seq);
528 NTOHL(ti->ti_ack);
529 NTOHS(ti->ti_win);
530 NTOHS(ti->ti_urp);
531
532 /*
533 * Drop TCP, IP headers and TCP options.
534 */
535 m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
536 m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
537
538 /*
539 * Locate pcb for segment.
540 */
541findso:
542 so = tcp_last_so;
543 if (so->so_fport != ti->ti_dport ||
544 so->so_lport != ti->ti_sport ||
545 so->so_laddr.s_addr != ti->ti_src.s_addr ||
546 so->so_faddr.s_addr != ti->ti_dst.s_addr) {
547 so = solookup(&tcb, ti->ti_src, ti->ti_sport,
548 ti->ti_dst, ti->ti_dport);
549 if (so)
550 tcp_last_so = so;
551 ++tcpstat.tcps_socachemiss;
552 }
553
554 /*
555 * If the state is CLOSED (i.e., TCB does not exist) then
556 * all data in the incoming segment is discarded.
557 * If the TCB exists but is in CLOSED state, it is embryonic,
558 * but should either do a listen or a connect soon.
559 *
560 * state == CLOSED means we've done socreate() but haven't
561 * attached it to a protocol yet...
562 *
563 * XXX If a TCB does not exist, and the TH_SYN flag is
564 * the only flag set, then create a session, mark it
565 * as if it was LISTENING, and continue...
566 */
567 if (so == 0) {
568 if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN)
569 goto dropwithreset;
570
571 if ((so = socreate()) == NULL)
572 goto dropwithreset;
573 if (tcp_attach(pData, so) < 0) {
574 free(so); /* Not sofree (if it failed, it's not insqued) */
575 goto dropwithreset;
576 }
577
578 sbreserve(&so->so_snd, tcp_sndspace);
579 sbreserve(&so->so_rcv, tcp_rcvspace);
580
581 /* tcp_last_so = so; */ /* XXX ? */
582 /* tp = sototcpcb(so); */
583
584 so->so_laddr = ti->ti_src;
585 so->so_lport = ti->ti_sport;
586 so->so_faddr = ti->ti_dst;
587 so->so_fport = ti->ti_dport;
588
589 if ((so->so_iptos = tcp_tos(so)) == 0)
590 so->so_iptos = ((struct ip *)ti)->ip_tos;
591
592 tp = sototcpcb(so);
593 tp->t_state = TCPS_LISTEN;
594 }
595
596 /*
597 * If this is a still-connecting socket, this probably
598 * a retransmit of the SYN. Whether it's a retransmit SYN
599 * or something else, we nuke it.
600 */
601 if (so->so_state & SS_ISFCONNECTING)
602 goto drop;
603
604 tp = sototcpcb(so);
605
606 /* XXX Should never fail */
607 if (tp == 0)
608 goto dropwithreset;
609 if (tp->t_state == TCPS_CLOSED)
610 goto drop;
611
612 /* Unscale the window into a 32-bit value. */
613/* if ((tiflags & TH_SYN) == 0)
614 * tiwin = ti->ti_win << tp->snd_scale;
615 * else
616 */
617 tiwin = ti->ti_win;
618
619 /*
620 * Segment received on connection.
621 * Reset idle time and keep-alive timer.
622 */
623 tp->t_idle = 0;
624 if (so_options)
625 tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
626 else
627 tp->t_timer[TCPT_KEEP] = tcp_keepidle;
628
629 /*
630 * Process options if not in LISTEN state,
631 * else do it below (after getting remote address).
632 */
633 if (optp && tp->t_state != TCPS_LISTEN)
634 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
635/* , */
636/* &ts_present, &ts_val, &ts_ecr); */
637
638 /*
639 * Header prediction: check for the two common cases
640 * of a uni-directional data xfer. If the packet has
641 * no control flags, is in-sequence, the window didn't
642 * change and we're not retransmitting, it's a
643 * candidate. If the length is zero and the ack moved
644 * forward, we're the sender side of the xfer. Just
645 * free the data acked & wake any higher level process
646 * that was blocked waiting for space. If the length
647 * is non-zero and the ack didn't move, we're the
648 * receiver side. If we're getting packets in-order
649 * (the reassembly queue is empty), add the data to
650 * the socket buffer and note that we need a delayed ack.
651 *
652 * XXX Some of these tests are not needed
653 * eg: the tiwin == tp->snd_wnd prevents many more
654 * predictions.. with no *real* advantage..
655 */
656 if (tp->t_state == TCPS_ESTABLISHED &&
657 (tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK &&
658/* (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) && */
659 ti->ti_seq == tp->rcv_nxt &&
660 tiwin && tiwin == tp->snd_wnd &&
661 tp->snd_nxt == tp->snd_max) {
662 /*
663 * If last ACK falls within this segment's sequence numbers,
664 * record the timestamp.
665 */
666/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
667 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len)) {
668 * tp->ts_recent_age = tcp_now;
669 * tp->ts_recent = ts_val;
670 * }
671 */
672 if (ti->ti_len == 0) {
673 if (SEQ_GT(ti->ti_ack, tp->snd_una) &&
674 SEQ_LEQ(ti->ti_ack, tp->snd_max) &&
675 tp->snd_cwnd >= tp->snd_wnd) {
676 /*
677 * this is a pure ack for outstanding data.
678 */
679 ++tcpstat.tcps_predack;
680/* if (ts_present)
681 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
682 * else
683 */ if (tp->t_rtt &&
684 SEQ_GT(ti->ti_ack, tp->t_rtseq))
685 tcp_xmit_timer(pData, tp, tp->t_rtt);
686 acked = ti->ti_ack - tp->snd_una;
687 tcpstat.tcps_rcvackpack++;
688 tcpstat.tcps_rcvackbyte += acked;
689 sbdrop(&so->so_snd, acked);
690 tp->snd_una = ti->ti_ack;
691 m_freem(pData, m);
692
693 /*
694 * If all outstanding data are acked, stop
695 * retransmit timer, otherwise restart timer
696 * using current (possibly backed-off) value.
697 * If process is waiting for space,
698 * wakeup/selwakeup/signal. If data
699 * are ready to send, let tcp_output
700 * decide between more output or persist.
701 */
702 if (tp->snd_una == tp->snd_max)
703 tp->t_timer[TCPT_REXMT] = 0;
704 else if (tp->t_timer[TCPT_PERSIST] == 0)
705 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
706
707 /*
708 * There's room in so_snd, sowwakup will read()
709 * from the socket if we can
710 */
711/* if (so->so_snd.sb_flags & SB_NOTIFY)
712 * sowwakeup(so);
713 */
714 /*
715 * This is called because sowwakeup might have
716 * put data into so_snd. Since we don't so sowwakeup,
717 * we don't need this.. XXX???
718 */
719 if (so->so_snd.sb_cc)
720 (void) tcp_output(pData, tp);
721
722 return;
723 }
724 } else if (ti->ti_ack == tp->snd_una &&
725#ifndef VBOX_WITH_BSD_REASS
726 u32_to_ptr(pData, tp->seg_next, struct tcpcb *) == tp &&
727#else /* VBOX_WITH_BSD_REASS */
728 LIST_FIRST(&tp->t_segq) &&
729#endif /* VBOX_WITH_BSD_REASS */
730 ti->ti_len <= sbspace(&so->so_rcv)) {
731 /*
732 * this is a pure, in-sequence data packet
733 * with nothing on the reassembly queue and
734 * we have enough buffer space to take it.
735 */
736 ++tcpstat.tcps_preddat;
737 tp->rcv_nxt += ti->ti_len;
738 tcpstat.tcps_rcvpack++;
739 tcpstat.tcps_rcvbyte += ti->ti_len;
740 /*
741 * Add data to socket buffer.
742 */
743 if (so->so_emu) {
744 if (tcp_emu(pData, so,m)) sbappend(pData, so, m);
745 } else
746 sbappend(pData, so, m);
747
748 /*
749 * XXX This is called when data arrives. Later, check
750 * if we can actually write() to the socket
751 * XXX Need to check? It's be NON_BLOCKING
752 */
753/* sorwakeup(so); */
754
755 /*
756 * If this is a short packet, then ACK now - with Nagel
757 * congestion avoidance sender won't send more until
758 * he gets an ACK.
759 *
760 * It is better to not delay acks at all to maximize
761 * TCP throughput. See RFC 2581.
762 */
763 tp->t_flags |= TF_ACKNOW;
764 tcp_output(pData, tp);
765 return;
766 }
767 } /* header prediction */
768 /*
769 * Calculate amount of space in receive window,
770 * and then do TCP input processing.
771 * Receive window is amount of space in rcv queue,
772 * but not less than advertised window.
773 */
774 { int win;
775 win = sbspace(&so->so_rcv);
776 if (win < 0)
777 win = 0;
778 tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
779 }
780
781 switch (tp->t_state) {
782
783 /*
784 * If the state is LISTEN then ignore segment if it contains an RST.
785 * If the segment contains an ACK then it is bad and send a RST.
786 * If it does not contain a SYN then it is not interesting; drop it.
787 * Don't bother responding if the destination was a broadcast.
788 * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
789 * tp->iss, and send a segment:
790 * <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
791 * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
792 * Fill in remote peer address fields if not previously specified.
793 * Enter SYN_RECEIVED state, and process any other fields of this
794 * segment in this state.
795 */
796 case TCPS_LISTEN: {
797
798 if (tiflags & TH_RST)
799 goto drop;
800 if (tiflags & TH_ACK)
801 goto dropwithreset;
802 if ((tiflags & TH_SYN) == 0)
803 goto drop;
804
805 /*
806 * This has way too many gotos...
807 * But a bit of spaghetti code never hurt anybody :)
808 */
809
810 if (so->so_emu & EMU_NOCONNECT) {
811 so->so_emu &= ~EMU_NOCONNECT;
812 goto cont_input;
813 }
814
815 if((tcp_fconnect(pData, so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
816 u_char code=ICMP_UNREACH_NET;
817 DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n",
818 errno,strerror(errno)));
819 if(errno == ECONNREFUSED) {
820 /* ACK the SYN, send RST to refuse the connection */
821 tcp_respond(pData, tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
822 TH_RST|TH_ACK);
823 } else {
824 if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
825 HTONL(ti->ti_seq); /* restore tcp header */
826 HTONL(ti->ti_ack);
827 HTONS(ti->ti_win);
828 HTONS(ti->ti_urp);
829 m->m_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
830 m->m_len += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr);
831 *ip=save_ip;
832 icmp_error(pData, m, ICMP_UNREACH,code, 0,strerror(errno));
833 }
834 tp = tcp_close(pData, tp);
835 m_free(pData, m);
836 } else {
837 /*
838 * Haven't connected yet, save the current mbuf
839 * and ti, and return
840 * XXX Some OS's don't tell us whether the connect()
841 * succeeded or not. So we must time it out.
842 */
843 so->so_m = m;
844 so->so_ti = ti;
845 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
846 tp->t_state = TCPS_SYN_RECEIVED;
847 }
848 return;
849
850 cont_conn:
851 /* m==NULL
852 * Check if the connect succeeded
853 */
854 if (so->so_state & SS_NOFDREF) {
855 tp = tcp_close(pData, tp);
856 goto dropwithreset;
857 }
858 cont_input:
859 tcp_template(tp);
860
861 if (optp)
862 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
863 /* , */
864 /* &ts_present, &ts_val, &ts_ecr); */
865
866 if (iss)
867 tp->iss = iss;
868 else
869 tp->iss = tcp_iss;
870 tcp_iss += TCP_ISSINCR/2;
871 tp->irs = ti->ti_seq;
872 tcp_sendseqinit(tp);
873 tcp_rcvseqinit(tp);
874 tp->t_flags |= TF_ACKNOW;
875 tp->t_state = TCPS_SYN_RECEIVED;
876 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
877 tcpstat.tcps_accepts++;
878 goto trimthenstep6;
879 } /* case TCPS_LISTEN */
880
881 /*
882 * If the state is SYN_SENT:
883 * if seg contains an ACK, but not for our SYN, drop the input.
884 * if seg contains a RST, then drop the connection.
885 * if seg does not contain SYN, then drop it.
886 * Otherwise this is an acceptable SYN segment
887 * initialize tp->rcv_nxt and tp->irs
888 * if seg contains ack then advance tp->snd_una
889 * if SYN has been acked change to ESTABLISHED else SYN_RCVD state
890 * arrange for segment to be acked (eventually)
891 * continue processing rest of data/controls, beginning with URG
892 */
893 case TCPS_SYN_SENT:
894 if ((tiflags & TH_ACK) &&
895 (SEQ_LEQ(ti->ti_ack, tp->iss) ||
896 SEQ_GT(ti->ti_ack, tp->snd_max)))
897 goto dropwithreset;
898
899 if (tiflags & TH_RST) {
900 if (tiflags & TH_ACK)
901 tp = tcp_drop(pData, tp,0); /* XXX Check t_softerror! */
902 goto drop;
903 }
904
905 if ((tiflags & TH_SYN) == 0)
906 goto drop;
907 if (tiflags & TH_ACK) {
908 tp->snd_una = ti->ti_ack;
909 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
910 tp->snd_nxt = tp->snd_una;
911 }
912
913 tp->t_timer[TCPT_REXMT] = 0;
914 tp->irs = ti->ti_seq;
915 tcp_rcvseqinit(tp);
916 tp->t_flags |= TF_ACKNOW;
917 if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) {
918 tcpstat.tcps_connects++;
919 soisfconnected(so);
920 tp->t_state = TCPS_ESTABLISHED;
921
922 /* Do window scaling on this connection? */
923/* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
924 * (TF_RCVD_SCALE|TF_REQ_SCALE)) {
925 * tp->snd_scale = tp->requested_s_scale;
926 * tp->rcv_scale = tp->request_r_scale;
927 * }
928 */
929#ifndef VBOX_WITH_BSD_REASS
930 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0,
931 (struct mbuf *)0);
932#else /* VBOX_WITH_BSD_REASS */
933 (void) tcp_reass(pData, tp, (struct tcphdr *)0, NULL, (struct mbuf *)0);
934#endif /* VBOX_WITH_BSD_REASS */
935 /*
936 * if we didn't have to retransmit the SYN,
937 * use its rtt as our initial srtt & rtt var.
938 */
939 if (tp->t_rtt)
940 tcp_xmit_timer(pData, tp, tp->t_rtt);
941 } else
942 tp->t_state = TCPS_SYN_RECEIVED;
943
944trimthenstep6:
945 /*
946 * Advance ti->ti_seq to correspond to first data byte.
947 * If data, trim to stay within window,
948 * dropping FIN if necessary.
949 */
950 ti->ti_seq++;
951 if (ti->ti_len > tp->rcv_wnd) {
952 todrop = ti->ti_len - tp->rcv_wnd;
953 m_adj(m, -todrop);
954 ti->ti_len = tp->rcv_wnd;
955 tiflags &= ~TH_FIN;
956 tcpstat.tcps_rcvpackafterwin++;
957 tcpstat.tcps_rcvbyteafterwin += todrop;
958 }
959 tp->snd_wl1 = ti->ti_seq - 1;
960 tp->rcv_up = ti->ti_seq;
961 goto step6;
962 } /* switch tp->t_state */
963 /*
964 * States other than LISTEN or SYN_SENT.
965 * First check timestamp, if present.
966 * Then check that at least some bytes of segment are within
967 * receive window. If segment begins before rcv_nxt,
968 * drop leading data (and SYN); if nothing left, just ack.
969 *
970 * RFC 1323 PAWS: If we have a timestamp reply on this segment
971 * and it's less than ts_recent, drop it.
972 */
973/* if (ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent &&
974 * TSTMP_LT(ts_val, tp->ts_recent)) {
975 *
976 */ /* Check to see if ts_recent is over 24 days old. */
977/* if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
978 */ /*
979 * * Invalidate ts_recent. If this segment updates
980 * * ts_recent, the age will be reset later and ts_recent
981 * * will get a valid value. If it does not, setting
982 * * ts_recent to zero will at least satisfy the
983 * * requirement that zero be placed in the timestamp
984 * * echo reply when ts_recent isn't valid. The
985 * * age isn't reset until we get a valid ts_recent
986 * * because we don't want out-of-order segments to be
987 * * dropped when ts_recent is old.
988 * */
989/* tp->ts_recent = 0;
990 * } else {
991 * tcpstat.tcps_rcvduppack++;
992 * tcpstat.tcps_rcvdupbyte += ti->ti_len;
993 * tcpstat.tcps_pawsdrop++;
994 * goto dropafterack;
995 * }
996 * }
997 */
998
999 todrop = tp->rcv_nxt - ti->ti_seq;
1000 if (todrop > 0) {
1001 if (tiflags & TH_SYN) {
1002 tiflags &= ~TH_SYN;
1003 ti->ti_seq++;
1004 if (ti->ti_urp > 1)
1005 ti->ti_urp--;
1006 else
1007 tiflags &= ~TH_URG;
1008 todrop--;
1009 }
1010 /*
1011 * Following if statement from Stevens, vol. 2, p. 960.
1012 */
1013 if (todrop > ti->ti_len
1014 || (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) {
1015 /*
1016 * Any valid FIN must be to the left of the window.
1017 * At this point the FIN must be a duplicate or out
1018 * of sequence; drop it.
1019 */
1020 tiflags &= ~TH_FIN;
1021
1022 /*
1023 * Send an ACK to resynchronize and drop any data.
1024 * But keep on processing for RST or ACK.
1025 */
1026 tp->t_flags |= TF_ACKNOW;
1027 todrop = ti->ti_len;
1028 tcpstat.tcps_rcvduppack++;
1029 tcpstat.tcps_rcvdupbyte += todrop;
1030 } else {
1031 tcpstat.tcps_rcvpartduppack++;
1032 tcpstat.tcps_rcvpartdupbyte += todrop;
1033 }
1034 m_adj(m, todrop);
1035 ti->ti_seq += todrop;
1036 ti->ti_len -= todrop;
1037 if (ti->ti_urp > todrop)
1038 ti->ti_urp -= todrop;
1039 else {
1040 tiflags &= ~TH_URG;
1041 ti->ti_urp = 0;
1042 }
1043 }
1044 /*
1045 * If new data are received on a connection after the
1046 * user processes are gone, then RST the other end.
1047 */
1048 if ((so->so_state & SS_NOFDREF) &&
1049 tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
1050 tp = tcp_close(pData, tp);
1051 tcpstat.tcps_rcvafterclose++;
1052 goto dropwithreset;
1053 }
1054
1055 /*
1056 * If segment ends after window, drop trailing data
1057 * (and PUSH and FIN); if nothing left, just ACK.
1058 */
1059 todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
1060 if (todrop > 0) {
1061 tcpstat.tcps_rcvpackafterwin++;
1062 if (todrop >= ti->ti_len) {
1063 tcpstat.tcps_rcvbyteafterwin += ti->ti_len;
1064 /*
1065 * If a new connection request is received
1066 * while in TIME_WAIT, drop the old connection
1067 * and start over if the sequence numbers
1068 * are above the previous ones.
1069 */
1070 if (tiflags & TH_SYN &&
1071 tp->t_state == TCPS_TIME_WAIT &&
1072 SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
1073 iss = tp->rcv_nxt + TCP_ISSINCR;
1074 tp = tcp_close(pData, tp);
1075 goto findso;
1076 }
1077 /*
1078 * If window is closed can only take segments at
1079 * window edge, and have to drop data and PUSH from
1080 * incoming segments. Continue processing, but
1081 * remember to ack. Otherwise, drop segment
1082 * and ack.
1083 */
1084 if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) {
1085 tp->t_flags |= TF_ACKNOW;
1086 tcpstat.tcps_rcvwinprobe++;
1087 } else
1088 goto dropafterack;
1089 } else
1090 tcpstat.tcps_rcvbyteafterwin += todrop;
1091 m_adj(m, -todrop);
1092 ti->ti_len -= todrop;
1093 tiflags &= ~(TH_PUSH|TH_FIN);
1094 }
1095
1096 /*
1097 * If last ACK falls within this segment's sequence numbers,
1098 * record its timestamp.
1099 */
1100/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
1101 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len +
1102 * ((tiflags & (TH_SYN|TH_FIN)) != 0))) {
1103 * tp->ts_recent_age = tcp_now;
1104 * tp->ts_recent = ts_val;
1105 * }
1106 */
1107
1108 /*
1109 * If the RST bit is set examine the state:
1110 * SYN_RECEIVED STATE:
1111 * If passive open, return to LISTEN state.
1112 * If active open, inform user that connection was refused.
1113 * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
1114 * Inform user that connection was reset, and close tcb.
1115 * CLOSING, LAST_ACK, TIME_WAIT STATES
1116 * Close the tcb.
1117 */
1118 if (tiflags&TH_RST) switch (tp->t_state) {
1119
1120 case TCPS_SYN_RECEIVED:
1121/* so->so_error = ECONNREFUSED; */
1122 goto close;
1123
1124 case TCPS_ESTABLISHED:
1125 case TCPS_FIN_WAIT_1:
1126 case TCPS_FIN_WAIT_2:
1127 case TCPS_CLOSE_WAIT:
1128/* so->so_error = ECONNRESET; */
1129 close:
1130 tp->t_state = TCPS_CLOSED;
1131 tcpstat.tcps_drops++;
1132 tp = tcp_close(pData, tp);
1133 goto drop;
1134
1135 case TCPS_CLOSING:
1136 case TCPS_LAST_ACK:
1137 case TCPS_TIME_WAIT:
1138 tp = tcp_close(pData, tp);
1139 goto drop;
1140 }
1141
1142 /*
1143 * If a SYN is in the window, then this is an
1144 * error and we send an RST and drop the connection.
1145 */
1146 if (tiflags & TH_SYN) {
1147 tp = tcp_drop(pData, tp,0);
1148 goto dropwithreset;
1149 }
1150
1151 /*
1152 * If the ACK bit is off we drop the segment and return.
1153 */
1154 if ((tiflags & TH_ACK) == 0) goto drop;
1155
1156 /*
1157 * Ack processing.
1158 */
1159 switch (tp->t_state) {
1160 /*
1161 * In SYN_RECEIVED state if the ack ACKs our SYN then enter
1162 * ESTABLISHED state and continue processing, otherwise
1163 * send an RST. una<=ack<=max
1164 */
1165 case TCPS_SYN_RECEIVED:
1166
1167 if (SEQ_GT(tp->snd_una, ti->ti_ack) ||
1168 SEQ_GT(ti->ti_ack, tp->snd_max))
1169 goto dropwithreset;
1170 tcpstat.tcps_connects++;
1171 tp->t_state = TCPS_ESTABLISHED;
1172 /*
1173 * The sent SYN is ack'ed with our sequence number +1
1174 * The first data byte already in the buffer will get
1175 * lost if no correction is made. This is only needed for
1176 * SS_CTL since the buffer is empty otherwise.
1177 * tp->snd_una++; or:
1178 */
1179 tp->snd_una=ti->ti_ack;
1180 soisfconnected(so);
1181
1182 /* Do window scaling? */
1183/* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
1184 * (TF_RCVD_SCALE|TF_REQ_SCALE)) {
1185 * tp->snd_scale = tp->requested_s_scale;
1186 * tp->rcv_scale = tp->request_r_scale;
1187 * }
1188 */
1189#ifndef VBOX_WITH_BSD_REASS
1190 (void) tcp_reass(pData, tp, (struct tcpiphdr *)0, (struct mbuf *)0);
1191#else /* VBOX_WITH_BSD_REASS */
1192 (void) tcp_reass(pData, tp, (struct tcphdr *)0, (int *)0, (struct mbuf *)0);
1193#endif /*VBOX_WITH_BSD_REASS*/
1194 tp->snd_wl1 = ti->ti_seq - 1;
1195 /* Avoid ack processing; snd_una==ti_ack => dup ack */
1196 goto synrx_to_est;
1197 /* fall into ... */
1198
1199 /*
1200 * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
1201 * ACKs. If the ack is in the range
1202 * tp->snd_una < ti->ti_ack <= tp->snd_max
1203 * then advance tp->snd_una to ti->ti_ack and drop
1204 * data from the retransmission queue. If this ACK reflects
1205 * more up to date window information we update our window information.
1206 */
1207 case TCPS_ESTABLISHED:
1208 case TCPS_FIN_WAIT_1:
1209 case TCPS_FIN_WAIT_2:
1210 case TCPS_CLOSE_WAIT:
1211 case TCPS_CLOSING:
1212 case TCPS_LAST_ACK:
1213 case TCPS_TIME_WAIT:
1214
1215 if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
1216 if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
1217 tcpstat.tcps_rcvdupack++;
1218 DEBUG_MISC((dfd," dup ack m = %lx so = %lx \n",
1219 (long )m, (long )so));
1220 /*
1221 * If we have outstanding data (other than
1222 * a window probe), this is a completely
1223 * duplicate ack (ie, window info didn't
1224 * change), the ack is the biggest we've
1225 * seen and we've seen exactly our rexmt
1226 * threshold of them, assume a packet
1227 * has been dropped and retransmit it.
1228 * Kludge snd_nxt & the congestion
1229 * window so we send only this one
1230 * packet.
1231 *
1232 * We know we're losing at the current
1233 * window size so do congestion avoidance
1234 * (set ssthresh to half the current window
1235 * and pull our congestion window back to
1236 * the new ssthresh).
1237 *
1238 * Dup acks mean that packets have left the
1239 * network (they're now cached at the receiver)
1240 * so bump cwnd by the amount in the receiver
1241 * to keep a constant cwnd packets in the
1242 * network.
1243 */
1244 if (tp->t_timer[TCPT_REXMT] == 0 ||
1245 ti->ti_ack != tp->snd_una)
1246 tp->t_dupacks = 0;
1247 else if (++tp->t_dupacks == tcprexmtthresh) {
1248 tcp_seq onxt = tp->snd_nxt;
1249 u_int win =
1250 min(tp->snd_wnd, tp->snd_cwnd) / 2 /
1251 tp->t_maxseg;
1252
1253 if (win < 2)
1254 win = 2;
1255 tp->snd_ssthresh = win * tp->t_maxseg;
1256 tp->t_timer[TCPT_REXMT] = 0;
1257 tp->t_rtt = 0;
1258 tp->snd_nxt = ti->ti_ack;
1259 tp->snd_cwnd = tp->t_maxseg;
1260 (void) tcp_output(pData, tp);
1261 tp->snd_cwnd = tp->snd_ssthresh +
1262 tp->t_maxseg * tp->t_dupacks;
1263 if (SEQ_GT(onxt, tp->snd_nxt))
1264 tp->snd_nxt = onxt;
1265 goto drop;
1266 } else if (tp->t_dupacks > tcprexmtthresh) {
1267 tp->snd_cwnd += tp->t_maxseg;
1268 (void) tcp_output(pData, tp);
1269 goto drop;
1270 }
1271 } else
1272 tp->t_dupacks = 0;
1273 break;
1274 }
1275 synrx_to_est:
1276 /*
1277 * If the congestion window was inflated to account
1278 * for the other side's cached packets, retract it.
1279 */
1280 if (tp->t_dupacks > tcprexmtthresh &&
1281 tp->snd_cwnd > tp->snd_ssthresh)
1282 tp->snd_cwnd = tp->snd_ssthresh;
1283 tp->t_dupacks = 0;
1284 if (SEQ_GT(ti->ti_ack, tp->snd_max)) {
1285 tcpstat.tcps_rcvacktoomuch++;
1286 goto dropafterack;
1287 }
1288 acked = ti->ti_ack - tp->snd_una;
1289 tcpstat.tcps_rcvackpack++;
1290 tcpstat.tcps_rcvackbyte += acked;
1291
1292 /*
1293 * If we have a timestamp reply, update smoothed
1294 * round trip time. If no timestamp is present but
1295 * transmit timer is running and timed sequence
1296 * number was acked, update smoothed round trip time.
1297 * Since we now have an rtt measurement, cancel the
1298 * timer backoff (cf., Phil Karn's retransmit alg.).
1299 * Recompute the initial retransmit timer.
1300 */
1301/* if (ts_present)
1302 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
1303 * else
1304 */
1305 if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
1306 tcp_xmit_timer(pData, tp,tp->t_rtt);
1307
1308 /*
1309 * If all outstanding data is acked, stop retransmit
1310 * timer and remember to restart (more output or persist).
1311 * If there is more data to be acked, restart retransmit
1312 * timer, using current (possibly backed-off) value.
1313 */
1314 if (ti->ti_ack == tp->snd_max) {
1315 tp->t_timer[TCPT_REXMT] = 0;
1316 needoutput = 1;
1317 } else if (tp->t_timer[TCPT_PERSIST] == 0)
1318 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1319 /*
1320 * When new data is acked, open the congestion window.
1321 * If the window gives us less than ssthresh packets
1322 * in flight, open exponentially (maxseg per packet).
1323 * Otherwise open linearly: maxseg per window
1324 * (maxseg^2 / cwnd per packet).
1325 */
1326 {
1327 register u_int cw = tp->snd_cwnd;
1328 register u_int incr = tp->t_maxseg;
1329
1330 if (cw > tp->snd_ssthresh)
1331 incr = incr * incr / cw;
1332 tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
1333 }
1334 if (acked > so->so_snd.sb_cc) {
1335 tp->snd_wnd -= so->so_snd.sb_cc;
1336 sbdrop(&so->so_snd, (int )so->so_snd.sb_cc);
1337 ourfinisacked = 1;
1338 } else {
1339 sbdrop(&so->so_snd, acked);
1340 tp->snd_wnd -= acked;
1341 ourfinisacked = 0;
1342 }
1343 /*
1344 * XXX sowwakup is called when data is acked and there's room for
1345 * for more data... it should read() the socket
1346 */
1347/* if (so->so_snd.sb_flags & SB_NOTIFY)
1348 * sowwakeup(so);
1349 */
1350 tp->snd_una = ti->ti_ack;
1351 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
1352 tp->snd_nxt = tp->snd_una;
1353
1354 switch (tp->t_state) {
1355
1356 /*
1357 * In FIN_WAIT_1 STATE in addition to the processing
1358 * for the ESTABLISHED state if our FIN is now acknowledged
1359 * then enter FIN_WAIT_2.
1360 */
1361 case TCPS_FIN_WAIT_1:
1362 if (ourfinisacked) {
1363 /*
1364 * If we can't receive any more
1365 * data, then closing user can proceed.
1366 * Starting the timer is contrary to the
1367 * specification, but if we don't get a FIN
1368 * we'll hang forever.
1369 */
1370 if (so->so_state & SS_FCANTRCVMORE) {
1371 soisfdisconnected(so);
1372 tp->t_timer[TCPT_2MSL] = tcp_maxidle;
1373 }
1374 tp->t_state = TCPS_FIN_WAIT_2;
1375 }
1376 break;
1377
1378 /*
1379 * In CLOSING STATE in addition to the processing for
1380 * the ESTABLISHED state if the ACK acknowledges our FIN
1381 * then enter the TIME-WAIT state, otherwise ignore
1382 * the segment.
1383 */
1384 case TCPS_CLOSING:
1385 if (ourfinisacked) {
1386 tp->t_state = TCPS_TIME_WAIT;
1387 tcp_canceltimers(tp);
1388 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1389 soisfdisconnected(so);
1390 }
1391 break;
1392
1393 /*
1394 * In LAST_ACK, we may still be waiting for data to drain
1395 * and/or to be acked, as well as for the ack of our FIN.
1396 * If our FIN is now acknowledged, delete the TCB,
1397 * enter the closed state and return.
1398 */
1399 case TCPS_LAST_ACK:
1400 if (ourfinisacked) {
1401 tp = tcp_close(pData, tp);
1402 goto drop;
1403 }
1404 break;
1405
1406 /*
1407 * In TIME_WAIT state the only thing that should arrive
1408 * is a retransmission of the remote FIN. Acknowledge
1409 * it and restart the finack timer.
1410 */
1411 case TCPS_TIME_WAIT:
1412 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1413 goto dropafterack;
1414 }
1415 } /* switch(tp->t_state) */
1416
1417step6:
1418 /*
1419 * Update window information.
1420 * Don't look at window if no ACK: TAC's send garbage on first SYN.
1421 */
1422 if ((tiflags & TH_ACK) &&
1423 (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
1424 (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
1425 (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
1426 /* keep track of pure window updates */
1427 if (ti->ti_len == 0 &&
1428 tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)
1429 tcpstat.tcps_rcvwinupd++;
1430 tp->snd_wnd = tiwin;
1431 tp->snd_wl1 = ti->ti_seq;
1432 tp->snd_wl2 = ti->ti_ack;
1433 if (tp->snd_wnd > tp->max_sndwnd)
1434 tp->max_sndwnd = tp->snd_wnd;
1435 needoutput = 1;
1436 }
1437
1438 /*
1439 * Process segments with URG.
1440 */
1441 if ((tiflags & TH_URG) && ti->ti_urp &&
1442 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1443 /*
1444 * This is a kludge, but if we receive and accept
1445 * random urgent pointers, we'll crash in
1446 * soreceive. It's hard to imagine someone
1447 * actually wanting to send this much urgent data.
1448 */
1449 if (ti->ti_urp + so->so_rcv.sb_cc > so->so_rcv.sb_datalen) {
1450 ti->ti_urp = 0;
1451 tiflags &= ~TH_URG;
1452 goto dodata;
1453 }
1454 /*
1455 * If this segment advances the known urgent pointer,
1456 * then mark the data stream. This should not happen
1457 * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
1458 * a FIN has been received from the remote side.
1459 * In these states we ignore the URG.
1460 *
1461 * According to RFC961 (Assigned Protocols),
1462 * the urgent pointer points to the last octet
1463 * of urgent data. We continue, however,
1464 * to consider it to indicate the first octet
1465 * of data past the urgent section as the original
1466 * spec states (in one of two places).
1467 */
1468 if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) {
1469 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1470 so->so_urgc = so->so_rcv.sb_cc +
1471 (tp->rcv_up - tp->rcv_nxt); /* -1; */
1472 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1473
1474 }
1475 } else
1476 /*
1477 * If no out of band data is expected,
1478 * pull receive urgent pointer along
1479 * with the receive window.
1480 */
1481 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
1482 tp->rcv_up = tp->rcv_nxt;
1483dodata:
1484
1485 /*
1486 * If this is a small packet, then ACK now - with Nagel
1487 * congestion avoidance sender won't send more until
1488 * he gets an ACK.
1489 *
1490 * See above.
1491 */
1492 if (ti->ti_len && (unsigned)ti->ti_len <= 5 &&
1493 ((struct tcpiphdr_2 *)ti)->first_char == (char)27) {
1494 tp->t_flags |= TF_ACKNOW;
1495 }
1496
1497 /*
1498 * Process the segment text, merging it into the TCP sequencing queue,
1499 * and arranging for acknowledgment of receipt if necessary.
1500 * This process logically involves adjusting tp->rcv_wnd as data
1501 * is presented to the user (this happens in tcp_usrreq.c,
1502 * case PRU_RCVD). If a FIN has already been received on this
1503 * connection then we just ignore the text.
1504 */
1505 if ((ti->ti_len || (tiflags&TH_FIN)) &&
1506 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1507#ifndef VBOX_WITH_BSD_REASS
1508 TCP_REASS(pData, tp, ti, m, so, tiflags);
1509#else /* VBOX_WITH_BSD_REASS */
1510 if (ti->ti_seq == tp->rcv_nxt
1511 && LIST_EMPTY(&tp->t_segq)
1512 && tp->t_state == TCPS_ESTABLISHED) {
1513 DELAY_ACK(tp, ti); /* little bit different from BSD declaration see netinet/tcp_input.c */
1514 tp->rcv_nxt += tlen;
1515 tiflags = ti->ti_t.th_flags & TH_FIN;
1516 tcpstat.tcps_rcvpack++;
1517 tcpstat.tcps_rcvbyte += tlen;
1518 if (so->so_state & SS_FCANTRCVMORE)
1519 m_freem(pData, m);
1520 else
1521 sbappend(pData, so, m);
1522 }
1523 else {
1524 tiflags = tcp_reass(pData, tp, &ti->ti_t, &tlen, m);
1525 tiflags |= TF_ACKNOW;
1526 }
1527#endif /* VBOX_WITH_BSD_REASS */
1528 /*
1529 * Note the amount of data that peer has sent into
1530 * our window, in order to estimate the sender's
1531 * buffer size.
1532 */
1533 len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt);
1534 } else {
1535 m_free(pData, m);
1536 tiflags &= ~TH_FIN;
1537 }
1538
1539 /*
1540 * If FIN is received ACK the FIN and let the user know
1541 * that the connection is closing.
1542 */
1543 if (tiflags & TH_FIN) {
1544 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1545 /*
1546 * If we receive a FIN we can't send more data,
1547 * set it SS_FDRAIN
1548 * Shutdown the socket if there is no rx data in the
1549 * buffer.
1550 * soread() is called on completion of shutdown() and
1551 * will got to TCPS_LAST_ACK, and use tcp_output()
1552 * to send the FIN.
1553 */
1554/* sofcantrcvmore(so); */
1555 sofwdrain(so);
1556
1557 tp->t_flags |= TF_ACKNOW;
1558 tp->rcv_nxt++;
1559 }
1560 switch (tp->t_state) {
1561
1562 /*
1563 * In SYN_RECEIVED and ESTABLISHED STATES
1564 * enter the CLOSE_WAIT state.
1565 */
1566 case TCPS_SYN_RECEIVED:
1567 case TCPS_ESTABLISHED:
1568 if(so->so_emu == EMU_CTL) /* no shutdown on socket */
1569 tp->t_state = TCPS_LAST_ACK;
1570 else
1571 tp->t_state = TCPS_CLOSE_WAIT;
1572 break;
1573
1574 /*
1575 * If still in FIN_WAIT_1 STATE FIN has not been acked so
1576 * enter the CLOSING state.
1577 */
1578 case TCPS_FIN_WAIT_1:
1579 tp->t_state = TCPS_CLOSING;
1580 break;
1581
1582 /*
1583 * In FIN_WAIT_2 state enter the TIME_WAIT state,
1584 * starting the time-wait timer, turning off the other
1585 * standard timers.
1586 */
1587 case TCPS_FIN_WAIT_2:
1588 tp->t_state = TCPS_TIME_WAIT;
1589 tcp_canceltimers(tp);
1590 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1591 soisfdisconnected(so);
1592 break;
1593
1594 /*
1595 * In TIME_WAIT state restart the 2 MSL time_wait timer.
1596 */
1597 case TCPS_TIME_WAIT:
1598 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1599 break;
1600 }
1601 }
1602
1603 /*
1604 * Return any desired output.
1605 */
1606 if (needoutput || (tp->t_flags & TF_ACKNOW)) {
1607 (void) tcp_output(pData, tp);
1608 }
1609 return;
1610
1611dropafterack:
1612 /*
1613 * Generate an ACK dropping incoming segment if it occupies
1614 * sequence space, where the ACK reflects our state.
1615 */
1616 if (tiflags & TH_RST)
1617 goto drop;
1618 m_freem(pData, m);
1619 tp->t_flags |= TF_ACKNOW;
1620 (void) tcp_output(pData, tp);
1621 return;
1622
1623dropwithreset:
1624 /* reuses m if m!=NULL, m_free() unnecessary */
1625 if (tiflags & TH_ACK)
1626 tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
1627 else {
1628 if (tiflags & TH_SYN) ti->ti_len++;
1629 tcp_respond(pData, tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
1630 TH_RST|TH_ACK);
1631 }
1632
1633 return;
1634
1635drop:
1636 /*
1637 * Drop space held by incoming segment and return.
1638 */
1639 m_free(pData, m);
1640
1641 return;
1642}
1643
1644 /* , ts_present, ts_val, ts_ecr) */
1645/* int *ts_present;
1646 * u_int32_t *ts_val, *ts_ecr;
1647 */
1648void
1649tcp_dooptions(PNATState pData, struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
1650{
1651 u_int16_t mss;
1652 int opt, optlen;
1653
1654 DEBUG_CALL("tcp_dooptions");
1655 DEBUG_ARGS((dfd," tp = %lx cnt=%i \n", (long )tp, cnt));
1656
1657 for (; cnt > 0; cnt -= optlen, cp += optlen) {
1658 opt = cp[0];
1659 if (opt == TCPOPT_EOL)
1660 break;
1661 if (opt == TCPOPT_NOP)
1662 optlen = 1;
1663 else {
1664 optlen = cp[1];
1665 if (optlen <= 0)
1666 break;
1667 }
1668 switch (opt) {
1669
1670 default:
1671 continue;
1672
1673 case TCPOPT_MAXSEG:
1674 if (optlen != TCPOLEN_MAXSEG)
1675 continue;
1676 if (!(ti->ti_flags & TH_SYN))
1677 continue;
1678 memcpy((char *) &mss, (char *) cp + 2, sizeof(mss));
1679 NTOHS(mss);
1680 (void) tcp_mss(pData, tp, mss); /* sets t_maxseg */
1681 break;
1682
1683/* case TCPOPT_WINDOW:
1684 * if (optlen != TCPOLEN_WINDOW)
1685 * continue;
1686 * if (!(ti->ti_flags & TH_SYN))
1687 * continue;
1688 * tp->t_flags |= TF_RCVD_SCALE;
1689 * tp->requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
1690 * break;
1691 */
1692/* case TCPOPT_TIMESTAMP:
1693 * if (optlen != TCPOLEN_TIMESTAMP)
1694 * continue;
1695 * *ts_present = 1;
1696 * memcpy((char *) ts_val, (char *)cp + 2, sizeof(*ts_val));
1697 * NTOHL(*ts_val);
1698 * memcpy((char *) ts_ecr, (char *)cp + 6, sizeof(*ts_ecr));
1699 * NTOHL(*ts_ecr);
1700 *
1701 */ /*
1702 * * A timestamp received in a SYN makes
1703 * * it ok to send timestamp requests and replies.
1704 * */
1705/* if (ti->ti_flags & TH_SYN) {
1706 * tp->t_flags |= TF_RCVD_TSTMP;
1707 * tp->ts_recent = *ts_val;
1708 * tp->ts_recent_age = tcp_now;
1709 * }
1710 */ break;
1711 }
1712 }
1713}
1714
1715
1716/*
1717 * Pull out of band byte out of a segment so
1718 * it doesn't appear in the user's data queue.
1719 * It is still reflected in the segment length for
1720 * sequencing purposes.
1721 */
1722
1723#ifdef notdef
1724
1725void
1726tcp_pulloutofband(so, ti, m)
1727 struct socket *so;
1728 struct tcpiphdr *ti;
1729 register struct mbuf *m;
1730{
1731 int cnt = ti->ti_urp - 1;
1732
1733 while (cnt >= 0) {
1734 if (m->m_len > cnt) {
1735 char *cp = mtod(m, caddr_t) + cnt;
1736 struct tcpcb *tp = sototcpcb(so);
1737
1738 tp->t_iobc = *cp;
1739 tp->t_oobflags |= TCPOOB_HAVEDATA;
1740 memcpy(sp, cp+1, (unsigned)(m->m_len - cnt - 1));
1741 m->m_len--;
1742 return;
1743 }
1744 cnt -= m->m_len;
1745 m = m->m_next; /* XXX WRONG! Fix it! */
1746 if (m == 0)
1747 break;
1748 }
1749 panic("tcp_pulloutofband");
1750}
1751
1752#endif /* notdef */
1753
1754/*
1755 * Collect new round-trip time estimate
1756 * and update averages and current timeout.
1757 */
1758
1759void
1760tcp_xmit_timer(PNATState pData, register struct tcpcb *tp, int rtt)
1761{
1762 register short delta;
1763
1764 DEBUG_CALL("tcp_xmit_timer");
1765 DEBUG_ARG("tp = %lx", (long)tp);
1766 DEBUG_ARG("rtt = %d", rtt);
1767
1768 tcpstat.tcps_rttupdated++;
1769 if (tp->t_srtt != 0) {
1770 /*
1771 * srtt is stored as fixed point with 3 bits after the
1772 * binary point (i.e., scaled by 8). The following magic
1773 * is equivalent to the smoothing algorithm in rfc793 with
1774 * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
1775 * point). Adjust rtt to origin 0.
1776 */
1777 delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT);
1778 if ((tp->t_srtt += delta) <= 0)
1779 tp->t_srtt = 1;
1780 /*
1781 * We accumulate a smoothed rtt variance (actually, a
1782 * smoothed mean difference), then set the retransmit
1783 * timer to smoothed rtt + 4 times the smoothed variance.
1784 * rttvar is stored as fixed point with 2 bits after the
1785 * binary point (scaled by 4). The following is
1786 * equivalent to rfc793 smoothing with an alpha of .75
1787 * (rttvar = rttvar*3/4 + |delta| / 4). This replaces
1788 * rfc793's wired-in beta.
1789 */
1790 if (delta < 0)
1791 delta = -delta;
1792 delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT);
1793 if ((tp->t_rttvar += delta) <= 0)
1794 tp->t_rttvar = 1;
1795 } else {
1796 /*
1797 * No rtt measurement yet - use the unsmoothed rtt.
1798 * Set the variance to half the rtt (so our first
1799 * retransmit happens at 3*rtt).
1800 */
1801 tp->t_srtt = rtt << TCP_RTT_SHIFT;
1802 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
1803 }
1804 tp->t_rtt = 0;
1805 tp->t_rxtshift = 0;
1806
1807 /*
1808 * the retransmit should happen at rtt + 4 * rttvar.
1809 * Because of the way we do the smoothing, srtt and rttvar
1810 * will each average +1/2 tick of bias. When we compute
1811 * the retransmit timer, we want 1/2 tick of rounding and
1812 * 1 extra tick because of +-1/2 tick uncertainty in the
1813 * firing of the timer. The bias will give us exactly the
1814 * 1.5 tick we need. But, because the bias is
1815 * statistical, we have to test that we don't drop below
1816 * the minimum feasible timer (which is 2 ticks).
1817 */
1818 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
1819 (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */
1820
1821 /*
1822 * We received an ack for a packet that wasn't retransmitted;
1823 * it is probably safe to discard any error indications we've
1824 * received recently. This isn't quite right, but close enough
1825 * for now (a route might have failed after we sent a segment,
1826 * and the return path might not be symmetrical).
1827 */
1828 tp->t_softerror = 0;
1829}
1830
1831/*
1832 * Determine a reasonable value for maxseg size.
1833 * If the route is known, check route for mtu.
1834 * If none, use an mss that can be handled on the outgoing
1835 * interface without forcing IP to fragment; if bigger than
1836 * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES
1837 * to utilize large mbufs. If no route is found, route has no mtu,
1838 * or the destination isn't local, use a default, hopefully conservative
1839 * size (usually 512 or the default IP max size, but no more than the mtu
1840 * of the interface), as we can't discover anything about intervening
1841 * gateways or networks. We also initialize the congestion/slow start
1842 * window to be a single segment if the destination isn't local.
1843 * While looking at the routing entry, we also initialize other path-dependent
1844 * parameters from pre-set or cached values in the routing entry.
1845 */
1846
1847int
1848tcp_mss(PNATState pData, register struct tcpcb *tp, u_int offer)
1849{
1850 struct socket *so = tp->t_socket;
1851 int mss;
1852
1853 DEBUG_CALL("tcp_mss");
1854 DEBUG_ARG("tp = %lx", (long)tp);
1855 DEBUG_ARG("offer = %d", offer);
1856
1857 mss = min(if_mtu, if_mru) - sizeof(struct tcpiphdr);
1858 if (offer)
1859 mss = min(mss, offer);
1860 mss = max(mss, 32);
1861 if (mss < tp->t_maxseg || offer != 0)
1862 tp->t_maxseg = mss;
1863
1864 tp->snd_cwnd = mss;
1865
1866 sbreserve(&so->so_snd, tcp_sndspace+((tcp_sndspace%mss)?(mss-(tcp_sndspace%mss)):0));
1867 sbreserve(&so->so_rcv, tcp_rcvspace+((tcp_rcvspace%mss)?(mss-(tcp_rcvspace%mss)):0));
1868
1869 DEBUG_MISC((dfd, " returning mss = %d\n", mss));
1870
1871 return mss;
1872}
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