When using ParseMACAddressFields to parse a MACAddress IE, only the Flags 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 of b[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.
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 underie/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.