All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipv6:delete duplicate code for reserved iid check
@ 2021-03-03  0:53 zhang kai
  2021-03-03  3:16 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: zhang kai @ 2021-03-03  0:53 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern, kuba, netdev; +Cc: zhang kai

Using the ipv6_reserved_interfaceid for interface id checking.

Signed-off-by: zhang kai <zhangkaiheb@126.com>
---
 net/ipv6/addrconf.c | 45 +++++++++++++++++++--------------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index f2337fb75..e9d13ce62 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -135,6 +135,7 @@ static inline void addrconf_sysctl_unregister(struct inet6_dev *idev)
 }
 #endif
 
+static bool ipv6_reserved_interfaceid(struct in6_addr address);
 static void ipv6_gen_rnd_iid(struct in6_addr *addr);
 
 static int ipv6_generate_eui64(u8 *eui, struct net_device *dev);
@@ -2352,32 +2353,12 @@ static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
 
 static void ipv6_gen_rnd_iid(struct in6_addr *addr)
 {
-regen:
-	get_random_bytes(&addr->s6_addr[8], 8);
-
-	/* <draft-ietf-6man-rfc4941bis-08.txt>, Section 3.3.1:
-	 * check if generated address is not inappropriate:
-	 *
-	 * - Reserved IPv6 Interface Identifers
-	 * - XXX: already assigned to an address on the device
-	 */
-
-	/* Subnet-router anycast: 0000:0000:0000:0000 */
-	if (!(addr->s6_addr32[2] | addr->s6_addr32[3]))
-		goto regen;
-
-	/* IANA Ethernet block: 0200:5EFF:FE00:0000-0200:5EFF:FE00:5212
-	 * Proxy Mobile IPv6:   0200:5EFF:FE00:5213
-	 * IANA Ethernet block: 0200:5EFF:FE00:5214-0200:5EFF:FEFF:FFFF
-	 */
-	if (ntohl(addr->s6_addr32[2]) == 0x02005eff &&
-	    (ntohl(addr->s6_addr32[3]) & 0Xff000000) == 0xfe000000)
-		goto regen;
+	struct in6_addr temp;
 
-	/* Reserved subnet anycast addresses */
-	if (ntohl(addr->s6_addr32[2]) == 0xfdffffff &&
-	    ntohl(addr->s6_addr32[3]) >= 0Xffffff80)
-		goto regen;
+	do {
+		get_random_bytes(&addr->s6_addr[8], 8);
+		temp = *addr;
+	} while (ipv6_reserved_interfaceid(temp));
 }
 
 /*
@@ -3189,15 +3170,27 @@ void addrconf_add_linklocal(struct inet6_dev *idev,
 }
 EXPORT_SYMBOL_GPL(addrconf_add_linklocal);
 
+/* <draft-ietf-6man-rfc4941bis-08.txt>, Section 3.3.1:
+ * check if generated address is not inappropriate:
+ *
+ * - Reserved IPv6 Interface Identifers
+ * - XXX: already assigned to an address on the device
+ */
 static bool ipv6_reserved_interfaceid(struct in6_addr address)
 {
+	/* Subnet-router anycast: 0000:0000:0000:0000 */
 	if ((address.s6_addr32[2] | address.s6_addr32[3]) == 0)
 		return true;
 
+	/* IANA Ethernet block: 0200:5EFF:FE00:0000-0200:5EFF:FE00:5212
+	 * Proxy Mobile IPv6:   0200:5EFF:FE00:5213
+	 * IANA Ethernet block: 0200:5EFF:FE00:5214-0200:5EFF:FEFF:FFFF
+	 */
 	if (address.s6_addr32[2] == htonl(0x02005eff) &&
-	    ((address.s6_addr32[3] & htonl(0xfe000000)) == htonl(0xfe000000)))
+	    ((address.s6_addr32[3] & htonl(0xff000000)) == htonl(0xfe000000)))
 		return true;
 
+	/* Reserved subnet anycast addresses */
 	if (address.s6_addr32[2] == htonl(0xfdffffff) &&
 	    ((address.s6_addr32[3] & htonl(0xffffff80)) == htonl(0xffffff80)))
 		return true;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ipv6:delete duplicate code for reserved iid check
  2021-03-03  0:53 [PATCH] ipv6:delete duplicate code for reserved iid check zhang kai
@ 2021-03-03  3:16 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-03-03  3:16 UTC (permalink / raw)
  To: zhang kai, davem, yoshfuji, dsahern, kuba, netdev

On 3/2/21 5:53 PM, zhang kai wrote:
> Using the ipv6_reserved_interfaceid for interface id checking.
> 
> Signed-off-by: zhang kai <zhangkaiheb@126.com>
> ---
>  net/ipv6/addrconf.c | 45 +++++++++++++++++++--------------------------
>  1 file changed, 19 insertions(+), 26 deletions(-)
> 

Looks equivalent to me. Code wise:

Reviewed-by: David Ahern <dsahern@kernel.org>

The commit message needs more words about the change.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-03  4:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  0:53 [PATCH] ipv6:delete duplicate code for reserved iid check zhang kai
2021-03-03  3:16 ` David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.