diff options
Diffstat (limited to 'libpod/network')
-rw-r--r-- | libpod/network/config.go | 5 | ||||
-rw-r--r-- | libpod/network/create.go | 31 | ||||
-rw-r--r-- | libpod/network/netconflist.go | 22 | ||||
-rw-r--r-- | libpod/network/network.go | 12 |
4 files changed, 58 insertions, 12 deletions
diff --git a/libpod/network/config.go b/libpod/network/config.go index ce351129e..294e23509 100644 --- a/libpod/network/config.go +++ b/libpod/network/config.go @@ -103,7 +103,9 @@ func (p PortMapConfig) Bytes() ([]byte, error) { // IPAMDHCP describes the ipamdhcp config type IPAMDHCP struct { - DHCP string `json:"type"` + DHCP string `json:"type"` + Routes []IPAMRoute `json:"routes,omitempty"` + Ranges [][]IPAMLocalHostRangeConf `json:"ranges,omitempty"` } // MacVLANConfig describes the macvlan config @@ -111,6 +113,7 @@ type MacVLANConfig struct { PluginType string `json:"type"` Master string `json:"master"` IPAM IPAMDHCP `json:"ipam"` + MTU int `json:"mtu,omitempty"` } // Bytes outputs the configuration as []byte 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, "", " ") diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go index 165a9067b..9be98e78f 100644 --- a/libpod/network/netconflist.go +++ b/libpod/network/netconflist.go @@ -172,15 +172,31 @@ func HasDNSNamePlugin(paths []string) bool { } // NewMacVLANPlugin creates a macvlanconfig with a given device name -func NewMacVLANPlugin(device string) MacVLANConfig { +func NewMacVLANPlugin(device string, gateway net.IP, ipRange *net.IPNet, subnet *net.IPNet, mtu int) (MacVLANConfig, error) { i := IPAMDHCP{DHCP: "dhcp"} + if gateway != nil || ipRange != nil || subnet != nil { + ipam, err := NewIPAMLocalHostRange(subnet, ipRange, gateway) + if err != nil { + return MacVLANConfig{}, err + } + ranges := make([][]IPAMLocalHostRangeConf, 0) + ranges = append(ranges, ipam) + i.Ranges = ranges + } m := MacVLANConfig{ PluginType: "macvlan", - Master: device, IPAM: i, } - return m + if mtu > 0 { + m.MTU = mtu + } + // CNI is supposed to use the default route if a + // parent device is not provided + if len(device) > 0 { + m.Master = device + } + return m, nil } // IfPassesFilter filters NetworkListReport and returns true if the filter match the given config diff --git a/libpod/network/network.go b/libpod/network/network.go index 0fb878b18..0ff14c1f7 100644 --- a/libpod/network/network.go +++ b/libpod/network/network.go @@ -17,11 +17,17 @@ import ( "github.com/sirupsen/logrus" ) -// DefaultNetworkDriver is the default network type used -var DefaultNetworkDriver = "bridge" +var ( + // BridgeNetworkDriver defines the bridge cni driver + BridgeNetworkDriver = "bridge" + // DefaultNetworkDriver is the default network type used + DefaultNetworkDriver = BridgeNetworkDriver + // MacVLANNetworkDriver defines the macvlan cni driver + MacVLANNetworkDriver = "macvlan" +) // SupportedNetworkDrivers describes the list of supported drivers -var SupportedNetworkDrivers = []string{DefaultNetworkDriver} +var SupportedNetworkDrivers = []string{BridgeNetworkDriver, MacVLANNetworkDriver} // isSupportedDriver checks if the user provided driver is supported func isSupportedDriver(driver string) error { |