9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Aidan Wiggins <akw@oneirism.org>
To: 9front@9front.org
Subject: [9front] [PATCH] libip/classmask.c: recognize unicast subnets
Date: Mon, 18 Jul 2022 12:37:29 -0700	[thread overview]
Message-ID: <E1663446C279BB3F45121980065B6EF7@oneirism.org> (raw)

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)

             reply	other threads:[~2022-07-18 19:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 19:37 Aidan Wiggins [this message]
2022-07-21  8:33 ` cinap_lenrek
2022-07-22  2:57   ` Aidan Wiggins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1663446C279BB3F45121980065B6EF7@oneirism.org \
    --to=akw@oneirism.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).