From bdcee7fbc930bae0428cadc9b1078a5dfa6eff72 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 27 Oct 2021 15:06:35 +0200 Subject: [PATCH] DEBUG: protocol: yell loudly during registration of invalid sock_domain 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/protocol.c b/src/protocol.c index b33e49463..dc0e41d74 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -35,12 +35,15 @@ __decl_spinlock(proto_lock); /* Registers the protocol */ 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); }