From 0e013d8b00dbc3ad96e98bc0405ec2e21887308e Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 21 Apr 2020 16:54:08 -0700 Subject: Don't ignore override if it is longer than layerStates PiperOrigin-RevId: 307708653 --- test/packetimpact/testbench/connections.go | 33 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'test/packetimpact/testbench/connections.go') diff --git a/test/packetimpact/testbench/connections.go b/test/packetimpact/testbench/connections.go index f84fd8ba7..00a366894 100644 --- a/test/packetimpact/testbench/connections.go +++ b/test/packetimpact/testbench/connections.go @@ -363,16 +363,33 @@ type Connection struct { // reverse is never a match. override overrides the default matchers for each // Layer. func (conn *Connection) match(override, received Layers) bool { - if len(received) < len(conn.layerStates) { + var layersToMatch int + if len(override) < len(conn.layerStates) { + layersToMatch = len(conn.layerStates) + } else { + layersToMatch = len(override) + } + if len(received) < layersToMatch { return false } - for i, s := range conn.layerStates { - toMatch := s.incoming(received[i]) - if toMatch == nil { - return false - } - if i < len(override) { - toMatch.merge(override[i]) + for i := 0; i < layersToMatch; i++ { + var toMatch Layer + if i < len(conn.layerStates) { + s := conn.layerStates[i] + toMatch = s.incoming(received[i]) + if toMatch == nil { + return false + } + if i < len(override) { + if err := toMatch.merge(override[i]); err != nil { + conn.t.Fatalf("failed to merge: %s", err) + } + } + } else { + toMatch = override[i] + if toMatch == nil { + conn.t.Fatalf("expect the overriding layers to be non-nil") + } } if !toMatch.match(received[i]) { return false -- cgit v1.2.3