odhcpd: remove confusing #defines
authorDavid Härdeman <[email protected]>
Tue, 30 Sep 2025 17:45:24 +0000 (19:45 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Wed, 1 Oct 2025 21:04:57 +0000 (23:04 +0200)
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 <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/261
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv6-ia.c
src/odhcpd.h
src/ubus.c

index b4c6c9536d16b2c7b50eeb87b925485a82569941..8cc95156f939502834faa5c346f7df1226760a8a 100644 (file)
@@ -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);
index 5b7b49f24ffe45ea5db3b6dc36c6e2ed1b579dca..6a1d48b5ed69aec19676d2557417f4f60140cb7d 100644 (file)
@@ -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[];
index 36d7dbb3229650e5e1717c28e978ce71ccecacd9..00fd171bdd11ded54c0fbd3331f0936d627841f1 100644 (file)
@@ -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