Path: blob/main/crypto/openssl/include/internal/bio_tfo.h
105310 views
/*1* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/*10* Contains definitions for simplifying the use of TCP Fast Open11* (RFC7413) in OpenSSL socket BIOs.12*/1314/* If a supported OS is added here, update test/bio_tfo_test.c */15#if defined(TCP_FASTOPEN) && !defined(OPENSSL_NO_TFO)1617#if defined(OPENSSL_SYS_MACOSX) || defined(__FreeBSD__)18#include <sys/sysctl.h>19#endif2021/*22* OSSL_TFO_SYSCTL is used to determine if TFO is supported by23* this kernel, and if supported, if it is enabled. This is more of24* a problem on FreeBSD 10.3 ~ 11.4, where TCP_FASTOPEN was defined,25* but not enabled by default in the kernel, and only for the server.26* Linux does not have sysctlbyname(), and the closest equivalent27* is to go into the /proc filesystem, but I'm not sure it's28* worthwhile.29*30* On MacOS and Linux:31* These operating systems use a single parameter to control TFO.32* The OSSL_TFO_CLIENT_FLAG and OSSL_TFO_SERVER_FLAGS are used to33* determine if TFO is enabled for the client and server respectively.34*35* OSSL_TFO_CLIENT_FLAG = 1 = client TFO enabled36* OSSL_TFO_SERVER_FLAG = 2 = server TFO enabled37*38* Such that:39* 0 = TFO disabled40* 3 = server and client TFO enabled41*42* macOS 10.14 and later support TFO.43* Linux kernel 3.6 added support for client TFO.44* Linux kernel 3.7 added support for server TFO.45* Linux kernel 3.13 enabled TFO by default.46* Linux kernel 4.11 added the TCP_FASTOPEN_CONNECT option.47*48* On FreeBSD:49* FreeBSD 10.3 ~ 11.4 uses a single sysctl for server enable.50* FreeBSD 12.0 and later uses separate sysctls for server and51* client enable.52*53* Some options are purposely NOT defined per-platform54*55* OSSL_TFO_SYSCTL56* Defined as a sysctlbyname() option to determine if57* TFO is enabled in the kernel (macOS, FreeBSD)58*59* OSSL_TFO_SERVER_SOCKOPT60* Defined to indicate the socket option used to enable61* TFO on a server socket (all)62*63* OSSL_TFO_SERVER_SOCKOPT_VALUE64* Value to be used with OSSL_TFO_SERVER_SOCKOPT65*66* OSSL_TFO_CONNECTX67* Use the connectx() function to make a client connection68* (macOS)69*70* OSSL_TFO_CLIENT_SOCKOPT71* Defined to indicate the socket option used to enable72* TFO on a client socket (FreeBSD, Linux 4.14 and later)73*74* OSSL_TFO_SENDTO75* Defined to indicate the sendto() message type to76* be used to initiate a TFO connection (FreeBSD,77* Linux pre-4.14)78*79* OSSL_TFO_DO_NOT_CONNECT80* Defined to skip calling connect() when creating a81* client socket (macOS, FreeBSD, Linux pre-4.14)82*/8384#if defined(OPENSSL_SYS_WINDOWS)85/*86* NO WINDOWS SUPPORT87*88* But this is what would be used on the server:89*90* define OSSL_TFO_SERVER_SOCKOPT TCP_FASTOPEN91* define OSSL_TFO_SERVER_SOCKOPT_VALUE 192*93* Still have to figure out client support94*/95#undef TCP_FASTOPEN96#endif9798/* NO VMS SUPPORT */99#if defined(OPENSSL_SYS_VMS)100#undef TCP_FASTOPEN101#endif102103#if defined(OPENSSL_SYS_MACOSX)104#define OSSL_TFO_SYSCTL "net.inet.tcp.fastopen"105#define OSSL_TFO_SERVER_SOCKOPT TCP_FASTOPEN106#define OSSL_TFO_SERVER_SOCKOPT_VALUE 1107#define OSSL_TFO_CONNECTX 1108#define OSSL_TFO_DO_NOT_CONNECT 1109#define OSSL_TFO_CLIENT_FLAG 1110#define OSSL_TFO_SERVER_FLAG 2111#endif112113#if defined(__FreeBSD__)114#if defined(TCP_FASTOPEN_PSK_LEN)115/* As of 12.0 these are the SYSCTLs */116#define OSSL_TFO_SYSCTL_SERVER "net.inet.tcp.fastopen.server_enable"117#define OSSL_TFO_SYSCTL_CLIENT "net.inet.tcp.fastopen.client_enable"118#define OSSL_TFO_SERVER_SOCKOPT TCP_FASTOPEN119#define OSSL_TFO_SERVER_SOCKOPT_VALUE MAX_LISTEN120#define OSSL_TFO_CLIENT_SOCKOPT TCP_FASTOPEN121#define OSSL_TFO_DO_NOT_CONNECT 1122#define OSSL_TFO_SENDTO 0123/* These are the same because the sysctl are client/server-specific */124#define OSSL_TFO_CLIENT_FLAG 1125#define OSSL_TFO_SERVER_FLAG 1126#else127/* 10.3 through 11.4 SYSCTL - ONLY SERVER SUPPORT */128#define OSSL_TFO_SYSCTL "net.inet.tcp.fastopen.enabled"129#define OSSL_TFO_SERVER_SOCKOPT TCP_FASTOPEN130#define OSSL_TFO_SERVER_SOCKOPT_VALUE MAX_LISTEN131#define OSSL_TFO_SERVER_FLAG 1132#endif133#endif134135#if defined(OPENSSL_SYS_LINUX)136/* OSSL_TFO_PROC not used, but of interest */137#define OSSL_TFO_PROC "/proc/sys/net/ipv4/tcp_fastopen"138#define OSSL_TFO_SERVER_SOCKOPT TCP_FASTOPEN139#define OSSL_TFO_SERVER_SOCKOPT_VALUE MAX_LISTEN140#if defined(TCP_FASTOPEN_CONNECT)141#define OSSL_TFO_CLIENT_SOCKOPT TCP_FASTOPEN_CONNECT142#else143#define OSSL_TFO_SENDTO MSG_FASTOPEN144#define OSSL_TFO_DO_NOT_CONNECT 1145#endif146#define OSSL_TFO_CLIENT_FLAG 1147#define OSSL_TFO_SERVER_FLAG 2148#endif149150#endif151152153