]> git.lizzy.rs Git - plan9front.git/commitdiff
snoopy(8): add support for dhcp classless static routes option
authorAlex Musolino <alex@musolino.id.au>
Tue, 11 Jun 2019 05:57:12 +0000 (15:27 +0930)
committerAlex Musolino <alex@musolino.id.au>
Tue, 11 Jun 2019 05:57:12 +0000 (15:27 +0930)
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.

sys/src/cmd/ip/dhcp.h
sys/src/cmd/ip/snoopy/dhcp.c

index 75bdeb62cfa50652f5bb3227f3da6e53ba87dbd7..924b39106bdc59672c91c562342869336dfc2e6c 100644 (file)
@@ -112,6 +112,7 @@ enum
        ODbootfile=             67,
 
        ODdnsdomain=            119,
+       ODclasslessroutes=      121,
 
        /* plan9 vendor info options, v4 addresses only (deprecated) */
        OP9fsv4=                128,    /* plan9 file servers */
index 9d7d2b7a23aafd98d753b4b76648e2c749e40035..66bc407049bdcb42b6e737d8ce28e1bef73899a8 100644 (file)
@@ -80,6 +80,52 @@ pserver(char *p, char *e, char *tag, uchar *o, int n)
        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_seprint(Msg *m)
                        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);