summaryrefslogtreecommitdiff
path: root/libpod/network/create.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/network/create.go')
-rw-r--r--libpod/network/create.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/libpod/network/create.go b/libpod/network/create.go
index a8f985af9..deacf487a 100644
--- a/libpod/network/create.go
+++ b/libpod/network/create.go
@@ -29,7 +29,7 @@ func Create(name string, options entities.NetworkCreateOptions, runtimeConfig *c
return nil, err
}
defer l.releaseCNILock()
- if len(options.MacVLAN) > 0 {
+ if len(options.MacVLAN) > 0 || options.Driver == MacVLANNetworkDriver {
fileName, err = createMacVLAN(name, options, runtimeConfig)
} else {
fileName, err = createBridge(name, options, runtimeConfig)
@@ -249,6 +249,7 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon
func createMacVLAN(name string, options entities.NetworkCreateOptions, runtimeConfig *config.Config) (string, error) {
var (
+ mtu int
plugins []CNIPlugins
)
liveNetNames, err := GetLiveNetworkNames()
@@ -256,9 +257,17 @@ func createMacVLAN(name string, options entities.NetworkCreateOptions, runtimeCo
return "", err
}
- // Make sure the host-device exists
- if !util.StringInSlice(options.MacVLAN, liveNetNames) {
- return "", errors.Errorf("failed to find network interface %q", options.MacVLAN)
+ // The parent can be defined with --macvlan or as an option (-o parent:device)
+ parentNetworkDevice := options.MacVLAN
+ if len(parentNetworkDevice) < 1 {
+ if parent, ok := options.Options["parent"]; ok {
+ parentNetworkDevice = parent
+ }
+ }
+
+ // Make sure the host-device exists if provided
+ if len(parentNetworkDevice) > 0 && !util.StringInSlice(parentNetworkDevice, liveNetNames) {
+ return "", errors.Errorf("failed to find network interface %q", parentNetworkDevice)
}
if len(name) > 0 {
netNames, err := GetNetworkNamesFromFileSystem(runtimeConfig)
@@ -275,7 +284,19 @@ func createMacVLAN(name string, options entities.NetworkCreateOptions, runtimeCo
}
}
ncList := NewNcList(name, version.Current(), options.Labels)
- macvlan := NewMacVLANPlugin(options.MacVLAN)
+ if val, ok := options.Options["mtu"]; ok {
+ intVal, err := strconv.Atoi(val)
+ if err != nil {
+ return "", err
+ }
+ if intVal > 0 {
+ mtu = intVal
+ }
+ }
+ macvlan, err := NewMacVLANPlugin(parentNetworkDevice, options.Gateway, &options.Range, &options.Subnet, mtu)
+ if err != nil {
+ return "", err
+ }
plugins = append(plugins, macvlan)
ncList["plugins"] = plugins
b, err := json.MarshalIndent(ncList, "", " ")