Remove detritus
- Unused constants - Unused functions - Unused arguments - Unkeyed literals - Unnecessary conversions PiperOrigin-RevId: 375253464
This commit is contained in:
parent
f77a24966e
commit
74b10e31a4
|
@ -701,7 +701,7 @@ func TCPTimestampChecker(wantTS bool, wantTSVal uint32, wantTSEcr uint32) Transp
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
opts := []byte(tcp.Options())
|
||||
opts := tcp.Options()
|
||||
limit := len(opts)
|
||||
foundTS := false
|
||||
tsVal := uint32(0)
|
||||
|
@ -748,12 +748,6 @@ func TCPTimestampChecker(wantTS bool, wantTSVal uint32, wantTSEcr uint32) Transp
|
|||
}
|
||||
}
|
||||
|
||||
// TCPNoSACKBlockChecker creates a checker that verifies that the segment does
|
||||
// not contain any SACK blocks in the TCP options.
|
||||
func TCPNoSACKBlockChecker() TransportChecker {
|
||||
return TCPSACKBlockChecker(nil)
|
||||
}
|
||||
|
||||
// TCPSACKBlockChecker creates a checker that verifies that the segment does
|
||||
// contain the specified SACK blocks in the TCP options.
|
||||
func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker {
|
||||
|
@ -765,7 +759,7 @@ func TCPSACKBlockChecker(sackBlocks []header.SACKBlock) TransportChecker {
|
|||
}
|
||||
var gotSACKBlocks []header.SACKBlock
|
||||
|
||||
opts := []byte(tcp.Options())
|
||||
opts := tcp.Options()
|
||||
limit := len(opts)
|
||||
for i := 0; i < limit; {
|
||||
switch opts[i] {
|
||||
|
|
|
@ -77,12 +77,12 @@ const (
|
|||
|
||||
// ndpPrefixInformationOnLinkFlagMask is the mask of the On-Link Flag
|
||||
// field in the flags byte within an NDPPrefixInformation.
|
||||
ndpPrefixInformationOnLinkFlagMask = (1 << 7)
|
||||
ndpPrefixInformationOnLinkFlagMask = 1 << 7
|
||||
|
||||
// ndpPrefixInformationAutoAddrConfFlagMask is the mask of the
|
||||
// Autonomous Address-Configuration flag field in the flags byte within
|
||||
// an NDPPrefixInformation.
|
||||
ndpPrefixInformationAutoAddrConfFlagMask = (1 << 6)
|
||||
ndpPrefixInformationAutoAddrConfFlagMask = 1 << 6
|
||||
|
||||
// ndpPrefixInformationReserved1FlagsMask is the mask of the Reserved1
|
||||
// field in the flags byte within an NDPPrefixInformation.
|
||||
|
@ -451,7 +451,7 @@ func (o NDPNonceOption) String() string {
|
|||
|
||||
// Nonce returns the nonce value this option holds.
|
||||
func (o NDPNonceOption) Nonce() []byte {
|
||||
return []byte(o)
|
||||
return o
|
||||
}
|
||||
|
||||
// NDPSourceLinkLayerAddressOption is the NDP Source Link Layer Option
|
||||
|
|
|
@ -288,5 +288,5 @@ func (*Endpoint) ARPHardwareType() header.ARPHardwareType {
|
|||
}
|
||||
|
||||
// AddHeader implements stack.LinkEndpoint.AddHeader.
|
||||
func (e *Endpoint) AddHeader(local, remote tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
|
||||
func (*Endpoint) AddHeader(tcpip.LinkAddress, tcpip.LinkAddress, tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
|
||||
}
|
||||
|
|
|
@ -396,7 +396,7 @@ func TestDirectRequest(t *testing.T) {
|
|||
nicID: nicID,
|
||||
entry: stack.NeighborEntry{
|
||||
Addr: test.senderAddr,
|
||||
LinkAddr: tcpip.LinkAddress(test.senderLinkAddr),
|
||||
LinkAddr: test.senderLinkAddr,
|
||||
State: stack.Stale,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -112,10 +112,6 @@ func TestExcludeBroadcast(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
type forwardedPacket struct {
|
||||
fragments []fragmentInfo
|
||||
}
|
||||
|
||||
func TestForwarding(t *testing.T) {
|
||||
const (
|
||||
incomingNICID = 1
|
||||
|
@ -453,7 +449,7 @@ func TestForwarding(t *testing.T) {
|
|||
return len(hdr.View())
|
||||
}
|
||||
|
||||
checker.IPv4(t, header.IPv4(stack.PayloadSince(reply.Pkt.NetworkHeader())),
|
||||
checker.IPv4(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.SrcAddr(incomingIPv4Addr.Address),
|
||||
checker.DstAddr(test.sourceAddr),
|
||||
checker.TTL(ipv4.DefaultTTL),
|
||||
|
@ -461,7 +457,7 @@ func TestForwarding(t *testing.T) {
|
|||
checker.ICMPv4Checksum(),
|
||||
checker.ICMPv4Type(test.icmpType),
|
||||
checker.ICMPv4Code(test.icmpCode),
|
||||
checker.ICMPv4Payload([]byte(hdr.View()[0:expectedICMPPayloadLength()])),
|
||||
checker.ICMPv4Payload(hdr.View()[:expectedICMPPayloadLength()]),
|
||||
),
|
||||
)
|
||||
} else if ok {
|
||||
|
@ -470,7 +466,7 @@ func TestForwarding(t *testing.T) {
|
|||
|
||||
if test.expectPacketForwarded {
|
||||
if len(test.expectedFragmentsForwarded) != 0 {
|
||||
fragmentedPackets := []*stack.PacketBuffer{}
|
||||
var fragmentedPackets []*stack.PacketBuffer
|
||||
for i := 0; i < len(test.expectedFragmentsForwarded); i++ {
|
||||
reply, ok = outgoingEndpoint.Read()
|
||||
if !ok {
|
||||
|
@ -487,7 +483,7 @@ func TestForwarding(t *testing.T) {
|
|||
// maximum IP header size and the maximum size allocated for link layer
|
||||
// headers. In this case, no size is allocated for link layer headers.
|
||||
expectedAvailableHeaderBytes := header.IPv4MaximumHeaderSize
|
||||
if err := compareFragments(fragmentedPackets, requestPkt, uint32(test.mtu), test.expectedFragmentsForwarded, header.ICMPv4ProtocolNumber, true /* withIPHeader */, expectedAvailableHeaderBytes); err != nil {
|
||||
if err := compareFragments(fragmentedPackets, requestPkt, test.mtu, test.expectedFragmentsForwarded, header.ICMPv4ProtocolNumber, true /* withIPHeader */, expectedAvailableHeaderBytes); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
|
@ -496,7 +492,7 @@ func TestForwarding(t *testing.T) {
|
|||
t.Fatal("expected ICMP Echo packet through outgoing NIC")
|
||||
}
|
||||
|
||||
checker.IPv4(t, header.IPv4(stack.PayloadSince(reply.Pkt.NetworkHeader())),
|
||||
checker.IPv4(t, stack.PayloadSince(reply.Pkt.NetworkHeader()),
|
||||
checker.SrcAddr(test.sourceAddr),
|
||||
checker.DstAddr(test.destAddr),
|
||||
checker.TTL(test.TTL-1),
|
||||
|
@ -1315,7 +1311,7 @@ func TestIPv4Sanity(t *testing.T) {
|
|||
checker.ICMPv4Type(test.ICMPType),
|
||||
checker.ICMPv4Code(test.ICMPCode),
|
||||
checker.ICMPv4Pointer(test.paramProblemPointer),
|
||||
checker.ICMPv4Payload([]byte(hdr.View())),
|
||||
checker.ICMPv4Payload(hdr.View()),
|
||||
),
|
||||
)
|
||||
return
|
||||
|
@ -1334,7 +1330,7 @@ func TestIPv4Sanity(t *testing.T) {
|
|||
checker.ICMPv4(
|
||||
checker.ICMPv4Type(test.ICMPType),
|
||||
checker.ICMPv4Code(test.ICMPCode),
|
||||
checker.ICMPv4Payload([]byte(hdr.View())),
|
||||
checker.ICMPv4Payload(hdr.View()),
|
||||
),
|
||||
)
|
||||
return
|
||||
|
@ -2301,7 +2297,7 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
|||
checker.ICMPv4Type(header.ICMPv4TimeExceeded),
|
||||
checker.ICMPv4Code(header.ICMPv4ReassemblyTimeout),
|
||||
checker.ICMPv4Checksum(),
|
||||
checker.ICMPv4Payload([]byte(firstFragmentSent)),
|
||||
checker.ICMPv4Payload(firstFragmentSent),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
@ -2705,7 +2701,7 @@ func TestReceiveFragments(t *testing.T) {
|
|||
TransportProtocols: []stack.TransportProtocolFactory{udp.NewProtocol},
|
||||
RawFactory: raw.EndpointFactory{},
|
||||
})
|
||||
e := channel.New(0, 1280, tcpip.LinkAddress("\xf0\x00"))
|
||||
e := channel.New(0, 1280, "\xf0\x00")
|
||||
if err := s.CreateNIC(nicID, e); err != nil {
|
||||
t.Fatalf("CreateNIC(%d, _) = %s", nicID, err)
|
||||
}
|
||||
|
@ -3074,7 +3070,7 @@ func TestPacketQueing(t *testing.T) {
|
|||
Length: header.UDPMinimumSize,
|
||||
})
|
||||
sum := header.PseudoHeaderChecksum(udp.ProtocolNumber, host2IPv4Addr.AddressWithPrefix.Address, host1IPv4Addr.AddressWithPrefix.Address, header.UDPMinimumSize)
|
||||
sum = header.Checksum(header.UDP([]byte{}), sum)
|
||||
sum = header.Checksum(nil, sum)
|
||||
u.SetChecksum(^u.CalculateChecksum(sum))
|
||||
ip := header.IPv4(hdr.Prepend(header.IPv4MinimumSize))
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
|
@ -3253,7 +3249,7 @@ func TestCloseLocking(t *testing.T) {
|
|||
TransportProtocols: []stack.TransportProtocolFactory{udp.NewProtocol},
|
||||
})
|
||||
|
||||
// Perform NAT so that the endoint tries to search for a sibling endpoint
|
||||
// Perform NAT so that the endpoint tries to search for a sibling endpoint
|
||||
// which ends up taking the protocol and endpoint lock (in that order).
|
||||
table := stack.Table{
|
||||
Rules: []stack.Rule{
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
|
@ -46,16 +45,12 @@ const (
|
|||
defaultChannelSize = 1
|
||||
defaultMTU = 65536
|
||||
|
||||
// Extra time to use when waiting for an async event to occur.
|
||||
defaultAsyncPositiveEventTimeout = 30 * time.Second
|
||||
|
||||
arbitraryHopLimit = 42
|
||||
)
|
||||
|
||||
var (
|
||||
lladdr0 = header.LinkLocalAddr(linkAddr0)
|
||||
lladdr1 = header.LinkLocalAddr(linkAddr1)
|
||||
lladdr2 = header.LinkLocalAddr(linkAddr2)
|
||||
)
|
||||
|
||||
type stubLinkEndpoint struct {
|
||||
|
@ -1309,7 +1304,7 @@ func TestPacketQueing(t *testing.T) {
|
|||
Length: header.UDPMinimumSize,
|
||||
})
|
||||
sum := header.PseudoHeaderChecksum(udp.ProtocolNumber, host2IPv6Addr.AddressWithPrefix.Address, host1IPv6Addr.AddressWithPrefix.Address, header.UDPMinimumSize)
|
||||
sum = header.Checksum(header.UDP([]byte{}), sum)
|
||||
sum = header.Checksum(nil, sum)
|
||||
u.SetChecksum(^u.CalculateChecksum(sum))
|
||||
payloadLength := hdr.UsedLength()
|
||||
ip := header.IPv6(hdr.Prepend(header.IPv6MinimumSize))
|
||||
|
|
|
@ -1754,7 +1754,7 @@ func (ndp *ndpState) startSolicitingRouters() {
|
|||
header.NDPSourceLinkLayerAddressOption(linkAddress),
|
||||
}
|
||||
}
|
||||
payloadSize := header.ICMPv6HeaderSize + header.NDPRSMinimumSize + int(optsSerializer.Length())
|
||||
payloadSize := header.ICMPv6HeaderSize + header.NDPRSMinimumSize + optsSerializer.Length()
|
||||
icmpData := header.ICMPv6(buffer.NewView(payloadSize))
|
||||
icmpData.SetType(header.ICMPv6RouterSolicit)
|
||||
rs := header.NDPRouterSolicit(icmpData.MessageBody())
|
||||
|
|
|
@ -32,58 +32,6 @@ import (
|
|||
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
|
||||
)
|
||||
|
||||
// setupStackAndEndpoint creates a stack with a single NIC with a link-local
|
||||
// address llladdr and an IPv6 endpoint to a remote with link-local address
|
||||
// rlladdr
|
||||
func setupStackAndEndpoint(t *testing.T, llladdr, rlladdr tcpip.Address) (*stack.Stack, stack.NetworkEndpoint) {
|
||||
t.Helper()
|
||||
|
||||
s := stack.New(stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
|
||||
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
|
||||
})
|
||||
|
||||
if err := s.CreateNIC(1, &stubLinkEndpoint{}); err != nil {
|
||||
t.Fatalf("CreateNIC(_) = %s", err)
|
||||
}
|
||||
{
|
||||
subnet, err := tcpip.NewSubnet(rlladdr, tcpip.AddressMask(strings.Repeat("\xff", len(rlladdr))))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.SetRouteTable(
|
||||
[]tcpip.Route{{
|
||||
Destination: subnet,
|
||||
NIC: 1,
|
||||
}},
|
||||
)
|
||||
}
|
||||
|
||||
netProto := s.NetworkProtocolInstance(ProtocolNumber)
|
||||
if netProto == nil {
|
||||
t.Fatalf("cannot find protocol instance for network protocol %d", ProtocolNumber)
|
||||
}
|
||||
|
||||
ep := netProto.NewEndpoint(&testInterface{}, &stubDispatcher{})
|
||||
if err := ep.Enable(); err != nil {
|
||||
t.Fatalf("ep.Enable(): %s", err)
|
||||
}
|
||||
t.Cleanup(ep.Close)
|
||||
|
||||
addressableEndpoint, ok := ep.(stack.AddressableEndpoint)
|
||||
if !ok {
|
||||
t.Fatalf("expected network endpoint to implement stack.AddressableEndpoint")
|
||||
}
|
||||
addr := llladdr.WithPrefix()
|
||||
if addressEP, err := addressableEndpoint.AddAndAcquirePermanentAddress(addr, stack.CanBePrimaryEndpoint, stack.AddressConfigStatic, false /* deprecated */); err != nil {
|
||||
t.Fatalf("addressableEndpoint.AddAndAcquirePermanentAddress(%s, CanBePrimaryEndpoint, AddressConfigStatic, false): %s", addr, err)
|
||||
} else {
|
||||
addressEP.DecRef()
|
||||
}
|
||||
|
||||
return s, ep
|
||||
}
|
||||
|
||||
var _ NDPDispatcher = (*testNDPDispatcher)(nil)
|
||||
|
||||
// testNDPDispatcher is an NDPDispatcher only allows default router discovery.
|
||||
|
@ -163,11 +111,6 @@ func TestStackNDPEndpointInvalidateDefaultRouter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type linkResolutionResult struct {
|
||||
linkAddr tcpip.LinkAddress
|
||||
ok bool
|
||||
}
|
||||
|
||||
// TestNeighborSolicitationWithSourceLinkLayerOption tests that receiving a
|
||||
// valid NDP NS message with the Source Link Layer Address option results in a
|
||||
// new entry in the link address cache for the sender of the message.
|
||||
|
|
|
@ -114,10 +114,6 @@ func (f *fwdTestNetworkEndpoint) MaxHeaderLength() uint16 {
|
|||
return f.nic.MaxHeaderLength() + fwdTestNetHeaderLen
|
||||
}
|
||||
|
||||
func (*fwdTestNetworkEndpoint) PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, dstAddr tcpip.Address) uint16 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (f *fwdTestNetworkEndpoint) NetworkProtocolNumber() tcpip.NetworkProtocolNumber {
|
||||
return f.proto.Number()
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ func (f *fwdTestNetworkEndpoint) WritePacket(r *Route, params NetworkHeaderParam
|
|||
}
|
||||
|
||||
// WritePackets implements LinkEndpoint.WritePackets.
|
||||
func (*fwdTestNetworkEndpoint) WritePackets(r *Route, pkts PacketBufferList, params NetworkHeaderParams) (int, tcpip.Error) {
|
||||
func (*fwdTestNetworkEndpoint) WritePackets(*Route, PacketBufferList, NetworkHeaderParams) (int, tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
@ -319,7 +315,7 @@ func (e *fwdTestLinkEndpoint) LinkAddress() tcpip.LinkAddress {
|
|||
return e.linkAddr
|
||||
}
|
||||
|
||||
func (e fwdTestLinkEndpoint) WritePacket(r RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
||||
func (e fwdTestLinkEndpoint) WritePacket(r RouteInfo, _ tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
|
||||
p := fwdTestPacketInfo{
|
||||
RemoteLinkAddress: r.RemoteLinkAddress,
|
||||
LocalLinkAddress: r.LocalLinkAddress,
|
||||
|
@ -354,7 +350,7 @@ func (*fwdTestLinkEndpoint) ARPHardwareType() header.ARPHardwareType {
|
|||
}
|
||||
|
||||
// AddHeader implements stack.LinkEndpoint.AddHeader.
|
||||
func (e *fwdTestLinkEndpoint) AddHeader(local, remote tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) {
|
||||
func (e *fwdTestLinkEndpoint) AddHeader(tcpip.LinkAddress, tcpip.LinkAddress, tcpip.NetworkProtocolNumber, *PacketBuffer) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
package stack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
@ -48,9 +46,6 @@ const (
|
|||
// be sent to all nodes.
|
||||
testEntryBroadcastAddr = tcpip.Address("broadcast")
|
||||
|
||||
// testEntryLocalAddr is the source address of neighbor probes.
|
||||
testEntryLocalAddr = tcpip.Address("local_addr")
|
||||
|
||||
// testEntryBroadcastLinkAddr is a special link address sent back to
|
||||
// multicast neighbor probes.
|
||||
testEntryBroadcastLinkAddr = tcpip.LinkAddress("mac_broadcast")
|
||||
|
@ -106,20 +101,24 @@ type testEntryStore struct {
|
|||
entriesMap map[tcpip.Address]NeighborEntry
|
||||
}
|
||||
|
||||
func toAddress(i int) tcpip.Address {
|
||||
buf := new(bytes.Buffer)
|
||||
binary.Write(buf, binary.BigEndian, uint8(1))
|
||||
binary.Write(buf, binary.BigEndian, uint8(0))
|
||||
binary.Write(buf, binary.BigEndian, uint16(i))
|
||||
return tcpip.Address(buf.String())
|
||||
func toAddress(i uint16) tcpip.Address {
|
||||
return tcpip.Address([]byte{
|
||||
1,
|
||||
0,
|
||||
byte(i >> 8),
|
||||
byte(i),
|
||||
})
|
||||
}
|
||||
|
||||
func toLinkAddress(i int) tcpip.LinkAddress {
|
||||
buf := new(bytes.Buffer)
|
||||
binary.Write(buf, binary.BigEndian, uint8(1))
|
||||
binary.Write(buf, binary.BigEndian, uint8(0))
|
||||
binary.Write(buf, binary.BigEndian, uint32(i))
|
||||
return tcpip.LinkAddress(buf.String())
|
||||
func toLinkAddress(i uint16) tcpip.LinkAddress {
|
||||
return tcpip.LinkAddress([]byte{
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
byte(i >> 8),
|
||||
byte(i),
|
||||
})
|
||||
}
|
||||
|
||||
// newTestEntryStore returns a testEntryStore pre-populated with entries.
|
||||
|
@ -127,7 +126,7 @@ func newTestEntryStore() *testEntryStore {
|
|||
store := &testEntryStore{
|
||||
entriesMap: make(map[tcpip.Address]NeighborEntry),
|
||||
}
|
||||
for i := 0; i < entryStoreSize; i++ {
|
||||
for i := uint16(0); i < entryStoreSize; i++ {
|
||||
addr := toAddress(i)
|
||||
linkAddr := toLinkAddress(i)
|
||||
|
||||
|
@ -140,15 +139,15 @@ func newTestEntryStore() *testEntryStore {
|
|||
}
|
||||
|
||||
// size returns the number of entries in the store.
|
||||
func (s *testEntryStore) size() int {
|
||||
func (s *testEntryStore) size() uint16 {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return len(s.entriesMap)
|
||||
return uint16(len(s.entriesMap))
|
||||
}
|
||||
|
||||
// entry returns the entry at index i. Returns an empty entry and false if i is
|
||||
// out of bounds.
|
||||
func (s *testEntryStore) entry(i int) (NeighborEntry, bool) {
|
||||
func (s *testEntryStore) entry(i uint16) (NeighborEntry, bool) {
|
||||
return s.entryByAddr(toAddress(i))
|
||||
}
|
||||
|
||||
|
@ -166,7 +165,7 @@ func (s *testEntryStore) entries() []NeighborEntry {
|
|||
entries := make([]NeighborEntry, 0, len(s.entriesMap))
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
for i := 0; i < entryStoreSize; i++ {
|
||||
for i := uint16(0); i < entryStoreSize; i++ {
|
||||
addr := toAddress(i)
|
||||
if entry, ok := s.entriesMap[addr]; ok {
|
||||
entries = append(entries, entry)
|
||||
|
@ -176,7 +175,7 @@ func (s *testEntryStore) entries() []NeighborEntry {
|
|||
}
|
||||
|
||||
// set modifies the link addresses of an entry.
|
||||
func (s *testEntryStore) set(i int, linkAddr tcpip.LinkAddress) {
|
||||
func (s *testEntryStore) set(i uint16, linkAddr tcpip.LinkAddress) {
|
||||
addr := toAddress(i)
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
@ -236,13 +235,6 @@ func (*testNeighborResolver) LinkAddressProtocol() tcpip.NetworkProtocolNumber {
|
|||
return 0
|
||||
}
|
||||
|
||||
type entryEvent struct {
|
||||
nicID tcpip.NICID
|
||||
address tcpip.Address
|
||||
linkAddr tcpip.LinkAddress
|
||||
state NeighborState
|
||||
}
|
||||
|
||||
func TestNeighborCacheGetConfig(t *testing.T) {
|
||||
nudDisp := testNUDDispatcher{}
|
||||
c := DefaultNUDConfigurations()
|
||||
|
@ -461,7 +453,7 @@ func newTestContext(c NUDConfigurations) testContext {
|
|||
}
|
||||
|
||||
type overflowOptions struct {
|
||||
startAtEntryIndex int
|
||||
startAtEntryIndex uint16
|
||||
wantStaticEntries []NeighborEntry
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1060,7 @@ func TestNeighborCacheKeepFrequentlyUsed(t *testing.T) {
|
|||
// periodically refreshes the frequently used entry.
|
||||
|
||||
// Fill the neighbor cache to capacity
|
||||
for i := 0; i < neighborCacheSize; i++ {
|
||||
for i := uint16(0); i < neighborCacheSize; i++ {
|
||||
entry, ok := linkRes.entries.entry(i)
|
||||
if !ok {
|
||||
t.Fatalf("got linkRes.entries.entry(%d) = _, false, want = true", i)
|
||||
|
@ -1084,7 +1076,7 @@ func TestNeighborCacheKeepFrequentlyUsed(t *testing.T) {
|
|||
}
|
||||
|
||||
// Keep adding more entries
|
||||
for i := neighborCacheSize; i < linkRes.entries.size(); i++ {
|
||||
for i := uint16(neighborCacheSize); i < linkRes.entries.size(); i++ {
|
||||
// Periodically refresh the frequently used entry
|
||||
if i%(neighborCacheSize/2) == 0 {
|
||||
if _, _, err := linkRes.neigh.entry(frequentlyUsedEntry.Addr, "", nil); err != nil {
|
||||
|
@ -1561,9 +1553,9 @@ func BenchmarkCacheClear(b *testing.B) {
|
|||
linkRes.delay = 0
|
||||
|
||||
// Clear for every possible size of the cache
|
||||
for cacheSize := 0; cacheSize < neighborCacheSize; cacheSize++ {
|
||||
for cacheSize := uint16(0); cacheSize < neighborCacheSize; cacheSize++ {
|
||||
// Fill the neighbor cache to capacity.
|
||||
for i := 0; i < cacheSize; i++ {
|
||||
for i := uint16(0); i < cacheSize; i++ {
|
||||
entry, ok := linkRes.entries.entry(i)
|
||||
if !ok {
|
||||
b.Fatalf("got linkRes.entries.entry(%d) = _, false, want = true", i)
|
||||
|
|
|
@ -36,11 +36,6 @@ const (
|
|||
|
||||
entryTestLinkAddr1 = tcpip.LinkAddress("\x0a\x00\x00\x00\x00\x01")
|
||||
entryTestLinkAddr2 = tcpip.LinkAddress("\x0a\x00\x00\x00\x00\x02")
|
||||
|
||||
// entryTestNetDefaultMTU is the MTU, in bytes, used throughout the tests,
|
||||
// except where another value is explicitly used. It is chosen to match the
|
||||
// MTU of loopback interfaces on Linux systems.
|
||||
entryTestNetDefaultMTU = 65536
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -196,13 +191,13 @@ func (r *entryTestLinkResolver) LinkAddressRequest(targetAddr, localAddr tcpip.A
|
|||
|
||||
// ResolveStaticAddress attempts to resolve address without sending requests.
|
||||
// It either resolves the name immediately or returns the empty LinkAddress.
|
||||
func (r *entryTestLinkResolver) ResolveStaticAddress(addr tcpip.Address) (tcpip.LinkAddress, bool) {
|
||||
func (*entryTestLinkResolver) ResolveStaticAddress(tcpip.Address) (tcpip.LinkAddress, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// LinkAddressProtocol returns the network protocol of the addresses this
|
||||
// resolver can resolve.
|
||||
func (r *entryTestLinkResolver) LinkAddressProtocol() tcpip.NetworkProtocolNumber {
|
||||
func (*entryTestLinkResolver) LinkAddressProtocol() tcpip.NetworkProtocolNumber {
|
||||
return entryTestNetNumber
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,15 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
defaultBaseReachableTime = 30 * time.Second
|
||||
minimumBaseReachableTime = time.Millisecond
|
||||
defaultMinRandomFactor = 0.5
|
||||
defaultMaxRandomFactor = 1.5
|
||||
defaultRetransmitTimer = time.Second
|
||||
minimumRetransmitTimer = time.Millisecond
|
||||
defaultDelayFirstProbeTime = 5 * time.Second
|
||||
defaultMaxMulticastProbes = 3
|
||||
defaultMaxUnicastProbes = 3
|
||||
defaultMaxAnycastDelayTime = time.Second
|
||||
defaultMaxReachbilityConfirmations = 3
|
||||
defaultBaseReachableTime = 30 * time.Second
|
||||
minimumBaseReachableTime = time.Millisecond
|
||||
defaultMinRandomFactor = 0.5
|
||||
defaultMaxRandomFactor = 1.5
|
||||
defaultRetransmitTimer = time.Second
|
||||
minimumRetransmitTimer = time.Millisecond
|
||||
defaultDelayFirstProbeTime = 5 * time.Second
|
||||
defaultMaxMulticastProbes = 3
|
||||
defaultMaxUnicastProbes = 3
|
||||
|
||||
defaultFakeRandomNum = 0.5
|
||||
)
|
||||
|
|
|
@ -40,13 +40,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// ageLimit is set to the same cache stale time used in Linux.
|
||||
ageLimit = 1 * time.Minute
|
||||
// resolutionTimeout is set to the same ARP timeout used in Linux.
|
||||
resolutionTimeout = 1 * time.Second
|
||||
// resolutionAttempts is set to the same ARP retries used in Linux.
|
||||
resolutionAttempts = 3
|
||||
|
||||
// DefaultTOS is the default type of service value for network endpoints.
|
||||
DefaultTOS = 0
|
||||
)
|
||||
|
|
|
@ -166,10 +166,6 @@ func (f *fakeNetworkEndpoint) MaxHeaderLength() uint16 {
|
|||
return f.nic.MaxHeaderLength() + fakeNetHeaderLen
|
||||
}
|
||||
|
||||
func (*fakeNetworkEndpoint) PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, dstAddr tcpip.Address) uint16 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (f *fakeNetworkEndpoint) NetworkProtocolNumber() tcpip.NetworkProtocolNumber {
|
||||
return f.proto.Number()
|
||||
}
|
||||
|
@ -197,11 +193,11 @@ func (f *fakeNetworkEndpoint) WritePacket(r *stack.Route, params stack.NetworkHe
|
|||
}
|
||||
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets.
|
||||
func (*fakeNetworkEndpoint) WritePackets(r *stack.Route, pkts stack.PacketBufferList, params stack.NetworkHeaderParams) (int, tcpip.Error) {
|
||||
func (*fakeNetworkEndpoint) WritePackets(*stack.Route, stack.PacketBufferList, stack.NetworkHeaderParams) (int, tcpip.Error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (*fakeNetworkEndpoint) WriteHeaderIncludedPacket(r *stack.Route, pkt *stack.PacketBuffer) tcpip.Error {
|
||||
func (*fakeNetworkEndpoint) WriteHeaderIncludedPacket(*stack.Route, *stack.PacketBuffer) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
|
@ -463,14 +459,14 @@ func testSend(t *testing.T, r *stack.Route, ep *channel.Endpoint, payload buffer
|
|||
}
|
||||
}
|
||||
|
||||
func testFailingSend(t *testing.T, r *stack.Route, ep *channel.Endpoint, payload buffer.View, wantErr tcpip.Error) {
|
||||
func testFailingSend(t *testing.T, r *stack.Route, payload buffer.View, wantErr tcpip.Error) {
|
||||
t.Helper()
|
||||
if gotErr := send(r, payload); gotErr != wantErr {
|
||||
t.Errorf("send failed: got = %s, want = %s ", gotErr, wantErr)
|
||||
}
|
||||
}
|
||||
|
||||
func testFailingSendTo(t *testing.T, s *stack.Stack, addr tcpip.Address, ep *channel.Endpoint, payload buffer.View, wantErr tcpip.Error) {
|
||||
func testFailingSendTo(t *testing.T, s *stack.Stack, addr tcpip.Address, payload buffer.View, wantErr tcpip.Error) {
|
||||
t.Helper()
|
||||
if gotErr := sendTo(s, addr, payload); gotErr != wantErr {
|
||||
t.Errorf("sendto failed: got = %s, want = %s ", gotErr, wantErr)
|
||||
|
@ -920,15 +916,15 @@ func TestRouteWithDownNIC(t *testing.T) {
|
|||
if err := test.downFn(s, nicID1); err != nil {
|
||||
t.Fatalf("test.downFn(_, %d): %s", nicID1, err)
|
||||
}
|
||||
testFailingSend(t, r1, ep1, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSend(t, r1, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testSend(t, r2, ep2, buf)
|
||||
|
||||
// Writes with Routes that use NIC2 after being brought down should fail.
|
||||
if err := test.downFn(s, nicID2); err != nil {
|
||||
t.Fatalf("test.downFn(_, %d): %s", nicID2, err)
|
||||
}
|
||||
testFailingSend(t, r1, ep1, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSend(t, r2, ep2, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSend(t, r1, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSend(t, r2, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
|
||||
if upFn := test.upFn; upFn != nil {
|
||||
// Writes with Routes that use NIC1 after being brought up should
|
||||
|
@ -941,7 +937,7 @@ func TestRouteWithDownNIC(t *testing.T) {
|
|||
t.Fatalf("test.upFn(_, %d): %s", nicID1, err)
|
||||
}
|
||||
testSend(t, r1, ep1, buf)
|
||||
testFailingSend(t, r2, ep2, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSend(t, r2, buf, &tcpip.ErrInvalidEndpointState{})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1066,7 +1062,7 @@ func TestAddressRemoval(t *testing.T) {
|
|||
t.Fatal("RemoveAddress failed:", err)
|
||||
}
|
||||
testFailingRecv(t, fakeNet, localAddrByte, ep, buf)
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
|
||||
// Check that removing the same address fails.
|
||||
err := s.RemoveAddress(1, localAddr)
|
||||
|
@ -1118,8 +1114,8 @@ func TestAddressRemovalWithRouteHeld(t *testing.T) {
|
|||
t.Fatal("RemoveAddress failed:", err)
|
||||
}
|
||||
testFailingRecv(t, fakeNet, localAddrByte, ep, buf)
|
||||
testFailingSend(t, r, ep, nil, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSend(t, r, nil, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
|
||||
// Check that removing the same address fails.
|
||||
{
|
||||
|
@ -1140,7 +1136,7 @@ func verifyAddress(t *testing.T, s *stack.Stack, nicID tcpip.NICID, addr tcpip.A
|
|||
// No address given, verify that there is no address assigned to the NIC.
|
||||
for _, a := range info.ProtocolAddresses {
|
||||
if a.Protocol == fakeNetNumber && a.AddressWithPrefix != (tcpip.AddressWithPrefix{}) {
|
||||
t.Errorf("verify no-address: got = %s, want = %s", a.AddressWithPrefix, (tcpip.AddressWithPrefix{}))
|
||||
t.Errorf("verify no-address: got = %s, want = %s", a.AddressWithPrefix, tcpip.AddressWithPrefix{})
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -1220,7 +1216,7 @@ func TestEndpointExpiration(t *testing.T) {
|
|||
// FIXME(b/139841518):Spoofing doesn't work if there is no primary address.
|
||||
// testSendTo(t, s, remoteAddr, ep, nil)
|
||||
} else {
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
}
|
||||
|
||||
// 2. Add Address, everything should work.
|
||||
|
@ -1248,7 +1244,7 @@ func TestEndpointExpiration(t *testing.T) {
|
|||
// FIXME(b/139841518):Spoofing doesn't work if there is no primary address.
|
||||
// testSendTo(t, s, remoteAddr, ep, nil)
|
||||
} else {
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
}
|
||||
|
||||
// 4. Add Address back, everything should work again.
|
||||
|
@ -1287,8 +1283,8 @@ func TestEndpointExpiration(t *testing.T) {
|
|||
testSend(t, r, ep, nil)
|
||||
testSendTo(t, s, remoteAddr, ep, nil)
|
||||
} else {
|
||||
testFailingSend(t, r, ep, nil, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSend(t, r, nil, &tcpip.ErrInvalidEndpointState{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
}
|
||||
|
||||
// 7. Add Address back, everything should work again.
|
||||
|
@ -1324,7 +1320,7 @@ func TestEndpointExpiration(t *testing.T) {
|
|||
// FIXME(b/139841518):Spoofing doesn't work if there is no primary address.
|
||||
// testSendTo(t, s, remoteAddr, ep, nil)
|
||||
} else {
|
||||
testFailingSendTo(t, s, remoteAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1574,7 +1570,7 @@ func TestSpoofingNoAddress(t *testing.T) {
|
|||
t.Errorf("FindRoute succeeded with route %+v when it should have failed", r)
|
||||
}
|
||||
// Sending a packet fails.
|
||||
testFailingSendTo(t, s, dstAddr, ep, nil, &tcpip.ErrNoRoute{})
|
||||
testFailingSendTo(t, s, dstAddr, nil, &tcpip.ErrNoRoute{})
|
||||
|
||||
// With address spoofing enabled, FindRoute permits any address to be used
|
||||
// as the source.
|
||||
|
@ -1615,7 +1611,7 @@ func TestOutgoingBroadcastWithEmptyRouteTable(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
protoAddr := tcpip.ProtocolAddress{Protocol: fakeNetNumber, AddressWithPrefix: tcpip.AddressWithPrefix{header.IPv4Any, 0}}
|
||||
protoAddr := tcpip.ProtocolAddress{Protocol: fakeNetNumber, AddressWithPrefix: tcpip.AddressWithPrefix{Address: header.IPv4Any}}
|
||||
if err := s.AddProtocolAddress(1, protoAddr); err != nil {
|
||||
t.Fatalf("AddProtocolAddress(1, %v) failed: %v", protoAddr, err)
|
||||
}
|
||||
|
@ -1641,12 +1637,12 @@ func TestOutgoingBroadcastWithEmptyRouteTable(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOutgoingBroadcastWithRouteTable(t *testing.T) {
|
||||
defaultAddr := tcpip.AddressWithPrefix{header.IPv4Any, 0}
|
||||
defaultAddr := tcpip.AddressWithPrefix{Address: header.IPv4Any}
|
||||
// Local subnet on NIC1: 192.168.1.58/24, gateway 192.168.1.1.
|
||||
nic1Addr := tcpip.AddressWithPrefix{"\xc0\xa8\x01\x3a", 24}
|
||||
nic1Addr := tcpip.AddressWithPrefix{Address: "\xc0\xa8\x01\x3a", PrefixLen: 24}
|
||||
nic1Gateway := testutil.MustParse4("192.168.1.1")
|
||||
// Local subnet on NIC2: 10.10.10.5/24, gateway 10.10.10.1.
|
||||
nic2Addr := tcpip.AddressWithPrefix{"\x0a\x0a\x0a\x05", 24}
|
||||
nic2Addr := tcpip.AddressWithPrefix{Address: "\x0a\x0a\x0a\x05", PrefixLen: 24}
|
||||
nic2Gateway := testutil.MustParse4("10.10.10.1")
|
||||
|
||||
// Create a new stack with two NICs.
|
||||
|
@ -1660,12 +1656,12 @@ func TestOutgoingBroadcastWithRouteTable(t *testing.T) {
|
|||
if err := s.CreateNIC(2, ep); err != nil {
|
||||
t.Fatalf("CreateNIC failed: %s", err)
|
||||
}
|
||||
nic1ProtoAddr := tcpip.ProtocolAddress{fakeNetNumber, nic1Addr}
|
||||
nic1ProtoAddr := tcpip.ProtocolAddress{Protocol: fakeNetNumber, AddressWithPrefix: nic1Addr}
|
||||
if err := s.AddProtocolAddress(1, nic1ProtoAddr); err != nil {
|
||||
t.Fatalf("AddProtocolAddress(1, %v) failed: %v", nic1ProtoAddr, err)
|
||||
}
|
||||
|
||||
nic2ProtoAddr := tcpip.ProtocolAddress{fakeNetNumber, nic2Addr}
|
||||
nic2ProtoAddr := tcpip.ProtocolAddress{Protocol: fakeNetNumber, AddressWithPrefix: nic2Addr}
|
||||
if err := s.AddProtocolAddress(2, nic2ProtoAddr); err != nil {
|
||||
t.Fatalf("AddAddress(2, %v) failed: %v", nic2ProtoAddr, err)
|
||||
}
|
||||
|
@ -1709,7 +1705,7 @@ func TestOutgoingBroadcastWithRouteTable(t *testing.T) {
|
|||
// 2. Case: Having an explicit route for broadcast will select that one.
|
||||
rt = append(
|
||||
[]tcpip.Route{
|
||||
{Destination: tcpip.AddressWithPrefix{header.IPv4Broadcast, 8 * header.IPv4AddressSize}.Subnet(), NIC: 1},
|
||||
{Destination: tcpip.AddressWithPrefix{Address: header.IPv4Broadcast, PrefixLen: 8 * header.IPv4AddressSize}.Subnet(), NIC: 1},
|
||||
},
|
||||
rt...,
|
||||
)
|
||||
|
@ -2049,7 +2045,7 @@ func TestAddAddress(t *testing.T) {
|
|||
}
|
||||
expectedAddresses = append(expectedAddresses, tcpip.ProtocolAddress{
|
||||
Protocol: fakeNetNumber,
|
||||
AddressWithPrefix: tcpip.AddressWithPrefix{address, fakeDefaultPrefixLen},
|
||||
AddressWithPrefix: tcpip.AddressWithPrefix{Address: address, PrefixLen: fakeDefaultPrefixLen},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2113,7 +2109,7 @@ func TestAddAddressWithOptions(t *testing.T) {
|
|||
}
|
||||
expectedAddresses = append(expectedAddresses, tcpip.ProtocolAddress{
|
||||
Protocol: fakeNetNumber,
|
||||
AddressWithPrefix: tcpip.AddressWithPrefix{address, fakeDefaultPrefixLen},
|
||||
AddressWithPrefix: tcpip.AddressWithPrefix{Address: address, PrefixLen: fakeDefaultPrefixLen},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -2234,7 +2230,7 @@ func TestCreateNICWithOptions(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
s := stack.New(stack.Options{})
|
||||
ep := channel.New(0, 0, tcpip.LinkAddress("\x00\x00\x00\x00\x00\x00"))
|
||||
ep := channel.New(0, 0, "\x00\x00\x00\x00\x00\x00")
|
||||
for _, call := range test.calls {
|
||||
if got, want := s.CreateNICWithOptions(call.nicID, ep, call.opts), call.err; got != want {
|
||||
t.Fatalf("CreateNICWithOptions(%v, _, %+v) = %v, want %v", call.nicID, call.opts, got, want)
|
||||
|
@ -2357,7 +2353,7 @@ func TestNICContextPreservation(t *testing.T) {
|
|||
t.Run(test.name, func(t *testing.T) {
|
||||
s := stack.New(stack.Options{})
|
||||
id := tcpip.NICID(1)
|
||||
ep := channel.New(0, 0, tcpip.LinkAddress("\x00\x00\x00\x00\x00\x00"))
|
||||
ep := channel.New(0, 0, "\x00\x00\x00\x00\x00\x00")
|
||||
if err := s.CreateNICWithOptions(id, ep, test.opts); err != nil {
|
||||
t.Fatalf("got stack.CreateNICWithOptions(%d, %+v, %+v) = %s, want nil", id, ep, test.opts, err)
|
||||
}
|
||||
|
@ -3878,8 +3874,6 @@ func TestGetMainNICAddressWhenNICDisabled(t *testing.T) {
|
|||
|
||||
// TestAddRoute tests Stack.AddRoute
|
||||
func TestAddRoute(t *testing.T) {
|
||||
const nicID = 1
|
||||
|
||||
s := stack.New(stack.Options{})
|
||||
|
||||
subnet1, err := tcpip.NewSubnet("\x00", "\x00")
|
||||
|
@ -3916,8 +3910,6 @@ func TestAddRoute(t *testing.T) {
|
|||
|
||||
// TestRemoveRoutes tests Stack.RemoveRoutes
|
||||
func TestRemoveRoutes(t *testing.T) {
|
||||
const nicID = 1
|
||||
|
||||
s := stack.New(stack.Options{})
|
||||
|
||||
addressToRemove := tcpip.Address("\x01")
|
||||
|
@ -4264,7 +4256,7 @@ func TestFindRouteWithForwarding(t *testing.T) {
|
|||
s.SetRouteTable([]tcpip.Route{{Destination: test.netCfg.remoteAddr.WithPrefix().Subnet(), NIC: nicID2}})
|
||||
|
||||
r, err := s.FindRoute(test.addrNIC, test.localAddr, test.netCfg.remoteAddr, test.netCfg.proto, false /* multicastLoop */)
|
||||
if r != nil {
|
||||
if err == nil {
|
||||
defer r.Release()
|
||||
}
|
||||
if diff := cmp.Diff(test.findRouteErr, err); diff != "" {
|
||||
|
|
|
@ -404,9 +404,6 @@ func TestForwardingWithLinkResolutionFailure(t *testing.T) {
|
|||
const (
|
||||
incomingNICID = 1
|
||||
outgoingNICID = 2
|
||||
randomSequence = 123
|
||||
randomIdent = 42
|
||||
randomTimeOffset = 0x10203040
|
||||
ttl = 2
|
||||
expectedHostUnreachableErrorCount = 1
|
||||
)
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
const (
|
||||
shortDuration = 1 * time.Nanosecond
|
||||
middleDuration = 100 * time.Millisecond
|
||||
longDuration = 1 * time.Second
|
||||
)
|
||||
|
||||
func TestJobReschedule(t *testing.T) {
|
||||
|
|
|
@ -160,7 +160,7 @@ func (e *endpoint) Close() {
|
|||
}
|
||||
|
||||
// ModerateRecvBuf implements tcpip.Endpoint.ModerateRecvBuf.
|
||||
func (e *endpoint) ModerateRecvBuf(copied int) {}
|
||||
func (*endpoint) ModerateRecvBuf(int) {}
|
||||
|
||||
// SetOwner implements tcpip.Endpoint.SetOwner.
|
||||
func (e *endpoint) SetOwner(owner tcpip.PacketOwner) {
|
||||
|
@ -349,7 +349,7 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp
|
|||
}
|
||||
|
||||
// SetSockOpt sets a socket option.
|
||||
func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) tcpip.Error {
|
||||
func (*endpoint) SetSockOpt(tcpip.SettableSocketOption) tcpip.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -390,7 +390,7 @@ func (e *endpoint) GetSockOptInt(opt tcpip.SockOptInt) (int, tcpip.Error) {
|
|||
}
|
||||
|
||||
// GetSockOpt implements tcpip.Endpoint.GetSockOpt.
|
||||
func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) tcpip.Error {
|
||||
func (*endpoint) GetSockOpt(tcpip.GettableSocketOption) tcpip.Error {
|
||||
return &tcpip.ErrUnknownProtocolOption{}
|
||||
}
|
||||
|
||||
|
@ -606,7 +606,7 @@ func (*endpoint) Accept(*tcpip.FullAddress) (tcpip.Endpoint, *waiter.Queue, tcpi
|
|||
return nil, nil, &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
func (e *endpoint) registerWithStack(nicID tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, id stack.TransportEndpointID) (stack.TransportEndpointID, tcpip.Error) {
|
||||
func (e *endpoint) registerWithStack(_ tcpip.NICID, netProtos []tcpip.NetworkProtocolNumber, id stack.TransportEndpointID) (stack.TransportEndpointID, tcpip.Error) {
|
||||
if id.LocalPort != 0 {
|
||||
// The endpoint already has a local port, just attempt to
|
||||
// register it.
|
||||
|
|
|
@ -159,7 +159,7 @@ func (ep *endpoint) Close() {
|
|||
}
|
||||
|
||||
// ModerateRecvBuf implements tcpip.Endpoint.ModerateRecvBuf.
|
||||
func (ep *endpoint) ModerateRecvBuf(copied int) {}
|
||||
func (*endpoint) ModerateRecvBuf(int) {}
|
||||
|
||||
// Read implements tcpip.Endpoint.Read.
|
||||
func (ep *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult, tcpip.Error) {
|
||||
|
@ -220,19 +220,19 @@ func (*endpoint) Disconnect() tcpip.Error {
|
|||
|
||||
// Connect implements tcpip.Endpoint.Connect. Packet sockets cannot be
|
||||
// connected, and this function always returnes *tcpip.ErrNotSupported.
|
||||
func (*endpoint) Connect(addr tcpip.FullAddress) tcpip.Error {
|
||||
func (*endpoint) Connect(tcpip.FullAddress) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
// Shutdown implements tcpip.Endpoint.Shutdown. Packet sockets cannot be used
|
||||
// with Shutdown, and this function always returns *tcpip.ErrNotSupported.
|
||||
func (*endpoint) Shutdown(flags tcpip.ShutdownFlags) tcpip.Error {
|
||||
func (*endpoint) Shutdown(tcpip.ShutdownFlags) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
// Listen implements tcpip.Endpoint.Listen. Packet sockets cannot be used with
|
||||
// Listen, and this function always returns *tcpip.ErrNotSupported.
|
||||
func (*endpoint) Listen(backlog int) tcpip.Error {
|
||||
func (*endpoint) Listen(int) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ func (ep *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) tcpip.Error {
|
|||
}
|
||||
|
||||
// SetSockOptInt implements tcpip.Endpoint.SetSockOptInt.
|
||||
func (ep *endpoint) SetSockOptInt(opt tcpip.SockOptInt, v int) tcpip.Error {
|
||||
func (*endpoint) SetSockOptInt(tcpip.SockOptInt, int) tcpip.Error {
|
||||
return &tcpip.ErrUnknownProtocolOption{}
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ func (ep *endpoint) UpdateLastError(err tcpip.Error) {
|
|||
}
|
||||
|
||||
// GetSockOpt implements tcpip.Endpoint.GetSockOpt.
|
||||
func (ep *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) tcpip.Error {
|
||||
func (*endpoint) GetSockOpt(tcpip.GettableSocketOption) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,7 @@ func (ep *endpoint) Stats() tcpip.EndpointStats {
|
|||
}
|
||||
|
||||
// SetOwner implements tcpip.Endpoint.SetOwner.
|
||||
func (ep *endpoint) SetOwner(owner tcpip.PacketOwner) {}
|
||||
func (*endpoint) SetOwner(tcpip.PacketOwner) {}
|
||||
|
||||
// SocketOptions implements tcpip.Endpoint.SocketOptions.
|
||||
func (ep *endpoint) SocketOptions() *tcpip.SocketOptions {
|
||||
|
|
|
@ -183,7 +183,7 @@ func (e *endpoint) Close() {
|
|||
}
|
||||
|
||||
// ModerateRecvBuf implements tcpip.Endpoint.ModerateRecvBuf.
|
||||
func (e *endpoint) ModerateRecvBuf(copied int) {}
|
||||
func (*endpoint) ModerateRecvBuf(int) {}
|
||||
|
||||
func (e *endpoint) SetOwner(owner tcpip.PacketOwner) {
|
||||
e.mu.Lock()
|
||||
|
@ -402,7 +402,7 @@ func (e *endpoint) Connect(addr tcpip.FullAddress) tcpip.Error {
|
|||
}
|
||||
|
||||
// Find a route to the destination.
|
||||
route, err := e.stack.FindRoute(nic, tcpip.Address(""), addr.Addr, e.NetProto, false)
|
||||
route, err := e.stack.FindRoute(nic, "", addr.Addr, e.NetProto, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func (e *endpoint) Connect(addr tcpip.FullAddress) tcpip.Error {
|
|||
}
|
||||
|
||||
// Shutdown implements tcpip.Endpoint.Shutdown. It's a noop for raw sockets.
|
||||
func (e *endpoint) Shutdown(flags tcpip.ShutdownFlags) tcpip.Error {
|
||||
func (e *endpoint) Shutdown(tcpip.ShutdownFlags) tcpip.Error {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
|
@ -439,7 +439,7 @@ func (e *endpoint) Shutdown(flags tcpip.ShutdownFlags) tcpip.Error {
|
|||
}
|
||||
|
||||
// Listen implements tcpip.Endpoint.Listen.
|
||||
func (*endpoint) Listen(backlog int) tcpip.Error {
|
||||
func (*endpoint) Listen(int) tcpip.Error {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
|
||||
|
@ -513,12 +513,12 @@ func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) tcpip.Error {
|
|||
}
|
||||
}
|
||||
|
||||
func (e *endpoint) SetSockOptInt(opt tcpip.SockOptInt, v int) tcpip.Error {
|
||||
func (*endpoint) SetSockOptInt(tcpip.SockOptInt, int) tcpip.Error {
|
||||
return &tcpip.ErrUnknownProtocolOption{}
|
||||
}
|
||||
|
||||
// GetSockOpt implements tcpip.Endpoint.GetSockOpt.
|
||||
func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) tcpip.Error {
|
||||
func (*endpoint) GetSockOpt(tcpip.GettableSocketOption) tcpip.Error {
|
||||
return &tcpip.ErrUnknownProtocolOption{}
|
||||
}
|
||||
|
||||
|
|
|
@ -421,7 +421,7 @@ func testV4Accept(t *testing.T, c *context.Context) {
|
|||
r.Reset(data)
|
||||
nep.Write(&r, tcpip.WriteOptions{})
|
||||
b = c.GetPacket()
|
||||
tcp = header.TCP(header.IPv4(b).Payload())
|
||||
tcp = header.IPv4(b).Payload()
|
||||
if string(tcp.Payload()) != data {
|
||||
t.Fatalf("Unexpected data: got %v, want %v", string(tcp.Payload()), data)
|
||||
}
|
||||
|
|
|
@ -818,7 +818,7 @@ func newEndpoint(s *stack.Stack, netProto tcpip.NetworkProtocolNumber, waiterQue
|
|||
},
|
||||
sndQueueInfo: sndQueueInfo{
|
||||
TCPSndBufState: stack.TCPSndBufState{
|
||||
SndMTU: int(math.MaxInt32),
|
||||
SndMTU: math.MaxInt32,
|
||||
},
|
||||
},
|
||||
waiterQueue: waiterQueue,
|
||||
|
@ -2748,7 +2748,7 @@ func (e *endpoint) updateSndBufferUsage(v int) {
|
|||
// We only notify when there is half the sendBufferSize available after
|
||||
// a full buffer event occurs. This ensures that we don't wake up
|
||||
// writers to queue just 1-2 segments and go back to sleep.
|
||||
notify = notify && e.sndQueueInfo.SndBufUsed < int(sendBufferSize)>>1
|
||||
notify = notify && e.sndQueueInfo.SndBufUsed < sendBufferSize>>1
|
||||
e.sndQueueInfo.sndQueueMu.Unlock()
|
||||
|
||||
if notify {
|
||||
|
|
|
@ -401,7 +401,7 @@ func (p *protocol) Option(option tcpip.GettableTransportProtocolOption) tcpip.Er
|
|||
|
||||
case *tcpip.TCPTimeWaitReuseOption:
|
||||
p.mu.RLock()
|
||||
*v = tcpip.TCPTimeWaitReuseOption(p.timeWaitReuse)
|
||||
*v = p.timeWaitReuse
|
||||
p.mu.RUnlock()
|
||||
return nil
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ func (s *sender) detectTLPRecovery(ack seqnum.Value, rcvdSeg *segment) {
|
|||
// been observed RACK uses reo_wnd of zero during loss recovery, in order to
|
||||
// retransmit quickly, or when the number of DUPACKs exceeds the classic
|
||||
// DUPACKthreshold.
|
||||
func (rc *rackControl) updateRACKReorderWindow(ackSeg *segment) {
|
||||
func (rc *rackControl) updateRACKReorderWindow() {
|
||||
dsackSeen := rc.DSACKSeen
|
||||
snd := rc.snd
|
||||
|
||||
|
|
|
@ -137,9 +137,9 @@ func (r *receiver) getSendParams() (RcvNxt seqnum.Value, rcvWnd seqnum.Size) {
|
|||
// rcvWUP RcvNxt RcvAcc new RcvAcc
|
||||
// <=====curWnd ===>
|
||||
// <========= newWnd > curWnd ========= >
|
||||
if r.RcvNxt.Add(seqnum.Size(curWnd)).LessThan(r.RcvNxt.Add(seqnum.Size(newWnd))) && toGrow {
|
||||
if r.RcvNxt.Add(curWnd).LessThan(r.RcvNxt.Add(newWnd)) && toGrow {
|
||||
// If the new window moves the right edge, then update RcvAcc.
|
||||
r.RcvAcc = r.RcvNxt.Add(seqnum.Size(newWnd))
|
||||
r.RcvAcc = r.RcvNxt.Add(newWnd)
|
||||
} else {
|
||||
if newWnd == 0 {
|
||||
// newWnd is zero but we can't advertise a zero as it would cause window
|
||||
|
|
|
@ -243,7 +243,7 @@ func (s *segment) parse(skipChecksumValidation bool) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
s.options = []byte(s.hdr[header.TCPMinimumSize:])
|
||||
s.options = s.hdr[header.TCPMinimumSize:]
|
||||
s.parsedOptions = header.ParseTCPOptions(s.options)
|
||||
if skipChecksumValidation {
|
||||
s.csumValid = true
|
||||
|
@ -262,5 +262,5 @@ func (s *segment) parse(skipChecksumValidation bool) bool {
|
|||
|
||||
// sackBlock returns a header.SACKBlock that represents this segment.
|
||||
func (s *segment) sackBlock() header.SACKBlock {
|
||||
return header.SACKBlock{s.sequenceNumber, s.sequenceNumber.Add(s.logicalLen())}
|
||||
return header.SACKBlock{Start: s.sequenceNumber, End: s.sequenceNumber.Add(s.logicalLen())}
|
||||
}
|
||||
|
|
|
@ -616,7 +616,7 @@ func (s *sender) NextSeg(nextSegHint *segment) (nextSeg, hint *segment, rescueRt
|
|||
// 'S2' that meets the following 3 criteria for determinig
|
||||
// loss, the sequence range of one segment of up to SMSS
|
||||
// octects starting with S2 MUST be returned.
|
||||
if !s.ep.scoreboard.IsSACKED(header.SACKBlock{segSeq, segSeq.Add(1)}) {
|
||||
if !s.ep.scoreboard.IsSACKED(header.SACKBlock{Start: segSeq, End: segSeq.Add(1)}) {
|
||||
// NextSeg():
|
||||
//
|
||||
// (1.a) S2 is greater than HighRxt
|
||||
|
@ -1024,7 +1024,7 @@ func (s *sender) SetPipe() {
|
|||
if segEnd.LessThan(endSeq) {
|
||||
endSeq = segEnd
|
||||
}
|
||||
sb := header.SACKBlock{startSeq, endSeq}
|
||||
sb := header.SACKBlock{Start: startSeq, End: endSeq}
|
||||
// SetPipe():
|
||||
//
|
||||
// After initializing pipe to zero, the following steps are
|
||||
|
@ -1455,7 +1455,7 @@ func (s *sender) handleRcvdSegment(rcvdSeg *segment) {
|
|||
// See: https://tools.ietf.org/html/draft-ietf-tcpm-rack-08#section-7.2
|
||||
// * Upon receiving an ACK:
|
||||
// * Step 4: Update RACK reordering window
|
||||
s.rc.updateRACKReorderWindow(rcvdSeg)
|
||||
s.rc.updateRACKReorderWindow()
|
||||
|
||||
// After the reorder window is calculated, detect any loss by checking
|
||||
// if the time elapsed after the segments are sent is greater than the
|
||||
|
|
|
@ -38,7 +38,7 @@ const (
|
|||
|
||||
func setStackRACKPermitted(t *testing.T, c *context.Context) {
|
||||
t.Helper()
|
||||
opt := tcpip.TCPRecovery(tcpip.TCPRACKLossDetection)
|
||||
opt := tcpip.TCPRACKLossDetection
|
||||
if err := c.Stack().SetTransportProtocolOption(header.TCPProtocolNumber, &opt); err != nil {
|
||||
t.Fatalf("c.s.SetTransportProtocolOption(%d, &%v(%v)): %s", header.TCPProtocolNumber, opt, opt, err)
|
||||
}
|
||||
|
|
|
@ -4259,7 +4259,7 @@ func TestReceivedInvalidSegmentCountIncrement(t *testing.T) {
|
|||
SrcPort: context.TestPort,
|
||||
DstPort: c.Port,
|
||||
Flags: header.TCPFlagAck,
|
||||
SeqNum: seqnum.Value(iss),
|
||||
SeqNum: iss,
|
||||
AckNum: c.IRS.Add(1),
|
||||
RcvWnd: 30000,
|
||||
})
|
||||
|
@ -5335,7 +5335,7 @@ func TestKeepalive(t *testing.T) {
|
|||
checker.IPv4(t, b,
|
||||
checker.TCP(
|
||||
checker.DstPort(context.TestPort),
|
||||
checker.TCPSeqNum(uint32(next-1)),
|
||||
checker.TCPSeqNum(next-1),
|
||||
checker.TCPAckNum(uint32(iss)),
|
||||
checker.TCPFlags(header.TCPFlagAck),
|
||||
),
|
||||
|
@ -5360,12 +5360,7 @@ func TestKeepalive(t *testing.T) {
|
|||
})
|
||||
|
||||
checker.IPv4(t, c.GetPacket(),
|
||||
checker.TCP(
|
||||
checker.DstPort(context.TestPort),
|
||||
checker.TCPSeqNum(uint32(next)),
|
||||
checker.TCPAckNum(uint32(0)),
|
||||
checker.TCPFlags(header.TCPFlagRst),
|
||||
),
|
||||
checker.TCP(checker.DstPort(context.TestPort), checker.TCPSeqNum(next), checker.TCPAckNum(uint32(0)), checker.TCPFlags(header.TCPFlagRst)),
|
||||
)
|
||||
|
||||
if got := c.Stack().Stats().TCP.EstablishedTimedout.Value(); got != 1 {
|
||||
|
@ -5507,7 +5502,7 @@ func TestListenBacklogFull(t *testing.T) {
|
|||
// Now execute send one more SYN. The stack should not respond as the backlog
|
||||
// is full at this point.
|
||||
c.SendPacket(nil, &context.Headers{
|
||||
SrcPort: context.TestPort + uint16(lastPortOffset),
|
||||
SrcPort: context.TestPort + lastPortOffset,
|
||||
DstPort: context.StackPort,
|
||||
Flags: header.TCPFlagSyn,
|
||||
SeqNum: seqnum.Value(context.TestInitialSequenceNumber),
|
||||
|
@ -5884,7 +5879,7 @@ func TestListenSynRcvdQueueFull(t *testing.T) {
|
|||
r.Reset(data)
|
||||
newEP.Write(&r, tcpip.WriteOptions{})
|
||||
pkt := c.GetPacket()
|
||||
tcp = header.TCP(header.IPv4(pkt).Payload())
|
||||
tcp = header.IPv4(pkt).Payload()
|
||||
if string(tcp.Payload()) != data {
|
||||
t.Fatalf("unexpected data: got %s, want %s", string(tcp.Payload()), data)
|
||||
}
|
||||
|
@ -6118,7 +6113,7 @@ func TestSynRcvdBadSeqNumber(t *testing.T) {
|
|||
}
|
||||
|
||||
pkt := c.GetPacket()
|
||||
tcpHdr = header.TCP(header.IPv4(pkt).Payload())
|
||||
tcpHdr = header.IPv4(pkt).Payload()
|
||||
if string(tcpHdr.Payload()) != data {
|
||||
t.Fatalf("unexpected data: got %s, want %s", string(tcpHdr.Payload()), data)
|
||||
}
|
||||
|
@ -6375,7 +6370,7 @@ func TestReceiveBufferAutoTuningApplicationLimited(t *testing.T) {
|
|||
|
||||
// Allocate a large enough payload for the test.
|
||||
payloadSize := receiveBufferSize * 2
|
||||
b := make([]byte, int(payloadSize))
|
||||
b := make([]byte, payloadSize)
|
||||
|
||||
worker := (c.EP).(interface {
|
||||
StopWork()
|
||||
|
@ -6429,7 +6424,7 @@ func TestReceiveBufferAutoTuningApplicationLimited(t *testing.T) {
|
|||
// ack, 1 for the non-zero window
|
||||
p := c.GetPacket()
|
||||
checker.IPv4(t, p, checker.TCP(
|
||||
checker.TCPAckNum(uint32(wantAckNum)),
|
||||
checker.TCPAckNum(wantAckNum),
|
||||
func(t *testing.T, h header.Transport) {
|
||||
tcp, ok := h.(header.TCP)
|
||||
if !ok {
|
||||
|
@ -6484,14 +6479,14 @@ func TestReceiveBufferAutoTuning(t *testing.T) {
|
|||
c.WindowScale = uint8(tcp.FindWndScale(maxReceiveBufferSize))
|
||||
|
||||
rawEP := c.CreateConnectedWithOptions(header.TCPSynOptions{TS: true, WS: 4})
|
||||
tsVal := uint32(rawEP.TSVal)
|
||||
tsVal := rawEP.TSVal
|
||||
rawEP.NextSeqNum--
|
||||
rawEP.SendPacketWithTS(nil, tsVal)
|
||||
rawEP.NextSeqNum++
|
||||
pkt := rawEP.VerifyAndReturnACKWithTS(tsVal)
|
||||
curRcvWnd := int(header.TCP(header.IPv4(pkt).Payload()).WindowSize()) << c.WindowScale
|
||||
scaleRcvWnd := func(rcvWnd int) uint16 {
|
||||
return uint16(rcvWnd >> uint16(c.WindowScale))
|
||||
return uint16(rcvWnd >> c.WindowScale)
|
||||
}
|
||||
// Allocate a large array to send to the endpoint.
|
||||
b := make([]byte, receiveBufferSize*48)
|
||||
|
@ -6619,19 +6614,16 @@ func TestDelayEnabled(t *testing.T) {
|
|||
defer c.Cleanup()
|
||||
checkDelayOption(t, c, false, false) // Delay is disabled by default.
|
||||
|
||||
for _, v := range []struct {
|
||||
delayEnabled tcpip.TCPDelayEnabled
|
||||
wantDelayOption bool
|
||||
}{
|
||||
{delayEnabled: false, wantDelayOption: false},
|
||||
{delayEnabled: true, wantDelayOption: true},
|
||||
} {
|
||||
c := context.New(t, defaultMTU)
|
||||
defer c.Cleanup()
|
||||
if err := c.Stack().SetTransportProtocolOption(tcp.ProtocolNumber, &v.delayEnabled); err != nil {
|
||||
t.Fatalf("SetTransportProtocolOption(%d, &%T(%t)): %s", tcp.ProtocolNumber, v.delayEnabled, v.delayEnabled, err)
|
||||
}
|
||||
checkDelayOption(t, c, v.delayEnabled, v.wantDelayOption)
|
||||
for _, delayEnabled := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("delayEnabled=%t", delayEnabled), func(t *testing.T) {
|
||||
c := context.New(t, defaultMTU)
|
||||
defer c.Cleanup()
|
||||
opt := tcpip.TCPDelayEnabled(delayEnabled)
|
||||
if err := c.Stack().SetTransportProtocolOption(tcp.ProtocolNumber, &opt); err != nil {
|
||||
t.Fatalf("SetTransportProtocolOption(%d, &%T(%t)): %s", tcp.ProtocolNumber, opt, delayEnabled, err)
|
||||
}
|
||||
checkDelayOption(t, c, opt, delayEnabled)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7042,7 +7034,7 @@ func TestTCPTimeWaitNewSyn(t *testing.T) {
|
|||
|
||||
// Receive the SYN-ACK reply.
|
||||
b = c.GetPacket()
|
||||
tcpHdr = header.TCP(header.IPv4(b).Payload())
|
||||
tcpHdr = header.IPv4(b).Payload()
|
||||
c.IRS = seqnum.Value(tcpHdr.SequenceNumber())
|
||||
|
||||
ackHeaders = &context.Headers{
|
||||
|
@ -7467,7 +7459,7 @@ func TestTCPUserTimeout(t *testing.T) {
|
|||
checker.IPv4(t, c.GetPacket(),
|
||||
checker.TCP(
|
||||
checker.DstPort(context.TestPort),
|
||||
checker.TCPSeqNum(uint32(next)),
|
||||
checker.TCPSeqNum(next),
|
||||
checker.TCPAckNum(uint32(0)),
|
||||
checker.TCPFlags(header.TCPFlagRst),
|
||||
),
|
||||
|
@ -7545,7 +7537,7 @@ func TestKeepaliveWithUserTimeout(t *testing.T) {
|
|||
DstPort: c.Port,
|
||||
Flags: header.TCPFlagAck,
|
||||
SeqNum: iss,
|
||||
AckNum: seqnum.Value(c.IRS + 1),
|
||||
AckNum: c.IRS + 1,
|
||||
RcvWnd: 30000,
|
||||
})
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ func (e *endpoint) Close() {
|
|||
}
|
||||
|
||||
// ModerateRecvBuf implements tcpip.Endpoint.ModerateRecvBuf.
|
||||
func (e *endpoint) ModerateRecvBuf(copied int) {}
|
||||
func (*endpoint) ModerateRecvBuf(int) {}
|
||||
|
||||
// Read implements tcpip.Endpoint.Read.
|
||||
func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult, tcpip.Error) {
|
||||
|
@ -802,8 +802,8 @@ func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) tcpip.Error {
|
|||
case *tcpip.MulticastInterfaceOption:
|
||||
e.mu.Lock()
|
||||
*o = tcpip.MulticastInterfaceOption{
|
||||
e.multicastNICID,
|
||||
e.multicastAddr,
|
||||
NIC: e.multicastNICID,
|
||||
InterfaceAddr: e.multicastAddr,
|
||||
}
|
||||
e.mu.Unlock()
|
||||
|
||||
|
@ -1302,12 +1302,12 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketB
|
|||
senderAddress: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.RemoteAddress,
|
||||
Port: header.UDP(hdr).SourcePort(),
|
||||
Port: hdr.SourcePort(),
|
||||
},
|
||||
destinationAddress: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.LocalAddress,
|
||||
Port: header.UDP(hdr).DestinationPort(),
|
||||
Port: hdr.DestinationPort(),
|
||||
},
|
||||
data: pkt.Data().ExtractVV(),
|
||||
}
|
||||
|
|
|
@ -1462,7 +1462,7 @@ func TestReadRecvOriginalDstAddr(t *testing.T) {
|
|||
name: "IPv4 unicast",
|
||||
proto: header.IPv4ProtocolNumber,
|
||||
flow: unicastV4,
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{1, stackAddr, stackPort},
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{NIC: 1, Addr: stackAddr, Port: stackPort},
|
||||
},
|
||||
{
|
||||
name: "IPv4 multicast",
|
||||
|
@ -1474,7 +1474,7 @@ func TestReadRecvOriginalDstAddr(t *testing.T) {
|
|||
// behaviour. We still include the test so that once the bug is
|
||||
// resolved, this test will start to fail and the individual tasked
|
||||
// with fixing this bug knows to also fix this test :).
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{1, multicastAddr, stackPort},
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{NIC: 1, Addr: multicastAddr, Port: stackPort},
|
||||
},
|
||||
{
|
||||
name: "IPv4 broadcast",
|
||||
|
@ -1486,13 +1486,13 @@ func TestReadRecvOriginalDstAddr(t *testing.T) {
|
|||
// behaviour. We still include the test so that once the bug is
|
||||
// resolved, this test will start to fail and the individual tasked
|
||||
// with fixing this bug knows to also fix this test :).
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{1, broadcastAddr, stackPort},
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{NIC: 1, Addr: broadcastAddr, Port: stackPort},
|
||||
},
|
||||
{
|
||||
name: "IPv6 unicast",
|
||||
proto: header.IPv6ProtocolNumber,
|
||||
flow: unicastV6,
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{1, stackV6Addr, stackPort},
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{NIC: 1, Addr: stackV6Addr, Port: stackPort},
|
||||
},
|
||||
{
|
||||
name: "IPv6 multicast",
|
||||
|
@ -1504,7 +1504,7 @@ func TestReadRecvOriginalDstAddr(t *testing.T) {
|
|||
// behaviour. We still include the test so that once the bug is
|
||||
// resolved, this test will start to fail and the individual tasked
|
||||
// with fixing this bug knows to also fix this test :).
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{1, multicastV6Addr, stackPort},
|
||||
expectedOriginalDstAddr: tcpip.FullAddress{NIC: 1, Addr: multicastV6Addr, Port: stackPort},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -2124,25 +2124,27 @@ func TestShortHeader(t *testing.T) {
|
|||
// global and endpoint stats are incremented.
|
||||
func TestBadChecksumErrors(t *testing.T) {
|
||||
for _, flow := range []testFlow{unicastV4, unicastV6} {
|
||||
c := newDualTestContext(t, defaultMTU)
|
||||
defer c.cleanup()
|
||||
t.Run(flow.String(), func(t *testing.T) {
|
||||
c := newDualTestContext(t, defaultMTU)
|
||||
defer c.cleanup()
|
||||
|
||||
c.createEndpoint(flow.sockProto())
|
||||
// Bind to wildcard.
|
||||
if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil {
|
||||
c.t.Fatalf("Bind failed: %s", err)
|
||||
}
|
||||
c.createEndpoint(flow.sockProto())
|
||||
// Bind to wildcard.
|
||||
if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil {
|
||||
c.t.Fatalf("Bind failed: %s", err)
|
||||
}
|
||||
|
||||
payload := newPayload()
|
||||
c.injectPacket(flow, payload, true /* badChecksum */)
|
||||
payload := newPayload()
|
||||
c.injectPacket(flow, payload, true /* badChecksum */)
|
||||
|
||||
const want = 1
|
||||
if got := c.s.Stats().UDP.ChecksumErrors.Value(); got != want {
|
||||
t.Errorf("got stats.UDP.ChecksumErrors.Value() = %d, want = %d", got, want)
|
||||
}
|
||||
if got := c.ep.Stats().(*tcpip.TransportEndpointStats).ReceiveErrors.ChecksumErrors.Value(); got != want {
|
||||
t.Errorf("got EP Stats.ReceiveErrors.ChecksumErrors stats = %d, want = %d", got, want)
|
||||
}
|
||||
const want = 1
|
||||
if got := c.s.Stats().UDP.ChecksumErrors.Value(); got != want {
|
||||
t.Errorf("got stats.UDP.ChecksumErrors.Value() = %d, want = %d", got, want)
|
||||
}
|
||||
if got := c.ep.Stats().(*tcpip.TransportEndpointStats).ReceiveErrors.ChecksumErrors.Value(); got != want {
|
||||
t.Errorf("got EP Stats.ReceiveErrors.ChecksumErrors stats = %d, want = %d", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue