]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: peers: Replace hard-coded values by macros.
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 24 May 2019 12:32:27 +0000 (14:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 Jun 2019 06:33:34 +0000 (08:33 +0200)
All the peer stick-table messages are made of a 2-byte header (PEER_MSG_HEADER_LEN)
followed by the encoded length of the remaining data wich is harcoded as 5 (in bytes)
for the maximum (PEER_MSG_ENCODED_LENGTH_MAXLEN). With such a length we can encode
a maximum length which equals to (1 << 32) - 1, which is from far enough.

This patches replaces both these values by macros where applicable.

src/peers.c

index 2a9fde1cca0140a3a6aefbe7a0b581de46e175ce..9733e1bc0bb9a8a2ddf702c48f1491ecb7e0520a 100644 (file)
@@ -167,6 +167,11 @@ struct peer_prep_params {
 #define PEER_MSG_STKT_UPDATE_TIMED     0x85
 #define PEER_MSG_STKT_INCUPDATE_TIMED  0x86
 
+/* The maximum length of an encoded data length. */
+#define PEER_MSG_ENC_LENGTH_MAXLEN    5
+
+#define PEER_MSG_HEADER_LEN               2
+
 /**********************************/
 /* Peer Session IO handler states */
 /**********************************/
@@ -516,7 +521,7 @@ static int peer_prepare_switchmsg(char *msg, size_t size, struct peer_prep_param
        struct shared_table *st;
 
        st = params->swtch.shared_table;
-       cursor = datamsg = msg + 2 + 5;
+       cursor = datamsg = msg + PEER_MSG_HEADER_LEN + PEER_MSG_ENC_LENGTH_MAXLEN;
 
        /* Encode data */
 
@@ -596,7 +601,7 @@ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params *
        uint32_t netinteger;
        struct shared_table *st;
 
-       cursor = datamsg = msg + 2 + 5;
+       cursor = datamsg = msg + PEER_MSG_HEADER_LEN + PEER_MSG_ENC_LENGTH_MAXLEN;
 
        st = p->ack.shared_table;
        intencode(st->remote_id, &cursor);