xref: /freebsd/sys/netinet/tcp_stacks/rack_bbr_common.h (revision 1cf55767b800492f15d2d49884f78f05506049c0)
1*1cf55767SRandall Stewart #ifndef __rack_bbr_common_h__
2*1cf55767SRandall Stewart #define __rack_bbr_common_h__
389e560f4SRandall Stewart /*-
435c7bb34SRandall Stewart  * Copyright (c) 2017-9 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  */
29*1cf55767SRandall Stewart 
30*1cf55767SRandall Stewart /* XXXLAS: Couple STATS to NETFLIX_STATS until stats(3) is fully upstreamed. */
31*1cf55767SRandall Stewart #ifndef	NETFLIX_STATS
32*1cf55767SRandall Stewart #undef	STATS
33*1cf55767SRandall Stewart #endif
34*1cf55767SRandall Stewart 
3589e560f4SRandall Stewart /* Common defines and such used by both RACK and BBR */
3689e560f4SRandall Stewart /* Special values for mss accounting array */
3789e560f4SRandall Stewart #define TCP_MSS_ACCT_JUSTRET 0
3889e560f4SRandall Stewart #define TCP_MSS_ACCT_SNDACK  1
3989e560f4SRandall Stewart #define TCP_MSS_ACCT_PERSIST 2
4089e560f4SRandall Stewart #define TCP_MSS_ACCT_ATIMER  60
4189e560f4SRandall Stewart #define TCP_MSS_ACCT_INPACE  61
4289e560f4SRandall Stewart #define TCP_MSS_ACCT_LATE    62
4389e560f4SRandall Stewart #define TCP_MSS_SMALL_SIZE_OFF 63	/* Point where small sizes enter */
4489e560f4SRandall Stewart #define TCP_MSS_ACCT_SIZE    70
4589e560f4SRandall Stewart #define TCP_MSS_SMALL_MAX_SIZE_DIV (TCP_MSS_ACCT_SIZE - TCP_MSS_SMALL_SIZE_OFF)
4689e560f4SRandall Stewart 
473b0b41e6SRandall Stewart #define DUP_ACK_THRESHOLD 3
4889e560f4SRandall Stewart 
4989e560f4SRandall Stewart /* Magic flags for tracing progress events */
5089e560f4SRandall Stewart #define PROGRESS_DROP   1
5189e560f4SRandall Stewart #define PROGRESS_UPDATE 2
5289e560f4SRandall Stewart #define PROGRESS_CLEAR  3
5389e560f4SRandall Stewart #define PROGRESS_START  4
5489e560f4SRandall Stewart 
55*1cf55767SRandall Stewart /* codes for just-return */
56*1cf55767SRandall Stewart #define CTF_JR_SENT_DATA    0
57*1cf55767SRandall Stewart #define CTF_JR_CWND_LIMITED 1
58*1cf55767SRandall Stewart #define CTF_JR_RWND_LIMITED 2
59*1cf55767SRandall Stewart #define CTF_JR_APP_LIMITED  3
60*1cf55767SRandall Stewart #define CTF_JR_ASSESSING    4
61*1cf55767SRandall Stewart #define CTF_JR_PERSISTS     5
62*1cf55767SRandall Stewart #define CTF_JR_PRR	    6
63*1cf55767SRandall Stewart 
64*1cf55767SRandall Stewart /* Compat. */
65*1cf55767SRandall Stewart #define BBR_JR_SENT_DATA CTF_JR_SENT_DATA
66*1cf55767SRandall Stewart #define BBR_JR_CWND_LIMITED CTF_JR_CWND_LIMITED
67*1cf55767SRandall Stewart #define BBR_JR_RWND_LIMITED CTF_JR_RWND_LIMITED
68*1cf55767SRandall Stewart #define BBR_JR_APP_LIMITED CTF_JR_APP_LIMITED
69*1cf55767SRandall Stewart #define BBR_JR_ASSESSING CTF_JR_ASSESSING
70*1cf55767SRandall Stewart #define BBR_JR_PERSISTS CTF_JR_PERSISTS
71*1cf55767SRandall Stewart #define BBR_JR_PRR CTF_JR_PRR
7289e560f4SRandall Stewart 
7389e560f4SRandall Stewart /* RTT sample methods */
7489e560f4SRandall Stewart #define USE_RTT_HIGH 0
7589e560f4SRandall Stewart #define USE_RTT_LOW  1
7689e560f4SRandall Stewart #define USE_RTT_AVG  2
7789e560f4SRandall Stewart 
783b0b41e6SRandall Stewart #define PACE_MAX_IP_BYTES 65536
793b0b41e6SRandall Stewart #define USECS_IN_SECOND 1000000
803b0b41e6SRandall Stewart #define MSEC_IN_SECOND 1000
813b0b41e6SRandall Stewart #define MS_IN_USEC 1000
823b0b41e6SRandall Stewart #define USEC_TO_MSEC(x) (x / MS_IN_USEC)
833b0b41e6SRandall Stewart #define TCP_TS_OVERHEAD 12		/* Overhead of having Timestamps on */
843b0b41e6SRandall Stewart 
85*1cf55767SRandall Stewart /* Bits per second in bytes per second */
86*1cf55767SRandall Stewart #define FORTY_EIGHT_MBPS 6000000 /* 48 megabits in bytes */
87*1cf55767SRandall Stewart #define THIRTY_MBPS 3750000 /* 30 megabits in bytes */
88*1cf55767SRandall Stewart #define TWENTY_THREE_MBPS 2896000
89*1cf55767SRandall Stewart #define FIVETWELVE_MBPS 64000000 /* 512 megabits in bytes */
90*1cf55767SRandall Stewart #define ONE_POINT_TWO_MEG 150000 /* 1.2 megabits in bytes */
91*1cf55767SRandall Stewart 
9289e560f4SRandall Stewart #ifdef _KERNEL
9389e560f4SRandall Stewart /* We have only 7 bits in rack so assert its true */
9489e560f4SRandall Stewart CTASSERT((PACE_TMR_MASK & 0x80) == 0);
953b0b41e6SRandall Stewart #ifdef KERN_TLS
963b0b41e6SRandall Stewart uint32_t ctf_get_opt_tls_size(struct socket *so, uint32_t rwnd);
973b0b41e6SRandall Stewart #endif
983b0b41e6SRandall Stewart int
993b0b41e6SRandall Stewart ctf_process_inbound_raw(struct tcpcb *tp, struct socket *so,
1003b0b41e6SRandall Stewart     struct mbuf *m, int has_pkt);
1013b0b41e6SRandall Stewart int
1023b0b41e6SRandall Stewart ctf_do_queued_segments(struct socket *so, struct tcpcb *tp, int have_pkt);
1033b0b41e6SRandall Stewart uint32_t ctf_outstanding(struct tcpcb *tp);
1043b0b41e6SRandall Stewart uint32_t ctf_flight_size(struct tcpcb *tp, uint32_t rc_sacked);
1053b0b41e6SRandall Stewart int
1063b0b41e6SRandall Stewart ctf_drop_checks(struct tcpopt *to, struct mbuf *m,
1073b0b41e6SRandall Stewart     struct tcphdr *th, struct tcpcb *tp, int32_t * tlenp, int32_t * thf,
1083b0b41e6SRandall Stewart     int32_t * drop_hdrlen, int32_t * ret_val);
1093b0b41e6SRandall Stewart void
1103b0b41e6SRandall Stewart ctf_do_dropafterack(struct mbuf *m, struct tcpcb *tp,
1113b0b41e6SRandall Stewart     struct tcphdr *th, int32_t thflags, int32_t tlen, int32_t * ret_val);
1123b0b41e6SRandall Stewart void
1133b0b41e6SRandall Stewart ctf_do_dropwithreset(struct mbuf *m, struct tcpcb *tp,
1143b0b41e6SRandall Stewart 	struct tcphdr *th, int32_t rstreason, int32_t tlen);
1153b0b41e6SRandall Stewart void
1163b0b41e6SRandall Stewart ctf_do_drop(struct mbuf *m, struct tcpcb *tp);
1173b0b41e6SRandall Stewart 
1183b0b41e6SRandall Stewart int
1193b0b41e6SRandall Stewart ctf_process_rst(struct mbuf *m, struct tcphdr *th,
1203b0b41e6SRandall Stewart     struct socket *so, struct tcpcb *tp);
1213b0b41e6SRandall Stewart 
1223b0b41e6SRandall Stewart void
1233b0b41e6SRandall Stewart ctf_challenge_ack(struct mbuf *m, struct tcphdr *th,
1243b0b41e6SRandall Stewart     struct tcpcb *tp, int32_t * ret_val);
1253b0b41e6SRandall Stewart 
1263b0b41e6SRandall Stewart int
1273b0b41e6SRandall Stewart ctf_ts_check(struct mbuf *m, struct tcphdr *th,
1283b0b41e6SRandall Stewart     struct tcpcb *tp, int32_t tlen, int32_t thflags, int32_t * ret_val);
1293b0b41e6SRandall Stewart 
1303b0b41e6SRandall Stewart void
1313b0b41e6SRandall Stewart ctf_calc_rwin(struct socket *so, struct tcpcb *tp);
1323b0b41e6SRandall Stewart 
1333b0b41e6SRandall Stewart void
1343b0b41e6SRandall Stewart ctf_do_dropwithreset_conn(struct mbuf *m, struct tcpcb *tp, struct tcphdr *th,
1353b0b41e6SRandall Stewart     int32_t rstreason, int32_t tlen);
1363b0b41e6SRandall Stewart 
1373b0b41e6SRandall Stewart uint32_t
1383b0b41e6SRandall Stewart ctf_fixed_maxseg(struct tcpcb *tp);
1393b0b41e6SRandall Stewart 
1403b0b41e6SRandall Stewart void
1413b0b41e6SRandall Stewart ctf_log_sack_filter(struct tcpcb *tp, int num_sack_blks, struct sackblk *sack_blocks);
1423b0b41e6SRandall Stewart 
1433b0b41e6SRandall Stewart uint32_t
1443b0b41e6SRandall Stewart ctf_decay_count(uint32_t count, uint32_t decay_percentage);
1453b0b41e6SRandall Stewart 
14689e560f4SRandall Stewart #endif
14789e560f4SRandall Stewart #endif
148