-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix using multiple enterprise IDs with vendclass (Option 124 DHCP / Option 16 DHCPv6) (#328) #408
Changes from 2 commits
c0a58f4
bcf800c
c68cea4
1f3cd2d
d7075fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,7 +808,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) | |
const struct dhcp_lease *lease = &state->lease; | ||
char hbuf[HOSTNAME_MAX_LEN + 1]; | ||
const char *hostname; | ||
const struct vivco *vivco; | ||
const struct vivco *vivco, *vivco_endp = ifo->vivco + ifo->vivco_len;; | ||
int mtu; | ||
#ifdef AUTH | ||
uint8_t *auth, auth_len; | ||
|
@@ -1142,26 +1142,29 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type) | |
{ | ||
AREA_CHECK(sizeof(ul)); | ||
*p++ = DHO_VIVCO; | ||
lp = p++; | ||
*lp = sizeof(ul); | ||
ul = htonl(ifo->vivco_en); | ||
memcpy(p, &ul, sizeof(ul)); | ||
p += sizeof(ul); | ||
for (i = 0, vivco = ifo->vivco; | ||
i < ifo->vivco_len; | ||
i++, vivco++) | ||
{ | ||
AREA_FIT(vivco->len); | ||
if (vivco->len + 2 + *lp > 255) { | ||
logerrx("%s: VIVCO option too big", | ||
ifp->name); | ||
free(bootp); | ||
return -1; | ||
} | ||
*p++ = (uint8_t)vivco->len; | ||
size_t totallen = 0; | ||
uint8_t datalen, datalenopt; | ||
for (vivco = ifo->vivco; vivco != vivco_endp; vivco++) | ||
totallen += sizeof(uint32_t) + 2 * sizeof(uint8_t) + vivco->len; | ||
if (totallen > UINT8_MAX) { | ||
logerrx("%s: VIVCO option too big", | ||
ifp->name); | ||
free(bootp); | ||
return -1; | ||
} | ||
*p++ = (uint8_t)totallen; | ||
for (vivco = ifo->vivco; vivco != vivco_endp; vivco++) { | ||
ul = htonl(vivco->en); | ||
memcpy(p, &ul, sizeof(ul)); | ||
p += sizeof(ul); | ||
datalen = (uint8_t)(sizeof(uint8_t) + vivco->len); | ||
memcpy(p, &datalen, sizeof(datalen)); | ||
p += sizeof(datalen); | ||
datalenopt = (uint8_t)(vivco->len); | ||
memcpy(p, &datalenopt, sizeof(datalenopt)); | ||
p += sizeof(datalenopt); | ||
memcpy(p, vivco->data, vivco->len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be re-written as
Much smaller code and no need to declare the variables then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'll fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the requested change with RFC3396 ctx. |
||
p += vivco->len; | ||
*lp = (uint8_t)(*lp + vivco->len + 1); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,6 +656,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, | |
struct dhcp_opt **dop, *ndop; | ||
size_t *dop_len, dl, odl; | ||
struct vivco *vivco; | ||
const struct vivco *vivco_endp = ifo->vivco + ifo->vivco_len; | ||
struct group *grp; | ||
#ifdef AUTH | ||
struct token *token; | ||
|
@@ -2119,6 +2120,12 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, | |
logerrx("invalid code: %s", arg); | ||
return -1; | ||
} | ||
for (vivco = ifo->vivco; vivco != vivco_endp; vivco++) { | ||
if (vivco->en == (uint32_t)u) { | ||
logerrx("only one vendor class option per enterprise number"); | ||
return -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a better text would be "vendor class option for enterprise number %u already defined". Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it is better regarding the text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would just free what was there and put new data in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the confusion, I meant about having a different option sent for the same enterprise number based on interface or profile name. Haven't worked with multiple profiles/interfaces tbh. |
||
} | ||
} | ||
fp = strskipwhite(fp); | ||
if (fp) { | ||
s = parse_string(NULL, 0, fp); | ||
|
@@ -2149,8 +2156,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, | |
return -1; | ||
} | ||
ifo->vivco = vivco; | ||
ifo->vivco_en = (uint32_t)u; | ||
vivco = &ifo->vivco[ifo->vivco_len++]; | ||
vivco->en = (uint32_t)u; | ||
vivco->len = dl; | ||
vivco->data = (uint8_t *)np; | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
White space between the declaration and the code please, but see below comment first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved with RFC3396 ctx.