diff --git a/link.go b/link.go index 79a7e3a..69445bd 100644 --- a/link.go +++ b/link.go @@ -413,7 +413,7 @@ func (a *LinkStats) unmarshalBinary(b []byte) error { a.RXCompressed = nativeEndian.Uint32(b[84:88]) a.TXCompressed = nativeEndian.Uint32(b[88:92]) - if l == 96 { + if l == 96 { // kernel 4.6+ a.RXNoHandler = nativeEndian.Uint32(b[92:96]) } @@ -453,13 +453,15 @@ type LinkStats64 struct { TXCompressed uint64 RXNoHandler uint64 // dropped, no handler found + + RXOtherhostDropped uint64 // Number of packets dropped due to mismatch in destination MAC address. } // unmarshalBinary unmarshals the contents of a byte slice into a LinkMessage. func (a *LinkStats64) unmarshalBinary(b []byte) error { l := len(b) - if l != 184 && l != 192 { - return fmt.Errorf("incorrect size, want: 184 or 192") + if l != 184 && l != 192 && l != 200 { + return fmt.Errorf("incorrect size, want: 184 or 192 or 200") } a.RXPackets = nativeEndian.Uint64(b[0:8]) @@ -489,10 +491,14 @@ func (a *LinkStats64) unmarshalBinary(b []byte) error { a.RXCompressed = nativeEndian.Uint64(b[168:176]) a.TXCompressed = nativeEndian.Uint64(b[176:184]) - if l == 192 { + if l > 191 { // kernel 4.6+ a.RXNoHandler = nativeEndian.Uint64(b[184:192]) } + if l > 199 { // kernel 5.19+ + a.RXOtherhostDropped = nativeEndian.Uint64(b[192:200]) + } + return nil } diff --git a/link_test.go b/link_test.go index 1b8e94c..7841233 100644 --- a/link_test.go +++ b/link_test.go @@ -520,22 +520,27 @@ func TestLinkStats64UnmarshalBinary(t *testing.T) { }{ { name: "empty", - err: fmt.Errorf("incorrect size, want: 184 or 192"), + err: fmt.Errorf("incorrect size, want: 184 or 192 or 200"), }, { name: "invalid < 184", b: make([]byte, 183), - err: fmt.Errorf("incorrect size, want: 184 or 192"), + err: fmt.Errorf("incorrect size, want: 184 or 192 or 200"), }, { - name: "invalid > 192", + name: "invalid > 184 < 192", + b: make([]byte, 188), + err: fmt.Errorf("incorrect size, want: 184 or 192 or 200"), + }, + { + name: "invalid > 192 < 200", b: make([]byte, 193), - err: fmt.Errorf("incorrect size, want: 184 or 192"), + err: fmt.Errorf("incorrect size, want: 184 or 192 or 200"), }, { - name: "invalid > 184 < 192", - b: make([]byte, 188), - err: fmt.Errorf("incorrect size, want: 184 or 192"), + name: "invalid > 200", + b: make([]byte, 201), + err: fmt.Errorf("incorrect size, want: 184 or 192 or 200"), }, { name: "kernel <4.6", @@ -616,7 +621,7 @@ func TestLinkStats64UnmarshalBinary(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, m: &LinkStats64{ RXPackets: 0x1b650, @@ -642,7 +647,64 @@ func TestLinkStats64UnmarshalBinary(t *testing.T) { TXWindowErrors: 0x0, RXCompressed: 0x0, TXCompressed: 0x0, - RXNoHandler: 0x0, + RXNoHandler: 0x1, + }, + }, + { + name: "kernel 5.19+", + b: []byte{ + 0x50, 0xb6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa9, 0x41, 0xcd, 0x09, 0x00, 0x00, 0x00, 0x00, + 0x96, 0x96, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + m: &LinkStats64{ + RXPackets: 0x1b650, + TXPackets: 0xc906, + RXBytes: 0x9cd41a9, + TXBytes: 0x2a9696, + RXErrors: 0x0, + TXErrors: 0x0, + RXDropped: 0x0, + TXDropped: 0x0, + Multicast: 0x0, + Collisions: 0x0, + RXLengthErrors: 0x0, + RXOverErrors: 0x0, + RXCRCErrors: 0x0, + RXFrameErrors: 0x0, + RXFIFOErrors: 0x0, + RXMissedErrors: 0x0, + TXAbortedErrors: 0x0, + TXCarrierErrors: 0x0, + TXFIFOErrors: 0x0, + TXHeartbeatErrors: 0x0, + TXWindowErrors: 0x0, + RXCompressed: 0x0, + TXCompressed: 0x0, + RXNoHandler: 0x1, + RXOtherhostDropped: 0x2, }, }, }