-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allocate 6 bytes to copy MAC addresses when unmarshalling ethernet match fields #30
Allocate 6 bytes to copy MAC addresses when unmarshalling ethernet match fields #30
Conversation
…tch fields Currently we are trying to unmarshal data to an uninitialized struct whose net.HardwareAddr fields are set to nil. In this case the copy() function silently does nothing. Initialize the fields to slices of bytes of length 6 before copying data to them. Signed-off-by: Dmitry Rozhkov <[email protected]>
Hi @rojkov thanks for working on this patch. I have one comment on this patch: OpenFlow 1.5 is the major version we planned to support for a long time ( OpenFlow1.3 is deprecated ), so please also change the code in path |
…tch fields Currently we are trying to unmarshal data to an uninitialized struct whose net.HardwareAddr fields are set to nil. In this case the copy() function silently does nothing. Initialize the fields to slices of bytes of length 6 before copying data to them. This commit is derived from antrea-io#30. Signed-off-by: shi0rik0 <[email protected]>
Hello, @wenyingd @tnqn @antoninbas ! package main
import (
"encoding/hex"
"fmt"
"antrea.io/libOpenflow/openflow15"
)
// Random OpenFlow1.5 Match from my OVS bridge;
var MatchWithMac, _ = hex.DecodeString("00010037800000040000000580000606deadbeef010280000806deadbeef030480000a020800800014010680001a02000580001c02000500")
func PrintEthFields(bytes []byte) (err error) {
ofMatch := openflow15.NewMatch()
err = ofMatch.UnmarshalBinary(bytes)
if err != nil {
return err
}
for _, field := range ofMatch.Fields {
switch f := field.Value.(type) {
case *openflow15.EthSrcField:
fmt.Printf("Ethernet src field: %s\n", f.EthSrc)
if f.EthSrc == nil {
return fmt.Errorf("ethernet src field is nil")
}
case *openflow15.EthDstField:
fmt.Printf("Ethernet dst field: %s\n", f.EthDst)
if f.EthDst == nil {
return fmt.Errorf("ethernet dst field is nil")
}
}
}
return nil
}
func main() {
err := PrintEthFields(MatchWithMac)
if err != nil {
panic(err)
}
} Correct output is: Ethernet dst field: de:ad:be:ef:01:02
Ethernet src field: de:ad:be:ef:03:04 |
@vanytsvetkov We are fine with the patch, but the original comment from @wenyingd was not addressed. The change should be applied to Feel free to take over this patch since we haven't heard back from @rojkov |
@vanytsvetkov please feel free to resubmit the patch under your credentials. I work on completely unrelated projects nowadays. |
…tch fields antrea-io#30 Signed-off-by: Ivan Tsvetkov <[email protected]>
Closing the PR as #62 has been merged. Thanks @rojkov @vanytsvetkov for fixing it. |
Currently we are trying to unmarshal data to an uninitialized struct whose
net.HardwareAddr
fields are set to nil. In this case thecopy()
function silently does nothing.Initialize the fields to slices of bytes of length 6 before copying data to them.
Signed-off-by: Dmitry Rozhkov [email protected]