Skip to content

Commit

Permalink
Fix fallback to pcap based bridge when odp is not supported
Browse files Browse the repository at this point in the history
The fix ensures that if odp is not supported (usually due to
missing openvswitch, vxlan or vport-vxlan kernel modules),
weaver will create the pcap based bridge instead of crashing.
  • Loading branch information
brb committed Jun 27, 2017
1 parent 3499dbf commit f373772
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
18 changes: 12 additions & 6 deletions net/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type Bridge interface {
String() string // human-readable type string
}

var errBridgeFallback = errors.New("special error value used to trigger a fallback to bridge type")
// Used to indicate a fallback to the Bridge type
var errBridgeNotSupported = errors.New("bridge not supported")

type bridgeImpl struct{ bridge netlink.Link }
type fastdpImpl struct{ datapathName string }
Expand Down Expand Up @@ -226,7 +227,7 @@ func (config *BridgeConfig) configuredBridgeType() Bridge {
}
}

func EnsureBridge(procPath string, config *BridgeConfig) (Bridge, error) {
func EnsureBridge(procPath string, config *BridgeConfig, log *logrus.Logger) (Bridge, error) {
bridgeType, err := ExistingBridgeType(config.WeaveBridgeName, config.DatapathName)
if bridgeType != nil || err != nil {
return bridgeType, err
Expand All @@ -235,7 +236,8 @@ func EnsureBridge(procPath string, config *BridgeConfig) (Bridge, error) {
bridgeType = config.configuredBridgeType()
for {
if err := bridgeType.init(config); err != nil {
if err == errBridgeFallback {
if errors.Cause(err) == errBridgeNotSupported {
log.Warnf("Skipping bridge creation of %q due to: %s", bridgeType, err)
bridgeType = bridgeImpl{}
continue
}
Expand Down Expand Up @@ -333,12 +335,16 @@ func (b bridgeImpl) init(config *BridgeConfig) error {

func (f fastdpImpl) init(config *BridgeConfig) error {
odpSupported, err := odp.CreateDatapath(f.datapathName)
if !odpSupported {
msg := ""
if err != nil {
msg = err.Error()
}
return errors.Wrap(errBridgeNotSupported, msg)
}
if err != nil {
return errors.Wrapf(err, "creating datapath %q", f.datapathName)
}
if !odpSupported {
return errBridgeFallback
}
datapath, err := netlink.LinkByName(f.datapathName)
if err != nil {
return errors.Wrapf(err, "finding datapath %q", f.datapathName)
Expand Down
2 changes: 1 addition & 1 deletion prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func main() {
name := peerName(routerName, bridgeConfig.WeaveBridgeName, dbPrefix, hostRoot)

bridgeConfig.Mac = name.String()
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig)
bridgeType, err := weavenet.EnsureBridge(procPath, &bridgeConfig, Log)
checkFatal(err)
Log.Println("Bridge type is", bridgeType)

Expand Down
3 changes: 2 additions & 1 deletion prog/weaveutil/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

"github.com/weaveworks/weave/common"
weavenet "github.com/weaveworks/weave/net"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func createBridge(args []string) error {
NPC: args[9] == "--expect-npc",
}
procPath := args[8]
bridgeType, err := weavenet.EnsureBridge(procPath, &config)
bridgeType, err := weavenet.EnsureBridge(procPath, &config, common.Log)
if err != nil {
return err
}
Expand Down

0 comments on commit f373772

Please sign in to comment.