From 7e78caac4eae5dfabc5f2128cac64d37512b0d81 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Fri, 3 Oct 2025 14:59:55 +0200 Subject: [PATCH] dhcpv6: change dhcpv6 message type check in relay MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When compiled, the switch instruction jump table O(1) is more efficient than multiple logical comparisons in the if block (4-5 checks). Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcpd/pull/279 Signed-off-by: Álvaro Fernández Rojas --- src/dhcpv6.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index b92790e..abb0f36 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -895,11 +895,29 @@ static void relay_client_request(struct sockaddr_in6 *source, struct odhcpd_ipaddr *ip; struct sockaddr_in6 s; - if (h->msg_type == DHCPV6_MSG_RELAY_REPL || - h->msg_type == DHCPV6_MSG_RECONFIGURE || - h->msg_type == DHCPV6_MSG_REPLY || - h->msg_type == DHCPV6_MSG_ADVERTISE) - return; /* Invalid message types for client */ + switch (h->msg_type) { + /* Valid message types from clients */ + case DHCPV6_MSG_SOLICIT: + case DHCPV6_MSG_REQUEST: + case DHCPV6_MSG_CONFIRM: + case DHCPV6_MSG_RENEW: + case DHCPV6_MSG_REBIND: + case DHCPV6_MSG_RELEASE: + case DHCPV6_MSG_DECLINE: + case DHCPV6_MSG_INFORMATION_REQUEST: + case DHCPV6_MSG_RELAY_FORW: + case DHCPV6_MSG_DHCPV4_QUERY: + break; + /* Invalid message types from clients i.e. server messages */ + case DHCPV6_MSG_ADVERTISE: + case DHCPV6_MSG_REPLY: + case DHCPV6_MSG_RECONFIGURE: + case DHCPV6_MSG_RELAY_REPL: + case DHCPV6_MSG_DHCPV4_RESPONSE: + return; + default: + break; + } debug("Got a DHCPv6-request on %s", iface->name); -- 2.30.2