From 7f1be76b5c388efe34cb658fb8eebb2bcec2a004 Mon Sep 17 00:00:00 2001 From: Anders F Björklund Date: Thu, 26 Nov 2020 17:38:38 +0100 Subject: Add podman network create option for bridge vlan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders F Björklund --- libpod/network/create.go | 15 ++++++++++++++- libpod/network/netconflist.go | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'libpod/network') diff --git a/libpod/network/create.go b/libpod/network/create.go index 50337013d..e9ab93262 100644 --- a/libpod/network/create.go +++ b/libpod/network/create.go @@ -92,6 +92,14 @@ func parseMTU(mtu string) (int, error) { 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 ( @@ -170,6 +178,11 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon return "", err } + vlan, err := parseVlan(options.Options["vlan"]) + if err != nil { + return "", err + } + // obtain host bridge name bridgeDeviceName, err := GetFreeDeviceName(runtimeConfig) if err != nil { @@ -193,7 +206,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, mtu, 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 8cbad39cb..a5fec5e80 100644 --- a/libpod/network/netconflist.go +++ b/libpod/network/netconflist.go @@ -41,13 +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, mtu int, 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 { -- cgit v1.2.3-54-g00ecf