shithub: riscv

Download patch

ref: 39a435ee1c9026ed8b26aa8bb1c03ac7d8d14809
parent: d904a57e1763ac884a749b04f19f3e490a4cec88
author: Alex Musolino <[email protected]>
date: Tue Jun 11 11:27:12 EDT 2019

snoopy(8): add support for dhcp classless static routes option

To complement the new cl-routes field, the bootp static routes option has been
renamed to cf-routes and the network/gateway pairs are separated with a right
arrow.

--- a/sys/src/cmd/ip/dhcp.h
+++ b/sys/src/cmd/ip/dhcp.h
@@ -112,6 +112,7 @@
 	ODbootfile=		67,
 
 	ODdnsdomain=		119,
+	ODclasslessroutes=	121,
 
 	/* plan9 vendor info options, v4 addresses only (deprecated) */
 	OP9fsv4=		128,	/* plan9 file servers */
--- a/sys/src/cmd/ip/snoopy/dhcp.c
+++ b/sys/src/cmd/ip/snoopy/dhcp.c
@@ -80,6 +80,52 @@
 	return p;
 }
 
+static char*
+pcfroutes(char *p, char *e, char *tag, uchar *o, int n)
+{
+	int i;
+
+	p = seprint(p, e, "%s=(", tag);
+	i = 0;
+	while(n >= 8){
+		if(i++ > 0)
+			p = seprint(p, e, " ");
+		p = seprint(p, e, "%V→%V", o, o+4);
+		o += 8;
+		n -= 8;
+	}
+	p = seprint(p, e, ")");
+	return p;
+}
+
+static char*
+pclroutes(char *p, char *e, char *tag, uchar *o, int n)
+{
+	uchar addr[4];
+	int i, nbits, nocts;
+
+	p = seprint(p, e, "%s=(", tag);
+	i = 0;
+	while(n >= 5){
+		nbits = *o++;
+		n--;
+		nocts = nbits <= 32 ? (nbits+7)/8 : 4;
+		if(n < nocts+4)
+			break;
+		memset(addr, 0, 4);
+		memmove(addr, o, nocts);
+		o += nocts;
+		n -= nocts;
+		if(i++ > 0)
+			p = seprint(p, e, " ");
+		p = seprint(p, e, "%V/%d→%V", addr, nbits, o);
+		o += 4;
+		n -= 4;
+	}
+	p = seprint(p, e, ")");
+	return p;
+}
+
 static char *dhcptype[256] =
 {
 [Discover]	"Discover",
@@ -264,7 +310,10 @@
 			p = pserver(p, e, "rsrouter", o, n);
 			break;
 		case OBstaticroutes:
-			p = phex(p, e, "staticroutes", o, n);
+			p = pcfroutes(p, e, "cf-routes", o, n);
+			break;
+		case ODclasslessroutes:
+			p = pclroutes(p, e, "cl-routes", o, n);
 			break;
 		case OBtrailerencap:
 			p = phex(p, e, "trailerencap", o, n);