[PATCH v2 2/9] various: refactor valid -> valid_lt (lifetime)

Paul Donald newtwen+github at gmail.com
Fri Apr 5 04:06:46 PDT 2024


From: Paul Donald <newtwen at gmail.com>

Refactor "valid" (valid what?) to "valid_lt".

Signed-off-by: Paul Donald <newtwen at gmail.com>
Reviewed-by: Daniel Golle <daniel at makrotopia.org>
---
 src/dhcpv6-ia.c | 62 ++++++++++++++++++++++++-------------------------
 src/dhcpv6.c    |  4 ++--
 src/dhcpv6.h    |  4 ++--
 src/netlink.c   | 24 +++++++++----------
 src/odhcpd.c    |  2 +-
 src/odhcpd.h    |  2 +-
 src/router.c    | 38 +++++++++++++++---------------
 7 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 6a9098e..39a316a 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -226,7 +226,7 @@ void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c,
 
 	for (size_t i = 0; i < addrlen; ++i) {
 		struct in6_addr addr;
-		uint32_t preferred_lt, valid;
+		uint32_t preferred_lt, valid_lt;
 		int prefix = c->managed ? addrs[i].prefix : c->length;
 
 		if (!valid_addr(&addrs[i], now))
@@ -243,7 +243,7 @@ void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c,
 
 		addr = addrs[i].addr.in6;
 		preferred_lt = addrs[i].preferred_lt;
-		valid = addrs[i].valid;
+		valid_lt = addrs[i].valid_lt;
 
 		if (c->flags & OAF_DHCPV6_NA) {
 			if (!ADDR_ENTRY_VALID_IA_ADDR(iface, i, m, addrs))
@@ -268,13 +268,13 @@ void dhcpv6_ia_enum_addrs(struct interface *iface, struct dhcp_assignment *c,
 		if (preferred_lt != UINT32_MAX)
 			preferred_lt -= now;
 
-		if (valid > (uint32_t)c->valid_until)
-			valid = c->valid_until;
+		if (valid_lt > (uint32_t)c->valid_until)
+			valid_lt = c->valid_until;
 
-		if (valid != UINT32_MAX)
-			valid -= now;
+		if (valid_lt != UINT32_MAX)
+			valid_lt -= now;
 
-		func(&addr, prefix, preferred_lt, valid, arg);
+		func(&addr, prefix, preferred_lt, valid_lt, arg);
 	}
 }
 
@@ -289,7 +289,7 @@ struct write_ctxt {
 };
 
 static void dhcpv6_write_ia_addrhosts(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
-				_unused uint32_t valid, void *arg)
+				_unused uint32_t valid_lt, void *arg)
 {
 	struct write_ctxt *ctxt = (struct write_ctxt *)arg;
 	char ipbuf[INET6_ADDRSTRLEN];
@@ -309,7 +309,7 @@ static void dhcpv6_write_ia_addrhosts(struct in6_addr *addr, int prefix, _unused
 }
 
 static void dhcpv6_write_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
-				_unused uint32_t valid, void *arg)
+				_unused uint32_t valid_lt, void *arg)
 {
 	struct write_ctxt *ctxt = (struct write_ctxt *)arg;
 	char ipbuf[INET6_ADDRSTRLEN];
@@ -682,10 +682,10 @@ static void managed_handle_pd_data(struct ustream *s, _unused int bytes_new)
 				continue;
 
 			x = strtok_r(NULL, ",", &saveptr2);
-			if (sscanf(x, "%u", &n->valid) < 1)
+			if (sscanf(x, "%u", &n->valid_lt) < 1)
 				continue;
 
-			if (n->preferred_lt > n->valid)
+			if (n->preferred_lt > n->valid_lt)
 				continue;
 
 			if (UINT32_MAX - now < n->preferred_lt)
@@ -693,10 +693,10 @@ static void managed_handle_pd_data(struct ustream *s, _unused int bytes_new)
 			else
 				n->preferred_lt += now;
 
-			if (UINT32_MAX - now < n->valid)
-				n->valid = UINT32_MAX;
+			if (UINT32_MAX - now < n->valid_lt)
+				n->valid_lt = UINT32_MAX;
 			else
-				n->valid += now;
+				n->valid_lt += now;
 
 			n->dprefix = 0;
 
@@ -1047,14 +1047,14 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 			preferred_lt = iface->preferred_lifetime;
 		}
 
-		uint32_t valid = leasetime;
+		uint32_t valid_lt = leasetime;
 
 		struct odhcpd_ipaddr *addrs = (a->managed) ? a->managed : iface->addr6;
 		size_t addrlen = (a->managed) ? (size_t)a->managed_size : iface->addr6_len;
 		size_t m = get_preferred_addr(addrs, addrlen);
 
 		for (size_t i = 0; i < addrlen; ++i) {
-			uint32_t prefix_preferred_lt, prefix_valid;
+			uint32_t prefix_preferred_lt, prefix_valid_lt;
 
 			if (!valid_addr(&addrs[i], now))
 				continue;
@@ -1069,7 +1069,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 			}
 
 			prefix_preferred_lt = addrs[i].preferred_lt;
-			prefix_valid = addrs[i].valid;
+			prefix_valid_lt = addrs[i].valid_lt;
 
 			if (prefix_preferred_lt != UINT32_MAX)
 				prefix_preferred_lt -= now;
@@ -1077,21 +1077,21 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 			if (prefix_preferred_lt > preferred_lt)
 				prefix_preferred_lt = preferred_lt;
 
-			if (prefix_valid != UINT32_MAX)
-				prefix_valid -= now;
+			if (prefix_valid_lt != UINT32_MAX)
+				prefix_valid_lt -= now;
 
-			if (prefix_valid > leasetime)
-				prefix_valid = leasetime;
+			if (prefix_valid_lt > leasetime)
+				prefix_valid_lt = leasetime;
 
-			if (prefix_preferred_lt > prefix_valid)
-				prefix_preferred_lt = prefix_valid;
+			if (prefix_preferred_lt > prefix_valid_lt)
+				prefix_preferred_lt = prefix_valid_lt;
 
 			if (a->flags & OAF_DHCPV6_PD) {
 				struct dhcpv6_ia_prefix o_ia_p = {
 					.type = htons(DHCPV6_OPT_IA_PREFIX),
 					.len = htons(sizeof(o_ia_p) - 4),
 					.preferred_lt = htonl(prefix_preferred_lt),
-					.valid = htonl(prefix_valid),
+					.valid_lt = htonl(prefix_valid_lt),
 					.prefix = (a->managed_size) ? addrs[i].prefix : a->length,
 					.addr = addrs[i].addr.in6,
 				};
@@ -1115,7 +1115,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 					.len = htons(sizeof(o_ia_a) - 4),
 					.addr = addrs[i].addr.in6,
 					.preferred_lt = htonl(prefix_preferred_lt),
-					.valid = htonl(prefix_valid)
+					.valid_lt = htonl(prefix_valid_lt)
 				};
 
 				o_ia_a.addr.s6_addr32[2] = htonl(a->assigned_host_id >> 32);
@@ -1136,14 +1136,14 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 				if (prefix_preferred_lt < preferred_lt)
 					preferred_lt = prefix_preferred_lt;
 
-				if (prefix_valid < valid)
-					valid = prefix_valid;
+				if (prefix_valid_lt < valid_lt)
+					valid_lt = prefix_valid_lt;
 			}
 		}
 
 		if (!INFINITE_VALID(a->valid_until))
 			/* UINT32_MAX is considered as infinite leasetime */
-			a->valid_until = (valid == UINT32_MAX) ? 0 : valid + now;
+			a->valid_until = (valid_lt == UINT32_MAX) ? 0 : valid_lt + now;
 
 		if (!INFINITE_VALID(a->preferred_until))
 			/* UINT32_MAX is considered as infinite leasetime */
@@ -1212,7 +1212,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 						.type = htons(DHCPV6_OPT_IA_PREFIX),
 						.len = htons(sizeof(o_ia_p) - 4),
 						.preferred_lt = 0,
-						.valid = 0,
+						.valid_lt = 0,
 						.prefix = ia_p->prefix,
 						.addr = ia_p->addr,
 					};
@@ -1228,7 +1228,7 @@ static size_t build_ia(uint8_t *buf, size_t buflen, uint16_t status,
 						.len = htons(sizeof(o_ia_a) - 4),
 						.addr = ia_a->addr,
 						.preferred_lt = 0,
-						.valid = 0,
+						.valid_lt = 0,
 					};
 
 					if (buflen < ia_len + sizeof(o_ia_a))
@@ -1253,7 +1253,7 @@ struct log_ctxt {
 };
 
 static void dhcpv6_log_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref_lt,
-				_unused uint32_t valid, void *arg)
+				_unused uint32_t valid_lt, void *arg)
 {
 	struct log_ctxt *ctxt = (struct log_ctxt *)arg;
 	char addrbuf[INET6_ADDRSTRLEN];
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index b0e5a79..58b7d9f 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -770,7 +770,7 @@ static struct odhcpd_ipaddr *relay_link_address(struct interface *iface)
 	time_t now = odhcpd_time();
 
 	for (size_t i = 0; i < iface->addr6_len; i++) {
-		if (iface->addr6[i].valid <= (uint32_t)now)
+		if (iface->addr6[i].valid_lt <= (uint32_t)now)
 			continue;
 
 		if (iface->addr6[i].preferred_lt > (uint32_t)now) {
@@ -778,7 +778,7 @@ static struct odhcpd_ipaddr *relay_link_address(struct interface *iface)
 			break;
 		}
 
-		if (!addr || (iface->addr6[i].valid > addr->valid))
+		if (!addr || (iface->addr6[i].valid_lt > addr->valid_lt))
 			addr = &iface->addr6[i];
 	}
 
diff --git a/src/dhcpv6.h b/src/dhcpv6.h
index 8681d7f..b925928 100644
--- a/src/dhcpv6.h
+++ b/src/dhcpv6.h
@@ -131,7 +131,7 @@ struct dhcpv6_ia_prefix {
 	uint16_t type;
 	uint16_t len;
 	uint32_t preferred_lt;
-	uint32_t valid;
+	uint32_t valid_lt;
 	uint8_t prefix;
 	struct in6_addr addr;
 } _packed;
@@ -141,7 +141,7 @@ struct dhcpv6_ia_addr {
 	uint16_t len;
 	struct in6_addr addr;
 	uint32_t preferred_lt;
-	uint32_t valid;
+	uint32_t valid_lt;
 } _packed;
 
 struct dhcpv6_cer_id {
diff --git a/src/netlink.c b/src/netlink.c
index cf77035..c33e3ea 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -207,7 +207,7 @@ static void refresh_iface_addr6(int ifindex)
 				if (!IN6_ARE_ADDR_EQUAL(&addr[i].addr.in6, &iface->addr6[i].addr.in6) ||
 				    addr[i].prefix != iface->addr6[i].prefix ||
 				    (addr[i].preferred_lt > (uint32_t)now) != (iface->addr6[i].preferred_lt > (uint32_t)now) ||
-				    addr[i].valid < iface->addr6[i].valid || addr[i].preferred_lt < iface->addr6[i].preferred_lt)
+				    addr[i].valid_lt < iface->addr6[i].valid_lt || addr[i].preferred_lt < iface->addr6[i].preferred_lt)
 					change = true;
 			}
 
@@ -230,7 +230,7 @@ static void refresh_iface_addr6(int ifindex)
 				for (size_t i = 0; i < iface->addr6_len; ++i) {
 					bool removed = true;
 
-					if (iface->addr6[i].valid <= (uint32_t)now)
+					if (iface->addr6[i].valid_lt <= (uint32_t)now)
 						continue;
 
 					for (ssize_t j = 0; removed && j < len; ++j) {
@@ -258,7 +258,7 @@ static void refresh_iface_addr6(int ifindex)
 						iface->invalid_addr6 = new_invalid_addr6;
 						iface->invalid_addr6_len++;
 						memcpy(&iface->invalid_addr6[pos], &iface->addr6[i], sizeof(*iface->invalid_addr6));
-						iface->invalid_addr6[pos].valid = iface->invalid_addr6[pos].preferred_lt = (uint32_t)now;
+						iface->invalid_addr6[pos].valid_lt = iface->invalid_addr6[pos].preferred_lt = (uint32_t)now;
 
 						if (iface->invalid_addr6[pos].prefix < 64)
 							iface->invalid_addr6[pos].prefix = 64;
@@ -631,7 +631,7 @@ static int cb_addr_valid(struct nl_msg *msg, void *arg)
 		struct ifa_cacheinfo *ifc = nla_data(nla[IFA_CACHEINFO]);
 
 		addrs[ctxt->ret].preferred_lt = ifc->ifa_prefered;
-		addrs[ctxt->ret].valid = ifc->ifa_valid;
+		addrs[ctxt->ret].valid_lt = ifc->ifa_valid;
 	}
 
 	if (ifa->ifa_flags & IFA_F_DEPRECATED)
@@ -752,8 +752,8 @@ ssize_t netlink_get_interface_addrs(int ifindex, bool v6, struct odhcpd_ipaddr *
 		if (addr[i].preferred_lt < UINT32_MAX - now)
 			addr[i].preferred_lt += now;
 
-		if (addr[i].valid < UINT32_MAX - now)
-			addr[i].valid += now;
+		if (addr[i].valid_lt < UINT32_MAX - now)
+			addr[i].valid_lt += now;
 	}
 
 free:
@@ -1124,16 +1124,16 @@ int netlink_setup_addr(struct odhcpd_ipaddr *addr,
 			cinfo.ifa_prefered = preferred_lt;
 		}
 
-		if (addr->valid) {
-			int64_t valid = addr->valid - now;
-			if (valid <= 0) {
+		if (addr->valid_lt) {
+			int64_t valid_lt = addr->valid_lt - now;
+			if (valid_lt <= 0) {
 				nlmsg_free(msg);
 				return -1;
 			}
-			else if (valid > UINT32_MAX)
-				valid = UINT32_MAX;
+			else if (valid_lt > UINT32_MAX)
+				valid_lt = UINT32_MAX;
 
-			cinfo.ifa_valid = valid;
+			cinfo.ifa_valid = valid_lt;
 		}
 
 		nla_put(msg, IFA_CACHEINFO, sizeof(cinfo), &cinfo);
diff --git a/src/odhcpd.c b/src/odhcpd.c
index e2e89c0..0849b43 100644
--- a/src/odhcpd.c
+++ b/src/odhcpd.c
@@ -269,7 +269,7 @@ int odhcpd_get_interface_dns_addr(const struct interface *iface, struct in6_addr
 		return -1;
 
 	for (size_t i = 0; i < iface->addr6_len; ++i) {
-		if (iface->addr6[i].valid <= (uint32_t)now)
+		if (iface->addr6[i].valid_lt <= (uint32_t)now)
 			continue;
 
 		if (m < 0) {
diff --git a/src/odhcpd.h b/src/odhcpd.h
index df27c14..7a82e98 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -127,7 +127,7 @@ struct odhcpd_ipaddr {
 	union if_addr addr;
 	uint8_t prefix;
 	uint32_t preferred_lt;
-	uint32_t valid;
+	uint32_t valid_lt;
 
 	union {
 		/* ipv6 only */
diff --git a/src/router.c b/src/router.c
index 55f3acb..6a9e19d 100644
--- a/src/router.c
+++ b/src/router.c
@@ -301,7 +301,7 @@ static bool router_icmpv6_valid(struct sockaddr_in6 *source, uint8_t *data, size
 static bool parse_routes(struct odhcpd_ipaddr *n, ssize_t len)
 {
 	struct odhcpd_ipaddr p = { .addr.in6 = IN6ADDR_ANY_INIT, .prefix = 0,
-					.dprefix = 0, .preferred_lt = 0, .valid = 0};
+					.dprefix = 0, .preferred_lt = 0, .valid_lt = 0};
 	bool found_default = false;
 	char line[512], ifname[16];
 
@@ -550,12 +550,12 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
 		struct odhcpd_ipaddr *addr = &addrs[i];
 		struct nd_opt_prefix_info *p = NULL;
 		uint32_t preferred_lt = 0;
-		uint32_t valid = 0;
+		uint32_t valid_lt = 0;
 
-		if (addr->prefix > 96 || (i < valid_addr_cnt && addr->valid <= (uint32_t)now)) {
-			syslog(LOG_INFO, "Address %s (prefix %d, valid %u) not suitable as RA prefix on %s",
+		if (addr->prefix > 96 || (i < valid_addr_cnt && addr->valid_lt <= (uint32_t)now)) {
+			syslog(LOG_INFO, "Address %s (prefix %d, valid-lifetime %u) not suitable as RA prefix on %s",
 				inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), addr->prefix,
-				addr->valid, iface->name);
+				addr->valid_lt, iface->name);
 			continue;
 		}
 
@@ -595,17 +595,17 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
 				preferred_lt = iface->preferred_lifetime;
 		}
 
-		if (addr->valid > (uint32_t)now) {
-			valid = TIME_LEFT(addr->valid, now);
+		if (addr->valid_lt > (uint32_t)now) {
+			valid_lt = TIME_LEFT(addr->valid_lt, now);
 
-			if (iface->ra_useleasetime && valid > iface->dhcp_leasetime)
-				valid = iface->dhcp_leasetime;
+			if (iface->ra_useleasetime && valid_lt > iface->dhcp_leasetime)
+				valid_lt = iface->dhcp_leasetime;
 		}
 
-		if (minvalid > valid)
-			minvalid = valid;
+		if (minvalid > valid_lt)
+			minvalid = valid_lt;
 
-		if ((!IN6_IS_ADDR_ULA(&addr->addr.in6) || iface->default_router) && valid)
+		if ((!IN6_IS_ADDR_ULA(&addr->addr.in6) || iface->default_router) && valid_lt)
 			valid_prefix = true;
 
 		odhcpd_bmemcpy(&p->nd_opt_pi_prefix, &addr->addr.in6,
@@ -621,7 +621,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr
 		if (iface->ra_advrouter)
 			p->nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;
 		p->nd_opt_pi_preferred_time = htonl(preferred_lt);
-		p->nd_opt_pi_valid_time = htonl(valid);
+		p->nd_opt_pi_valid_time = htonl(valid_lt);
 	}
 
 	iov[IOV_RA_PFXS].iov_base = (char *)pfxs;
@@ -780,12 +780,12 @@ pref64_out:
 	for (ssize_t i = 0; i < valid_addr_cnt; ++i) {
 		struct odhcpd_ipaddr *addr = &addrs[i];
 		struct nd_opt_route_info *tmp;
-		uint32_t valid;
+		uint32_t valid_lt;
 
-		if (addr->dprefix >= 64 || addr->dprefix == 0 || addr->valid <= (uint32_t)now) {
-			syslog(LOG_INFO, "Address %s (dprefix %d, valid %u) not suitable as RA route on %s",
+		if (addr->dprefix >= 64 || addr->dprefix == 0 || addr->valid_lt <= (uint32_t)now) {
+			syslog(LOG_INFO, "Address %s (dprefix %d, valid-lifetime %u) not suitable as RA route on %s",
 				inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
-				addr->dprefix, addr->valid, iface->name);
+				addr->dprefix, addr->valid_lt, iface->name);
 
 			continue; /* Address not suitable */
 		}
@@ -822,8 +822,8 @@ pref64_out:
 		else if (iface->route_preference > 0)
 			routes[routes_cnt].flags |= ND_RA_PREF_HIGH;
 
-		valid = TIME_LEFT(addr->valid, now);
-		routes[routes_cnt].lifetime = htonl(valid < lifetime ? valid : lifetime);
+		valid_lt = TIME_LEFT(addr->valid_lt, now);
+		routes[routes_cnt].lifetime = htonl(valid_lt < lifetime ? valid_lt : lifetime);
 		routes[routes_cnt].addr[0] = addr->addr.in6.s6_addr32[0];
 		routes[routes_cnt].addr[1] = addr->addr.in6.s6_addr32[1];
 		routes[routes_cnt].addr[2] = 0;
-- 
2.44.0




More information about the openwrt-devel mailing list