1 /* 2 * Copyright (c) 2018, Sam Kumar <samkumar@cs.berkeley.edu> 3 * Copyright (c) 2018, University of California, Berkeley 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holder nor the 14 * names of its contributors may be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* 31 * samkumar: I created this file to store many of the constants shared by the 32 * various files in the FreeBSD protocol logic. The original variables were 33 * often virtualized ("V_"-prefixed) variables. I've changed the definitions to 34 * be enumerations rather than globals, to save some memory. These variables 35 * often serve to enable, disable, or configure certain TCP-related features. 36 */ 37 38 #ifndef TCPLP_TCP_CONST_H_ 39 #define TCPLP_TCP_CONST_H_ 40 41 #include "../tcplp.h" 42 43 #include "tcp_var.h" 44 #include "tcp_timer.h" 45 46 /* 47 * samkumar: these are TCPlp-specific constants that I added. They were not 48 * present in the FreeBSD-derived code. 49 */ 50 51 #define FRAMES_PER_SEG 5 52 #define FRAMECAP_6LOWPAN (122 - 11 - 5) 53 #define IP6HDR_SIZE (2 + 1 + 1 + 16 + 16) // IPHC header (2) + Next header (1) + Hop count (1) + Dest. addr (16) + Src. addr (16) 54 #define MSS_6LOWPAN ((FRAMES_PER_SEG * FRAMECAP_6LOWPAN) - IP6HDR_SIZE - sizeof(struct tcphdr)) 55 56 /* 57 * samkumar: The remaining constants were present in the original FreeBSD code, 58 * but I set their values. 59 */ 60 61 #define hz 1000 // number of ticks per second, assuming millisecond ticks 62 63 enum tcp_input_consts { 64 tcp_keepcnt = TCPTV_KEEPCNT, 65 tcp_fast_finwait2_recycle = 0, 66 tcprexmtthresh = 3, 67 V_drop_synfin = 0, 68 V_tcp_do_ecn = 1, 69 V_tcp_ecn_maxretries = 3, 70 V_tcp_do_rfc3042 = 1, 71 V_path_mtu_discovery = 0, 72 V_tcp_delack_enabled = 1, 73 V_tcp_initcwnd_segments = 0, 74 V_tcp_do_rfc3390 = 0, 75 V_tcp_abc_l_var = 2 // this is what was in the original tcp_input.c 76 }; 77 78 enum tcp_subr_consts { 79 tcp_delacktime = TCPTV_DELACK, 80 tcp_keepinit = TCPTV_KEEP_INIT, 81 tcp_keepidle = TCPTV_KEEP_IDLE, 82 tcp_keepintvl = TCPTV_KEEPINTVL, 83 tcp_maxpersistidle = TCPTV_KEEP_IDLE, 84 tcp_msl = TCPTV_MSL, 85 tcp_rexmit_slop = TCPTV_CPU_VAR, 86 tcp_finwait2_timeout = TCPTV_FINWAIT2_TIMEOUT, 87 88 V_tcp_do_rfc1323 = 1, 89 V_tcp_v6mssdflt = MSS_6LOWPAN, 90 /* Normally, this is used to prevent DoS attacks by sending tiny MSS values in the options. */ 91 V_tcp_minmss = TCP_MAXOLEN + 1, // Must have enough space for TCP options, and one more byte for data. Default is 216. 92 V_tcp_do_sack = 1 93 }; 94 95 enum tcp_timer_consts { 96 // V_tcp_v6pmtud_blackhole_mss = FRAMECAP_6LOWPAN - sizeof(struct ip6_hdr) - sizeof(struct tcphdr), // Doesn't matter unless blackhole_detect is 1. 97 tcp_rexmit_drop_options = 0, // drop options after a few retransmits 98 always_keepalive = 1 99 }; 100 101 enum tcp_fastopen_consts { 102 V_tcp_fastopen_client_enable = 1, 103 V_tcp_fastopen_server_enable = 1, 104 V_tcp_fastopen_acceptany = 1, 105 V_tcp_fastopen_numkeys = 4 106 }; 107 #define TCP_RFC7413 108 109 /* 110 * Force a time value to be in a certain range. 111 */ 112 #define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 113 (tv) = (value) + tcp_rexmit_slop; \ 114 if ((uint64_t)(tv) < (uint64_t)(tvmin)) \ 115 (tv) = (tvmin); \ 116 if ((uint64_t)(tv) > (uint64_t)(tvmax)) \ 117 (tv) = (tvmax); \ 118 } while(0) 119 120 #endif 121