Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

spoljak-ent
Copy link
Contributor

@spoljak-ent spoljak-ent commented Nov 21, 2024

As it's outlined in #328, using multiple enterprise IDs with vendclass overwrites all previous values.
This fixes the malformation of the DHCPv4 packet and adds support for multiple different enterprise ID vendclass options.

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;
Copy link
Member

Choose a reason for hiding this comment

The 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".
We might also want to consider do we want to have a different option sent for the same enterprise number based on interface or profile name? If so, we might just want to silently override it instead.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is better regarding the text.
Regarding the different option, I was going along with RFC 3925 that we should have only one enterprise number among all instances of this option.
How would this work with the silent override?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would just free what was there and put new data in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

src/dhcp.c Outdated
*p++ = (uint8_t)vivco->len;
size_t totallen = 0;
uint8_t datalen, datalenopt;
for (vivco = ifo->vivco; vivco != vivco_endp; vivco++)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved with RFC3396 ctx.

src/dhcp.c Outdated
p += sizeof(datalen);
datalenopt = (uint8_t)(vivco->len);
memcpy(p, &datalenopt, sizeof(datalenopt));
p += sizeof(datalenopt);
memcpy(p, vivco->data, vivco->len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be re-written as

*p++ = (uint8_t)(sizeof(uint8_t) + vivco->len);
*p++ = (uint8_t)(vivco->len);

Much smaller code and no need to declare the variables then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the requested change with RFC3396 ctx.
Looks much cleaner now.

@rsmarples
Copy link
Member

RFC 3925 says

Multiple instances of this option may be present
and MUST be concatenated in accordance with RFC 3396 [4].

So we should try and use the rfc3396 encoding functions we added in the previous PR to help here.

@spoljak-ent
Copy link
Contributor Author

RFC 3925 says

Multiple instances of this option may be present
and MUST be concatenated in accordance with RFC 3396 [4].

So we should try and use the rfc3396 encoding functions we added in the previous PR to help here.

We could, but I wasn't sure about adding (much) more code since the previous PR was wrapped in #ifndef SMALL.

@rsmarples
Copy link
Member

RFC 3925 says

Multiple instances of this option may be present
and MUST be concatenated in accordance with RFC 3396 [4].

So we should try and use the rfc3396 encoding functions we added in the previous PR to help here.

We could, but I wasn't sure about adding (much) more code since the previous PR was wrapped in #ifndef SMALL.

We should wrap this code in #ifndef SMALL as well really.

@spoljak-ent
Copy link
Contributor Author

RFC 3925 says

Multiple instances of this option may be present
and MUST be concatenated in accordance with RFC 3396 [4].

So we should try and use the rfc3396 encoding functions we added in the previous PR to help here.

We could, but I wasn't sure about adding (much) more code since the previous PR was wrapped in #ifndef SMALL.

We should wrap this code in #ifndef SMALL as well really.

Got it. I'll make the changes.

@spoljak-ent
Copy link
Contributor Author

RFC 3925 says

Multiple instances of this option may be present
and MUST be concatenated in accordance with RFC 3396 [4].

So we should try and use the rfc3396 encoding functions we added in the previous PR to help here.

We could, but I wasn't sure about adding (much) more code since the previous PR was wrapped in #ifndef SMALL.

We should wrap this code in #ifndef SMALL as well really.

Got it. I'll make the changes.

All required changes done... for now 😄

Copy link
Member

@rsmarples rsmarples left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good now, thanks.

I'm currently in the process of moving house so won't get a chance to actually test it for Some Time.

src/dhcp.c Outdated
if (lp == NULL)
goto toobig;
if (rfc3396_write_byte(&rctx,
(uint8_t)vivco->len) == -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where the line breaks or flows onto the next, please use 4 spaces rather than a tab.
I should really force an opinionated formatter on pull requests at some point :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted and corrected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants