summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Härdeman2025-11-27 17:02:11 +0000
committerÁlvaro Fernández Rojas2025-11-30 16:00:25 +0000
commitd0e6bc4d1cc2d2ed2373ad62bfda1b749c5edea1 (patch)
treeef49114132cc71f2afb1d36ecc54306c402b88cb
parent9ae348c07ce058dfc125a7036bb662a76d93e64f (diff)
odhcpd: remove OAF_BOUND
Replace the OAF_BOUND flag with a simple boolean. Signed-off-by: David Härdeman <david@hardeman.nu> Link: https://github.com/openwrt/odhcpd/pull/331 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
-rw-r--r--src/dhcpv4.c12
-rw-r--r--src/dhcpv6-ia.c22
-rw-r--r--src/odhcpd.h8
-rw-r--r--src/statefiles.c8
-rw-r--r--src/ubus.c4
5 files changed, 27 insertions, 27 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index ab1a762..5073d97 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -568,7 +568,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
lease = NULL;
}
- if (lease && (lease->flags & OAF_BOUND) && lease->fr_ip) {
+ if (lease && lease->bound && lease->fr_ip) {
*fr_serverid = lease->fr_ip->addr.addr.in.s_addr;
dhcpv4_fr_stop(lease);
}
@@ -587,7 +587,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
if (!lease)
return NULL;
- lease->flags &= ~OAF_BOUND;
+ lease->bound = false;
if (!lease->lease_cfg || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) {
memset(lease->hwaddr, 0, sizeof(lease->hwaddr));
@@ -655,7 +655,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
*req_leasetime = max_leasetime;
if (req_msg == DHCPV4_MSG_DISCOVER) {
- lease->flags &= ~OAF_BOUND;
+ lease->bound = false;
*reply_incl_fr = req_accept_fr;
lease->valid_until = now;
break;
@@ -672,14 +672,14 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
}
*reply_incl_fr = false;
- if (!(lease->flags & OAF_BOUND)) {
+ if (!lease->bound) {
/* This is the client's first request for the address */
if (req_accept_fr) {
lease->accept_fr_nonce = true;
*reply_incl_fr = true;
odhcpd_urandom(lease->key, sizeof(lease->key));
}
- lease->flags |= OAF_BOUND;
+ lease->bound = true;
}
if (*req_leasetime == UINT32_MAX)
@@ -1601,7 +1601,7 @@ static void dhcpv4_addrlist_change(struct interface *iface)
}
avl_for_each_element(&iface->dhcpv4_leases, lease, iface_avl) {
- if ((lease->flags & OAF_BOUND) && lease->fr_ip && !lease->fr_cnt) {
+ if (lease->bound && lease->fr_ip && !lease->fr_cnt) {
if (lease->accept_fr_nonce || iface->dhcpv4_forcereconf)
dhcpv4_fr_rand_delay(lease);
else
diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 6f3852d..f227ad6 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -63,7 +63,7 @@ void dhcpv6_free_lease(struct dhcpv6_lease *a)
list_del(&a->head);
list_del(&a->lease_cfg_list);
- if ((a->flags & OAF_BOUND) && (a->flags & OAF_DHCPV6_PD))
+ if (a->bound && (a->flags & OAF_DHCPV6_PD))
apply_lease(a, false);
if (a->fr_cnt)
@@ -349,7 +349,7 @@ static bool assign_pd(struct interface *iface, struct dhcpv6_lease *assign)
if (assign->assigned_subnet_id >= current && assign->assigned_subnet_id + asize < c->assigned_subnet_id) {
list_add_tail(&assign->head, &c->head);
- if (assign->flags & OAF_BOUND)
+ if (assign->bound)
apply_lease(assign, true);
return true;
@@ -371,7 +371,7 @@ static bool assign_pd(struct interface *iface, struct dhcpv6_lease *assign)
assign->assigned_subnet_id = current;
list_add_tail(&assign->head, &c->head);
- if (assign->flags & OAF_BOUND)
+ if (assign->bound)
apply_lease(assign, true);
return true;
@@ -466,7 +466,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
list_for_each_entry(c, &iface->ia_assignments, head) {
if ((c->flags & OAF_DHCPV6_PD) && !(iface->ra_flags & ND_RA_FLAG_MANAGED)
- && (c->flags & OAF_BOUND))
+ && (c->bound))
__apply_lease(c, info->addrs_old.addrs,
info->addrs_old.len, false);
}
@@ -481,7 +481,7 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
if (c->assigned_subnet_id >= border->assigned_subnet_id)
list_move(&c->head, &reassign);
- else if (c->flags & OAF_BOUND)
+ else if (c->bound)
apply_lease(c, true);
if (c->accept_fr_nonce && c->fr_cnt == 0) {
@@ -1117,7 +1117,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
a = c;
/* Reset state */
- if (a->flags & OAF_BOUND)
+ if (a->bound)
apply_lease(a, false);
stop_reconf(a);
@@ -1228,7 +1228,7 @@ proceed:
/* Was only a solicitation: mark binding for removal in 60 seconds */
if (assigned && hdr->msg_type == DHCPV6_MSG_SOLICIT && !rapid_commit) {
- a->flags &= ~OAF_BOUND;
+ a->bound = false;
a->valid_until = now + 60;
} else if (assigned &&
@@ -1245,7 +1245,7 @@ proceed:
}
}
a->accept_fr_nonce = accept_reconf;
- a->flags |= OAF_BOUND;
+ a->bound = true;
apply_lease(a, true);
} else if (!assigned) {
/* Cleanup failed assignment */
@@ -1263,13 +1263,13 @@ proceed:
hdr->msg_type == DHCPV6_MSG_REBIND) {
ia_response_len = build_ia(buf, buflen, status, ia, a, iface, false);
if (a) {
- a->flags |= OAF_BOUND;
+ a->bound = true;
apply_lease(a, true);
}
} else if (hdr->msg_type == DHCPV6_MSG_RELEASE) {
a->valid_until = now - 1;
} else if ((a->flags & OAF_DHCPV6_NA) && hdr->msg_type == DHCPV6_MSG_DECLINE) {
- a->flags &= ~OAF_BOUND;
+ a->bound = false;
if (!a->lease_cfg || a->lease_cfg->hostid != a->assigned_host_id) {
memset(a->duid, 0, a->duid_len);
@@ -1283,7 +1283,7 @@ proceed:
break;
}
- if (!ia_addr_present || !a || !(a->flags & OAF_BOUND)) {
+ if (!ia_addr_present || !a || !a->bound) {
response_len = 0;
goto out;
}
diff --git a/src/odhcpd.h b/src/odhcpd.h
index 3fb3acc..1ce2452 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -190,9 +190,8 @@ enum odhcpd_mode {
enum odhcpd_assignment_flags {
- OAF_BOUND = (1 << 0),
- OAF_DHCPV6_NA = (1 << 1),
- OAF_DHCPV6_PD = (1 << 2),
+ OAF_DHCPV6_NA = (1 << 0),
+ OAF_DHCPV6_PD = (1 << 1),
};
/* 2-byte type + 128-byte DUID, RFC8415, §11.1 */
@@ -254,7 +253,7 @@ struct dhcpv4_lease {
struct lease_cfg *lease_cfg; // host lease cfg, nullable
struct in_addr ipv4; // client IPv4 address
- unsigned int flags; // OAF_*
+ bool bound; // the lease has been accepted by the client
time_t valid_until; // CLOCK_MONOTONIC time, 0 = inf
char *hostname; // client hostname
bool hostname_valid; // is the hostname one or more valid DNS labels?
@@ -298,6 +297,7 @@ struct dhcpv6_lease {
uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
unsigned int flags;
+ bool bound; // the lease has been accepted by the client
uint32_t leasetime;
char *hostname;
bool hostname_valid; // is the hostname one or more valid DNS labels?
diff --git a/src/statefiles.c b/src/statefiles.c
index 20664f6..d0ccef5 100644
--- a/src/statefiles.c
+++ b/src/statefiles.c
@@ -122,7 +122,7 @@ static void statefiles_write_hosts(time_t now)
struct dhcpv6_lease *lease;
list_for_each_entry(lease, &ctxt.iface->ia_assignments, head) {
- if (!(lease->flags & OAF_BOUND))
+ if (!lease->bound)
continue;
if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -137,7 +137,7 @@ static void statefiles_write_hosts(time_t now)
struct dhcpv4_lease *lease;
avl_for_each_element(&ctxt.iface->dhcpv4_leases, lease, iface_avl) {
- if (!(lease->flags & OAF_BOUND))
+ if (!lease->bound)
continue;
if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -273,7 +273,7 @@ static bool statefiles_write_state(time_t now)
struct dhcpv6_lease *lease;
list_for_each_entry(lease, &ctxt.iface->ia_assignments, head) {
- if (!(lease->flags & OAF_BOUND))
+ if (!lease->bound)
continue;
if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
@@ -287,7 +287,7 @@ static bool statefiles_write_state(time_t now)
struct dhcpv4_lease *lease;
avl_for_each_element(&ctxt.iface->dhcpv4_leases, lease, iface_avl) {
- if (!(lease->flags & OAF_BOUND))
+ if (!lease->bound)
continue;
if (!INFINITE_VALID(lease->valid_until) && lease->valid_until <= now)
diff --git a/src/ubus.c b/src/ubus.c
index 5cbd09d..413bbfc 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -59,7 +59,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _o_unused struct ubus_
blobmsg_add_u8(&b, "accept-reconf", c->accept_fr_nonce);
m = blobmsg_open_array(&b, "flags");
- if (c->flags & OAF_BOUND)
+ if (c->bound)
blobmsg_add_string(&b, NULL, "bound");
if (c->lease_cfg)
@@ -151,7 +151,7 @@ static int handle_dhcpv6_leases(_o_unused struct ubus_context *ctx, _o_unused st
blobmsg_add_u16(&b, "assigned", a->assigned_subnet_id);
m = blobmsg_open_array(&b, "flags");
- if (a->flags & OAF_BOUND)
+ if (a->bound)
blobmsg_add_string(&b, NULL, "bound");
if (a->lease_cfg)