Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 4b903b3

Browse files
committed
handle gracefully add/delete of vethwedu dummy interface
fixes #3414
1 parent 9654df4 commit 4b903b3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

net/bridge.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ datapath of old kernel versions (https://github.com/weaveworks/weave/issues/1577
5555

5656
const (
5757
WeaveBridgeName = "weave"
58+
WeaveDummyIfName = "vethwedu"
5859
DatapathName = "datapath"
5960
DatapathIfName = "vethwe-datapath"
6061
BridgeIfName = "vethwe-bridge"
@@ -328,8 +329,8 @@ func (b bridgeImpl) initPrep(config *BridgeConfig) error {
328329
// instead we create a temporary interface with the desired MTU,
329330
// attach that to the bridge, and then remove it again.
330331
dummy := &netlink.Dummy{LinkAttrs: netlink.NewLinkAttrs()}
331-
dummy.LinkAttrs.Name = "vethwedu"
332-
if err = netlink.LinkAdd(dummy); err != nil {
332+
dummy.LinkAttrs.Name = WeaveDummyIfName
333+
if err = LinkAddIfNotExist(dummy); err != nil {
333334
return errors.Wrap(err, "creating dummy interface")
334335
}
335336
if err := netlink.LinkSetMTU(dummy, config.MTU); err != nil {
@@ -338,11 +339,16 @@ func (b bridgeImpl) initPrep(config *BridgeConfig) error {
338339
if err := netlink.LinkSetMasterByIndex(dummy, b.bridge.Attrs().Index); err != nil {
339340
return errors.Wrap(err, "setting dummy interface master")
340341
}
341-
if err := netlink.LinkDel(dummy); err != nil {
342-
return errors.Wrap(err, "deleting dummy interface")
343-
}
344-
345-
return nil
342+
defer func() {
343+
var dummyIf netlink.Link
344+
dummyIf, err = netlink.LinkByName(WeaveDummyIfName)
345+
if err == nil {
346+
if err = netlink.LinkDel(dummyIf); err != nil {
347+
err = errors.Wrap(err, "deleting dummy interface")
348+
}
349+
}
350+
}()
351+
return err
346352
}
347353

348354
func (b bridgeImpl) init(config *BridgeConfig) error {

0 commit comments

Comments
 (0)