Merge release-20190806.1-292-g51538c9 (automated)

This commit is contained in:
gVisor bot 2019-10-18 23:17:23 +00:00
commit 9fe1139c23
1 changed files with 11 additions and 24 deletions

View File

@ -19,7 +19,6 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"gvisor.dev/gvisor/pkg/ilist"
"gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/pkg/tcpip/header"
@ -37,7 +36,7 @@ type NIC struct {
mu sync.RWMutex mu sync.RWMutex
spoofing bool spoofing bool
promiscuous bool promiscuous bool
primary map[tcpip.NetworkProtocolNumber]*ilist.List primary map[tcpip.NetworkProtocolNumber][]*referencedNetworkEndpoint
endpoints map[NetworkEndpointID]*referencedNetworkEndpoint endpoints map[NetworkEndpointID]*referencedNetworkEndpoint
addressRanges []tcpip.Subnet addressRanges []tcpip.Subnet
mcastJoins map[NetworkEndpointID]int32 mcastJoins map[NetworkEndpointID]int32
@ -85,7 +84,7 @@ func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, loopback
name: name, name: name,
linkEP: ep, linkEP: ep,
loopback: loopback, loopback: loopback,
primary: make(map[tcpip.NetworkProtocolNumber]*ilist.List), primary: make(map[tcpip.NetworkProtocolNumber][]*referencedNetworkEndpoint),
endpoints: make(map[NetworkEndpointID]*referencedNetworkEndpoint), endpoints: make(map[NetworkEndpointID]*referencedNetworkEndpoint),
mcastJoins: make(map[NetworkEndpointID]int32), mcastJoins: make(map[NetworkEndpointID]int32),
stats: NICStats{ stats: NICStats{
@ -166,13 +165,7 @@ func (n *NIC) primaryEndpoint(protocol tcpip.NetworkProtocolNumber) *referencedN
n.mu.RLock() n.mu.RLock()
defer n.mu.RUnlock() defer n.mu.RUnlock()
list := n.primary[protocol] for _, r := range n.primary[protocol] {
if list == nil {
return nil
}
for e := list.Front(); e != nil; e = e.Next() {
r := e.(*referencedNetworkEndpoint)
if r.isValidForOutgoing() && r.tryIncRef() { if r.isValidForOutgoing() && r.tryIncRef() {
return r return r
} }
@ -357,17 +350,11 @@ func (n *NIC) addAddressLocked(protocolAddress tcpip.ProtocolAddress, peb Primar
n.endpoints[id] = ref n.endpoints[id] = ref
l, ok := n.primary[protocolAddress.Protocol]
if !ok {
l = &ilist.List{}
n.primary[protocolAddress.Protocol] = l
}
switch peb { switch peb {
case CanBePrimaryEndpoint: case CanBePrimaryEndpoint:
l.PushBack(ref) n.primary[protocolAddress.Protocol] = append(n.primary[protocolAddress.Protocol], ref)
case FirstPrimaryEndpoint: case FirstPrimaryEndpoint:
l.PushFront(ref) n.primary[protocolAddress.Protocol] = append([]*referencedNetworkEndpoint{ref}, n.primary[protocolAddress.Protocol]...)
} }
// If we are adding a tentative IPv6 address, start DAD. // If we are adding a tentative IPv6 address, start DAD.
@ -425,8 +412,7 @@ func (n *NIC) PrimaryAddresses() []tcpip.ProtocolAddress {
var addrs []tcpip.ProtocolAddress var addrs []tcpip.ProtocolAddress
for proto, list := range n.primary { for proto, list := range n.primary {
for e := list.Front(); e != nil; e = e.Next() { for _, ref := range list {
ref := e.(*referencedNetworkEndpoint)
// Don't include tentative, expired or tempory endpoints // Don't include tentative, expired or tempory endpoints
// to avoid confusion and prevent the caller from using // to avoid confusion and prevent the caller from using
// those. // those.
@ -508,9 +494,11 @@ func (n *NIC) removeEndpointLocked(r *referencedNetworkEndpoint) {
} }
delete(n.endpoints, id) delete(n.endpoints, id)
wasInList := r.Next() != nil || r.Prev() != nil || r == n.primary[r.protocol].Front() for i, ref := range n.primary[r.protocol] {
if wasInList { if ref == r {
n.primary[r.protocol].Remove(r) n.primary[r.protocol] = append(n.primary[r.protocol][:i], n.primary[r.protocol][i+1:]...)
break
}
} }
r.ep.Close() r.ep.Close()
@ -869,7 +857,6 @@ const (
) )
type referencedNetworkEndpoint struct { type referencedNetworkEndpoint struct {
ilist.Entry
ep NetworkEndpoint ep NetworkEndpoint
nic *NIC nic *NIC
protocol tcpip.NetworkProtocolNumber protocol tcpip.NetworkProtocolNumber