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

Probe whether the kernel has ODP vxlan support #1619

Merged
merged 1 commit into from
Nov 2, 2015
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/davecheney/profile"
"github.com/docker/docker/pkg/mflag"
"github.com/gorilla/mux"
"github.com/weaveworks/go-odp/odp"

. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
Expand Down Expand Up @@ -119,8 +118,12 @@ func main() {
os.Exit(0)

case createDatapath:
err := weave.CreateDatapath(datapathName)
if odp.IsKernelLacksODPError(err) {
err, odp_supported := weave.CreateDatapath(datapathName)
if !odp_supported {
if err != nil {
Log.Error(err)
}

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.


// When the kernel lacks ODP support, exit
// with a special status to distinguish it for
// the weave script.
Expand Down
43 changes: 38 additions & 5 deletions router/odp.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
package router

import (
"fmt"
"net"
"syscall"

"github.com/weaveworks/go-odp/odp"
)

// ODP admin functionality

func CreateDatapath(dpname string) error {
func CreateDatapath(dpname string) (err error, supported bool) {
dpif, err := odp.NewDpif()
if err != nil {
return err
if odp.IsKernelLacksODPError(err) {
return nil, false
}

return err, true
}

defer dpif.Close()

_, err = dpif.CreateDatapath(dpname)
dp, err := dpif.CreateDatapath(dpname)
if err != nil && !odp.IsDatapathNameAlreadyExistsError(err) {
return err
return err, true
}

// Pick an ephemeral port number to use in probing for vxlan
// support.
udpconn, err := net.ListenUDP("udp4", nil)
if err != nil {
return err, true

This comment was marked as abuse.

This comment was marked as abuse.

}

// we leave the UDP socket open, so creating a vxlan vport on
// the same port number should fail. But that's fine: It's
// still sufficient to probe for support.
portno := uint16(udpconn.LocalAddr().(*net.UDPAddr).Port)
vpid, err := dp.CreateVport(odp.NewVxlanVportSpec(
fmt.Sprintf("vxlan-%d", portno), portno))
if nlerr, ok := err.(odp.NetlinkError); ok {
if syscall.Errno(nlerr) == syscall.EAFNOSUPPORT {
dp.Delete()
return fmt.Errorf("kernel does not have Open vSwitch VXLAN support"), false
}
}

if err == nil {
dp.DeleteVport(vpid)
}

return nil
udpconn.Close()
return nil, true
}

func DeleteDatapath(dpname string) error {
Expand Down