summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Härdeman2025-10-07 11:18:21 +0000
committerÁlvaro Fernández Rojas2025-10-09 06:48:13 +0000
commit9bc1b4e26e105f2c1b5bf9f593fae8f982f99241 (patch)
treed644350e17985be049936eed7bfa999c92c6a242
parentd402cdae431668f55f9d82b7072b0afa3b8090df (diff)
downloadodhcpd-9bc1b4e26e105f2c1b5bf9f593fae8f982f99241.tar.gz
odhcpd: reduce use of WITH_UBUS defines in code
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 <david@hardeman.nu> Link: https://github.com/openwrt/odhcpd/pull/270/ Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
-rw-r--r--src/config.c4
-rw-r--r--src/dhcpv4.c8
-rw-r--r--src/odhcpd.h25
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);