Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion modules/http3/h3_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void* h3_merge_server_config(apr_pool_t* p, void* base_conf, void* new_conf)
h3_server_conf* merged = apr_pcalloc(p, sizeof(h3_server_conf));
h3_server_conf* base = (h3_server_conf*)base_conf;
h3_server_conf* new = (h3_server_conf*)new_conf;


merged->h3_enabled = new->h3_enabled != H3_FLAG_UNSET ? new->h3_enabled : base->h3_enabled;
merged->h3_port = new->h3_port ? new->h3_port : base->h3_port;
merged->h3_max_concurrent_streams = new->h3_max_concurrent_streams ? new->h3_max_concurrent_streams : base->h3_max_concurrent_streams;
merged->h3_max_connections = new->h3_max_connections ? new->h3_max_connections : base->h3_max_connections;
Expand Down Expand Up @@ -96,6 +97,17 @@ static int mpm_query(int code)
return ap_mpm_query(code, &value) == APR_SUCCESS ? value : -1;
}

static const char* set_h3_engine(cmd_parms* cmd, void* dummy H3_UNUSED, int flag)
{
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL)
return err;
h3_server_conf *conf = ap_get_module_config(cmd->server->module_config, &http3_module);
CHECK(conf);
conf->h3_enabled = flag ? H3_FLAG_ON : H3_FLAG_OFF;
return NULL;
}

static const char* set_h3_port(cmd_parms* cmd, void* dummy H3_UNUSED, const char* arg)
{
if (!arg || !*arg)
Expand Down Expand Up @@ -646,8 +658,22 @@ static int h3_sni_select_cert(SSL* ssl, void* arg)
return 1; /* no match: the listener's own certificate */
}

int h3_is_enabled(const server_rec *s)
{
server_rec *base = s ? s : ap_server_conf;
h3_server_conf *conf = ap_get_module_config(base->module_config, &http3_module);

return conf ? conf->h3_enabled != H3_FLAG_OFF : 1;
}

int h3_post_config(apr_pool_t* p, apr_pool_t* plog H3_UNUSED, apr_pool_t* ptemp, server_rec* s)
{
if (!h3_is_enabled(s)) {
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
"mod_http3: inhibited globally via H3Engine Off");
return OK;
}

CHECK(p);
CHECK(ptemp);
CHECK(s);
Expand Down Expand Up @@ -687,6 +713,10 @@ int h3_post_config(apr_pool_t* p, apr_pool_t* plog H3_UNUSED, apr_pool_t* ptemp,
e->ctx = vc->ssl_ctx;
}
vc->host_port = get_server_port(vs);
if (vc->h3_enabled == H3_FLAG_UNSET)
{
vc->h3_enabled = H3_FLAG_ON;
}
if (vc->h3_port == 0)
{
vc->h3_port = vc->host_port;
Expand Down Expand Up @@ -811,6 +841,8 @@ void* h3_merge_dir_config(apr_pool_t* p H3_UNUSED, void* base, void* add H3_UNUS
}

const command_rec h3_cmds[] = {
AP_INIT_FLAG("H3Engine", set_h3_engine, NULL, RSRC_CONF,
"Enable or inhibit mod_http3 globally (on|off)"),
AP_INIT_TAKE1("H3Port", set_h3_port, NULL, RSRC_CONF, "UDP port to listen on for QUIC/HTTP-3 (default: same as main server)"),
AP_INIT_TAKE1("H3MaxConcurrentStreams", set_h3_max_concurrent_streams, NULL, RSRC_CONF, "Maximum number of concurrent HTTP/3 streams per connection (default: 100)"),
AP_INIT_TAKE1("H3MaxConnections", set_h3_max_connections, NULL, RSRC_CONF, "Maximum concurrent QUIC/HTTP/3 connections per child process (default: 256)"),
Expand Down
13 changes: 12 additions & 1 deletion modules/http3/h3_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ int h3_hook_ssl_conn_is_ssl(conn_rec* c)

int h3_hook_fixups(request_rec* r)
{
if (!h3_is_enabled(r->server))
{
return DECLINED;
}

if (!ap_is_initial_req(r))
{
return DECLINED;
Expand Down Expand Up @@ -86,7 +91,7 @@ int h3_hook_fixups(request_rec* r)
{
return DECLINED;
}

if (conf->h3_alt_svc == H3_FLAG_OFF)
{
return DECLINED;
Expand All @@ -105,6 +110,9 @@ int h3_hook_fixups(request_rec* r)

int h3_hook_post_read_request(request_rec* r)
{
if (!h3_is_enabled(r->server))
return DECLINED;

CHECK(r);
if (!IS_H3_REQUEST(r))
{
Expand Down Expand Up @@ -161,6 +169,9 @@ int h3_hook_http_create_request(request_rec* r)

int h3_status_handler(request_rec* r)
{
if (!h3_is_enabled(r->server))
return DECLINED;

if (strcmp(r->handler, "http3-status"))
{
return DECLINED;
Expand Down
9 changes: 9 additions & 0 deletions modules/http3/h3_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ static apr_status_t child_pool_cleanup(void* data H3_UNUSED)

void h3_child_init(apr_pool_t* pchild, server_rec* s)
{
if (!h3_is_enabled(s))
return;

server_rec* vhost = NULL;
h3_server_conf* conf = find_h3_server(s, &vhost);
apr_pool_t* pool = NULL;
Expand Down Expand Up @@ -346,6 +349,12 @@ void h3_server_post_config(server_rec* s)
{
return;
}

if (!h3_is_enabled(s))
{
return;
}

int ok = apr_pool_create(&ps->pool, s->process->pool) == APR_SUCCESS;
if (ok)
{
Expand Down
87 changes: 87 additions & 0 deletions modules/http3/h3_socket_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,93 @@
#define SO_ATTACH_REUSEPORT_EBPF 52
#endif

/*
* Définition portable de __NR_bpf pour toutes les architectures Linux.
* Utile lors de la compilation avec des en-têtes glibc/kernel anciens.
*/
#ifndef __NR_bpf

/* --- x86 (32-bit, x86_64 et x32 ABI) --- */
# if defined(__x86_64__)
# if defined(__ILP32__)
/* ABI x32 : __X32_SYSCALL_BIT (0x40000000) + 321 */
# define __NR_bpf 1073742145
# else
# define __NR_bpf 321
# endif
# elif defined(__i386__)
# define __NR_bpf 357

/* --- Architectures utilisant asm-generic/unistd.h (280) --- */
# elif defined(__aarch64__) || defined(__riscv) || defined(__loongarch__) || \
defined(__arc__) || defined(__csky__) || defined(__hexagon__) || \
defined(__nios2__) || defined(__openrisc__) || defined(__or1k__)
# define __NR_bpf 280

/* --- ARM 32-bit (EABI) --- */
# elif defined(__arm__)
# define __NR_bpf 386

/* --- PowerPC (32-bit et 64-bit, Big et Little Endian) --- */
# elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__)
# define __NR_bpf 361

/* --- IBM Z / s390 (31-bit et 64-bit) --- */
# elif defined(__s390__) || defined(__s390x__)
# define __NR_bpf 351

/* --- MIPS (ABIs o32, n64 et n32) --- */
# elif defined(__mips__)
# if defined(_MIPS_SIM)
# if _MIPS_SIM == _ABIO32
# define __NR_bpf 4355 /* 4000 + 355 */
# elif _MIPS_SIM == _ABI64
# define __NR_bpf 5315 /* 5000 + 315 */
# elif _MIPS_SIM == _ABIN32
# define __NR_bpf 6319 /* 6000 + 319 */
# else
# error "ABI MIPS non reconnue pour __NR_bpf"
# endif
# else
# error "_MIPS_SIM non défini pour déterminer __NR_bpf"
# endif

/* --- SPARC (32-bit et 64-bit) --- */
# elif defined(__sparc__)
# define __NR_bpf 349

/* --- Autres architectures actives --- */
# elif defined(__alpha__)
# define __NR_bpf 515
# elif defined(__hppa__)
# define __NR_bpf 341
# elif defined(__m68k__)
# define __NR_bpf 354
# elif defined(__microblaze__)
# define __NR_bpf 387
# elif defined(__sh__)
# define __NR_bpf 375
# elif defined(__xtensa__)
# define __NR_bpf 340

/* --- Architectures historiques (retirées des noyaux récents) --- */
# elif defined(__ia64__)
# define __NR_bpf 1341 /* Retiré dans Linux 6.7 */
# elif defined(__nds32__)
# define __NR_bpf 280 /* Retiré dans Linux 5.18 */
# elif defined(__bfin__) || defined(__BFIN__)
# define __NR_bpf 391 /* Blackfin, retiré dans Linux 4.17 */
# elif defined(__cris__)
# define __NR_bpf 358 /* Retiré dans Linux 4.17 */
# elif defined(__metag__) || defined(__tile__)
# define __NR_bpf 280 /* MetaG / TILE-Gx / TILEPro, retirés dans 4.17 */

# else
# error "__NR_bpf n'est pas défini pour cette architecture cible"
# endif

#endif /* !__NR_bpf */

struct insn
{
uint8_t code;
Expand Down
9 changes: 9 additions & 0 deletions modules/http3/include/h3_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct h3_server_conf
/** QUIC TLS context, built from mod_ssl's certificate when the host lists h3 in Protocols. */
struct ssl_ctx_st* ssl_ctx;

h3_tri_flag h3_enabled;
apr_port_t h3_port;
apr_uint32_t h3_max_concurrent_streams;
apr_uint32_t h3_max_connections;
Expand Down Expand Up @@ -137,4 +138,12 @@ int h3_ssl_add_cert_files(server_rec* s, apr_pool_t* p, apr_array_header_t* cert
*/
int h3_post_config(apr_pool_t* p, apr_pool_t* plog, apr_pool_t* ptemp, server_rec* s);

/**
* Test if http3 is enabled.
* @param s The server_rec.
* @return 1 if HTTP3 is enabled, else 0.
*/

int h3_is_enabled(const server_rec *s);

#endif /* H3_CONFIG_H */