diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-03-16 17:34:27 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-16 17:34:27 +0000 |
commit | 8663fa59e76a84e284b4e726a487f4920c5b4a76 (patch) | |
tree | aca473b6adf0d1d3bb8f328a00437e453cd21254 | |
parent | 34cc37e563c44dc9c16322a8640f944597648a84 (diff) | |
parent | ebd7c1b889e5d212f4a694d3addbada241936e8e (diff) |
Merge release-20210309.0-31-gebd7c1b88 (automated)
-rw-r--r-- | pkg/tcpip/network/arp/arp.go | 8 | ||||
-rw-r--r-- | pkg/tcpip/network/ipv6/icmp.go | 5 | ||||
-rw-r--r-- | pkg/tcpip/stack/nic.go | 14 | ||||
-rw-r--r-- | pkg/tcpip/stack/registration.go | 8 | ||||
-rw-r--r-- | pkg/tcpip/stack/stack.go | 3 |
5 files changed, 22 insertions, 16 deletions
diff --git a/pkg/tcpip/network/arp/arp.go b/pkg/tcpip/network/arp/arp.go index ae0461a6d..43a4b7cac 100644 --- a/pkg/tcpip/network/arp/arp.go +++ b/pkg/tcpip/network/arp/arp.go @@ -305,8 +305,6 @@ func (*endpoint) LinkAddressProtocol() tcpip.NetworkProtocolNumber { // LinkAddressRequest implements stack.LinkAddressResolver.LinkAddressRequest. func (e *endpoint) LinkAddressRequest(targetAddr, localAddr tcpip.Address, remoteLinkAddr tcpip.LinkAddress) tcpip.Error { - nicID := e.nic.ID() - stats := e.stats.arp if len(remoteLinkAddr) == 0 { @@ -314,9 +312,9 @@ func (e *endpoint) LinkAddressRequest(targetAddr, localAddr tcpip.Address, remot } if len(localAddr) == 0 { - addr, ok := e.protocol.stack.GetMainNICAddress(nicID, header.IPv4ProtocolNumber) - if !ok { - return &tcpip.ErrUnknownNICID{} + addr, err := e.nic.PrimaryAddress(header.IPv4ProtocolNumber) + if err != nil { + return err } if len(addr.Address) == 0 { diff --git a/pkg/tcpip/network/ipv6/icmp.go b/pkg/tcpip/network/ipv6/icmp.go index 6344a3e09..8059e0690 100644 --- a/pkg/tcpip/network/ipv6/icmp.go +++ b/pkg/tcpip/network/ipv6/icmp.go @@ -899,13 +899,16 @@ func (e *endpoint) LinkAddressRequest(targetAddr, localAddr tcpip.Address, remot } if len(localAddr) == 0 { + // Find an address that we can use as our source address. addressEndpoint := e.AcquireOutgoingPrimaryAddress(remoteAddr, false /* allowExpired */) if addressEndpoint == nil { return &tcpip.ErrNetworkUnreachable{} } localAddr = addressEndpoint.AddressWithPrefix().Address - } else if e.protocol.stack.CheckLocalAddress(e.nic.ID(), ProtocolNumber, localAddr) == 0 { + addressEndpoint.DecRef() + } else if !e.checkLocalAddress(localAddr) { + // The provided local address is not assigned to us. return &tcpip.ErrBadLocalAddress{} } diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 62f7c880e..ca15c0691 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -568,23 +568,19 @@ func (n *nic) primaryAddresses() []tcpip.ProtocolAddress { return addrs } -// primaryAddress returns the primary address associated with this NIC. -// -// primaryAddress will return the first non-deprecated address if such an -// address exists. If no non-deprecated address exists, the first deprecated -// address will be returned. -func (n *nic) primaryAddress(proto tcpip.NetworkProtocolNumber) tcpip.AddressWithPrefix { +// PrimaryAddress implements NetworkInterface. +func (n *nic) PrimaryAddress(proto tcpip.NetworkProtocolNumber) (tcpip.AddressWithPrefix, tcpip.Error) { ep, ok := n.networkEndpoints[proto] if !ok { - return tcpip.AddressWithPrefix{} + return tcpip.AddressWithPrefix{}, &tcpip.ErrUnknownProtocol{} } addressableEndpoint, ok := ep.(AddressableEndpoint) if !ok { - return tcpip.AddressWithPrefix{} + return tcpip.AddressWithPrefix{}, &tcpip.ErrNotSupported{} } - return addressableEndpoint.MainAddress() + return addressableEndpoint.MainAddress(), nil } // removeAddress removes an address from n. diff --git a/pkg/tcpip/stack/registration.go b/pkg/tcpip/stack/registration.go index 85f0f471a..ff3a385e1 100644 --- a/pkg/tcpip/stack/registration.go +++ b/pkg/tcpip/stack/registration.go @@ -525,6 +525,14 @@ type NetworkInterface interface { // assigned to it. Spoofing() bool + // PrimaryAddress returns the primary address associated with the interface. + // + // PrimaryAddress will return the first non-deprecated address if such an + // address exists. If no non-deprecated addresses exist, the first deprecated + // address will be returned. If no deprecated addresses exist, the zero value + // will be returned. + PrimaryAddress(tcpip.NetworkProtocolNumber) (tcpip.AddressWithPrefix, tcpip.Error) + // CheckLocalAddress returns true if the address exists on the interface. CheckLocalAddress(tcpip.NetworkProtocolNumber, tcpip.Address) bool diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 53370c354..1fffe9274 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -1224,7 +1224,8 @@ func (s *Stack) GetMainNICAddress(id tcpip.NICID, protocol tcpip.NetworkProtocol return tcpip.AddressWithPrefix{}, false } - return nic.primaryAddress(protocol), true + addr, err := nic.PrimaryAddress(protocol) + return addr, err == nil } func (s *Stack) getAddressEP(nic *nic, localAddr, remoteAddr tcpip.Address, netProto tcpip.NetworkProtocolNumber) AssignableAddressEndpoint { |