Skip to content

Commit

Permalink
Bugfix: incorrect calculation on IP packet header length (antrea-io#38)
Browse files Browse the repository at this point in the history
This change is to resolve this issue: the header option length in an IP packet
header is not counted.

There are at least 20 bytes in the IP packet header. Hence, if the IHL value is
less than 5, 5 is used to count IP header length, otherwise it should use the IHL
value directly.

Signed-off-by: wenyingd <[email protected]>
  • Loading branch information
wenyingd authored May 22, 2023
1 parent 7964f82 commit a5eadc6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.10.1
v0.10.2
14 changes: 14 additions & 0 deletions openflow15/nxt_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package openflow15

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_PacketIn2UnMarshal(t *testing.T) {
msgBytes := []byte{0, 0, 0, 50, 1, 0, 94, 20, 50, 173, 34, 101, 235, 44, 251, 123, 8, 0, 70, 192, 0, 32, 0, 0, 64, 0, 1, 2, 15, 169, 192, 168, 0, 5, 225, 20, 50, 173, 148, 4, 0, 0, 18, 0, 218, 61, 225, 20, 50, 173, 0, 0, 0, 0, 0, 0, 0, 3, 0, 5, 33, 0, 0, 0, 0, 4, 0, 16, 0, 0, 0, 0, 0, 3, 5, 0, 0, 0, 0, 0, 0, 5, 0, 5, 0, 0, 0, 0, 0, 6, 0, 32, 128, 0, 0, 4, 0, 0, 0, 6, 128, 1, 1, 16, 0, 0, 0, 3, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 7, 0, 5, 3, 0, 0, 0}
pktIn2 := new(PacketIn2)
err := pktIn2.UnmarshalBinary(msgBytes)
assert.NoError(t, err)
}
4 changes: 3 additions & 1 deletion protocol/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func NewIPv4() *IPv4 {
}

func (i *IPv4) Len() (n uint16) {
i.IHL = 5
if i.IHL < 5 {
i.IHL = 5
}
if i.Data != nil {
return uint16(i.IHL*4) + i.Data.Len()
}
Expand Down

0 comments on commit a5eadc6

Please sign in to comment.