Skip to content
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

Merged
merged 1 commit into from
Mar 13, 2017
Merged

Support for com.docker.network.container_iface_prefix driver label #1667

merged 1 commit into from
Mar 13, 2017

Conversation

wnagele
Copy link
Contributor

@wnagele wnagele commented Feb 27, 2017

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.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Mtu int
DefaultBindingIP net.IP
DefaultBridge bool
ContainerInterfacePrefix string
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@@ -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)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

gwv6 net.IP
staticRoutes []*types.StaticRoute
neighbors []*neigh
nextIfIndexes map[string]int
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@wnagele
Copy link
Contributor Author

wnagele commented Feb 28, 2017

All comments addressed now.

@@ -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
Copy link
Contributor

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])

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

@@ -15,4 +15,7 @@ const (

// DefaultBridge label
DefaultBridge = "com.docker.network.bridge.default_bridge"

// ContainerIfacePrefix label
ContainerIfacePrefix = "com.docker.network.bridge.container_iface_prefix"
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@aboch
Copy link
Contributor

aboch commented Feb 28, 2017

Thanks @wnagele , I only have one last comment about making the new option driver agnostic.

Signed-off-by: Wolfgang Nagele <mail@wnagele.com>
@aboch
Copy link
Contributor

aboch commented Mar 1, 2017

Thanks @wnagele

LGTM

@wnagele
Copy link
Contributor Author

wnagele commented Mar 1, 2017

Merge? :)

@aboch
Copy link
Contributor

aboch commented Mar 1, 2017

@wnagele
For most of the PRs we usually require two mantainers' LGTMs before merging.

@wnagele
Copy link
Contributor Author

wnagele commented Mar 12, 2017

Anybody else able to review this for a merge? @sanimej @mavenugo

@@ -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])
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

@mavenugo mavenugo left a 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.

@mavenugo mavenugo merged commit af59385 into moby:master Mar 13, 2017
@aboch aboch changed the title Support for com.docker.network.bridge.container_interface_prefix label Support for com.docker.network.container_interface_prefix driver label Mar 14, 2017
@thaJeztah thaJeztah changed the title Support for com.docker.network.container_interface_prefix driver label Support for com.docker.network.container_iface_prefix driver label May 31, 2021
@thaJeztah
Copy link
Member

Updated the title to include container_iface_prefix instead of container_interface_prefix (see docker/cli#2984)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants