Wed Oct 9 05:29:18 2019 UTC ()
 All of snd_wnd, snd_cwnd and snd_ssthresh in stuct tcpcb are u_long,
so use u_long and ulmin() instead of u_int and uimin(). Found by lgtm bot.

XXX TCP's sequence number is uint32_t, so it might be good to change some
entries in struct tcpcb to uint32_t instead of u_long. FreeBSD did it.


(msaitoh)
diff -r1.26 -r1.27 src/sys/netinet/tcp_congctl.c

cvs diff -r1.26 -r1.27 src/sys/netinet/tcp_congctl.c (expand / switch to unified diff)

--- src/sys/netinet/tcp_congctl.c 2018/09/03 16:29:36 1.26
+++ src/sys/netinet/tcp_congctl.c 2019/10/09 05:29:18 1.27
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tcp_congctl.c,v 1.26 2018/09/03 16:29:36 riastradh Exp $ */ 1/* $NetBSD: tcp_congctl.c,v 1.27 2019/10/09 05:29:18 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 1999, 2001, 2005, 2006 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 1999, 2001, 2005, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 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 8 * by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
9 * Facility, NASA Ames Research Center. 9 * Facility, NASA Ames Research Center.
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Charles M. Hannum. 11 * by Charles M. Hannum.
12 * This code is derived from software contributed to The NetBSD Foundation 12 * This code is derived from software contributed to The NetBSD Foundation
13 * by Rui Paulo. 13 * by Rui Paulo.
14 * 14 *
@@ -125,27 +125,27 @@ @@ -125,27 +125,27 @@
125 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 125 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
126 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 126 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
127 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 127 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
128 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 128 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
129 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 129 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
130 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 130 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
131 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 131 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
132 * SUCH DAMAGE. 132 * SUCH DAMAGE.
133 * 133 *
134 * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95 134 * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
135 */ 135 */
136 136
137#include <sys/cdefs.h> 137#include <sys/cdefs.h>
138__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.26 2018/09/03 16:29:36 riastradh Exp $"); 138__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.27 2019/10/09 05:29:18 msaitoh Exp $");
139 139
140#ifdef _KERNEL_OPT 140#ifdef _KERNEL_OPT
141#include "opt_inet.h" 141#include "opt_inet.h"
142#include "opt_tcp_debug.h" 142#include "opt_tcp_debug.h"
143#include "opt_tcp_congctl.h" 143#include "opt_tcp_congctl.h"
144#endif 144#endif
145 145
146#include <sys/param.h> 146#include <sys/param.h>
147#include <sys/systm.h> 147#include <sys/systm.h>
148#include <sys/malloc.h> 148#include <sys/malloc.h>
149#include <sys/mbuf.h> 149#include <sys/mbuf.h>
150#include <sys/protosw.h> 150#include <sys/protosw.h>
151#include <sys/socket.h> 151#include <sys/socket.h>
@@ -417,32 +417,32 @@ tcp_congctl_fillnames(void) @@ -417,32 +417,32 @@ tcp_congctl_fillnames(void)
417/* Window reduction (1-beta) for [New]Reno: 0.5 */ 417/* Window reduction (1-beta) for [New]Reno: 0.5 */
418#define RENO_BETAA 1 418#define RENO_BETAA 1
419#define RENO_BETAB 2 419#define RENO_BETAB 2
420/* Window reduction (1-beta) for Cubic: 0.8 */ 420/* Window reduction (1-beta) for Cubic: 0.8 */
421#define CUBIC_BETAA 4 421#define CUBIC_BETAA 4
422#define CUBIC_BETAB 5 422#define CUBIC_BETAB 5
423/* Draft Rhee Section 4.1 */ 423/* Draft Rhee Section 4.1 */
424#define CUBIC_CA 4 424#define CUBIC_CA 4
425#define CUBIC_CB 10 425#define CUBIC_CB 10
426 426
427static void 427static void
428tcp_common_congestion_exp(struct tcpcb *tp, int betaa, int betab) 428tcp_common_congestion_exp(struct tcpcb *tp, int betaa, int betab)
429{ 429{
430 u_int win; 430 u_long win;
431 431
432 /*  432 /*
433 * Reduce the congestion window and the slow start threshold. 433 * Reduce the congestion window and the slow start threshold.
434 */ 434 */
435 win = uimin(tp->snd_wnd, tp->snd_cwnd) * betaa / betab / tp->t_segsz; 435 win = ulmin(tp->snd_wnd, tp->snd_cwnd) * betaa / betab / tp->t_segsz;
436 if (win < 2) 436 if (win < 2)
437 win = 2; 437 win = 2;
438 438
439 tp->snd_ssthresh = win * tp->t_segsz; 439 tp->snd_ssthresh = win * tp->t_segsz;
440 tp->snd_recover = tp->snd_max; 440 tp->snd_recover = tp->snd_max;
441 tp->snd_cwnd = tp->snd_ssthresh; 441 tp->snd_cwnd = tp->snd_ssthresh;
442 442
443 /* 443 /*
444 * When using TCP ECN, notify the peer that 444 * When using TCP ECN, notify the peer that
445 * we reduced the cwnd. 445 * we reduced the cwnd.
446 */ 446 */
447 if (TCP_ECN_ALLOWED(tp)) 447 if (TCP_ECN_ALLOWED(tp))
448 tp->t_flags |= TF_ECN_SND_CWR; 448 tp->t_flags |= TF_ECN_SND_CWR;
@@ -509,54 +509,54 @@ tcp_reno_fast_retransmit(struct tcpcb *t @@ -509,54 +509,54 @@ tcp_reno_fast_retransmit(struct tcpcb *t
509 * window size so do congestion avoidance 509 * window size so do congestion avoidance
510 * (set ssthresh to half the current window 510 * (set ssthresh to half the current window
511 * and pull our congestion window back to 511 * and pull our congestion window back to
512 * the new ssthresh). 512 * the new ssthresh).
513 */ 513 */
514 514
515 tcp_reno_congestion_exp(tp); 515 tcp_reno_congestion_exp(tp);
516 return tcp_reno_do_fast_retransmit(tp, th); 516 return tcp_reno_do_fast_retransmit(tp, th);
517} 517}
518 518
519static void 519static void
520tcp_reno_slow_retransmit(struct tcpcb *tp) 520tcp_reno_slow_retransmit(struct tcpcb *tp)
521{ 521{
522 u_int win; 522 u_long win;
523 523
524 /* 524 /*
525 * Close the congestion window down to one segment 525 * Close the congestion window down to one segment
526 * (we'll open it by one segment for each ack we get). 526 * (we'll open it by one segment for each ack we get).
527 * Since we probably have a window's worth of unacked 527 * Since we probably have a window's worth of unacked
528 * data accumulated, this "slow start" keeps us from 528 * data accumulated, this "slow start" keeps us from
529 * dumping all that data as back-to-back packets (which 529 * dumping all that data as back-to-back packets (which
530 * might overwhelm an intermediate gateway). 530 * might overwhelm an intermediate gateway).
531 * 531 *
532 * There are two phases to the opening: Initially we 532 * There are two phases to the opening: Initially we
533 * open by one mss on each ack. This makes the window 533 * open by one mss on each ack. This makes the window
534 * size increase exponentially with time. If the 534 * size increase exponentially with time. If the
535 * window is larger than the path can handle, this 535 * window is larger than the path can handle, this
536 * exponential growth results in dropped packet(s) 536 * exponential growth results in dropped packet(s)
537 * almost immediately. To get more time between 537 * almost immediately. To get more time between
538 * drops but still "push" the network to take advantage 538 * drops but still "push" the network to take advantage
539 * of improving conditions, we switch from exponential 539 * of improving conditions, we switch from exponential
540 * to linear window opening at some threshhold size. 540 * to linear window opening at some threshhold size.
541 * For a threshhold, we use half the current window 541 * For a threshhold, we use half the current window
542 * size, truncated to a multiple of the mss. 542 * size, truncated to a multiple of the mss.
543 * 543 *
544 * (the minimum cwnd that will give us exponential 544 * (the minimum cwnd that will give us exponential
545 * growth is 2 mss. We don't allow the threshhold 545 * growth is 2 mss. We don't allow the threshhold
546 * to go below this.) 546 * to go below this.)
547 */ 547 */
548 548
549 win = uimin(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz; 549 win = ulmin(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
550 if (win < 2) 550 if (win < 2)
551 win = 2; 551 win = 2;
552 /* Loss Window MUST be one segment. */ 552 /* Loss Window MUST be one segment. */
553 tp->snd_cwnd = tp->t_segsz; 553 tp->snd_cwnd = tp->t_segsz;
554 tp->snd_ssthresh = win * tp->t_segsz; 554 tp->snd_ssthresh = win * tp->t_segsz;
555 tp->t_partialacks = -1; 555 tp->t_partialacks = -1;
556 tp->t_dupacks = 0; 556 tp->t_dupacks = 0;
557 tp->t_bytes_acked = 0; 557 tp->t_bytes_acked = 0;
558 558
559 if (TCP_ECN_ALLOWED(tp)) 559 if (TCP_ECN_ALLOWED(tp))
560 tp->t_flags |= TF_ECN_SND_CWR; 560 tp->t_flags |= TF_ECN_SND_CWR;
561} 561}
562 562