ndp: Fix calculation of length for DNS Search List option (31)

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-07-17 17:58:03 +02:00
parent 4667226bb0
commit a9c8d4d924

6
ndp.c
View file

@ -127,7 +127,7 @@ int ndp(struct ctx *c, struct ethhdr *eh, size_t len)
len += strlen(c->dns_search[n].n) + 2; len += strlen(c->dns_search[n].n) + 2;
if (len) { if (len) {
*p++ = 31; /* DNSSL */ *p++ = 31; /* DNSSL */
*p++ = 2 + (len + 8 - 1) / 8; /* length */ *p++ = (len + 8 - 1) / 8 + 1; /* length */
p += 2; /* reserved */ p += 2; /* reserved */
*(uint32_t *)p = htonl(60); /* lifetime */ *(uint32_t *)p = htonl(60); /* lifetime */
p += 4; p += 4;
@ -148,8 +148,8 @@ int ndp(struct ctx *c, struct ethhdr *eh, size_t len)
*(p++) = 0; *(p++) = 0;
} }
memset(p, 0, len % 8); /* padding */ memset(p, 0, 8 - len % 8); /* padding */
p += len % 8; p += 8 - len % 8;
} }
*p++ = 1; /* source ll */ *p++ = 1; /* source ll */