tcp_input.c (3cf38784e2948c7dadac9734024299c9bc17b989) tcp_input.c (adc56f5a383771f594829b7db9c263b6f0dcf1bd)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 2007-2008,2010
7 * Swinburne University of Technology, Melbourne, Australia.
8 * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>

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

53__FBSDID("$FreeBSD$");
54
55#include "opt_inet.h"
56#include "opt_inet6.h"
57#include "opt_ipsec.h"
58#include "opt_tcpdebug.h"
59
60#include <sys/param.h>
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 2007-2008,2010
7 * Swinburne University of Technology, Melbourne, Australia.
8 * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>

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

53__FBSDID("$FreeBSD$");
54
55#include "opt_inet.h"
56#include "opt_inet6.h"
57#include "opt_ipsec.h"
58#include "opt_tcpdebug.h"
59
60#include <sys/param.h>
61#include <sys/arb.h>
61#include <sys/kernel.h>
62#ifdef TCP_HHOOK
63#include <sys/hhook.h>
64#endif
65#include <sys/malloc.h>
66#include <sys/mbuf.h>
67#include <sys/proc.h> /* for proc0 declaration */
68#include <sys/protosw.h>
62#include <sys/kernel.h>
63#ifdef TCP_HHOOK
64#include <sys/hhook.h>
65#endif
66#include <sys/malloc.h>
67#include <sys/mbuf.h>
68#include <sys/proc.h> /* for proc0 declaration */
69#include <sys/protosw.h>
70#include <sys/qmath.h>
69#include <sys/sdt.h>
70#include <sys/signalvar.h>
71#include <sys/socket.h>
72#include <sys/socketvar.h>
73#include <sys/sysctl.h>
74#include <sys/syslog.h>
75#include <sys/systm.h>
71#include <sys/sdt.h>
72#include <sys/signalvar.h>
73#include <sys/socket.h>
74#include <sys/socketvar.h>
75#include <sys/sysctl.h>
76#include <sys/syslog.h>
77#include <sys/systm.h>
78#include <sys/stats.h>
76
77#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
78
79#include <vm/uma.h>
80
81#include <net/if.h>
82#include <net/if_var.h>
83#include <net/route.h>

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

293
294/*
295 * CC wrapper hook functions
296 */
297void
298cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t nsegs,
299 uint16_t type)
300{
79
80#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
81
82#include <vm/uma.h>
83
84#include <net/if.h>
85#include <net/if_var.h>
86#include <net/route.h>

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

296
297/*
298 * CC wrapper hook functions
299 */
300void
301cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t nsegs,
302 uint16_t type)
303{
304#ifdef STATS
305 int32_t gput;
306#endif
307
301 INP_WLOCK_ASSERT(tp->t_inpcb);
302
303 tp->ccv->nsegs = nsegs;
304 tp->ccv->bytes_this_ack = BYTES_THIS_ACK(tp, th);
305 if ((!V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd)) ||
306 (V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd) &&
307 (tp->snd_cwnd < (tcp_compute_pipe(tp) * 2))))
308 tp->ccv->flags |= CCF_CWND_LIMITED;
309 else
310 tp->ccv->flags &= ~CCF_CWND_LIMITED;
311
312 if (type == CC_ACK) {
308 INP_WLOCK_ASSERT(tp->t_inpcb);
309
310 tp->ccv->nsegs = nsegs;
311 tp->ccv->bytes_this_ack = BYTES_THIS_ACK(tp, th);
312 if ((!V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd)) ||
313 (V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd) &&
314 (tp->snd_cwnd < (tcp_compute_pipe(tp) * 2))))
315 tp->ccv->flags |= CCF_CWND_LIMITED;
316 else
317 tp->ccv->flags &= ~CCF_CWND_LIMITED;
318
319 if (type == CC_ACK) {
320#ifdef STATS
321 stats_voi_update_abs_s32(tp->t_stats, VOI_TCP_CALCFRWINDIFF,
322 ((int32_t)tp->snd_cwnd) - tp->snd_wnd);
323 if (!IN_RECOVERY(tp->t_flags))
324 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_ACKLEN,
325 tp->ccv->bytes_this_ack / (tcp_maxseg(tp) * nsegs));
326 if ((tp->t_flags & TF_GPUTINPROG) &&
327 SEQ_GEQ(th->th_ack, tp->gput_ack)) {
328 /*
329 * Compute goodput in bits per millisecond.
330 */
331 gput = (((int64_t)(th->th_ack - tp->gput_seq)) << 3) /
332 max(1, tcp_ts_getticks() - tp->gput_ts);
333 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_GPUT,
334 gput);
335 /*
336 * XXXLAS: This is a temporary hack, and should be
337 * chained off VOI_TCP_GPUT when stats(9) grows an API
338 * to deal with chained VOIs.
339 */
340 if (tp->t_stats_gput_prev > 0)
341 stats_voi_update_abs_s32(tp->t_stats,
342 VOI_TCP_GPUT_ND,
343 ((gput - tp->t_stats_gput_prev) * 100) /
344 tp->t_stats_gput_prev);
345 tp->t_flags &= ~TF_GPUTINPROG;
346 tp->t_stats_gput_prev = gput;
347 }
348#endif /* STATS */
313 if (tp->snd_cwnd > tp->snd_ssthresh) {
314 tp->t_bytes_acked += min(tp->ccv->bytes_this_ack,
315 nsegs * V_tcp_abc_l_var * tcp_maxseg(tp));
316 if (tp->t_bytes_acked >= tp->snd_cwnd) {
317 tp->t_bytes_acked -= tp->snd_cwnd;
318 tp->ccv->flags |= CCF_ABC_SENTAWND;
319 }
320 } else {
321 tp->ccv->flags &= ~CCF_ABC_SENTAWND;
322 tp->t_bytes_acked = 0;
323 }
324 }
325
326 if (CC_ALGO(tp)->ack_received != NULL) {
327 /* XXXLAS: Find a way to live without this */
328 tp->ccv->curack = th->th_ack;
329 CC_ALGO(tp)->ack_received(tp->ccv, type);
330 }
349 if (tp->snd_cwnd > tp->snd_ssthresh) {
350 tp->t_bytes_acked += min(tp->ccv->bytes_this_ack,
351 nsegs * V_tcp_abc_l_var * tcp_maxseg(tp));
352 if (tp->t_bytes_acked >= tp->snd_cwnd) {
353 tp->t_bytes_acked -= tp->snd_cwnd;
354 tp->ccv->flags |= CCF_ABC_SENTAWND;
355 }
356 } else {
357 tp->ccv->flags &= ~CCF_ABC_SENTAWND;
358 tp->t_bytes_acked = 0;
359 }
360 }
361
362 if (CC_ALGO(tp)->ack_received != NULL) {
363 /* XXXLAS: Find a way to live without this */
364 tp->ccv->curack = th->th_ack;
365 CC_ALGO(tp)->ack_received(tp->ccv, type);
366 }
367#ifdef STATS
368 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_LCWIN, tp->snd_cwnd);
369#endif
331}
332
333void
334cc_conn_init(struct tcpcb *tp)
335{
336 struct hc_metrics_lite metrics;
337 struct inpcb *inp = tp->t_inpcb;
338 u_int maxseg;

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

388
389void inline
390cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type)
391{
392 u_int maxseg;
393
394 INP_WLOCK_ASSERT(tp->t_inpcb);
395
370}
371
372void
373cc_conn_init(struct tcpcb *tp)
374{
375 struct hc_metrics_lite metrics;
376 struct inpcb *inp = tp->t_inpcb;
377 u_int maxseg;

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

427
428void inline
429cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type)
430{
431 u_int maxseg;
432
433 INP_WLOCK_ASSERT(tp->t_inpcb);
434
435#ifdef STATS
436 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_CSIG, type);
437#endif
438
396 switch(type) {
397 case CC_NDUPACK:
398 if (!IN_FASTRECOVERY(tp->t_flags)) {
399 tp->snd_recover = tp->snd_max;
400 if (tp->t_flags2 & TF2_ECN_PERMIT)
401 tp->t_flags2 |= TF2_ECN_SND_CWR;
402 }
403 break;

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

1491 */
1492 tp->t_rcvtime = ticks;
1493
1494 /*
1495 * Scale up the window into a 32-bit value.
1496 * For the SYN_SENT state the scale is zero.
1497 */
1498 tiwin = th->th_win << tp->snd_scale;
439 switch(type) {
440 case CC_NDUPACK:
441 if (!IN_FASTRECOVERY(tp->t_flags)) {
442 tp->snd_recover = tp->snd_max;
443 if (tp->t_flags2 & TF2_ECN_PERMIT)
444 tp->t_flags2 |= TF2_ECN_SND_CWR;
445 }
446 break;

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

1534 */
1535 tp->t_rcvtime = ticks;
1536
1537 /*
1538 * Scale up the window into a 32-bit value.
1539 * For the SYN_SENT state the scale is zero.
1540 */
1541 tiwin = th->th_win << tp->snd_scale;
1542#ifdef STATS
1543 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_FRWIN, tiwin);
1544#endif
1499
1500 /*
1501 * TCP ECN processing.
1502 */
1503 if (tp->t_flags2 & TF2_ECN_PERMIT) {
1504 if (thflags & TH_CWR)
1505 tp->t_flags2 &= ~TF2_ECN_SND_ECE;
1506 switch (iptos & IPTOS_ECN_MASK) {

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

3354tcp_xmit_timer(struct tcpcb *tp, int rtt)
3355{
3356 int delta;
3357
3358 INP_WLOCK_ASSERT(tp->t_inpcb);
3359
3360 TCPSTAT_INC(tcps_rttupdated);
3361 tp->t_rttupdated++;
1545
1546 /*
1547 * TCP ECN processing.
1548 */
1549 if (tp->t_flags2 & TF2_ECN_PERMIT) {
1550 if (thflags & TH_CWR)
1551 tp->t_flags2 &= ~TF2_ECN_SND_ECE;
1552 switch (iptos & IPTOS_ECN_MASK) {

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

3400tcp_xmit_timer(struct tcpcb *tp, int rtt)
3401{
3402 int delta;
3403
3404 INP_WLOCK_ASSERT(tp->t_inpcb);
3405
3406 TCPSTAT_INC(tcps_rttupdated);
3407 tp->t_rttupdated++;
3408#ifdef STATS
3409 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_RTT,
3410 imax(0, rtt * 1000 / hz));
3411#endif
3362 if ((tp->t_srtt != 0) && (tp->t_rxtshift <= TCP_RTT_INVALIDATE)) {
3363 /*
3364 * srtt is stored as fixed point with 5 bits after the
3365 * binary point (i.e., scaled by 8). The following magic
3366 * is equivalent to the smoothing algorithm in rfc793 with
3367 * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
3368 * point). Adjust rtt to origin 0.
3369 */

--- 418 unchanged lines hidden ---
3412 if ((tp->t_srtt != 0) && (tp->t_rxtshift <= TCP_RTT_INVALIDATE)) {
3413 /*
3414 * srtt is stored as fixed point with 5 bits after the
3415 * binary point (i.e., scaled by 8). The following magic
3416 * is equivalent to the smoothing algorithm in rfc793 with
3417 * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
3418 * point). Adjust rtt to origin 0.
3419 */

--- 418 unchanged lines hidden ---