-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for com.docker.network.container_iface_prefix driver label #1667
Conversation
osl/interface_linux.go
Outdated
@@ -241,8 +241,9 @@ 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++ | |||
var dstPrefix = i.dstName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is internal, please rename to ContainerIfacePrefix so that we can reduce this change's footprint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
drivers/bridge/bridge.go
Outdated
@@ -1217,7 +1220,11 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, | |||
} | |||
|
|||
iNames := jinfo.InterfaceName() | |||
err = iNames.SetNames(endpoint.srcName, containerVethPrefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
osl/namespace_linux.go
Outdated
gwv6 net.IP | ||
staticRoutes []*types.StaticRoute | ||
neighbors []*neigh | ||
nextIfIndexes map[string]int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
All comments addressed now. |
osl/interface_linux.go
Outdated
@@ -241,8 +241,9 @@ 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++ | |||
dstNamePrefix := i.dstName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -15,4 +15,7 @@ const ( | |||
|
|||
// DefaultBridge label | |||
DefaultBridge = "com.docker.network.bridge.default_bridge" | |||
|
|||
// ContainerIfacePrefix label | |||
ContainerIfacePrefix = "com.docker.network.bridge.container_iface_prefix" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct - basically just moved the original method towards using a map to track all prefixes independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.