Support for com.docker.network.container_iface_prefix driver label#1667
Support for com.docker.network.container_iface_prefix driver label#1667mavenugo merged 1 commit intomoby:masterfrom wnagele:master
Conversation
osl/interface_linux.go
Outdated
| } else { | ||
| i.dstName = fmt.Sprintf("%s%d", i.dstName, n.nextIfIndex) | ||
| n.nextIfIndex++ | ||
| var dstPrefix = i.dstName |
There was a problem hiding this comment.
You do not need to declare the dstPrefix variable. Just reuse the dstPrefix from the function input parameters.
There was a problem hiding this comment.
Fixed - using dstNamePrefix now. dstPrefix is for the name inside the host - thus using it here is wrong and confusing.
drivers/bridge/bridge.go
Outdated
| Mtu int | ||
| DefaultBindingIP net.IP | ||
| DefaultBridge bool | ||
| ContainerInterfacePrefix string |
There was a problem hiding this comment.
As this is internal, please rename to ContainerIfacePrefix so that we can reduce this change's footprint.
| } | ||
|
|
||
| iNames := jinfo.InterfaceName() | ||
| err = iNames.SetNames(endpoint.srcName, containerVethPrefix) |
There was a problem hiding this comment.
For readability, I would rename the constant to defaultContainerVethPrefix and here have
containerVethPrefix := defaultContainerVethPrefix
if network.config.ContainerIfacePrefix != "" {
containerVethPrefix = network.config.ContainerInterfacePrefix
}
err = iNames.SetNames(endpoint.srcName, containerVethPrefix)
osl/namespace_linux.go
Outdated
| gwv6 net.IP | ||
| staticRoutes []*types.StaticRoute | ||
| neighbors []*neigh | ||
| nextIfIndexes map[string]int |
There was a problem hiding this comment.
Again to reduce the fix footprint, I would leave the variable name as is, even if it now is a map. At the end it is one index per interface.
|
All comments addressed now. |
osl/interface_linux.go
Outdated
| } else { | ||
| i.dstName = fmt.Sprintf("%s%d", i.dstName, n.nextIfIndex) | ||
| n.nextIfIndex++ | ||
| dstNamePrefix := i.dstName |
There was a problem hiding this comment.
please remove this line
and modify next one to
i.dstName = fmt.Sprintf("%s%d", dstPrefix, n.nextIfIndex[dstPrefix])
There was a problem hiding this comment.
dstPrefix is the prefix of the interface in the host system - I am trying to modify the one in the container. If I override this it will change the logic in the code following. I do not think this is correct - please clarify.
The only reason I assign dstName to a new dstNamePrefix is that the original data of dstName is to be modified and dstNamePrefix is needed for the increment.
There was a problem hiding this comment.
i.srcName is the original name of the veth pipe end which is going to be moved into the container's netns.
i.dstName is the new name the above interface will be renamed to, once it is moved.
dstPrefix is the prefix of the interface in the host system
No, dstPrefix the network driver chosen prefix for the new interface name once we move it into the netns.
func (n *networkNamespace) AddInterface(srcName, dstPrefix string, options ...IfaceOption) error {
At this point of the code i.dstName == dstPrefix (L229 i := &nwIface{srcName: srcName, dstName: dstPrefix, ns: n})
IMO, original code was already confusing and should have been written as
i.dstName = fmt.Sprintf("%s%d", dstPrefix, n.nextIfIndex)
There was a problem hiding this comment.
You are of course correct. Should have read up a few lines in the code. Have made this modification now as well.
drivers/bridge/labels.go
Outdated
| DefaultBridge = "com.docker.network.bridge.default_bridge" | ||
|
|
||
| // ContainerIfacePrefix label | ||
| ContainerIfacePrefix = "com.docker.network.bridge.container_iface_prefix" |
There was a problem hiding this comment.
Looking at this again, it makes me think people may want the same option while using different network drivers in future.
In a way it s not specific to a network driver (like the MTU option we have now).
So I was thinking it may be better we make this option driver agnostic from the beginning, and define it in https://github.com/docker/libnetwork/blob/master/netlabel/labels.go
as
ContainerIfacePrefix = "com.docker.network.container_iface_prefix
Also wondering whether we should keep a 1-to-1 match to the networking objects (here would be sandbox_iface_PREFIX) or stick to container given it is a user input option. It is probably better to leave it as container_iface_prefix, more clear.
There was a problem hiding this comment.
That is now done as well.
|
Thanks @wnagele , I only have one last comment about making the new option driver agnostic. |
Signed-off-by: Wolfgang Nagele <[email protected]>
|
Thanks @wnagele LGTM |
|
Merge? :) |
|
@wnagele |
| } else { | ||
| i.dstName = fmt.Sprintf("%s%d", i.dstName, n.nextIfIndex) | ||
| n.nextIfIndex++ | ||
| i.dstName = fmt.Sprintf("%s%d", dstPrefix, n.nextIfIndex[dstPrefix]) |
There was a problem hiding this comment.
j/c. are you relying on the fact that the map access on new prefix will return 0 ?
There was a problem hiding this comment.
Correct - basically just moved the original method towards using a map to track all prefixes independently.
mavenugo
left a comment
There was a problem hiding this comment.
LGTM
It would have been better to have changed other drivers as well. But we can deal with it in individual PRs.
|
Updated the title to include |
This adds support for a custom interface prefix. Can be used to address issues such as moby/moby#20067. If the label is not used the default behaviour prevails.