@@ -16,7 +16,6 @@ package ovsnl
1616
1717import (
1818 "encoding/binary"
19- "fmt"
2019
2120 "github.com/digitalocean/go-openvswitch/ovsnl/internal/ovsh"
2221 "github.com/mdlayher/genetlink"
@@ -139,8 +138,9 @@ func parseDatapaths(msgs []genetlink.Message) ([]Datapath, error) {
139138 Index : int (h .Ifindex ),
140139 }
141140
142- // Skip the header to parse attributes.
143- attrs , err := netlink .UnmarshalAttributes (m .Data [sizeofHeader :])
141+ // Skip past the header to parse attributes.
142+ hdrSize := binary .Size (h )
143+ attrs , err := netlink .UnmarshalAttributes (m .Data [hdrSize :])
144144 if err != nil {
145145 return nil , err
146146 }
@@ -170,20 +170,8 @@ func parseDatapaths(msgs []genetlink.Message) ([]Datapath, error) {
170170 return dps , nil
171171}
172172
173- // Sizes of various structures, used for safety checks during unmarshaling.
174- var (
175- sizeofHeader = binary .Size (ovsh.Header {})
176- sizeofDPStats = binary .Size ((ovsh.DPStats {}))
177- sizeofDPMegaflowStats = binary .Size ((ovsh.DPMegaflowStats {}))
178- )
179-
180173// parseDPStats converts a byte slice into DatapathStats.
181174func parseDPStats (b []byte ) (DatapathStats , error ) {
182- // Verify that the byte slice is the correct length before unmarshaling.
183- if want , got := sizeofDPStats , len (b ); want != got {
184- return DatapathStats {}, fmt .Errorf ("unexpected datapath stats structure size, want %d, got %d" , want , got )
185- }
186-
187175 s := new (ovsh.DPStats )
188176 err := ovsh .UnmarshalBinary (b , s )
189177 if err != nil {
@@ -200,11 +188,6 @@ func parseDPStats(b []byte) (DatapathStats, error) {
200188
201189// parseDPMegaflowStats converts a byte slice into DatapathMegaflowStats.
202190func parseDPMegaflowStats (b []byte ) (DatapathMegaflowStats , error ) {
203- // Verify that the byte slice is the correct length before unmarshaling.
204- if want , got := sizeofDPMegaflowStats , len (b ); want != got {
205- return DatapathMegaflowStats {}, fmt .Errorf ("unexpected datapath megaflow stats structure size, want %d, got %d" , want , got )
206- }
207-
208191 s := new (ovsh.DPMegaflowStats )
209192 err := ovsh .UnmarshalBinary (b , s )
210193 if err != nil {
@@ -219,11 +202,6 @@ func parseDPMegaflowStats(b []byte) (DatapathMegaflowStats, error) {
219202
220203// parseHeader converts a byte slice into ovsh.Header.
221204func parseHeader (b []byte ) (ovsh.Header , error ) {
222- // Verify we have enough data for what we are expecting before unmarshaling.
223- if l := len (b ); l < sizeofHeader {
224- return ovsh.Header {}, fmt .Errorf ("not enough data for OVS message header: %d bytes" , l )
225- }
226-
227205 h := new (ovsh.Header )
228206 err := ovsh .UnmarshalBinary (b , h )
229207 if err != nil {
0 commit comments