From 40980aeb90fc93afe39a8cced1b92cf516a36d60 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Thu, 23 Aug 2018 10:02:21 +0530 Subject: [PATCH] Monitor and throw error message in the logs if Weave bridge interface is found to be in DOWN state Fixes #3133 Do something more useful when the weave bridge is DOWN On Weave restart there is already logic in place to create the bridge interface and bring it up, this fix only monotors the weave bridge interface and logs error if it is in DOWN state --- net/bridge.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/net/bridge.go b/net/bridge.go index e6fb747c..a65210fa 100644 --- a/net/bridge.go +++ b/net/bridge.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net" "path/filepath" + "syscall" "github.com/coreos/go-iptables/iptables" "github.com/pkg/errors" @@ -283,6 +284,10 @@ func EnsureBridge(procPath string, config *BridgeConfig, log *logrus.Logger, ips return bridgeType, err } + if err := monitorInterface(config.WeaveBridgeName, log); err != nil { + return bridgeType, err + } + if err := configureARPCache(procPath, config.WeaveBridgeName); err != nil { return bridgeType, errors.Wrapf(err, "configuring ARP cache on bridge %q", config.WeaveBridgeName) } @@ -609,3 +614,27 @@ func reexpose(config *BridgeConfig, log *logrus.Logger) error { return nil } + +func monitorInterface(ifaceName string, log *logrus.Logger) error { + _, err := netlink.LinkByName(ifaceName) + if err != nil { + return fmt.Errorf("Unable to find link %q: %s", ifaceName, err) + } + + updatesChannel := make(chan netlink.LinkUpdate) + if err := netlink.LinkSubscribe(updatesChannel, nil); err != nil { + return errors.Wrapf(err, "error monitoring link %q for UP/DOWN notifications", ifaceName) + } + + go func() { + for { + select { + case update := <-updatesChannel: + if update.Link.Attrs().Name == ifaceName && update.IfInfomsg.Flags&syscall.IFF_UP == 0 { + log.Errorf("Interface %q which needs to be in UP state for Weave functioning is found to be in DOWN state", ifaceName) + } + } + } + }() + return nil +}