aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-02 01:01:09 +0100
committerGitHub <noreply@github.com>2020-12-02 01:01:09 +0100
commitc585012db395e259b13157a685d7f9596c0b9f7d (patch)
tree260a3d2e2b20af7f91cad8443278f53288b0c42d /libpod
parentb2cd6e0402bcd425130e397d79588dc406eccf53 (diff)
parentdb70e91bde90514ace510f66a1069207217a8d69 (diff)
downloadpodman-c585012db395e259b13157a685d7f9596c0b9f7d.tar.gz
podman-c585012db395e259b13157a685d7f9596c0b9f7d.tar.bz2
podman-c585012db395e259b13157a685d7f9596c0b9f7d.zip
Merge pull request #8457 from afbjorklund/bridge-mtu
Add podman network create flag for bridge mtu
Diffstat (limited to 'libpod')
-rw-r--r--libpod/network/create.go48
-rw-r--r--libpod/network/netconflist.go4
2 files changed, 50 insertions, 2 deletions
diff --git a/libpod/network/create.go b/libpod/network/create.go
index cac438963..094fbe349 100644
--- a/libpod/network/create.go
+++ b/libpod/network/create.go
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strconv"
"github.com/containernetworking/cni/pkg/version"
"github.com/containers/common/pkg/config"
@@ -76,6 +77,29 @@ func validateBridgeOptions(options entities.NetworkCreateOptions) error {
}
+// parseMTU parses the mtu option
+func parseMTU(mtu string) (int, error) {
+ if mtu == "" {
+ return 0, nil // default
+ }
+ m, err := strconv.Atoi(mtu)
+ if err != nil {
+ return 0, err
+ }
+ if m < 0 {
+ return 0, errors.Errorf("the value %d for mtu is less than zero", m)
+ }
+ return m, nil
+}
+
+// parseVlan parses the vlan option
+func parseVlan(vlan string) (int, error) {
+ if vlan == "" {
+ return 0, nil // default
+ }
+ return strconv.Atoi(vlan)
+}
+
// createBridge creates a CNI network
func createBridge(name string, options entities.NetworkCreateOptions, runtimeConfig *config.Config) (string, error) {
var (
@@ -149,6 +173,28 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon
ipMasq = false
}
+ var mtu int
+ var vlan int
+ for k, v := range options.Options {
+ var err error
+ switch k {
+ case "mtu":
+ mtu, err = parseMTU(v)
+ if err != nil {
+ return "", err
+ }
+
+ case "vlan":
+ vlan, err = parseVlan(v)
+ if err != nil {
+ return "", err
+ }
+
+ default:
+ return "", errors.Errorf("unsupported option %s", k)
+ }
+ }
+
// obtain host bridge name
bridgeDeviceName, err := GetFreeDeviceName(runtimeConfig)
if err != nil {
@@ -172,7 +218,7 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon
ncList := NewNcList(name, version.Current(), options.Labels)
var plugins []CNIPlugins
// TODO need to iron out the role of isDefaultGW and IPMasq
- bridge := NewHostLocalBridge(bridgeDeviceName, isGateway, false, ipMasq, ipamConfig)
+ bridge := NewHostLocalBridge(bridgeDeviceName, isGateway, false, ipMasq, mtu, vlan, ipamConfig)
plugins = append(plugins, bridge)
plugins = append(plugins, NewPortMapPlugin())
plugins = append(plugins, NewFirewallPlugin())
diff --git a/libpod/network/netconflist.go b/libpod/network/netconflist.go
index 3db38485b..a5fec5e80 100644
--- a/libpod/network/netconflist.go
+++ b/libpod/network/netconflist.go
@@ -41,12 +41,14 @@ func NewNcList(name, version string, labels NcLabels) NcList {
}
// NewHostLocalBridge creates a new LocalBridge for host-local
-func NewHostLocalBridge(name string, isGateWay, isDefaultGW, ipMasq bool, ipamConf IPAMHostLocalConf) *HostLocalBridge {
+func NewHostLocalBridge(name string, isGateWay, isDefaultGW, ipMasq bool, mtu int, vlan int, ipamConf IPAMHostLocalConf) *HostLocalBridge {
hostLocalBridge := HostLocalBridge{
PluginType: "bridge",
BrName: name,
IPMasq: ipMasq,
+ MTU: mtu,
HairpinMode: true,
+ Vlan: vlan,
IPAM: ipamConf,
}
if isGateWay {