xref: /freebsd/sys/netinet/tcp_fastopen.h (revision f9bc005b8ef3b507a5ecbc2d7fe4411ef70eff38)
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 
27 #ifndef _TCP_FASTOPEN_H_
28 #define _TCP_FASTOPEN_H_
29 
30 #ifdef _KERNEL
31 
32 #include "opt_inet.h"
33 
34 #define	TCP_FASTOPEN_COOKIE_LEN		8	/* SipHash24 64-bit output */
35 
36 #ifdef TCP_RFC7413
37 VNET_DECLARE(unsigned int, tcp_fastopen_client_enable);
38 #define	V_tcp_fastopen_client_enable	VNET(tcp_fastopen_client_enable)
39 
40 VNET_DECLARE(unsigned int, tcp_fastopen_server_enable);
41 #define	V_tcp_fastopen_server_enable	VNET(tcp_fastopen_server_enable)
42 #else
43 #define	V_tcp_fastopen_client_enable	0
44 #define	V_tcp_fastopen_server_enable	0
45 #endif  /* TCP_RFC7413 */
46 
47 struct tcpcb;
48 #ifdef TCP_RFC7413
49 void	tcp_fastopen_init(void);
50 void	tcp_fastopen_vnet_init(void);
51 void	tcp_fastopen_vnet_destroy(void);
52 unsigned int *tcp_fastopen_alloc_counter(void);
53 void	tcp_fastopen_decrement_counter(unsigned int *);
54 int	tcp_fastopen_check_cookie(struct in_conninfo *, uint8_t *, unsigned int,
55 	    uint64_t *);
56 void	tcp_fastopen_connect(struct tcpcb *);
57 void	tcp_fastopen_disable_path(struct tcpcb *);
58 void	tcp_fastopen_update_cache(struct tcpcb *, uint16_t, uint8_t,
59 	    uint8_t *);
60 #else
61 static __inline void
62 tcp_fastopen_init(void)
63 {
64 }
65 
66 static __inline void
67 tcp_fastopen_vnet_init(void)
68 {
69 }
70 
71 static __inline void
72 tcp_fastopen_vnet_destroy(void)
73 {
74 }
75 
76 static __inline unsigned int *
77 tcp_fastopen_alloc_counter(void)
78 {
79 	return (NULL);
80 }
81 
82 static __inline void
83 tcp_fastopen_decrement_counter(unsigned int *_counter)
84 {
85 }
86 
87 static __inline int
88 tcp_fastopen_check_cookie(struct in_conninfo *_inc, uint8_t *_cookie,
89     unsigned int _len, uint64_t *_latest_cookie)
90 {
91 	return (-1);
92 }
93 
94 static __inline void
95 tcp_fastopen_connect(struct tcpcb *_tp)
96 {
97 }
98 
99 static __inline void
100 tcp_fastopen_disable_path(struct tcpcb *_tp)
101 {
102 }
103 
104 static __inline void
105 tcp_fastopen_update_cache(struct tcpcb *_tp, uint16_t _mss, uint8_t _cookie_len,
106     uint8_t *_cookie)
107 {
108 }
109 #endif /* TCP_RFC7413 */
110 
111 #endif /* _KERNEL */
112 
113 #endif /* _TCP_FASTOPEN_H_ */
114