Deleted Added
full compact
tcp_output.c (132717) tcp_output.c (133874)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
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

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
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

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
30 * $FreeBSD: head/sys/netinet/tcp_output.c 132717 2004-07-28 02:15:14Z jayanth $
30 * $FreeBSD: head/sys/netinet/tcp_output.c 133874 2004-08-16 18:32:07Z rwatson $
31 */
32
33#include "opt_inet.h"
34#include "opt_inet6.h"
35#include "opt_ipsec.h"
36#include "opt_mac.h"
37#include "opt_tcpdebug.h"
38#include "opt_tcp_sack.h"

--- 58 unchanged lines hidden (view full) ---

97 &ss_fltsz, 1, "Slow start flight size");
98
99int ss_fltsz_local = 4;
100SYSCTL_INT(_net_inet_tcp, OID_AUTO, local_slowstart_flightsize, CTLFLAG_RW,
101 &ss_fltsz_local, 1, "Slow start flight size for local networks");
102
103int tcp_do_newreno = 1;
104SYSCTL_INT(_net_inet_tcp, OID_AUTO, newreno, CTLFLAG_RW, &tcp_do_newreno,
31 */
32
33#include "opt_inet.h"
34#include "opt_inet6.h"
35#include "opt_ipsec.h"
36#include "opt_mac.h"
37#include "opt_tcpdebug.h"
38#include "opt_tcp_sack.h"

--- 58 unchanged lines hidden (view full) ---

97 &ss_fltsz, 1, "Slow start flight size");
98
99int ss_fltsz_local = 4;
100SYSCTL_INT(_net_inet_tcp, OID_AUTO, local_slowstart_flightsize, CTLFLAG_RW,
101 &ss_fltsz_local, 1, "Slow start flight size for local networks");
102
103int tcp_do_newreno = 1;
104SYSCTL_INT(_net_inet_tcp, OID_AUTO, newreno, CTLFLAG_RW, &tcp_do_newreno,
105 0, "Enable NewReno Algorithms");
105 0, "Enable NewReno Algorithms");
106
107/*
108 * Tcp output routine: figure out what should be sent and send it.
109 */
110int
111tcp_output(struct tcpcb *tp)
112{
113 struct socket *so = tp->t_inpcb->inp_socket;

--- 32 unchanged lines hidden (view full) ---

146 * to send, then transmit; otherwise, investigate further.
147 */
148 idle = (tp->t_flags & TF_LASTIDLE) || (tp->snd_max == tp->snd_una);
149 if (idle && (ticks - tp->t_rcvtime) >= tp->t_rxtcur) {
150 /*
151 * We have been idle for "a while" and no acks are
152 * expected to clock out any data we send --
153 * slow start to get ack "clock" running again.
106
107/*
108 * Tcp output routine: figure out what should be sent and send it.
109 */
110int
111tcp_output(struct tcpcb *tp)
112{
113 struct socket *so = tp->t_inpcb->inp_socket;

--- 32 unchanged lines hidden (view full) ---

146 * to send, then transmit; otherwise, investigate further.
147 */
148 idle = (tp->t_flags & TF_LASTIDLE) || (tp->snd_max == tp->snd_una);
149 if (idle && (ticks - tp->t_rcvtime) >= tp->t_rxtcur) {
150 /*
151 * We have been idle for "a while" and no acks are
152 * expected to clock out any data we send --
153 * slow start to get ack "clock" running again.
154 *
154 *
155 * Set the slow-start flight size depending on whether
156 * this is a local network or not.
155 * Set the slow-start flight size depending on whether
156 * this is a local network or not.
157 */
157 */
158 int ss = ss_fltsz;
159#ifdef INET6
160 if (isipv6) {
161 if (in6_localaddr(&tp->t_inpcb->in6p_faddr))
162 ss = ss_fltsz_local;
163 } else
164#endif /* INET6 */
165 if (in_localaddr(tp->t_inpcb->inp_faddr))

--- 23 unchanged lines hidden (view full) ---

189 flags = tcp_outflags[tp->t_state];
190 /*
191 * Send any SACK-generated retransmissions. If we're explicitly trying
192 * to send out new data (when sendalot is 1), bypass this function.
193 * If we retransmit in fast recovery mode, decrement snd_cwnd, since
194 * we're replacing a (future) new transmission with a retransmission
195 * now, and we previously incremented snd_cwnd in tcp_input().
196 */
158 int ss = ss_fltsz;
159#ifdef INET6
160 if (isipv6) {
161 if (in6_localaddr(&tp->t_inpcb->in6p_faddr))
162 ss = ss_fltsz_local;
163 } else
164#endif /* INET6 */
165 if (in_localaddr(tp->t_inpcb->inp_faddr))

--- 23 unchanged lines hidden (view full) ---

189 flags = tcp_outflags[tp->t_state];
190 /*
191 * Send any SACK-generated retransmissions. If we're explicitly trying
192 * to send out new data (when sendalot is 1), bypass this function.
193 * If we retransmit in fast recovery mode, decrement snd_cwnd, since
194 * we're replacing a (future) new transmission with a retransmission
195 * now, and we previously incremented snd_cwnd in tcp_input().
196 */
197 /*
197 /*
198 * Still in sack recovery , reset rxmit flag to zero.
199 */
200 sack_rxmit = 0;
201 len = 0;
202 p = NULL;
203 if (tp->sack_enable && IN_FASTRECOVERY(tp) &&
204 (p = tcp_sack_output(tp))) {
205 KASSERT(tp->snd_cwnd >= 0,
206 ("%s: CWIN is negative : %ld", __func__, tp->snd_cwnd));
207 /* Do not retransmit SACK segments beyond snd_recover */
208 if (SEQ_GT(p->end, tp->snd_recover)) {
209 /*
198 * Still in sack recovery , reset rxmit flag to zero.
199 */
200 sack_rxmit = 0;
201 len = 0;
202 p = NULL;
203 if (tp->sack_enable && IN_FASTRECOVERY(tp) &&
204 (p = tcp_sack_output(tp))) {
205 KASSERT(tp->snd_cwnd >= 0,
206 ("%s: CWIN is negative : %ld", __func__, tp->snd_cwnd));
207 /* Do not retransmit SACK segments beyond snd_recover */
208 if (SEQ_GT(p->end, tp->snd_recover)) {
209 /*
210 * (At least) part of sack hole extends beyond
211 * snd_recover. Check to see if we can rexmit data
210 * (At least) part of sack hole extends beyond
211 * snd_recover. Check to see if we can rexmit data
212 * for this hole.
213 */
214 if (SEQ_GEQ(p->rxmit, tp->snd_recover)) {
212 * for this hole.
213 */
214 if (SEQ_GEQ(p->rxmit, tp->snd_recover)) {
215 /*
215 /*
216 * Can't rexmit any more data for this hole.
216 * Can't rexmit any more data for this hole.
217 * That data will be rexmitted in the next
218 * sack recovery episode, when snd_recover
217 * That data will be rexmitted in the next
218 * sack recovery episode, when snd_recover
219 * moves past p->rxmit.
220 */
221 p = NULL;
222 goto after_sack_rexmit;
223 } else
224 /* Can rexmit part of the current hole */
219 * moves past p->rxmit.
220 */
221 p = NULL;
222 goto after_sack_rexmit;
223 } else
224 /* Can rexmit part of the current hole */
225 len = ((long)ulmin(tp->snd_cwnd,
225 len = ((long)ulmin(tp->snd_cwnd,
226 tp->snd_recover - p->rxmit));
227 } else
228 len = ((long)ulmin(tp->snd_cwnd, p->end - p->rxmit));
229 sack_rxmit = 1;
230 sendalot = 1;
231 off = p->rxmit - tp->snd_una;
226 tp->snd_recover - p->rxmit));
227 } else
228 len = ((long)ulmin(tp->snd_cwnd, p->end - p->rxmit));
229 sack_rxmit = 1;
230 sendalot = 1;
231 off = p->rxmit - tp->snd_una;
232 KASSERT(off >= 0,("%s: sack block to the left of una : %d",
232 KASSERT(off >= 0,("%s: sack block to the left of una : %d",
233 __func__, off));
234 if (len > 0) {
235 tcpstat.tcps_sack_rexmits++;
233 __func__, off));
234 if (len > 0) {
235 tcpstat.tcps_sack_rexmits++;
236 tcpstat.tcps_sack_rexmit_bytes +=
236 tcpstat.tcps_sack_rexmit_bytes +=
237 min(len, tp->t_maxseg);
238 }
239 }
240after_sack_rexmit:
241 /*
242 * Get standard flags, and add SYN or FIN if requested by 'hidden'
243 * state flags.
244 */

--- 31 unchanged lines hidden (view full) ---

276 sendwin = 1;
277 } else {
278 callout_stop(tp->tt_persist);
279 tp->t_rxtshift = 0;
280 }
281 }
282
283 /*
237 min(len, tp->t_maxseg);
238 }
239 }
240after_sack_rexmit:
241 /*
242 * Get standard flags, and add SYN or FIN if requested by 'hidden'
243 * state flags.
244 */

--- 31 unchanged lines hidden (view full) ---

276 sendwin = 1;
277 } else {
278 callout_stop(tp->tt_persist);
279 tp->t_rxtshift = 0;
280 }
281 }
282
283 /*
284 * If snd_nxt == snd_max and we have transmitted a FIN, the
284 * If snd_nxt == snd_max and we have transmitted a FIN, the
285 * offset will be > 0 even if so_snd.sb_cc is 0, resulting in
286 * a negative length. This can also occur when TCP opens up
287 * its congestion window while receiving additional duplicate
288 * acks after fast-retransmit because TCP will reset snd_nxt
289 * to snd_max after the fast-retransmit.
290 *
291 * In the normal retransmit-FIN-only case, however, snd_nxt will
292 * be set to snd_una, the offset will be 0, and the length may
293 * wind up 0.
285 * offset will be > 0 even if so_snd.sb_cc is 0, resulting in
286 * a negative length. This can also occur when TCP opens up
287 * its congestion window while receiving additional duplicate
288 * acks after fast-retransmit because TCP will reset snd_nxt
289 * to snd_max after the fast-retransmit.
290 *
291 * In the normal retransmit-FIN-only case, however, snd_nxt will
292 * be set to snd_una, the offset will be 0, and the length may
293 * wind up 0.
294 *
294 *
295 * If sack_rxmit is true we are retransmitting from the scoreboard
295 * If sack_rxmit is true we are retransmitting from the scoreboard
296 * in which case len is already set.
296 * in which case len is already set.
297 */
298 if (!sack_rxmit)
299 len = ((long)ulmin(so->so_snd.sb_cc, sendwin) - off);
300
301 /*
302 * Lop off SYN bit if it has already been sent. However, if this
303 * is SYN-SENT state and if segment contains data and if we don't
304 * know that foreign host supports TAO, suppress sending segment.

--- 49 unchanged lines hidden (view full) ---

354 */
355 if (len > tp->t_maxseg) {
356 len = tp->t_maxseg;
357 sendalot = 1;
358 }
359 if (sack_rxmit) {
360 if (SEQ_LT(p->rxmit + len, tp->snd_una + so->so_snd.sb_cc))
361 flags &= ~TH_FIN;
297 */
298 if (!sack_rxmit)
299 len = ((long)ulmin(so->so_snd.sb_cc, sendwin) - off);
300
301 /*
302 * Lop off SYN bit if it has already been sent. However, if this
303 * is SYN-SENT state and if segment contains data and if we don't
304 * know that foreign host supports TAO, suppress sending segment.

--- 49 unchanged lines hidden (view full) ---

354 */
355 if (len > tp->t_maxseg) {
356 len = tp->t_maxseg;
357 sendalot = 1;
358 }
359 if (sack_rxmit) {
360 if (SEQ_LT(p->rxmit + len, tp->snd_una + so->so_snd.sb_cc))
361 flags &= ~TH_FIN;
362 } else {
362 } else {
363 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
364 flags &= ~TH_FIN;
365 }
366
367 recwin = sbspace(&so->so_rcv);
368
369 /*
370 * Sender silly window avoidance. We transmit under the following

--- 75 unchanged lines hidden (view full) ---

446 ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
447 goto send;
448 /*
449 * In SACK, it is possible for tcp_output to fail to send a segment
450 * after the retransmission timer has been turned off. Make sure
451 * that the retransmission timer is set.
452 */
453 if (tp->sack_enable && SEQ_GT(tp->snd_max, tp->snd_una) &&
363 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
364 flags &= ~TH_FIN;
365 }
366
367 recwin = sbspace(&so->so_rcv);
368
369 /*
370 * Sender silly window avoidance. We transmit under the following

--- 75 unchanged lines hidden (view full) ---

446 ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
447 goto send;
448 /*
449 * In SACK, it is possible for tcp_output to fail to send a segment
450 * after the retransmission timer has been turned off. Make sure
451 * that the retransmission timer is set.
452 */
453 if (tp->sack_enable && SEQ_GT(tp->snd_max, tp->snd_una) &&
454 !callout_active(tp->tt_rexmt) &&
454 !callout_active(tp->tt_rexmt) &&
455 !callout_active(tp->tt_persist)) {
456 callout_reset(tp->tt_rexmt, tp->t_rxtcur,
457 tcp_timer_rexmt, tp);
455 !callout_active(tp->tt_persist)) {
456 callout_reset(tp->tt_rexmt, tp->t_rxtcur,
457 tcp_timer_rexmt, tp);
458 return (0);
459 }
458 return (0);
459 }
460 /*
461 * TCP window updates are not reliable, rather a polling protocol
462 * using ``persist'' packets is used to insure receipt of window
463 * updates. The three ``states'' for the output side are:
464 * idle not doing retransmits or persists
465 * persisting to move a small or zero window
466 * (re)transmitting and thereby not persisting
467 *

--- 44 unchanged lines hidden (view full) ---

512 u_short mss;
513
514 opt[0] = TCPOPT_MAXSEG;
515 opt[1] = TCPOLEN_MAXSEG;
516 mss = htons((u_short) tcp_mssopt(&tp->t_inpcb->inp_inc));
517 (void)memcpy(opt + 2, &mss, sizeof(mss));
518 optlen = TCPOLEN_MAXSEG;
519
460 /*
461 * TCP window updates are not reliable, rather a polling protocol
462 * using ``persist'' packets is used to insure receipt of window
463 * updates. The three ``states'' for the output side are:
464 * idle not doing retransmits or persists
465 * persisting to move a small or zero window
466 * (re)transmitting and thereby not persisting
467 *

--- 44 unchanged lines hidden (view full) ---

512 u_short mss;
513
514 opt[0] = TCPOPT_MAXSEG;
515 opt[1] = TCPOLEN_MAXSEG;
516 mss = htons((u_short) tcp_mssopt(&tp->t_inpcb->inp_inc));
517 (void)memcpy(opt + 2, &mss, sizeof(mss));
518 optlen = TCPOLEN_MAXSEG;
519
520 /*
521 * If this is the first SYN of connection (not a SYN
522 * ACK), include SACK_PERMIT_HDR option. If this is a
523 * SYN ACK, include SACK_PERMIT_HDR option if peer has
524 * already done so. This is only for active connect,
520 /*
521 * If this is the first SYN of connection (not a SYN
522 * ACK), include SACK_PERMIT_HDR option. If this is a
523 * SYN ACK, include SACK_PERMIT_HDR option if peer has
524 * already done so. This is only for active connect,
525 * since the syncache takes care of the passive connect.
525 * since the syncache takes care of the passive connect.
526 */
527 if (tp->sack_enable && ((flags & TH_ACK) == 0 ||
526 */
527 if (tp->sack_enable && ((flags & TH_ACK) == 0 ||
528 (tp->t_flags & TF_SACK_PERMIT))) {
528 (tp->t_flags & TF_SACK_PERMIT))) {
529 *((u_int32_t *) (opt + optlen)) =
529 *((u_int32_t *) (opt + optlen)) =
530 htonl(TCPOPT_SACK_PERMIT_HDR);
530 htonl(TCPOPT_SACK_PERMIT_HDR);
531 optlen += 4;
532 }
531 optlen += 4;
532 }
533 if ((tp->t_flags & TF_REQ_SCALE) &&
534 ((flags & TH_ACK) == 0 ||
535 (tp->t_flags & TF_RCVD_SCALE))) {
536 *((u_int32_t *)(opt + optlen)) = htonl(
537 TCPOPT_NOP << 24 |
538 TCPOPT_WINDOW << 16 |
539 TCPOLEN_WINDOW << 8 |
540 tp->request_r_scale);
541 optlen += 4;
542 }
543 }
533 if ((tp->t_flags & TF_REQ_SCALE) &&
534 ((flags & TH_ACK) == 0 ||
535 (tp->t_flags & TF_RCVD_SCALE))) {
536 *((u_int32_t *)(opt + optlen)) = htonl(
537 TCPOPT_NOP << 24 |
538 TCPOPT_WINDOW << 16 |
539 TCPOLEN_WINDOW << 8 |
540 tp->request_r_scale);
541 optlen += 4;
542 }
543 }
544 }
544 }
545
545
546 /*
546 /*
547 * Send a timestamp and echo-reply if this is a SYN and our side
548 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
549 * and our peer have sent timestamps in our SYN's.
547 * Send a timestamp and echo-reply if this is a SYN and our side
548 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
549 * and our peer have sent timestamps in our SYN's.
550 */
551 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
552 (flags & TH_RST) == 0 &&
550 */
551 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
552 (flags & TH_RST) == 0 &&
553 ((flags & TH_ACK) == 0 ||
554 (tp->t_flags & TF_RCVD_TSTMP))) {
555 u_int32_t *lp = (u_int32_t *)(opt + optlen);
556
553 ((flags & TH_ACK) == 0 ||
554 (tp->t_flags & TF_RCVD_TSTMP))) {
555 u_int32_t *lp = (u_int32_t *)(opt + optlen);
556
557 /* Form timestamp option as shown in appendix A of RFC 1323. */
558 *lp++ = htonl(TCPOPT_TSTAMP_HDR);
559 *lp++ = htonl(ticks);
560 *lp = htonl(tp->ts_recent);
561 optlen += TCPOLEN_TSTAMP_APPA;
562 }
557 /* Form timestamp option as shown in appendix A of RFC 1323. */
558 *lp++ = htonl(TCPOPT_TSTAMP_HDR);
559 *lp++ = htonl(ticks);
560 *lp = htonl(tp->ts_recent);
561 optlen += TCPOLEN_TSTAMP_APPA;
562 }
563
564 /*
565 * Send SACKs if necessary. This should be the last option processed.
566 * Only as many SACKs are sent as are permitted by the maximum options
567 * size. No more than three SACKs are sent.
568 */
569 if (tp->sack_enable && tp->t_state == TCPS_ESTABLISHED &&
570 (tp->t_flags & (TF_SACK_PERMIT|TF_NOOPT)) == TF_SACK_PERMIT &&

--- 11 unchanged lines hidden (view full) ---

582 continue;
583 *lp++ = htonl(sack.start);
584 *lp++ = htonl(sack.end);
585 count++;
586 }
587 *olp = htonl(TCPOPT_SACK_HDR|(TCPOLEN_SACK*count+2));
588 optlen += TCPOLEN_SACK*count + 4; /* including leading NOPs */
589 }
563
564 /*
565 * Send SACKs if necessary. This should be the last option processed.
566 * Only as many SACKs are sent as are permitted by the maximum options
567 * size. No more than three SACKs are sent.
568 */
569 if (tp->sack_enable && tp->t_state == TCPS_ESTABLISHED &&
570 (tp->t_flags & (TF_SACK_PERMIT|TF_NOOPT)) == TF_SACK_PERMIT &&

--- 11 unchanged lines hidden (view full) ---

582 continue;
583 *lp++ = htonl(sack.start);
584 *lp++ = htonl(sack.end);
585 count++;
586 }
587 *olp = htonl(TCPOPT_SACK_HDR|(TCPOLEN_SACK*count+2));
588 optlen += TCPOLEN_SACK*count + 4; /* including leading NOPs */
589 }
590 /*
590 /*
591 * Send `CC-family' options if our side wants to use them (TF_REQ_CC),
592 * options are allowed (!TF_NOOPT) and it's not a RST.
591 * Send `CC-family' options if our side wants to use them (TF_REQ_CC),
592 * options are allowed (!TF_NOOPT) and it's not a RST.
593 */
594 if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
595 (flags & TH_RST) == 0) {
593 */
594 if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
595 (flags & TH_RST) == 0) {
596 switch (flags & (TH_SYN|TH_ACK)) {
597 /*
598 * This is a normal ACK, send CC if we received CC before
599 * from our peer.
600 */
601 case TH_ACK:
602 if (!(tp->t_flags & TF_RCVD_CC))
603 break;

--- 21 unchanged lines hidden (view full) ---

625 */
626 case TH_SYN:
627 opt[optlen++] = TCPOPT_NOP;
628 opt[optlen++] = TCPOPT_NOP;
629 opt[optlen++] = tp->t_flags & TF_SENDCCNEW ?
630 TCPOPT_CCNEW : TCPOPT_CC;
631 opt[optlen++] = TCPOLEN_CC;
632 *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
596 switch (flags & (TH_SYN|TH_ACK)) {
597 /*
598 * This is a normal ACK, send CC if we received CC before
599 * from our peer.
600 */
601 case TH_ACK:
602 if (!(tp->t_flags & TF_RCVD_CC))
603 break;

--- 21 unchanged lines hidden (view full) ---

625 */
626 case TH_SYN:
627 opt[optlen++] = TCPOPT_NOP;
628 opt[optlen++] = TCPOPT_NOP;
629 opt[optlen++] = tp->t_flags & TF_SENDCCNEW ?
630 TCPOPT_CCNEW : TCPOPT_CC;
631 opt[optlen++] = TCPOLEN_CC;
632 *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
633 optlen += 4;
633 optlen += 4;
634 break;
635
636 /*
637 * This is a SYN,ACK; send CC and CC.echo if we received
638 * CC from our peer.
639 */
640 case (TH_SYN|TH_ACK):
641 if (tp->t_flags & TF_RCVD_CC) {

--- 9 unchanged lines hidden (view full) ---

651 opt[optlen++] = TCPOPT_CCECHO;
652 opt[optlen++] = TCPOLEN_CC;
653 *(u_int32_t *)&opt[optlen] =
654 htonl(tp->cc_recv);
655 optlen += 4;
656 }
657 break;
658 }
634 break;
635
636 /*
637 * This is a SYN,ACK; send CC and CC.echo if we received
638 * CC from our peer.
639 */
640 case (TH_SYN|TH_ACK):
641 if (tp->t_flags & TF_RCVD_CC) {

--- 9 unchanged lines hidden (view full) ---

651 opt[optlen++] = TCPOPT_CCECHO;
652 opt[optlen++] = TCPOLEN_CC;
653 *(u_int32_t *)&opt[optlen] =
654 htonl(tp->cc_recv);
655 optlen += 4;
656 }
657 break;
658 }
659 }
659 }
660
661#ifdef TCP_SIGNATURE
662#ifdef INET6
663 if (!isipv6)
664#endif
665 if (tp->t_flags & TF_SIGNATURE) {
666 int i;
667 u_char *bp;

--- 9 unchanged lines hidden (view full) ---

677
678 /* Terminate options list and maintain 32-bit alignment. */
679 *bp++ = TCPOPT_NOP;
680 *bp++ = TCPOPT_EOL;
681 optlen += 2;
682 }
683#endif /* TCP_SIGNATURE */
684
660
661#ifdef TCP_SIGNATURE
662#ifdef INET6
663 if (!isipv6)
664#endif
665 if (tp->t_flags & TF_SIGNATURE) {
666 int i;
667 u_char *bp;

--- 9 unchanged lines hidden (view full) ---

677
678 /* Terminate options list and maintain 32-bit alignment. */
679 *bp++ = TCPOPT_NOP;
680 *bp++ = TCPOPT_EOL;
681 optlen += 2;
682 }
683#endif /* TCP_SIGNATURE */
684
685 hdrlen += optlen;
685 hdrlen += optlen;
686
687#ifdef INET6
688 if (isipv6)
689 ipoptlen = ip6_optlen(tp->t_inpcb);
690 else
691#endif
692 if (tp->t_inpcb->inp_options)
693 ipoptlen = tp->t_inpcb->inp_options->m_len -

--- 16 unchanged lines hidden (view full) ---

710 */
711 flags &= ~TH_FIN;
712 len = tp->t_maxopd - optlen - ipoptlen;
713 sendalot = 1;
714 }
715
716/*#ifdef DIAGNOSTIC*/
717#ifdef INET6
686
687#ifdef INET6
688 if (isipv6)
689 ipoptlen = ip6_optlen(tp->t_inpcb);
690 else
691#endif
692 if (tp->t_inpcb->inp_options)
693 ipoptlen = tp->t_inpcb->inp_options->m_len -

--- 16 unchanged lines hidden (view full) ---

710 */
711 flags &= ~TH_FIN;
712 len = tp->t_maxopd - optlen - ipoptlen;
713 sendalot = 1;
714 }
715
716/*#ifdef DIAGNOSTIC*/
717#ifdef INET6
718 if (max_linkhdr + hdrlen > MCLBYTES)
718 if (max_linkhdr + hdrlen > MCLBYTES)
719#else
719#else
720 if (max_linkhdr + hdrlen > MHLEN)
720 if (max_linkhdr + hdrlen > MHLEN)
721#endif
722 panic("tcphdr too big");
723/*#endif*/
724
725 /*
726 * Grab a header mbuf, attaching a copy of data to
727 * be transmitted, and initialize the header from
728 * the template for sends on this connection.

--- 88 unchanged lines hidden (view full) ---

817#endif
818#ifdef INET6
819 if (isipv6) {
820 ip6 = mtod(m, struct ip6_hdr *);
821 th = (struct tcphdr *)(ip6 + 1);
822 tcpip_fillheaders(tp->t_inpcb, ip6, th);
823 } else
824#endif /* INET6 */
721#endif
722 panic("tcphdr too big");
723/*#endif*/
724
725 /*
726 * Grab a header mbuf, attaching a copy of data to
727 * be transmitted, and initialize the header from
728 * the template for sends on this connection.

--- 88 unchanged lines hidden (view full) ---

817#endif
818#ifdef INET6
819 if (isipv6) {
820 ip6 = mtod(m, struct ip6_hdr *);
821 th = (struct tcphdr *)(ip6 + 1);
822 tcpip_fillheaders(tp->t_inpcb, ip6, th);
823 } else
824#endif /* INET6 */
825 {
826 ip = mtod(m, struct ip *);
827 ipov = (struct ipovly *)ip;
828 th = (struct tcphdr *)(ip + 1);
829 tcpip_fillheaders(tp->t_inpcb, ip, th);
830 }
825 {
826 ip = mtod(m, struct ip *);
827 ipov = (struct ipovly *)ip;
828 th = (struct tcphdr *)(ip + 1);
829 tcpip_fillheaders(tp->t_inpcb, ip, th);
830 }
831
832 /*
833 * Fill in fields, remembering maximum advertised
834 * window for use in delaying messages about window sizes.
835 * If resending a FIN, be sure not to use a new sequence number.
836 */
837 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
838 tp->snd_nxt == tp->snd_max)

--- 6 unchanged lines hidden (view full) ---

845 * of the next unsent octet. So, if there is no data
846 * (and no SYN or FIN), use snd_max instead of snd_nxt
847 * when filling in ti_seq. But if we are in persist
848 * state, snd_max might reflect one byte beyond the
849 * right edge of the window, so use snd_nxt in that
850 * case, since we know we aren't doing a retransmission.
851 * (retransmit and persist are mutually exclusive...)
852 */
831
832 /*
833 * Fill in fields, remembering maximum advertised
834 * window for use in delaying messages about window sizes.
835 * If resending a FIN, be sure not to use a new sequence number.
836 */
837 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
838 tp->snd_nxt == tp->snd_max)

--- 6 unchanged lines hidden (view full) ---

845 * of the next unsent octet. So, if there is no data
846 * (and no SYN or FIN), use snd_max instead of snd_nxt
847 * when filling in ti_seq. But if we are in persist
848 * state, snd_max might reflect one byte beyond the
849 * right edge of the window, so use snd_nxt in that
850 * case, since we know we aren't doing a retransmission.
851 * (retransmit and persist are mutually exclusive...)
852 */
853 if (len || (flags & (TH_SYN|TH_FIN))
853 if (len || (flags & (TH_SYN|TH_FIN))
854 || callout_active(tp->tt_persist))
855 th->th_seq = htonl(tp->snd_nxt);
856 else
857 th->th_seq = htonl(tp->snd_max);
858 if (sack_rxmit) {
859 th->th_seq = htonl(p->rxmit);
860 p->rxmit += len;
861 }

--- 60 unchanged lines hidden (view full) ---

922 /*
923 * ip6_plen is not need to be filled now, and will be filled
924 * in ip6_output.
925 */
926 th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
927 sizeof(struct tcphdr) + optlen + len);
928 else
929#endif /* INET6 */
854 || callout_active(tp->tt_persist))
855 th->th_seq = htonl(tp->snd_nxt);
856 else
857 th->th_seq = htonl(tp->snd_max);
858 if (sack_rxmit) {
859 th->th_seq = htonl(p->rxmit);
860 p->rxmit += len;
861 }

--- 60 unchanged lines hidden (view full) ---

922 /*
923 * ip6_plen is not need to be filled now, and will be filled
924 * in ip6_output.
925 */
926 th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
927 sizeof(struct tcphdr) + optlen + len);
928 else
929#endif /* INET6 */
930 {
931 m->m_pkthdr.csum_flags = CSUM_TCP;
932 m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
933 th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
934 htons(sizeof(struct tcphdr) + IPPROTO_TCP + len + optlen));
930 {
931 m->m_pkthdr.csum_flags = CSUM_TCP;
932 m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
933 th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
934 htons(sizeof(struct tcphdr) + IPPROTO_TCP + len + optlen));
935
935
936 /* IP version must be set here for ipv4/ipv6 checking later */
937 KASSERT(ip->ip_v == IPVERSION,
938 ("%s: IP version incorrect: %d", __func__, ip->ip_v));
939 }
936 /* IP version must be set here for ipv4/ipv6 checking later */
937 KASSERT(ip->ip_v == IPVERSION,
938 ("%s: IP version incorrect: %d", __func__, ip->ip_v));
939 }
940
941 /*
942 * In transmit state, time the transmission and arrange for
943 * the retransmit. In persist state, just set snd_max.
944 */
945 if (tp->t_force == 0 || !callout_active(tp->tt_persist)) {
946 tcp_seq startseq = tp->snd_nxt;
947

--- 114 unchanged lines hidden (view full) ---

1062 tp->t_inpcb->in6p_outputopts, NULL,
1063 (so->so_options & SO_DONTROUTE), NULL, NULL,
1064 tp->t_inpcb);
1065 } else
1066#endif /* INET6 */
1067 {
1068 ip->ip_len = m->m_pkthdr.len;
1069#ifdef INET6
940
941 /*
942 * In transmit state, time the transmission and arrange for
943 * the retransmit. In persist state, just set snd_max.
944 */
945 if (tp->t_force == 0 || !callout_active(tp->tt_persist)) {
946 tcp_seq startseq = tp->snd_nxt;
947

--- 114 unchanged lines hidden (view full) ---

1062 tp->t_inpcb->in6p_outputopts, NULL,
1063 (so->so_options & SO_DONTROUTE), NULL, NULL,
1064 tp->t_inpcb);
1065 } else
1066#endif /* INET6 */
1067 {
1068 ip->ip_len = m->m_pkthdr.len;
1069#ifdef INET6
1070 if (INP_CHECK_SOCKAF(so, AF_INET6))
1071 ip->ip_ttl = in6_selecthlim(tp->t_inpcb, NULL);
1070 if (INP_CHECK_SOCKAF(so, AF_INET6))
1071 ip->ip_ttl = in6_selecthlim(tp->t_inpcb, NULL);
1072#endif /* INET6 */
1073 /*
1074 * If we do path MTU discovery, then we set DF on every packet.
1075 * This might not be the best thing to do according to RFC3390
1076 * Section 2. However the tcp hostcache migitates the problem
1077 * so it affects only the first tcp connection with a host.
1078 */
1079 if (path_mtu_discovery)

--- 11 unchanged lines hidden (view full) ---

1091 if (tp->t_force == 0 || !callout_active(tp->tt_persist)) {
1092 /*
1093 * No need to check for TH_FIN here because
1094 * the TF_SENTFIN flag handles that case.
1095 */
1096 if ((flags & TH_SYN) == 0) {
1097 if (sack_rxmit)
1098 p->rxmit -= len;
1072#endif /* INET6 */
1073 /*
1074 * If we do path MTU discovery, then we set DF on every packet.
1075 * This might not be the best thing to do according to RFC3390
1076 * Section 2. However the tcp hostcache migitates the problem
1077 * so it affects only the first tcp connection with a host.
1078 */
1079 if (path_mtu_discovery)

--- 11 unchanged lines hidden (view full) ---

1091 if (tp->t_force == 0 || !callout_active(tp->tt_persist)) {
1092 /*
1093 * No need to check for TH_FIN here because
1094 * the TF_SENTFIN flag handles that case.
1095 */
1096 if ((flags & TH_SYN) == 0) {
1097 if (sack_rxmit)
1098 p->rxmit -= len;
1099 else
1099 else
1100 tp->snd_nxt -= len;
1101 }
1102 }
1103
1104out:
1105 if (error == ENOBUFS) {
1106 if (!callout_active(tp->tt_rexmt) &&
1100 tp->snd_nxt -= len;
1101 }
1102 }
1103
1104out:
1105 if (error == ENOBUFS) {
1106 if (!callout_active(tp->tt_rexmt) &&
1107 !callout_active(tp->tt_persist))
1107 !callout_active(tp->tt_persist))
1108 callout_reset(tp->tt_rexmt, tp->t_rxtcur,
1108 callout_reset(tp->tt_rexmt, tp->t_rxtcur,
1109 tcp_timer_rexmt, tp);
1109 tcp_timer_rexmt, tp);
1110 tcp_quench(tp->t_inpcb, 0);
1111 return (0);
1112 }
1113 if (error == EMSGSIZE) {
1114 /*
1115 * ip_output() will have already fixed the route
1116 * for us. tcp_mtudisc() will, as its last action,
1117 * initiate retransmission, so it is important to

--- 59 unchanged lines hidden ---
1110 tcp_quench(tp->t_inpcb, 0);
1111 return (0);
1112 }
1113 if (error == EMSGSIZE) {
1114 /*
1115 * ip_output() will have already fixed the route
1116 * for us. tcp_mtudisc() will, as its last action,
1117 * initiate retransmission, so it is important to

--- 59 unchanged lines hidden ---