ref: dbfb76673539e5b59dac437c6b2a2159c896731c
parent: 12b3c82014efd24fa57037c001c7d3ce78204e5a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Sep 25 11:04:19 EDT 2018
ip/dhcpd: implement rfc3397 dhcp search domain option (dnsdomain)
--- a/sys/src/cmd/ip/dhcp.h
+++ b/sys/src/cmd/ip/dhcp.h
@@ -111,6 +111,8 @@
ODtftpserver= 66,
ODbootfile= 67,
+ ODdnsdomain= 119,
+
/* plan9 vendor info options, v4 addresses only (deprecated) */
OP9fsv4= 128, /* plan9 file servers */
OP9authv4= 129, /* plan9 auth servers */
--- a/sys/src/cmd/ip/dhcpd/dhcpd.c
+++ b/sys/src/cmd/ip/dhcpd/dhcpd.c
@@ -161,6 +161,7 @@
[ODclientid] "cid",
[ODtftpserver] "tftpserver",
[ODbootfile] "bf",
+[ODdnsdomain] "dnsdomain",
};
void addropt(Req*, int, uchar*);
@@ -177,6 +178,7 @@
void miscoptions(Req*, uchar*);
int openlisten(char *net);
void p9addrsopt(Req *rp, int t, uchar **ip, int i);
+void dnsnamesopt(Req *rp, int t, char *attr, Ndbtuple *nt);
void parseoptions(Req*);
void proto(Req*, int);
void rcvdecline(Req*);
@@ -1170,6 +1172,7 @@
a = attr;
if(*rp->ii.domain == 0)
a[na++] = "dom";
+ a[na++] = "dnsdomain";
for(i = 0; i < sizeof(rp->requested); i++)
switch(rp->requested[i]){
case OBrouter:
@@ -1228,6 +1231,9 @@
if(p != nil)
stringopt(rp, OBdomainname, p+1);
break;
+ case ODdnsdomain:
+ dnsnamesopt(rp, ODdnsdomain, "dnsdomain", t);
+ break;
case OBnetbiosns:
j = lookupserver("wins", addrs, nelem(addrs), t);
addrsopt(rp, OBnetbiosns, addrs, j);
@@ -1573,6 +1579,40 @@
}
op = seprint(op, oe, "%s(%s)", optname[t], str);
+}
+
+void
+dnsnamesopt(Req *rp, int t, char *attr, Ndbtuple *nt)
+{
+ char *s;
+ uchar *d;
+ int n, l;
+
+ for(; nt != nil; nt = nt->entry){
+ if(strcmp(nt->attr, attr) != 0)
+ continue;
+ d = &rp->p[2];
+ for(s = nt->val; *s != 0; s++){
+ for(l = 0; *s != 0 && *s != '.'; l++)
+ s++;
+ if(l > 077)
+ goto Skip;
+ d += l+1;
+ if(d >= rp->max)
+ return;
+ d[-l-1] = l;
+ memmove(d-l, s-l, l);
+ }
+ *d++ = 0;
+ n = d - &rp->p[2];
+ if(n > 255)
+ continue;
+ rp->p[0] = t;
+ rp->p[1] = n;
+ rp->p = d;
+ op = seprint(op, oe, "%s(%s)", optname[t], nt->val);
+ Skip:;
+ }
}
void