mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Disable auto-generation of IPv6 link-local addresses for loopback NICs
Test: Test that an IPv6 link-local address is not auto-generated for loopback NICs, even when it is enabled for non-loopback NICS. PiperOrigin-RevId: 288519591
This commit is contained in:
committed by
gVisor bot
parent
ed60bc326b
commit
2031cc4701
@@ -174,7 +174,8 @@ func (n *NIC) enable() *tcpip.Error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !n.stack.autoGenIPv6LinkLocal {
|
||||
// Do not auto-generate an IPv6 link-local address for loopback devices.
|
||||
if !n.stack.autoGenIPv6LinkLocal || n.loopback {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -444,8 +444,8 @@ type Stack struct {
|
||||
ndpConfigs NDPConfigurations
|
||||
|
||||
// autoGenIPv6LinkLocal determines whether or not the stack will attempt
|
||||
// to auto-generate an IPv6 link-local address for newly enabled NICs.
|
||||
// See the AutoGenIPv6LinkLocal field of Options for more details.
|
||||
// to auto-generate an IPv6 link-local address for newly enabled non-loopback
|
||||
// NICs. See the AutoGenIPv6LinkLocal field of Options for more details.
|
||||
autoGenIPv6LinkLocal bool
|
||||
|
||||
// ndpDisp is the NDP event dispatcher that is used to send the netstack
|
||||
@@ -496,13 +496,15 @@ type Options struct {
|
||||
// before assigning an address to a NIC.
|
||||
NDPConfigs NDPConfigurations
|
||||
|
||||
// AutoGenIPv6LinkLocal determins whether or not the stack will attempt
|
||||
// to auto-generate an IPv6 link-local address for newly enabled NICs.
|
||||
// AutoGenIPv6LinkLocal determines whether or not the stack will attempt to
|
||||
// auto-generate an IPv6 link-local address for newly enabled non-loopback
|
||||
// NICs.
|
||||
//
|
||||
// Note, setting this to true does not mean that a link-local address
|
||||
// will be assigned right away, or at all. If Duplicate Address
|
||||
// Detection is enabled, an address will only be assigned if it
|
||||
// successfully resolves. If it fails, no further attempt will be made
|
||||
// to auto-generate an IPv6 link-local address.
|
||||
// will be assigned right away, or at all. If Duplicate Address Detection
|
||||
// is enabled, an address will only be assigned if it successfully resolves.
|
||||
// If it fails, no further attempt will be made to auto-generate an IPv6
|
||||
// link-local address.
|
||||
//
|
||||
// The generated link-local address will follow RFC 4291 Appendix A
|
||||
// guidelines.
|
||||
|
||||
@@ -2121,6 +2121,55 @@ func TestNICAutoGenAddrWithOpaque(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNoLinkLocalAutoGenForLoopbackNIC tests that IPv6 link-local addresses are
|
||||
// not auto-generated for loopback NICs.
|
||||
func TestNoLinkLocalAutoGenForLoopbackNIC(t *testing.T) {
|
||||
const nicID = 1
|
||||
const nicName = "nicName"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
opaqueIIDOpts stack.OpaqueInterfaceIdentifierOptions
|
||||
}{
|
||||
{
|
||||
name: "IID From MAC",
|
||||
opaqueIIDOpts: stack.OpaqueInterfaceIdentifierOptions{},
|
||||
},
|
||||
{
|
||||
name: "Opaque IID",
|
||||
opaqueIIDOpts: stack.OpaqueInterfaceIdentifierOptions{
|
||||
NICNameFromID: func(_ tcpip.NICID, nicName string) string {
|
||||
return nicName
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
opts := stack.Options{
|
||||
NetworkProtocols: []stack.NetworkProtocol{ipv6.NewProtocol()},
|
||||
AutoGenIPv6LinkLocal: true,
|
||||
OpaqueIIDOpts: test.opaqueIIDOpts,
|
||||
}
|
||||
|
||||
e := channel.New(0, 1280, linkAddr1)
|
||||
s := stack.New(opts)
|
||||
if err := s.CreateNamedLoopbackNIC(nicID, nicName, e); err != nil {
|
||||
t.Fatalf("CreateNamedLoopbackNIC(%d, %q, _) = %s", nicID, nicName, err)
|
||||
}
|
||||
|
||||
addr, err := s.GetMainNICAddress(nicID, header.IPv6ProtocolNumber)
|
||||
if err != nil {
|
||||
t.Fatalf("stack.GetMainNICAddress(%d, _) err = %s", nicID, err)
|
||||
}
|
||||
if want := (tcpip.AddressWithPrefix{}); addr != want {
|
||||
t.Errorf("got stack.GetMainNICAddress(%d, _) = %s, want = %s", nicID, addr, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user