1281a0fd4SPatrick Kelsey /*-
2c560df6fSPatrick Kelsey * Copyright (c) 2015-2017 Patrick Kelsey
3281a0fd4SPatrick Kelsey * All rights reserved.
4281a0fd4SPatrick Kelsey *
5281a0fd4SPatrick Kelsey * Redistribution and use in source and binary forms, with or without
6281a0fd4SPatrick Kelsey * modification, are permitted provided that the following conditions
7281a0fd4SPatrick Kelsey * are met:
8281a0fd4SPatrick Kelsey * 1. Redistributions of source code must retain the above copyright
9281a0fd4SPatrick Kelsey * notice, this list of conditions and the following disclaimer.
10281a0fd4SPatrick Kelsey * 2. Redistributions in binary form must reproduce the above copyright
11281a0fd4SPatrick Kelsey * notice, this list of conditions and the following disclaimer in the
12281a0fd4SPatrick Kelsey * documentation and/or other materials provided with the distribution.
13281a0fd4SPatrick Kelsey *
14281a0fd4SPatrick Kelsey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15281a0fd4SPatrick Kelsey * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16281a0fd4SPatrick Kelsey * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17281a0fd4SPatrick Kelsey * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18281a0fd4SPatrick Kelsey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19281a0fd4SPatrick Kelsey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20281a0fd4SPatrick Kelsey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21281a0fd4SPatrick Kelsey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22281a0fd4SPatrick Kelsey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23281a0fd4SPatrick Kelsey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24281a0fd4SPatrick Kelsey * SUCH DAMAGE.
25281a0fd4SPatrick Kelsey */
26281a0fd4SPatrick Kelsey
27281a0fd4SPatrick Kelsey #ifndef _TCP_FASTOPEN_H_
28281a0fd4SPatrick Kelsey #define _TCP_FASTOPEN_H_
29281a0fd4SPatrick Kelsey
30281a0fd4SPatrick Kelsey #ifdef _KERNEL
31281a0fd4SPatrick Kelsey
3218a75309SPatrick Kelsey #include "opt_inet.h"
3318a75309SPatrick Kelsey
34c560df6fSPatrick Kelsey #define TCP_FASTOPEN_COOKIE_LEN 8 /* SipHash24 64-bit output */
35281a0fd4SPatrick Kelsey
3618a75309SPatrick Kelsey #ifdef TCP_RFC7413
37c560df6fSPatrick Kelsey VNET_DECLARE(unsigned int, tcp_fastopen_client_enable);
38c560df6fSPatrick Kelsey #define V_tcp_fastopen_client_enable VNET(tcp_fastopen_client_enable)
39c560df6fSPatrick Kelsey
40c560df6fSPatrick Kelsey VNET_DECLARE(unsigned int, tcp_fastopen_server_enable);
41c560df6fSPatrick Kelsey #define V_tcp_fastopen_server_enable VNET(tcp_fastopen_server_enable)
4218a75309SPatrick Kelsey #else
4318a75309SPatrick Kelsey #define V_tcp_fastopen_client_enable 0
4418a75309SPatrick Kelsey #define V_tcp_fastopen_server_enable 0
4518a75309SPatrick Kelsey #endif /* TCP_RFC7413 */
46c560df6fSPatrick Kelsey
47c560df6fSPatrick Kelsey union tcp_fastopen_ip_addr {
48c560df6fSPatrick Kelsey struct in_addr v4;
49c560df6fSPatrick Kelsey struct in6_addr v6;
50c560df6fSPatrick Kelsey };
51c560df6fSPatrick Kelsey
52c560df6fSPatrick Kelsey struct tcp_fastopen_ccache_entry {
53c560df6fSPatrick Kelsey TAILQ_ENTRY(tcp_fastopen_ccache_entry) cce_link;
54c560df6fSPatrick Kelsey union tcp_fastopen_ip_addr cce_client_ip; /* network byte order */
55c560df6fSPatrick Kelsey union tcp_fastopen_ip_addr cce_server_ip; /* network byte order */
56c560df6fSPatrick Kelsey uint16_t server_port; /* network byte order */
57c560df6fSPatrick Kelsey uint16_t server_mss; /* host byte order */
58c560df6fSPatrick Kelsey uint8_t af;
59c560df6fSPatrick Kelsey uint8_t cookie_len;
60c560df6fSPatrick Kelsey uint8_t cookie[TCP_FASTOPEN_MAX_COOKIE_LEN];
61c560df6fSPatrick Kelsey sbintime_t disable_time; /* non-zero value means path is disabled */
62c560df6fSPatrick Kelsey };
63c560df6fSPatrick Kelsey
64c560df6fSPatrick Kelsey struct tcp_fastopen_ccache;
65c560df6fSPatrick Kelsey
66c560df6fSPatrick Kelsey struct tcp_fastopen_ccache_bucket {
67c560df6fSPatrick Kelsey struct mtx ccb_mtx;
68c560df6fSPatrick Kelsey TAILQ_HEAD(bucket_entries, tcp_fastopen_ccache_entry) ccb_entries;
69c560df6fSPatrick Kelsey int ccb_num_entries;
70c560df6fSPatrick Kelsey struct tcp_fastopen_ccache *ccb_ccache;
71c560df6fSPatrick Kelsey };
72c560df6fSPatrick Kelsey
73c560df6fSPatrick Kelsey struct tcp_fastopen_ccache {
74c560df6fSPatrick Kelsey uma_zone_t zone;
75c560df6fSPatrick Kelsey struct tcp_fastopen_ccache_bucket *base;
76c560df6fSPatrick Kelsey unsigned int bucket_limit;
77c560df6fSPatrick Kelsey unsigned int buckets;
78c560df6fSPatrick Kelsey unsigned int mask;
79c560df6fSPatrick Kelsey uint32_t secret;
80c560df6fSPatrick Kelsey };
81281a0fd4SPatrick Kelsey
82*d62c4607SGleb Smirnoff struct tcpcb;
8318a75309SPatrick Kelsey #ifdef TCP_RFC7413
84281a0fd4SPatrick Kelsey void tcp_fastopen_init(void);
85281a0fd4SPatrick Kelsey void tcp_fastopen_destroy(void);
86281a0fd4SPatrick Kelsey unsigned int *tcp_fastopen_alloc_counter(void);
87c560df6fSPatrick Kelsey void tcp_fastopen_decrement_counter(unsigned int *);
88c560df6fSPatrick Kelsey int tcp_fastopen_check_cookie(struct in_conninfo *, uint8_t *, unsigned int,
89c560df6fSPatrick Kelsey uint64_t *);
90c560df6fSPatrick Kelsey void tcp_fastopen_connect(struct tcpcb *);
91c560df6fSPatrick Kelsey void tcp_fastopen_disable_path(struct tcpcb *);
92c560df6fSPatrick Kelsey void tcp_fastopen_update_cache(struct tcpcb *, uint16_t, uint8_t,
93c560df6fSPatrick Kelsey uint8_t *);
9418a75309SPatrick Kelsey #else
953b994db7SJohn Baldwin static __inline void
tcp_fastopen_init(void)963b994db7SJohn Baldwin tcp_fastopen_init(void)
973b994db7SJohn Baldwin {
983b994db7SJohn Baldwin }
993b994db7SJohn Baldwin
1003b994db7SJohn Baldwin static __inline void
tcp_fastopen_destroy(void)1013b994db7SJohn Baldwin tcp_fastopen_destroy(void)
1023b994db7SJohn Baldwin {
1033b994db7SJohn Baldwin }
1043b994db7SJohn Baldwin
1053b994db7SJohn Baldwin static __inline unsigned int *
tcp_fastopen_alloc_counter(void)1063b994db7SJohn Baldwin tcp_fastopen_alloc_counter(void)
1073b994db7SJohn Baldwin {
1083b994db7SJohn Baldwin return (NULL);
1093b994db7SJohn Baldwin }
1103b994db7SJohn Baldwin
1113b994db7SJohn Baldwin static __inline void
tcp_fastopen_decrement_counter(unsigned int * _counter)1123b994db7SJohn Baldwin tcp_fastopen_decrement_counter(unsigned int *_counter)
1133b994db7SJohn Baldwin {
1143b994db7SJohn Baldwin }
1153b994db7SJohn Baldwin
1163b994db7SJohn Baldwin static __inline int
tcp_fastopen_check_cookie(struct in_conninfo * _inc,uint8_t * _cookie,unsigned int _len,uint64_t * _latest_cookie)1173b994db7SJohn Baldwin tcp_fastopen_check_cookie(struct in_conninfo *_inc, uint8_t *_cookie,
1183b994db7SJohn Baldwin unsigned int _len, uint64_t *_latest_cookie)
1193b994db7SJohn Baldwin {
1203b994db7SJohn Baldwin return (-1);
1213b994db7SJohn Baldwin }
1223b994db7SJohn Baldwin
1233b994db7SJohn Baldwin static __inline void
tcp_fastopen_connect(struct tcpcb * _tp)1243b994db7SJohn Baldwin tcp_fastopen_connect(struct tcpcb *_tp)
1253b994db7SJohn Baldwin {
1263b994db7SJohn Baldwin }
1273b994db7SJohn Baldwin
1283b994db7SJohn Baldwin static __inline void
tcp_fastopen_disable_path(struct tcpcb * _tp)1293b994db7SJohn Baldwin tcp_fastopen_disable_path(struct tcpcb *_tp)
1303b994db7SJohn Baldwin {
1313b994db7SJohn Baldwin }
1323b994db7SJohn Baldwin
1333b994db7SJohn Baldwin static __inline void
tcp_fastopen_update_cache(struct tcpcb * _tp,uint16_t _mss,uint8_t _cookie_len,uint8_t * _cookie)1343b994db7SJohn Baldwin tcp_fastopen_update_cache(struct tcpcb *_tp, uint16_t _mss, uint8_t _cookie_len,
1353b994db7SJohn Baldwin uint8_t *_cookie)
1363b994db7SJohn Baldwin {
1373b994db7SJohn Baldwin }
13818a75309SPatrick Kelsey #endif /* TCP_RFC7413 */
13918a75309SPatrick Kelsey
140281a0fd4SPatrick Kelsey #endif /* _KERNEL */
141281a0fd4SPatrick Kelsey
142281a0fd4SPatrick Kelsey #endif /* _TCP_FASTOPEN_H_ */
143