Skip to content

Commit

Permalink
Add podman network create option for bridge vlan
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Dec 1, 2020
1 parent b1b3570 commit 7f1be76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/source/markdown/podman-network-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ Driver to manage the network (default "bridge"). Currently only `bridge` is sup

Set driver specific options.

For the `bridge` driver the following options are supported: `mtu`.
For the `bridge` driver the following options are supported: `mtu` and `vlan`.
The `mtu` option sets the Maximum Transmission Unit (MTU) and takes an integer value.
The `vlan` option assign VLAN tag and enables vlan\_filtering. Defaults to none.

#### **--gateway**

Expand Down
15 changes: 14 additions & 1 deletion libpod/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion libpod/network/netconflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7f1be76

Please sign in to comment.