From 9bc1b4e26e105f2c1b5bf9f593fae8f982f99241 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Tue, 7 Oct 2025 13:18:21 +0200 Subject: [PATCH] odhcpd: reduce use of WITH_UBUS defines in code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit By defining some dummy functions in the header file, we can avoid sprinkling WITH_UBUS defines through the code, which helps readability and also ensures that compilation errors (e.g. when a variable is renamed) is caught in builds with and without ubus. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/270/ Signed-off-by: Álvaro Fernández Rojas --- src/config.c | 4 ---- src/dhcpv4.c | 8 ++------ src/odhcpd.h | 25 ++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/config.c b/src/config.c index 46b7363..0dcef1b 100644 --- a/src/config.c +++ b/src/config.c @@ -2100,9 +2100,7 @@ void odhcpd_reload(void) vlist_flush(&leases); -#ifdef WITH_UBUS ubus_apply_network(); -#endif bool any_dhcpv6_slave = false, any_ra_slave = false, any_ndp_slave = false; @@ -2210,10 +2208,8 @@ void odhcpd_run(void) signal(SIGINT, handle_signal); signal(SIGHUP, handle_signal); -#ifdef WITH_UBUS while (ubus_init()) sleep(1); -#endif odhcpd_reload(); uloop_run(); diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 9caf35e..8b6a0ce 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -703,13 +703,11 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, syslog(LOG_INFO, "Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg), odhcpd_print_mac(req->chaddr, req->hlen), iface->name); -#ifdef WITH_UBUS if (reqmsg == DHCPV4_MSG_RELEASE) { struct in_addr ciaddr = req->ciaddr; // ensure pointer alignment ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen, - &ciaddr, a ? a->hostname : NULL, iface->ifname); + &ciaddr, a ? a->hostname : NULL, iface->ifname); } -#endif if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE) return; @@ -933,13 +931,11 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen), inet_ntoa(dest.sin_addr)); -#ifdef WITH_UBUS if (msg == DHCPV4_MSG_ACK) { struct in_addr yiaddr = reply.yiaddr; // ensure pointer alignment ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &yiaddr, - a ? a->hostname : NULL, iface->ifname); + a ? a->hostname : NULL, iface->ifname); } -#endif } /* Handler for DHCPv4 messages */ diff --git a/src/odhcpd.h b/src/odhcpd.h index 4f88727..7244274 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -519,9 +519,28 @@ int ubus_init(void); const char* ubus_get_ifname(const char *name); void ubus_apply_network(void); bool ubus_has_prefix(const char *name, const char *ifname); -void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac, const size_t mac_len, - const struct in_addr *addr, const char *name, const char *interface); -#endif +void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac, + const size_t mac_len, const struct in_addr *addr, + const char *name, const char *interface); +#else +static inline int ubus_init(void) +{ + return 0; +} + +static inline void ubus_apply_network(void) +{ + return; +} + +static inline +void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac, + const size_t mac_len, const struct in_addr *addr, + const char *name, const char *interface) +{ + return; +} +#endif /* WITH_UBUS */ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *iface, const struct sockaddr_in6 *addr, const void *data, const uint8_t *end); -- 2.30.2