From 7328bfe40f810c8ca78c86ed4811eb742a9d3761 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Tue, 30 Sep 2025 19:45:24 +0200 Subject: [PATCH] odhcpd: remove confusing #defines MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Right now, odhcpd.h contains lines like "#define hwaddr mac", which is a great footgun when hacking on odhcpd (like when creating a function with a local variable named "hwaddr" and later getting compiler errors talking about how "mac" has the wrong type...in a function which has no variable named "mac"). So, remove these definitions. I'm not sure the chosen variable names are the most descriptive, but I erred on the side of caution and picked the alternative that required the least amount of changes. We can always change the names of the variables later. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/261 Signed-off-by: Álvaro Fernández Rojas --- src/dhcpv6-ia.c | 40 ++++++++++++++++++++-------------------- src/odhcpd.h | 13 +++++-------- src/ubus.c | 2 +- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index b4c6c95..8cc9515 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -211,7 +211,7 @@ static void dhcpv6_ia_free_assignment(struct dhcp_assignment *a) if ((a->flags & OAF_BOUND) && (a->flags & OAF_DHCPV6_PD)) apply_lease(a, false); - if (a->reconf_cnt) + if (a->fr_cnt) stop_reconf(a); free(a->managed); @@ -661,8 +661,8 @@ static void managed_handle_pd_data(struct ustream *s, _unused int bytes_new) end[-1] = 0; c->managed_size = 0; - if (c->accept_reconf) - c->reconf_cnt = 1; + if (c->accept_fr_nonce) + c->fr_cnt = 1; char *saveptr; for (char *line = strtok_r(data, "\n", &saveptr); line; line = strtok_r(NULL, "\n", &saveptr)) { @@ -725,8 +725,8 @@ static void managed_handle_pd_done(struct ustream *s) c->managed_size = 0; - if (c->accept_reconf) - c->reconf_cnt = 1; + if (c->accept_fr_nonce) + c->fr_cnt = 1; } static bool assign_pd(struct interface *iface, struct dhcp_assignment *assign) @@ -929,7 +929,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info) else if (c->flags & OAF_BOUND) apply_lease(c, true); - if (c->accept_reconf && c->reconf_cnt == 0) { + if (c->accept_fr_nonce && c->fr_cnt == 0) { struct dhcp_assignment *a; start_reconf(c); @@ -938,7 +938,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info) list_for_each_entry(a, &iface->ia_assignments, head) if (a != c && a->clid_len == c->clid_len && !memcmp(a->clid_data, c->clid_data, a->clid_len)) - a->reconf_cnt = INT_MAX; + a->fr_cnt = INT_MAX; } } @@ -954,32 +954,32 @@ static void handle_addrlist_change(struct netevent_handler_info *info) static void reconf_timeout_cb(struct uloop_timeout *event) { - struct dhcp_assignment *a = container_of(event, struct dhcp_assignment, reconf_timer); + struct dhcp_assignment *a = container_of(event, struct dhcp_assignment, fr_timer); - if (a->reconf_cnt > 0 && a->reconf_cnt < DHCPV6_REC_MAX_RC) { + if (a->fr_cnt > 0 && a->fr_cnt < DHCPV6_REC_MAX_RC) { send_reconf(a); - uloop_timeout_set(&a->reconf_timer, - DHCPV6_REC_TIMEOUT << a->reconf_cnt); - a->reconf_cnt++; + uloop_timeout_set(&a->fr_timer, + DHCPV6_REC_TIMEOUT << a->fr_cnt); + a->fr_cnt++; } else stop_reconf(a); } static void start_reconf(struct dhcp_assignment *a) { - uloop_timeout_set(&a->reconf_timer, - DHCPV6_REC_TIMEOUT << a->reconf_cnt); - a->reconf_timer.cb = reconf_timeout_cb; - a->reconf_cnt++; + uloop_timeout_set(&a->fr_timer, + DHCPV6_REC_TIMEOUT << a->fr_cnt); + a->fr_timer.cb = reconf_timeout_cb; + a->fr_cnt++; send_reconf(a); } static void stop_reconf(struct dhcp_assignment *a) { - uloop_timeout_cancel(&a->reconf_timer); - a->reconf_cnt = 0; - a->reconf_timer.cb = NULL; + uloop_timeout_cancel(&a->fr_timer); + a->fr_cnt = 0; + a->fr_timer.cb = NULL; } static void valid_until_cb(struct uloop_timeout *event) @@ -1647,7 +1647,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac a->flags |= OAF_BROKEN_HOSTNAME; } } - a->accept_reconf = accept_reconf; + a->accept_fr_nonce = accept_reconf; a->flags &= ~OAF_TENTATIVE; a->flags |= OAF_BOUND; apply_lease(a, true); diff --git a/src/odhcpd.h b/src/odhcpd.h index 5b7b49f..6a1d48b 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -218,12 +218,10 @@ struct dhcp_assignment { time_t valid_until; time_t preferred_until; -#define fr_timer reconf_timer - struct uloop_timeout reconf_timer; -#define accept_fr_nonce accept_reconf - bool accept_reconf; -#define fr_cnt reconf_cnt - int reconf_cnt; + // ForceRenew - RFC6704 §3.1.2 (IPv4), RFC8415 (IPv6), §20.4, §21.11 + struct uloop_timeout fr_timer; + bool accept_fr_nonce; + int fr_cnt; uint8_t key[16]; struct odhcpd_ref_ip *fr_ip; @@ -245,8 +243,7 @@ struct dhcp_assignment { uint8_t *reqopts; size_t reqopts_len; -#define hwaddr mac - uint8_t mac[6]; + uint8_t hwaddr[6]; uint16_t clid_len; uint8_t clid_data[]; diff --git a/src/ubus.c b/src/ubus.c index 36d7dbb..00fd171 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -143,7 +143,7 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct blobmsg_add_u32(&b, "iaid", ntohl(a->iaid)); blobmsg_add_string(&b, "hostname", (a->hostname) ? a->hostname : ""); - blobmsg_add_u8(&b, "accept-reconf", a->accept_reconf); + blobmsg_add_u8(&b, "accept-reconf", a->accept_fr_nonce); if (a->flags & OAF_DHCPV6_NA) blobmsg_add_u64(&b, "assigned", a->assigned_host_id); else -- 2.30.2