mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
committed by
gVisor bot
parent
7fe91395d2
commit
b91cc35b40
@@ -26,15 +26,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
// PacketInfo holds all the information about an outbound packet.
|
||||
type PacketInfo struct {
|
||||
Pkt *stack.PacketBuffer
|
||||
|
||||
// TODO(https://gvisor.dev/issue/6537): Remove these fields.
|
||||
Proto tcpip.NetworkProtocolNumber
|
||||
Route stack.RouteInfo
|
||||
}
|
||||
|
||||
// Notification is the interface for receiving notification from the packet
|
||||
// queue.
|
||||
type Notification interface {
|
||||
@@ -52,7 +43,7 @@ type NotificationHandle struct {
|
||||
|
||||
type queue struct {
|
||||
// c is the outbound packet channel.
|
||||
c chan PacketInfo
|
||||
c chan *stack.PacketBuffer
|
||||
// mu protects fields below.
|
||||
mu sync.RWMutex
|
||||
notify []*NotificationHandle
|
||||
@@ -62,25 +53,25 @@ func (q *queue) Close() {
|
||||
close(q.c)
|
||||
}
|
||||
|
||||
func (q *queue) Read() (PacketInfo, bool) {
|
||||
func (q *queue) Read() *stack.PacketBuffer {
|
||||
select {
|
||||
case p := <-q.c:
|
||||
return p, true
|
||||
return p
|
||||
default:
|
||||
return PacketInfo{}, false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (q *queue) ReadContext(ctx context.Context) (PacketInfo, bool) {
|
||||
func (q *queue) ReadContext(ctx context.Context) *stack.PacketBuffer {
|
||||
select {
|
||||
case pkt := <-q.c:
|
||||
return pkt, true
|
||||
return pkt
|
||||
case <-ctx.Done():
|
||||
return PacketInfo{}, false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (q *queue) Write(p PacketInfo) bool {
|
||||
func (q *queue) Write(pkt *stack.PacketBuffer) bool {
|
||||
// q holds the PacketBuffer.
|
||||
|
||||
// Ideally, Write() should take a reference here, since it is adding
|
||||
@@ -92,10 +83,10 @@ func (q *queue) Write(p PacketInfo) bool {
|
||||
// make a call to PreserveObject(), which prevents the PacketBuffer
|
||||
// pooling implementation from reclaiming this instance, even when
|
||||
// the refcount goes to zero.
|
||||
p.Pkt.PreserveObject()
|
||||
pkt.PreserveObject()
|
||||
wrote := false
|
||||
select {
|
||||
case q.c <- p:
|
||||
case q.c <- pkt:
|
||||
wrote = true
|
||||
default:
|
||||
}
|
||||
@@ -157,7 +148,7 @@ type Endpoint struct {
|
||||
func New(size int, mtu uint32, linkAddr tcpip.LinkAddress) *Endpoint {
|
||||
return &Endpoint{
|
||||
q: &queue{
|
||||
c: make(chan PacketInfo, size),
|
||||
c: make(chan *stack.PacketBuffer, size),
|
||||
},
|
||||
mtu: mtu,
|
||||
linkAddr: linkAddr,
|
||||
@@ -171,25 +162,23 @@ func (e *Endpoint) Close() {
|
||||
}
|
||||
|
||||
// Read does non-blocking read one packet from the outbound packet queue.
|
||||
func (e *Endpoint) Read() (PacketInfo, bool) {
|
||||
func (e *Endpoint) Read() *stack.PacketBuffer {
|
||||
return e.q.Read()
|
||||
}
|
||||
|
||||
// ReadContext does blocking read for one packet from the outbound packet queue.
|
||||
// It can be cancelled by ctx, and in this case, it returns false.
|
||||
func (e *Endpoint) ReadContext(ctx context.Context) (PacketInfo, bool) {
|
||||
func (e *Endpoint) ReadContext(ctx context.Context) *stack.PacketBuffer {
|
||||
return e.q.ReadContext(ctx)
|
||||
}
|
||||
|
||||
// Drain removes all outbound packets from the channel and counts them.
|
||||
func (e *Endpoint) Drain() int {
|
||||
c := 0
|
||||
for {
|
||||
if _, ok := e.Read(); !ok {
|
||||
return c
|
||||
}
|
||||
for e.Read() != nil {
|
||||
c++
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// NumQueued returns the number of packet queued for outbound.
|
||||
@@ -251,32 +240,20 @@ func (e *Endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
}
|
||||
|
||||
// WritePacket stores outbound packets into the channel.
|
||||
func (e *Endpoint) WritePacket(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
p := PacketInfo{
|
||||
Pkt: pkt,
|
||||
Proto: protocol,
|
||||
Route: r,
|
||||
}
|
||||
|
||||
func (e *Endpoint) WritePacket(_ stack.RouteInfo, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
// Write returns false if the queue is full. A full queue is not an error
|
||||
// from the perspective of a LinkEndpoint so we ignore Write's return
|
||||
// value and always return nil from this method.
|
||||
_ = e.q.Write(p)
|
||||
_ = e.q.Write(pkt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WritePackets stores outbound packets into the channel.
|
||||
func (e *Endpoint) WritePackets(r stack.RouteInfo, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
func (e *Endpoint) WritePackets(_ stack.RouteInfo, pkts stack.PacketBufferList, _ tcpip.NetworkProtocolNumber) (int, tcpip.Error) {
|
||||
n := 0
|
||||
for pkt := pkts.Front(); pkt != nil; pkt = pkt.Next() {
|
||||
p := PacketInfo{
|
||||
Pkt: pkt,
|
||||
Proto: protocol,
|
||||
Route: r,
|
||||
}
|
||||
|
||||
if !e.q.Write(p) {
|
||||
if !e.q.Write(pkt) {
|
||||
break
|
||||
}
|
||||
n++
|
||||
@@ -310,15 +287,10 @@ func (*Endpoint) AddHeader(tcpip.LinkAddress, tcpip.LinkAddress, tcpip.NetworkPr
|
||||
|
||||
// WriteRawPacket implements stack.LinkEndpoint.
|
||||
func (e *Endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
|
||||
p := PacketInfo{
|
||||
Pkt: pkt,
|
||||
Proto: pkt.NetworkProtocolNumber,
|
||||
}
|
||||
|
||||
// Write returns false if the queue is full. A full queue is not an error
|
||||
// from the perspective of a LinkEndpoint so we ignore Write's return
|
||||
// value and always return nil from this method.
|
||||
_ = e.q.Write(p)
|
||||
_ = e.q.Write(pkt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -248,12 +248,12 @@ func (d *Device) Read() ([]byte, error) {
|
||||
}
|
||||
|
||||
for {
|
||||
info, ok := endpoint.Read()
|
||||
if !ok {
|
||||
pkt := endpoint.Read()
|
||||
if pkt == nil {
|
||||
return nil, linuxerr.ErrWouldBlock
|
||||
}
|
||||
|
||||
v, ok := d.encodePkt(&info)
|
||||
v, ok := d.encodePkt(pkt)
|
||||
if !ok {
|
||||
// Ignore unsupported packet.
|
||||
continue
|
||||
@@ -263,14 +263,14 @@ func (d *Device) Read() ([]byte, error) {
|
||||
}
|
||||
|
||||
// encodePkt encodes packet for fd side.
|
||||
func (d *Device) encodePkt(info *channel.PacketInfo) (buffer.View, bool) {
|
||||
func (d *Device) encodePkt(pkt *stack.PacketBuffer) (buffer.View, bool) {
|
||||
var vv buffer.VectorisedView
|
||||
|
||||
// Packet information.
|
||||
if !d.flags.NoPacketInfo {
|
||||
hdr := make(PacketInfoHeader, PacketInfoHeaderSize)
|
||||
hdr.Encode(&PacketInfoFields{
|
||||
Protocol: info.Proto,
|
||||
Protocol: pkt.NetworkProtocolNumber,
|
||||
})
|
||||
vv.AppendView(buffer.View(hdr))
|
||||
}
|
||||
@@ -278,17 +278,17 @@ func (d *Device) encodePkt(info *channel.PacketInfo) (buffer.View, bool) {
|
||||
// Ethernet header (TAP only).
|
||||
if d.flags.TAP {
|
||||
// Add ethernet header if not provided.
|
||||
if info.Pkt.LinkHeader().View().IsEmpty() {
|
||||
d.endpoint.AddHeader(info.Route.LocalLinkAddress, info.Route.RemoteLinkAddress, info.Proto, info.Pkt)
|
||||
if pkt.LinkHeader().View().IsEmpty() {
|
||||
d.endpoint.AddHeader(pkt.EgressRoute.LocalLinkAddress, pkt.EgressRoute.RemoteLinkAddress, pkt.NetworkProtocolNumber, pkt)
|
||||
}
|
||||
vv.AppendView(info.Pkt.LinkHeader().View())
|
||||
vv.AppendView(pkt.LinkHeader().View())
|
||||
}
|
||||
|
||||
// Append upper headers.
|
||||
vv.AppendView(info.Pkt.NetworkHeader().View())
|
||||
vv.AppendView(info.Pkt.TransportHeader().View())
|
||||
vv.AppendView(pkt.NetworkHeader().View())
|
||||
vv.AppendView(pkt.TransportHeader().View())
|
||||
// Append data payload.
|
||||
vv.Append(info.Pkt.Data().ExtractVV())
|
||||
vv.Append(pkt.Data().ExtractVV())
|
||||
|
||||
return vv.ToView(), true
|
||||
}
|
||||
|
||||
@@ -312,8 +312,8 @@ 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, ok := c.linkEP.Read(); ok {
|
||||
t.Errorf("unexpected packet sent with network protocol number %d", pkt.Proto)
|
||||
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 {
|
||||
t.Errorf("got c.s.Stats().ARP.RequestsReceivedUnknownTargetAddress.Value() = %d, want = %d", got, want)
|
||||
@@ -330,15 +330,15 @@ func TestDirectRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify an ARP response was sent.
|
||||
pi, ok := c.linkEP.Read()
|
||||
if !ok {
|
||||
pi := c.linkEP.Read()
|
||||
if pi == nil {
|
||||
t.Fatal("expected ARP response to be sent, got none")
|
||||
}
|
||||
|
||||
if pi.Proto != arp.ProtocolNumber {
|
||||
t.Fatalf("expected ARP response, got network protocol number %d", pi.Proto)
|
||||
if got, want := pi.NetworkProtocolNumber, arp.ProtocolNumber; got != want {
|
||||
t.Fatalf("expected %d, got network protocol number %d", want, got)
|
||||
}
|
||||
rep := header.ARP(pi.Pkt.NetworkHeader().View())
|
||||
rep := header.ARP(pi.NetworkHeader().View())
|
||||
if !rep.IsValid() {
|
||||
t.Fatalf("invalid ARP response: len = %d; response = %x", len(rep), rep)
|
||||
}
|
||||
@@ -614,16 +614,16 @@ func TestLinkAddressRequest(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
pkt, ok := linkEP.Read()
|
||||
if !ok {
|
||||
pkt := linkEP.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to send a link address request")
|
||||
}
|
||||
|
||||
if pkt.Route.RemoteLinkAddress != test.expectedRemoteLinkAddr {
|
||||
t.Errorf("got pkt.Route.RemoteLinkAddress = %s, want = %s", pkt.Route.RemoteLinkAddress, test.expectedRemoteLinkAddr)
|
||||
if pkt.EgressRoute.RemoteLinkAddress != test.expectedRemoteLinkAddr {
|
||||
t.Errorf("got pkt.EgressRoute.RemoteLinkAddress = %s, want = %s", pkt.EgressRoute.RemoteLinkAddress, test.expectedRemoteLinkAddr)
|
||||
}
|
||||
|
||||
rep := header.ARP(stack.PayloadSince(pkt.Pkt.NetworkHeader()))
|
||||
rep := header.ARP(stack.PayloadSince(pkt.NetworkHeader()))
|
||||
if got := rep.Op(); got != header.ARPRequest {
|
||||
t.Errorf("got Op = %d, want = %d", got, header.ARPRequest)
|
||||
}
|
||||
@@ -665,16 +665,16 @@ func TestDADARPRequestPacket(t *testing.T) {
|
||||
}
|
||||
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
pkt, ok := e.Read()
|
||||
if !ok {
|
||||
pkt := e.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to send an ARP request")
|
||||
}
|
||||
|
||||
if pkt.Route.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got pkt.Route.RemoteLinkAddress = %s, want = %s", pkt.Route.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
if pkt.EgressRoute.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got pkt.EgressRoute.RemoteLinkAddress = %s, want = %s", pkt.EgressRoute.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
}
|
||||
|
||||
req := header.ARP(stack.PayloadSince(pkt.Pkt.NetworkHeader()))
|
||||
req := header.ARP(stack.PayloadSince(pkt.NetworkHeader()))
|
||||
if !req.IsValid() {
|
||||
t.Errorf("got req.IsValid() = false, want = true")
|
||||
}
|
||||
|
||||
@@ -1716,11 +1716,11 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
pkt, ok := e.Read()
|
||||
if !ok {
|
||||
pkt := e.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected a packet to be written")
|
||||
}
|
||||
test.checker(t, pkt.Pkt, subTest.srcAddr)
|
||||
test.checker(t, pkt, subTest.srcAddr)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -1958,14 +1958,14 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
},
|
||||
})
|
||||
v := test.injector(e, test.srcAddress, payload)
|
||||
pkt, ok := e.Read()
|
||||
if !ok {
|
||||
pkt := e.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected a packet to be written")
|
||||
}
|
||||
if got, want := pkt.Pkt.Size(), test.replyLength; got != want {
|
||||
if got, want := pkt.Size(), test.replyLength; got != want {
|
||||
t.Fatalf("got %d bytes of icmp error packet, want %d", got, want)
|
||||
}
|
||||
test.checker(t, pkt.Pkt, v)
|
||||
test.checker(t, pkt, v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ var (
|
||||
multicastAddr = testutil.MustParse4("224.0.0.3")
|
||||
)
|
||||
|
||||
// validateIgmpPacket checks that a passed PacketInfo is an IPv4 IGMP packet
|
||||
// sent to the provided address with the passed fields set. Raises a t.Error if
|
||||
// any field does not match.
|
||||
func validateIgmpPacket(t *testing.T, p channel.PacketInfo, igmpType header.IGMPType, maxRespTime byte, srcAddr, dstAddr, groupAddress tcpip.Address) {
|
||||
// validateIgmpPacket checks that a passed packet is an IPv4 IGMP packet sent
|
||||
// to the provided address with the passed fields set. Raises a t.Error if any
|
||||
// field does not match.
|
||||
func validateIgmpPacket(t *testing.T, pkt *stack.PacketBuffer, igmpType header.IGMPType, maxRespTime byte, srcAddr, dstAddr, groupAddress tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
payload := header.IPv4(stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
payload := header.IPv4(stack.PayloadSince(pkt.NetworkHeader()))
|
||||
checker.IPv4(t, payload,
|
||||
checker.SrcAddr(srcAddr),
|
||||
checker.DstAddr(dstAddr),
|
||||
@@ -135,8 +135,8 @@ func TestIGMPV1Present(t *testing.T) {
|
||||
// This NIC will send an IGMPv2 report immediately, before this test can get
|
||||
// the IGMPv1 General Membership Query in.
|
||||
{
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("unable to Read IGMP packet, expected V2MembershipReport")
|
||||
}
|
||||
if got := s.Stats().IGMP.PacketsSent.V2MembershipReport.Value(); got != 1 {
|
||||
@@ -165,13 +165,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, ok := e.Read(); ok {
|
||||
t.Fatalf("sent unexpected packet, expected V1MembershipReport only after advancing the clock = %+v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet, expected V1MembershipReport only after advancing the clock = %+v", p)
|
||||
}
|
||||
clock.Advance(ipv4.UnsolicitedReportIntervalMax)
|
||||
{
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("unable to Read IGMP packet, expected V1MembershipReport")
|
||||
}
|
||||
if got := s.Stats().IGMP.PacketsSent.V1MembershipReport.Value(); got != 1 {
|
||||
@@ -188,8 +188,8 @@ func TestIGMPV1Present(t *testing.T) {
|
||||
t.Fatalf("s.EnableNIC(%d): %s", nicID, err)
|
||||
}
|
||||
{
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("unable to Read IGMP packet, expected V2MembershipReport")
|
||||
}
|
||||
if got := s.Stats().IGMP.PacketsSent.V2MembershipReport.Value(); got != 2 {
|
||||
@@ -212,7 +212,7 @@ func TestSendQueuedIGMPReports(t *testing.T) {
|
||||
t.Errorf("got reportStat.Value() = %d, want = 0", got)
|
||||
}
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("got unexpected packet = %#v", p)
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ func TestSendQueuedIGMPReports(t *testing.T) {
|
||||
if got := reportStat.Value(); got != 1 {
|
||||
t.Errorf("got reportStat.Value() = %d, want = 1", got)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Error("expected to send an IGMP membership report")
|
||||
} else {
|
||||
validateIgmpPacket(t, p, header.IGMPv2MembershipReport, 0, stackAddr, multicastAddr, multicastAddr)
|
||||
@@ -243,7 +243,7 @@ func TestSendQueuedIGMPReports(t *testing.T) {
|
||||
if got := reportStat.Value(); got != 2 {
|
||||
t.Errorf("got reportStat.Value() = %d, want = 2", got)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Error("expected to send an IGMP membership report")
|
||||
} else {
|
||||
validateIgmpPacket(t, p, header.IGMPv2MembershipReport, 0, stackAddr, multicastAddr, multicastAddr)
|
||||
@@ -255,7 +255,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, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("got unexpected packet = %#v", p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,10 +432,10 @@ func TestForwarding(t *testing.T) {
|
||||
requestPkt.NetworkProtocolNumber = header.IPv4ProtocolNumber
|
||||
incomingEndpoint.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
|
||||
|
||||
reply, ok := incomingEndpoint.Read()
|
||||
reply := incomingEndpoint.Read()
|
||||
|
||||
if test.expectErrorICMP {
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatalf("expected ICMP packet type %d through incoming NIC", test.icmpType)
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ func TestForwarding(t *testing.T) {
|
||||
return len(hdr.View())
|
||||
}
|
||||
|
||||
checker.IPv4(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(incomingIPv4Addr.Address),
|
||||
checker.DstAddr(test.sourceAddr),
|
||||
checker.TTL(ipv4.DefaultTTL),
|
||||
@@ -462,7 +462,7 @@ func TestForwarding(t *testing.T) {
|
||||
checker.ICMPv4Payload(hdr.View()[:expectedICMPPayloadLength()]),
|
||||
),
|
||||
)
|
||||
} else if ok {
|
||||
} else if reply != nil {
|
||||
t.Fatalf("expected no ICMP packet through incoming NIC, instead found: %#v", reply)
|
||||
}
|
||||
|
||||
@@ -470,11 +470,11 @@ func TestForwarding(t *testing.T) {
|
||||
if len(test.expectedFragmentsForwarded) != 0 {
|
||||
var fragmentedPackets []*stack.PacketBuffer
|
||||
for i := 0; i < len(test.expectedFragmentsForwarded); i++ {
|
||||
reply, ok = outgoingEndpoint.Read()
|
||||
if !ok {
|
||||
reply := outgoingEndpoint.Read()
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP Echo fragment through outgoing NIC")
|
||||
}
|
||||
fragmentedPackets = append(fragmentedPackets, reply.Pkt)
|
||||
fragmentedPackets = append(fragmentedPackets, reply)
|
||||
}
|
||||
|
||||
// The forwarded packet's TTL will have been decremented.
|
||||
@@ -489,12 +489,12 @@ func TestForwarding(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
reply, ok = outgoingEndpoint.Read()
|
||||
if !ok {
|
||||
reply := outgoingEndpoint.Read()
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP Echo packet through outgoing NIC")
|
||||
}
|
||||
|
||||
checker.IPv4(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(test.sourceAddr),
|
||||
checker.DstAddr(test.destAddr),
|
||||
checker.TTL(test.TTL-1),
|
||||
@@ -508,7 +508,7 @@ func TestForwarding(t *testing.T) {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if reply, ok = outgoingEndpoint.Read(); ok {
|
||||
if reply := outgoingEndpoint.Read(); reply != nil {
|
||||
t.Fatalf("expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
|
||||
}
|
||||
}
|
||||
@@ -1253,8 +1253,8 @@ func TestIPv4Sanity(t *testing.T) {
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
|
||||
reply, ok := e.Read()
|
||||
if !ok {
|
||||
reply := e.Read()
|
||||
if reply == nil {
|
||||
if test.shouldFail {
|
||||
if test.expectErrorICMP {
|
||||
t.Fatalf("ICMP error response (type %d, code %d) missing", test.ICMPType, test.ICMPCode)
|
||||
@@ -1271,15 +1271,15 @@ func TestIPv4Sanity(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check the route that brought the packet to us.
|
||||
if reply.Route.LocalAddress != ipv4Addr.Address {
|
||||
t.Errorf("got pkt.Route.LocalAddress = %s, want = %s", reply.Route.LocalAddress, ipv4Addr.Address)
|
||||
if reply.EgressRoute.LocalAddress != ipv4Addr.Address {
|
||||
t.Errorf("got pkt.Route.LocalAddress = %s, want = %s", reply.EgressRoute.LocalAddress, ipv4Addr.Address)
|
||||
}
|
||||
if reply.Route.RemoteAddress != remoteIPv4Addr {
|
||||
t.Errorf("got pkt.Route.RemoteAddress = %s, want = %s", reply.Route.RemoteAddress, remoteIPv4Addr)
|
||||
if reply.EgressRoute.RemoteAddress != remoteIPv4Addr {
|
||||
t.Errorf("got pkt.Route.RemoteAddress = %s, want = %s", reply.EgressRoute.RemoteAddress, remoteIPv4Addr)
|
||||
}
|
||||
|
||||
// Make sure it's all in one buffer for checker.
|
||||
replyIPHeader := header.IPv4(stack.PayloadSince(reply.Pkt.NetworkHeader()))
|
||||
replyIPHeader := header.IPv4(stack.PayloadSince(reply.NetworkHeader()))
|
||||
|
||||
// At this stage we only know it's probably an IP+ICMP header so verify
|
||||
// that much.
|
||||
@@ -2201,21 +2201,21 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
|
||||
clock.Advance(ipv4.ReassembleTimeout)
|
||||
|
||||
reply, ok := e.Read()
|
||||
reply := e.Read()
|
||||
if !test.expectICMP {
|
||||
if ok {
|
||||
if reply != nil {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP error message missing")
|
||||
}
|
||||
if firstFragmentSent == nil {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
|
||||
checker.IPv4(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(addr2),
|
||||
checker.DstAddr(addr1),
|
||||
checker.IPFullLength(uint16(header.IPv4MinimumSize+header.ICMPv4MinimumSize+firstFragmentSent.Size())),
|
||||
@@ -2992,17 +2992,17 @@ func TestPacketQueuing(t *testing.T) {
|
||||
}))
|
||||
},
|
||||
checkResp: func(t *testing.T, e *channel.Endpoint) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != header.IPv4ProtocolNumber {
|
||||
t.Errorf("got p.Proto = %d, want = %d", p.Proto, header.IPv4ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv4ProtocolNumber {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", p.NetworkProtocolNumber, header.IPv4ProtocolNumber)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, host2NICLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, host2NICLinkAddr)
|
||||
}
|
||||
checker.IPv4(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv4(
|
||||
@@ -3035,17 +3035,17 @@ func TestPacketQueuing(t *testing.T) {
|
||||
}))
|
||||
},
|
||||
checkResp: func(t *testing.T, e *channel.Endpoint) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != header.IPv4ProtocolNumber {
|
||||
t.Errorf("got p.Proto = %d, want = %d", p.Proto, header.IPv4ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv4ProtocolNumber {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", p.NetworkProtocolNumber, header.IPv4ProtocolNumber)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, host2NICLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, host2NICLinkAddr)
|
||||
}
|
||||
checker.IPv4(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv4(
|
||||
@@ -3087,17 +3087,17 @@ func TestPacketQueuing(t *testing.T) {
|
||||
// performed.
|
||||
{
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != arp.ProtocolNumber {
|
||||
t.Errorf("got p.Proto = %d, want = %d", p.Proto, arp.ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != arp.ProtocolNumber {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", p.NetworkProtocolNumber, arp.ProtocolNumber)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
if p.EgressRoute.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
}
|
||||
rep := header.ARP(p.Pkt.NetworkHeader().View())
|
||||
rep := header.ARP(p.NetworkHeader().View())
|
||||
if got := rep.Op(); got != header.ARPRequest {
|
||||
t.Errorf("got Op() = %d, want = %d", got, header.ARPRequest)
|
||||
}
|
||||
@@ -3329,14 +3329,14 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
return hdr.View()
|
||||
},
|
||||
check: func(t *testing.T, e *channel.Endpoint, round int) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected echo response, no packet read in endpoint in round %d", round)
|
||||
}
|
||||
if got, want := p.Proto, header.IPv4ProtocolNumber; got != want {
|
||||
t.Errorf("got p.Proto = %d, want = %d", got, want)
|
||||
if got, want := p.NetworkProtocolNumber, header.IPv4ProtocolNumber; got != want {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
checker.IPv4(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv4(
|
||||
@@ -3367,17 +3367,17 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
return hdr.View()
|
||||
},
|
||||
check: func(t *testing.T, e *channel.Endpoint, round int) {
|
||||
p, ok := e.Read()
|
||||
p := e.Read()
|
||||
if round >= icmpBurst {
|
||||
if ok {
|
||||
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Pkt.Data().Views(), round)
|
||||
if p != nil {
|
||||
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Data().Views(), round)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
if p == nil {
|
||||
t.Fatalf("expected unreachable in round %d, no packet read in endpoint", round)
|
||||
}
|
||||
checker.IPv4(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv4(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv4Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv4(
|
||||
|
||||
@@ -475,30 +475,30 @@ func routeICMPv6Packet(t *testing.T, clock *faketime.ManualClock, args routeArgs
|
||||
t.Helper()
|
||||
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
pi, ok := args.src.Read()
|
||||
if !ok {
|
||||
pi := args.src.Read()
|
||||
if pi == nil {
|
||||
t.Fatal("packet didn't arrive")
|
||||
}
|
||||
|
||||
{
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: buffer.NewVectorisedView(pi.Pkt.Size(), pi.Pkt.Views()),
|
||||
Data: buffer.NewVectorisedView(pi.Size(), pi.Views()),
|
||||
})
|
||||
args.dst.InjectLinkAddr(pi.Proto, args.dst.LinkAddress(), pkt)
|
||||
args.dst.InjectLinkAddr(pi.NetworkProtocolNumber, args.dst.LinkAddress(), pkt)
|
||||
}
|
||||
|
||||
if pi.Proto != ProtocolNumber {
|
||||
t.Errorf("unexpected protocol number %d", pi.Proto)
|
||||
if pi.NetworkProtocolNumber != ProtocolNumber {
|
||||
t.Errorf("unexpected protocol number %d", pi.NetworkProtocolNumber)
|
||||
return
|
||||
}
|
||||
|
||||
if len(args.remoteLinkAddr) != 0 && pi.Route.RemoteLinkAddress != args.remoteLinkAddr {
|
||||
t.Errorf("got remote link address = %s, want = %s", pi.Route.RemoteLinkAddress, args.remoteLinkAddr)
|
||||
if len(args.remoteLinkAddr) != 0 && pi.EgressRoute.RemoteLinkAddress != args.remoteLinkAddr {
|
||||
t.Errorf("got remote link address = %s, want = %s", pi.EgressRoute.RemoteLinkAddress, args.remoteLinkAddr)
|
||||
}
|
||||
|
||||
// Pull the full payload since network header. Needed for header.IPv6 to
|
||||
// extract its payload.
|
||||
ipv6 := header.IPv6(stack.PayloadSince(pi.Pkt.NetworkHeader()))
|
||||
ipv6 := header.IPv6(stack.PayloadSince(pi.NetworkHeader()))
|
||||
transProto := tcpip.TransportProtocolNumber(ipv6.NextHeader())
|
||||
if transProto != header.ICMPv6ProtocolNumber {
|
||||
t.Errorf("unexpected transport protocol number %d", transProto)
|
||||
@@ -1281,18 +1281,18 @@ func TestLinkAddressRequest(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
pkt, ok := linkEP.Read()
|
||||
if !ok {
|
||||
pkt := linkEP.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to send a link address request")
|
||||
}
|
||||
|
||||
var want stack.RouteInfo
|
||||
want.NetProto = ProtocolNumber
|
||||
want.RemoteLinkAddress = test.expectedRemoteLinkAddr
|
||||
if diff := cmp.Diff(want, pkt.Route, cmp.AllowUnexported(want)); diff != "" {
|
||||
if diff := cmp.Diff(want, pkt.EgressRoute, cmp.AllowUnexported(want)); diff != "" {
|
||||
t.Errorf("route info mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(pkt.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(pkt.NetworkHeader()),
|
||||
checker.SrcAddr(lladdr1),
|
||||
checker.DstAddr(test.expectedRemoteAddr),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -1359,17 +1359,17 @@ func TestPacketQueing(t *testing.T) {
|
||||
}))
|
||||
},
|
||||
checkResp: func(t *testing.T, e *channel.Endpoint) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != ProtocolNumber {
|
||||
t.Errorf("got p.Proto = %d, want = %d", p.Proto, ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != ProtocolNumber {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", p.NetworkProtocolNumber, ProtocolNumber)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, host2NICLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, host2NICLinkAddr)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv6(
|
||||
@@ -1405,17 +1405,17 @@ func TestPacketQueing(t *testing.T) {
|
||||
}))
|
||||
},
|
||||
checkResp: func(t *testing.T, e *channel.Endpoint) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != ProtocolNumber {
|
||||
t.Errorf("got p.Proto = %d, want = %d", p.Proto, ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != ProtocolNumber {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", p.NetworkProtocolNumber, ProtocolNumber)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, host2NICLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != host2NICLinkAddr {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, host2NICLinkAddr)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv6(
|
||||
@@ -1460,18 +1460,18 @@ func TestPacketQueing(t *testing.T) {
|
||||
// be performed.
|
||||
{
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("timed out waiting for packet")
|
||||
}
|
||||
if p.Proto != ProtocolNumber {
|
||||
t.Errorf("got Proto = %d, want = %d", p.Proto, ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != ProtocolNumber {
|
||||
t.Errorf("got Proto = %d, want = %d", p.NetworkProtocolNumber, ProtocolNumber)
|
||||
}
|
||||
snmc := header.SolicitedNodeAddr(host2IPv6Addr.AddressWithPrefix.Address)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); p.Route.RemoteLinkAddress != want {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, want)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); p.EgressRoute.RemoteLinkAddress != want {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, want)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(snmc),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
|
||||
@@ -1013,21 +1013,21 @@ func TestReceiveIPv6ExtHdrs(t *testing.T) {
|
||||
}
|
||||
|
||||
if !test.expectICMP {
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("unexpected packet received: %#v", p)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ICMP required.
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected packet wasn't written out")
|
||||
}
|
||||
|
||||
// Pack the output packet into a single buffer.View as the checkers
|
||||
// assume that.
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(p.Size(), p.Views())
|
||||
pkt := vv.ToView()
|
||||
if got, want := len(pkt), header.IPv6FixedHeaderSize+header.ICMPv6MinimumSize+hdr.UsedLength(); got != want {
|
||||
t.Fatalf("got an ICMP packet of size = %d, want = %d", got, want)
|
||||
@@ -1040,11 +1040,11 @@ func TestReceiveIPv6ExtHdrs(t *testing.T) {
|
||||
|
||||
// We know we are looking at no extension headers in the error ICMP
|
||||
// packets.
|
||||
icmpPkt := header.ICMPv6(ipHdr.Payload())
|
||||
icm := header.ICMPv6(ipHdr.Payload())
|
||||
// We know we sent small packets that won't be truncated when reflected
|
||||
// back to us.
|
||||
originalPacket := icmpPkt.Payload()
|
||||
if got, want := icmpPkt.TypeSpecific(), test.pointer; got != want {
|
||||
originalPacket := icm.Payload()
|
||||
if got, want := icm.TypeSpecific(), test.pointer; got != want {
|
||||
t.Errorf("unexpected ICMPv6 pointer, got = %d, want = %d\n", got, want)
|
||||
}
|
||||
if diff := cmp.Diff(hdr.View(), buffer.View(originalPacket)); diff != "" {
|
||||
@@ -2212,18 +2212,18 @@ func TestInvalidIPv6Fragments(t *testing.T) {
|
||||
t.Errorf("got Stats.IP.MalformedFragmentsReceived = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
reply, ok := e.Read()
|
||||
reply := e.Read()
|
||||
if !test.expectICMP {
|
||||
if ok {
|
||||
if reply != nil {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP error message missing")
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(addr2),
|
||||
checker.DstAddr(addr1),
|
||||
checker.IPFullLength(uint16(header.IPv6MinimumSize+header.ICMPv6MinimumSize+expectICMPPayload.Size())),
|
||||
@@ -2465,21 +2465,21 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
|
||||
clock.Advance(ReassembleTimeout)
|
||||
|
||||
reply, ok := e.Read()
|
||||
reply := e.Read()
|
||||
if !test.expectICMP {
|
||||
if ok {
|
||||
if reply != nil {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP error message missing")
|
||||
}
|
||||
if firstFragmentSent == nil {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(addr2),
|
||||
checker.DstAddr(addr1),
|
||||
checker.IPFullLength(uint16(header.IPv6MinimumSize+header.ICMPv6MinimumSize+firstFragmentSent.Size())),
|
||||
@@ -3290,15 +3290,15 @@ func TestForwarding(t *testing.T) {
|
||||
SrcAddr: test.sourceAddr,
|
||||
DstAddr: test.destAddr,
|
||||
})
|
||||
requestPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
reques := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
})
|
||||
incomingEndpoint.InjectInbound(ProtocolNumber, requestPkt)
|
||||
incomingEndpoint.InjectInbound(ProtocolNumber, reques)
|
||||
|
||||
reply, ok := incomingEndpoint.Read()
|
||||
reply := incomingEndpoint.Read()
|
||||
|
||||
if test.expectErrorICMP {
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatalf("expected ICMP packet type %d through incoming NIC", test.icmpType)
|
||||
}
|
||||
|
||||
@@ -3315,7 +3315,7 @@ func TestForwarding(t *testing.T) {
|
||||
return len(hdr.View())
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(incomingIPv6Addr.Address),
|
||||
checker.DstAddr(test.sourceAddr),
|
||||
checker.TTL(DefaultTTL),
|
||||
@@ -3329,17 +3329,17 @@ func TestForwarding(t *testing.T) {
|
||||
if n := outgoingEndpoint.Drain(); n != 0 {
|
||||
t.Fatalf("got e2.Drain() = %d, want = 0", n)
|
||||
}
|
||||
} else if ok {
|
||||
} else if reply != nil {
|
||||
t.Fatalf("expected no ICMP packet through incoming NIC, instead found: %#v", reply)
|
||||
}
|
||||
|
||||
reply, ok = outgoingEndpoint.Read()
|
||||
reply = outgoingEndpoint.Read()
|
||||
if test.expectPacketForwarded {
|
||||
if !ok {
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP Echo Request packet through outgoing NIC")
|
||||
}
|
||||
|
||||
checker.IPv6WithExtHdr(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.IPv6WithExtHdr(t, stack.PayloadSince(reply.NetworkHeader()),
|
||||
checker.SrcAddr(test.sourceAddr),
|
||||
checker.DstAddr(test.destAddr),
|
||||
checker.TTL(test.TTL-1),
|
||||
@@ -3354,7 +3354,7 @@ func TestForwarding(t *testing.T) {
|
||||
if n := incomingEndpoint.Drain(); n != 0 {
|
||||
t.Fatalf("got e1.Drain() = %d, want = 0", n)
|
||||
}
|
||||
} else if ok {
|
||||
} else if reply != nil {
|
||||
t.Fatalf("expected no ICMP Echo packet through outgoing NIC, instead found: %#v", reply)
|
||||
}
|
||||
|
||||
@@ -3492,14 +3492,14 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
return hdr.View()
|
||||
},
|
||||
check: func(t *testing.T, e *channel.Endpoint, round int) {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected echo response, no packet read in endpoint in round %d", round)
|
||||
}
|
||||
if got, want := p.Proto, header.IPv6ProtocolNumber; got != want {
|
||||
t.Errorf("got p.Proto = %d, want = %d", got, want)
|
||||
if got, want := p.NetworkProtocolNumber, header.IPv6ProtocolNumber; got != want {
|
||||
t.Errorf("got p.NetworkProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv6(
|
||||
@@ -3536,17 +3536,17 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
return hdr.View()
|
||||
},
|
||||
check: func(t *testing.T, e *channel.Endpoint, round int) {
|
||||
p, ok := e.Read()
|
||||
p := e.Read()
|
||||
if round >= icmpBurst {
|
||||
if ok {
|
||||
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Pkt.Data().Views(), round)
|
||||
if p != nil {
|
||||
t.Errorf("got packet %x in round %d, expected ICMP rate limit to stop it", p.Data().Views(), round)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
if p == nil {
|
||||
t.Fatalf("expected unreachable in round %d, no packet read in endpoint", round)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(host1IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.DstAddr(host2IPv6Addr.AddressWithPrefix.Address),
|
||||
checker.ICMPv6(
|
||||
|
||||
@@ -82,10 +82,10 @@ 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, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
}
|
||||
|
||||
// The stack will leave an address's solicited node multicast address when
|
||||
@@ -94,10 +94,10 @@ func TestIPv6JoinLeaveSolicitedNodeAddressPerformsMLD(t *testing.T) {
|
||||
if err := s.RemoveAddress(nicID, linkLocalAddr); err != nil {
|
||||
t.Fatalf("RemoveAddress(%d, %s) = %s", nicID, linkLocalAddr, err)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a done message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), header.IPv6Any, header.IPv6AllRoutersLinkLocalMulticastAddress, header.ICMPv6MulticastListenerDone, linkLocalAddrSNMC)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), header.IPv6Any, header.IPv6AllRoutersLinkLocalMulticastAddress, header.ICMPv6MulticastListenerDone, linkLocalAddrSNMC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,10 +166,10 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
|
||||
resolveDAD := func(addr, snmc tcpip.Address) {
|
||||
clock.Advance(dadResolutionTime)
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected DAD packet")
|
||||
} else {
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(header.IPv6Any),
|
||||
checker.DstAddr(snmc),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -200,13 +200,13 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
if got := reportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got reportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Errorf("expected MLD report for %s", globalMulticastAddr)
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), header.IPv6Any, globalMulticastAddr, header.ICMPv6MulticastListenerReport, globalMulticastAddr)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), header.IPv6Any, globalMulticastAddr, header.ICMPv6MulticastListenerReport, globalMulticastAddr)
|
||||
}
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("got unexpected packet = %#v", p)
|
||||
}
|
||||
if t.Failed() {
|
||||
@@ -232,10 +232,10 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
if got := reportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got reportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Errorf("expected MLD report for %s", globalAddrSNMC)
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), header.IPv6Any, globalAddrSNMC, header.ICMPv6MulticastListenerReport, globalAddrSNMC)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), header.IPv6Any, globalAddrSNMC, header.ICMPv6MulticastListenerReport, globalAddrSNMC)
|
||||
}
|
||||
if dadResolutionTime != 0 {
|
||||
// Reports should not be sent when the address resolves.
|
||||
@@ -252,7 +252,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
if got := doneStat.Value(); got != doneCounter {
|
||||
t.Errorf("got doneStat.Value() = %d, want = %d", got, doneCounter)
|
||||
}
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("got unexpected packet = %#v", p)
|
||||
}
|
||||
if t.Failed() {
|
||||
@@ -273,10 +273,10 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
if got := reportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got reportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Errorf("expected MLD report for %s", linkLocalAddrSNMC)
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), header.IPv6Any, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), header.IPv6Any, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
}
|
||||
resolveDAD(linkLocalAddr, linkLocalAddrSNMC)
|
||||
}
|
||||
@@ -297,12 +297,12 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
linkLocalAddrSNMC: false,
|
||||
}
|
||||
for range addrs {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected MLD report for %s and %s; addrs = %#v", globalMulticastAddr, linkLocalAddrSNMC, addrs)
|
||||
}
|
||||
|
||||
addr := header.IPv6(stack.PayloadSince(p.Pkt.NetworkHeader())).DestinationAddress()
|
||||
addr := header.IPv6(stack.PayloadSince(p.NetworkHeader())).DestinationAddress()
|
||||
if seen, ok := addrs[addr]; !ok {
|
||||
t.Fatalf("got unexpected packet destined to %s", addr)
|
||||
} else if seen {
|
||||
@@ -310,7 +310,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
}
|
||||
|
||||
addrs[addr] = true
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), linkLocalAddr, addr, header.ICMPv6MulticastListenerReport, addr)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, addr, header.ICMPv6MulticastListenerReport, addr)
|
||||
|
||||
clock.Advance(ipv6.UnsolicitedReportIntervalMax)
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func TestSendQueuedMLDReports(t *testing.T) {
|
||||
|
||||
// Should not send any more reports.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("got unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
@@ -587,10 +587,10 @@ 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, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, linkLocalAddrSNMC, header.ICMPv6MulticastListenerReport, linkLocalAddrSNMC)
|
||||
}
|
||||
|
||||
if err := s.JoinGroup(ipv6.ProtocolNumber, nicID, test.group); err != nil {
|
||||
@@ -603,17 +603,17 @@ func TestMLDSkipProtocol(t *testing.T) {
|
||||
}
|
||||
|
||||
if !test.expectReport {
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("got e.Read() = (%#v, true), want = (_, false)", p)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, stack.PayloadSince(p.Pkt.NetworkHeader()), linkLocalAddr, test.group, header.ICMPv6MulticastListenerReport, test.group)
|
||||
validateMLDPacket(t, stack.PayloadSince(p.NetworkHeader()), linkLocalAddr, test.group, header.ICMPv6MulticastListenerReport, test.group)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -464,8 +464,8 @@ func TestNeighborSolicitationResponse(t *testing.T) {
|
||||
t.Fatalf("got invalid = %d, want = 1", got)
|
||||
}
|
||||
|
||||
if p, got := e.Read(); got {
|
||||
t.Fatalf("unexpected response to an invalid NS = %+v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("unexpected response to an invalid NS = %+v", p)
|
||||
}
|
||||
|
||||
// If we expected the NS to be invalid, we have nothing else to check.
|
||||
@@ -478,8 +478,8 @@ func TestNeighborSolicitationResponse(t *testing.T) {
|
||||
|
||||
if test.performsLinkResolution {
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
p, got := e.Read()
|
||||
if !got {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("expected an NDP NS response")
|
||||
}
|
||||
|
||||
@@ -487,11 +487,11 @@ func TestNeighborSolicitationResponse(t *testing.T) {
|
||||
var want stack.RouteInfo
|
||||
want.NetProto = ProtocolNumber
|
||||
want.RemoteLinkAddress = header.EthernetAddressFromMulticastIPv6Address(respNSDst)
|
||||
if diff := cmp.Diff(want, p.Route, cmp.AllowUnexported(want)); diff != "" {
|
||||
if diff := cmp.Diff(want, p.EgressRoute, cmp.AllowUnexported(want)); diff != "" {
|
||||
t.Errorf("route info mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(nicAddr),
|
||||
checker.DstAddr(respNSDst),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -534,25 +534,25 @@ func TestNeighborSolicitationResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
p, got := e.Read()
|
||||
if !got {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("expected an NDP NA response")
|
||||
}
|
||||
|
||||
if p.Route.LocalAddress != test.naSrc {
|
||||
t.Errorf("got p.Route.LocalAddress = %s, want = %s", p.Route.LocalAddress, test.naSrc)
|
||||
if p.EgressRoute.LocalAddress != test.naSrc {
|
||||
t.Errorf("got p.EgressRoute.LocalAddress = %s, want = %s", p.EgressRoute.LocalAddress, test.naSrc)
|
||||
}
|
||||
if p.Route.LocalLinkAddress != nicLinkAddr {
|
||||
t.Errorf("p.Route.LocalLinkAddress = %s, want = %s", p.Route.LocalLinkAddress, nicLinkAddr)
|
||||
if p.EgressRoute.LocalLinkAddress != nicLinkAddr {
|
||||
t.Errorf("p.EgressRoute.LocalLinkAddress = %s, want = %s", p.EgressRoute.LocalLinkAddress, nicLinkAddr)
|
||||
}
|
||||
if p.Route.RemoteAddress != test.naDst {
|
||||
t.Errorf("got p.Route.RemoteAddress = %s, want = %s", p.Route.RemoteAddress, test.naDst)
|
||||
if p.EgressRoute.RemoteAddress != test.naDst {
|
||||
t.Errorf("got p.EgressRoute.RemoteAddress = %s, want = %s", p.EgressRoute.RemoteAddress, test.naDst)
|
||||
}
|
||||
if p.Route.RemoteLinkAddress != test.naDstLinkAddr {
|
||||
t.Errorf("got p.Route.RemoteLinkAddress = %s, want = %s", p.Route.RemoteLinkAddress, test.naDstLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != test.naDstLinkAddr {
|
||||
t.Errorf("got p.EgressRoute.RemoteLinkAddress = %s, want = %s", p.EgressRoute.RemoteLinkAddress, test.naDstLinkAddr)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(test.naSrc),
|
||||
checker.DstAddr(test.naDst),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -1281,20 +1281,20 @@ func TestCheckDuplicateAddress(t *testing.T) {
|
||||
remoteLinkAddr := header.EthernetAddressFromMulticastIPv6Address(snmc)
|
||||
checkDADMsg := func() {
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected %d-th DAD message", dadPacketsSent)
|
||||
}
|
||||
|
||||
if p.Proto != header.IPv6ProtocolNumber {
|
||||
t.Errorf("(i=%d) got p.Proto = %d, want = %d", dadPacketsSent, p.Proto, header.IPv6ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Errorf("(i=%d) got p.NetworkProtocolNumber = %d, want = %d", dadPacketsSent, p.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
}
|
||||
|
||||
if p.Route.RemoteLinkAddress != remoteLinkAddr {
|
||||
t.Errorf("(i=%d) got p.Route.RemoteLinkAddress = %s, want = %s", dadPacketsSent, p.Route.RemoteLinkAddress, remoteLinkAddr)
|
||||
if p.EgressRoute.RemoteLinkAddress != remoteLinkAddr {
|
||||
t.Errorf("(i=%d) got p.EgressRoute.RemoteLinkAddress = %s, want = %s", dadPacketsSent, p.EgressRoute.RemoteLinkAddress, remoteLinkAddr)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(header.IPv6Any),
|
||||
checker.DstAddr(snmc),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -1359,7 +1359,7 @@ func TestCheckDuplicateAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
// Should have no more packets.
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("got unexpected packet = %#v", p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +79,10 @@ var (
|
||||
|
||||
// validateMLDPacket checks that a passed PacketInfo is an IPv6 MLD packet
|
||||
// sent to the provided address with the passed fields set.
|
||||
func validateMLDPacket(t *testing.T, p channel.PacketInfo, remoteAddress tcpip.Address, mldType uint8, maxRespTime byte, groupAddress tcpip.Address) {
|
||||
func validateMLDPacket(t *testing.T, p *stack.PacketBuffer, remoteAddress tcpip.Address, mldType uint8, maxRespTime byte, groupAddress tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
payload := header.IPv6(stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
payload := header.IPv6(stack.PayloadSince(p.NetworkHeader()))
|
||||
checker.IPv6WithExtHdr(t, payload,
|
||||
checker.IPv6ExtHdr(
|
||||
checker.IPv6HopByHopExtensionHeader(checker.IPv6RouterAlert(header.IPv6RouterAlertMLD)),
|
||||
@@ -100,10 +100,10 @@ func validateMLDPacket(t *testing.T, p channel.PacketInfo, remoteAddress tcpip.A
|
||||
|
||||
// validateIGMPPacket checks that a passed PacketInfo is an IPv4 IGMP packet
|
||||
// sent to the provided address with the passed fields set.
|
||||
func validateIGMPPacket(t *testing.T, p channel.PacketInfo, remoteAddress tcpip.Address, igmpType uint8, maxRespTime byte, groupAddress tcpip.Address) {
|
||||
func validateIGMPPacket(t *testing.T, p *stack.PacketBuffer, remoteAddress tcpip.Address, igmpType uint8, maxRespTime byte, groupAddress tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
payload := header.IPv4(stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
payload := header.IPv4(stack.PayloadSince(p.NetworkHeader()))
|
||||
checker.IPv4(t, payload,
|
||||
checker.SrcAddr(stackIPv4Addr),
|
||||
checker.DstAddr(remoteAddress),
|
||||
@@ -187,7 +187,7 @@ func checkInitialIPv6Groups(t *testing.T, e *channel.Endpoint, s *stack.Stack, c
|
||||
if got := stats.MulticastListenerReport.Value(); got != reportCounter {
|
||||
t.Errorf("got stats.MulticastListenerReport.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, p, ipv6AddrSNMC, mldReport, 0, ipv6AddrSNMC)
|
||||
@@ -202,7 +202,7 @@ func checkInitialIPv6Groups(t *testing.T, e *channel.Endpoint, s *stack.Stack, c
|
||||
if got := stats.MulticastListenerDone.Value(); got != leaveCounter {
|
||||
t.Errorf("got stats.MulticastListenerDone.Value() = %d, want = %d", got, leaveCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
validateMLDPacket(t, p, header.IPv6AllRoutersLinkLocalMulticastAddress, mldDone, 0, ipv6AddrSNMC)
|
||||
@@ -210,7 +210,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, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
|
||||
@@ -337,8 +337,8 @@ func TestMGPDisabled(t *testing.T) {
|
||||
t.Fatalf("got sentReportStat.Value() = %d, want = 0", got)
|
||||
}
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled MGP sent packet = %#v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled MGP sent packet = %#v", p)
|
||||
}
|
||||
|
||||
// Test joining a specific group explicitly and verify that no reports are
|
||||
@@ -350,8 +350,8 @@ func TestMGPDisabled(t *testing.T) {
|
||||
t.Fatalf("got sentReportStat.Value() = %d, want = 0", got)
|
||||
}
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %#v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %#v", p)
|
||||
}
|
||||
|
||||
// Inject a general query message. This should only trigger a report to be
|
||||
@@ -361,8 +361,8 @@ func TestMGPDisabled(t *testing.T) {
|
||||
t.Fatalf("got receivedQueryStat(_).Value() = %d, want = 1", got)
|
||||
}
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %+v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet, stack with disabled IGMP sent packet = %+v", p)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -471,7 +471,7 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
maxUnsolicitedResponseDelay time.Duration
|
||||
sentReportStat func(*stack.Stack) *tcpip.StatCounter
|
||||
receivedQueryStat func(*stack.Stack) *tcpip.StatCounter
|
||||
validateReport func(*testing.T, channel.PacketInfo)
|
||||
validateReport func(*testing.T, *stack.PacketBuffer)
|
||||
checkInitialGroups func(*testing.T, *channel.Endpoint, *stack.Stack, *faketime.ManualClock) (uint64, uint64)
|
||||
}{
|
||||
{
|
||||
@@ -485,7 +485,7 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
receivedQueryStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().IGMP.PacketsReceived.MembershipQuery
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, ipv4MulticastAddr1, igmpv2MembershipReport, 0, ipv4MulticastAddr1)
|
||||
@@ -502,7 +502,7 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
receivedQueryStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().ICMP.V6.PacketsReceived.MulticastListenerQuery
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, ipv6MulticastAddr1, mldReport, 0, ipv6MulticastAddr1)
|
||||
@@ -530,7 +530,7 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -541,16 +541,16 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
|
||||
// Verify the second report is sent by the maximum unsolicited response
|
||||
// interval.
|
||||
p, ok := e.Read()
|
||||
if ok {
|
||||
t.Fatalf("sent unexpected packet, expected report only after advancing the clock = %#v", p.Pkt)
|
||||
p := e.Read()
|
||||
if p != nil {
|
||||
t.Fatalf("sent unexpected packet, expected report only after advancing the clock = %#v", p)
|
||||
}
|
||||
clock.Advance(test.maxUnsolicitedResponseDelay)
|
||||
reportCounter++
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -558,7 +558,7 @@ func TestMGPJoinGroup(t *testing.T) {
|
||||
|
||||
// Should not send any more packets.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
@@ -574,8 +574,8 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
multicastAddr tcpip.Address
|
||||
sentReportStat func(*stack.Stack) *tcpip.StatCounter
|
||||
sentLeaveStat func(*stack.Stack) *tcpip.StatCounter
|
||||
validateReport func(*testing.T, channel.PacketInfo)
|
||||
validateLeave func(*testing.T, channel.PacketInfo)
|
||||
validateReport func(*testing.T, *stack.PacketBuffer)
|
||||
validateLeave func(*testing.T, *stack.PacketBuffer)
|
||||
checkInitialGroups func(*testing.T, *channel.Endpoint, *stack.Stack, *faketime.ManualClock) (uint64, uint64)
|
||||
}{
|
||||
{
|
||||
@@ -588,12 +588,12 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
sentLeaveStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().IGMP.PacketsSent.LeaveGroup
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, ipv4MulticastAddr1, igmpv2MembershipReport, 0, ipv4MulticastAddr1)
|
||||
},
|
||||
validateLeave: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateLeave: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, header.IPv4AllRoutersGroup, igmpLeaveGroup, 0, ipv4MulticastAddr1)
|
||||
@@ -609,12 +609,12 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
sentLeaveStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().ICMP.V6.PacketsSent.MulticastListenerDone
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, ipv6MulticastAddr1, mldReport, 0, ipv6MulticastAddr1)
|
||||
},
|
||||
validateLeave: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateLeave: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, header.IPv6AllRoutersLinkLocalMulticastAddress, mldDone, 0, ipv6MulticastAddr1)
|
||||
@@ -640,7 +640,7 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
if got := test.sentReportStat(s).Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat(_).Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -657,7 +657,7 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
if got := test.sentLeaveStat(s).Value(); got != leaveCounter {
|
||||
t.Fatalf("got sentLeaveStat(_).Value() = %d, want = %d", got, leaveCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a leave message to be sent")
|
||||
} else {
|
||||
test.validateLeave(t, p)
|
||||
@@ -665,7 +665,7 @@ func TestMGPLeaveGroup(t *testing.T) {
|
||||
|
||||
// Should not send any more packets.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
@@ -683,7 +683,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
sentReportStat func(*stack.Stack) *tcpip.StatCounter
|
||||
receivedQueryStat func(*stack.Stack) *tcpip.StatCounter
|
||||
rxQuery func(*channel.Endpoint, uint8, tcpip.Address)
|
||||
validateReport func(*testing.T, channel.PacketInfo)
|
||||
validateReport func(*testing.T, *stack.PacketBuffer)
|
||||
maxRespTimeToDuration func(uint8) time.Duration
|
||||
checkInitialGroups func(*testing.T, *channel.Endpoint, *stack.Stack, *faketime.ManualClock) (uint64, uint64)
|
||||
}{
|
||||
@@ -701,7 +701,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
rxQuery: func(e *channel.Endpoint, maxRespTime uint8, groupAddress tcpip.Address) {
|
||||
createAndInjectIGMPPacket(e, igmpMembershipQuery, maxRespTime, groupAddress)
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, ipv4MulticastAddr1, igmpv2MembershipReport, 0, ipv4MulticastAddr1)
|
||||
@@ -722,7 +722,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
rxQuery: func(e *channel.Endpoint, maxRespTime uint8, groupAddress tcpip.Address) {
|
||||
createAndInjectMLDPacket(e, mldQuery, maxRespTime, groupAddress)
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, ipv6MulticastAddr1, mldReport, 0, ipv6MulticastAddr1)
|
||||
@@ -781,7 +781,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("(i=%d) got sentReportStat.Value() = %d, want = %d", i, got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatalf("expected %d-th report message to be sent", i)
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -794,7 +794,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
|
||||
// Should not send any more packets until a query.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
|
||||
@@ -803,8 +803,8 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
// targeted at the host.
|
||||
const maxRespTime = 100
|
||||
test.rxQuery(e, maxRespTime, subTest.multicastAddr)
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("sent unexpected packet = %#v", p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
|
||||
if subTest.expectReport {
|
||||
@@ -813,7 +813,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -822,7 +822,7 @@ func TestMGPQueryMessages(t *testing.T) {
|
||||
|
||||
// Should not send any more packets.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
@@ -841,7 +841,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
sentReportStat func(*stack.Stack) *tcpip.StatCounter
|
||||
sentLeaveStat func(*stack.Stack) *tcpip.StatCounter
|
||||
rxReport func(*channel.Endpoint)
|
||||
validateReport func(*testing.T, channel.PacketInfo)
|
||||
validateReport func(*testing.T, *stack.PacketBuffer)
|
||||
maxRespTimeToDuration func(uint8) time.Duration
|
||||
checkInitialGroups func(*testing.T, *channel.Endpoint, *stack.Stack, *faketime.ManualClock) (uint64, uint64)
|
||||
}{
|
||||
@@ -858,7 +858,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
rxReport: func(e *channel.Endpoint) {
|
||||
createAndInjectIGMPPacket(e, igmpv2MembershipReport, 0, ipv4MulticastAddr1)
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, ipv4MulticastAddr1, igmpv2MembershipReport, 0, ipv4MulticastAddr1)
|
||||
@@ -878,7 +878,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
rxReport: func(e *channel.Endpoint) {
|
||||
createAndInjectMLDPacket(e, mldReport, 0, ipv6MulticastAddr1)
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, ipv6MulticastAddr1, mldReport, 0, ipv6MulticastAddr1)
|
||||
@@ -908,7 +908,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p)
|
||||
@@ -924,7 +924,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
if t.Failed() {
|
||||
@@ -943,7 +943,7 @@ func TestMGPReportMessages(t *testing.T) {
|
||||
|
||||
// Should not send any more packets.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
@@ -959,9 +959,9 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
maxUnsolicitedResponseDelay time.Duration
|
||||
sentReportStat func(*stack.Stack) *tcpip.StatCounter
|
||||
sentLeaveStat func(*stack.Stack) *tcpip.StatCounter
|
||||
validateReport func(*testing.T, channel.PacketInfo, tcpip.Address)
|
||||
validateLeave func(*testing.T, channel.PacketInfo, tcpip.Address)
|
||||
getAndCheckGroupAddress func(*testing.T, map[tcpip.Address]bool, channel.PacketInfo) tcpip.Address
|
||||
validateReport func(*testing.T, *stack.PacketBuffer, tcpip.Address)
|
||||
validateLeave func(*testing.T, *stack.PacketBuffer, tcpip.Address)
|
||||
getAndCheckGroupAddress func(*testing.T, map[tcpip.Address]bool, *stack.PacketBuffer) tcpip.Address
|
||||
checkInitialGroups func(*testing.T, *channel.Endpoint, *stack.Stack, *faketime.ManualClock) (uint64, uint64)
|
||||
}{
|
||||
{
|
||||
@@ -976,20 +976,20 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
sentLeaveStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().IGMP.PacketsSent.LeaveGroup
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo, addr tcpip.Address) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer, addr tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, addr, igmpv2MembershipReport, 0, addr)
|
||||
},
|
||||
validateLeave: func(t *testing.T, p channel.PacketInfo, addr tcpip.Address) {
|
||||
validateLeave: func(t *testing.T, p *stack.PacketBuffer, addr tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
validateIGMPPacket(t, p, header.IPv4AllRoutersGroup, igmpLeaveGroup, 0, addr)
|
||||
},
|
||||
getAndCheckGroupAddress: func(t *testing.T, seen map[tcpip.Address]bool, p channel.PacketInfo) tcpip.Address {
|
||||
getAndCheckGroupAddress: func(t *testing.T, seen map[tcpip.Address]bool, p *stack.PacketBuffer) tcpip.Address {
|
||||
t.Helper()
|
||||
|
||||
ipv4 := header.IPv4(stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
ipv4 := header.IPv4(stack.PayloadSince(p.NetworkHeader()))
|
||||
if got := tcpip.TransportProtocolNumber(ipv4.Protocol()); got != header.IGMPProtocolNumber {
|
||||
t.Fatalf("got ipv4.Protocol() = %d, want = %d", got, header.IGMPProtocolNumber)
|
||||
}
|
||||
@@ -1017,20 +1017,20 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
sentLeaveStat: func(s *stack.Stack) *tcpip.StatCounter {
|
||||
return s.Stats().ICMP.V6.PacketsSent.MulticastListenerDone
|
||||
},
|
||||
validateReport: func(t *testing.T, p channel.PacketInfo, addr tcpip.Address) {
|
||||
validateReport: func(t *testing.T, p *stack.PacketBuffer, addr tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, addr, mldReport, 0, addr)
|
||||
},
|
||||
validateLeave: func(t *testing.T, p channel.PacketInfo, addr tcpip.Address) {
|
||||
validateLeave: func(t *testing.T, p *stack.PacketBuffer, addr tcpip.Address) {
|
||||
t.Helper()
|
||||
|
||||
validateMLDPacket(t, p, header.IPv6AllRoutersLinkLocalMulticastAddress, mldDone, 0, addr)
|
||||
},
|
||||
getAndCheckGroupAddress: func(t *testing.T, seen map[tcpip.Address]bool, p channel.PacketInfo) tcpip.Address {
|
||||
getAndCheckGroupAddress: func(t *testing.T, seen map[tcpip.Address]bool, p *stack.PacketBuffer) tcpip.Address {
|
||||
t.Helper()
|
||||
|
||||
ipv6 := header.IPv6(stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
ipv6 := header.IPv6(stack.PayloadSince(p.NetworkHeader()))
|
||||
|
||||
ipv6HeaderIter := header.MakeIPv6PayloadIterator(
|
||||
header.IPv6ExtensionHeaderIdentifier(ipv6.NextHeader()),
|
||||
@@ -1093,7 +1093,7 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatalf("expected a report message to be sent for %s", a)
|
||||
} else {
|
||||
test.validateReport(t, p, a)
|
||||
@@ -1120,8 +1120,8 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := range test.multicastAddrs {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected (%d-th) leave message to be sent", i)
|
||||
}
|
||||
|
||||
@@ -1147,8 +1147,8 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := range test.multicastAddrs {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("expected (%d-th) report message to be sent", i)
|
||||
}
|
||||
|
||||
@@ -1168,7 +1168,7 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
t.Errorf("got sentLeaveStat.Value() = %d, want = %d", got, leaveCounter)
|
||||
}
|
||||
for i := range test.multicastAddrs {
|
||||
if _, ok := e.Read(); !ok {
|
||||
if e.Read() == nil {
|
||||
t.Fatalf("expected (%d-th) leave message to be sent", i)
|
||||
}
|
||||
}
|
||||
@@ -1179,8 +1179,8 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
if got := sentLeaveStat.Value(); got != leaveCounter {
|
||||
t.Errorf("got sentLeaveStat.Value() = %d, want = %d", got, leaveCounter)
|
||||
}
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("leaving group %s on disabled NIC sent unexpected packet = %#v", a, p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("leaving group %s on disabled NIC sent unexpected packet = %#v", a, p)
|
||||
}
|
||||
}
|
||||
if err := s.JoinGroup(test.protoNum, nicID, test.finalMulticastAddr); err != nil {
|
||||
@@ -1189,8 +1189,8 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); ok {
|
||||
t.Fatalf("joining group %s on disabled NIC sent unexpected packet = %#v", test.finalMulticastAddr, p.Pkt)
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("joining group %s on disabled NIC sent unexpected packet = %#v", test.finalMulticastAddr, p)
|
||||
}
|
||||
|
||||
// A report should only be sent for the group we last joined after
|
||||
@@ -1202,7 +1202,7 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p, test.finalMulticastAddr)
|
||||
@@ -1213,7 +1213,7 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
if got := sentReportStat.Value(); got != reportCounter {
|
||||
t.Errorf("got sentReportStat.Value() = %d, want = %d", got, reportCounter)
|
||||
}
|
||||
if p, ok := e.Read(); !ok {
|
||||
if p := e.Read(); p == nil {
|
||||
t.Fatal("expected a report message to be sent")
|
||||
} else {
|
||||
test.validateReport(t, p, test.finalMulticastAddr)
|
||||
@@ -1221,7 +1221,7 @@ func TestMGPWithNICLifecycle(t *testing.T) {
|
||||
|
||||
// Should not send any more packets.
|
||||
clock.Advance(time.Hour)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("sent unexpected packet = %#v", p)
|
||||
}
|
||||
})
|
||||
|
||||
+36
-36
@@ -610,20 +610,20 @@ func TestDADResolve(t *testing.T) {
|
||||
|
||||
// Validate the sent Neighbor Solicitation messages.
|
||||
for i := uint8(0); i < test.dupAddrDetectTransmits; i++ {
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("packet didn't arrive")
|
||||
}
|
||||
|
||||
// Make sure its an IPv6 packet.
|
||||
if p.Proto != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.Proto, header.IPv6ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
}
|
||||
|
||||
// Make sure the right remote link address is used.
|
||||
snmc := header.SolicitedNodeAddr(addr1)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); p.Route.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.Route.RemoteLinkAddress, want)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); p.EgressRoute.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.EgressRoute.RemoteLinkAddress, want)
|
||||
}
|
||||
|
||||
// Check NDP NS packet.
|
||||
@@ -631,7 +631,7 @@ func TestDADResolve(t *testing.T) {
|
||||
// As per RFC 4861 section 4.3, a possible option is the Source Link
|
||||
// Layer option, but this option MUST NOT be included when the source
|
||||
// address of the packet is the unspecified address.
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(header.IPv6Any),
|
||||
checker.DstAddr(snmc),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -640,8 +640,8 @@ func TestDADResolve(t *testing.T) {
|
||||
checker.NDPNSOptions([]header.NDPOption{header.NDPNonceOption(nonces[i])}),
|
||||
))
|
||||
|
||||
if l, want := p.Pkt.AvailableHeaderBytes(), int(test.linkHeaderLen); l != want {
|
||||
t.Errorf("got p.Pkt.AvailableHeaderBytes() = %d; want = %d", l, want)
|
||||
if l, want := p.AvailableHeaderBytes(), int(test.linkHeaderLen); l != want {
|
||||
t.Errorf("got p.AvailableHeaderBytes() = %d; want = %d", l, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1316,19 +1316,19 @@ func TestDynamicConfigurationsDisabled(t *testing.T) {
|
||||
t.Errorf("got v6Stats.ICMP.PacketsSent.RouterSolicit.Value() = %d, want = %d", got, want)
|
||||
}
|
||||
if handleRAsDisabled {
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Errorf("unexpectedly got a packet = %#v", p)
|
||||
}
|
||||
} else if p, ok := e.Read(); !ok {
|
||||
} else if p := e.Read(); p == nil {
|
||||
t.Error("expected router solicitation packet")
|
||||
} else if p.Proto != header.IPv6ProtocolNumber {
|
||||
t.Errorf("got Proto = %d, want = %d", p.Proto, header.IPv6ProtocolNumber)
|
||||
} else if p.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Errorf("got Proto = %d, want = %d", p.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
} else {
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(header.IPv6AllRoutersLinkLocalMulticastAddress); p.Route.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.Route.RemoteLinkAddress, want)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(header.IPv6AllRoutersLinkLocalMulticastAddress); p.EgressRoute.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.EgressRoute.RemoteLinkAddress, want)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(header.IPv6Any),
|
||||
checker.DstAddr(header.IPv6AllRoutersLinkLocalMulticastAddress),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -5348,36 +5348,36 @@ func TestRouterSolicitation(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
clock.Advance(timeout)
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("expected router solicitation packet")
|
||||
}
|
||||
|
||||
if p.Proto != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.Proto, header.IPv6ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
}
|
||||
|
||||
// Make sure the right remote link address is used.
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(header.IPv6AllRoutersLinkLocalMulticastAddress); p.Route.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.Route.RemoteLinkAddress, want)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(header.IPv6AllRoutersLinkLocalMulticastAddress); p.EgressRoute.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", p.EgressRoute.RemoteLinkAddress, want)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(test.expectedSrcAddr),
|
||||
checker.DstAddr(header.IPv6AllRoutersLinkLocalMulticastAddress),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
checker.NDPRS(checker.NDPRSOptions(test.expectedNDPOpts)),
|
||||
)
|
||||
|
||||
if l, want := p.Pkt.AvailableHeaderBytes(), int(test.linkHeaderLen); l != want {
|
||||
t.Errorf("got p.Pkt.AvailableHeaderBytes() = %d; want = %d", l, want)
|
||||
if l, want := p.AvailableHeaderBytes(), int(test.linkHeaderLen); l != want {
|
||||
t.Errorf("got p.AvailableHeaderBytes() = %d; want = %d", l, want)
|
||||
}
|
||||
}
|
||||
waitForNothing := func(timeout time.Duration) {
|
||||
t.Helper()
|
||||
|
||||
clock.Advance(timeout)
|
||||
if p, ok := e.Read(); ok {
|
||||
if p := e.Read(); p != nil {
|
||||
t.Fatalf("unexpectedly got a packet = %#v", p)
|
||||
}
|
||||
}
|
||||
@@ -5538,15 +5538,15 @@ func TestStopStartSolicitingRouters(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
clock.Advance(timeout)
|
||||
p, ok := e.Read()
|
||||
if !ok {
|
||||
p := e.Read()
|
||||
if p == nil {
|
||||
t.Fatal("timed out waiting for packet")
|
||||
}
|
||||
|
||||
if p.Proto != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.Proto, header.IPv6ProtocolNumber)
|
||||
if p.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", p.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
}
|
||||
checker.IPv6(t, stack.PayloadSince(p.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(p.NetworkHeader()),
|
||||
checker.SrcAddr(header.IPv6Any),
|
||||
checker.DstAddr(header.IPv6AllRoutersLinkLocalMulticastAddress),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -5571,10 +5571,10 @@ func TestStopStartSolicitingRouters(t *testing.T) {
|
||||
// Stop soliciting routers.
|
||||
test.stopFn(t, s, true /* first */)
|
||||
clock.Advance(delay)
|
||||
if _, ok := e.Read(); ok {
|
||||
if e.Read() != nil {
|
||||
// A single RS may have been sent before solicitations were stopped.
|
||||
clock.Advance(interval)
|
||||
if _, ok = e.Read(); ok {
|
||||
if e.Read() != nil {
|
||||
t.Fatal("should not have sent more than one RS message")
|
||||
}
|
||||
}
|
||||
@@ -5583,7 +5583,7 @@ func TestStopStartSolicitingRouters(t *testing.T) {
|
||||
// do nothing.
|
||||
test.stopFn(t, s, false /* first */)
|
||||
clock.Advance(delay)
|
||||
if _, ok := e.Read(); ok {
|
||||
if e.Read() != nil {
|
||||
t.Fatal("unexpectedly got a packet after router solicitation has been stopepd")
|
||||
}
|
||||
|
||||
@@ -5598,7 +5598,7 @@ func TestStopStartSolicitingRouters(t *testing.T) {
|
||||
waitForPkt(clock, interval)
|
||||
waitForPkt(clock, interval)
|
||||
clock.Advance(interval)
|
||||
if _, ok := e.Read(); ok {
|
||||
if e.Read() != nil {
|
||||
t.Fatal("unexpectedly got an extra packet after sending out the expected RSs")
|
||||
}
|
||||
|
||||
@@ -5606,7 +5606,7 @@ func TestStopStartSolicitingRouters(t *testing.T) {
|
||||
// nothing.
|
||||
test.startFn(t, s)
|
||||
clock.Advance(interval)
|
||||
if _, ok := e.Read(); ok {
|
||||
if e.Read() != nil {
|
||||
t.Fatal("unexpectedly got a packet after finishing router solicitations")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4430,15 +4430,15 @@ func TestFindRouteWithForwarding(t *testing.T) {
|
||||
if n := ep1.Drain(); n != 0 {
|
||||
t.Errorf("got %d unexpected packets from ep1", n)
|
||||
}
|
||||
pkt, ok := ep2.Read()
|
||||
if !ok {
|
||||
pkt := ep2.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("packet not sent through ep2")
|
||||
}
|
||||
if pkt.Route.LocalAddress != test.localAddrWithPrefix.Address {
|
||||
t.Errorf("got pkt.Route.LocalAddress = %s, want = %s", pkt.Route.LocalAddress, test.localAddrWithPrefix.Address)
|
||||
if pkt.EgressRoute.LocalAddress != test.localAddrWithPrefix.Address {
|
||||
t.Errorf("got pkt.EgressRoute.LocalAddress = %s, want = %s", pkt.EgressRoute.LocalAddress, test.localAddrWithPrefix.Address)
|
||||
}
|
||||
if pkt.Route.RemoteAddress != test.netCfg.remoteAddr {
|
||||
t.Errorf("got pkt.Route.RemoteAddress = %s, want = %s", pkt.Route.RemoteAddress, test.netCfg.remoteAddr)
|
||||
if pkt.EgressRoute.RemoteAddress != test.netCfg.remoteAddr {
|
||||
t.Errorf("got pkt.EgressRoute.RemoteAddress = %s, want = %s", pkt.EgressRoute.RemoteAddress, test.netCfg.remoteAddr)
|
||||
}
|
||||
|
||||
if !test.forwardingEnabled || !test.dependentOnForwarding {
|
||||
@@ -4499,18 +4499,18 @@ func TestWritePacketToRemote(t *testing.T) {
|
||||
t.Fatalf("s.WritePacketToRemote(_, _, _, _) = %s", err)
|
||||
}
|
||||
|
||||
pkt, ok := e.Read()
|
||||
if got, want := ok, true; got != want {
|
||||
pkt := e.Read()
|
||||
if got, want := pkt != nil, true; got != want {
|
||||
t.Fatalf("e.Read() = %t, want %t", got, want)
|
||||
}
|
||||
if got, want := pkt.Proto, test.protocol; got != want {
|
||||
t.Fatalf("pkt.Proto = %d, want %d", got, want)
|
||||
if got, want := pkt.NetworkProtocolNumber, test.protocol; got != want {
|
||||
t.Fatalf("pkt.NetworkProtocolNumber = %d, want %d", got, want)
|
||||
}
|
||||
if pkt.Route.RemoteLinkAddress != linkAddr2 {
|
||||
t.Fatalf("pkt.Route.RemoteAddress = %s, want %s", pkt.Route.RemoteLinkAddress, linkAddr2)
|
||||
if pkt.EgressRoute.RemoteLinkAddress != linkAddr2 {
|
||||
t.Fatalf("pkt.EgressRoute.RemoteAddress = %s, want %s", pkt.EgressRoute.RemoteLinkAddress, linkAddr2)
|
||||
}
|
||||
if diff := cmp.Diff(pkt.Pkt.Data().AsRange().ToOwnedView(), buffer.View(test.payload)); diff != "" {
|
||||
t.Errorf("pkt.Pkt.Data mismatch (-want +got):\n%s", diff)
|
||||
if diff := cmp.Diff(pkt.Data().AsRange().ToOwnedView(), buffer.View(test.payload)); diff != "" {
|
||||
t.Errorf("pkt.Data mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -4520,8 +4520,8 @@ func TestWritePacketToRemote(t *testing.T) {
|
||||
if _, ok := err.(*tcpip.ErrUnknownDevice); !ok {
|
||||
t.Fatalf("s.WritePacketToRemote(_, _, _, _) = %s, want = %s", err, &tcpip.ErrUnknownDevice{})
|
||||
}
|
||||
pkt, ok := e.Read()
|
||||
if got, want := ok, false; got != want {
|
||||
pkt := e.Read()
|
||||
if got, want := pkt != nil, false; got != want {
|
||||
t.Fatalf("e.Read() = %t, %v; want %t", got, pkt, want)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -508,13 +508,13 @@ func TestMulticastForwarding(t *testing.T) {
|
||||
|
||||
test.rx(e1, test.srcAddr, test.dstAddr)
|
||||
|
||||
p, ok := e2.Read()
|
||||
if ok != test.expectForward {
|
||||
t.Fatalf("got e2.Read() = (%#v, %t), want = (_, %t)", p, ok, test.expectForward)
|
||||
p := e2.Read()
|
||||
if (p != nil) != test.expectForward {
|
||||
t.Fatalf("got e2.Read() = %#v, want = (_ == nil) = %t", p, test.expectForward)
|
||||
}
|
||||
|
||||
if test.expectForward {
|
||||
test.checker(t, stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
test.checker(t, stack.PayloadSince(p.NetworkHeader()))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -683,13 +683,13 @@ func TestPerInterfaceForwarding(t *testing.T) {
|
||||
})
|
||||
|
||||
test.rx(subTest.nicEP, test.srcAddr, test.dstAddr)
|
||||
if p, ok := subTest.nicEP.Read(); ok {
|
||||
if p := subTest.nicEP.Read(); p != nil {
|
||||
t.Errorf("unexpectedly got a response from the interface the packet arrived on: %#v", p)
|
||||
}
|
||||
if p, ok := subTest.otherNICEP.Read(); ok != subTest.expectForwarding {
|
||||
if p := subTest.otherNICEP.Read(); (p != nil) != subTest.expectForwarding {
|
||||
t.Errorf("got otherNICEP.Read() = (%#v, %t), want = (_, %t)", p, ok, subTest.expectForwarding)
|
||||
} else if subTest.expectForwarding {
|
||||
test.checker(t, stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
test.checker(t, stack.PayloadSince(p.NetworkHeader()))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -957,12 +957,12 @@ func TestForwardingHook(t *testing.T) {
|
||||
t.Errorf("got ip2Stats.PacketsSent.Value() = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
p, ok := e2.Read()
|
||||
if ok != expectTransmitPacket {
|
||||
t.Fatalf("got e2.Read() = (%#v, %t), want = (_, %t)", p, ok, expectTransmitPacket)
|
||||
p := e2.Read()
|
||||
if (p != nil) != expectTransmitPacket {
|
||||
t.Fatalf("got e2.Read() = %#v, want = (_ == nil) = %t", p, expectTransmitPacket)
|
||||
}
|
||||
if expectTransmitPacket {
|
||||
test.checker(t, stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
test.checker(t, stack.PayloadSince(p.NetworkHeader()))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1147,13 +1147,13 @@ func TestInputHookWithLocalForwarding(t *testing.T) {
|
||||
t.Errorf("got ip2Stats.PacketsSent.Value() = %d, want = 0", got)
|
||||
}
|
||||
|
||||
if p, ok := e1.Read(); ok == subTest.expectDrop {
|
||||
t.Errorf("got e1.Read() = (%#v, %t), want = (_, %t)", p, ok, !subTest.expectDrop)
|
||||
if p := e1.Read(); (p != nil) == subTest.expectDrop {
|
||||
t.Errorf("got e1.Read() = %#v, want = (_ == nil) = %t", p, !subTest.expectDrop)
|
||||
} else if !subTest.expectDrop {
|
||||
test.checker(t, stack.PayloadSince(p.Pkt.NetworkHeader()))
|
||||
test.checker(t, stack.PayloadSince(p.NetworkHeader()))
|
||||
}
|
||||
if p, ok := e2.Read(); ok {
|
||||
t.Errorf("got e1.Read() = (%#v, true), want = (_, false)", p)
|
||||
if p := e2.Read(); p != nil {
|
||||
t.Errorf("got e1.Read() = %#v, want = nil)", p)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1502,11 +1502,11 @@ func TestNATEcho(t *testing.T) {
|
||||
ep2.InjectInbound(test.netProto, stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: test.echoPkt(natTypeTest.requestSrc, natTypeTest.requestDst, false /* reply */).ToVectorisedView(),
|
||||
}))
|
||||
pkt, ok := ep1.Read()
|
||||
if !ok {
|
||||
pkt := ep1.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to read a packet on ep1")
|
||||
}
|
||||
test.checkEchoPkt(t, stack.PayloadSince(pkt.Pkt.NetworkHeader()), natTypeTest.expectedRequestSrc, natTypeTest.expectedRequestDst, false /* reply */)
|
||||
test.checkEchoPkt(t, stack.PayloadSince(pkt.NetworkHeader()), natTypeTest.expectedRequestSrc, natTypeTest.expectedRequestDst, false /* reply */)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
@@ -1518,11 +1518,11 @@ func TestNATEcho(t *testing.T) {
|
||||
ep1.InjectInbound(test.netProto, stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: test.echoPkt(natTypeTest.expectedRequestDst, natTypeTest.expectedRequestSrc, true /* reply */).ToVectorisedView(),
|
||||
}))
|
||||
pkt, ok := ep2.Read()
|
||||
if !ok {
|
||||
pkt := ep2.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to read a packet on ep2")
|
||||
}
|
||||
test.checkEchoPkt(t, stack.PayloadSince(pkt.Pkt.NetworkHeader()), natTypeTest.requestDst, natTypeTest.requestSrc, true /* reply */)
|
||||
test.checkEchoPkt(t, stack.PayloadSince(pkt.NetworkHeader()), natTypeTest.requestDst, natTypeTest.requestSrc, true /* reply */)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2485,11 +2485,11 @@ func TestNATICMPError(t *testing.T) {
|
||||
}))
|
||||
|
||||
{
|
||||
pkt, ok := ep1.Read()
|
||||
if !ok {
|
||||
pkt := ep1.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to read a packet on ep1")
|
||||
}
|
||||
pktView := stack.PayloadSince(pkt.Pkt.NetworkHeader())
|
||||
pktView := stack.PayloadSince(pkt.NetworkHeader())
|
||||
transportType.checkNATed(t, pktView)
|
||||
if t.Failed() {
|
||||
t.FailNow()
|
||||
@@ -2503,16 +2503,16 @@ func TestNATICMPError(t *testing.T) {
|
||||
}))
|
||||
}
|
||||
|
||||
pkt, ok := ep2.Read()
|
||||
pkt := ep2.Read()
|
||||
expectResponse := icmpType.expectResponse && trimTest.expectNATedICMP
|
||||
if ok != expectResponse {
|
||||
t.Fatalf("got ep2.Read() = (%#v, %t), want = (_, %t)", pkt, ok, expectResponse)
|
||||
if (pkt != nil) != expectResponse {
|
||||
t.Fatalf("got ep2.Read() = %#v, want = (_ == nil) = %t", pkt, expectResponse)
|
||||
}
|
||||
if !expectResponse {
|
||||
return
|
||||
}
|
||||
test.decrementTTL(buf)
|
||||
test.checkNATedError(t, stack.PayloadSince(pkt.Pkt.NetworkHeader()), buf, icmpType.val)
|
||||
test.checkNATedError(t, stack.PayloadSince(pkt.NetworkHeader()), buf, icmpType.val)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -2851,11 +2851,11 @@ func TestSNATHandlePortOrIdentConflicts(t *testing.T) {
|
||||
Data: transportType.buf(srcAddr, srcPortOrIdent).ToVectorisedView(),
|
||||
}))
|
||||
|
||||
pkt, ok := ep1.Read()
|
||||
if !ok {
|
||||
pkt := ep1.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected to read a packet on ep1")
|
||||
}
|
||||
pktView := stack.PayloadSince(pkt.Pkt.NetworkHeader())
|
||||
pktView := stack.PayloadSince(pkt.NetworkHeader())
|
||||
transportType.checkNATed(t, pktView, srcPortOrIdent, i == 0, srcPortOrIdentRange.targetRange)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -430,14 +430,14 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
||||
utils.RxICMPv6EchoRequest(e, src, dst, ttl)
|
||||
}
|
||||
|
||||
arpChecker := func(t *testing.T, request channel.PacketInfo, src, dst tcpip.Address) {
|
||||
if request.Proto != arp.ProtocolNumber {
|
||||
t.Errorf("got request.Proto = %d, want = %d", request.Proto, arp.ProtocolNumber)
|
||||
arpChecker := func(t *testing.T, request *stack.PacketBuffer, src, dst tcpip.Address) {
|
||||
if request.NetworkProtocolNumber != arp.ProtocolNumber {
|
||||
t.Errorf("got request.NetworkProtocolNumber = %d, want = %d", request.NetworkProtocolNumber, arp.ProtocolNumber)
|
||||
}
|
||||
if request.Route.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got request.Route.RemoteLinkAddress = %s, want = %s", request.Route.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
if request.EgressRoute.RemoteLinkAddress != header.EthernetBroadcastAddress {
|
||||
t.Errorf("got request.EgressRoute.RemoteLinkAddress = %s, want = %s", request.EgressRoute.RemoteLinkAddress, header.EthernetBroadcastAddress)
|
||||
}
|
||||
rep := header.ARP(request.Pkt.NetworkHeader().View())
|
||||
rep := header.ARP(request.NetworkHeader().View())
|
||||
if got := rep.Op(); got != header.ARPRequest {
|
||||
t.Errorf("got Op() = %d, want = %d", got, header.ARPRequest)
|
||||
}
|
||||
@@ -452,17 +452,17 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ndpChecker := func(t *testing.T, request channel.PacketInfo, src, dst tcpip.Address) {
|
||||
if request.Proto != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", request.Proto, header.IPv6ProtocolNumber)
|
||||
ndpChecker := func(t *testing.T, request *stack.PacketBuffer, src, dst tcpip.Address) {
|
||||
if request.NetworkProtocolNumber != header.IPv6ProtocolNumber {
|
||||
t.Fatalf("got Proto = %d, want = %d", request.NetworkProtocolNumber, header.IPv6ProtocolNumber)
|
||||
}
|
||||
|
||||
snmc := header.SolicitedNodeAddr(dst)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); request.Route.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", request.Route.RemoteLinkAddress, want)
|
||||
if want := header.EthernetAddressFromMulticastIPv6Address(snmc); request.EgressRoute.RemoteLinkAddress != want {
|
||||
t.Errorf("got remote link address = %s, want = %s", request.EgressRoute.RemoteLinkAddress, want)
|
||||
}
|
||||
|
||||
checker.IPv6(t, stack.PayloadSince(request.Pkt.NetworkHeader()),
|
||||
checker.IPv6(t, stack.PayloadSince(request.NetworkHeader()),
|
||||
checker.SrcAddr(src),
|
||||
checker.DstAddr(snmc),
|
||||
checker.TTL(header.NDPHopLimit),
|
||||
@@ -506,7 +506,7 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
||||
outgoingAddr tcpip.AddressWithPrefix
|
||||
transportProtocol func(*stack.Stack) stack.TransportProtocol
|
||||
rx func(*channel.Endpoint, tcpip.Address, tcpip.Address)
|
||||
linkResolutionRequestChecker func(*testing.T, channel.PacketInfo, tcpip.Address, tcpip.Address)
|
||||
linkResolutionRequestChecker func(*testing.T, *stack.PacketBuffer, tcpip.Address, tcpip.Address)
|
||||
icmpReplyChecker func(*testing.T, []byte, tcpip.Address, tcpip.Address)
|
||||
mtu uint32
|
||||
}{
|
||||
@@ -613,8 +613,8 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
||||
clock.RunImmediatelyScheduledJobs()
|
||||
|
||||
for i := 0; i < int(nudConfigs.MaxMulticastProbes); i++ {
|
||||
request, ok := outgoingEndpoint.Read()
|
||||
if !ok {
|
||||
request := outgoingEndpoint.Read()
|
||||
if request == nil {
|
||||
t.Fatal("expected ARP packet through outgoing NIC")
|
||||
}
|
||||
|
||||
@@ -628,17 +628,17 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
||||
// necessary because outgoing packets are dequeued asynchronously when
|
||||
// link resolution fails, and this dequeue is what triggers the ICMP
|
||||
// error.
|
||||
reply, ok := incomingEndpoint.Read()
|
||||
if !ok {
|
||||
reply := incomingEndpoint.Read()
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP packet through incoming NIC")
|
||||
}
|
||||
|
||||
test.icmpReplyChecker(t, stack.PayloadSince(reply.Pkt.NetworkHeader()), test.incomingAddr.Address, test.sourceAddr)
|
||||
test.icmpReplyChecker(t, stack.PayloadSince(reply.NetworkHeader()), test.incomingAddr.Address, test.sourceAddr)
|
||||
|
||||
// Since link resolution failed, we don't expect the packet to be
|
||||
// forwarded.
|
||||
forwardedPacket, ok := outgoingEndpoint.Read()
|
||||
if ok {
|
||||
forwardedPacket := outgoingEndpoint.Read()
|
||||
if forwardedPacket != nil {
|
||||
t.Fatalf("expected no ICMP Echo packet through outgoing NIC, instead found: %#v", forwardedPacket)
|
||||
}
|
||||
|
||||
|
||||
@@ -141,21 +141,21 @@ func TestPingMulticastBroadcast(t *testing.T) {
|
||||
})
|
||||
|
||||
test.rxICMP(e, test.srcAddr, test.dstAddr, ttl)
|
||||
pkt, ok := e.Read()
|
||||
if !ok {
|
||||
pkt := e.Read()
|
||||
if pkt == nil {
|
||||
t.Fatal("expected ICMP response")
|
||||
}
|
||||
|
||||
if pkt.Route.LocalAddress != test.expectedSrc {
|
||||
t.Errorf("got pkt.Route.LocalAddress = %s, want = %s", pkt.Route.LocalAddress, test.expectedSrc)
|
||||
if pkt.EgressRoute.LocalAddress != test.expectedSrc {
|
||||
t.Errorf("got pkt.EgressRoute.LocalAddress = %s, want = %s", pkt.EgressRoute.LocalAddress, test.expectedSrc)
|
||||
}
|
||||
// The destination of the response packet should be the source of the
|
||||
// original packet.
|
||||
if pkt.Route.RemoteAddress != test.srcAddr {
|
||||
t.Errorf("got pkt.Route.RemoteAddress = %s, want = %s", pkt.Route.RemoteAddress, test.srcAddr)
|
||||
if pkt.EgressRoute.RemoteAddress != test.srcAddr {
|
||||
t.Errorf("got pkt.EgressRoute.RemoteAddress = %s, want = %s", pkt.EgressRoute.RemoteAddress, test.srcAddr)
|
||||
}
|
||||
|
||||
src, dst := s.NetworkProtocolInstance(test.protoNum).ParseAddresses(stack.PayloadSince(pkt.Pkt.NetworkHeader()))
|
||||
src, dst := s.NetworkProtocolInstance(test.protoNum).ParseAddresses(stack.PayloadSince(pkt.NetworkHeader()))
|
||||
if src != test.expectedSrc {
|
||||
t.Errorf("got pkt source = %s, want = %s", src, test.expectedSrc)
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the packet was sent out the default NIC.
|
||||
p, ok := defaultEP.Read()
|
||||
if !ok {
|
||||
p := defaultEP.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("got defaultEP.Read(_) = _, false; want = _, true (packet wasn't written out)")
|
||||
}
|
||||
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(p.Size(), p.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
checker.IPv4(t, b, []checker.NetworkChecker{
|
||||
@@ -148,7 +148,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) {
|
||||
}...)
|
||||
|
||||
// Verify the packet was not sent out the alternate NIC.
|
||||
if p, ok := alternateEP.Read(); ok {
|
||||
if p := alternateEP.Read(); p != nil {
|
||||
t.Fatalf("got alternateEP.Read(_) = %+v, true; want = _, false", p)
|
||||
}
|
||||
}
|
||||
@@ -172,17 +172,17 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the packet was not sent out the default NIC.
|
||||
if p, ok := defaultEP.Read(); ok {
|
||||
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, ok := alternateEP.Read()
|
||||
if !ok {
|
||||
p := alternateEP.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("got alternateEP.Read(_) = _, false; want = _, true (packet wasn't written out)")
|
||||
}
|
||||
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(p.Size(), p.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
checker.IPv4(t, b, []checker.NetworkChecker{
|
||||
@@ -214,12 +214,12 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify the packet was sent out the default NIC.
|
||||
p, ok := defaultEP.Read()
|
||||
if !ok {
|
||||
p := defaultEP.Read()
|
||||
if p == nil {
|
||||
t.Fatalf("got defaultEP.Read(_) = _, false; want = _, true (packet wasn't written out)")
|
||||
}
|
||||
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(p.Size(), p.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
checker.IPv4(t, b, []checker.NetworkChecker{
|
||||
@@ -232,7 +232,7 @@ func TestWriteUnboundWithBindToDevice(t *testing.T) {
|
||||
}...)
|
||||
|
||||
// Verify the packet was not sent out the alternate NIC.
|
||||
if p, ok := alternateEP.Read(); ok {
|
||||
if p := alternateEP.Read(); p != nil {
|
||||
t.Fatalf("got alternateEP.Read(_) = %+v, true; want = _, false", p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,10 +204,10 @@ func TestEndpointStateTransitions(t *testing.T) {
|
||||
}), false /* headerIncluded */); err != nil {
|
||||
t.Fatalf("ctx.WritePacket(_, false): %s", err)
|
||||
}
|
||||
if pkt, ok := e.Read(); !ok {
|
||||
if pkt := e.Read(); pkt == nil {
|
||||
t.Fatalf("expected packet to be read from link endpoint")
|
||||
} else {
|
||||
test.checker(t, stack.PayloadSince(pkt.Pkt.NetworkHeader()))
|
||||
test.checker(t, stack.PayloadSince(pkt.NetworkHeader()))
|
||||
}
|
||||
|
||||
ep.Close()
|
||||
|
||||
@@ -296,7 +296,7 @@ func (c *Context) CheckNoPacketTimeout(errMsg string, wait time.Duration) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), wait)
|
||||
defer cancel()
|
||||
if _, ok := c.linkEP.ReadContext(ctx); ok {
|
||||
if c.linkEP.ReadContext(ctx) != nil {
|
||||
c.t.Fatal(errMsg)
|
||||
}
|
||||
}
|
||||
@@ -315,28 +315,28 @@ func (c *Context) GetPacketWithTimeout(timeout time.Duration) []byte {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
p, ok := c.linkEP.ReadContext(ctx)
|
||||
if !ok {
|
||||
pkt := c.linkEP.ReadContext(ctx)
|
||||
if pkt == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.Proto != ipv4.ProtocolNumber {
|
||||
c.t.Fatalf("Bad network protocol: got %v, wanted %v", p.Proto, ipv4.ProtocolNumber)
|
||||
if got, want := pkt.NetworkProtocolNumber, ipv4.ProtocolNumber; got != want {
|
||||
c.t.Fatalf("got pkt.NetworkProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
// Just check that the stack set the transport protocol number for outbound
|
||||
// TCP messages.
|
||||
// TODO(gvisor.dev/issues/3810): Remove when protocol numbers are part
|
||||
// of the headerinfo.
|
||||
if p.Pkt.TransportProtocolNumber != tcp.ProtocolNumber {
|
||||
c.t.Fatalf("got p.Pkt.TransportProtocolNumber = %d, want = %d", p.Pkt.TransportProtocolNumber, tcp.ProtocolNumber)
|
||||
if got, want := pkt.TransportProtocolNumber, tcp.ProtocolNumber; got != want {
|
||||
c.t.Fatalf("got pkt.TransportProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(pkt.Size(), pkt.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
if p.Pkt.GSOOptions.Type != stack.GSONone && p.Pkt.GSOOptions.L3HdrLen != header.IPv4MinimumSize {
|
||||
c.t.Errorf("got L3HdrLen = %d, want = %d", p.Pkt.GSOOptions.L3HdrLen, header.IPv4MinimumSize)
|
||||
if pkt.GSOOptions.Type != stack.GSONone && pkt.GSOOptions.L3HdrLen != header.IPv4MinimumSize {
|
||||
c.t.Errorf("got L3HdrLen = %d, want = %d", pkt.GSOOptions.L3HdrLen, header.IPv4MinimumSize)
|
||||
}
|
||||
|
||||
checker.IPv4(c.t, b, checker.SrcAddr(StackAddr), checker.DstAddr(TestAddr))
|
||||
@@ -365,24 +365,24 @@ func (c *Context) GetPacket() []byte {
|
||||
func (c *Context) GetPacketNonBlocking() []byte {
|
||||
c.t.Helper()
|
||||
|
||||
p, ok := c.linkEP.Read()
|
||||
if !ok {
|
||||
pkt := c.linkEP.Read()
|
||||
if pkt == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.Proto != ipv4.ProtocolNumber {
|
||||
c.t.Fatalf("Bad network protocol: got %v, wanted %v", p.Proto, ipv4.ProtocolNumber)
|
||||
if got, want := pkt.NetworkProtocolNumber, ipv4.ProtocolNumber; got != want {
|
||||
c.t.Fatalf("got pkt.NetworkProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
// Just check that the stack set the transport protocol number for outbound
|
||||
// TCP messages.
|
||||
// TODO(gvisor.dev/issues/3810): Remove when protocol numbers are part
|
||||
// of the headerinfo.
|
||||
if p.Pkt.TransportProtocolNumber != tcp.ProtocolNumber {
|
||||
c.t.Fatalf("got p.Pkt.TransportProtocolNumber = %d, want = %d", p.Pkt.TransportProtocolNumber, tcp.ProtocolNumber)
|
||||
if got, want := pkt.TransportProtocolNumber, tcp.ProtocolNumber; got != want {
|
||||
c.t.Fatalf("got pkt.TransportProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(pkt.Size(), pkt.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
checker.IPv4(c.t, b, checker.SrcAddr(StackAddr), checker.DstAddr(TestAddr))
|
||||
@@ -609,16 +609,16 @@ func (c *Context) GetV6Packet() []byte {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
p, ok := c.linkEP.ReadContext(ctx)
|
||||
if !ok {
|
||||
pkt := c.linkEP.ReadContext(ctx)
|
||||
if pkt == nil {
|
||||
c.t.Fatalf("Packet wasn't written out")
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.Proto != ipv6.ProtocolNumber {
|
||||
c.t.Fatalf("Bad network protocol: got %v, wanted %v", p.Proto, ipv6.ProtocolNumber)
|
||||
if got, want := pkt.NetworkProtocolNumber, ipv6.ProtocolNumber; got != want {
|
||||
c.t.Fatalf("got pkt.NetworkProtocolNumber = %d, want = %d", got, want)
|
||||
}
|
||||
vv := buffer.NewVectorisedView(p.Pkt.Size(), p.Pkt.Views())
|
||||
vv := buffer.NewVectorisedView(pkt.Size(), pkt.Views())
|
||||
b := vv.ToView()
|
||||
|
||||
checker.IPv6(c.t, b, checker.SrcAddr(StackV6Addr), checker.DstAddr(TestV6Addr))
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user