mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Vendor libnetwork @51d88e9ae63f
- Fixes #26440 Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
parent
ba07661f0d
commit
7d8048de06
7 changed files with 58 additions and 14 deletions
|
@ -71,7 +71,7 @@ clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
|
||||||
clone git github.com/imdario/mergo 0.2.1
|
clone git github.com/imdario/mergo 0.2.1
|
||||||
|
|
||||||
#get libnetwork packages
|
#get libnetwork packages
|
||||||
clone git github.com/docker/libnetwork 00e7660daeb4b6108a333319d289bf7dc8b9932e
|
clone git github.com/docker/libnetwork 51d88e9ae63f4164f3678fe74feda89d6990befa
|
||||||
clone git github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
|
clone git github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
|
||||||
clone git github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
clone git github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
||||||
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
||||||
|
|
|
@ -70,8 +70,19 @@ type networkConfiguration struct {
|
||||||
dbIndex uint64
|
dbIndex uint64
|
||||||
dbExists bool
|
dbExists bool
|
||||||
Internal bool
|
Internal bool
|
||||||
|
|
||||||
|
BridgeIfaceCreator ifaceCreator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ifaceCreator represents how the bridge interface was created
|
||||||
|
type ifaceCreator int8
|
||||||
|
|
||||||
|
const (
|
||||||
|
ifaceCreatorUnknown ifaceCreator = iota
|
||||||
|
ifaceCreatedByLibnetwork
|
||||||
|
ifaceCreatedByUser
|
||||||
|
)
|
||||||
|
|
||||||
// endpointConfiguration represents the user specified configuration for the sandbox endpoint
|
// endpointConfiguration represents the user specified configuration for the sandbox endpoint
|
||||||
type endpointConfiguration struct {
|
type endpointConfiguration struct {
|
||||||
MacAddress net.HardwareAddr
|
MacAddress net.HardwareAddr
|
||||||
|
@ -512,6 +523,17 @@ func parseNetworkOptions(id string, option options.Generic) (*networkConfigurati
|
||||||
config.BridgeName = "br-" + id[:12]
|
config.BridgeName = "br-" + id[:12]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exists, err := bridgeInterfaceExists(config.BridgeName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
config.BridgeIfaceCreator = ifaceCreatedByLibnetwork
|
||||||
|
} else {
|
||||||
|
config.BridgeIfaceCreator = ifaceCreatedByUser
|
||||||
|
}
|
||||||
|
|
||||||
config.ID = id
|
config.ID = id
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
@ -778,11 +800,17 @@ func (d *driver) DeleteNetwork(nid string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only delete the bridge when it's not the default bridge. This is keep the backward compatible behavior.
|
switch config.BridgeIfaceCreator {
|
||||||
if !config.DefaultBridge {
|
case ifaceCreatedByLibnetwork, ifaceCreatorUnknown:
|
||||||
if err := d.nlh.LinkDel(n.bridge.Link); err != nil {
|
// We only delete the bridge if it was created by the bridge driver and
|
||||||
logrus.Warnf("Failed to remove bridge interface %s on network %s delete: %v", config.BridgeName, nid, err)
|
// it is not the default one (to keep the backward compatible behavior.)
|
||||||
|
if !config.DefaultBridge {
|
||||||
|
if err := d.nlh.LinkDel(n.bridge.Link); err != nil {
|
||||||
|
logrus.Warnf("Failed to remove bridge interface %s on network %s delete: %v", config.BridgeName, nid, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
case ifaceCreatedByUser:
|
||||||
|
// Don't delete the bridge interface if it was not created by libnetwork.
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean all relevant iptables rules
|
// clean all relevant iptables rules
|
||||||
|
|
|
@ -143,6 +143,7 @@ func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) {
|
||||||
nMap["DefaultBindingIP"] = ncfg.DefaultBindingIP.String()
|
nMap["DefaultBindingIP"] = ncfg.DefaultBindingIP.String()
|
||||||
nMap["DefaultGatewayIPv4"] = ncfg.DefaultGatewayIPv4.String()
|
nMap["DefaultGatewayIPv4"] = ncfg.DefaultGatewayIPv4.String()
|
||||||
nMap["DefaultGatewayIPv6"] = ncfg.DefaultGatewayIPv6.String()
|
nMap["DefaultGatewayIPv6"] = ncfg.DefaultGatewayIPv6.String()
|
||||||
|
nMap["BridgeIfaceCreator"] = ncfg.BridgeIfaceCreator
|
||||||
|
|
||||||
if ncfg.AddressIPv4 != nil {
|
if ncfg.AddressIPv4 != nil {
|
||||||
nMap["AddressIPv4"] = ncfg.AddressIPv4.String()
|
nMap["AddressIPv4"] = ncfg.AddressIPv4.String()
|
||||||
|
@ -191,6 +192,10 @@ func (ncfg *networkConfiguration) UnmarshalJSON(b []byte) error {
|
||||||
ncfg.Internal = v.(bool)
|
ncfg.Internal = v.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := nMap["BridgeIfaceCreator"]; ok {
|
||||||
|
ncfg.BridgeIfaceCreator = ifaceCreator(v.(float64))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !arm,!ppc64,!ppc64le,!s390x
|
// +build !arm,!ppc64,!ppc64le
|
||||||
|
|
||||||
package bridge
|
package bridge
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
// +build s390x
|
|
||||||
|
|
||||||
package bridge
|
|
||||||
|
|
||||||
func ifrDataByte(b byte) uint8 {
|
|
||||||
return uint8(b)
|
|
||||||
}
|
|
|
@ -2,8 +2,10 @@ package bridge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/libnetwork/ns"
|
||||||
"github.com/docker/libnetwork/types"
|
"github.com/docker/libnetwork/types"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
@ -51,3 +53,19 @@ func findIPv6Address(addr netlink.Addr, addresses []netlink.Addr) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bridgeInterfaceExists(name string) (bool, error) {
|
||||||
|
nlh := ns.NlHandle()
|
||||||
|
link, err := nlh.LinkByName(name)
|
||||||
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "Link not found") {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("failed to check bridge interface existence: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if link.Type() == "bridge" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("existing interface %s is not a bridge", name)
|
||||||
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (sb *sandbox) Key() string {
|
||||||
|
|
||||||
func (sb *sandbox) Labels() map[string]interface{} {
|
func (sb *sandbox) Labels() map[string]interface{} {
|
||||||
sb.Lock()
|
sb.Lock()
|
||||||
sb.Unlock()
|
defer sb.Unlock()
|
||||||
opts := make(map[string]interface{}, len(sb.config.generic))
|
opts := make(map[string]interface{}, len(sb.config.generic))
|
||||||
for k, v := range sb.config.generic {
|
for k, v := range sb.config.generic {
|
||||||
opts[k] = v
|
opts[k] = v
|
||||||
|
|
Loading…
Add table
Reference in a new issue