Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using
ParseMACAddressFields
to parse a MACAddress IE, only theFlags
field is correctly initialized. All the source/destination/uppersource/upperdestination mac address fields remain empty.After investigation, it appears that when using copy, the number of elements copied is the
the minimum of len(src) and len(dst)
- see doc here.But at this point, the MAC address fields are nil. So the copy didn't update the MAC address fields.
The fix proposal here is to initialize each field as a
net.HardwareAddr
of size 6.net.HardwareAddr
being a type alias for[]byte
, the MAC address field will have the correct size to be able to copy the content ofb[offset:offset+6]
into it.I also added unit tests to cover this issue, plus extra test cases around the
ParseMACAddressFields
.I'm not sure about the convention to follow here. The existing unit tests files seemed to cover generic parsing of IEs. But as this is more a specific parsing function, I opted for putting them under
ie/mac_address_test.go
.Please let me know In case the unit tests should be moved somewhere else.
I also ran all the unit tests locally to verify that they still passed with my changes.