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

handle gracefully add/delete of vethwedu dummy interface #3459

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions net/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ datapath of old kernel versions (https://github.com/weaveworks/weave/issues/1577

const (
WeaveBridgeName = "weave"
WeaveDummyIfName = "vethwedu"
DatapathName = "datapath"
DatapathIfName = "vethwe-datapath"
BridgeIfName = "vethwe-bridge"
Expand Down Expand Up @@ -327,22 +328,24 @@ func (b bridgeImpl) initPrep(config *BridgeConfig) error {
// fails. Bridges take the lowest MTU of their interfaces. So
// instead we create a temporary interface with the desired MTU,
// attach that to the bridge, and then remove it again.
dummy := &netlink.Dummy{LinkAttrs: netlink.NewLinkAttrs()}
dummy.LinkAttrs.Name = "vethwedu"
if err = netlink.LinkAdd(dummy); err != nil {
var dummy netlink.Link
dummy = &netlink.Dummy{LinkAttrs: netlink.NewLinkAttrs()}
dummy.Attrs().Name = WeaveDummyIfName
if err = LinkAddIfNotExist(dummy); err != nil {
return errors.Wrap(err, "creating dummy interface")
}
defer func() {
if err = netlink.LinkDel(dummy); err != nil {
err = errors.Wrap(err, "deleting dummy interface")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think assigning to the local variable err at this point has no effect.
If err is made a named return value from initPrep it would work, but suppose both LinkSetMTU and LinkDel fail, we'd only see one error.
Maybe use a different err to record the LinkDel() result and use Wrap() to add the previous error (if any).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, Wrap() can only wrap one error. Maybe just add the text of this one to the previous one, if it exists.

}
}()
if err := netlink.LinkSetMTU(dummy, config.MTU); err != nil {
return errors.Wrapf(err, "setting dummy interface mtu to %d", config.MTU)
}
if err := netlink.LinkSetMasterByIndex(dummy, b.bridge.Attrs().Index); err != nil {
return errors.Wrap(err, "setting dummy interface master")
}
if err := netlink.LinkDel(dummy); err != nil {
return errors.Wrap(err, "deleting dummy interface")
}

return nil
return err
}

func (b bridgeImpl) init(config *BridgeConfig) error {
Expand Down