diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h index 136ad1e22..c173abff4 100644 --- a/include/haproxy/listener-t.h +++ b/include/haproxy/listener-t.h @@ -191,6 +191,16 @@ struct bind_conf { struct rx_settings settings; /* all the settings needed for the listening socket */ }; +/* Fields of a listener allocated per thread */ +struct li_per_thread { + struct { + struct mt_list list; /* list element in the QUIC accept queue */ + struct mt_list conns; /* list of QUIC connections from this listener ready to be accepted */ + } quic_accept; + + struct listener *li; /* back reference on the listener */ +}; + #define LI_F_QUIC_LISTENER 0x00000001 /* listener uses proto quic */ /* The listener will be directly referenced by the fdtab[] which holds its @@ -234,6 +244,8 @@ struct listener { struct eb32_node id; /* place in the tree of used IDs */ } conf; /* config information */ + struct li_per_thread *per_thr; /* per-thread fields */ + EXTRA_COUNTERS(extra_counters); }; diff --git a/include/haproxy/listener.h b/include/haproxy/listener.h index 39dce4cf9..5bbbad40e 100644 --- a/include/haproxy/listener.h +++ b/include/haproxy/listener.h @@ -31,6 +31,8 @@ struct proxy; struct task; +int li_init_per_thr(struct listener *li); + /* adjust the listener's state and its proxy's listener counters if needed */ void listener_set_state(struct listener *l, enum li_state st); diff --git a/src/cfgparse.c b/src/cfgparse.c index 3dfaf65cb..036a30321 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3906,8 +3906,10 @@ out_uri_auth_compat: listener->accept = session_accept_fd; #ifdef USE_QUIC /* override the accept callback for QUIC listeners. */ - if (listener->flags & LI_F_QUIC_LISTENER) + if (listener->flags & LI_F_QUIC_LISTENER) { listener->accept = quic_session_accept; + li_init_per_thr(listener); + } #endif listener->analysers |= curproxy->fe_req_ana; diff --git a/src/listener.c b/src/listener.c index cb30dd234..db505cdc6 100644 --- a/src/listener.c +++ b/src/listener.c @@ -191,6 +191,28 @@ REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init); #endif // USE_THREAD +/* Memory allocation and initialization of the per_thr field. + * Returns 0 if the field has been successfully initialized, -1 on failure. + */ +int li_init_per_thr(struct listener *li) +{ + int i; + + /* allocate per-thread elements for listener */ + li->per_thr = calloc(global.nbthread, sizeof(*li->per_thr)); + if (!li->per_thr) + return -1; + + for (i = 0; i < global.nbthread; ++i) { + MT_LIST_INIT(&li->per_thr[i].quic_accept.list); + MT_LIST_INIT(&li->per_thr[i].quic_accept.conns); + + li->per_thr[i].li = li; + } + + return 0; +} + /* helper to get listener status for stats */ enum li_status get_li_status(struct listener *l) { diff --git a/src/proxy.c b/src/proxy.c index e583e5104..b874cb1ed 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -309,6 +309,7 @@ void free_proxy(struct proxy *p) LIST_DELETE(&l->by_fe); LIST_DELETE(&l->by_bind); free(l->name); + free(l->per_thr); free(l->counters); EXTRA_COUNTERS_FREE(l->extra_counters);