Support for com.docker.network.bridge.container_interface_prefix label
Signed-off-by: Wolfgang Nagele <mail@wnagele.com>
This commit is contained in:
parent
bdc9dcea1a
commit
40bae11aa7
|
@ -28,11 +28,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
networkType = "bridge"
|
networkType = "bridge"
|
||||||
vethPrefix = "veth"
|
vethPrefix = "veth"
|
||||||
vethLen = 7
|
vethLen = 7
|
||||||
containerVethPrefix = "eth"
|
defaultContainerVethPrefix = "eth"
|
||||||
maxAllocatePortAttempts = 10
|
maxAllocatePortAttempts = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -55,14 +55,15 @@ type configuration struct {
|
||||||
|
|
||||||
// networkConfiguration for network specific configuration
|
// networkConfiguration for network specific configuration
|
||||||
type networkConfiguration struct {
|
type networkConfiguration struct {
|
||||||
ID string
|
ID string
|
||||||
BridgeName string
|
BridgeName string
|
||||||
EnableIPv6 bool
|
EnableIPv6 bool
|
||||||
EnableIPMasquerade bool
|
EnableIPMasquerade bool
|
||||||
EnableICC bool
|
EnableICC bool
|
||||||
Mtu int
|
Mtu int
|
||||||
DefaultBindingIP net.IP
|
DefaultBindingIP net.IP
|
||||||
DefaultBridge bool
|
DefaultBridge bool
|
||||||
|
ContainerIfacePrefix string
|
||||||
// Internal fields set after ipam data parsing
|
// Internal fields set after ipam data parsing
|
||||||
AddressIPv4 *net.IPNet
|
AddressIPv4 *net.IPNet
|
||||||
AddressIPv6 *net.IPNet
|
AddressIPv6 *net.IPNet
|
||||||
|
@ -239,6 +240,8 @@ func (c *networkConfiguration) fromLabels(labels map[string]string) error {
|
||||||
if c.DefaultBindingIP = net.ParseIP(value); c.DefaultBindingIP == nil {
|
if c.DefaultBindingIP = net.ParseIP(value); c.DefaultBindingIP == nil {
|
||||||
return parseErr(label, value, "nil ip")
|
return parseErr(label, value, "nil ip")
|
||||||
}
|
}
|
||||||
|
case netlabel.ContainerIfacePrefix:
|
||||||
|
c.ContainerIfacePrefix = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,6 +1220,10 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
iNames := jinfo.InterfaceName()
|
iNames := jinfo.InterfaceName()
|
||||||
|
containerVethPrefix := defaultContainerVethPrefix
|
||||||
|
if network.config.ContainerIfacePrefix != "" {
|
||||||
|
containerVethPrefix = network.config.ContainerIfacePrefix
|
||||||
|
}
|
||||||
err = iNames.SetNames(endpoint.srcName, containerVethPrefix)
|
err = iNames.SetNames(endpoint.srcName, containerVethPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -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["ContainerIfacePrefix"] = ncfg.ContainerIfacePrefix
|
||||||
nMap["BridgeIfaceCreator"] = ncfg.BridgeIfaceCreator
|
nMap["BridgeIfaceCreator"] = ncfg.BridgeIfaceCreator
|
||||||
|
|
||||||
if ncfg.AddressIPv4 != nil {
|
if ncfg.AddressIPv4 != nil {
|
||||||
|
@ -178,6 +179,10 @@ func (ncfg *networkConfiguration) UnmarshalJSON(b []byte) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := nMap["ContainerIfacePrefix"]; ok {
|
||||||
|
ncfg.ContainerIfacePrefix = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
ncfg.DefaultBridge = nMap["DefaultBridge"].(bool)
|
ncfg.DefaultBridge = nMap["DefaultBridge"].(bool)
|
||||||
ncfg.DefaultBindingIP = net.ParseIP(nMap["DefaultBindingIP"].(string))
|
ncfg.DefaultBindingIP = net.ParseIP(nMap["DefaultBindingIP"].(string))
|
||||||
ncfg.DefaultGatewayIPv4 = net.ParseIP(nMap["DefaultGatewayIPv4"].(string))
|
ncfg.DefaultGatewayIPv4 = net.ParseIP(nMap["DefaultGatewayIPv4"].(string))
|
||||||
|
|
|
@ -50,6 +50,9 @@ const (
|
||||||
|
|
||||||
// Internal constant represents that the network is internal which disables default gateway service
|
// Internal constant represents that the network is internal which disables default gateway service
|
||||||
Internal = Prefix + ".internal"
|
Internal = Prefix + ".internal"
|
||||||
|
|
||||||
|
// ContainerIfacePrefix can be used to override the interface prefix used inside the container
|
||||||
|
ContainerIfacePrefix = Prefix + ".container_iface_prefix"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -241,8 +241,8 @@ func (n *networkNamespace) AddInterface(srcName, dstPrefix string, options ...If
|
||||||
if n.isDefault {
|
if n.isDefault {
|
||||||
i.dstName = i.srcName
|
i.dstName = i.srcName
|
||||||
} else {
|
} else {
|
||||||
i.dstName = fmt.Sprintf("%s%d", i.dstName, n.nextIfIndex)
|
i.dstName = fmt.Sprintf("%s%d", dstPrefix, n.nextIfIndex[dstPrefix])
|
||||||
n.nextIfIndex++
|
n.nextIfIndex[dstPrefix]++
|
||||||
}
|
}
|
||||||
|
|
||||||
path := n.path
|
path := n.path
|
||||||
|
|
|
@ -48,7 +48,7 @@ type networkNamespace struct {
|
||||||
gwv6 net.IP
|
gwv6 net.IP
|
||||||
staticRoutes []*types.StaticRoute
|
staticRoutes []*types.StaticRoute
|
||||||
neighbors []*neigh
|
neighbors []*neigh
|
||||||
nextIfIndex int
|
nextIfIndex map[string]int
|
||||||
isDefault bool
|
isDefault bool
|
||||||
nlHandle *netlink.Handle
|
nlHandle *netlink.Handle
|
||||||
loV6Enabled bool
|
loV6Enabled bool
|
||||||
|
@ -203,7 +203,7 @@ func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error) {
|
||||||
once.Do(createBasePath)
|
once.Do(createBasePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
n := &networkNamespace{path: key, isDefault: !osCreate}
|
n := &networkNamespace{path: key, isDefault: !osCreate, nextIfIndex: make(map[string]int)}
|
||||||
|
|
||||||
sboxNs, err := netns.GetFromPath(n.path)
|
sboxNs, err := netns.GetFromPath(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -256,7 +256,7 @@ func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error) {
|
||||||
if err := mountNetworkNamespace(basePath, key); err != nil {
|
if err := mountNetworkNamespace(basePath, key); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
n := &networkNamespace{path: key}
|
n := &networkNamespace{path: key, nextIfIndex: make(map[string]int)}
|
||||||
|
|
||||||
sboxNs, err := netns.GetFromPath(n.path)
|
sboxNs, err := netns.GetFromPath(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -495,8 +495,8 @@ func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*ty
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
n.Lock()
|
n.Lock()
|
||||||
if index > n.nextIfIndex {
|
if index > n.nextIfIndex[dstPrefix] {
|
||||||
n.nextIfIndex = index
|
n.nextIfIndex[dstPrefix] = index
|
||||||
}
|
}
|
||||||
n.iFaces = append(n.iFaces, i)
|
n.iFaces = append(n.iFaces, i)
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue