9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] libip/classmask.c: recognize unicast subnets
@ 2022-07-18 19:37 Aidan Wiggins
  2022-07-21  8:33 ` cinap_lenrek
  0 siblings, 1 reply; 3+ messages in thread
From: Aidan Wiggins @ 2022-07-18 19:37 UTC (permalink / raw)
  To: 9front

When using ndbiplookup, unicast ipv6 prefixes do not produce
the correct mask if there is no ipmask attr in the database.

In general, this changes defmask() to account for addresses of
the form: "a:b:c:d::".

I also consolidated the static ints into an enum for style and
did away with the v6loopback array as it would fall through
the control structure anyways and yield /128 as any other
unicast address would by default.

I'm also new to this so I could be incorrect and have targeted
the wrong thing.

Thanks!
Aidan

diff d1acc5831683a713653255b27b1d42ef66825dfe uncommitted
--- a//sys/src/libip/classmask.c
+++ b//sys/src/libip/classmask.c
@@ -9,13 +9,6 @@
 	0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0x00,
 };
 
-static uchar v6loopback[IPaddrlen] = {
-	0, 0, 0, 0,
-	0, 0, 0, 0,
-	0, 0, 0, 0,
-	0, 0, 0, 0x01
-};
-
 static uchar v6linklocal[IPaddrlen] = {
 	0xfe, 0x80, 0, 0,
 	0, 0, 0, 0,
@@ -28,8 +21,14 @@
 	0, 0, 0, 0,
 	0, 0, 0, 0
 };
-static int v6llpreflen = 8;	/* link-local prefix length in bytes */
 
+static uchar v6unicastmask[IPaddrlen] = {
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff, 0xff, 0xff,
+	0, 0, 0, 0,
+	0, 0, 0, 0
+};
+
 static uchar v6multicast[IPaddrlen] = {
 	0xff, 0, 0, 0,
 	0, 0, 0, 0,
@@ -42,7 +41,6 @@
 	0, 0, 0, 0,
 	0, 0, 0, 0
 };
-static int v6mcpreflen = 1;	/* multicast prefix length */
 
 static uchar v6solicitednode[IPaddrlen] = {
 	0xff, 0x02, 0, 0,
@@ -56,18 +54,25 @@
 	0xff, 0xff, 0xff, 0xff,
 	0xff, 0x0, 0x0, 0x0
 };
-static int v6snpreflen = 13;
 
+enum {
+	v6llpreflen = 8,	/* link-local prefix length in bytes */
+	v6unisublen = 8,	/* global unicast prefix length */
+	v6snpreflen = 13,	/* solicited-node prefix length */
+	v6mcpreflen = 1,	/* multicast prefix length */
+};
+
 uchar*
 defmask(uchar *ip)
 {
 	if(isv4(ip))
 		return classmask[ip[IPv4off]>>6];
-	else {
-		if(ipcmp(ip, v6loopback) == 0)
-			return IPallbits;
-		else if(memcmp(ip, v6linklocal, v6llpreflen) == 0)
+	else{
+		if(memcmp(ip, v6linklocal, v6llpreflen) == 0)
 			return v6linklocalmask;
+		else if(memcmp(ip, IPnoaddr, v6unisublen) > 0)
+			if(memcmp(ip+8, IPnoaddr, v6unisublen) == 0)
+				return v6unicastmask;
 		else if(memcmp(ip, v6solicitednode, v6snpreflen) == 0)
 			return v6solicitednodemask;
 		else if(memcmp(ip, v6multicast, v6mcpreflen) == 0)

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

end of thread, other threads:[~2022-07-22  3:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 19:37 [9front] [PATCH] libip/classmask.c: recognize unicast subnets Aidan Wiggins
2022-07-21  8:33 ` cinap_lenrek
2022-07-22  2:57   ` Aidan Wiggins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).