1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #40384 from arkodg/bump-libnetwork-latest

Bump Libnetwork to latest refpoint
This commit is contained in:
Brian Goff 2020-01-16 21:03:26 -08:00 committed by GitHub
commit e5c8eca2ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 135 additions and 34 deletions

View file

@ -3,7 +3,7 @@
# LIBNETWORK_COMMIT is used to build the docker-userland-proxy binary. When # LIBNETWORK_COMMIT is used to build the docker-userland-proxy binary. When
# updating the binary version, consider updating github.com/docker/libnetwork # updating the binary version, consider updating github.com/docker/libnetwork
# in vendor.conf accordingly # in vendor.conf accordingly
: "${LIBNETWORK_COMMIT:=90afbb01e1d8acacb505a092744ea42b9f167377}" : "${LIBNETWORK_COMMIT:=feeff4f0a3fd2a2bb19cf67c826082c66ffaaed9}"
install_proxy() { install_proxy() {
case "$1" in case "$1" in

View file

@ -38,7 +38,7 @@ github.com/gofrs/flock 392e7fae8f1b0bdbd67dad7237d2
# libnetwork # libnetwork
# When updating, also update LIBNETWORK_COMMIT in hack/dockerfile/install/proxy.installer accordingly # When updating, also update LIBNETWORK_COMMIT in hack/dockerfile/install/proxy.installer accordingly
github.com/docker/libnetwork 90afbb01e1d8acacb505a092744ea42b9f167377 github.com/docker/libnetwork feeff4f0a3fd2a2bb19cf67c826082c66ffaaed9
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80 github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec

View file

@ -184,6 +184,16 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
err := driver.DiscoverNew(discoverapi.EncryptionKeysUpdate, drvEnc) err := driver.DiscoverNew(discoverapi.EncryptionKeysUpdate, drvEnc)
if err != nil { if err != nil {
logrus.Warnf("Failed to update datapath keys in driver %s: %v", name, err) logrus.Warnf("Failed to update datapath keys in driver %s: %v", name, err)
// Attempt to reconfigure keys in case of a update failure
// which can arise due to a mismatch of keys
// if worker nodes get temporarily disconnected
logrus.Warnf("Reconfiguring datapath keys for %s", name)
drvCfgEnc := discoverapi.DriverEncryptionConfig{}
drvCfgEnc.Keys, drvCfgEnc.Tags = c.getKeys(subsysIPSec)
err = driver.DiscoverNew(discoverapi.EncryptionKeysConfig, drvCfgEnc)
if err != nil {
logrus.Warnf("Failed to reset datapath keys in driver %s: %v", name, err)
}
} }
return false return false
}) })

View file

@ -1,6 +1,7 @@
package config package config
import ( import (
"fmt"
"strings" "strings"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
@ -13,6 +14,7 @@ import (
"github.com/docker/libnetwork/ipamutils" "github.com/docker/libnetwork/ipamutils"
"github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/osl" "github.com/docker/libnetwork/osl"
"github.com/docker/libnetwork/portallocator"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -238,6 +240,23 @@ func OptionExperimental(exp bool) Option {
} }
} }
// OptionDynamicPortRange function returns an option setter for service port allocation range
func OptionDynamicPortRange(in string) Option {
return func(c *Config) {
start, end := 0, 0
if len(in) > 0 {
n, err := fmt.Sscanf(in, "%d-%d", &start, &end)
if n != 2 || err != nil {
logrus.Errorf("Failed to parse range string with err %v", err)
return
}
}
if err := portallocator.Get().SetPortRange(start, end); err != nil {
logrus.Errorf("Failed to set port range with err %v", err)
}
}
}
// OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU // OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU
func OptionNetworkControlPlaneMTU(exp int) Option { func OptionNetworkControlPlaneMTU(exp int) Option {
return func(c *Config) { return func(c *Config) {

View file

@ -35,18 +35,17 @@ func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
setMac = kv.Kernel > 3 || (kv.Kernel == 3 && kv.Major >= 3) setMac = kv.Kernel > 3 || (kv.Kernel == 3 && kv.Major >= 3)
} }
if setMac {
hwAddr := netutils.GenerateRandomMAC()
i.Link.Attrs().HardwareAddr = hwAddr
logrus.Debugf("Setting bridge mac address to %s", hwAddr)
}
if err = i.nlh.LinkAdd(i.Link); err != nil { if err = i.nlh.LinkAdd(i.Link); err != nil {
logrus.Debugf("Failed to create bridge %s via netlink. Trying ioctl", config.BridgeName) logrus.Debugf("Failed to create bridge %s via netlink. Trying ioctl", config.BridgeName)
return ioctlCreateBridge(config.BridgeName, setMac) return ioctlCreateBridge(config.BridgeName, setMac)
} }
if setMac {
hwAddr := netutils.GenerateRandomMAC()
if err = i.nlh.LinkSetHardwareAddr(i.Link, hwAddr); err != nil {
return fmt.Errorf("failed to set bridge mac-address %s : %s", hwAddr, err.Error())
}
logrus.Debugf("Setting bridge mac address to %s", hwAddr)
}
return err return err
} }

View file

@ -378,7 +378,7 @@ func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{})
} }
} }
if err := d.updateKeys(newKey, priKey, delKey); err != nil { if err := d.updateKeys(newKey, priKey, delKey); err != nil {
logrus.Warn(err) return err
} }
default: default:
} }

View file

@ -498,11 +498,14 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) (err error) {
} }
if doUpdateHostsFile(n, sb) { if doUpdateHostsFile(n, sb) {
address := "" var addresses []string
if ip := ep.getFirstInterfaceAddress(); ip != nil { if ip := ep.getFirstInterfaceIPv4Address(); ip != nil {
address = ip.String() addresses = append(addresses, ip.String())
} }
if err = sb.updateHostsFile(address); err != nil { if ip := ep.getFirstInterfaceIPv6Address(); ip != nil {
addresses = append(addresses, ip.String())
}
if err = sb.updateHostsFile(addresses); err != nil {
return err return err
} }
} }
@ -912,7 +915,7 @@ func (ep *endpoint) getSandbox() (*sandbox, bool) {
return ps, ok return ps, ok
} }
func (ep *endpoint) getFirstInterfaceAddress() net.IP { func (ep *endpoint) getFirstInterfaceIPv4Address() net.IP {
ep.Lock() ep.Lock()
defer ep.Unlock() defer ep.Unlock()
@ -923,6 +926,17 @@ func (ep *endpoint) getFirstInterfaceAddress() net.IP {
return nil return nil
} }
func (ep *endpoint) getFirstInterfaceIPv6Address() net.IP {
ep.Lock()
defer ep.Unlock()
if ep.iface.addrv6 != nil {
return ep.iface.addrv6.IP
}
return nil
}
// EndpointOptionGeneric function returns an option setter for a Generic option defined // EndpointOptionGeneric function returns an option setter for a Generic option defined
// in a Dictionary of Key-Value pair // in a Dictionary of Key-Value pair
func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption { func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {

View file

@ -3,17 +3,36 @@ package portallocator
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/sirupsen/logrus"
"net" "net"
"sync" "sync"
) )
const ( var (
// DefaultPortRangeStart indicates the first port in port range // defaultPortRangeStart indicates the first port in port range
DefaultPortRangeStart = 49153 defaultPortRangeStart = 49153
// DefaultPortRangeEnd indicates the last port in port range // defaultPortRangeEnd indicates the last port in port range
DefaultPortRangeEnd = 65535 // consistent with default /proc/sys/net/ipv4/ip_local_port_range
// upper bound on linux
defaultPortRangeEnd = 60999
) )
func sanitizePortRange(start int, end int) (newStart, newEnd int, err error) {
if start > defaultPortRangeEnd || end < defaultPortRangeStart || start > end {
return 0, 0, fmt.Errorf("Request out allowed range [%v, %v]",
defaultPortRangeStart, defaultPortRangeEnd)
}
err = nil
newStart, newEnd = start, end
if start < defaultPortRangeStart {
newStart = defaultPortRangeStart
}
if end > defaultPortRangeEnd {
newEnd = defaultPortRangeEnd
}
return
}
type ipMapping map[string]protoMap type ipMapping map[string]protoMap
var ( var (
@ -92,11 +111,19 @@ func Get() *PortAllocator {
return instance return instance
} }
func newInstance() *PortAllocator { func getDefaultPortRange() (int, int) {
start, end, err := getDynamicPortRange() start, end, err := getDynamicPortRange()
if err != nil { if err == nil {
start, end = DefaultPortRangeStart, DefaultPortRangeEnd start, end, err = sanitizePortRange(start, end)
} }
if err != nil {
start, end = defaultPortRangeStart, defaultPortRangeEnd
}
return start, end
}
func newInstance() *PortAllocator {
start, end := getDefaultPortRange()
return &PortAllocator{ return &PortAllocator{
ipMap: ipMapping{}, ipMap: ipMapping{},
Begin: start, Begin: start,
@ -170,6 +197,35 @@ func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) error {
return nil return nil
} }
// SetPortRange sets dynamic port allocation range.
// if both portBegin and portEnd are 0, the port range reverts to default
// value. Otherwise they are sanitized against the default values to
// ensure their validity.
func (p *PortAllocator) SetPortRange(portBegin, portEnd int) error {
// if begin and end is zero, revert to default values
var begin, end int
var err error
if portBegin == 0 && portEnd == 0 {
begin, end = getDefaultPortRange()
} else {
begin, end, err = sanitizePortRange(portBegin, portEnd)
if err != nil {
return err
}
}
logrus.Debugf("Setting up port allocator to range %v-%v, current %v-%v",
begin, end, p.Begin, p.End)
p.mutex.Lock()
defer p.mutex.Unlock()
if p.Begin == begin && p.End == end {
return nil
}
p.ipMap = ipMapping{}
p.Begin, p.End = begin, end
return nil
}
func (p *PortAllocator) newPortMap() *portMap { func (p *PortAllocator) newPortMap() *portMap {
defaultKey := getRangeKey(p.Begin, p.End) defaultKey := getRangeKey(p.Begin, p.End)
pm := &portMap{ pm := &portMap{

View file

@ -8,7 +8,7 @@ import (
func getDynamicPortRange() (start int, end int, err error) { func getDynamicPortRange() (start int, end int, err error) {
portRangeKernelSysctl := []string{"net.inet.ip.portrange.hifirst", "net.ip.portrange.hilast"} portRangeKernelSysctl := []string{"net.inet.ip.portrange.hifirst", "net.ip.portrange.hilast"}
portRangeFallback := fmt.Sprintf("using fallback port range %d-%d", DefaultPortRangeStart, DefaultPortRangeEnd) portRangeFallback := fmt.Sprintf("using fallback port range %d-%d", defaultPortRangeStart, defaultPortRangeEnd)
portRangeLowCmd := exec.Command("/sbin/sysctl", portRangeKernelSysctl[0]) portRangeLowCmd := exec.Command("/sbin/sysctl", portRangeKernelSysctl[0])
var portRangeLowOut bytes.Buffer var portRangeLowOut bytes.Buffer
portRangeLowCmd.Stdout = &portRangeLowOut portRangeLowCmd.Stdout = &portRangeLowOut

View file

@ -8,7 +8,7 @@ import (
func getDynamicPortRange() (start int, end int, err error) { func getDynamicPortRange() (start int, end int, err error) {
const portRangeKernelParam = "/proc/sys/net/ipv4/ip_local_port_range" const portRangeKernelParam = "/proc/sys/net/ipv4/ip_local_port_range"
portRangeFallback := fmt.Sprintf("using fallback port range %d-%d", DefaultPortRangeStart, DefaultPortRangeEnd) portRangeFallback := fmt.Sprintf("using fallback port range %d-%d", defaultPortRangeStart, defaultPortRangeEnd)
file, err := os.Open(portRangeKernelParam) file, err := os.Open(portRangeKernelParam)
if err != nil { if err != nil {
return 0, 0, fmt.Errorf("port allocator - %s due to error: %v", portRangeFallback, err) return 0, 0, fmt.Errorf("port allocator - %s due to error: %v", portRangeFallback, err)

View file

@ -1,10 +1,10 @@
package portallocator package portallocator
const ( func init() {
StartPortRange = 60000 defaultPortRangeStart = 60000
EndPortRange = 65000 defaultPortRangeEnd = 65000
) }
func getDynamicPortRange() (start int, end int, err error) { func getDynamicPortRange() (start int, end int, err error) {
return StartPortRange, EndPortRange, nil return defaultPortRangeStart, defaultPortRangeEnd, nil
} }

View file

@ -98,8 +98,8 @@ func (sb *sandbox) buildHostsFile() error {
return etchosts.Build(sb.config.hostsPath, "", sb.config.hostName, sb.config.domainName, extraContent) return etchosts.Build(sb.config.hostsPath, "", sb.config.hostName, sb.config.domainName, extraContent)
} }
func (sb *sandbox) updateHostsFile(ifaceIP string) error { func (sb *sandbox) updateHostsFile(ifaceIPs []string) error {
if ifaceIP == "" { if ifaceIPs == nil || len(ifaceIPs) == 0 {
return nil return nil
} }
@ -120,7 +120,10 @@ func (sb *sandbox) updateHostsFile(ifaceIP string) error {
mhost = fmt.Sprintf("%s %s", fqdn, parts[0]) mhost = fmt.Sprintf("%s %s", fqdn, parts[0])
} }
extraContent := []etchosts.Record{{Hosts: mhost, IP: ifaceIP}} var extraContent []etchosts.Record
for _, ip := range ifaceIPs {
extraContent = append(extraContent, etchosts.Record{Hosts: mhost, IP: ip})
}
sb.addHostsEntries(extraContent) sb.addHostsEntries(extraContent)
return nil return nil

View file

@ -18,7 +18,7 @@ func (sb *sandbox) setupResolutionFiles() error {
func (sb *sandbox) restorePath() { func (sb *sandbox) restorePath() {
} }
func (sb *sandbox) updateHostsFile(ifaceIP string) error { func (sb *sandbox) updateHostsFile(ifaceIP []string) error {
return nil return nil
} }