aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/tcp_fastopen.h
blob: ee860941fdb8d5054c371f26b8cba41d5c8eaeb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*-
 * Copyright (c) 2015-2017 Patrick Kelsey
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _TCP_FASTOPEN_H_
#define _TCP_FASTOPEN_H_

#ifdef _KERNEL

#include "opt_inet.h"

#define	TCP_FASTOPEN_COOKIE_LEN		8	/* SipHash24 64-bit output */

#ifdef TCP_RFC7413
VNET_DECLARE(unsigned int, tcp_fastopen_client_enable);
#define	V_tcp_fastopen_client_enable	VNET(tcp_fastopen_client_enable)

VNET_DECLARE(unsigned int, tcp_fastopen_server_enable);
#define	V_tcp_fastopen_server_enable	VNET(tcp_fastopen_server_enable)
#else
#define	V_tcp_fastopen_client_enable	0
#define	V_tcp_fastopen_server_enable	0
#endif  /* TCP_RFC7413 */

union tcp_fastopen_ip_addr {
	struct in_addr v4;
	struct in6_addr v6;
};

struct tcp_fastopen_ccache_entry {
	TAILQ_ENTRY(tcp_fastopen_ccache_entry) cce_link;
	union tcp_fastopen_ip_addr cce_client_ip;	/* network byte order */
	union tcp_fastopen_ip_addr cce_server_ip;	/* network byte order */
	uint16_t server_port;				/* network byte order */
	uint16_t server_mss;				/* host byte order */
	uint8_t af;
	uint8_t cookie_len;
	uint8_t cookie[TCP_FASTOPEN_MAX_COOKIE_LEN];
	sbintime_t disable_time; /* non-zero value means path is disabled */
};

struct tcp_fastopen_ccache;

struct tcp_fastopen_ccache_bucket {
	struct mtx	ccb_mtx;
	TAILQ_HEAD(bucket_entries, tcp_fastopen_ccache_entry) ccb_entries;
	int		ccb_num_entries;
	struct tcp_fastopen_ccache *ccb_ccache;
};

struct tcp_fastopen_ccache {
	uma_zone_t 	zone;
	struct tcp_fastopen_ccache_bucket *base;
	unsigned int 	bucket_limit;
	unsigned int 	buckets;
	unsigned int 	mask;
	uint32_t 	secret;
};

#ifdef TCP_RFC7413
void	tcp_fastopen_init(void);
void	tcp_fastopen_destroy(void);
unsigned int *tcp_fastopen_alloc_counter(void);
void	tcp_fastopen_decrement_counter(unsigned int *);
int	tcp_fastopen_check_cookie(struct in_conninfo *, uint8_t *, unsigned int,
	    uint64_t *);
void	tcp_fastopen_connect(struct tcpcb *);
void	tcp_fastopen_disable_path(struct tcpcb *);
void	tcp_fastopen_update_cache(struct tcpcb *, uint16_t, uint8_t,
	    uint8_t *);
#else
static __inline void
tcp_fastopen_init(void)
{
}

static __inline void
tcp_fastopen_destroy(void)
{
}

static __inline unsigned int *
tcp_fastopen_alloc_counter(void)
{
	return (NULL);
}

static __inline void
tcp_fastopen_decrement_counter(unsigned int *_counter)
{
}

static __inline int
tcp_fastopen_check_cookie(struct in_conninfo *_inc, uint8_t *_cookie,
    unsigned int _len, uint64_t *_latest_cookie)
{
	return (-1);
}

static __inline void
tcp_fastopen_connect(struct tcpcb *_tp)
{
}

static __inline void
tcp_fastopen_disable_path(struct tcpcb *_tp)
{
}

static __inline void
tcp_fastopen_update_cache(struct tcpcb *_tp, uint16_t _mss, uint8_t _cookie_len,
    uint8_t *_cookie)
{
}
#endif /* TCP_RFC7413 */

#endif /* _KERNEL */

#endif /* _TCP_FASTOPEN_H_ */