diff mbox series

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

Message ID 20240509223213.97389-5-newtwen+github@gmail.com
State New
Headers show
Series odhcpd config value clamping | expand

Commit Message

Paul Donald May 9, 2024, 10:30 p.m. UTC
From: Paul Donald <newtwen@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@gmail.com>
---
 src/odhcpd.h |  2 +-
 src/router.c | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)
diff mbox series

Patch

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;
 }