[RFC PATCH 04/14] router: refactor calc_ra_lifetime, and define ra_lifetime as uint32_t

Paul Donald newtwen+github at gmail.com
Thu May 9 15:30:36 PDT 2024


From: Paul Donald <newtwen at gmail.com>

ra_lifetime no longer holds negative values, because we no longer do
'init' when we do calc_ra_lifetime.

Signed-off-by: Paul Donald <newtwen at gmail.com>
---
 src/odhcpd.h |  2 +-
 src/router.c | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/odhcpd.h b/src/odhcpd.h
index 7a82e98..09cd4f1 100644
--- a/src/odhcpd.h
+++ b/src/odhcpd.h
@@ -314,7 +314,7 @@ struct interface {
 	int route_preference;
 	int ra_maxinterval;
 	int ra_mininterval;
-	int ra_lifetime;
+	uint32_t ra_lifetime;
 	uint32_t ra_reachabletime;
 	uint32_t ra_retranstime;
 	uint32_t ra_hoplimit;
diff --git a/src/router.c b/src/router.c
index 96237d6..b859c46 100644
--- a/src/router.c
+++ b/src/router.c
@@ -366,17 +366,14 @@ static int calc_adv_interval(struct interface *iface, uint32_t lowest_found_life
 
 static uint32_t calc_ra_lifetime(struct interface *iface, uint32_t maxival)
 {
-	uint32_t lifetime = 3*maxival;
-
-	if (iface->ra_lifetime >= 0) {
-		lifetime = iface->ra_lifetime;
-		if (lifetime > 0 && lifetime < maxival)
-			lifetime = maxival;
-		/* // RouterLifetime is a 16 bit packet field: skip this check
-		else if (lifetime > RouterLifetime_MAX)
-			lifetime = RouterLifetime_MAX;
-		*/
-	}
+	uint32_t lifetime = iface->ra_lifetime;
+
+	if (lifetime > 0 && lifetime < maxival)
+		lifetime = maxival;
+	/* // RouterLifetime is a 16 bit packet field: skip this check
+	else if (lifetime > RouterLifetime_MAX)
+		lifetime = RouterLifetime_MAX;
+	*/
 
 	return lifetime;
 }
-- 
2.44.0




More information about the openwrt-devel mailing list