ip/ipconfig: refactor plan9 vendor parsing
Unless ip/dhcpd is started with the -6 option, we only receive v4 addresses. If we do see the v6 options we should prefer them but should also make sure we grab the v4 addresses as a fallback. None of the v6 options should overwrite valid overrides given at the command line. Add our custom types to logging.
This commit is contained in:
parent
207d124dfe
commit
df92301d8f
1 changed files with 37 additions and 33 deletions
|
@ -18,6 +18,7 @@ enum
|
||||||
Tulong,
|
Tulong,
|
||||||
Tvec,
|
Tvec,
|
||||||
Tnames,
|
Tnames,
|
||||||
|
Tp9addrs,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Option Option;
|
typedef struct Option Option;
|
||||||
|
@ -93,6 +94,7 @@ static Option option[256] =
|
||||||
[OBircserver] { "irc", Taddrs },
|
[OBircserver] { "irc", Taddrs },
|
||||||
[OBstserver] { "st", Taddrs },
|
[OBstserver] { "st", Taddrs },
|
||||||
[OBstdaserver] { "stdar", Taddrs },
|
[OBstdaserver] { "stdar", Taddrs },
|
||||||
|
[OBvendorinfo] { "vendorinfo", Tvec },
|
||||||
|
|
||||||
[ODipaddr] { "ipaddr", Taddr },
|
[ODipaddr] { "ipaddr", Taddr },
|
||||||
[ODlease] { "lease", Tulong },
|
[ODlease] { "lease", Tulong },
|
||||||
|
@ -109,6 +111,14 @@ static Option option[256] =
|
||||||
[ODtftpserver] { "tftp", Tstr },
|
[ODtftpserver] { "tftp", Tstr },
|
||||||
[ODbootfile] { "bootfile", Tstr },
|
[ODbootfile] { "bootfile", Tstr },
|
||||||
[ODdnsdomain] { "dnsdomain", Tnames },
|
[ODdnsdomain] { "dnsdomain", Tnames },
|
||||||
|
|
||||||
|
[OP9authv4] { "p9authv4", Taddrs },
|
||||||
|
[OP9fsv4] { "p9fsv4", Taddrs },
|
||||||
|
[OP9fs] { "p9fs", Tp9addrs },
|
||||||
|
[OP9auth] { "p9auth", Tp9addrs },
|
||||||
|
[OP9ipaddr] { "p9ipaddr", Tp9addrs },
|
||||||
|
[OP9ipmask] { "p9ipmask", Tp9addrs },
|
||||||
|
[OP9ipgw] { "p9ipgw", Tp9addrs },
|
||||||
};
|
};
|
||||||
|
|
||||||
static uchar defrequested[] = {
|
static uchar defrequested[] = {
|
||||||
|
@ -414,7 +424,7 @@ dhcprecv(void)
|
||||||
int i, n, type;
|
int i, n, type;
|
||||||
ulong lease;
|
ulong lease;
|
||||||
char err[ERRMAX];
|
char err[ERRMAX];
|
||||||
uchar buf[8000], vopts[256], taddr[IPaddrlen];
|
uchar buf[8000], vopts[256], taddr[IPaddrlen*2];
|
||||||
Bootp *bp;
|
Bootp *bp;
|
||||||
|
|
||||||
memset(buf, 0, sizeof buf);
|
memset(buf, 0, sizeof buf);
|
||||||
|
@ -544,39 +554,33 @@ dhcprecv(void)
|
||||||
/* get plan9-specific options */
|
/* get plan9-specific options */
|
||||||
n = optgetvec(bp->optdata, OBvendorinfo, vopts, sizeof vopts-1);
|
n = optgetvec(bp->optdata, OBvendorinfo, vopts, sizeof vopts-1);
|
||||||
if(n > 0 && parseoptions(vopts, n) == 0){
|
if(n > 0 && parseoptions(vopts, n) == 0){
|
||||||
if(validip(conf.fs) && Oflag)
|
if(!(Oflag && validip(conf.fs))){
|
||||||
n = 1;
|
n = optgetp9addrs(vopts, OP9fs, taddr, 2);
|
||||||
else {
|
if(n < 2)
|
||||||
n = optgetp9addrs(vopts, OP9fs, conf.fs, 2);
|
n += optgetaddrs(vopts, OP9fsv4, taddr + (n * IPaddrlen), 2 - n);
|
||||||
if (n == 0)
|
memmove(conf.fs, taddr, n * IPaddrlen);
|
||||||
n = optgetaddrs(vopts, OP9fsv4,
|
|
||||||
conf.fs, 2);
|
|
||||||
}
|
}
|
||||||
for(i = 0; i < n; i++)
|
if(!(Oflag && validip(conf.auth))){
|
||||||
DEBUG("fs=%I ", conf.fs + i*IPaddrlen);
|
n = optgetp9addrs(vopts, OP9auth, taddr, 2);
|
||||||
|
if(n < 2)
|
||||||
if(validip(conf.auth) && Oflag)
|
n += optgetaddrs(vopts, OP9authv4, taddr + (n * IPaddrlen), 2 - n);
|
||||||
n = 1;
|
memmove(conf.auth, taddr, n * IPaddrlen);
|
||||||
else {
|
|
||||||
n = optgetp9addrs(vopts, OP9auth, conf.auth, 2);
|
|
||||||
if (n == 0)
|
|
||||||
n = optgetaddrs(vopts, OP9authv4,
|
|
||||||
conf.auth, 2);
|
|
||||||
}
|
}
|
||||||
for(i = 0; i < n; i++)
|
DEBUG("fs=(%I %I) auth=(%I %I)", conf.fs, conf.fs + IPaddrlen, conf.auth , conf.auth + IPaddrlen);
|
||||||
DEBUG("auth=%I ", conf.auth + i*IPaddrlen);
|
|
||||||
|
|
||||||
n = optgetp9addrs(vopts, OP9ipaddr, taddr, 1);
|
if(!(Oflag && validip(conf.laddr)))
|
||||||
if (n > 0)
|
if(optgetp9addrs(vopts, OP9ipaddr, taddr, 1))
|
||||||
ipmove(conf.laddr, taddr);
|
ipmove(conf.laddr, taddr);
|
||||||
n = optgetp9addrs(vopts, OP9ipmask, taddr, 1);
|
|
||||||
if (n > 0)
|
if(!(Oflag && validip(conf.mask)))
|
||||||
ipmove(conf.mask, taddr);
|
if(optgetp9addrs(vopts, OP9ipmask, taddr, 1))
|
||||||
n = optgetp9addrs(vopts, OP9ipgw, taddr, 1);
|
ipmove(conf.mask, taddr);
|
||||||
if (n > 0)
|
|
||||||
ipmove(conf.gaddr, taddr);
|
if(!(Oflag && validip(conf.gaddr)))
|
||||||
DEBUG("new ipaddr=%I new ipmask=%M new ipgw=%I",
|
if(optgetp9addrs(vopts, OP9ipgw, taddr, 1))
|
||||||
conf.laddr, conf.mask, conf.gaddr);
|
ipmove(conf.gaddr, taddr);
|
||||||
|
|
||||||
|
DEBUG("p9 opt ipaddr=%I ipmask=%M ipgw=%I", conf.laddr, conf.mask, conf.gaddr);
|
||||||
}
|
}
|
||||||
conf.lease = lease;
|
conf.lease = lease;
|
||||||
conf.state = Sbound;
|
conf.state = Sbound;
|
||||||
|
@ -779,8 +783,8 @@ optgetp9addrs(uchar *ap, int op, uchar *ip, int n)
|
||||||
slen = strlen(p) + 1;
|
slen = strlen(p) + 1;
|
||||||
if (parseip(&ip[i*IPaddrlen], p) == -1)
|
if (parseip(&ip[i*IPaddrlen], p) == -1)
|
||||||
fprint(2, "%s: bad address %s\n", argv0, p);
|
fprint(2, "%s: bad address %s\n", argv0, p);
|
||||||
DEBUG("got plan 9 option %d addr %I (%s)",
|
DEBUG("got plan 9 option %s addr %I (%s)",
|
||||||
op, &ip[i*IPaddrlen], p);
|
option[op].name, &ip[i*IPaddrlen], p);
|
||||||
p += slen;
|
p += slen;
|
||||||
len -= slen;
|
len -= slen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue