Skip to content

Conversation

jesson1
Copy link

@jesson1 jesson1 commented Jan 13, 2025

Fix the ARP packet parsing code to adapt to the scenario where the switch adds extra padding bytes to ARP packets to meet the 64-byte minimum frame size.

Error stack:

panic: runtime error: slice bounds out of range [4:0]
goroutine 1127 [running]:
third_party/libOpenflow/openflow13.(*PacketIn2PropPacket).UnmarshalBinary(0xc0000f7a40, {0xc0012fe840, 0x58, 0x7c0})
        /third_party/libOpenflow/openflow13/nxt_message.go:807 +0x17a
third_party/libOpenflow/openflow13.DecodePacketIn2Prop({0xc0012fe840?, 0x58?, 0x7c0?})
        /third_party/libOpenflow/openflow13/nxt_message.go:1201 +0x1f1
third_party/libOpenflow/openflow13.(*PacketIn2).UnmarshalBinary(0xc0006b4678, {0xc0012fe810, 0x88, 0x7f0})
        /third_party/libOpenflow/openflow13/nxt_message.go:1240 +0xa5
third_party/libOpenflow/openflow13.decodeVendorData(0x40de87?, {0xc0012fe810, 0x88, 0x7f0})
        /third_party/libOpenflow/openflow13/nxt_message.go:1326 +0x1a2
third_party/libOpenflow/openflow13.(*VendorHeader).UnmarshalBinary(0xc000cf3080, {0xc0012fe800?, 0x4148c5?, 0x0?})
        /third_party/libOpenflow/openflow13/openflow13.go:841 +0xd0
third_party/libOpenflow/openflow13.Parse({0xc0012fe800, 0x98, 0x800})
        /third_party/libOpenflow/openflow13/openflow13.go:127 +0x230
third_party/ofnet/ofctrl.(*Controller).Parse(0xc0016c2f70?, {0xc0012fe800?, 0x0?, 0x0?})
        /third_party/ofnet/ofctrl/ofctrl.go:228 +0x3c
third_party/libOpenflow/util.(*streamWorker).parse(0xc00096c570, 0xc00132e000, {0x20c8e80, 0xc000a0eed0}, 0x0?, 0x0?)
        /third_party/libOpenflow/util/stream.go:41 +0x163
created by third_party/libOpenflow/util.NewMessageStream
        /third_party/libOpenflow/util/stream.go:98 +0x319

…he switch adds extra padding bytes to ARP packets to meet the 64-byte minimum frame size.

Signed-off-by: jiasheng.yu <[email protected]>
@@ -21,6 +21,9 @@ type ARP struct {
IPSrc net.IP
HWDst net.HardwareAddr
IPDst net.IP
// The actual test shows that ARP reply packets sent by the H3C switch include an additional 14 bytes.
// This is done by the switch to meet the minimum frame length requirement of 64 bytes.
Padding []byte
Copy link

Choose a reason for hiding this comment

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

No need to define a dedicated field for padding, you can directly update the function Len() by adding the corresponding length to meet the minimum frame length requirement of 64 bytes..

@@ -91,5 +96,10 @@ func (a *ARP) UnmarshalBinary(data []byte) error {
n += int(a.HWLength)
a.IPDst = make([]byte, a.ProtoLength)
copy(a.IPDst, data[n:n+int(a.ProtoLength)])
n += int(a.ProtoLength)
if len(data[n:]) > 0 {
Copy link

Choose a reason for hiding this comment

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

ditto. No need to copy the "padding" bytes, since it is not a valid case that a component consumes the padding bytes.

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