Skip to contentSkip to conversation

net: ipv6: Fix IPv6 netmask parsing

PATCH In review [email protected] 4 participants 4 messages Jan 7, 2023 – Feb 3, 2023 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ipv6: Fix IPv6 netmask parsing

From: Sean Edmond <[email protected]>

It should be possible to specify a netmask when
setting a static IPv6 address. For example:
setenv ip6addr 2001:cafe:cafe:cafe::100/64

The net_prefix_length and net_ip6 should be updated properly.

---
 net/net6.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/net6.c +6 -3
index fdea078788..75577bcea1 100644
@@ -47,10 +47,13 @@ static int on_ip6addr(const char *name, const char *value, enum env_op op,
 	}
 
 	mask = strchr(value, '/');
-	len = strlen(value);
 
-	if (mask)
-		net_prefix_length = simple_strtoul(value + len, NULL, 10);
+	if (mask) {
+		net_prefix_length = simple_strtoul(mask + 1, NULL, 10);
+		len = mask - value;
+	} else {
+		len = strlen(value);
+	}
 
 	return string_to_ip6(value, len, &net_ip6);
 }
Signature · 1 line
2.39.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 36 lines · On Fri, 2023-01-06 at 14:22 -0800, [email protected] wrote:

From: Sean Edmond <[email protected]>

It should be possible to specify a netmask when
setting a static IPv6 address. For example:
setenv ip6addr 2001:cafe:cafe:cafe::100/64

The net_prefix_length and net_ip6 should be updated properly.

---
 net/net6.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/net6.c +6 -3
index fdea078788..75577bcea1 100644
@@ -47,10 +47,13 @@ static int on_ip6addr(const char *name, const
 char *value, enum env_op op,
        }
 
        mask = strchr(value, '/');
-       len = strlen(value);
 
-       if (mask)
-               net_prefix_length = simple_strtoul(value + len, NULL,
 10);
+       if (mask) {
+               net_prefix_length = simple_strtoul(mask + 1, NULL,
 10);
+               len = mask - value;
+       } else {
+               len = strlen(value);
+       }
Quoted 4 lines
        return string_to_ip6(value, len, &net_ip6);

}
--
2.39.0

I do agree with your changes.Thanks

Reviewed-by
#2 lore raw
Quoted 39 lines · Vyacheslav V. Mitrofanov
Quoted 36 lines · On Fri, 2023-01-06 at 14:22 -0800, [email protected] wrote:

From: Sean Edmond <[email protected]>

It should be possible to specify a netmask when
setting a static IPv6 address. For example:
setenv ip6addr 2001:cafe:cafe:cafe::100/64

The net_prefix_length and net_ip6 should be updated properly.

---
 net/net6.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/net6.c +6 -3
index fdea078788..75577bcea1 100644
@@ -47,10 +47,13 @@ static int on_ip6addr(const char *name, const
 char *value, enum env_op op,
        }
 
        mask = strchr(value, '/');
-       len = strlen(value);
 
-       if (mask)
-               net_prefix_length = simple_strtoul(value + len, NULL,
 10);
+       if (mask) {
+               net_prefix_length = simple_strtoul(mask + 1, NULL,
 10);
+               len = mask - value;
+       } else {
+               len = strlen(value);
+       }
Quoted 7 lines
Quoted 4 lines
        return string_to_ip6(value, len, &net_ip6);

}
--
2.39.0

I do agree with your changes.Thanks

#3 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, Jan 06, 2023 at 02:22:55PM -0800, [email protected] wrote:

From: Sean Edmond <[email protected]>

It should be possible to specify a netmask when
setting a static IPv6 address. For example:
setenv ip6addr 2001:cafe:cafe:cafe::100/64

Quoted 6 lines

The net_prefix_length and net_ip6 should be updated properly.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom