MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tcp_fastopen_init

Function tcp_fastopen_init

freebsd/netinet/tcp_fastopen.c:385–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383
384#pragma GCC diagnostic ignored "-Waddress"
385void
386tcp_fastopen_init(void)
387{
388 unsigned int i;
389
390 V_counter_zone = uma_zcreate("tfo", sizeof(unsigned int),
391 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
392 rm_init(&V_tcp_fastopen_keylock, "tfo_keylock");
393 callout_init_rm(&V_tcp_fastopen_autokey_ctx.c,
394 &V_tcp_fastopen_keylock, 0);
395 V_tcp_fastopen_autokey_ctx.v = curvnet;
396 V_tcp_fastopen_keys.newest = TCP_FASTOPEN_MAX_KEYS - 1;
397 V_tcp_fastopen_keys.newest_psk = TCP_FASTOPEN_MAX_PSKS - 1;
398
399 /* May already be non-zero if kernel tunable was set */
400 if (V_tcp_fastopen_ccache.bucket_limit == 0)
401 V_tcp_fastopen_ccache.bucket_limit =
402 TCP_FASTOPEN_CCACHE_BUCKET_LIMIT_DEFAULT;
403
404 /* May already be non-zero if kernel tunable was set */
405 if ((V_tcp_fastopen_ccache_buckets == 0) ||
406 !powerof2(V_tcp_fastopen_ccache_buckets))
407 V_tcp_fastopen_ccache.buckets =
408 TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT;
409 else
410 V_tcp_fastopen_ccache.buckets = V_tcp_fastopen_ccache_buckets;
411
412 V_tcp_fastopen_ccache.mask = V_tcp_fastopen_ccache.buckets - 1;
413 V_tcp_fastopen_ccache.secret = arc4random();
414
415 V_tcp_fastopen_ccache.base = malloc(V_tcp_fastopen_ccache.buckets *
416 sizeof(struct tcp_fastopen_ccache_bucket), M_TCP_FASTOPEN_CCACHE,
417 M_WAITOK | M_ZERO);
418
419 for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) {
420 TAILQ_INIT(&V_tcp_fastopen_ccache.base[i].ccb_entries);
421 mtx_init(&V_tcp_fastopen_ccache.base[i].ccb_mtx, "tfo_ccache_bucket",
422 NULL, MTX_DEF);
423 if (V_tcp_fastopen_client_enable) {
424 /* enable bucket */
425 V_tcp_fastopen_ccache.base[i].ccb_num_entries = 0;
426 } else {
427 /* disable bucket */
428 V_tcp_fastopen_ccache.base[i].ccb_num_entries = -1;
429 }
430 V_tcp_fastopen_ccache.base[i].ccb_ccache = &V_tcp_fastopen_ccache;
431 }
432
433 /*
434 * Note that while the total number of entries in the cookie cache
435 * is limited by the table management logic to
436 * V_tcp_fastopen_ccache.buckets *
437 * V_tcp_fastopen_ccache.bucket_limit, the total number of items in
438 * this zone can exceed that amount by the number of CPUs in the
439 * system times the maximum number of unallocated items that can be
440 * present in each UMA per-CPU cache for this zone.
441 */
442 V_tcp_fastopen_ccache.zone = uma_zcreate("tfo_ccache_entries",

Callers 1

tcp_initFunction · 0.85

Calls 5

uma_zcreateFunction · 0.85
mallocFunction · 0.85
mtx_initFunction · 0.85
rm_initFunction · 0.50
arc4randomFunction · 0.50

Tested by

no test coverage detected