dhcp: Fix netmask calculation for option 1 from prefix length
Similar to the conf_print() fix from commit4129764eca
("conf: Fix mask calculation from prefix_len in conf_print()"): to calculate an IPv4 netmask from the prefix length, we need to left shift 32 all-one bits by 32 minus the prefix length -- not by the prefix length itself. Reported-by: Yalan Zhang <yalzhang@redhat.com> Fixes:dd09cceaee
("Minor improvements to IPv4 netmask handling") Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
7564b58a7f
commit
77a6d976aa
1 changed files with 1 additions and 1 deletions
2
dhcp.c
2
dhcp.c
|
@ -335,7 +335,7 @@ int dhcp(const struct ctx *c, const struct pool *p)
|
||||||
m->chaddr[3], m->chaddr[4], m->chaddr[5]);
|
m->chaddr[3], m->chaddr[4], m->chaddr[5]);
|
||||||
|
|
||||||
m->yiaddr = c->ip4.addr;
|
m->yiaddr = c->ip4.addr;
|
||||||
mask.s_addr = htonl(0xffffffff << c->ip4.prefix_len);
|
mask.s_addr = htonl(0xffffffff << (32 - c->ip4.prefix_len));
|
||||||
memcpy(opts[1].s, &mask, sizeof(mask));
|
memcpy(opts[1].s, &mask, sizeof(mask));
|
||||||
memcpy(opts[3].s, &c->ip4.gw, sizeof(c->ip4.gw));
|
memcpy(opts[3].s, &c->ip4.gw, sizeof(c->ip4.gw));
|
||||||
memcpy(opts[54].s, &c->ip4.gw, sizeof(c->ip4.gw));
|
memcpy(opts[54].s, &c->ip4.gw, sizeof(c->ip4.gw));
|
||||||
|
|
Loading…
Reference in a new issue