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
28 * This is an implementation of TCP Fast Open (TFO) [RFC7413]. To include
29 * this code, add the following line to your kernel config:
34 * The generated TFO cookies are the 64-bit output of
35 * SipHash24(key=<16-byte-key>, msg=<client-ip>). Multiple concurrent valid
36 * keys are supported so that time-based rolling cookie invalidation
37 * policies can be implemented in the system. The default number of
38 * concurrent keys is 2. This can be adjusted in the kernel config as
41 * options TCP_RFC7413_MAX_KEYS=<num-keys>
44 * In addition to the facilities defined in RFC7413, this implementation
45 * supports a pre-shared key (PSK) mode of operation in which the TFO server
46 * requires the client to be in posession of a shared secret in order for
47 * the client to be able to successfully open TFO connections with the
48 * server. This is useful, for example, in environments where TFO servers
49 * are exposed to both internal and external clients and only wish to allow
50 * TFO connections from internal clients.
52 * In the PSK mode of operation, the server generates and sends TFO cookies
53 * to requesting clients as usual. However, when validating cookies
54 * received in TFO SYNs from clients, the server requires the
55 * client-supplied cookie to equal SipHash24(key=<16-byte-psk>,
56 * msg=<cookie-sent-to-client>).
58 * Multiple concurrent valid pre-shared keys are supported so that
59 * time-based rolling PSK invalidation policies can be implemented in the
60 * system. The default number of concurrent pre-shared keys is 2. This can
61 * be adjusted in the kernel config as follows:
63 * options TCP_RFC7413_MAX_PSKS=<num-psks>
66 * The following TFO-specific sysctls are defined:
68 * net.inet.tcp.fastopen.acceptany (RW, default 0)
69 * When non-zero, all client-supplied TFO cookies will be considered to
72 * net.inet.tcp.fastopen.autokey (RW, default 120)
73 * When this and net.inet.tcp.fastopen.server_enable are non-zero, a new
74 * key will be automatically generated after this many seconds.
76 * net.inet.tcp.fastopen.ccache_bucket_limit
77 * (RWTUN, default TCP_FASTOPEN_CCACHE_BUCKET_LIMIT_DEFAULT)
78 * The maximum number of entries in a client cookie cache bucket.
80 * net.inet.tcp.fastopen.ccache_buckets
81 * (RDTUN, default TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT)
82 * The number of client cookie cache buckets.
84 * net.inet.tcp.fastopen.ccache_list (RO)
85 * Print the client cookie cache.
87 * net.inet.tcp.fastopen.client_enable (RW, default 0)
88 * When zero, no new active (i.e., client) TFO connections can be
89 * created. On the transition from enabled to disabled, the client
90 * cookie cache is cleared and disabled. The transition from enabled to
91 * disabled does not affect any active TFO connections in progress; it
92 * only prevents new ones from being made.
94 * net.inet.tcp.fastopen.keylen (RD)
95 * The key length in bytes.
97 * net.inet.tcp.fastopen.maxkeys (RD)
98 * The maximum number of keys supported.
100 * net.inet.tcp.fastopen.maxpsks (RD)
101 * The maximum number of pre-shared keys supported.
103 * net.inet.tcp.fastopen.numkeys (RD)
104 * The current number of keys installed.
106 * net.inet.tcp.fastopen.numpsks (RD)
107 * The current number of pre-shared keys installed.
109 * net.inet.tcp.fastopen.path_disable_time
110 * (RW, default TCP_FASTOPEN_PATH_DISABLE_TIME_DEFAULT)
111 * When a failure occurs while trying to create a new active (i.e.,
112 * client) TFO connection, new active connections on the same path, as
113 * determined by the tuple {client_ip, server_ip, server_port}, will be
114 * forced to be non-TFO for this many seconds. Note that the path
115 * disable mechanism relies on state stored in client cookie cache
116 * entries, so it is possible for the disable time for a given path to
117 * be reduced if the corresponding client cookie cache entry is reused
118 * due to resource pressure before the disable period has elapsed.
120 * net.inet.tcp.fastopen.psk_enable (RW, default 0)
121 * When non-zero, pre-shared key (PSK) mode is enabled for all TFO
122 * servers. On the transition from enabled to disabled, all installed
123 * pre-shared keys are removed.
125 * net.inet.tcp.fastopen.server_enable (RW, default 0)
126 * When zero, no new passive (i.e., server) TFO connections can be
127 * created. On the transition from enabled to disabled, all installed
128 * keys and pre-shared keys are removed. On the transition from
129 * disabled to enabled, if net.inet.tcp.fastopen.autokey is non-zero and
130 * there are no keys installed, a new key will be generated immediately.
131 * The transition from enabled to disabled does not affect any passive
132 * TFO connections in progress; it only prevents new ones from being
135 * net.inet.tcp.fastopen.setkey (WR)
136 * Install a new key by writing net.inet.tcp.fastopen.keylen bytes to
139 * net.inet.tcp.fastopen.setpsk (WR)
140 * Install a new pre-shared key by writing net.inet.tcp.fastopen.keylen
141 * bytes to this sysctl.
143 * In order for TFO connections to be created via a listen socket, that
144 * socket must have the TCP_FASTOPEN socket option set on it. This option
145 * can be set on the socket either before or after the listen() is invoked.
146 * Clearing this option on a listen socket after it has been set has no
147 * effect on existing TFO connections or TFO connections in progress; it
148 * only prevents new TFO connections from being made.
150 * For passively-created sockets, the TCP_FASTOPEN socket option can be
151 * queried to determine whether the connection was established using TFO.
152 * Note that connections that are established via a TFO SYN, but that fall
153 * back to using a non-TFO SYN|ACK will have the TCP_FASTOPEN socket option
156 * Per the RFC, this implementation limits the number of TFO connections
157 * that can be in the SYN_RECEIVED state on a per listen-socket basis.
158 * Whenever this limit is exceeded, requests for new TFO connections are
159 * serviced as non-TFO requests. Without such a limit, given a valid TFO
160 * cookie, an attacker could keep the listen queue in an overflow condition
161 * using a TFO SYN flood. This implementation sets the limit at half the
162 * configured listen backlog.
166 #include <sys/cdefs.h>
167 #include "opt_inet.h"
169 #include <sys/param.h>
170 #include <sys/jail.h>
171 #include <sys/kernel.h>
172 #include <sys/hash.h>
173 #include <sys/limits.h>
174 #include <sys/lock.h>
175 #include <sys/proc.h>
176 #include <sys/rmlock.h>
177 #include <sys/sbuf.h>
178 #include <sys/socket.h>
179 #include <sys/socketvar.h>
180 #include <sys/sysctl.h>
181 #include <sys/systm.h>
183 #include <crypto/siphash/siphash.h>
185 #include <net/vnet.h>
187 #include <netinet/in.h>
188 #include <netinet/in_pcb.h>
189 #include <netinet/tcp_var.h>
190 #include <netinet/tcp_fastopen.h>
192 #define TCP_FASTOPEN_KEY_LEN SIPHASH_KEY_LENGTH
194 #if TCP_FASTOPEN_PSK_LEN != TCP_FASTOPEN_KEY_LEN
195 #error TCP_FASTOPEN_PSK_LEN must be equal to TCP_FASTOPEN_KEY_LEN
199 * Because a PSK-mode setsockopt() uses tcpcb.t_tfo_cookie.client to hold
200 * the PSK until the connect occurs.
202 #if TCP_FASTOPEN_MAX_COOKIE_LEN < TCP_FASTOPEN_PSK_LEN
203 #error TCP_FASTOPEN_MAX_COOKIE_LEN must be >= TCP_FASTOPEN_PSK_LEN
206 #define TCP_FASTOPEN_CCACHE_BUCKET_LIMIT_DEFAULT 16
207 #define TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT 2048 /* must be power of 2 */
209 #define TCP_FASTOPEN_PATH_DISABLE_TIME_DEFAULT 900 /* seconds */
211 #if !defined(TCP_RFC7413_MAX_KEYS) || (TCP_RFC7413_MAX_KEYS < 1)
212 #define TCP_FASTOPEN_MAX_KEYS 2
214 #define TCP_FASTOPEN_MAX_KEYS TCP_RFC7413_MAX_KEYS
217 #if TCP_FASTOPEN_MAX_KEYS > 10
218 #undef TCP_FASTOPEN_MAX_KEYS
219 #define TCP_FASTOPEN_MAX_KEYS 10
222 #if !defined(TCP_RFC7413_MAX_PSKS) || (TCP_RFC7413_MAX_PSKS < 1)
223 #define TCP_FASTOPEN_MAX_PSKS 2
225 #define TCP_FASTOPEN_MAX_PSKS TCP_RFC7413_MAX_PSKS
228 #if TCP_FASTOPEN_MAX_PSKS > 10
229 #undef TCP_FASTOPEN_MAX_PSKS
230 #define TCP_FASTOPEN_MAX_PSKS 10
233 struct tcp_fastopen_keylist {
235 unsigned int newest_psk;
236 uint8_t key[TCP_FASTOPEN_MAX_KEYS][TCP_FASTOPEN_KEY_LEN];
237 uint8_t psk[TCP_FASTOPEN_MAX_PSKS][TCP_FASTOPEN_KEY_LEN];
240 struct tcp_fastopen_callout {
245 static struct tcp_fastopen_ccache_entry *tcp_fastopen_ccache_lookup(
246 struct in_conninfo *, struct tcp_fastopen_ccache_bucket **);
247 static struct tcp_fastopen_ccache_entry *tcp_fastopen_ccache_create(
248 struct tcp_fastopen_ccache_bucket *, struct in_conninfo *, uint16_t, uint8_t,
250 static void tcp_fastopen_ccache_bucket_trim(struct tcp_fastopen_ccache_bucket *,
252 static void tcp_fastopen_ccache_entry_drop(struct tcp_fastopen_ccache_entry *,
253 struct tcp_fastopen_ccache_bucket *);
255 SYSCTL_NODE(_net_inet_tcp, OID_AUTO, fastopen, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
258 VNET_DEFINE_STATIC(int, tcp_fastopen_acceptany) = 0;
259 #define V_tcp_fastopen_acceptany VNET(tcp_fastopen_acceptany)
260 SYSCTL_INT(_net_inet_tcp_fastopen, OID_AUTO, acceptany,
261 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(tcp_fastopen_acceptany), 0,
262 "Accept any non-empty cookie");
264 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_autokey) = 120;
265 #define V_tcp_fastopen_autokey VNET(tcp_fastopen_autokey)
266 static int sysctl_net_inet_tcp_fastopen_autokey(SYSCTL_HANDLER_ARGS);
267 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, autokey,
268 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
269 NULL, 0, &sysctl_net_inet_tcp_fastopen_autokey, "IU",
270 "Number of seconds between auto-generation of a new key; zero disables");
272 static int sysctl_net_inet_tcp_fastopen_ccache_bucket_limit(SYSCTL_HANDLER_ARGS);
273 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, ccache_bucket_limit,
274 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT,
275 NULL, 0, &sysctl_net_inet_tcp_fastopen_ccache_bucket_limit, "IU",
276 "Max entries per bucket in client cookie cache");
278 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_ccache_buckets) =
279 TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT;
280 #define V_tcp_fastopen_ccache_buckets VNET(tcp_fastopen_ccache_buckets)
281 SYSCTL_UINT(_net_inet_tcp_fastopen, OID_AUTO, ccache_buckets,
282 CTLFLAG_VNET | CTLFLAG_RDTUN, &VNET_NAME(tcp_fastopen_ccache_buckets), 0,
283 "Client cookie cache number of buckets (power of 2)");
285 VNET_DEFINE(unsigned int, tcp_fastopen_client_enable) = 1;
286 static int sysctl_net_inet_tcp_fastopen_client_enable(SYSCTL_HANDLER_ARGS);
287 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, client_enable,
288 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
289 NULL, 0, &sysctl_net_inet_tcp_fastopen_client_enable, "IU",
290 "Enable/disable TCP Fast Open client functionality");
292 SYSCTL_INT(_net_inet_tcp_fastopen, OID_AUTO, keylen,
293 CTLFLAG_RD, SYSCTL_NULL_INT_PTR, TCP_FASTOPEN_KEY_LEN,
294 "Key length in bytes");
296 SYSCTL_INT(_net_inet_tcp_fastopen, OID_AUTO, maxkeys,
297 CTLFLAG_RD, SYSCTL_NULL_INT_PTR, TCP_FASTOPEN_MAX_KEYS,
298 "Maximum number of keys supported");
300 SYSCTL_INT(_net_inet_tcp_fastopen, OID_AUTO, maxpsks,
301 CTLFLAG_RD, SYSCTL_NULL_INT_PTR, TCP_FASTOPEN_MAX_PSKS,
302 "Maximum number of pre-shared keys supported");
304 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_numkeys) = 0;
305 #define V_tcp_fastopen_numkeys VNET(tcp_fastopen_numkeys)
306 SYSCTL_UINT(_net_inet_tcp_fastopen, OID_AUTO, numkeys,
307 CTLFLAG_VNET | CTLFLAG_RD, &VNET_NAME(tcp_fastopen_numkeys), 0,
308 "Number of keys installed");
310 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_numpsks) = 0;
311 #define V_tcp_fastopen_numpsks VNET(tcp_fastopen_numpsks)
312 SYSCTL_UINT(_net_inet_tcp_fastopen, OID_AUTO, numpsks,
313 CTLFLAG_VNET | CTLFLAG_RD, &VNET_NAME(tcp_fastopen_numpsks), 0,
314 "Number of pre-shared keys installed");
316 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_path_disable_time) =
317 TCP_FASTOPEN_PATH_DISABLE_TIME_DEFAULT;
318 #define V_tcp_fastopen_path_disable_time VNET(tcp_fastopen_path_disable_time)
319 SYSCTL_UINT(_net_inet_tcp_fastopen, OID_AUTO, path_disable_time,
320 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(tcp_fastopen_path_disable_time), 0,
321 "Seconds a TFO failure disables a {client_ip, server_ip, server_port} path");
323 VNET_DEFINE_STATIC(unsigned int, tcp_fastopen_psk_enable) = 0;
324 #define V_tcp_fastopen_psk_enable VNET(tcp_fastopen_psk_enable)
325 static int sysctl_net_inet_tcp_fastopen_psk_enable(SYSCTL_HANDLER_ARGS);
326 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, psk_enable,
327 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
328 NULL, 0, &sysctl_net_inet_tcp_fastopen_psk_enable, "IU",
329 "Enable/disable TCP Fast Open server pre-shared key mode");
331 VNET_DEFINE(unsigned int, tcp_fastopen_server_enable) = 0;
332 static int sysctl_net_inet_tcp_fastopen_server_enable(SYSCTL_HANDLER_ARGS);
333 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, server_enable,
334 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
335 NULL, 0, &sysctl_net_inet_tcp_fastopen_server_enable, "IU",
336 "Enable/disable TCP Fast Open server functionality");
338 static int sysctl_net_inet_tcp_fastopen_setkey(SYSCTL_HANDLER_ARGS);
339 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, setkey,
340 CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_WR | CTLFLAG_MPSAFE,
341 NULL, 0, &sysctl_net_inet_tcp_fastopen_setkey, "",
342 "Install a new key");
344 static int sysctl_net_inet_tcp_fastopen_setpsk(SYSCTL_HANDLER_ARGS);
345 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, setpsk,
346 CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_WR | CTLFLAG_MPSAFE,
347 NULL, 0, &sysctl_net_inet_tcp_fastopen_setpsk, "",
348 "Install a new pre-shared key");
350 static int sysctl_net_inet_tcp_fastopen_ccache_list(SYSCTL_HANDLER_ARGS);
351 SYSCTL_PROC(_net_inet_tcp_fastopen, OID_AUTO, ccache_list,
352 CTLFLAG_VNET | CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE,
353 NULL, 0, sysctl_net_inet_tcp_fastopen_ccache_list, "A",
354 "List of all client cookie cache entries");
356 VNET_DEFINE_STATIC(struct rmlock, tcp_fastopen_keylock);
357 #define V_tcp_fastopen_keylock VNET(tcp_fastopen_keylock)
359 #define TCP_FASTOPEN_KEYS_RLOCK(t) rm_rlock(&V_tcp_fastopen_keylock, (t))
360 #define TCP_FASTOPEN_KEYS_RUNLOCK(t) rm_runlock(&V_tcp_fastopen_keylock, (t))
361 #define TCP_FASTOPEN_KEYS_WLOCK() rm_wlock(&V_tcp_fastopen_keylock)
362 #define TCP_FASTOPEN_KEYS_WUNLOCK() rm_wunlock(&V_tcp_fastopen_keylock)
364 VNET_DEFINE_STATIC(struct tcp_fastopen_keylist, tcp_fastopen_keys);
365 #define V_tcp_fastopen_keys VNET(tcp_fastopen_keys)
367 VNET_DEFINE_STATIC(struct tcp_fastopen_callout, tcp_fastopen_autokey_ctx);
368 #define V_tcp_fastopen_autokey_ctx VNET(tcp_fastopen_autokey_ctx)
370 VNET_DEFINE_STATIC(uma_zone_t, counter_zone);
371 #define V_counter_zone VNET(counter_zone)
373 static MALLOC_DEFINE(M_TCP_FASTOPEN_CCACHE, "tfo_ccache", "TFO client cookie cache buckets");
375 VNET_DEFINE_STATIC(struct tcp_fastopen_ccache, tcp_fastopen_ccache);
376 #define V_tcp_fastopen_ccache VNET(tcp_fastopen_ccache)
378 #define CCB_LOCK(ccb) mtx_lock(&(ccb)->ccb_mtx)
379 #define CCB_UNLOCK(ccb) mtx_unlock(&(ccb)->ccb_mtx)
380 #define CCB_LOCK_ASSERT(ccb) mtx_assert(&(ccb)->ccb_mtx, MA_OWNED)
383 tcp_fastopen_init(void)
387 V_counter_zone = uma_zcreate("tfo", sizeof(unsigned int),
388 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
389 rm_init(&V_tcp_fastopen_keylock, "tfo_keylock");
390 callout_init_rm(&V_tcp_fastopen_autokey_ctx.c,
391 &V_tcp_fastopen_keylock, 0);
392 V_tcp_fastopen_autokey_ctx.v = curvnet;
393 V_tcp_fastopen_keys.newest = TCP_FASTOPEN_MAX_KEYS - 1;
394 V_tcp_fastopen_keys.newest_psk = TCP_FASTOPEN_MAX_PSKS - 1;
396 /* May already be non-zero if kernel tunable was set */
397 if (V_tcp_fastopen_ccache.bucket_limit == 0)
398 V_tcp_fastopen_ccache.bucket_limit =
399 TCP_FASTOPEN_CCACHE_BUCKET_LIMIT_DEFAULT;
401 /* May already be non-zero if kernel tunable was set */
402 if ((V_tcp_fastopen_ccache_buckets == 0) ||
403 !powerof2(V_tcp_fastopen_ccache_buckets))
404 V_tcp_fastopen_ccache.buckets =
405 TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT;
407 V_tcp_fastopen_ccache.buckets = V_tcp_fastopen_ccache_buckets;
409 V_tcp_fastopen_ccache.mask = V_tcp_fastopen_ccache.buckets - 1;
410 V_tcp_fastopen_ccache.secret = arc4random();
412 V_tcp_fastopen_ccache.base = malloc(V_tcp_fastopen_ccache.buckets *
413 sizeof(struct tcp_fastopen_ccache_bucket), M_TCP_FASTOPEN_CCACHE,
416 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
417 TAILQ_INIT(&V_tcp_fastopen_ccache.base[i].ccb_entries);
418 mtx_init(&V_tcp_fastopen_ccache.base[i].ccb_mtx, "tfo_ccache_bucket",
420 if (V_tcp_fastopen_client_enable) {
422 V_tcp_fastopen_ccache.base[i].ccb_num_entries = 0;
425 V_tcp_fastopen_ccache.base[i].ccb_num_entries = -1;
427 V_tcp_fastopen_ccache.base[i].ccb_ccache = &V_tcp_fastopen_ccache;
431 * Note that while the total number of entries in the cookie cache
432 * is limited by the table management logic to
433 * V_tcp_fastopen_ccache.buckets *
434 * V_tcp_fastopen_ccache.bucket_limit, the total number of items in
435 * this zone can exceed that amount by the number of CPUs in the
436 * system times the maximum number of unallocated items that can be
437 * present in each UMA per-CPU cache for this zone.
439 V_tcp_fastopen_ccache.zone = uma_zcreate("tfo_ccache_entries",
440 sizeof(struct tcp_fastopen_ccache_entry), NULL, NULL, NULL, NULL,
445 tcp_fastopen_destroy(void)
447 struct tcp_fastopen_ccache_bucket *ccb;
450 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
451 ccb = &V_tcp_fastopen_ccache.base[i];
452 tcp_fastopen_ccache_bucket_trim(ccb, 0);
453 mtx_destroy(&ccb->ccb_mtx);
456 KASSERT(uma_zone_get_cur(V_tcp_fastopen_ccache.zone) == 0,
457 ("%s: TFO ccache zone allocation count not 0", __func__));
458 uma_zdestroy(V_tcp_fastopen_ccache.zone);
459 free(V_tcp_fastopen_ccache.base, M_TCP_FASTOPEN_CCACHE);
461 callout_drain(&V_tcp_fastopen_autokey_ctx.c);
462 rm_destroy(&V_tcp_fastopen_keylock);
463 uma_zdestroy(V_counter_zone);
467 tcp_fastopen_alloc_counter(void)
469 unsigned int *counter;
470 counter = uma_zalloc(V_counter_zone, M_NOWAIT);
477 tcp_fastopen_decrement_counter(unsigned int *counter)
480 uma_zfree(V_counter_zone, counter);
482 atomic_subtract_int(counter, 1);
486 tcp_fastopen_addkey_locked(uint8_t *key)
489 V_tcp_fastopen_keys.newest++;
490 if (V_tcp_fastopen_keys.newest == TCP_FASTOPEN_MAX_KEYS)
491 V_tcp_fastopen_keys.newest = 0;
492 memcpy(V_tcp_fastopen_keys.key[V_tcp_fastopen_keys.newest], key,
493 TCP_FASTOPEN_KEY_LEN);
494 if (V_tcp_fastopen_numkeys < TCP_FASTOPEN_MAX_KEYS)
495 V_tcp_fastopen_numkeys++;
499 tcp_fastopen_addpsk_locked(uint8_t *psk)
502 V_tcp_fastopen_keys.newest_psk++;
503 if (V_tcp_fastopen_keys.newest_psk == TCP_FASTOPEN_MAX_PSKS)
504 V_tcp_fastopen_keys.newest_psk = 0;
505 memcpy(V_tcp_fastopen_keys.psk[V_tcp_fastopen_keys.newest_psk], psk,
506 TCP_FASTOPEN_KEY_LEN);
507 if (V_tcp_fastopen_numpsks < TCP_FASTOPEN_MAX_PSKS)
508 V_tcp_fastopen_numpsks++;
512 tcp_fastopen_autokey_locked(void)
514 uint8_t newkey[TCP_FASTOPEN_KEY_LEN];
516 arc4rand(newkey, TCP_FASTOPEN_KEY_LEN, 0);
517 tcp_fastopen_addkey_locked(newkey);
521 tcp_fastopen_autokey_callout(void *arg)
523 struct tcp_fastopen_callout *ctx = arg;
526 tcp_fastopen_autokey_locked();
527 callout_reset(&ctx->c, V_tcp_fastopen_autokey * hz,
528 tcp_fastopen_autokey_callout, ctx);
533 tcp_fastopen_make_cookie(uint8_t key[SIPHASH_KEY_LENGTH], struct in_conninfo *inc)
538 SipHash24_Init(&ctx);
539 SipHash_SetKey(&ctx, key);
540 switch (inc->inc_flags & INC_ISIPV6) {
543 SipHash_Update(&ctx, &inc->inc_faddr, sizeof(inc->inc_faddr));
548 SipHash_Update(&ctx, &inc->inc6_faddr, sizeof(inc->inc6_faddr));
552 SipHash_Final((u_int8_t *)&siphash, &ctx);
558 tcp_fastopen_make_psk_cookie(uint8_t *psk, uint8_t *cookie, uint8_t cookie_len)
563 SipHash24_Init(&ctx);
564 SipHash_SetKey(&ctx, psk);
565 SipHash_Update(&ctx, cookie, cookie_len);
566 SipHash_Final((u_int8_t *)&psk_cookie, &ctx);
572 tcp_fastopen_find_cookie_match_locked(uint8_t *wire_cookie, uint64_t *cur_cookie)
574 unsigned int i, psk_index;
577 if (V_tcp_fastopen_psk_enable) {
578 psk_index = V_tcp_fastopen_keys.newest_psk;
579 for (i = 0; i < V_tcp_fastopen_numpsks; i++) {
581 tcp_fastopen_make_psk_cookie(
582 V_tcp_fastopen_keys.psk[psk_index],
583 (uint8_t *)cur_cookie,
584 TCP_FASTOPEN_COOKIE_LEN);
586 if (memcmp(wire_cookie, &psk_cookie,
587 TCP_FASTOPEN_COOKIE_LEN) == 0)
591 psk_index = TCP_FASTOPEN_MAX_PSKS - 1;
595 } else if (memcmp(wire_cookie, cur_cookie, TCP_FASTOPEN_COOKIE_LEN) == 0)
603 * -1 the cookie is invalid and no valid cookie is available
604 * 0 the cookie is invalid and the latest cookie has been returned
605 * 1 the cookie is valid and the latest cookie has been returned
608 tcp_fastopen_check_cookie(struct in_conninfo *inc, uint8_t *cookie,
609 unsigned int len, uint64_t *latest_cookie)
611 struct rm_priotracker tracker;
612 unsigned int i, key_index;
616 if (V_tcp_fastopen_acceptany) {
621 TCP_FASTOPEN_KEYS_RLOCK(&tracker);
622 if (len != TCP_FASTOPEN_COOKIE_LEN) {
623 if (V_tcp_fastopen_numkeys > 0) {
625 tcp_fastopen_make_cookie(
626 V_tcp_fastopen_keys.key[V_tcp_fastopen_keys.newest],
635 * Check against each available key, from newest to oldest.
637 key_index = V_tcp_fastopen_keys.newest;
638 for (i = 0; i < V_tcp_fastopen_numkeys; i++) {
640 tcp_fastopen_make_cookie(V_tcp_fastopen_keys.key[key_index],
643 *latest_cookie = cur_cookie;
644 rv = tcp_fastopen_find_cookie_match_locked(cookie, &cur_cookie);
648 key_index = TCP_FASTOPEN_MAX_KEYS - 1;
655 TCP_FASTOPEN_KEYS_RUNLOCK(&tracker);
660 sysctl_net_inet_tcp_fastopen_autokey(SYSCTL_HANDLER_ARGS)
665 new = V_tcp_fastopen_autokey;
666 error = sysctl_handle_int(oidp, &new, 0, req);
667 if (error == 0 && req->newptr) {
668 if (new > (INT_MAX / hz))
671 TCP_FASTOPEN_KEYS_WLOCK();
672 if (V_tcp_fastopen_server_enable) {
673 if (V_tcp_fastopen_autokey && !new)
674 callout_stop(&V_tcp_fastopen_autokey_ctx.c);
676 callout_reset(&V_tcp_fastopen_autokey_ctx.c,
677 new * hz, tcp_fastopen_autokey_callout,
678 &V_tcp_fastopen_autokey_ctx);
680 V_tcp_fastopen_autokey = new;
681 TCP_FASTOPEN_KEYS_WUNLOCK();
688 sysctl_net_inet_tcp_fastopen_psk_enable(SYSCTL_HANDLER_ARGS)
693 new = V_tcp_fastopen_psk_enable;
694 error = sysctl_handle_int(oidp, &new, 0, req);
695 if (error == 0 && req->newptr) {
696 if (V_tcp_fastopen_psk_enable && !new) {
697 /* enabled -> disabled */
698 TCP_FASTOPEN_KEYS_WLOCK();
699 V_tcp_fastopen_numpsks = 0;
700 V_tcp_fastopen_keys.newest_psk =
701 TCP_FASTOPEN_MAX_PSKS - 1;
702 V_tcp_fastopen_psk_enable = 0;
703 TCP_FASTOPEN_KEYS_WUNLOCK();
704 } else if (!V_tcp_fastopen_psk_enable && new) {
705 /* disabled -> enabled */
706 TCP_FASTOPEN_KEYS_WLOCK();
707 V_tcp_fastopen_psk_enable = 1;
708 TCP_FASTOPEN_KEYS_WUNLOCK();
715 sysctl_net_inet_tcp_fastopen_server_enable(SYSCTL_HANDLER_ARGS)
720 new = V_tcp_fastopen_server_enable;
721 error = sysctl_handle_int(oidp, &new, 0, req);
722 if (error == 0 && req->newptr) {
723 if (V_tcp_fastopen_server_enable && !new) {
724 /* enabled -> disabled */
725 TCP_FASTOPEN_KEYS_WLOCK();
726 V_tcp_fastopen_numkeys = 0;
727 V_tcp_fastopen_keys.newest = TCP_FASTOPEN_MAX_KEYS - 1;
728 if (V_tcp_fastopen_autokey)
729 callout_stop(&V_tcp_fastopen_autokey_ctx.c);
730 V_tcp_fastopen_numpsks = 0;
731 V_tcp_fastopen_keys.newest_psk =
732 TCP_FASTOPEN_MAX_PSKS - 1;
733 V_tcp_fastopen_server_enable = 0;
734 TCP_FASTOPEN_KEYS_WUNLOCK();
735 } else if (!V_tcp_fastopen_server_enable && new) {
736 /* disabled -> enabled */
737 TCP_FASTOPEN_KEYS_WLOCK();
738 if (V_tcp_fastopen_autokey &&
739 (V_tcp_fastopen_numkeys == 0)) {
740 tcp_fastopen_autokey_locked();
741 callout_reset(&V_tcp_fastopen_autokey_ctx.c,
742 V_tcp_fastopen_autokey * hz,
743 tcp_fastopen_autokey_callout,
744 &V_tcp_fastopen_autokey_ctx);
746 V_tcp_fastopen_server_enable = 1;
747 TCP_FASTOPEN_KEYS_WUNLOCK();
754 sysctl_net_inet_tcp_fastopen_setkey(SYSCTL_HANDLER_ARGS)
757 uint8_t newkey[TCP_FASTOPEN_KEY_LEN];
759 if (req->oldptr != NULL || req->oldlen != 0)
761 if (req->newptr == NULL)
763 if (req->newlen != sizeof(newkey))
765 error = SYSCTL_IN(req, newkey, sizeof(newkey));
769 TCP_FASTOPEN_KEYS_WLOCK();
770 tcp_fastopen_addkey_locked(newkey);
771 TCP_FASTOPEN_KEYS_WUNLOCK();
777 sysctl_net_inet_tcp_fastopen_setpsk(SYSCTL_HANDLER_ARGS)
780 uint8_t newpsk[TCP_FASTOPEN_KEY_LEN];
782 if (req->oldptr != NULL || req->oldlen != 0)
784 if (req->newptr == NULL)
786 if (req->newlen != sizeof(newpsk))
788 error = SYSCTL_IN(req, newpsk, sizeof(newpsk));
792 TCP_FASTOPEN_KEYS_WLOCK();
793 tcp_fastopen_addpsk_locked(newpsk);
794 TCP_FASTOPEN_KEYS_WUNLOCK();
800 sysctl_net_inet_tcp_fastopen_ccache_bucket_limit(SYSCTL_HANDLER_ARGS)
802 struct tcp_fastopen_ccache_bucket *ccb;
807 new = V_tcp_fastopen_ccache.bucket_limit;
808 error = sysctl_handle_int(oidp, &new, 0, req);
809 if (error == 0 && req->newptr) {
810 if ((new == 0) || (new > INT_MAX))
813 if (new < V_tcp_fastopen_ccache.bucket_limit) {
814 for (i = 0; i < V_tcp_fastopen_ccache.buckets;
816 ccb = &V_tcp_fastopen_ccache.base[i];
817 tcp_fastopen_ccache_bucket_trim(ccb, new);
820 V_tcp_fastopen_ccache.bucket_limit = new;
827 sysctl_net_inet_tcp_fastopen_client_enable(SYSCTL_HANDLER_ARGS)
829 struct tcp_fastopen_ccache_bucket *ccb;
833 new = V_tcp_fastopen_client_enable;
834 error = sysctl_handle_int(oidp, &new, 0, req);
835 if (error == 0 && req->newptr) {
836 if (V_tcp_fastopen_client_enable && !new) {
837 /* enabled -> disabled */
838 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
839 ccb = &V_tcp_fastopen_ccache.base[i];
840 KASSERT(ccb->ccb_num_entries > -1,
841 ("%s: ccb->ccb_num_entries %d is negative",
842 __func__, ccb->ccb_num_entries));
843 tcp_fastopen_ccache_bucket_trim(ccb, 0);
845 V_tcp_fastopen_client_enable = 0;
846 } else if (!V_tcp_fastopen_client_enable && new) {
847 /* disabled -> enabled */
848 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
849 ccb = &V_tcp_fastopen_ccache.base[i];
851 KASSERT(TAILQ_EMPTY(&ccb->ccb_entries),
852 ("%s: ccb->ccb_entries not empty", __func__));
853 KASSERT(ccb->ccb_num_entries == -1,
854 ("%s: ccb->ccb_num_entries %d not -1", __func__,
855 ccb->ccb_num_entries));
856 ccb->ccb_num_entries = 0; /* enable bucket */
859 V_tcp_fastopen_client_enable = 1;
866 tcp_fastopen_connect(struct tcpcb *tp)
868 struct inpcb *inp = tptoinpcb(tp);
869 struct tcp_fastopen_ccache_bucket *ccb;
870 struct tcp_fastopen_ccache_entry *cce;
876 cce = tcp_fastopen_ccache_lookup(&inp->inp_inc, &ccb);
878 if (cce->disable_time == 0) {
879 if ((cce->cookie_len > 0) &&
880 (tp->t_tfo_client_cookie_len ==
881 TCP_FASTOPEN_PSK_LEN)) {
883 tcp_fastopen_make_psk_cookie(
884 tp->t_tfo_cookie.client,
885 cce->cookie, cce->cookie_len);
887 tp->t_tfo_client_cookie_len = cce->cookie_len;
888 memcpy(tp->t_tfo_cookie.client, cce->cookie,
891 server_mss = cce->server_mss;
893 if (tp->t_tfo_client_cookie_len ==
894 TCP_FASTOPEN_PSK_LEN && psk_cookie) {
895 tp->t_tfo_client_cookie_len =
896 TCP_FASTOPEN_COOKIE_LEN;
897 memcpy(tp->t_tfo_cookie.client, &psk_cookie,
898 TCP_FASTOPEN_COOKIE_LEN);
900 tcp_mss(tp, server_mss ? server_mss : -1);
901 tp->snd_wnd = tp->t_maxseg;
904 * The path is disabled. Check the time and
905 * possibly re-enable.
907 now = getsbinuptime();
908 if (now - cce->disable_time >
909 ((sbintime_t)V_tcp_fastopen_path_disable_time << 32)) {
911 * Re-enable path. Force a TFO cookie
912 * request. Forget the old MSS as it may be
913 * bogus now, and we will rediscover it in
916 cce->disable_time = 0;
920 * tp->t_tfo... cookie details are already
921 * zero from the tcpcb init.
925 * Path is disabled, so disable TFO on this
928 tp->t_flags &= ~TF_FASTOPEN;
933 * snd_wnd is irrelevant since we are either forcing
934 * a TFO cookie request or disabling TFO - either
935 * way, no data with the SYN.
940 * A new entry for this path will be created when a SYN|ACK
941 * comes back, or the attempt otherwise fails.
946 * snd_wnd is irrelevant since we are forcing a TFO cookie
953 tcp_fastopen_disable_path(struct tcpcb *tp)
955 struct in_conninfo *inc = &tptoinpcb(tp)->inp_inc;
956 struct tcp_fastopen_ccache_bucket *ccb;
957 struct tcp_fastopen_ccache_entry *cce;
959 cce = tcp_fastopen_ccache_lookup(inc, &ccb);
964 * Preserve the existing disable time if it is already
967 if (cce->disable_time == 0)
968 cce->disable_time = getsbinuptime();
969 } else /* use invalid cookie len to create disabled entry */
970 tcp_fastopen_ccache_create(ccb, inc, 0,
971 TCP_FASTOPEN_MAX_COOKIE_LEN + 1, NULL);
974 tp->t_flags &= ~TF_FASTOPEN;
978 tcp_fastopen_update_cache(struct tcpcb *tp, uint16_t mss,
979 uint8_t cookie_len, uint8_t *cookie)
981 struct in_conninfo *inc = &tptoinpcb(tp)->inp_inc;
982 struct tcp_fastopen_ccache_bucket *ccb;
983 struct tcp_fastopen_ccache_entry *cce;
985 cce = tcp_fastopen_ccache_lookup(inc, &ccb);
987 if ((cookie_len >= TCP_FASTOPEN_MIN_COOKIE_LEN) &&
988 (cookie_len <= TCP_FASTOPEN_MAX_COOKIE_LEN) &&
989 ((cookie_len & 0x1) == 0)) {
990 cce->server_mss = mss;
991 cce->cookie_len = cookie_len;
992 memcpy(cce->cookie, cookie, cookie_len);
993 cce->disable_time = 0;
995 /* invalid cookie length, disable entry */
999 * Preserve the existing disable time if it is
1002 if (cce->disable_time == 0)
1003 cce->disable_time = getsbinuptime();
1006 tcp_fastopen_ccache_create(ccb, inc, mss, cookie_len, cookie);
1011 static struct tcp_fastopen_ccache_entry *
1012 tcp_fastopen_ccache_lookup(struct in_conninfo *inc,
1013 struct tcp_fastopen_ccache_bucket **ccbp)
1015 struct tcp_fastopen_ccache_bucket *ccb;
1016 struct tcp_fastopen_ccache_entry *cce;
1020 hash = jenkins_hash32((uint32_t *)&inc->inc_ie.ie_dependladdr, 4,
1021 V_tcp_fastopen_ccache.secret);
1022 hash = jenkins_hash32((uint32_t *)&inc->inc_ie.ie_dependfaddr, 4,
1024 last_word = inc->inc_fport;
1025 hash = jenkins_hash32(&last_word, 1, hash);
1026 ccb = &V_tcp_fastopen_ccache.base[hash & V_tcp_fastopen_ccache.mask];
1031 * Always returns with locked bucket.
1033 TAILQ_FOREACH(cce, &ccb->ccb_entries, cce_link)
1034 if ((!(cce->af == AF_INET6) == !(inc->inc_flags & INC_ISIPV6)) &&
1035 (cce->server_port == inc->inc_ie.ie_fport) &&
1036 (((cce->af == AF_INET) &&
1037 (cce->cce_client_ip.v4.s_addr == inc->inc_laddr.s_addr) &&
1038 (cce->cce_server_ip.v4.s_addr == inc->inc_faddr.s_addr)) ||
1039 ((cce->af == AF_INET6) &&
1040 IN6_ARE_ADDR_EQUAL(&cce->cce_client_ip.v6, &inc->inc6_laddr) &&
1041 IN6_ARE_ADDR_EQUAL(&cce->cce_server_ip.v6, &inc->inc6_faddr))))
1047 static struct tcp_fastopen_ccache_entry *
1048 tcp_fastopen_ccache_create(struct tcp_fastopen_ccache_bucket *ccb,
1049 struct in_conninfo *inc, uint16_t mss, uint8_t cookie_len, uint8_t *cookie)
1051 struct tcp_fastopen_ccache_entry *cce;
1054 * 1. Create a new entry, or
1055 * 2. Reclaim an existing entry, or
1059 CCB_LOCK_ASSERT(ccb);
1062 if (ccb->ccb_num_entries < V_tcp_fastopen_ccache.bucket_limit)
1063 cce = uma_zalloc(V_tcp_fastopen_ccache.zone, M_NOWAIT);
1067 * At bucket limit, or out of memory - reclaim last
1070 cce = TAILQ_LAST(&ccb->ccb_entries, bucket_entries);
1072 /* XXX count this event */
1076 TAILQ_REMOVE(&ccb->ccb_entries, cce, cce_link);
1078 ccb->ccb_num_entries++;
1080 TAILQ_INSERT_HEAD(&ccb->ccb_entries, cce, cce_link);
1081 cce->af = (inc->inc_flags & INC_ISIPV6) ? AF_INET6 : AF_INET;
1082 if (cce->af == AF_INET) {
1083 cce->cce_client_ip.v4 = inc->inc_laddr;
1084 cce->cce_server_ip.v4 = inc->inc_faddr;
1086 cce->cce_client_ip.v6 = inc->inc6_laddr;
1087 cce->cce_server_ip.v6 = inc->inc6_faddr;
1089 cce->server_port = inc->inc_fport;
1090 if ((cookie_len >= TCP_FASTOPEN_MIN_COOKIE_LEN) &&
1091 (cookie_len <= TCP_FASTOPEN_MAX_COOKIE_LEN) &&
1092 ((cookie_len & 0x1) == 0)) {
1093 cce->server_mss = mss;
1094 cce->cookie_len = cookie_len;
1095 memcpy(cce->cookie, cookie, cookie_len);
1096 cce->disable_time = 0;
1098 /* invalid cookie length, disable cce */
1099 cce->server_mss = 0;
1100 cce->cookie_len = 0;
1101 cce->disable_time = getsbinuptime();
1108 tcp_fastopen_ccache_bucket_trim(struct tcp_fastopen_ccache_bucket *ccb,
1111 struct tcp_fastopen_ccache_entry *cce, *cce_tmp;
1112 unsigned int entries;
1116 TAILQ_FOREACH_SAFE(cce, &ccb->ccb_entries, cce_link, cce_tmp) {
1118 if (entries > limit)
1119 tcp_fastopen_ccache_entry_drop(cce, ccb);
1121 KASSERT(ccb->ccb_num_entries <= (int)limit,
1122 ("%s: ccb->ccb_num_entries %d exceeds limit %d", __func__,
1123 ccb->ccb_num_entries, limit));
1125 KASSERT(TAILQ_EMPTY(&ccb->ccb_entries),
1126 ("%s: ccb->ccb_entries not empty", __func__));
1127 ccb->ccb_num_entries = -1; /* disable bucket */
1133 tcp_fastopen_ccache_entry_drop(struct tcp_fastopen_ccache_entry *cce,
1134 struct tcp_fastopen_ccache_bucket *ccb)
1137 CCB_LOCK_ASSERT(ccb);
1139 TAILQ_REMOVE(&ccb->ccb_entries, cce, cce_link);
1140 ccb->ccb_num_entries--;
1141 uma_zfree(V_tcp_fastopen_ccache.zone, cce);
1145 sysctl_net_inet_tcp_fastopen_ccache_list(SYSCTL_HANDLER_ARGS)
1148 struct tcp_fastopen_ccache_bucket *ccb;
1149 struct tcp_fastopen_ccache_entry *cce;
1150 sbintime_t now, duration, limit;
1151 const int linesize = 128;
1152 int i, error, num_entries;
1155 char clt_buf[INET6_ADDRSTRLEN], srv_buf[INET6_ADDRSTRLEN];
1157 char clt_buf[INET_ADDRSTRLEN], srv_buf[INET_ADDRSTRLEN];
1160 if (jailed_without_vnet(curthread->td_ucred) != 0)
1163 /* Only allow root to read the client cookie cache */
1164 if (curthread->td_ucred->cr_uid != 0)
1168 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
1169 ccb = &V_tcp_fastopen_ccache.base[i];
1171 if (ccb->ccb_num_entries > 0)
1172 num_entries += ccb->ccb_num_entries;
1175 sbuf_new(&sb, NULL, linesize * (num_entries + 1), SBUF_INCLUDENUL);
1178 "\nLocal IP address Remote IP address Port MSS"
1179 " Disabled Cookie\n");
1181 now = getsbinuptime();
1182 limit = (sbintime_t)V_tcp_fastopen_path_disable_time << 32;
1183 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
1184 ccb = &V_tcp_fastopen_ccache.base[i];
1186 TAILQ_FOREACH(cce, &ccb->ccb_entries, cce_link) {
1187 if (cce->disable_time != 0) {
1188 duration = now - cce->disable_time;
1189 if (limit >= duration)
1190 duration = limit - duration;
1196 "%-20s %-20s %5u %5u ",
1197 inet_ntop(cce->af, &cce->cce_client_ip,
1198 clt_buf, sizeof(clt_buf)),
1199 inet_ntop(cce->af, &cce->cce_server_ip,
1200 srv_buf, sizeof(srv_buf)),
1201 ntohs(cce->server_port),
1204 sbuf_printf(&sb, "%7ds ", sbintime_getsec(duration));
1206 sbuf_printf(&sb, "%8s ", "No");
1207 for (j = 0; j < cce->cookie_len; j++)
1208 sbuf_printf(&sb, "%02x", cce->cookie[j]);
1209 sbuf_putc(&sb, '\n');
1213 error = sbuf_finish(&sb);
1215 error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb));