xref: /freebsd/sys/netinet/tcp_stacks/rack_bbr_common.h (revision 5d8fd932e418f03e98b3469c4088a36f0ef34ffe)
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  *
2789e560f4SRandall Stewart  * __FBSDID("$FreeBSD$");
2889e560f4SRandall Stewart  */
291cf55767SRandall Stewart 
3089e560f4SRandall Stewart /* Common defines and such used by both RACK and BBR */
3189e560f4SRandall Stewart /* Special values for mss accounting array */
3289e560f4SRandall Stewart #define TCP_MSS_ACCT_JUSTRET 0
3389e560f4SRandall Stewart #define TCP_MSS_ACCT_SNDACK  1
3489e560f4SRandall Stewart #define TCP_MSS_ACCT_PERSIST 2
3589e560f4SRandall Stewart #define TCP_MSS_ACCT_ATIMER  60
3689e560f4SRandall Stewart #define TCP_MSS_ACCT_INPACE  61
3789e560f4SRandall Stewart #define TCP_MSS_ACCT_LATE    62
3889e560f4SRandall Stewart #define TCP_MSS_SMALL_SIZE_OFF 63	/* Point where small sizes enter */
3989e560f4SRandall Stewart #define TCP_MSS_ACCT_SIZE    70
4089e560f4SRandall Stewart #define TCP_MSS_SMALL_MAX_SIZE_DIV (TCP_MSS_ACCT_SIZE - TCP_MSS_SMALL_SIZE_OFF)
4189e560f4SRandall Stewart 
423b0b41e6SRandall Stewart #define DUP_ACK_THRESHOLD 3
4389e560f4SRandall Stewart 
4489e560f4SRandall Stewart /* Magic flags for tracing progress events */
4589e560f4SRandall Stewart #define PROGRESS_DROP   1
4689e560f4SRandall Stewart #define PROGRESS_UPDATE 2
4789e560f4SRandall Stewart #define PROGRESS_CLEAR  3
4889e560f4SRandall Stewart #define PROGRESS_START  4
4989e560f4SRandall Stewart 
501cf55767SRandall Stewart /* codes for just-return */
511cf55767SRandall Stewart #define CTF_JR_SENT_DATA    0
521cf55767SRandall Stewart #define CTF_JR_CWND_LIMITED 1
531cf55767SRandall Stewart #define CTF_JR_RWND_LIMITED 2
541cf55767SRandall Stewart #define CTF_JR_APP_LIMITED  3
551cf55767SRandall Stewart #define CTF_JR_ASSESSING    4
561cf55767SRandall Stewart #define CTF_JR_PERSISTS     5
571cf55767SRandall Stewart #define CTF_JR_PRR	    6
581cf55767SRandall Stewart 
591cf55767SRandall Stewart /* Compat. */
601cf55767SRandall Stewart #define BBR_JR_SENT_DATA CTF_JR_SENT_DATA
611cf55767SRandall Stewart #define BBR_JR_CWND_LIMITED CTF_JR_CWND_LIMITED
621cf55767SRandall Stewart #define BBR_JR_RWND_LIMITED CTF_JR_RWND_LIMITED
631cf55767SRandall Stewart #define BBR_JR_APP_LIMITED CTF_JR_APP_LIMITED
641cf55767SRandall Stewart #define BBR_JR_ASSESSING CTF_JR_ASSESSING
651cf55767SRandall Stewart #define BBR_JR_PERSISTS CTF_JR_PERSISTS
661cf55767SRandall Stewart #define BBR_JR_PRR CTF_JR_PRR
6789e560f4SRandall Stewart 
6889e560f4SRandall Stewart /* RTT sample methods */
6989e560f4SRandall Stewart #define USE_RTT_HIGH 0
7089e560f4SRandall Stewart #define USE_RTT_LOW  1
7189e560f4SRandall Stewart #define USE_RTT_AVG  2
7289e560f4SRandall Stewart 
733b0b41e6SRandall Stewart #define PACE_MAX_IP_BYTES 65536
743b0b41e6SRandall Stewart #define USECS_IN_SECOND 1000000
753b0b41e6SRandall Stewart #define MSEC_IN_SECOND 1000
763b0b41e6SRandall Stewart #define MS_IN_USEC 1000
773b0b41e6SRandall Stewart #define USEC_TO_MSEC(x) (x / MS_IN_USEC)
783b0b41e6SRandall Stewart #define TCP_TS_OVERHEAD 12		/* Overhead of having Timestamps on */
793b0b41e6SRandall Stewart 
801cf55767SRandall Stewart /* Bits per second in bytes per second */
811cf55767SRandall Stewart #define FORTY_EIGHT_MBPS 6000000 /* 48 megabits in bytes */
821cf55767SRandall Stewart #define THIRTY_MBPS 3750000 /* 30 megabits in bytes */
83963fb2adSRandall Stewart #define TWENTY_THREE_MBPS 2896000 /* 23 megabits in bytes */
841cf55767SRandall Stewart #define FIVETWELVE_MBPS 64000000 /* 512 megabits in bytes */
851cf55767SRandall Stewart #define ONE_POINT_TWO_MEG 150000 /* 1.2 megabits in bytes */
861cf55767SRandall Stewart 
8789e560f4SRandall Stewart #ifdef _KERNEL
8889e560f4SRandall Stewart /* We have only 7 bits in rack so assert its true */
8989e560f4SRandall Stewart CTASSERT((PACE_TMR_MASK & 0x80) == 0);
903b0b41e6SRandall Stewart #ifdef KERN_TLS
913b0b41e6SRandall Stewart uint32_t ctf_get_opt_tls_size(struct socket *so, uint32_t rwnd);
923b0b41e6SRandall Stewart #endif
933b0b41e6SRandall Stewart int
943b0b41e6SRandall Stewart ctf_process_inbound_raw(struct tcpcb *tp, struct socket *so,
953b0b41e6SRandall Stewart     struct mbuf *m, int has_pkt);
963b0b41e6SRandall Stewart int
973b0b41e6SRandall Stewart ctf_do_queued_segments(struct socket *so, struct tcpcb *tp, int have_pkt);
983b0b41e6SRandall Stewart uint32_t ctf_outstanding(struct tcpcb *tp);
993b0b41e6SRandall Stewart uint32_t ctf_flight_size(struct tcpcb *tp, uint32_t rc_sacked);
1003b0b41e6SRandall Stewart int
101*5d8fd932SRandall Stewart _ctf_drop_checks(struct tcpopt *to, struct mbuf *m, struct tcphdr *th,
102*5d8fd932SRandall Stewart     struct tcpcb *tp, int32_t *tlenp,
103*5d8fd932SRandall Stewart     int32_t *thf, int32_t *drop_hdrlen, int32_t *ret_val,
104*5d8fd932SRandall Stewart     uint32_t *ts, uint32_t *cnt);
105*5d8fd932SRandall Stewart void ctf_ack_war_checks(struct tcpcb *tp, uint32_t *ts, uint32_t *cnt);
106*5d8fd932SRandall Stewart #define ctf_drop_checks(a, b, c, d, e, f, g, h) _ctf_drop_checks(a, b, c, d, e, f, g, h, NULL, NULL)
107*5d8fd932SRandall Stewart 
1083b0b41e6SRandall Stewart void
109*5d8fd932SRandall Stewart __ctf_do_dropafterack(struct mbuf *m, struct tcpcb *tp,
110*5d8fd932SRandall Stewart       struct tcphdr *th, int32_t thflags, int32_t tlen,
111*5d8fd932SRandall Stewart       int32_t *ret_val, uint32_t *ts, uint32_t *cnt);
112*5d8fd932SRandall Stewart 
113*5d8fd932SRandall Stewart #define ctf_do_dropafterack(a, b, c, d, e, f) __ctf_do_dropafterack(a, b, c, d, e, f, NULL, NULL)
114*5d8fd932SRandall Stewart 
1153b0b41e6SRandall Stewart void
1163b0b41e6SRandall Stewart ctf_do_dropwithreset(struct mbuf *m, struct tcpcb *tp,
1173b0b41e6SRandall Stewart 	struct tcphdr *th, int32_t rstreason, int32_t tlen);
1183b0b41e6SRandall Stewart void
1193b0b41e6SRandall Stewart ctf_do_drop(struct mbuf *m, struct tcpcb *tp);
1203b0b41e6SRandall Stewart 
1213b0b41e6SRandall Stewart int
1223b0b41e6SRandall Stewart ctf_process_rst(struct mbuf *m, struct tcphdr *th,
1233b0b41e6SRandall Stewart     struct socket *so, struct tcpcb *tp);
1243b0b41e6SRandall Stewart 
1253b0b41e6SRandall Stewart void
1263b0b41e6SRandall Stewart ctf_challenge_ack(struct mbuf *m, struct tcphdr *th,
1273b0b41e6SRandall Stewart     struct tcpcb *tp, int32_t * ret_val);
1283b0b41e6SRandall Stewart 
1293b0b41e6SRandall Stewart int
1303b0b41e6SRandall Stewart ctf_ts_check(struct mbuf *m, struct tcphdr *th,
1313b0b41e6SRandall Stewart     struct tcpcb *tp, int32_t tlen, int32_t thflags, int32_t * ret_val);
1323b0b41e6SRandall Stewart 
133*5d8fd932SRandall Stewart int
134*5d8fd932SRandall Stewart ctf_ts_check_ac(struct tcpcb *tp, int32_t thflags);
135*5d8fd932SRandall Stewart 
1363b0b41e6SRandall Stewart void
1373b0b41e6SRandall Stewart ctf_calc_rwin(struct socket *so, struct tcpcb *tp);
1383b0b41e6SRandall Stewart 
1393b0b41e6SRandall Stewart void
1403b0b41e6SRandall Stewart ctf_do_dropwithreset_conn(struct mbuf *m, struct tcpcb *tp, struct tcphdr *th,
1413b0b41e6SRandall Stewart     int32_t rstreason, int32_t tlen);
1423b0b41e6SRandall Stewart 
1433b0b41e6SRandall Stewart uint32_t
1443b0b41e6SRandall Stewart ctf_fixed_maxseg(struct tcpcb *tp);
1453b0b41e6SRandall Stewart 
1463b0b41e6SRandall Stewart void
1473b0b41e6SRandall Stewart ctf_log_sack_filter(struct tcpcb *tp, int num_sack_blks, struct sackblk *sack_blocks);
1483b0b41e6SRandall Stewart 
1493b0b41e6SRandall Stewart uint32_t
1503b0b41e6SRandall Stewart ctf_decay_count(uint32_t count, uint32_t decay_percentage);
1513b0b41e6SRandall Stewart 
152963fb2adSRandall Stewart int32_t
153963fb2adSRandall Stewart ctf_progress_timeout_check(struct tcpcb *tp, bool log);
154963fb2adSRandall Stewart 
15589e560f4SRandall Stewart #endif
15689e560f4SRandall Stewart #endif
157