]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: define per-thr struct
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 25 Jan 2022 15:21:47 +0000 (16:21 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 26 Jan 2022 15:13:54 +0000 (16:13 +0100)
Create a new structure li_per_thread. This is uses as an array in the
listener structure, with an entry allocated per thread. The new function
li_init_per_thr is responsible of the allocation.

For now, li_per_thread contains fields only useful for QUIC listeners.
As such, it is only allocated for QUIC listeners.

include/haproxy/listener-t.h
include/haproxy/listener.h
src/cfgparse.c
src/listener.c
src/proxy.c

index 136ad1e22605530cc0e40b225e0fbd2efd189012..c173abff436ba57a559706183a3253f6dccf5ae0 100644 (file)
@@ -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);
 };
 
index 39dce4cf9f6d6f567df2be013e57816454d0f3a5..5bbbad40e3387708e5a07a9e2763dab0268f5818 100644 (file)
@@ -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);
 
index 3dfaf65cb568b93a49ab86ca4f2411fd5587d3c7..036a30321798ed01c5e9a072bafe4b09155012ac 100644 (file)
@@ -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;
index cb30dd23444a8bf53ae657a3d89f713f308a7c2f..db505cdc6943876a9e23007b483ffb5657a08cf6 100644 (file)
@@ -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)
 {
index e583e5104bac9a2d38602d474ad4cb4d64402bfb..b874cb1eddefdefe5a22b655c39dadb1d2515f4e 100644 (file)
@@ -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);