Skip to content

Commit ea744fb

Browse files
author
Arko Dasgupta
committed
Move dummyLinkExists into createDummyLink
Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
1 parent 4c5094c commit ea744fb

4 files changed

Lines changed: 36 additions & 39 deletions

File tree

drivers/ipvlan/ipvlan_network.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
9797
if !parentExists(config.Parent) {
9898
// if the --internal flag is set, create a dummy link
9999
if config.Internal {
100-
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
101-
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
102-
if err != nil {
103-
return false, err
104-
}
105-
config.CreatedSlaveLink = true
106-
107-
} else {
108-
logrus.Debugf("Dummy Link %s for ipvlan already exists", getDummyName(stringid.TruncateID(config.ID)))
100+
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
101+
if err != nil {
102+
return false, err
109103
}
104+
config.CreatedSlaveLink = true
110105

111106
// notify the user in logs they have limited communications
112107
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
@@ -116,17 +111,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
116111
} else {
117112
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
118113
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
119-
if !vlanLinkExists(config.Parent) {
120-
err := createVlanLink(config.Parent)
121-
if err != nil {
122-
return false, err
123-
}
124-
// if driver created the networks slave link, record it for future deletion
125-
config.CreatedSlaveLink = true
126-
} else {
127-
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
114+
err := createVlanLink(config.Parent)
115+
if err != nil {
116+
return false, err
128117
}
129-
118+
// if driver created the networks slave link, record it for future deletion
119+
config.CreatedSlaveLink = true
130120
}
131121
}
132122
if !foundExisting {

drivers/ipvlan/ipvlan_setup.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func vlanLinkExists(linkStr string) bool {
8181

8282
// createVlanLink parses sub-interfaces and vlan id for creation
8383
func createVlanLink(parentName string) error {
84+
if vlanLinkExists(parentName) {
85+
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
86+
return nil
87+
}
88+
8489
if strings.Contains(parentName, ".") {
8590
parent, vidInt, err := parseVlan(parentName)
8691
if err != nil {
@@ -176,6 +181,11 @@ func dummyLinkExists(dummyName string) bool {
176181

177182
// createDummyLink creates a dummy0 parent link
178183
func createDummyLink(dummyName, truncNetID string) error {
184+
// check if dummyLinkExists and return if it does
185+
if dummyLinkExists(truncNetID) {
186+
logrus.Debugf("Dummy Link %s for ipvlan already exists", truncNetID)
187+
return nil
188+
}
179189
// create a parent interface since one was not specified
180190
parent := &netlink.Dummy{
181191
LinkAttrs: netlink.LinkAttrs{

drivers/macvlan/macvlan_network.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
102102
if !parentExists(config.Parent) {
103103
// if the --internal flag is set, create a dummy link
104104
if config.Internal {
105-
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
106-
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
107-
if err != nil {
108-
return false, err
109-
}
110-
config.CreatedSlaveLink = true
111-
} else {
112-
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", getDummyName(stringid.TruncateID(config.ID)))
105+
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
106+
if err != nil {
107+
return false, err
113108
}
109+
config.CreatedSlaveLink = true
114110
// notify the user in logs they have limited communications
115111
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
116112
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
@@ -119,19 +115,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
119115
} else {
120116
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
121117
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
122-
123-
if !vlanLinkExists(config.Parent) {
124-
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
125-
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
126-
err := createVlanLink(config.Parent)
127-
if err != nil {
128-
return false, err
129-
}
130-
// if driver created the networks slave link, record it for future deletion
131-
config.CreatedSlaveLink = true
132-
} else {
133-
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
118+
err := createVlanLink(config.Parent)
119+
if err != nil {
120+
return false, err
134121
}
122+
// if driver created the networks slave link, record it for future deletion
123+
config.CreatedSlaveLink = true
135124
}
136125
}
137126
if !foundExisting {

drivers/macvlan/macvlan_setup.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func vlanLinkExists(linkStr string) bool {
8585

8686
// createVlanLink parses sub-interfaces and vlan id for creation
8787
func createVlanLink(parentName string) error {
88+
if vlanLinkExists(parentName) {
89+
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
90+
return nil
91+
}
8892
if strings.Contains(parentName, ".") {
8993
parent, vidInt, err := parseVlan(parentName)
9094
if err != nil {
@@ -180,6 +184,10 @@ func dummyLinkExists(dummyName string) bool {
180184

181185
// createDummyLink creates a dummy0 parent link
182186
func createDummyLink(dummyName, truncNetID string) error {
187+
if dummyLinkExists(truncNetID) {
188+
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", truncNetID)
189+
return nil
190+
}
183191
// create a parent interface since one was not specified
184192
parent := &netlink.Dummy{
185193
LinkAttrs: netlink.LinkAttrs{

0 commit comments

Comments
 (0)