浏览代码

Added kernel version checks for macvlan/ipvlan

ipvlan >= 4.0.0 due to early instability
macvlan >= 3.9

Signed-off-by: Brent Salisbury <brent@docker.com>
Brent Salisbury 9 年之前
父节点
当前提交
af75e8a624

+ 10 - 0
libnetwork/drivers/ipvlan/ipvlan_network.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fmt"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
+	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/netlabel"
 	"github.com/docker/libnetwork/netlabel"
@@ -13,6 +14,15 @@ import (
 
 
 // CreateNetwork the network for the specified driver type
 // CreateNetwork the network for the specified driver type
 func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
 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
 	// parse and validate the config and bind to networkConfiguration
 	config, err := parseNetworkOptions(nid, option)
 	config, err := parseNetworkOptions(nid, option)
 	if err != nil {
 	if err != nil {

+ 3 - 2
libnetwork/drivers/ipvlan/ipvlan_setup.go

@@ -14,8 +14,9 @@ import (
 )
 )
 
 
 const (
 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
 // createIPVlan Create the ipvlan slave specifying the source name

+ 10 - 0
libnetwork/drivers/macvlan/macvlan_network.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fmt"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
+	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/driverapi"
 	"github.com/docker/libnetwork/netlabel"
 	"github.com/docker/libnetwork/netlabel"
@@ -13,6 +14,15 @@ import (
 
 
 // CreateNetwork the network for the specified driver type
 // CreateNetwork the network for the specified driver type
 func (d *driver) CreateNetwork(nid string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
 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
 	// parse and validate the config and bind to networkConfiguration
 	config, err := parseNetworkOptions(nid, option)
 	config, err := parseNetworkOptions(nid, option)
 	if err != nil {
 	if err != nil {

+ 2 - 1
libnetwork/drivers/macvlan/macvlan_setup.go

@@ -15,7 +15,8 @@ import (
 
 
 const (
 const (
 	dummyPrefix      = "dm-" // macvlan prefix for dummy parent interface
 	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
 // Create the macvlan slave specifying the source name