]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: protocol: yell loudly during registration of invalid sock_domain
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 13:06:35 +0000 (15:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 13:50:49 +0000 (15:50 +0200)
The test on the sock_domain is a bit useless because the protocols are
registered at boot time, and the test silently fails and returns no
error. Use a BUG_ON() instead to make sure to catch such bugs in the
code if any.

src/protocol.c

index b33e494633cc994c0ef3734a5d3aa1b72afc6911..dc0e41d74acead3529ba045e845b3d3e9483f5d7 100644 (file)
@@ -35,12 +35,15 @@ __decl_spinlock(proto_lock);
 /* Registers the protocol <proto> */
 void protocol_register(struct protocol *proto)
 {
+       int sock_domain = proto->fam->sock_domain;
+
+       BUG_ON(sock_domain < 0 || sock_domain >= AF_CUST_MAX);
+
        HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
        LIST_APPEND(&protocols, &proto->list);
-       if (proto->fam->sock_domain >= 0 && proto->fam->sock_domain < AF_CUST_MAX)
-               __protocol_by_family[proto->fam->sock_domain]
-                       [proto->sock_type == SOCK_DGRAM]
-                       [proto->ctrl_type == SOCK_DGRAM] = proto;
+       __protocol_by_family[sock_domain]
+                           [proto->sock_type == SOCK_DGRAM]
+                           [proto->ctrl_type == SOCK_DGRAM] = proto;
        HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
 }