ip/dhcpd: don't get confused by ipv6 addresses for bootp Info

When looking up tftp/bootp information from ndb,
filter out ipv6 addresses. This can happen
when for example the tftp= attribute points to
a domain or sys-name that resolves to both
ipv4 and ipv6 addresses.

Make validip() do the isv4() check, and provide
separate validipmask() function.
This commit is contained in:
cinap_lenrek 2024-12-22 20:06:18 +00:00
parent 94d9b7a49d
commit 35cab9b816
3 changed files with 20 additions and 7 deletions

View file

@ -50,6 +50,7 @@ struct Info
/* from dhcp.c */
extern int validip(uchar*);
extern int validipmask(uchar*);
extern void fatal(char*, ...);
extern void warning(char*, ...);
#pragma varargck argpos fatal 1

View file

@ -1134,9 +1134,9 @@ miscoptions(Req *rp, uchar *ip)
addrs[i] = &x[i*IPaddrlen];
/* always supply these */
if(validip(rp->ii.ipmask))
if(validipmask(rp->ii.ipmask))
maskopt(rp, OBmask, rp->ii.ipmask);
else if(validip(rp->gii.ipmask))
else if(validipmask(rp->gii.ipmask))
maskopt(rp, OBmask, rp->gii.ipmask);
else if((lifc = ipremoteonifc(rp->ifc, ip)) != nil)
maskopt(rp, OBmask, lifc->mask);
@ -1391,6 +1391,16 @@ readsysname(void)
extern int
validip(uchar *ip)
{
if(ipcmp(ip, IPnoaddr) == 0)
return 0;
if(ipcmp(ip, v4prefix) == 0)
return 0;
return isv4(ip);
}
extern int
validipmask(uchar *ip)
{
if(ipcmp(ip, IPnoaddr) == 0)
return 0;

View file

@ -60,14 +60,18 @@ static void
setipaddr(uchar *addr, char *ip)
{
if(ipcmp(addr, IPnoaddr) == 0)
parseip(addr, ip);
if(parseip(addr, ip) == -1
|| !validip(addr))
ipmove(addr, IPnoaddr); /* invalid */
}
static void
setipmask(uchar *mask, char *ip)
{
if(ipcmp(mask, IPnoaddr) == 0)
parseipmask(mask, ip, 1);
if(parseipmask(mask, ip, 1) == -1
|| !validipmask(mask))
ipmove(mask, IPnoaddr); /* invalid */
}
/*
@ -228,9 +232,7 @@ lookup(Bootp *bp, Info *iip, Info *riip)
for(nt = t; nt != nil; nt = nt->entry){
if(strcmp(nt->attr, "ip") != 0)
continue;
if(parseip(ciaddr, nt->val) == -1 || !isv4(ciaddr))
continue;
if(!validip(ciaddr))
if(parseip(ciaddr, nt->val) == -1 || !validip(ciaddr))
continue;
if(!samenet(ciaddr, riip))
continue;