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

DHPCv4 options const values are not actually OptionCodes #4

Closed
get9 opened this issue Mar 6, 2018 · 1 comment
Closed

DHPCv4 options const values are not actually OptionCodes #4

get9 opened this issue Mar 6, 2018 · 1 comment

Comments

@get9
Copy link
Collaborator

get9 commented Mar 6, 2018

I was refactoring some of the tests to take advantage of stretchr/testify/assert and ran into an interesting bug. It turns out the DHCPv4 options in dhcpv4/types.go are not all OptionCodes - only the first one is. The rest of them are ints due to the way the initialization works.

I forsee two fixes:

  1. Prepend OptionCode before each =
  2. Change the first line to OptionPad = iota and figure out what to do for the gaps in the range due to e.g. returned options.
@insomniacslk
Copy link
Owner

insomniacslk commented Mar 6, 2018

Nice finding, thanks!

For how ugly it may look, I would rather prepend OptionCode before each line.
The reason is that iota should not be used for cases like this, when defining constants from some spec, they should only be used for internal use (like enums, but different). Unfortunately this is something I learned only after writing this code. This means that also MessageTypeDiscover and OpcodeBootRequest in the same file (and their blocks), should be converted to stop using iota and prepend the type before the assignment.

Same thing for dhcpv6/types.go

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

No branches or pull requests

2 participants