changeset 5359:e6b89e1a4077 draft

DHCP6: Use sla setting when calculating delegated prefix length This is fine as we have a limited list of interfaces we're delegating to so we know all the numbers. This fixes an issue where an interface index could exceed 8 bits. While here change sla_set to a boolean.
author Roy Marples <roy@marples.name>
date Mon, 15 Jun 2020 15:51:17 +0100
parents d2c66d08c2d7
children 1033af2dded0
files src/dhcp6.c src/if-options.c src/if-options.h
diffstat 3 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp6.c	Mon Jun 15 15:14:53 2020 +0100
+++ b/src/dhcp6.c	Mon Jun 15 15:51:17 2020 +0100
@@ -541,12 +541,12 @@
 		state->reason = "DELEGATED6";
 	}
 
-	if (sla == NULL || sla->sla_set == 0) {
+	if (sla == NULL || !sla->sla_set) {
 		/* No SLA set, so make an assumption of
 		 * desired SLA and prefix length. */
 		asla.sla = ifp->index;
 		asla.prefix_len = 0;
-		asla.sla_set = 0;
+		asla.sla_set = false;
 		sla = &asla;
 	} else if (sla->prefix_len == 0) {
 		/* An SLA was given, but prefix length was not.
@@ -554,7 +554,7 @@
 		 * potentially more than one interface. */
 		asla.sla = sla->sla;
 		asla.prefix_len = 0;
-		asla.sla_set = 0;
+		asla.sla_set = sla->sla_set;
 		sla = &asla;
 	}
 
@@ -562,16 +562,15 @@
 		uint32_t sla_max;
 		int bits;
 
-		if (ia->sla_max == 0) {
+		sla_max = ia->sla_max;
+		if (sla_max == 0 && (sla == NULL || !sla->sla_set)) {
 			const struct interface *ifi;
 
-			sla_max = 0;
 			TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) {
 				if (ifi->index > sla_max)
 					sla_max = ifi->index;
 			}
-		} else
-			sla_max = ia->sla_max;
+		}
 
 		bits = fls32(sla_max);
 
--- a/src/if-options.c	Mon Jun 15 15:14:53 2020 +0100
+++ b/src/if-options.c	Mon Jun 15 15:51:17 2020 +0100
@@ -1460,7 +1460,7 @@
 				logerrx("%s: interface name too long", arg);
 				goto err_sla;
 			}
-			sla->sla_set = 0;
+			sla->sla_set = false;
 			sla->prefix_len = 0;
 			sla->suffix = 1;
 			p = np;
@@ -1471,7 +1471,7 @@
 				if (*p != '\0') {
 					sla->sla = (uint32_t)strtou(p, NULL,
 					    0, 0, UINT32_MAX, &e);
-					sla->sla_set = 1;
+					sla->sla_set = true;
 					if (e) {
 						logerrx("%s: failed to convert "
 						    "sla",
@@ -1530,7 +1530,7 @@
 					    sla->ifname);
 					goto err_sla;
 				}
-				if (sla->sla_set == 0 &&
+				if (!sla->sla_set &&
 				    strcmp(slap->ifname, sla->ifname) == 0)
 				{
 					logwarnx("%s: cannot specify the "
--- a/src/if-options.h	Mon Jun 15 15:14:53 2020 +0100
+++ b/src/if-options.h	Mon Jun 15 15:51:17 2020 +0100
@@ -188,7 +188,7 @@
 	uint32_t sla;
 	uint8_t prefix_len;
 	uint64_t suffix;
-	int8_t sla_set;
+	bool sla_set;
 };
 
 struct if_ia {