xref: /freebsd/sys/netinet/tcp_stacks/rack_bbr_common.h (revision c349e881cf52e51ab063c098bd9b99db487b6377)
11cf55767SRandall Stewart #ifndef __rack_bbr_common_h__
21cf55767SRandall Stewart #define __rack_bbr_common_h__
389e560f4SRandall Stewart /*-
4963fb2adSRandall Stewart  * Copyright (c) 2016-2020 Netflix, Inc.
589e560f4SRandall Stewart  *
689e560f4SRandall Stewart  * Redistribution and use in source and binary forms, with or without
789e560f4SRandall Stewart  * modification, are permitted provided that the following conditions
889e560f4SRandall Stewart  * are met:
989e560f4SRandall Stewart  * 1. Redistributions of source code must retain the above copyright
1089e560f4SRandall Stewart  *    notice, this list of conditions and the following disclaimer.
1189e560f4SRandall Stewart  * 2. Redistributions in binary form must reproduce the above copyright
1289e560f4SRandall Stewart  *    notice, this list of conditions and the following disclaimer in the
1389e560f4SRandall Stewart  *    documentation and/or other materials provided with the distribution.
1489e560f4SRandall Stewart  *
1589e560f4SRandall Stewart  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1689e560f4SRandall Stewart  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1789e560f4SRandall Stewart  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1889e560f4SRandall Stewart  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1989e560f4SRandall Stewart  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2089e560f4SRandall Stewart  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2189e560f4SRandall Stewart  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2289e560f4SRandall Stewart  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2389e560f4SRandall Stewart  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2489e560f4SRandall Stewart  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2589e560f4SRandall Stewart  * SUCH DAMAGE.
2689e560f4SRandall Stewart  */
271cf55767SRandall Stewart 
2889e560f4SRandall Stewart /* Common defines and such used by both RACK and BBR */
2989e560f4SRandall Stewart /* Special values for mss accounting array */
3089e560f4SRandall Stewart #define TCP_MSS_ACCT_JUSTRET 0
3189e560f4SRandall Stewart #define TCP_MSS_ACCT_SNDACK  1
3289e560f4SRandall Stewart #define TCP_MSS_ACCT_PERSIST 2
3389e560f4SRandall Stewart #define TCP_MSS_ACCT_ATIMER  60
3489e560f4SRandall Stewart #define TCP_MSS_ACCT_INPACE  61
3589e560f4SRandall Stewart #define TCP_MSS_ACCT_LATE    62
3689e560f4SRandall Stewart #define TCP_MSS_SMALL_SIZE_OFF 63	/* Point where small sizes enter */
3789e560f4SRandall Stewart #define TCP_MSS_ACCT_SIZE    70
3889e560f4SRandall Stewart #define TCP_MSS_SMALL_MAX_SIZE_DIV (TCP_MSS_ACCT_SIZE - TCP_MSS_SMALL_SIZE_OFF)
3989e560f4SRandall Stewart 
403b0b41e6SRandall Stewart #define DUP_ACK_THRESHOLD 3
4189e560f4SRandall Stewart 
4289e560f4SRandall Stewart /* Magic flags for tracing progress events */
4389e560f4SRandall Stewart #define PROGRESS_DROP   1
4489e560f4SRandall Stewart #define PROGRESS_UPDATE 2
4589e560f4SRandall Stewart #define PROGRESS_CLEAR  3
4689e560f4SRandall Stewart #define PROGRESS_START  4
4789e560f4SRandall Stewart 
481cf55767SRandall Stewart /* codes for just-return */
491cf55767SRandall Stewart #define CTF_JR_SENT_DATA    0
501cf55767SRandall Stewart #define CTF_JR_CWND_LIMITED 1
511cf55767SRandall Stewart #define CTF_JR_RWND_LIMITED 2
521cf55767SRandall Stewart #define CTF_JR_APP_LIMITED  3
531cf55767SRandall Stewart #define CTF_JR_ASSESSING    4
541cf55767SRandall Stewart #define CTF_JR_PERSISTS     5
551cf55767SRandall Stewart #define CTF_JR_PRR	    6
561cf55767SRandall Stewart 
571cf55767SRandall Stewart /* Compat. */
581cf55767SRandall Stewart #define BBR_JR_SENT_DATA CTF_JR_SENT_DATA
591cf55767SRandall Stewart #define BBR_JR_CWND_LIMITED CTF_JR_CWND_LIMITED
601cf55767SRandall Stewart #define BBR_JR_RWND_LIMITED CTF_JR_RWND_LIMITED
611cf55767SRandall Stewart #define BBR_JR_APP_LIMITED CTF_JR_APP_LIMITED
621cf55767SRandall Stewart #define BBR_JR_ASSESSING CTF_JR_ASSESSING
631cf55767SRandall Stewart #define BBR_JR_PERSISTS CTF_JR_PERSISTS
641cf55767SRandall Stewart #define BBR_JR_PRR CTF_JR_PRR
6589e560f4SRandall Stewart 
6689e560f4SRandall Stewart /* RTT sample methods */
6789e560f4SRandall Stewart #define USE_RTT_HIGH 0
6889e560f4SRandall Stewart #define USE_RTT_LOW  1
6989e560f4SRandall Stewart #define USE_RTT_AVG  2
7089e560f4SRandall Stewart 
713b0b41e6SRandall Stewart #define PACE_MAX_IP_BYTES 65536
723b0b41e6SRandall Stewart #define USECS_IN_SECOND 1000000
733b0b41e6SRandall Stewart #define MSEC_IN_SECOND 1000
743b0b41e6SRandall Stewart #define MS_IN_USEC 1000
753b0b41e6SRandall Stewart #define USEC_TO_MSEC(x) (x / MS_IN_USEC)
763b0b41e6SRandall Stewart #define TCP_TS_OVERHEAD 12		/* Overhead of having Timestamps on */
773b0b41e6SRandall Stewart 
781cf55767SRandall Stewart /* Bits per second in bytes per second */
791cf55767SRandall Stewart #define FORTY_EIGHT_MBPS 6000000 /* 48 megabits in bytes */
801cf55767SRandall Stewart #define THIRTY_MBPS 3750000 /* 30 megabits in bytes */
81963fb2adSRandall Stewart #define TWENTY_THREE_MBPS 2896000 /* 23 megabits in bytes */
821cf55767SRandall Stewart #define FIVETWELVE_MBPS 64000000 /* 512 megabits in bytes */
831cf55767SRandall Stewart #define ONE_POINT_TWO_MEG 150000 /* 1.2 megabits in bytes */
841cf55767SRandall Stewart 
8589e560f4SRandall Stewart #ifdef _KERNEL
8689e560f4SRandall Stewart /* We have only 7 bits in rack so assert its true */
8789e560f4SRandall Stewart CTASSERT((PACE_TMR_MASK & 0x80) == 0);
8835bc0bccSGleb Smirnoff int ctf_do_queued_segments(struct tcpcb *tp, int have_pkt);
893b0b41e6SRandall Stewart uint32_t ctf_outstanding(struct tcpcb *tp);
903b0b41e6SRandall Stewart uint32_t ctf_flight_size(struct tcpcb *tp, uint32_t rc_sacked);
913b0b41e6SRandall Stewart int
92*c349e881SMichael Tuexen ctf_drop_checks(struct tcpopt *to, struct mbuf *m, struct tcphdr *th,
935d8fd932SRandall Stewart     struct tcpcb *tp, int32_t *tlenp,
94*c349e881SMichael Tuexen     int32_t *thf, int32_t *drop_hdrlen, int32_t *ret_val);
95*c349e881SMichael Tuexen void ctf_ack_war_checks(struct tcpcb *tp);
965d8fd932SRandall Stewart 
973b0b41e6SRandall Stewart void
98*c349e881SMichael Tuexen ctf_do_dropafterack(struct mbuf *m, struct tcpcb *tp,
995d8fd932SRandall Stewart       struct tcphdr *th, int32_t thflags, int32_t tlen,
100*c349e881SMichael Tuexen       int32_t *ret_val);
1015d8fd932SRandall Stewart 
1023b0b41e6SRandall Stewart void
1033b0b41e6SRandall Stewart ctf_do_dropwithreset(struct mbuf *m, struct tcpcb *tp,
1043b0b41e6SRandall Stewart 	struct tcphdr *th, int32_t rstreason, int32_t tlen);
1053b0b41e6SRandall Stewart void
1063b0b41e6SRandall Stewart ctf_do_drop(struct mbuf *m, struct tcpcb *tp);
1073b0b41e6SRandall Stewart 
1083b0b41e6SRandall Stewart int
109*c349e881SMichael Tuexen ctf_process_rst(struct mbuf *m, struct tcphdr *th,
110*c349e881SMichael Tuexen       struct socket *so, struct tcpcb *tp);
1113b0b41e6SRandall Stewart 
1123b0b41e6SRandall Stewart void
1133b0b41e6SRandall Stewart ctf_challenge_ack(struct mbuf *m, struct tcphdr *th,
11483c1ec92SRichard Scheffenegger     struct tcpcb *tp, uint8_t iptos, int32_t * ret_val);
1153b0b41e6SRandall Stewart 
1163b0b41e6SRandall Stewart int
1173b0b41e6SRandall Stewart ctf_ts_check(struct mbuf *m, struct tcphdr *th,
1183b0b41e6SRandall Stewart     struct tcpcb *tp, int32_t tlen, int32_t thflags, int32_t * ret_val);
1193b0b41e6SRandall Stewart 
1205d8fd932SRandall Stewart int
1215d8fd932SRandall Stewart ctf_ts_check_ac(struct tcpcb *tp, int32_t thflags);
1225d8fd932SRandall Stewart 
1233b0b41e6SRandall Stewart void
1243b0b41e6SRandall Stewart ctf_calc_rwin(struct socket *so, struct tcpcb *tp);
1253b0b41e6SRandall Stewart 
1263b0b41e6SRandall Stewart void
1273b0b41e6SRandall Stewart ctf_do_dropwithreset_conn(struct mbuf *m, struct tcpcb *tp, struct tcphdr *th,
1283b0b41e6SRandall Stewart     int32_t rstreason, int32_t tlen);
1293b0b41e6SRandall Stewart 
1303b0b41e6SRandall Stewart uint32_t
1313b0b41e6SRandall Stewart ctf_fixed_maxseg(struct tcpcb *tp);
1323b0b41e6SRandall Stewart 
1333b0b41e6SRandall Stewart void
1343b0b41e6SRandall Stewart ctf_log_sack_filter(struct tcpcb *tp, int num_sack_blks, struct sackblk *sack_blocks);
1353b0b41e6SRandall Stewart 
1363b0b41e6SRandall Stewart uint32_t
1373b0b41e6SRandall Stewart ctf_decay_count(uint32_t count, uint32_t decay_percentage);
1383b0b41e6SRandall Stewart 
139963fb2adSRandall Stewart int32_t
140963fb2adSRandall Stewart ctf_progress_timeout_check(struct tcpcb *tp, bool log);
141963fb2adSRandall Stewart 
14289e560f4SRandall Stewart #endif
14389e560f4SRandall Stewart #endif
144