From af75e8a624c2067bdd2572989b6b38d066a04f09 Mon Sep 17 00:00:00 2001 From: Brent Salisbury Date: Thu, 10 Mar 2016 17:09:48 -0500 Subject: [PATCH] Added kernel version checks for macvlan/ipvlan ipvlan >= 4.0.0 due to early instability macvlan >= 3.9 Signed-off-by: Brent Salisbury --- libnetwork/drivers/ipvlan/ipvlan_network.go | 10 ++++++++++ libnetwork/drivers/ipvlan/ipvlan_setup.go | 5 +++-- libnetwork/drivers/macvlan/macvlan_network.go | 10 ++++++++++ libnetwork/drivers/macvlan/macvlan_setup.go | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libnetwork/drivers/ipvlan/ipvlan_network.go b/libnetwork/drivers/ipvlan/ipvlan_network.go index c0fa276190..036b37c472 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_network.go +++ b/libnetwork/drivers/ipvlan/ipvlan_network.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/stringid" "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" @@ -13,6 +14,15 @@ import ( // CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error { + kv, err := kernel.GetKernelVersion() + if err != nil { + return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err) + } + // ensure Kernel version is greater then v4.0 for ipvlan support + if kv.Kernel < ipvlanKernelVer { + return fmt.Errorf("kernel version failed to meet the minimum ipvlan kernel requirement of %d.%d, found %d.%d.%d", + ipvlanKernelVer, ipvlanMajorVer, kv.Kernel, kv.Major, kv.Minor) + } // parse and validate the config and bind to networkConfiguration config, err := parseNetworkOptions(nid, option) if err != nil { diff --git a/libnetwork/drivers/ipvlan/ipvlan_setup.go b/libnetwork/drivers/ipvlan/ipvlan_setup.go index 3f8f4c2757..fb362c94ff 100644 --- a/libnetwork/drivers/ipvlan/ipvlan_setup.go +++ b/libnetwork/drivers/ipvlan/ipvlan_setup.go @@ -14,8 +14,9 @@ import ( ) const ( - dummyPrefix = "di-" // ipvlan prefix for dummy parent interface - ipvlanKernelVer = "3.19" // minimum ipvlan kernel version support + dummyPrefix = "di-" // ipvlan prefix for dummy parent interface + ipvlanKernelVer = 4 // minimum ipvlan kernel support + ipvlanMajorVer = 0 // minimum ipvlan major kernel support ) // createIPVlan Create the ipvlan slave specifying the source name diff --git a/libnetwork/drivers/macvlan/macvlan_network.go b/libnetwork/drivers/macvlan/macvlan_network.go index 3b46a335f8..4fa00161d0 100644 --- a/libnetwork/drivers/macvlan/macvlan_network.go +++ b/libnetwork/drivers/macvlan/macvlan_network.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/stringid" "github.com/docker/libnetwork/driverapi" "github.com/docker/libnetwork/netlabel" @@ -13,6 +14,15 @@ import ( // CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error { + kv, err := kernel.GetKernelVersion() + if err != nil { + return fmt.Errorf("failed to check kernel version for %s driver support: %v", macvlanType, err) + } + // ensure Kernel version is greater then v3.9 for macvlan support + if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { + return fmt.Errorf("kernel version failed to meet the minimum macvlan kernel requirement of %d.%d, found %d.%d.%d", + macvlanKernelVer, macvlanMajorVer, kv.Kernel, kv.Major, kv.Minor) + } // parse and validate the config and bind to networkConfiguration config, err := parseNetworkOptions(nid, option) if err != nil { diff --git a/libnetwork/drivers/macvlan/macvlan_setup.go b/libnetwork/drivers/macvlan/macvlan_setup.go index d6d97a1b3a..9380dab504 100644 --- a/libnetwork/drivers/macvlan/macvlan_setup.go +++ b/libnetwork/drivers/macvlan/macvlan_setup.go @@ -15,7 +15,8 @@ import ( const ( dummyPrefix = "dm-" // macvlan prefix for dummy parent interface - macvlanKernelVer = "3.9" // minimum ipvlan kernel version support + macvlanKernelVer = 3 // minimum macvlan kernel support + macvlanMajorVer = 9 // minimum macvlan major kernel support ) // Create the macvlan slave specifying the source name