changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: snoopy(8): add support for dhcp classless static routes option

changeset 7266: 9c6308ab12e0
parent 7265: ff77c8e6d1a0
child 7267: a3e539617163
author: Alex Musolino <alex@musolino.id.au>
date: Tue, 11 Jun 2019 15:27:12 +0930
files: sys/src/cmd/ip/dhcp.h sys/src/cmd/ip/snoopy/dhcp.c
description: 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.
     1.1--- a/sys/src/cmd/ip/dhcp.h
     1.2+++ b/sys/src/cmd/ip/dhcp.h
     1.3@@ -112,6 +112,7 @@ enum
     1.4 	ODbootfile=		67,
     1.5 
     1.6 	ODdnsdomain=		119,
     1.7+	ODclasslessroutes=	121,
     1.8 
     1.9 	/* plan9 vendor info options, v4 addresses only (deprecated) */
    1.10 	OP9fsv4=		128,	/* plan9 file servers */
     2.1--- a/sys/src/cmd/ip/snoopy/dhcp.c
     2.2+++ b/sys/src/cmd/ip/snoopy/dhcp.c
     2.3@@ -80,6 +80,52 @@ pserver(char *p, char *e, char *tag, uch
     2.4 	return p;
     2.5 }
     2.6 
     2.7+static char*
     2.8+pcfroutes(char *p, char *e, char *tag, uchar *o, int n)
     2.9+{
    2.10+	int i;
    2.11+
    2.12+	p = seprint(p, e, "%s=(", tag);
    2.13+	i = 0;
    2.14+	while(n >= 8){
    2.15+		if(i++ > 0)
    2.16+			p = seprint(p, e, " ");
    2.17+		p = seprint(p, e, "%V→%V", o, o+4);
    2.18+		o += 8;
    2.19+		n -= 8;
    2.20+	}
    2.21+	p = seprint(p, e, ")");
    2.22+	return p;
    2.23+}
    2.24+
    2.25+static char*
    2.26+pclroutes(char *p, char *e, char *tag, uchar *o, int n)
    2.27+{
    2.28+	uchar addr[4];
    2.29+	int i, nbits, nocts;
    2.30+
    2.31+	p = seprint(p, e, "%s=(", tag);
    2.32+	i = 0;
    2.33+	while(n >= 5){
    2.34+		nbits = *o++;
    2.35+		n--;
    2.36+		nocts = nbits <= 32 ? (nbits+7)/8 : 4;
    2.37+		if(n < nocts+4)
    2.38+			break;
    2.39+		memset(addr, 0, 4);
    2.40+		memmove(addr, o, nocts);
    2.41+		o += nocts;
    2.42+		n -= nocts;
    2.43+		if(i++ > 0)
    2.44+			p = seprint(p, e, " ");
    2.45+		p = seprint(p, e, "%V/%d→%V", addr, nbits, o);
    2.46+		o += 4;
    2.47+		n -= 4;
    2.48+	}
    2.49+	p = seprint(p, e, ")");
    2.50+	return p;
    2.51+}
    2.52+
    2.53 static char *dhcptype[256] =
    2.54 {
    2.55 [Discover]	"Discover",
    2.56@@ -264,7 +310,10 @@ p_seprint(Msg *m)
    2.57 			p = pserver(p, e, "rsrouter", o, n);
    2.58 			break;
    2.59 		case OBstaticroutes:
    2.60-			p = phex(p, e, "staticroutes", o, n);
    2.61+			p = pcfroutes(p, e, "cf-routes", o, n);
    2.62+			break;
    2.63+		case ODclasslessroutes:
    2.64+			p = pclroutes(p, e, "cl-routes", o, n);
    2.65 			break;
    2.66 		case OBtrailerencap:
    2.67 			p = phex(p, e, "trailerencap", o, n);