2 * Copyright (c) 2015-2017 Patrick Kelsey
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #ifndef _TCP_FASTOPEN_H_
28 #define _TCP_FASTOPEN_H_
34 #define TCP_FASTOPEN_COOKIE_LEN 8 /* SipHash24 64-bit output */
37 VNET_DECLARE(unsigned int, tcp_fastopen_client_enable
);
38 #define V_tcp_fastopen_client_enable VNET(tcp_fastopen_client_enable)
40 VNET_DECLARE(unsigned int, tcp_fastopen_server_enable
);
41 #define V_tcp_fastopen_server_enable VNET(tcp_fastopen_server_enable)
43 #define V_tcp_fastopen_client_enable 0
44 #define V_tcp_fastopen_server_enable 0
45 #endif /* TCP_RFC7413 */
47 union tcp_fastopen_ip_addr
{
52 struct tcp_fastopen_ccache_entry
{
53 TAILQ_ENTRY(tcp_fastopen_ccache_entry
) cce_link
;
54 union tcp_fastopen_ip_addr cce_client_ip
; /* network byte order */
55 union tcp_fastopen_ip_addr cce_server_ip
; /* network byte order */
56 uint16_t server_port
; /* network byte order */
57 uint16_t server_mss
; /* host byte order */
60 uint8_t cookie
[TCP_FASTOPEN_MAX_COOKIE_LEN
];
61 sbintime_t disable_time
; /* non-zero value means path is disabled */
64 struct tcp_fastopen_ccache
;
66 struct tcp_fastopen_ccache_bucket
{
68 TAILQ_HEAD(bucket_entries
, tcp_fastopen_ccache_entry
) ccb_entries
;
70 struct tcp_fastopen_ccache
*ccb_ccache
;
73 struct tcp_fastopen_ccache
{
75 struct tcp_fastopen_ccache_bucket
*base
;
76 unsigned int bucket_limit
;
84 void tcp_fastopen_init(void);
85 void tcp_fastopen_destroy(void);
86 unsigned int *tcp_fastopen_alloc_counter(void);
87 void tcp_fastopen_decrement_counter(unsigned int *);
88 int tcp_fastopen_check_cookie(struct in_conninfo
*, uint8_t *, unsigned int,
90 void tcp_fastopen_connect(struct tcpcb
*);
91 void tcp_fastopen_disable_path(struct tcpcb
*);
92 void tcp_fastopen_update_cache(struct tcpcb
*, uint16_t, uint8_t,
96 tcp_fastopen_init(void)
101 tcp_fastopen_destroy(void)
105 static __inline
unsigned int *
106 tcp_fastopen_alloc_counter(void)
112 tcp_fastopen_decrement_counter(unsigned int *_counter
)
117 tcp_fastopen_check_cookie(struct in_conninfo
*_inc
, uint8_t *_cookie
,
118 unsigned int _len
, uint64_t *_latest_cookie
)
124 tcp_fastopen_connect(struct tcpcb
*_tp
)
129 tcp_fastopen_disable_path(struct tcpcb
*_tp
)
134 tcp_fastopen_update_cache(struct tcpcb
*_tp
, uint16_t _mss
, uint8_t _cookie_len
,
138 #endif /* TCP_RFC7413 */
142 #endif /* _TCP_FASTOPEN_H_ */