1 #ifndef __rack_bbr_common_h__ 2 #define __rack_bbr_common_h__ 3 /*- 4 * Copyright (c) 2016-2020 Netflix, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * __FBSDID("$FreeBSD$"); 28 */ 29 30 /* Common defines and such used by both RACK and BBR */ 31 /* Special values for mss accounting array */ 32 #define TCP_MSS_ACCT_JUSTRET 0 33 #define TCP_MSS_ACCT_SNDACK 1 34 #define TCP_MSS_ACCT_PERSIST 2 35 #define TCP_MSS_ACCT_ATIMER 60 36 #define TCP_MSS_ACCT_INPACE 61 37 #define TCP_MSS_ACCT_LATE 62 38 #define TCP_MSS_SMALL_SIZE_OFF 63 /* Point where small sizes enter */ 39 #define TCP_MSS_ACCT_SIZE 70 40 #define TCP_MSS_SMALL_MAX_SIZE_DIV (TCP_MSS_ACCT_SIZE - TCP_MSS_SMALL_SIZE_OFF) 41 42 #define DUP_ACK_THRESHOLD 3 43 44 /* Magic flags for tracing progress events */ 45 #define PROGRESS_DROP 1 46 #define PROGRESS_UPDATE 2 47 #define PROGRESS_CLEAR 3 48 #define PROGRESS_START 4 49 50 /* codes for just-return */ 51 #define CTF_JR_SENT_DATA 0 52 #define CTF_JR_CWND_LIMITED 1 53 #define CTF_JR_RWND_LIMITED 2 54 #define CTF_JR_APP_LIMITED 3 55 #define CTF_JR_ASSESSING 4 56 #define CTF_JR_PERSISTS 5 57 #define CTF_JR_PRR 6 58 59 /* Compat. */ 60 #define BBR_JR_SENT_DATA CTF_JR_SENT_DATA 61 #define BBR_JR_CWND_LIMITED CTF_JR_CWND_LIMITED 62 #define BBR_JR_RWND_LIMITED CTF_JR_RWND_LIMITED 63 #define BBR_JR_APP_LIMITED CTF_JR_APP_LIMITED 64 #define BBR_JR_ASSESSING CTF_JR_ASSESSING 65 #define BBR_JR_PERSISTS CTF_JR_PERSISTS 66 #define BBR_JR_PRR CTF_JR_PRR 67 68 /* RTT sample methods */ 69 #define USE_RTT_HIGH 0 70 #define USE_RTT_LOW 1 71 #define USE_RTT_AVG 2 72 73 #define PACE_MAX_IP_BYTES 65536 74 #define USECS_IN_SECOND 1000000 75 #define MSEC_IN_SECOND 1000 76 #define MS_IN_USEC 1000 77 #define USEC_TO_MSEC(x) (x / MS_IN_USEC) 78 #define TCP_TS_OVERHEAD 12 /* Overhead of having Timestamps on */ 79 80 /* Bits per second in bytes per second */ 81 #define FORTY_EIGHT_MBPS 6000000 /* 48 megabits in bytes */ 82 #define THIRTY_MBPS 3750000 /* 30 megabits in bytes */ 83 #define TWENTY_THREE_MBPS 2896000 /* 23 megabits in bytes */ 84 #define FIVETWELVE_MBPS 64000000 /* 512 megabits in bytes */ 85 #define ONE_POINT_TWO_MEG 150000 /* 1.2 megabits in bytes */ 86 87 #ifdef _KERNEL 88 /* We have only 7 bits in rack so assert its true */ 89 CTASSERT((PACE_TMR_MASK & 0x80) == 0); 90 #ifdef KERN_TLS 91 uint32_t ctf_get_opt_tls_size(struct socket *so, uint32_t rwnd); 92 #endif 93 int 94 ctf_process_inbound_raw(struct tcpcb *tp, struct socket *so, 95 struct mbuf *m, int has_pkt); 96 int 97 ctf_do_queued_segments(struct socket *so, struct tcpcb *tp, int have_pkt); 98 uint32_t ctf_outstanding(struct tcpcb *tp); 99 uint32_t ctf_flight_size(struct tcpcb *tp, uint32_t rc_sacked); 100 int 101 _ctf_drop_checks(struct tcpopt *to, struct mbuf *m, struct tcphdr *th, 102 struct tcpcb *tp, int32_t *tlenp, 103 int32_t *thf, int32_t *drop_hdrlen, int32_t *ret_val, 104 uint32_t *ts, uint32_t *cnt); 105 void ctf_ack_war_checks(struct tcpcb *tp, uint32_t *ts, uint32_t *cnt); 106 #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 108 void 109 __ctf_do_dropafterack(struct mbuf *m, struct tcpcb *tp, 110 struct tcphdr *th, int32_t thflags, int32_t tlen, 111 int32_t *ret_val, uint32_t *ts, uint32_t *cnt); 112 113 #define ctf_do_dropafterack(a, b, c, d, e, f) __ctf_do_dropafterack(a, b, c, d, e, f, NULL, NULL) 114 115 void 116 ctf_do_dropwithreset(struct mbuf *m, struct tcpcb *tp, 117 struct tcphdr *th, int32_t rstreason, int32_t tlen); 118 void 119 ctf_do_drop(struct mbuf *m, struct tcpcb *tp); 120 121 int 122 __ctf_process_rst(struct mbuf *m, struct tcphdr *th, 123 struct socket *so, struct tcpcb *tp, uint32_t *ts, uint32_t *cnt); 124 #define ctf_process_rst(m, t, s, p) __ctf_process_rst(m, t, s, p, NULL, NULL) 125 126 void 127 ctf_challenge_ack(struct mbuf *m, struct tcphdr *th, 128 struct tcpcb *tp, int32_t * ret_val); 129 130 int 131 ctf_ts_check(struct mbuf *m, struct tcphdr *th, 132 struct tcpcb *tp, int32_t tlen, int32_t thflags, int32_t * ret_val); 133 134 int 135 ctf_ts_check_ac(struct tcpcb *tp, int32_t thflags); 136 137 void 138 ctf_calc_rwin(struct socket *so, struct tcpcb *tp); 139 140 void 141 ctf_do_dropwithreset_conn(struct mbuf *m, struct tcpcb *tp, struct tcphdr *th, 142 int32_t rstreason, int32_t tlen); 143 144 uint32_t 145 ctf_fixed_maxseg(struct tcpcb *tp); 146 147 void 148 ctf_log_sack_filter(struct tcpcb *tp, int num_sack_blks, struct sackblk *sack_blocks); 149 150 uint32_t 151 ctf_decay_count(uint32_t count, uint32_t decay_percentage); 152 153 int32_t 154 ctf_progress_timeout_check(struct tcpcb *tp, bool log); 155 156 #endif 157 #endif 158