netstack: remove PacketBuffer.IsNil()

The change was originally motivated by ticket references (cl/450976957), which
were never implemented.

PiperOrigin-RevId: 617480960
This commit is contained in:
Kevin Krakauer
2024-03-20 05:31:48 -07:00
committed by gVisor bot
parent 5a6aadda2f
commit 3c75945fd6
40 changed files with 208 additions and 213 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ func (e *Endpoint) ReadContext(ctx context.Context) *stack.PacketBuffer {
// Drain removes all outbound packets from the channel and counts them.
func (e *Endpoint) Drain() int {
c := 0
for pkt := e.Read(); !pkt.IsNil(); pkt = e.Read() {
for pkt := e.Read(); pkt != nil; pkt = e.Read() {
pkt.DecRef()
c++
}
+1 -1
View File
@@ -193,7 +193,7 @@ func TestWritePacketToRemoteAddHeader(t *testing.T) {
{
pkt := c.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected to read a packet")
}
+1 -1
View File
@@ -62,7 +62,7 @@ func checkPacketInfoEqual(t *testing.T, got, want packetInfo) {
if diff := cmp.Diff(
want, got,
cmp.Transformer("ExtractPacketBuffer", func(pk *stack.PacketBuffer) *packetContents {
if pk.IsNil() {
if pk == nil {
return nil
}
return &packetContents{
@@ -76,10 +76,10 @@ type testNetworkDispatcher struct {
}
func (t *testNetworkDispatcher) reset() {
if pkt := t.linkPacket.pkt; !pkt.IsNil() {
if pkt := t.linkPacket.pkt; pkt != nil {
pkt.DecRef()
}
if pkt := t.networkPacket.pkt; !pkt.IsNil() {
if pkt := t.networkPacket.pkt; pkt != nil {
pkt.DecRef()
}
+2 -2
View File
@@ -97,7 +97,7 @@ func (qd *queueDispatcher) dispatchLoop() {
case &qd.newPacketWaker:
case &qd.closeWaker:
qd.mu.Lock()
for p := qd.queue.removeFront(); !p.IsNil(); p = qd.queue.removeFront() {
for p := qd.queue.removeFront(); p != nil; p = qd.queue.removeFront() {
p.DecRef()
}
qd.queue.decRef()
@@ -107,7 +107,7 @@ func (qd *queueDispatcher) dispatchLoop() {
panic("unknown waker")
}
qd.mu.Lock()
for pkt := qd.queue.removeFront(); !pkt.IsNil(); pkt = qd.queue.removeFront() {
for pkt := qd.queue.removeFront(); pkt != nil; pkt = qd.queue.removeFront() {
batch.PushBack(pkt)
if batch.Len() < BatchSize && !qd.queue.isEmpty() {
continue
+1 -1
View File
@@ -262,7 +262,7 @@ func (d *Device) Read() (*buffer.View, error) {
}
pkt := endpoint.Read()
if pkt.IsNil() {
if pkt == nil {
return nil, linuxerr.ErrWouldBlock
}
v := d.encodePkt(pkt)
+4 -4
View File
@@ -319,7 +319,7 @@ func TestDirectRequest(t *testing.T) {
// No packets should be sent after receiving an invalid ARP request.
// There is no need to perform a blocking read here, since packets are
// sent in the same function that handles ARP requests.
if pkt := c.linkEP.Read(); !pkt.IsNil() {
if pkt := c.linkEP.Read(); pkt != nil {
t.Errorf("unexpected packet sent: %+v", pkt)
}
if got, want := c.s.Stats().ARP.RequestsReceivedUnknownTargetAddress.Value(), requestsRecvUnknownAddr+1; got != want {
@@ -338,7 +338,7 @@ func TestDirectRequest(t *testing.T) {
// Verify an ARP response was sent.
pi := c.linkEP.Read()
if pi.IsNil() {
if pi == nil {
t.Fatal("expected ARP response to be sent, got none")
}
@@ -714,7 +714,7 @@ func TestLinkAddressRequest(t *testing.T) {
}
pkt := linkEP.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected to send a link address request")
}
@@ -773,7 +773,7 @@ func TestDADARPRequestPacket(t *testing.T) {
clock.RunImmediatelyScheduledJobs()
pkt := e.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected to send an ARP request")
}
@@ -251,12 +251,12 @@ func (f *Fragmentation) release(r *reassembler, timedOut bool) {
if h := f.timeoutHandler; timedOut && h != nil {
h.OnReassemblyTimeout(r.pkt)
}
if !r.pkt.IsNil() {
if r.pkt != nil {
r.pkt.DecRef()
r.pkt = nil
}
for _, h := range r.holes {
if !h.pkt.IsNil() {
if h.pkt != nil {
h.pkt.DecRef()
h.pkt = nil
}
@@ -117,7 +117,7 @@ func TestFragmentationProcess(t *testing.T) {
defer in.pkt.DecRef()
defer c.out[i].buf.Release()
resPkt, proto, done, err := f.Process(in.id, in.first, in.last, in.more, in.proto, in.pkt)
if !resPkt.IsNil() {
if resPkt != nil {
defer resPkt.DecRef()
}
if err != nil {
@@ -267,7 +267,7 @@ func TestReassemblingTimeout(t *testing.T) {
p := pkt(len(frag.data), frag.data)
defer p.DecRef()
pkt, _, done, err := f.Process(FragmentID{}, frag.first, frag.last, frag.more, protocol, p)
if !pkt.IsNil() {
if pkt != nil {
pkt.DecRef()
}
if err != nil {
@@ -450,7 +450,7 @@ func TestErrors(t *testing.T) {
f := NewFragmentation(test.blockSize, HighFragThreshold, LowFragThreshold, reassembleTimeout, c, nil)
resPkt, _, done, err := f.Process(FragmentID{}, test.first, test.last, test.more, 0, p0)
if !resPkt.IsNil() {
if resPkt != nil {
resPkt.DecRef()
}
if !errors.Is(err, test.err) {
@@ -689,11 +689,11 @@ func TestTimeoutHandler(t *testing.T) {
f.release(r, true)
}
switch {
case !handler.pkt.IsNil() && test.wantPkt.IsNil():
case handler.pkt != nil && test.wantPkt == nil:
t.Errorf("got handler.pkt = not nil (pkt.Data = %x), want = nil", handler.pkt.Data().AsRange().ToSlice())
case handler.pkt.IsNil() && !test.wantPkt.IsNil():
case handler.pkt == nil && test.wantPkt != nil:
t.Errorf("got handler.pkt = nil, want = not nil (pkt.Data = %x)", test.wantPkt.Data().AsRange().ToSlice())
case !handler.pkt.IsNil() && !test.wantPkt.IsNil():
case handler.pkt != nil && test.wantPkt != nil:
if diff := cmp.Diff(test.wantPkt.Data().AsRange().ToSlice(), handler.pkt.Data().AsRange().ToSlice()); diff != "" {
t.Errorf("pkt.Data mismatch (-want, +got):\n%s", diff)
}
@@ -145,7 +145,7 @@ func (r *reassembler) process(first, last uint16, more bool, proto uint8, pkt *s
// options received in the first fragment should be used - and they should
// override options from following fragments.
if first == 0 {
if !r.pkt.IsNil() {
if r.pkt != nil {
r.pkt.DecRef()
}
r.pkt = pkt.IncRef()
@@ -191,11 +191,11 @@ func TestReassemblerProcess(t *testing.T) {
// reassembler will leak PacketBuffers.
defer func() {
for _, h := range r.holes {
if !h.pkt.IsNil() {
if h.pkt != nil {
h.pkt.DecRef()
}
}
if !r.pkt.IsNil() {
if r.pkt != nil {
r.pkt.DecRef()
}
}()
@@ -203,7 +203,7 @@ func TestReassemblerProcess(t *testing.T) {
var isDone bool
for _, param := range test.params {
pkt, _, done, _, err := r.process(param.first, param.last, param.more, proto, param.pkt)
if !pkt.IsNil() {
if pkt != nil {
defer pkt.DecRef()
}
if done != param.wantDone || err != param.wantError {
@@ -217,7 +217,7 @@ func TestReassemblerProcess(t *testing.T) {
ignorePkt := func(a, b *stack.PacketBuffer) bool { return true }
cmpPktData := func(a, b *stack.PacketBuffer) bool {
if a.IsNil() || b.IsNil() {
if a == nil || b == nil {
return a == b
}
return bytes.Equal(a.Data().AsRange().ToSlice(), b.Data().AsRange().ToSlice())
@@ -246,16 +246,16 @@ func TestReassemblerProcess(t *testing.T) {
}
})
for _, p := range test.params {
if !p.pkt.IsNil() {
if p.pkt != nil {
p.pkt.DecRef()
}
}
for _, w := range test.want {
if !w.pkt.IsNil() {
if w.pkt != nil {
w.pkt.DecRef()
}
}
if !test.wantPkt.IsNil() {
if test.wantPkt != nil {
test.wantPkt.DecRef()
}
}
@@ -234,7 +234,7 @@ func ValidateIGMPv3RecordsAcrossReports(t *testing.T, e *channel.Endpoint, srcAd
for len(expectedRecords) != 0 {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected IGMP message with expectedRecords = %#v", expectedRecords)
}
v := stack.PayloadSince(p.NetworkHeader())
@@ -265,7 +265,7 @@ func ValidMultipleIGMPv2ReportLeaves(t *testing.T, e *channel.Endpoint, srcAddr
for len(expectedGroups) != 0 {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected IGMP message with expectedGroups = %#v", expectedGroups)
}
v := stack.PayloadSince(p.NetworkHeader())
@@ -334,7 +334,7 @@ func ValidateMLDv2RecordsAcrossReports(t *testing.T, e *channel.Endpoint, srcAdd
for len(expectedRecords) != 0 {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected MLD Message with expectedRecords = %#v", expectedRecords)
}
v := stack.PayloadSince(p.NetworkHeader())
@@ -365,7 +365,7 @@ func ValidMultipleMLDv1ReportLeaves(t *testing.T, e *channel.Endpoint, srcAddr t
for len(expectedGroups) != 0 {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected MLD Message with expectedGroups = %#v", expectedGroups)
}
v := stack.PayloadSince(p.NetworkHeader())
+2 -2
View File
@@ -1799,7 +1799,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
}
pkt := e.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected a packet to be written")
}
test.checker(t, pkt, subTest.srcAddr)
@@ -2055,7 +2055,7 @@ func TestICMPInclusionSize(t *testing.T) {
})
v := test.injector(e, test.srcAddress, payload)
pkt := e.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected a packet to be written")
}
if got, want := pkt.Size(), test.replyLength; got != want {
+1 -1
View File
@@ -816,7 +816,7 @@ func (p *protocol) OnReassemblyTimeout(pkt *stack.PacketBuffer) {
//
// If fragment zero is not available then no time exceeded need be sent at
// all.
if !pkt.IsNil() {
if pkt != nil {
p.returnError(&icmpReasonReassemblyTimeout{}, pkt, true /* deliveredLocally */)
}
}
+10 -10
View File
@@ -174,7 +174,7 @@ func TestIGMPV1Present(t *testing.T) {
// the IGMPv1 General Membership Query in.
{
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatal("unable to Read IGMP packet, expected V3MembershipReport")
}
if got := s.Stats().IGMP.PacketsSent.V3MembershipReport.Value(); got != 1 {
@@ -203,13 +203,13 @@ func TestIGMPV1Present(t *testing.T) {
// Verify the solicited Membership Report is sent. Now that this NIC has seen
// an IGMPv1 query, it should send an IGMPv1 Membership Report.
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Fatalf("sent unexpected packet, expected V1MembershipReport only after advancing the clock = %+v", p)
}
ctx.clock.Advance(ipv4.UnsolicitedReportIntervalMax)
{
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatal("unable to Read IGMP packet, expected V1MembershipReport")
}
if got := s.Stats().IGMP.PacketsSent.V1MembershipReport.Value(); got != 1 {
@@ -228,7 +228,7 @@ func TestIGMPV1Present(t *testing.T) {
}
{
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatal("unable to Read IGMP packet, expected V2MembershipReport")
}
if got := s.Stats().IGMP.PacketsSent.V3MembershipReport.Value(); got != 2 {
@@ -322,7 +322,7 @@ func TestSendQueuedIGMPReports(t *testing.T) {
}
}
test.checkStats(t, s, reportCounter, doneCounter, reportV2Counter)
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Fatalf("got unexpected packet = %#v", p)
}
@@ -358,7 +358,7 @@ func TestSendQueuedIGMPReports(t *testing.T) {
// Should have no more packets to send after the initial set of unsolicited
// reports.
clock.Advance(time.Hour)
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Fatalf("got unexpected packet = %#v", p)
}
})
@@ -540,7 +540,7 @@ func TestGetSetIGMPVersion(t *testing.T) {
if err := s.JoinGroup(ipv4.ProtocolNumber, nicID, multicastAddr1); err != nil {
t.Fatalf("JoinGroup(ipv4, nic, %s) = %s", multicastAddr1, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateIgmpv3ReportPacket(t, p, stackAddr, multicastAddr1)
@@ -556,7 +556,7 @@ func TestGetSetIGMPVersion(t *testing.T) {
if err := s.JoinGroup(ipv4.ProtocolNumber, nicID, multicastAddr2); err != nil {
t.Fatalf("JoinGroup(ipv4, nic, %s) = %s", multicastAddr2, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateIgmpPacket(t, p, header.IGMPv2MembershipReport, 0, stackAddr, multicastAddr2, multicastAddr2)
@@ -572,7 +572,7 @@ func TestGetSetIGMPVersion(t *testing.T) {
if err := s.JoinGroup(ipv4.ProtocolNumber, nicID, multicastAddr3); err != nil {
t.Fatalf("JoinGroup(ipv4, nic, %s) = %s", multicastAddr3, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateIgmpPacket(t, p, header.IGMPv1MembershipReport, 0, stackAddr, multicastAddr3, multicastAddr3)
@@ -588,7 +588,7 @@ func TestGetSetIGMPVersion(t *testing.T) {
if err := s.JoinGroup(ipv4.ProtocolNumber, nicID, multicastAddr4); err != nil {
t.Fatalf("JoinGroup(ipv4, nic, %s) = %s", multicastAddr4, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateIgmpv3ReportPacket(t, p, stackAddr, multicastAddr4)
+22 -22
View File
@@ -319,7 +319,7 @@ func checkFragements(t *testing.T, ep *channel.Endpoint, expectedFragments []fra
var fragmentedPackets []*stack.PacketBuffer
for i := 0; i < len(expectedFragments); i++ {
reply := ep.Read()
if reply.IsNil() {
if reply == nil {
t.Fatal("Expected ICMP Echo fragment through outgoing NIC")
}
fragmentedPackets = append(fragmentedPackets, reply)
@@ -563,7 +563,7 @@ func TestForwarding(t *testing.T) {
reply := incomingEndpoint.Read()
if test.icmpError != nil {
if reply.IsNil() {
if reply == nil {
t.Fatalf("Expected ICMP packet type %d through incoming NIC", test.icmpError.icmpType)
}
@@ -581,7 +581,7 @@ func TestForwarding(t *testing.T) {
),
)
reply.DecRef()
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
@@ -592,7 +592,7 @@ func TestForwarding(t *testing.T) {
if test.expectPacketForwarded {
reply := outgoingEndpoint.Read()
if reply.IsNil() {
if reply == nil {
t.Fatal("Expected ICMP Echo packet through outgoing NIC")
}
@@ -612,7 +612,7 @@ func TestForwarding(t *testing.T) {
)
reply.DecRef()
} else {
if reply := outgoingEndpoint.Read(); !reply.IsNil() {
if reply := outgoingEndpoint.Read(); reply != nil {
t.Fatalf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
}
@@ -753,7 +753,7 @@ func TestFragmentForwarding(t *testing.T) {
reply := incomingEndpoint.Read()
if test.icmpError != nil {
if reply.IsNil() {
if reply == nil {
t.Fatalf("Expected ICMP packet type %d through incoming NIC", test.icmpError.icmpType)
}
@@ -771,7 +771,7 @@ func TestFragmentForwarding(t *testing.T) {
),
)
reply.DecRef()
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
@@ -783,7 +783,7 @@ func TestFragmentForwarding(t *testing.T) {
if len(test.expectedFragmentsForwarded) > 0 {
checkFragements(t, outgoingEndpoint, test.expectedFragmentsForwarded, requestPkt)
} else {
if reply := outgoingEndpoint.Read(); !reply.IsNil() {
if reply := outgoingEndpoint.Read(); reply != nil {
t.Errorf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
}
@@ -919,7 +919,7 @@ func TestMulticastFragmentForwarding(t *testing.T) {
incomingEndpoint.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
reply := incomingEndpoint.Read()
if !reply.IsNil() {
if reply != nil {
// An ICMP error should never be sent in response to a multicast packet.
t.Errorf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
@@ -932,7 +932,7 @@ func TestMulticastFragmentForwarding(t *testing.T) {
if len(test.expectedFragmentsForwarded) > 0 {
checkFragements(t, outgoingEndpoint, test.expectedFragmentsForwarded, requestPkt)
} else {
if reply := outgoingEndpoint.Read(); !reply.IsNil() {
if reply := outgoingEndpoint.Read(); reply != nil {
t.Errorf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
}
@@ -1084,7 +1084,7 @@ func TestMulticastForwardingOptions(t *testing.T) {
incomingEndpoint.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
reply := incomingEndpoint.Read()
if !reply.IsNil() {
if reply != nil {
// An ICMP error should never be sent in response to a multicast packet.
t.Errorf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
@@ -1096,7 +1096,7 @@ func TestMulticastForwardingOptions(t *testing.T) {
if test.expectPacketForwarded {
reply := outgoingEndpoint.Read()
if reply.IsNil() {
if reply == nil {
t.Fatal("Expected ICMP Echo packet through outgoing NIC")
}
@@ -1116,7 +1116,7 @@ func TestMulticastForwardingOptions(t *testing.T) {
)
reply.DecRef()
} else {
if reply := outgoingEndpoint.Read(); !reply.IsNil() {
if reply := outgoingEndpoint.Read(); reply != nil {
t.Fatalf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
}
@@ -1837,7 +1837,7 @@ func TestIPv4Sanity(t *testing.T) {
defer requestPkt.DecRef()
e.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
reply := e.Read()
if reply.IsNil() {
if reply == nil {
if test.shouldFail {
if test.expectErrorICMP {
t.Fatalf("ICMP error response (type %d, code %d) missing", test.ICMPType, test.ICMPCode)
@@ -2812,12 +2812,12 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
reply := e.Read()
if !test.expectICMP {
if !reply.IsNil() {
if reply != nil {
t.Fatalf("unexpected ICMP error message received: %#v", reply)
}
return
}
if reply.IsNil() {
if reply == nil {
t.Fatal("expected ICMP error message missing")
}
if firstFragmentSent.Size() == 0 {
@@ -3605,7 +3605,7 @@ func TestPacketQueuing(t *testing.T) {
},
checkResp: func(t *testing.T, e *channel.Endpoint) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
defer p.DecRef()
@@ -3653,7 +3653,7 @@ func TestPacketQueuing(t *testing.T) {
},
checkResp: func(t *testing.T, e *channel.Endpoint) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
defer p.DecRef()
@@ -3707,7 +3707,7 @@ func TestPacketQueuing(t *testing.T) {
{
clock.RunImmediatelyScheduledJobs()
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
if p.NetworkProtocolNumber != arp.ProtocolNumber {
@@ -3952,7 +3952,7 @@ func TestIcmpRateLimit(t *testing.T) {
},
check: func(t *testing.T, e *channel.Endpoint, round int) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected echo response, no packet read in endpoint in round %d", round)
}
defer p.DecRef()
@@ -3994,13 +3994,13 @@ func TestIcmpRateLimit(t *testing.T) {
check: func(t *testing.T, e *channel.Endpoint, round int) {
p := e.Read()
if round >= icmpBurst {
if !p.IsNil() {
if p != nil {
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Data().AsRange().ToSlice(), round)
p.DecRef()
}
return
}
if p.IsNil() {
if p == nil {
t.Fatalf("expected unreachable in round %d, no packet read in endpoint", round)
}
defer p.DecRef()
+1 -1
View File
@@ -1225,7 +1225,7 @@ func (p *protocol) OnReassemblyTimeout(pkt *stack.PacketBuffer) {
// If the first fragment (i.e., the one with a Fragment Offset of zero) has
// been received, an ICMP Time Exceeded -- Fragment Reassembly Time Exceeded
// message should be sent to the source of that fragment.
if !pkt.IsNil() {
if pkt != nil {
p.returnError(&icmpReasonReassemblyTimeout{}, pkt, true /* deliveredLocally */)
}
}
+5 -5
View File
@@ -527,7 +527,7 @@ func routeICMPv6Packet(t *testing.T, clock *faketime.ManualClock, args routeArgs
clock.RunImmediatelyScheduledJobs()
pi := args.src.Read()
if pi.IsNil() {
if pi == nil {
t.Fatal("packet didn't arrive")
}
defer pi.DecRef()
@@ -1347,7 +1347,7 @@ func TestLinkAddressRequest(t *testing.T) {
}
pkt := linkEP.Read()
if pkt.IsNil() {
if pkt == nil {
t.Fatal("expected to send a link address request")
}
defer pkt.DecRef()
@@ -1431,7 +1431,7 @@ func TestPacketQueing(t *testing.T) {
},
checkResp: func(t *testing.T, e *channel.Endpoint) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
defer p.DecRef()
@@ -1482,7 +1482,7 @@ func TestPacketQueing(t *testing.T) {
},
checkResp: func(t *testing.T, e *channel.Endpoint) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
defer p.DecRef()
@@ -1537,7 +1537,7 @@ func TestPacketQueing(t *testing.T) {
{
c.clock.RunImmediatelyScheduledJobs()
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("timed out waiting for packet")
}
if p.NetworkProtocolNumber != ProtocolNumber {
+17 -17
View File
@@ -1035,7 +1035,7 @@ func TestReceiveIPv6ExtHdrs(t *testing.T) {
}
if !test.expectICMP {
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Fatalf("unexpected packet received: %#v", p)
}
return
@@ -1043,7 +1043,7 @@ func TestReceiveIPv6ExtHdrs(t *testing.T) {
// ICMP required.
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected packet wasn't written out")
}
defer p.DecRef()
@@ -2197,12 +2197,12 @@ func TestInvalidIPv6Fragments(t *testing.T) {
reply := e.Read()
if !test.expectICMP {
if !reply.IsNil() {
if reply != nil {
t.Fatalf("unexpected ICMP error message received: %#v", reply)
}
return
}
if reply.IsNil() {
if reply == nil {
t.Fatal("expected ICMP error message missing")
}
@@ -2453,12 +2453,12 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
reply := e.Read()
if !test.expectICMP {
if !reply.IsNil() {
if reply != nil {
t.Fatalf("unexpected ICMP error message received: %#v", reply)
}
return
}
if reply.IsNil() {
if reply == nil {
t.Fatal("expected ICMP error message missing")
}
if firstFragmentSent == nil {
@@ -3290,7 +3290,7 @@ func TestForwarding(t *testing.T) {
}
if test.expectedICMPError != nil {
if reply.IsNil() {
if reply == nil {
t.Fatalf("Expected ICMP packet type %d through incoming NIC", test.expectedICMPError.icmpType)
}
@@ -3324,13 +3324,13 @@ func TestForwarding(t *testing.T) {
if n := outgoingEndpoint.Drain(); n != 0 {
t.Fatalf("e2.Drain() = %d, want = 0", n)
}
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
reply = outgoingEndpoint.Read()
if test.expectPacketForwarded {
if reply.IsNil() {
if reply == nil {
t.Fatal("Expected ICMP Echo Request packet through outgoing NIC")
}
@@ -3352,7 +3352,7 @@ func TestForwarding(t *testing.T) {
if n := incomingEndpoint.Drain(); n != 0 {
t.Fatalf("e1.Drain() = %d, want = 0", n)
}
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
@@ -3625,7 +3625,7 @@ func TestMulticastForwarding(t *testing.T) {
}
if test.expectedICMPError != nil {
if reply.IsNil() {
if reply == nil {
t.Fatalf("Expected ICMP packet type %d through incoming NIC", test.expectedICMPError.icmpType)
}
@@ -3659,13 +3659,13 @@ func TestMulticastForwarding(t *testing.T) {
if n := outgoingEndpoint.Drain(); n != 0 {
t.Fatalf("e2.Drain() = %d, want = 0", n)
}
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP packet through incoming NIC, instead found: %#v", reply)
}
reply = outgoingEndpoint.Read()
if test.expectPacketForwarded {
if reply.IsNil() {
if reply == nil {
t.Fatal("Expected ICMP Echo Request packet through outgoing NIC")
}
@@ -3687,7 +3687,7 @@ func TestMulticastForwarding(t *testing.T) {
if n := incomingEndpoint.Drain(); n != 0 {
t.Fatalf("e1.Drain() = %d, want = 0", n)
}
} else if !reply.IsNil() {
} else if reply != nil {
t.Fatalf("Expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
}
@@ -3806,7 +3806,7 @@ func TestIcmpRateLimit(t *testing.T) {
},
check: func(t *testing.T, e *channel.Endpoint, round int) {
p := e.Read()
if p.IsNil() {
if p == nil {
t.Fatalf("expected echo response, no packet read in endpoint in round %d", round)
}
defer p.DecRef()
@@ -3854,13 +3854,13 @@ func TestIcmpRateLimit(t *testing.T) {
check: func(t *testing.T, e *channel.Endpoint, round int) {
p := e.Read()
if round >= icmpBurst {
if !p.IsNil() {
if p != nil {
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Data().AsRange().ToSlice(), round)
p.DecRef()
}
return
}
if p.IsNil() {
if p == nil {
t.Fatalf("expected unreachable in round %d, no packet read in endpoint", round)
}
payload := stack.PayloadSince(p.NetworkHeader())
+12 -12
View File
@@ -170,7 +170,7 @@ func TestIPv6JoinLeaveSolicitedNodeAddressPerformsMLD(t *testing.T) {
if err := s.AddProtocolAddress(nicID, protocolAddr, stack.AddressProperties{}); err != nil {
t.Fatalf("AddProtocolAddress(%d, %+v, {}): %s", nicID, protocolAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
test.validate(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, false /* leave */)
@@ -183,7 +183,7 @@ func TestIPv6JoinLeaveSolicitedNodeAddressPerformsMLD(t *testing.T) {
if err := s.RemoveAddress(nicID, linkLocalAddr); err != nil {
t.Fatalf("RemoveAddress(%d, %s) = %s", nicID, linkLocalAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a done message to be sent")
} else {
test.validate(t, stack.PayloadSince(p.NetworkHeader()), header.IPv6Any, linkLocalAddrSNMC, true /* leave */)
@@ -281,7 +281,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
resolveDAD := func(addr, snmc tcpip.Address) {
t.Helper()
clock.Advance(dadResolutionTime)
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected DAD packet")
} else {
payload := stack.PayloadSince(p.NetworkHeader())
@@ -313,7 +313,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
subTest.checkStats(t, s, reportCounter, doneCounter, reportV2Counter)
subTest.validate(t, e, header.IPv6Any, []tcpip.Address{globalMulticastAddr}, false /* leave */)
clock.Advance(time.Hour)
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Errorf("got unexpected packet = %#v", p)
p.DecRef()
}
@@ -355,7 +355,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
subTest.validate(t, e, header.IPv6Any, []tcpip.Address{globalAddrSNMC}, true /* leave */)
}
subTest.checkStats(t, s, reportCounter, doneCounter, reportV2Counter)
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Errorf("got unexpected packet = %#v", p)
p.DecRef()
}
@@ -407,7 +407,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
// Should not send any more reports.
clock.Advance(time.Hour)
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Errorf("got unexpected packet = %#v", p)
p.DecRef()
}
@@ -706,7 +706,7 @@ func TestMLDSkipProtocol(t *testing.T) {
if err := s.AddProtocolAddress(nicID, protocolAddr, stack.AddressProperties{}); err != nil {
t.Fatalf("AddProtocolAddress(%d, %+v, {}): %s", nicID, protocolAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
subTest.validate(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC)
@@ -724,14 +724,14 @@ func TestMLDSkipProtocol(t *testing.T) {
}
if !test.expectReport {
if p := e.Read(); !p.IsNil() {
if p := e.Read(); p != nil {
t.Fatalf("got e.Read() = (%#v, true), want = (_, false)", p)
}
return
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
subTest.validate(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, testGroup)
@@ -776,7 +776,7 @@ func TestGetSetMLDVersion(t *testing.T) {
if err := s.AddProtocolAddress(nicID, protocolAddr, stack.AddressProperties{}); err != nil {
t.Fatalf("AddProtocolAddress(%d, %+v, {}): %s", nicID, protocolAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateMLDv2ReportPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, header.MLDv2ReportRecordChangeToExcludeMode)
@@ -792,7 +792,7 @@ func TestGetSetMLDVersion(t *testing.T) {
if err := s.JoinGroup(ipv6.ProtocolNumber, nicID, globalMulticastAddr); err != nil {
t.Fatalf("s.JoinGroup(%d, %d, %s): %s", ipv6.ProtocolNumber, nicID, globalMulticastAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, globalMulticastAddr, header.ICMPv6MulticastListenerReport, globalMulticastAddr)
@@ -808,7 +808,7 @@ func TestGetSetMLDVersion(t *testing.T) {
if err := s.LeaveGroup(ipv6.ProtocolNumber, nicID, globalMulticastAddr); err != nil {
t.Fatalf("s.LeaveGroup(%d, %d, %s): %s", ipv6.ProtocolNumber, nicID, globalMulticastAddr, err)
}
if p := e.Read(); p.IsNil() {
if p := e.Read(); p == nil {
t.Fatal("expected a report message to be sent")
} else {
validateMLDv2ReportPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, globalMulticastAddr, header.MLDv2ReportRecordChangeToIncludeMode)

Some files were not shown because too many files have changed in this diff Show More