diff --git a/pkg/tcpip/link/channel/channel.go b/pkg/tcpip/link/channel/channel.go index 4c21fec47..3ea016cbb 100644 --- a/pkg/tcpip/link/channel/channel.go +++ b/pkg/tcpip/link/channel/channel.go @@ -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++ } diff --git a/pkg/tcpip/link/ethernet/ethernet_test.go b/pkg/tcpip/link/ethernet/ethernet_test.go index 014183fe3..832dbbe1d 100644 --- a/pkg/tcpip/link/ethernet/ethernet_test.go +++ b/pkg/tcpip/link/ethernet/ethernet_test.go @@ -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") } diff --git a/pkg/tcpip/link/fdbased/endpoint_test.go b/pkg/tcpip/link/fdbased/endpoint_test.go index 3081eb406..3edd2f3f6 100644 --- a/pkg/tcpip/link/fdbased/endpoint_test.go +++ b/pkg/tcpip/link/fdbased/endpoint_test.go @@ -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{ diff --git a/pkg/tcpip/link/packetsocket/packetsocket_test.go b/pkg/tcpip/link/packetsocket/packetsocket_test.go index df086356e..b715c19f5 100644 --- a/pkg/tcpip/link/packetsocket/packetsocket_test.go +++ b/pkg/tcpip/link/packetsocket/packetsocket_test.go @@ -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() } diff --git a/pkg/tcpip/link/qdisc/fifo/fifo.go b/pkg/tcpip/link/qdisc/fifo/fifo.go index 299fc08f0..1d917f3c1 100644 --- a/pkg/tcpip/link/qdisc/fifo/fifo.go +++ b/pkg/tcpip/link/qdisc/fifo/fifo.go @@ -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 diff --git a/pkg/tcpip/link/tun/device.go b/pkg/tcpip/link/tun/device.go index 070338f7a..4bb74640b 100644 --- a/pkg/tcpip/link/tun/device.go +++ b/pkg/tcpip/link/tun/device.go @@ -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) diff --git a/pkg/tcpip/network/arp/arp_test.go b/pkg/tcpip/network/arp/arp_test.go index b3a874973..0bc875982 100644 --- a/pkg/tcpip/network/arp/arp_test.go +++ b/pkg/tcpip/network/arp/arp_test.go @@ -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") } diff --git a/pkg/tcpip/network/internal/fragmentation/fragmentation.go b/pkg/tcpip/network/internal/fragmentation/fragmentation.go index 22f5806cf..b7d3c6741 100644 --- a/pkg/tcpip/network/internal/fragmentation/fragmentation.go +++ b/pkg/tcpip/network/internal/fragmentation/fragmentation.go @@ -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 } diff --git a/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go b/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go index f73da9be1..4dc5ddfd5 100644 --- a/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go +++ b/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go @@ -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) } diff --git a/pkg/tcpip/network/internal/fragmentation/reassembler.go b/pkg/tcpip/network/internal/fragmentation/reassembler.go index 42c42e082..59fea4bbe 100644 --- a/pkg/tcpip/network/internal/fragmentation/reassembler.go +++ b/pkg/tcpip/network/internal/fragmentation/reassembler.go @@ -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() diff --git a/pkg/tcpip/network/internal/fragmentation/reassembler_test.go b/pkg/tcpip/network/internal/fragmentation/reassembler_test.go index c189d484b..943bfd275 100644 --- a/pkg/tcpip/network/internal/fragmentation/reassembler_test.go +++ b/pkg/tcpip/network/internal/fragmentation/reassembler_test.go @@ -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() } } diff --git a/pkg/tcpip/network/internal/testutil/testutil.go b/pkg/tcpip/network/internal/testutil/testutil.go index 0bbba1116..638adeadd 100644 --- a/pkg/tcpip/network/internal/testutil/testutil.go +++ b/pkg/tcpip/network/internal/testutil/testutil.go @@ -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()) diff --git a/pkg/tcpip/network/ip_test.go b/pkg/tcpip/network/ip_test.go index 7224107c1..9ba4c2d1f 100644 --- a/pkg/tcpip/network/ip_test.go +++ b/pkg/tcpip/network/ip_test.go @@ -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 { diff --git a/pkg/tcpip/network/ipv4/icmp.go b/pkg/tcpip/network/ipv4/icmp.go index 09e500bc9..b6da8bd40 100644 --- a/pkg/tcpip/network/ipv4/icmp.go +++ b/pkg/tcpip/network/ipv4/icmp.go @@ -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 */) } } diff --git a/pkg/tcpip/network/ipv4/igmp_test.go b/pkg/tcpip/network/ipv4/igmp_test.go index df0460656..3d08fe095 100644 --- a/pkg/tcpip/network/ipv4/igmp_test.go +++ b/pkg/tcpip/network/ipv4/igmp_test.go @@ -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) diff --git a/pkg/tcpip/network/ipv4/ipv4_test.go b/pkg/tcpip/network/ipv4/ipv4_test.go index 4f3e4a257..9bb1647e8 100644 --- a/pkg/tcpip/network/ipv4/ipv4_test.go +++ b/pkg/tcpip/network/ipv4/ipv4_test.go @@ -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() diff --git a/pkg/tcpip/network/ipv6/icmp.go b/pkg/tcpip/network/ipv6/icmp.go index 661507b31..4028f91df 100644 --- a/pkg/tcpip/network/ipv6/icmp.go +++ b/pkg/tcpip/network/ipv6/icmp.go @@ -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 */) } } diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go index b6bf1354c..0f405c417 100644 --- a/pkg/tcpip/network/ipv6/icmp_test.go +++ b/pkg/tcpip/network/ipv6/icmp_test.go @@ -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 { diff --git a/pkg/tcpip/network/ipv6/ipv6_test.go b/pkg/tcpip/network/ipv6/ipv6_test.go index bd56f5df9..cc24da19e 100644 --- a/pkg/tcpip/network/ipv6/ipv6_test.go +++ b/pkg/tcpip/network/ipv6/ipv6_test.go @@ -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()) diff --git a/pkg/tcpip/network/ipv6/mld_test.go b/pkg/tcpip/network/ipv6/mld_test.go index bc2cc418f..f7c66800a 100644 --- a/pkg/tcpip/network/ipv6/mld_test.go +++ b/pkg/tcpip/network/ipv6/mld_test.go @@ -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) diff --git a/pkg/tcpip/network/ipv6/ndp_test.go b/pkg/tcpip/network/ipv6/ndp_test.go index f45048bd2..1c4476c73 100644 --- a/pkg/tcpip/network/ipv6/ndp_test.go +++ b/pkg/tcpip/network/ipv6/ndp_test.go @@ -479,7 +479,7 @@ func TestNeighborSolicitationResponse(t *testing.T) { t.Fatalf("got invalid = %d, want = 1", got) } - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("unexpected response to an invalid NS = %+v", p) } @@ -494,7 +494,7 @@ func TestNeighborSolicitationResponse(t *testing.T) { if test.performsLinkResolution { c.clock.RunImmediatelyScheduledJobs() p := e.Read() - if p.IsNil() { + if p == nil { t.Fatal("expected an NDP NS response") } @@ -557,7 +557,7 @@ func TestNeighborSolicitationResponse(t *testing.T) { c.clock.RunImmediatelyScheduledJobs() p := e.Read() - if p.IsNil() { + if p == nil { t.Fatal("expected an NDP NA response") } defer p.DecRef() @@ -1312,7 +1312,7 @@ func TestCheckDuplicateAddress(t *testing.T) { checkDADMsg := func() { clock.RunImmediatelyScheduledJobs() p := e.Read() - if p.IsNil() { + if p == nil { t.Fatalf("expected %d-th DAD message", dadPacketsSent) } defer p.DecRef() @@ -1391,7 +1391,7 @@ func TestCheckDuplicateAddress(t *testing.T) { } // Should have no more packets. - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Errorf("got unexpected packet = %#v", p) } } diff --git a/pkg/tcpip/network/multicast_group_test.go b/pkg/tcpip/network/multicast_group_test.go index c49e46607..a01242102 100644 --- a/pkg/tcpip/network/multicast_group_test.go +++ b/pkg/tcpip/network/multicast_group_test.go @@ -221,7 +221,7 @@ func checkInitialIPv6Groups(t *testing.T, e *channel.Endpoint, s *stack.Stack, c reportCounter++ iptestutil.CheckMLDv2Stats(t, s, 0, 0, reportCounter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { v := stack.PayloadSince(p.NetworkHeader()) @@ -238,7 +238,7 @@ func checkInitialIPv6Groups(t *testing.T, e *channel.Endpoint, s *stack.Stack, c for i := 0; i < 2; i++ { reportCounter++ iptestutil.CheckMLDv2Stats(t, s, 0, 0, reportCounter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { v := stack.PayloadSince(p.NetworkHeader()) @@ -252,7 +252,7 @@ func checkInitialIPv6Groups(t *testing.T, e *channel.Endpoint, s *stack.Stack, c // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } @@ -387,7 +387,7 @@ func TestMGPDisabled(t *testing.T) { t.Fatalf("got sentReportStat.Value() = %d, want = 0", got) } clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet, stack with disabled MGP sent packet = %#v", p) } @@ -400,7 +400,7 @@ func TestMGPDisabled(t *testing.T) { t.Fatalf("got sentReportStat.Value() = %d, want = 0", got) } clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %#v", p) } @@ -411,7 +411,7 @@ func TestMGPDisabled(t *testing.T) { t.Fatalf("got receivedQueryStat(_).Value() = %d, want = 1", got) } clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %+v", p) } }) @@ -626,7 +626,7 @@ func TestMGPJoinGroup(t *testing.T) { } reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { subTest.validateReport(t, p) @@ -639,13 +639,13 @@ func TestMGPJoinGroup(t *testing.T) { // Verify the second report is sent by the maximum unsolicited response // interval. p := e.Read() - if !p.IsNil() { + if p != nil { t.Fatalf("sent unexpected packet, expected report only after advancing the clock = %#v", p) } clock.Advance(test.maxUnsolicitedResponseDelay) reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { subTest.validateReport(t, p) @@ -654,7 +654,7 @@ func TestMGPJoinGroup(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } }) @@ -794,7 +794,7 @@ func TestMGPLeaveGroup(t *testing.T) { } reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { subTest.validateReport(t, p) @@ -811,7 +811,7 @@ func TestMGPLeaveGroup(t *testing.T) { for i := subTest.leaveCount; i > 0; i-- { leaveCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a leave message to be sent") } else { subTest.validateLeave(t, p) @@ -822,7 +822,7 @@ func TestMGPLeaveGroup(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } }) @@ -1001,7 +1001,7 @@ func TestMGPQueryMessages(t *testing.T) { for i := 0; i < maxUnsolicitedReports; i++ { reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatalf("expected %d-th report message to be sent", i) } else { subTest.validateReport(t, p, false /* queryResponse */) @@ -1015,7 +1015,7 @@ func TestMGPQueryMessages(t *testing.T) { // Should not send any more packets until a query. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } @@ -1024,7 +1024,7 @@ func TestMGPQueryMessages(t *testing.T) { // targeted at the host. const maxRespTime = 100 subTest.rxQuery(e, maxRespTime, addrTest.multicastAddr) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } @@ -1032,7 +1032,7 @@ func TestMGPQueryMessages(t *testing.T) { clock.Advance(test.maxRespTimeToDuration(maxRespTime)) reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { subTest.validateReport(t, p, true /* queryResponse */) @@ -1042,7 +1042,7 @@ func TestMGPQueryMessages(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } }) @@ -1181,7 +1181,7 @@ func TestMGPReportMessages(t *testing.T) { } reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { subTest.validateReport(t, p) @@ -1197,7 +1197,7 @@ func TestMGPReportMessages(t *testing.T) { clock.Advance(time.Hour) subTest.enterVersion(e) subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Errorf("sent unexpected packet = %#v", p) } if t.Failed() { @@ -1212,7 +1212,7 @@ func TestMGPReportMessages(t *testing.T) { for i := subTest.leaveCount; i > 0; i-- { leaveCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a leave message to be sent") } else { subTest.validateLeave(t, p) @@ -1224,7 +1224,7 @@ func TestMGPReportMessages(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } }) @@ -1402,7 +1402,7 @@ func TestMGPWithNICLifecycle(t *testing.T) { } reportCounter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatalf("expected a report message to be sent for %s", a) } else { subTest.validateReport(t, p, a) @@ -1449,7 +1449,7 @@ func TestMGPWithNICLifecycle(t *testing.T) { } reportV2Counter++ subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected leave message to be sent") } else { p.DecRef() @@ -1459,7 +1459,7 @@ func TestMGPWithNICLifecycle(t *testing.T) { t.Fatalf("LeaveGroup(%d, nic, %s): %s", test.protoNum, a, err) } subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("leaving group %s on disabled NIC sent unexpected packet = %#v", a, p) } } @@ -1467,7 +1467,7 @@ func TestMGPWithNICLifecycle(t *testing.T) { t.Fatalf("JoinGroup(%d, %d, %s): %s", test.protoNum, nicID, test.finalMulticastAddr, err) } subTest.checkStats(t, s, reportCounter, leaveCounter, reportV2Counter) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("joining group %s on disabled NIC sent unexpected packet = %#v", test.finalMulticastAddr, p) } @@ -1487,7 +1487,7 @@ func TestMGPWithNICLifecycle(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } }) @@ -1695,7 +1695,7 @@ func TestMGPCoalescedQueryResponseRecords(t *testing.T) { } reportV2Counter++ test.checkStats(t, s, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { test.validateReport(t, p, addr) @@ -1708,13 +1708,13 @@ func TestMGPCoalescedQueryResponseRecords(t *testing.T) { // Verify the second report is sent by the maximum unsolicited response // interval. p := e.Read() - if !p.IsNil() { + if p != nil { t.Fatalf("sent unexpected packet, expected report only after advancing the clock = %#v", p) } clock.Advance(test.maxUnsolicitedResponseDelay) reportV2Counter++ test.checkStats(t, s, reportV2Counter) - if p := e.Read(); p.IsNil() { + if p := e.Read(); p == nil { t.Fatal("expected a report message to be sent") } else { test.validateReport(t, p, addr) @@ -1724,7 +1724,7 @@ func TestMGPCoalescedQueryResponseRecords(t *testing.T) { // Should not send any more packets. clock.Advance(time.Hour) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("sent unexpected packet = %#v", p) } test.checkStats(t, s, reportV2Counter) diff --git a/pkg/tcpip/stack/ndp_test.go b/pkg/tcpip/stack/ndp_test.go index 7d40f7866..c5b1ab046 100644 --- a/pkg/tcpip/stack/ndp_test.go +++ b/pkg/tcpip/stack/ndp_test.go @@ -683,7 +683,7 @@ func TestDADResolve(t *testing.T) { // Validate the sent Neighbor Solicitation messages. for i := uint8(0); i < test.dupAddrDetectTransmits; i++ { p := e.Read() - if p.IsNil() { + if p == nil { t.Fatal("packet didn't arrive") } @@ -1466,10 +1466,10 @@ func TestDynamicConfigurationsDisabled(t *testing.T) { t.Errorf("got v6Stats.ICMP.PacketsSent.RouterSolicit.Value() = %d, want = %d", got, want) } if handleRAsDisabled { - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Errorf("unexpectedly got a packet = %#v", p) } - } else if p := e.Read(); p.IsNil() { + } else if p := e.Read(); p == nil { t.Error("expected router solicitation packet") } else if p.NetworkProtocolNumber != header.IPv6ProtocolNumber { t.Errorf("got Proto = %d, want = %d", p.NetworkProtocolNumber, header.IPv6ProtocolNumber) @@ -5805,7 +5805,7 @@ func TestRouterSolicitation(t *testing.T) { clock.Advance(timeout) p := e.Read() - if p.IsNil() { + if p == nil { t.Fatal("expected router solicitation packet") } defer p.DecRef() @@ -5834,7 +5834,7 @@ func TestRouterSolicitation(t *testing.T) { t.Helper() clock.Advance(timeout) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { t.Fatalf("unexpectedly got a packet = %#v", p) } } @@ -5996,7 +5996,7 @@ func TestStopStartSolicitingRouters(t *testing.T) { clock.Advance(timeout) p := e.Read() - if p.IsNil() { + if p == nil { t.Fatal("timed out waiting for packet") } @@ -6029,11 +6029,11 @@ func TestStopStartSolicitingRouters(t *testing.T) { // Stop soliciting routers. test.stopFn(t, s, true /* first */) clock.Advance(delay) - if p := e.Read(); !p.IsNil() { + if p := e.Read(); p != nil { p.DecRef() // A single RS may have been sent before solicitations were stopped. clock.Advance(interval) - if pb := e.Read(); !pb.IsNil() { + if pb := e.Read(); pb != nil { t.Fatal("should not have sent more than one RS message") } } @@ -6042,7 +6042,7 @@ func TestStopStartSolicitingRouters(t *testing.T) { // do nothing. test.stopFn(t, s, false /* first */) clock.Advance(delay) - if pb := e.Read(); !pb.IsNil() { + if pb := e.Read(); pb != nil { t.Fatal("unexpectedly got a packet after router solicitation has been stopepd") } @@ -6057,7 +6057,7 @@ func TestStopStartSolicitingRouters(t *testing.T) { waitForPkt(clock, interval) waitForPkt(clock, interval) clock.Advance(interval) - if pb := e.Read(); !pb.IsNil() { + if pb := e.Read(); pb != nil { t.Fatal("unexpectedly got an extra packet after sending out the expected RSs") } @@ -6065,7 +6065,7 @@ func TestStopStartSolicitingRouters(t *testing.T) { // nothing. test.startFn(t, s) clock.Advance(interval) - if pb := e.Read(); !pb.IsNil() { + if pb := e.Read(); pb != nil { t.Fatal("unexpectedly got a packet after finishing router solicitations") } }) diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 7e9348182..39028f9e8 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -759,12 +759,12 @@ func (n *nic) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt *Packe // Deliver to interested packet endpoints without holding NIC lock. var packetEPPkt *PacketBuffer defer func() { - if !packetEPPkt.IsNil() { + if packetEPPkt != nil { packetEPPkt.DecRef() } }() deliverPacketEPs := func(ep PacketEndpoint) { - if packetEPPkt.IsNil() { + if packetEPPkt == nil { // Packet endpoints hold the full packet. // // We perform a deep copy because higher-level endpoints may point to diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go index e49cc613f..24956e71b 100644 --- a/pkg/tcpip/stack/packet_buffer.go +++ b/pkg/tcpip/stack/packet_buffer.go @@ -469,11 +469,6 @@ func (pk *PacketBuffer) DeepCopyForForwarding(reservedHeaderBytes int) *PacketBu return newPk } -// IsNil returns whether the pointer is logically nil. -func (pk *PacketBuffer) IsNil() bool { - return pk == nil -} - // headerInfo stores metadata about a header in a packet. // // +stateify savable diff --git a/pkg/tcpip/stack/stack_test.go b/pkg/tcpip/stack/stack_test.go index be6142589..29fd50d73 100644 --- a/pkg/tcpip/stack/stack_test.go +++ b/pkg/tcpip/stack/stack_test.go @@ -4800,7 +4800,7 @@ func TestFindRouteWithForwarding(t *testing.T) { t.Errorf("got %d unexpected packets from ep1", n) } pkt := ep2.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("packet not sent through ep2") } defer pkt.DecRef() @@ -5366,7 +5366,7 @@ func TestWritePacketToRemote(t *testing.T) { } pkt := e.Read() - if got, want := !pkt.IsNil(), true; got != want { + if got, want := pkt != nil, true; got != want { t.Fatalf("e.Read() = %t, want %t", got, want) } defer pkt.DecRef() @@ -5388,7 +5388,7 @@ func TestWritePacketToRemote(t *testing.T) { t.Fatalf("s.WritePacketToRemote(_, _, _, _) = %s, want = %s", err, &tcpip.ErrUnknownDevice{}) } pkt := e.Read() - if got, want := !pkt.IsNil(), false; got != want { + if got, want := pkt != nil, false; got != want { t.Fatalf("e.Read() = %t, %v; want %t", got, pkt, want) } }) diff --git a/pkg/tcpip/tests/integration/forward_test.go b/pkg/tcpip/tests/integration/forward_test.go index a7172a2c9..6350e3bae 100644 --- a/pkg/tcpip/tests/integration/forward_test.go +++ b/pkg/tcpip/tests/integration/forward_test.go @@ -495,7 +495,7 @@ func TestUnicastForwarding(t *testing.T) { expectForward := test.expectForward && !full p := e2.Read() - if (!p.IsNil()) != expectForward { + if (p != nil) != expectForward { t.Fatalf("got e2.Read() = %#v, want = (_ == nil) = %t", p, expectForward) } @@ -683,15 +683,15 @@ func TestPerInterfaceForwarding(t *testing.T) { }) test.rx(subTest.nicEP, test.srcAddr, test.dstAddr) - if p := subTest.nicEP.Read(); !p.IsNil() { + if p := subTest.nicEP.Read(); p != nil { t.Errorf("unexpectedly got a response from the interface the packet arrived on: %#v", p) p.DecRef() } p := subTest.otherNICEP.Read() - if (!p.IsNil()) != subTest.expectForwarding { + if (p != nil) != subTest.expectForwarding { t.Errorf("got otherNICEP.Read() = (%#v, %t), want = (_, %t)", p, ok, subTest.expectForwarding) } - if !p.IsNil() { + if p != nil { payload := stack.PayloadSince(p.NetworkHeader()) defer payload.Release() test.checker(t, payload) diff --git a/pkg/tcpip/tests/integration/iptables_test.go b/pkg/tcpip/tests/integration/iptables_test.go index 0d805b585..bd8fae290 100644 --- a/pkg/tcpip/tests/integration/iptables_test.go +++ b/pkg/tcpip/tests/integration/iptables_test.go @@ -944,7 +944,7 @@ func TestForwardingHook(t *testing.T) { } p := e2.Read() - if (!p.IsNil()) != expectTransmitPacket { + if (p != nil) != expectTransmitPacket { t.Fatalf("got e2.Read() = %#v, want = (_ == nil) = %t", p, expectTransmitPacket) } if expectTransmitPacket { @@ -1186,16 +1186,16 @@ func TestFilteringEchoPacketsWithLocalForwarding(t *testing.T) { expectPacket := subTest.expectResult == noneDropped p := e1.Read() - if (!p.IsNil()) != expectPacket { + if (p != nil) != expectPacket { t.Errorf("got e1.Read() = %#v, want = (_ == nil) = %t", p, expectPacket) } - if !p.IsNil() { + if p != nil { payload := stack.PayloadSince(p.NetworkHeader()) defer payload.Release() test.checker(t, payload) p.DecRef() } - if p := e2.Read(); !p.IsNil() { + if p := e2.Read(); p != nil { t.Errorf("got e1.Read() = %#v, want = nil)", p) p.DecRef() } @@ -1544,7 +1544,7 @@ func TestNATEcho(t *testing.T) { Payload: buffer.MakeWithData(test.echoPkt(natTypeTest.requestSrc, natTypeTest.requestDst, false /* reply */)), })) pkt := ep1.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep1") } payload := stack.PayloadSince(pkt.NetworkHeader()) @@ -1563,7 +1563,7 @@ func TestNATEcho(t *testing.T) { Payload: buffer.MakeWithData(test.echoPkt(natTypeTest.expectedRequestDst, natTypeTest.expectedRequestSrc, true /* reply */)), })) pkt := ep2.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep2") } payload := stack.PayloadSince(pkt.NetworkHeader()) @@ -2537,7 +2537,7 @@ func TestNATICMPError(t *testing.T) { { pkt := ep1.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep1") } pktView := stack.PayloadSince(pkt.NetworkHeader()) @@ -2558,7 +2558,7 @@ func TestNATICMPError(t *testing.T) { pkt := ep2.Read() expectResponse := icmpType.expectResponse && trimTest.expectNATedICMP - if (!pkt.IsNil()) != expectResponse { + if (pkt != nil) != expectResponse { t.Fatalf("got ep2.Read() = %#v, want = (_ == nil) = %t", pkt, expectResponse) } if !expectResponse { @@ -2907,7 +2907,7 @@ func TestSNATHandlePortOrIdentConflicts(t *testing.T) { })) pkt := ep1.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep1") } pktView := stack.PayloadSince(pkt.NetworkHeader()) @@ -3000,7 +3000,7 @@ func TestSNATLocallyGeneratedTrafficPorts(t *testing.T) { Payload: buffer.MakeWithData(udpv4Packet(ep1Addr, ep2Addr, ep1Port, ep2Port, 0 /* dataSize */)), })) pkt := ep2.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep2") } pktView := stack.PayloadSince(pkt.NetworkHeader()) @@ -3054,7 +3054,7 @@ func TestSNATLocallyGeneratedTrafficPorts(t *testing.T) { // ep2 should observe the traffic as coming from the router's address, but // *not* from the same port as the traffic from ep1 before. pkt = ep2.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep2") } pktView = stack.PayloadSince(pkt.NetworkHeader()) @@ -3082,7 +3082,7 @@ func TestSNATLocallyGeneratedTrafficPorts(t *testing.T) { Payload: buffer.MakeWithData(udpv4Packet(ep2Addr, routerNIC2Addr, ep2Port, ep1Port, 0 /* dataSize */)), })) pkt = ep1.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep2") } pktView = stack.PayloadSince(pkt.NetworkHeader()) @@ -3518,7 +3518,7 @@ func TestRejectWith(t *testing.T) { { pkt := ep1.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected to read a packet on ep1") } payload := stack.PayloadSince(pkt.NetworkHeader()) diff --git a/pkg/tcpip/tests/integration/link_resolution_test.go b/pkg/tcpip/tests/integration/link_resolution_test.go index 782bf63ff..e5658c6dd 100644 --- a/pkg/tcpip/tests/integration/link_resolution_test.go +++ b/pkg/tcpip/tests/integration/link_resolution_test.go @@ -630,7 +630,7 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) { for i := 0; i < int(nudConfigs.MaxMulticastProbes); i++ { request := outgoingEndpoint.Read() - if request.IsNil() { + if request == nil { t.Fatal("expected ARP packet through outgoing NIC") } @@ -646,7 +646,7 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) { // link resolution fails, and this dequeue is what triggers the ICMP // error. reply := incomingEndpoint.Read() - if reply.IsNil() { + if reply == nil { t.Fatal("expected ICMP packet through incoming NIC") } @@ -658,7 +658,7 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) { // Since link resolution failed, we don't expect the packet to be // forwarded. forwardedPacket := outgoingEndpoint.Read() - if !forwardedPacket.IsNil() { + if forwardedPacket != nil { t.Fatalf("expected no ICMP Echo packet through outgoing NIC, instead found: %#v", forwardedPacket) } diff --git a/pkg/tcpip/tests/integration/multicast_broadcast_test.go b/pkg/tcpip/tests/integration/multicast_broadcast_test.go index fc408068c..46de7a7a2 100644 --- a/pkg/tcpip/tests/integration/multicast_broadcast_test.go +++ b/pkg/tcpip/tests/integration/multicast_broadcast_test.go @@ -146,7 +146,7 @@ func TestPingMulticastBroadcast(t *testing.T) { test.rxICMP(e, test.srcAddr, test.dstAddr, ttl) pkt := e.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("expected ICMP response") } defer pkt.DecRef() diff --git a/pkg/tcpip/tests/integration/multicast_forward_test.go b/pkg/tcpip/tests/integration/multicast_forward_test.go index 7671b69d9..53c73aac7 100644 --- a/pkg/tcpip/tests/integration/multicast_forward_test.go +++ b/pkg/tcpip/tests/integration/multicast_forward_test.go @@ -462,7 +462,7 @@ func TestAddMulticastRoute(t *testing.T) { injectPacket(incomingEp, protocol, srcAddr, dstAddr, packetTTL) p := incomingEp.Read() - if !p.IsNil() { + if p != nil { // An ICMP error should never be sent in response to a multicast packet. t.Fatalf("got incomingEp.Read() = %#v, want = nil", p) } @@ -501,7 +501,7 @@ func TestAddMulticastRoute(t *testing.T) { p := outgoingEp.Read() - if (!p.IsNil()) != test.expectForward { + if (p != nil) != test.expectForward { t.Fatalf("got outgoingEp.Read() = %#v, want = (_ == nil) = %t", p, test.expectForward) } @@ -697,7 +697,7 @@ func TestMulticastRouteLastUsedTime(t *testing.T) { injectPacket(incomingEp, protocol, srcAddr, dstAddr, packetTTL) p := incomingEp.Read() - if !p.IsNil() { + if p != nil { t.Fatalf("Expected no ICMP packet through incoming NIC, instead found: %#v", p) } @@ -861,7 +861,7 @@ func TestRemoveMulticastRoute(t *testing.T) { injectPacket(incomingEp, protocol, srcAddr, dstAddr, packetTTL) p := incomingEp.Read() - if !p.IsNil() { + if p != 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", p) @@ -877,7 +877,7 @@ func TestRemoveMulticastRoute(t *testing.T) { // If the route was successfully removed, then the packet should not be // forwarded. expectForward := test.wantErr != nil - if (!p.IsNil()) != expectForward { + if (p != nil) != expectForward { t.Fatalf("got outgoingEp.Read() = %#v, want = (_ == nil) = %t", p, expectForward) } @@ -1138,7 +1138,7 @@ func TestMulticastForwarding(t *testing.T) { injectPacket(incomingEp, protocol, srcAddr, dstAddr, test.ttl) p := incomingEp.Read() - if !p.IsNil() { + if p != nil { // An ICMP error should never be sent in response to a multicast packet. t.Fatalf("expected no ICMP packet through incoming NIC, instead found: %#v", p) } @@ -1153,7 +1153,7 @@ func TestMulticastForwarding(t *testing.T) { expectForward := contains(nicID, test.expectedForwardingInterfaces) - if (!p.IsNil()) != expectForward { + if (p != nil) != expectForward { t.Fatalf("got outgoingEp.Read() = %#v, want = (_ == nil) = %t", p, expectForward) } @@ -1170,7 +1170,7 @@ func TestMulticastForwarding(t *testing.T) { p = otherEp.Read() - if (!p.IsNil()) != test.joinMulticastGroup { + if (p != nil) != test.joinMulticastGroup { t.Fatalf("got otherEp.Read() = %#v, want = (_ == nil) = %t", p, test.joinMulticastGroup) } diff --git a/pkg/tcpip/transport/datagram_test.go b/pkg/tcpip/transport/datagram_test.go index 961f2364c..7d7787ffe 100644 --- a/pkg/tcpip/transport/datagram_test.go +++ b/pkg/tcpip/transport/datagram_test.go @@ -1097,7 +1097,7 @@ func TestIPv6PacketInfo(t *testing.T) { { p := e1.Read() - if p.IsNil() { + if p == nil { t.Fatal("packet didn't arrive at ep1") } @@ -1107,7 +1107,7 @@ func TestIPv6PacketInfo(t *testing.T) { ) } - if p := e2.Read(); !p.IsNil() { + if p := e2.Read(); p != nil { t.Errorf("unexpected packet from ep2 = %#v", p) } }) diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index 5ea7791fc..f411832e0 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -412,7 +412,7 @@ func send4(s *stack.Stack, ctx *network.WriteContext, ident uint16, data *buffer } pkt := ctx.TryNewPacketBuffer(header.ICMPv4MinimumSize+int(maxHeaderLength), buffer.Buffer{}) - if pkt.IsNil() { + if pkt == nil { return &tcpip.ErrWouldBlock{} } defer pkt.DecRef() @@ -454,7 +454,7 @@ func send6(s *stack.Stack, ctx *network.WriteContext, ident uint16, data *buffer } pkt := ctx.TryNewPacketBuffer(header.ICMPv6MinimumSize+int(maxHeaderLength), buffer.Buffer{}) - if pkt.IsNil() { + if pkt == nil { return &tcpip.ErrWouldBlock{} } defer pkt.DecRef() diff --git a/pkg/tcpip/transport/icmp/icmp_test.go b/pkg/tcpip/transport/icmp/icmp_test.go index 7930d91a2..23e52758f 100644 --- a/pkg/tcpip/transport/icmp/icmp_test.go +++ b/pkg/tcpip/transport/icmp/icmp_test.go @@ -142,7 +142,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) { // Verify the packet was sent out the default NIC. p := defaultEP.Read() - if p.IsNil() { + if p == nil { t.Fatalf("got defaultEP.Read(_) = _, false; want = _, true (packet wasn't written out)") } defer p.DecRef() @@ -159,7 +159,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) { }...) // Verify the packet was not sent out the alternate NIC. - if p := alternateEP.Read(); !p.IsNil() { + if p := alternateEP.Read(); p != nil { t.Fatalf("got alternateEP.Read(_) = %+v, true; want = _, false", p) } } @@ -184,13 +184,13 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) { } // Verify the packet was not sent out the default NIC. - if p := defaultEP.Read(); !p.IsNil() { + if p := defaultEP.Read(); p != nil { t.Fatalf("got defaultEP.Read(_) = %+v, true; want = _, false", p) } // Verify the packet was sent out the alternate NIC. p := alternateEP.Read() - if p.IsNil() { + if p == nil { t.Fatalf("got alternateEP.Read(_) = _, false; want = _, true (packet wasn't written out)") } defer p.DecRef() @@ -228,7 +228,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) { // Verify the packet was sent out the default NIC. p := defaultEP.Read() - if p.IsNil() { + if p == nil { t.Fatalf("got defaultEP.Read(_) = _, false; want = _, true (packet wasn't written out)") } defer p.DecRef() @@ -245,7 +245,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) { }...) // Verify the packet was not sent out the alternate NIC. - if p := alternateEP.Read(); !p.IsNil() { + if p := alternateEP.Read(); p != nil { t.Fatalf("got alternateEP.Read(_) = %+v, true; want = _, false", p) } } diff --git a/pkg/tcpip/transport/internal/network/endpoint_test.go b/pkg/tcpip/transport/internal/network/endpoint_test.go index f25475385..5897a6728 100644 --- a/pkg/tcpip/transport/internal/network/endpoint_test.go +++ b/pkg/tcpip/transport/internal/network/endpoint_test.go @@ -211,7 +211,7 @@ func TestEndpointStateTransitions(t *testing.T) { if err := ctx.WritePacket(injectPkt, false /* headerIncluded */); err != nil { t.Fatalf("ctx.WritePacket(_, false): %s", err) } - if pkt := e.Read(); pkt.IsNil() { + if pkt := e.Read(); pkt == nil { t.Fatalf("expected packet to be read from link endpoint") } else { payload := stack.PayloadSince(pkt.NetworkHeader()) diff --git a/pkg/tcpip/transport/packet/packet_test.go b/pkg/tcpip/transport/packet/packet_test.go index 89199e93f..0d90f79d3 100644 --- a/pkg/tcpip/transport/packet/packet_test.go +++ b/pkg/tcpip/transport/packet/packet_test.go @@ -98,7 +98,7 @@ func TestWriteRaw(t *testing.T) { t.Errorf("got ep.Write(..) = %d, want = %d", n, want) } pkt := chEP.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("Packet wasn't written out") } defer pkt.DecRef() diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index 1634671ff..1eaedc197 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -377,7 +377,7 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp } pkt := ctx.TryNewPacketBuffer(int(ctx.PacketInfo().MaxHeaderLength), payload.Clone()) - if pkt.IsNil() { + if pkt == nil { return 0, &tcpip.ErrWouldBlock{} } defer pkt.DecRef() diff --git a/pkg/tcpip/transport/tcp/testing/context/context.go b/pkg/tcpip/transport/tcp/testing/context/context.go index f115d2055..f0c968968 100644 --- a/pkg/tcpip/transport/tcp/testing/context/context.go +++ b/pkg/tcpip/transport/tcp/testing/context/context.go @@ -317,7 +317,7 @@ func (c *Context) CheckNoPacketTimeout(errMsg string, wait time.Duration) { ctx, cancel := context.WithTimeout(context.Background(), wait) defer cancel() - if pkt := c.linkEP.ReadContext(ctx); !pkt.IsNil() { + if pkt := c.linkEP.ReadContext(ctx); pkt != nil { c.t.Fatal(errMsg) } } @@ -337,7 +337,7 @@ func (c *Context) GetPacketWithTimeout(timeout time.Duration) *buffer.View { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() pkt := c.linkEP.ReadContext(ctx) - if pkt.IsNil() { + if pkt == nil { return nil } defer pkt.DecRef() @@ -387,7 +387,7 @@ func (c *Context) GetPacketNonBlocking() *buffer.View { c.t.Helper() pkt := c.linkEP.Read() - if pkt.IsNil() { + if pkt == nil { return nil } defer pkt.DecRef() @@ -634,7 +634,7 @@ func (c *Context) GetV6Packet() *buffer.View { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() pkt := c.linkEP.ReadContext(ctx) - if pkt.IsNil() { + if pkt == nil { c.t.Fatalf("Packet wasn't written out") return nil } diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 82100f9ff..0c21be861 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -476,7 +476,7 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp dataSz := udpInfo.data.Size() pktInfo := udpInfo.ctx.PacketInfo() pkt := udpInfo.ctx.TryNewPacketBuffer(header.UDPMinimumSize+int(pktInfo.MaxHeaderLength), udpInfo.data) - if pkt.IsNil() { + if pkt == nil { return 0, &tcpip.ErrWouldBlock{} } defer pkt.DecRef() diff --git a/pkg/tcpip/transport/udp/udp_test.go b/pkg/tcpip/transport/udp/udp_test.go index 21c8529e7..83bfcc66d 100644 --- a/pkg/tcpip/transport/udp/udp_test.go +++ b/pkg/tcpip/transport/udp/udp_test.go @@ -591,7 +591,7 @@ func testWriteAndVerifyInternal(c *context.Context, flow context.TestFlow, setDe // Received the packet and check the payload. p := c.LinkEP.Read() - if p.IsNil() { + if p == nil { c.T.Fatalf("Packet wasn't written out") } defer p.DecRef() @@ -1553,7 +1553,7 @@ func TestV4UnknownDestination(t *testing.T) { } } if !tc.icmpRequired { - if p := c.LinkEP.Read(); !p.IsNil() { + if p := c.LinkEP.Read(); p != nil { t.Fatalf("unexpected packet received: %+v", p) } return @@ -1561,7 +1561,7 @@ func TestV4UnknownDestination(t *testing.T) { // ICMP required. p := c.LinkEP.Read() - if p.IsNil() { + if p == nil { t.Fatalf("packet wasn't written out") } @@ -1650,7 +1650,7 @@ func TestV6UnknownDestination(t *testing.T) { } } if !tc.icmpRequired { - if p := c.LinkEP.Read(); !p.IsNil() { + if p := c.LinkEP.Read(); p != nil { t.Fatalf("unexpected packet received: %+v", p) } return @@ -1658,7 +1658,7 @@ func TestV6UnknownDestination(t *testing.T) { // ICMP required. p := c.LinkEP.Read() - if p.IsNil() { + if p == nil { t.Fatalf("packet wasn't written out") } @@ -2212,7 +2212,7 @@ func TestChecksumWithZeroValueOnesComplementSum(t *testing.T) { } pkt := c.LinkEP.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("Packet wasn't written out") } @@ -2249,7 +2249,7 @@ func TestChecksumWithZeroValueOnesComplementSum(t *testing.T) { { pkt := c.LinkEP.Read() - if pkt.IsNil() { + if pkt == nil { t.Fatal("Packet wasn't written out") } defer pkt.DecRef()