Support for com.docker.network.bridge.container_interface_prefix label
Signed-off-by: Wolfgang Nagele <mail@wnagele.com>
This commit is contained in:
parent
1a8c8e9a61
commit
d07e1a02a4
5 changed files with 35 additions and 20 deletions
|
@ -28,11 +28,11 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
networkType = "bridge"
|
||||
vethPrefix = "veth"
|
||||
vethLen = 7
|
||||
containerVethPrefix = "eth"
|
||||
maxAllocatePortAttempts = 10
|
||||
networkType = "bridge"
|
||||
vethPrefix = "veth"
|
||||
vethLen = 7
|
||||
defaultContainerVethPrefix = "eth"
|
||||
maxAllocatePortAttempts = 10
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -55,14 +55,15 @@ type configuration struct {
|
|||
|
||||
// networkConfiguration for network specific configuration
|
||||
type networkConfiguration struct {
|
||||
ID string
|
||||
BridgeName string
|
||||
EnableIPv6 bool
|
||||
EnableIPMasquerade bool
|
||||
EnableICC bool
|
||||
Mtu int
|
||||
DefaultBindingIP net.IP
|
||||
DefaultBridge bool
|
||||
ID string
|
||||
BridgeName string
|
||||
EnableIPv6 bool
|
||||
EnableIPMasquerade bool
|
||||
EnableICC bool
|
||||
Mtu int
|
||||
DefaultBindingIP net.IP
|
||||
DefaultBridge bool
|
||||
ContainerIfacePrefix string
|
||||
// Internal fields set after ipam data parsing
|
||||
AddressIPv4 *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 {
|
||||
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()
|
||||
containerVethPrefix := defaultContainerVethPrefix
|
||||
if network.config.ContainerIfacePrefix != "" {
|
||||
containerVethPrefix = network.config.ContainerIfacePrefix
|
||||
}
|
||||
err = iNames.SetNames(endpoint.srcName, containerVethPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -143,6 +143,7 @@ func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) {
|
|||
nMap["DefaultBindingIP"] = ncfg.DefaultBindingIP.String()
|
||||
nMap["DefaultGatewayIPv4"] = ncfg.DefaultGatewayIPv4.String()
|
||||
nMap["DefaultGatewayIPv6"] = ncfg.DefaultGatewayIPv6.String()
|
||||
nMap["ContainerIfacePrefix"] = ncfg.ContainerIfacePrefix
|
||||
nMap["BridgeIfaceCreator"] = ncfg.BridgeIfaceCreator
|
||||
|
||||
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.DefaultBindingIP = net.ParseIP(nMap["DefaultBindingIP"].(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 = Prefix + ".internal"
|
||||
|
||||
// ContainerIfacePrefix can be used to override the interface prefix used inside the container
|
||||
ContainerIfacePrefix = Prefix + ".container_iface_prefix"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -241,8 +241,8 @@ func (n *networkNamespace) AddInterface(srcName, dstPrefix string, options ...If
|
|||
if n.isDefault {
|
||||
i.dstName = i.srcName
|
||||
} else {
|
||||
i.dstName = fmt.Sprintf("%s%d", i.dstName, n.nextIfIndex)
|
||||
n.nextIfIndex++
|
||||
i.dstName = fmt.Sprintf("%s%d", dstPrefix, n.nextIfIndex[dstPrefix])
|
||||
n.nextIfIndex[dstPrefix]++
|
||||
}
|
||||
|
||||
path := n.path
|
||||
|
|
|
@ -48,7 +48,7 @@ type networkNamespace struct {
|
|||
gwv6 net.IP
|
||||
staticRoutes []*types.StaticRoute
|
||||
neighbors []*neigh
|
||||
nextIfIndex int
|
||||
nextIfIndex map[string]int
|
||||
isDefault bool
|
||||
nlHandle *netlink.Handle
|
||||
loV6Enabled bool
|
||||
|
@ -203,7 +203,7 @@ func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error) {
|
|||
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)
|
||||
if err != nil {
|
||||
|
@ -256,7 +256,7 @@ func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error) {
|
|||
if err := mountNetworkNamespace(basePath, key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
n := &networkNamespace{path: key}
|
||||
n := &networkNamespace{path: key, nextIfIndex: make(map[string]int)}
|
||||
|
||||
sboxNs, err := netns.GetFromPath(n.path)
|
||||
if err != nil {
|
||||
|
@ -495,8 +495,8 @@ func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*ty
|
|||
}
|
||||
index++
|
||||
n.Lock()
|
||||
if index > n.nextIfIndex {
|
||||
n.nextIfIndex = index
|
||||
if index > n.nextIfIndex[dstPrefix] {
|
||||
n.nextIfIndex[dstPrefix] = index
|
||||
}
|
||||
n.iFaces = append(n.iFaces, i)
|
||||
n.Unlock()
|
||||
|
|
Loading…
Reference in a new issue