1 /*- 2 * Copyright (c) 2015-2017 Patrick Kelsey 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * 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 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef TCPLP_TCP_FASTOPEN_H_ 30 #define TCPLP_TCP_FASTOPEN_H_ 31 32 // #include "opt_inet.h" 33 #include "tcp_const.h" 34 #include "tcp_var.h" 35 36 #define TCP_FASTOPEN_COOKIE_LEN 8 /* SipHash24 64-bit output */ 37 38 #if 0 39 40 #ifdef TCP_RFC7413 41 VNET_DECLARE(unsigned int, tcp_fastopen_client_enable); 42 #define V_tcp_fastopen_client_enable VNET(tcp_fastopen_client_enable) 43 44 VNET_DECLARE(unsigned int, tcp_fastopen_server_enable); 45 #define V_tcp_fastopen_server_enable VNET(tcp_fastopen_server_enable) 46 #else 47 #define V_tcp_fastopen_client_enable 0 48 #define V_tcp_fastopen_server_enable 0 49 #endif /* TCP_RFC7413 */ 50 51 union tcp_fastopen_ip_addr { 52 struct in_addr v4; 53 struct in6_addr v6; 54 }; 55 56 struct tcp_fastopen_ccache_entry { 57 TAILQ_ENTRY(tcp_fastopen_ccache_entry) cce_link; 58 union tcp_fastopen_ip_addr cce_client_ip; /* network byte order */ 59 union tcp_fastopen_ip_addr cce_server_ip; /* network byte order */ 60 uint16_t server_port; /* network byte order */ 61 uint16_t server_mss; /* host byte order */ 62 uint8_t af; 63 uint8_t cookie_len; 64 uint8_t cookie[TCP_FASTOPEN_MAX_COOKIE_LEN]; 65 sbintime_t disable_time; /* non-zero value means path is disabled */ 66 }; 67 68 struct tcp_fastopen_ccache; 69 70 struct tcp_fastopen_ccache_bucket { 71 struct mtx ccb_mtx; 72 TAILQ_HEAD(bucket_entries, tcp_fastopen_ccache_entry) ccb_entries; 73 int ccb_num_entries; 74 struct tcp_fastopen_ccache *ccb_ccache; 75 }; 76 77 struct tcp_fastopen_ccache { 78 uma_zone_t zone; 79 struct tcp_fastopen_ccache_bucket *base; 80 unsigned int bucket_limit; 81 unsigned int buckets; 82 unsigned int mask; 83 uint32_t secret; 84 }; 85 86 #endif 87 88 #ifdef TCP_RFC7413 89 void tcp_fastopen_init(void); 90 void tcp_fastopen_destroy(void); 91 unsigned int *tcp_fastopen_alloc_counter(void); 92 void tcp_fastopen_decrement_counter(unsigned int *); 93 /* samkumar: changed type of first argument from "struct in_conninfo *"" to "struct tcpcb*"". */ 94 int tcp_fastopen_check_cookie(struct tcpcb*, uint8_t *, unsigned int, 95 uint64_t *); 96 void tcp_fastopen_connect(struct tcpcb *); 97 void tcp_fastopen_disable_path(struct tcpcb *); 98 void tcp_fastopen_update_cache(struct tcpcb *, uint16_t, uint8_t, 99 uint8_t *); 100 #else 101 #define tcp_fastopen_init() ((void)0) 102 #define tcp_fastopen_destroy() ((void)0) 103 #define tcp_fastopen_alloc_counter() NULL 104 #define tcp_fastopen_decrement_counter(c) ((void)0) 105 #define tcp_fastopen_check_cookie(i, c, l, lc) (-1) 106 #define tcp_fastopen_connect(t) ((void)0) 107 #define tcp_fastopen_disable_path(t) ((void)0) 108 #define tcp_fastopen_update_cache(t, m, l, c) ((void)0) 109 #endif /* TCP_RFC7413 */ 110 111 #endif /* _TCP_FASTOPEN_H_ */ 112