mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Automated rollback of changelist 288990597
PiperOrigin-RevId: 289169518
This commit is contained in:
committed by
gVisor bot
parent
bcedf6a8e4
commit
d27208463e
+3
-20
@@ -53,6 +53,7 @@ go_test(
|
||||
name = "stack_x_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"ndp_test.go",
|
||||
"stack_test.go",
|
||||
"transport_demuxer_test.go",
|
||||
"transport_test.go",
|
||||
@@ -62,12 +63,14 @@ go_test(
|
||||
"//pkg/rand",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/checker",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/iptables",
|
||||
"//pkg/tcpip/link/channel",
|
||||
"//pkg/tcpip/link/loopback",
|
||||
"//pkg/tcpip/network/ipv4",
|
||||
"//pkg/tcpip/network/ipv6",
|
||||
"//pkg/tcpip/transport/icmp",
|
||||
"//pkg/tcpip/transport/udp",
|
||||
"//pkg/waiter",
|
||||
"@com_github_google_go-cmp//cmp:go_default_library",
|
||||
@@ -85,23 +88,3 @@ go_test(
|
||||
"//pkg/tcpip",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "ndp_test",
|
||||
size = "small",
|
||||
srcs = ["ndp_test.go"],
|
||||
deps = [
|
||||
":stack",
|
||||
"//pkg/rand",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/checker",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/link/channel",
|
||||
"//pkg/tcpip/network/ipv6",
|
||||
"//pkg/tcpip/transport/icmp",
|
||||
"//pkg/tcpip/transport/udp",
|
||||
"//pkg/waiter",
|
||||
"@com_github_google_go-cmp//cmp:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ndp_test
|
||||
package stack_test
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
@@ -301,8 +301,6 @@ func (n *ndpDispatcher) OnDHCPv6Configuration(nicID tcpip.NICID, configuration s
|
||||
// Included in the subtests is a test to make sure that an invalid
|
||||
// RetransmitTimer (<1ms) values get fixed to the default RetransmitTimer of 1s.
|
||||
func TestDADResolve(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
dupAddrDetectTransmits uint8
|
||||
@@ -435,8 +433,6 @@ func TestDADResolve(t *testing.T) {
|
||||
// a node doing DAD for the same address), or if another node is detected to own
|
||||
// the address already (receive an NA message for the tentative address).
|
||||
func TestDADFail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
makeBuf func(tgt tcpip.Address) buffer.Prependable
|
||||
@@ -580,8 +576,6 @@ func TestDADFail(t *testing.T) {
|
||||
// TestDADStop tests to make sure that the DAD process stops when an address is
|
||||
// removed.
|
||||
func TestDADStop(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ndpDisp := ndpDispatcher{
|
||||
dadC: make(chan ndpDADEvent),
|
||||
}
|
||||
@@ -654,71 +648,6 @@ func TestDADStop(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNICAutoGenAddrDoesDAD tests that the successful auto-generation of IPv6
|
||||
// link-local addresses will only be assigned after the DAD process resolves.
|
||||
func TestNICAutoGenAddrDoesDAD(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ndpDisp := ndpDispatcher{
|
||||
dadC: make(chan ndpDADEvent),
|
||||
}
|
||||
ndpConfigs := stack.DefaultNDPConfigurations()
|
||||
opts := stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocol{ipv6.NewProtocol()},
|
||||
NDPConfigs: ndpConfigs,
|
||||
AutoGenIPv6LinkLocal: true,
|
||||
NDPDisp: &ndpDisp,
|
||||
}
|
||||
|
||||
e := channel.New(0, 1280, linkAddr1)
|
||||
s := stack.New(opts)
|
||||
if err := s.CreateNIC(1, e); err != nil {
|
||||
t.Fatalf("CreateNIC(_) = %s", err)
|
||||
}
|
||||
|
||||
// Address should not be considered bound to the
|
||||
// NIC yet (DAD ongoing).
|
||||
addr, err := s.GetMainNICAddress(1, header.IPv6ProtocolNumber)
|
||||
if err != nil {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = (_, %v), want = (_, nil)", err)
|
||||
}
|
||||
if want := (tcpip.AddressWithPrefix{}); addr != want {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = (%s, nil), want = (%s, nil)", addr, want)
|
||||
}
|
||||
|
||||
linkLocalAddr := header.LinkLocalAddr(linkAddr1)
|
||||
|
||||
// Wait for DAD to resolve.
|
||||
select {
|
||||
case <-time.After(time.Duration(ndpConfigs.DupAddrDetectTransmits)*ndpConfigs.RetransmitTimer + time.Second):
|
||||
// We should get a resolution event after 1s (default time to
|
||||
// resolve as per default NDP configurations). Waiting for that
|
||||
// resolution time + an extra 1s without a resolution event
|
||||
// means something is wrong.
|
||||
t.Fatal("timed out waiting for DAD resolution")
|
||||
case e := <-ndpDisp.dadC:
|
||||
if e.err != nil {
|
||||
t.Fatal("got DAD error: ", e.err)
|
||||
}
|
||||
if e.nicID != 1 {
|
||||
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
|
||||
}
|
||||
if e.addr != linkLocalAddr {
|
||||
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, linkLocalAddr)
|
||||
}
|
||||
if !e.resolved {
|
||||
t.Fatal("got DAD event w/ resolved = false, want = true")
|
||||
}
|
||||
}
|
||||
addr, err = s.GetMainNICAddress(1, header.IPv6ProtocolNumber)
|
||||
if err != nil {
|
||||
t.Fatalf("stack.GetMainNICAddress(_, _) err = %s", err)
|
||||
}
|
||||
if want := (tcpip.AddressWithPrefix{Address: linkLocalAddr, PrefixLen: header.IPv6LinkLocalPrefix.PrefixLen}); addr != want {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = %s, want = %s", addr, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetNDPConfigurationFailsForBadNICID tests to make sure we get an error if
|
||||
// we attempt to update NDP configurations using an invalid NICID.
|
||||
func TestSetNDPConfigurationFailsForBadNICID(t *testing.T) {
|
||||
@@ -736,8 +665,6 @@ func TestSetNDPConfigurationFailsForBadNICID(t *testing.T) {
|
||||
// configurations without affecting the default NDP configurations or other
|
||||
// interfaces' configurations.
|
||||
func TestSetNDPConfigurations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
dupAddrDetectTransmits uint8
|
||||
@@ -992,8 +919,6 @@ func raBufWithPI(ip tcpip.Address, rl uint16, prefix tcpip.AddressWithPrefix, on
|
||||
// TestNoRouterDiscovery tests that router discovery will not be performed if
|
||||
// configured not to.
|
||||
func TestNoRouterDiscovery(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Being configured to discover routers means handle and
|
||||
// discover are set to true and forwarding is set to false.
|
||||
// This tests all possible combinations of the configurations,
|
||||
@@ -1006,6 +931,8 @@ func TestNoRouterDiscovery(t *testing.T) {
|
||||
forwarding := i&4 == 0
|
||||
|
||||
t.Run(fmt.Sprintf("HandleRAs(%t), DiscoverDefaultRouters(%t), Forwarding(%t)", handle, discover, forwarding), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ndpDisp := ndpDispatcher{
|
||||
routerC: make(chan ndpRouterEvent, 1),
|
||||
}
|
||||
@@ -1240,8 +1167,6 @@ func TestRouterDiscoveryMaxRouters(t *testing.T) {
|
||||
// TestNoPrefixDiscovery tests that prefix discovery will not be performed if
|
||||
// configured not to.
|
||||
func TestNoPrefixDiscovery(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prefix := tcpip.AddressWithPrefix{
|
||||
Address: tcpip.Address("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00"),
|
||||
PrefixLen: 64,
|
||||
@@ -1259,6 +1184,8 @@ func TestNoPrefixDiscovery(t *testing.T) {
|
||||
forwarding := i&4 == 0
|
||||
|
||||
t.Run(fmt.Sprintf("HandleRAs(%t), DiscoverOnLinkPrefixes(%t), Forwarding(%t)", handle, discover, forwarding), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ndpDisp := ndpDispatcher{
|
||||
prefixC: make(chan ndpPrefixEvent, 1),
|
||||
}
|
||||
@@ -1615,8 +1542,6 @@ func contains(list []tcpip.ProtocolAddress, item tcpip.AddressWithPrefix) bool {
|
||||
|
||||
// TestNoAutoGenAddr tests that SLAAC is not performed when configured not to.
|
||||
func TestNoAutoGenAddr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prefix, _, _ := prefixSubnetAddr(0, "")
|
||||
|
||||
// Being configured to auto-generate addresses means handle and
|
||||
@@ -1631,6 +1556,8 @@ func TestNoAutoGenAddr(t *testing.T) {
|
||||
forwarding := i&4 == 0
|
||||
|
||||
t.Run(fmt.Sprintf("HandleRAs(%t), AutoGenAddr(%t), Forwarding(%t)", handle, autogen, forwarding), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ndpDisp := ndpDispatcher{
|
||||
autoGenAddrC: make(chan ndpAutoGenAddrEvent, 1),
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
@@ -49,8 +50,6 @@ const (
|
||||
// where another value is explicitly used. It is chosen to match the MTU
|
||||
// of loopback interfaces on linux systems.
|
||||
defaultMTU = 65536
|
||||
|
||||
linkAddr = "\x02\x02\x03\x04\x05\x06"
|
||||
)
|
||||
|
||||
// fakeNetworkEndpoint is a network-layer protocol endpoint. It counts sent and
|
||||
@@ -1910,7 +1909,7 @@ func TestNICAutoGenAddr(t *testing.T) {
|
||||
{
|
||||
"Disabled",
|
||||
false,
|
||||
linkAddr,
|
||||
linkAddr1,
|
||||
stack.OpaqueInterfaceIdentifierOptions{
|
||||
NICNameFromID: func(nicID tcpip.NICID, _ string) string {
|
||||
return fmt.Sprintf("nic%d", nicID)
|
||||
@@ -1921,7 +1920,7 @@ func TestNICAutoGenAddr(t *testing.T) {
|
||||
{
|
||||
"Enabled",
|
||||
true,
|
||||
linkAddr,
|
||||
linkAddr1,
|
||||
stack.OpaqueInterfaceIdentifierOptions{},
|
||||
true,
|
||||
},
|
||||
@@ -2069,14 +2068,14 @@ func TestNICAutoGenAddrWithOpaque(t *testing.T) {
|
||||
name: "Disabled",
|
||||
nicName: "nic1",
|
||||
autoGen: false,
|
||||
linkAddr: linkAddr,
|
||||
linkAddr: linkAddr1,
|
||||
secretKey: secretKey[:],
|
||||
},
|
||||
{
|
||||
name: "Enabled",
|
||||
nicName: "nic1",
|
||||
autoGen: true,
|
||||
linkAddr: linkAddr,
|
||||
linkAddr: linkAddr1,
|
||||
secretKey: secretKey[:],
|
||||
},
|
||||
// These are all cases where we would not have generated a
|
||||
@@ -2214,6 +2213,69 @@ func TestNoLinkLocalAutoGenForLoopbackNIC(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNICAutoGenAddrDoesDAD tests that the successful auto-generation of IPv6
|
||||
// link-local addresses will only be assigned after the DAD process resolves.
|
||||
func TestNICAutoGenAddrDoesDAD(t *testing.T) {
|
||||
ndpDisp := ndpDispatcher{
|
||||
dadC: make(chan ndpDADEvent),
|
||||
}
|
||||
ndpConfigs := stack.DefaultNDPConfigurations()
|
||||
opts := stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocol{ipv6.NewProtocol()},
|
||||
NDPConfigs: ndpConfigs,
|
||||
AutoGenIPv6LinkLocal: true,
|
||||
NDPDisp: &ndpDisp,
|
||||
}
|
||||
|
||||
e := channel.New(10, 1280, linkAddr1)
|
||||
s := stack.New(opts)
|
||||
if err := s.CreateNIC(1, e); err != nil {
|
||||
t.Fatalf("CreateNIC(_) = %s", err)
|
||||
}
|
||||
|
||||
// Address should not be considered bound to the
|
||||
// NIC yet (DAD ongoing).
|
||||
addr, err := s.GetMainNICAddress(1, header.IPv6ProtocolNumber)
|
||||
if err != nil {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = (_, %v), want = (_, nil)", err)
|
||||
}
|
||||
if want := (tcpip.AddressWithPrefix{}); addr != want {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = (%s, nil), want = (%s, nil)", addr, want)
|
||||
}
|
||||
|
||||
linkLocalAddr := header.LinkLocalAddr(linkAddr1)
|
||||
|
||||
// Wait for DAD to resolve.
|
||||
select {
|
||||
case <-time.After(time.Duration(ndpConfigs.DupAddrDetectTransmits)*ndpConfigs.RetransmitTimer + time.Second):
|
||||
// We should get a resolution event after 1s (default time to
|
||||
// resolve as per default NDP configurations). Waiting for that
|
||||
// resolution time + an extra 1s without a resolution event
|
||||
// means something is wrong.
|
||||
t.Fatal("timed out waiting for DAD resolution")
|
||||
case e := <-ndpDisp.dadC:
|
||||
if e.err != nil {
|
||||
t.Fatal("got DAD error: ", e.err)
|
||||
}
|
||||
if e.nicID != 1 {
|
||||
t.Fatalf("got DAD event w/ nicID = %d, want = 1", e.nicID)
|
||||
}
|
||||
if e.addr != linkLocalAddr {
|
||||
t.Fatalf("got DAD event w/ addr = %s, want = %s", addr, linkLocalAddr)
|
||||
}
|
||||
if !e.resolved {
|
||||
t.Fatal("got DAD event w/ resolved = false, want = true")
|
||||
}
|
||||
}
|
||||
addr, err = s.GetMainNICAddress(1, header.IPv6ProtocolNumber)
|
||||
if err != nil {
|
||||
t.Fatalf("stack.GetMainNICAddress(_, _) err = %s", err)
|
||||
}
|
||||
if want := (tcpip.AddressWithPrefix{Address: linkLocalAddr, PrefixLen: header.IPv6LinkLocalPrefix.PrefixLen}); addr != want {
|
||||
t.Fatalf("got stack.GetMainNICAddress(_, _) = %s, want = %s", addr, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewPEB tests that a new PrimaryEndpointBehavior value (peb) is respected
|
||||
// when an address's kind gets "promoted" to permanent from permanentExpired.
|
||||
func TestNewPEBOnPromotionToPermanent(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user