]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: Add a ref to peers section in the peer structure
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 May 2022 12:47:52 +0000 (14:47 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:22 +0000 (16:13 +0200)
This change is required to handle asynchrone init of the appctx. It is now
possible to directly get the peers section associated to a peer.

include/haproxy/peers-t.h
src/cfgparse.c
src/peers.c

index 6d2a9688a9978024370002121b96f7a12cfab243..6a2e749258f85ced969bde468cb2b7f3c13f1dd2 100644 (file)
@@ -80,6 +80,7 @@ struct peer {
        struct shared_table *tables;
        struct server *srv;
        struct dcache *dcache;        /* dictionary cache */
+       struct peers *peers;          /* associated peer section */
        struct peer *next;            /* next peer in the list */
 };
 
index 32b4cb3663f1e74674c6379be0542f6fd3b4454d..b1ec46f2facbf42c6a95471fa347f5decaf22ed8 100644 (file)
@@ -650,6 +650,7 @@ static struct peer *cfg_peers_add_peer(struct peers *peers,
 
        /* the peers are linked backwards first */
        peers->count++;
+       p->peers = peers;
        p->next = peers->remote;
        peers->remote = p;
        p->conf.file = strdup(file);
index 07520a4b42f2f53e81c49300208a08f5a75538bc..267a68d2102756dc030835b0079ed2145e3883ac 100644 (file)
@@ -443,11 +443,8 @@ static void peers_trace(enum trace_level level, uint64_t mask,
                        const struct peer *peer = a2;
                        struct peers *peers = NULL;
 
-                       if (peer->appctx) {
-                               struct stream *s = appctx_strm(peer->appctx);
-
-                               peers = strm_fe(s)->parent;
-                       }
+                       if (peer->appctx)
+                               peers = peer->peers;
 
                        if (peers)
                                chunk_appendf(&trace_buf, " %s", peers->local->id);
@@ -1037,16 +1034,9 @@ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params *
  */
 void __peer_session_deinit(struct peer *peer)
 {
-       struct stream *s;
-       struct peers *peers;
-
-       if (!peer->appctx)
-               return;
-
-       s = appctx_strm(peer->appctx);
+       struct peers *peers = peer->peers;
 
-       peers = strm_fe(s)->parent;
-       if (!peers)
+       if (!peers || !peer->appctx)
                return;
 
        if (peer->appctx->st0 == PEER_SESS_ST_WAITMSG)
@@ -2373,8 +2363,7 @@ static inline int peer_recv_msg(struct appctx *appctx, char *msg_head, size_t ms
 static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *peer, unsigned char *msg_head,
                                          char **msg_cur, char *msg_end, int msg_len, int totl)
 {
-       struct stream *s = appctx_strm(appctx);
-       struct peers *peers = strm_fe(s)->parent;
+       struct peers *peers = peer->peers;
 
        if (msg_head[0] == PEER_MSG_CLASS_CONTROL) {
                if (msg_head[1] == PEER_MSG_CTRL_RESYNCREQ) {