tcp_congctl.c revision 1.6 1 /* $NetBSD: tcp_congctl.c,v 1.6 2006/10/15 17:45:06 rpaulo Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998, 1999, 2001, 2005, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
9 * Facility, NASA Ames Research Center.
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Charles M. Hannum.
12 * This code is derived from software contributed to The NetBSD Foundation
13 * by Rui Paulo.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the NetBSD
26 * Foundation, Inc. and its contributors.
27 * 4. Neither the name of The NetBSD Foundation nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
32 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
35 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 /*
45 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
46 * All rights reserved.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. Neither the name of the project nor the names of its contributors
57 * may be used to endorse or promote products derived from this software
58 * without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 */
72
73 /*
74 * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
75 *
76 * NRL grants permission for redistribution and use in source and binary
77 * forms, with or without modification, of the software and documentation
78 * created at NRL provided that the following conditions are met:
79 *
80 * 1. Redistributions of source code must retain the above copyright
81 * notice, this list of conditions and the following disclaimer.
82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution.
85 * 3. All advertising materials mentioning features or use of this software
86 * must display the following acknowledgements:
87 * This product includes software developed by the University of
88 * California, Berkeley and its contributors.
89 * This product includes software developed at the Information
90 * Technology Division, US Naval Research Laboratory.
91 * 4. Neither the name of the NRL nor the names of its contributors
92 * may be used to endorse or promote products derived from this software
93 * without specific prior written permission.
94 *
95 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
96 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
97 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
98 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
99 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
100 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
101 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
102 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
103 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
104 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
105 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
106 *
107 * The views and conclusions contained in the software and documentation
108 * are those of the authors and should not be interpreted as representing
109 * official policies, either expressed or implied, of the US Naval
110 * Research Laboratory (NRL).
111 */
112
113 /*
114 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
115 * The Regents of the University of California. All rights reserved.
116 *
117 * Redistribution and use in source and binary forms, with or without
118 * modification, are permitted provided that the following conditions
119 * are met:
120 * 1. Redistributions of source code must retain the above copyright
121 * notice, this list of conditions and the following disclaimer.
122 * 2. Redistributions in binary form must reproduce the above copyright
123 * notice, this list of conditions and the following disclaimer in the
124 * documentation and/or other materials provided with the distribution.
125 * 3. Neither the name of the University nor the names of its contributors
126 * may be used to endorse or promote products derived from this software
127 * without specific prior written permission.
128 *
129 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
130 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
131 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
132 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
133 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
134 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
135 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
136 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
137 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
138 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
139 * SUCH DAMAGE.
140 *
141 * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
142 */
143
144 #include <sys/cdefs.h>
145 __KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.6 2006/10/15 17:45:06 rpaulo Exp $");
146
147 #include "opt_inet.h"
148 #include "opt_tcp_debug.h"
149 #include "opt_tcp_congctl.h"
150
151 #include <sys/param.h>
152 #include <sys/systm.h>
153 #include <sys/malloc.h>
154 #include <sys/mbuf.h>
155 #include <sys/protosw.h>
156 #include <sys/socket.h>
157 #include <sys/socketvar.h>
158 #include <sys/errno.h>
159 #include <sys/syslog.h>
160 #include <sys/pool.h>
161 #include <sys/domain.h>
162 #include <sys/kernel.h>
163 #include <sys/lock.h>
164
165 #include <net/if.h>
166 #include <net/route.h>
167
168 #include <netinet/in.h>
169 #include <netinet/in_systm.h>
170 #include <netinet/ip.h>
171 #include <netinet/in_pcb.h>
172 #include <netinet/in_var.h>
173 #include <netinet/ip_var.h>
174
175 #ifdef INET6
176 #ifndef INET
177 #include <netinet/in.h>
178 #endif
179 #include <netinet/ip6.h>
180 #include <netinet6/ip6_var.h>
181 #include <netinet6/in6_pcb.h>
182 #include <netinet6/ip6_var.h>
183 #include <netinet6/in6_var.h>
184 #include <netinet/icmp6.h>
185 #include <netinet6/nd6.h>
186 #endif
187
188 #include <netinet/tcp.h>
189 #include <netinet/tcp_fsm.h>
190 #include <netinet/tcp_seq.h>
191 #include <netinet/tcp_timer.h>
192 #include <netinet/tcp_var.h>
193 #include <netinet/tcpip.h>
194 #include <netinet/tcp_congctl.h>
195 #ifdef TCP_DEBUG
196 #include <netinet/tcp_debug.h>
197 #endif
198
199 /*
200 * TODO:
201 * consider separating the actual implementations in another file.
202 */
203
204 static int tcp_reno_fast_retransmit(struct tcpcb *, struct tcphdr *);
205 static void tcp_reno_slow_retransmit(struct tcpcb *);
206 static void tcp_reno_fast_retransmit_newack(struct tcpcb *, struct tcphdr *);
207 static void tcp_reno_newack(struct tcpcb *, struct tcphdr *);
208 static void tcp_reno_congestion_exp(struct tcpcb *tp);
209
210 static int tcp_newreno_fast_retransmit(struct tcpcb *, struct tcphdr *);
211 static void tcp_newreno_fast_retransmit_newack(struct tcpcb *,
212 struct tcphdr *);
213 static void tcp_newreno_newack(struct tcpcb *, struct tcphdr *);
214
215
216 static void tcp_congctl_fillnames(void);
217
218 extern int tcprexmtthresh;
219
220 MALLOC_DEFINE(M_TCPCONGCTL, "tcpcongctl", "TCP congestion control structures");
221
222 /*
223 * Used to list the available congestion control algorithms.
224 */
225 struct tcp_congctlent {
226 TAILQ_ENTRY(tcp_congctlent) congctl_ent;
227 char congctl_name[TCPCC_MAXLEN];
228 struct tcp_congctl *congctl_ctl;
229 };
230 TAILQ_HEAD(, tcp_congctlent) tcp_congctlhd;
231
232 struct simplelock tcp_congctl_slock;
233
234 void
235 tcp_congctl_init(void)
236 {
237 int r;
238
239 TAILQ_INIT(&tcp_congctlhd);
240 simple_lock_init(&tcp_congctl_slock);
241
242 /* Base algorithms. */
243 r = tcp_congctl_register("reno", &tcp_reno_ctl);
244 KASSERT(r == 0);
245 r = tcp_congctl_register("newreno", &tcp_newreno_ctl);
246 KASSERT(r == 0);
247
248 /* NewReno is the default. */
249 #ifndef TCP_CONGCTL_DEFAULT
250 #define TCP_CONGCTL_DEFAULT "newreno"
251 #endif
252
253 r = tcp_congctl_select(NULL, TCP_CONGCTL_DEFAULT);
254 KASSERT(r == 0);
255 }
256
257 /*
258 * Register a congestion algorithm and select it if we have none.
259 */
260 int
261 tcp_congctl_register(const char *name, struct tcp_congctl *tcc)
262 {
263 struct tcp_congctlent *ntcc, *tccp;
264
265 TAILQ_FOREACH(tccp, &tcp_congctlhd, congctl_ent)
266 if (!strcmp(name, tccp->congctl_name)) {
267 /* name already registered */
268 return EEXIST;
269 }
270
271 ntcc = malloc(sizeof(*ntcc), M_TCPCONGCTL, M_WAITOK);
272
273 strlcpy(ntcc->congctl_name, name, sizeof(ntcc->congctl_name) - 1);
274 ntcc->congctl_ctl = tcc;
275
276 TAILQ_INSERT_TAIL(&tcp_congctlhd, ntcc, congctl_ent);
277 tcp_congctl_fillnames();
278
279 if (TAILQ_FIRST(&tcp_congctlhd) == ntcc)
280 tcp_congctl_select(NULL, name);
281
282 return 0;
283 }
284
285 int
286 tcp_congctl_unregister(const char *name)
287 {
288 struct tcp_congctlent *tccp, *rtccp;
289 unsigned int size;
290
291 rtccp = NULL;
292 size = 0;
293 TAILQ_FOREACH(tccp, &tcp_congctlhd, congctl_ent) {
294 if (!strcmp(name, tccp->congctl_name))
295 rtccp = tccp;
296 size++;
297 }
298
299 if (!rtccp)
300 return ENOENT;
301
302 if (size <= 1 || tcp_congctl_global == rtccp->congctl_ctl ||
303 rtccp->congctl_ctl->refcnt)
304 return EBUSY;
305
306 TAILQ_REMOVE(&tcp_congctlhd, rtccp, congctl_ent);
307 free(rtccp, M_TCPCONGCTL);
308 tcp_congctl_fillnames();
309
310 return 0;
311 }
312
313 /*
314 * Select a congestion algorithm by name.
315 */
316 int
317 tcp_congctl_select(struct tcpcb *tp, const char *name)
318 {
319 struct tcp_congctlent *tccp;
320
321 KASSERT(name);
322
323 TAILQ_FOREACH(tccp, &tcp_congctlhd, congctl_ent)
324 if (!strcmp(name, tccp->congctl_name)) {
325 if (tp) {
326 simple_lock(&tcp_congctl_slock);
327 tp->t_congctl->refcnt--;
328 tp->t_congctl = tccp->congctl_ctl;
329 tp->t_congctl->refcnt++;
330 simple_unlock(&tcp_congctl_slock);
331 } else {
332 tcp_congctl_global = tccp->congctl_ctl;
333 strlcpy(tcp_congctl_global_name,
334 tccp->congctl_name,
335 sizeof(tcp_congctl_global_name) - 1);
336 }
337 return 0;
338 }
339
340 return EINVAL;
341 }
342
343 /*
344 * Returns the name of a congestion algorithm.
345 */
346 const char *
347 tcp_congctl_bystruct(const struct tcp_congctl *tcc)
348 {
349 struct tcp_congctlent *tccp;
350
351 KASSERT(tcc);
352
353 TAILQ_FOREACH(tccp, &tcp_congctlhd, congctl_ent)
354 if (tccp->congctl_ctl == tcc)
355 return tccp->congctl_name;
356
357 return NULL;
358 }
359
360 static void
361 tcp_congctl_fillnames(void)
362 {
363 struct tcp_congctlent *tccp;
364 const char *delim = " ";
365
366 tcp_congctl_avail[0] = '\0';
367 TAILQ_FOREACH(tccp, &tcp_congctlhd, congctl_ent) {
368 strlcat(tcp_congctl_avail, tccp->congctl_name,
369 sizeof(tcp_congctl_avail) - 1);
370 if (TAILQ_NEXT(tccp, congctl_ent))
371 strlcat(tcp_congctl_avail, delim,
372 sizeof(tcp_congctl_avail) - 1);
373 }
374
375 }
376
377 /* ------------------------------------------------------------------------ */
378
379 /*
380 * TCP/Reno congestion control.
381 */
382 static void
383 tcp_reno_congestion_exp(struct tcpcb *tp)
384 {
385 u_int win;
386
387 /*
388 * Halve the congestion window and reduce the
389 * slow start threshold.
390 */
391 win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
392 if (win < 2)
393 win = 2;
394
395 tp->snd_ssthresh = win * tp->t_segsz;
396 tp->snd_recover = tp->snd_max;
397 tp->snd_cwnd = tp->snd_ssthresh;
398
399 if (TCP_ECN_ALLOWED(tp))
400 tp->t_flags |= TF_ECN_SND_CWR;
401 }
402
403
404
405 static int
406 tcp_reno_fast_retransmit(struct tcpcb *tp, struct tcphdr *th)
407 {
408 tcp_seq onxt;
409
410 onxt = tp->snd_nxt;
411 tcp_reno_congestion_exp(tp);
412 tp->t_partialacks = 0;
413 TCP_TIMER_DISARM(tp, TCPT_REXMT);
414 tp->t_rtttime = 0;
415 if (TCP_SACK_ENABLED(tp)) {
416 tp->t_dupacks = tcprexmtthresh;
417 tp->sack_newdata = tp->snd_nxt;
418 tp->snd_cwnd = tp->t_segsz;
419 (void) tcp_output(tp);
420 return 0;
421 }
422 tp->snd_nxt = th->th_ack;
423 tp->snd_cwnd = tp->t_segsz;
424 (void) tcp_output(tp);
425 tp->snd_cwnd = tp->snd_ssthresh + tp->t_segsz * tp->t_dupacks;
426 if (SEQ_GT(onxt, tp->snd_nxt))
427 tp->snd_nxt = onxt;
428
429 return 0;
430 }
431
432 static void
433 tcp_reno_slow_retransmit(struct tcpcb *tp)
434 {
435 u_int win;
436
437 /*
438 * Close the congestion window down to one segment
439 * (we'll open it by one segment for each ack we get).
440 * Since we probably have a window's worth of unacked
441 * data accumulated, this "slow start" keeps us from
442 * dumping all that data as back-to-back packets (which
443 * might overwhelm an intermediate gateway).
444 *
445 * There are two phases to the opening: Initially we
446 * open by one mss on each ack. This makes the window
447 * size increase exponentially with time. If the
448 * window is larger than the path can handle, this
449 * exponential growth results in dropped packet(s)
450 * almost immediately. To get more time between
451 * drops but still "push" the network to take advantage
452 * of improving conditions, we switch from exponential
453 * to linear window opening at some threshhold size.
454 * For a threshhold, we use half the current window
455 * size, truncated to a multiple of the mss.
456 *
457 * (the minimum cwnd that will give us exponential
458 * growth is 2 mss. We don't allow the threshhold
459 * to go below this.)
460 */
461
462 win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
463 if (win < 2)
464 win = 2;
465 /* Loss Window MUST be one segment. */
466 tp->snd_cwnd = tp->t_segsz;
467 tp->snd_ssthresh = win * tp->t_segsz;
468 tp->t_partialacks = -1;
469 tp->t_dupacks = 0;
470 }
471
472 static void
473 tcp_reno_fast_retransmit_newack(struct tcpcb *tp, struct tcphdr *th __unused)
474 {
475 if (tp->t_partialacks < 0) {
476 /*
477 * We were not in fast recovery. Reset the duplicate ack
478 * counter.
479 */
480 tp->t_dupacks = 0;
481 } else {
482 /*
483 * Clamp the congestion window to the crossover point and
484 * exit fast recovery.
485 */
486 if (tp->snd_cwnd > tp->snd_ssthresh)
487 tp->snd_cwnd = tp->snd_ssthresh;
488 tp->t_partialacks = -1;
489 tp->t_dupacks = 0;
490 }
491 }
492
493 static void
494 tcp_reno_newack(struct tcpcb *tp, struct tcphdr *th __unused)
495 {
496 /*
497 * When new data is acked, open the congestion window.
498 * If the window gives us less than ssthresh packets
499 * in flight, open exponentially (segsz per packet).
500 * Otherwise open linearly: segsz per window
501 * (segsz^2 / cwnd per packet).
502 */
503
504 u_int cw = tp->snd_cwnd;
505 u_int incr = tp->t_segsz;
506
507 if (cw >= tp->snd_ssthresh)
508 incr = incr * incr / cw;
509
510 tp->snd_cwnd = min(cw + incr, TCP_MAXWIN << tp->snd_scale);
511 }
512
513 struct tcp_congctl tcp_reno_ctl = {
514 .fast_retransmit = tcp_reno_fast_retransmit,
515 .slow_retransmit = tcp_reno_slow_retransmit,
516 .fast_retransmit_newack = tcp_reno_fast_retransmit_newack,
517 .newack = tcp_reno_newack,
518 .cong_exp = tcp_reno_congestion_exp,
519 };
520
521 /*
522 * TCP/NewReno Congestion control.
523 */
524 static int
525 tcp_newreno_fast_retransmit(struct tcpcb *tp, struct tcphdr *th)
526 {
527 if (SEQ_LT(th->th_ack, tp->snd_high)) {
528 /*
529 * False fast retransmit after timeout.
530 * Do not enter fast recovery
531 */
532 tp->t_dupacks = 0;
533 return 1;
534 } else {
535 /*
536 * Fast retransmit is same as reno.
537 */
538 return tcp_reno_fast_retransmit(tp, th);
539 }
540
541 return 0;
542 }
543
544 /*
545 * Implement the NewReno response to a new ack, checking for partial acks in
546 * fast recovery.
547 */
548 static void
549 tcp_newreno_fast_retransmit_newack(struct tcpcb *tp, struct tcphdr *th)
550 {
551 if (tp->t_partialacks < 0) {
552 /*
553 * We were not in fast recovery. Reset the duplicate ack
554 * counter.
555 */
556 tp->t_dupacks = 0;
557 } else if (SEQ_LT(th->th_ack, tp->snd_recover)) {
558 /*
559 * This is a partial ack. Retransmit the first unacknowledged
560 * segment and deflate the congestion window by the amount of
561 * acknowledged data. Do not exit fast recovery.
562 */
563 tcp_seq onxt = tp->snd_nxt;
564 u_long ocwnd = tp->snd_cwnd;
565
566 /*
567 * snd_una has not yet been updated and the socket's send
568 * buffer has not yet drained off the ACK'd data, so we
569 * have to leave snd_una as it was to get the correct data
570 * offset in tcp_output().
571 */
572 if (++tp->t_partialacks == 1)
573 TCP_TIMER_DISARM(tp, TCPT_REXMT);
574 tp->t_rtttime = 0;
575 tp->snd_nxt = th->th_ack;
576 /*
577 * Set snd_cwnd to one segment beyond ACK'd offset. snd_una
578 * is not yet updated when we're called.
579 */
580 tp->snd_cwnd = tp->t_segsz + (th->th_ack - tp->snd_una);
581 (void) tcp_output(tp);
582 tp->snd_cwnd = ocwnd;
583 if (SEQ_GT(onxt, tp->snd_nxt))
584 tp->snd_nxt = onxt;
585 /*
586 * Partial window deflation. Relies on fact that tp->snd_una
587 * not updated yet.
588 */
589 tp->snd_cwnd -= (th->th_ack - tp->snd_una - tp->t_segsz);
590 } else {
591 /*
592 * Complete ack. Inflate the congestion window to ssthresh
593 * and exit fast recovery.
594 *
595 * Window inflation should have left us with approx.
596 * snd_ssthresh outstanding data. But in case we
597 * would be inclined to send a burst, better to do
598 * it via the slow start mechanism.
599 */
600 if (SEQ_SUB(tp->snd_max, th->th_ack) < tp->snd_ssthresh)
601 tp->snd_cwnd = SEQ_SUB(tp->snd_max, th->th_ack)
602 + tp->t_segsz;
603 else
604 tp->snd_cwnd = tp->snd_ssthresh;
605 tp->t_partialacks = -1;
606 tp->t_dupacks = 0;
607 }
608 }
609
610 static void
611 tcp_newreno_newack(struct tcpcb *tp, struct tcphdr *th)
612 {
613 /*
614 * If we are still in fast recovery (meaning we are using
615 * NewReno and we have only received partial acks), do not
616 * inflate the window yet.
617 */
618 if (tp->t_partialacks < 0)
619 tcp_reno_newack(tp, th);
620 }
621
622
623 struct tcp_congctl tcp_newreno_ctl = {
624 .fast_retransmit = tcp_newreno_fast_retransmit,
625 .slow_retransmit = tcp_reno_slow_retransmit,
626 .fast_retransmit_newack = tcp_newreno_fast_retransmit_newack,
627 .newack = tcp_newreno_newack,
628 .cong_exp = tcp_reno_congestion_exp,
629 };
630
631
632