The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8325
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Fixes #8318 Signed-off-by: Tim Rots <tim.r...@protonmail.ch>
From 274d307a71bddc084f0d6f4a86bb99d8d6f1f41a Mon Sep 17 00:00:00 2001 From: Tim Rots <tim.r...@protonmail.ch> Date: Wed, 13 Jan 2021 00:07:32 +0100 Subject: [PATCH] Support GVRP on macvlan Networks Fixes #8318 Signed-off-by: Tim Rots <tim.r...@protonmail.ch> --- lxd/device/device_utils_network.go | 8 ++++++-- lxd/device/nic_macvlan.go | 7 ++++--- lxd/network/driver_physical.go | 2 +- lxd/network/network_utils.go | 10 ++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lxd/device/device_utils_network.go b/lxd/device/device_utils_network.go index 80aa53262f..6e89fa673d 100644 --- a/lxd/device/device_utils_network.go +++ b/lxd/device/device_utils_network.go @@ -101,9 +101,13 @@ func networkRemoveInterfaceIfNeeded(state *state.State, nic string, current inst } // networkCreateVlanDeviceIfNeeded creates a VLAN device if doesn't already exist. -func networkCreateVlanDeviceIfNeeded(state *state.State, parent string, vlanDevice string, vlanID string) (string, error) { +func networkCreateVlanDeviceIfNeeded(state *state.State, parent string, vlanDevice string, vlanID string, gvrp string) (string, error) { if vlanID != "" { - created, err := network.VLANInterfaceCreate(parent, vlanDevice, vlanID) + + if gvrp != "" { + gvrp = "gvrp on" + } + created, err := network.VLANInterfaceCreate(parent, vlanDevice, vlanID, gvrp) if err != nil { return "", err } diff --git a/lxd/device/nic_macvlan.go b/lxd/device/nic_macvlan.go index c389eb2d51..4f33874034 100644 --- a/lxd/device/nic_macvlan.go +++ b/lxd/device/nic_macvlan.go @@ -36,13 +36,14 @@ func (d *nicMACVLAN) validateConfig(instConf instance.ConfigReader) error { "maas.subnet.ipv4", "maas.subnet.ipv6", "boot.priority", + "gvrp", } // Check that if network proeperty is set that conflicting keys are not present. if d.config["network"] != "" { requiredFields = append(requiredFields, "network") - bannedKeys := []string{"nictype", "parent", "mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"} + bannedKeys := []string{"nictype", "parent", "mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6", "gvrp"} for _, bannedKey := range bannedKeys { if d.config[bannedKey] != "" { return fmt.Errorf("Cannot use %q property in conjunction with %q property", bannedKey, "network") @@ -70,7 +71,7 @@ func (d *nicMACVLAN) validateConfig(instConf instance.ConfigReader) error { d.config["parent"] = netConfig["parent"] // Copy certain keys verbatim from the network's settings. - inheritKeys := []string{"mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"} + inheritKeys := []string{"mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6", "gvrp"} for _, inheritKey := range inheritKeys { if _, found := netConfig[inheritKey]; found { d.config[inheritKey] = netConfig[inheritKey] @@ -125,7 +126,7 @@ func (d *nicMACVLAN) Start() (*deviceConfig.RunConfig, error) { saveData["host_name"] = network.RandomDevName("mac") // Create VLAN parent device if needed. - statusDev, err := networkCreateVlanDeviceIfNeeded(d.state, d.config["parent"], actualParentName, d.config["vlan"]) + statusDev, err := networkCreateVlanDeviceIfNeeded(d.state, d.config["parent"], actualParentName, d.config["vlan"], d.config["gvrp"]) if err != nil { return nil, err } diff --git a/lxd/network/driver_physical.go b/lxd/network/driver_physical.go index 57c654b507..f24695a112 100644 --- a/lxd/network/driver_physical.go +++ b/lxd/network/driver_physical.go @@ -152,7 +152,7 @@ func (n *physical) Start() error { defer revert.Fail() hostName := GetHostDevice(n.config["parent"], n.config["vlan"]) - created, err := VLANInterfaceCreate(n.config["parent"], hostName, n.config["vlan"]) + created, err := VLANInterfaceCreate(n.config["parent"], hostName, n.config["vlan"], n.config["gvrp"]) if err != nil { return err } diff --git a/lxd/network/network_utils.go b/lxd/network/network_utils.go index fb488b212d..4e7f40d76c 100644 --- a/lxd/network/network_utils.go +++ b/lxd/network/network_utils.go @@ -1023,7 +1023,7 @@ func parseIPRanges(ipRangesList string, allowedNets ...*net.IPNet) ([]*shared.IP // VLANInterfaceCreate creates a VLAN interface on parent interface (if needed). // Returns boolean indicating if VLAN interface was created. -func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string) (bool, error) { +func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string, gvrp string) (bool, error) { if vlanID == "" { return false, nil } @@ -1032,6 +1032,12 @@ func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string) (bool, return false, nil } + // set optional gvrp flag + gvrpOptionString := "" + if gvrp != "" { + gvrpOptionString := "gvrp on" + } + // Bring the parent interface up so we can add a vlan to it. _, err := shared.RunCommand("ip", "link", "set", "dev", parent, "up") if err != nil { @@ -1039,7 +1045,7 @@ func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string) (bool, } // Add VLAN interface on top of parent. - _, err = shared.RunCommand("ip", "link", "add", "link", parent, "name", vlanDevice, "up", "type", "vlan", "id", vlanID) + _, err = shared.RunCommand("ip", "link", "add", "link", parent, "name", vlanDevice, "up", "type", "vlan", "id", vlanID, gvrpOptionString) if err != nil { return false, errors.Wrapf(err, "Failed to create VLAN interface %q on %q", vlanDevice, parent) }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel