Skip to content

Commit 974eb2b

Browse files
committed
incusd/device/nic_physical: Fix inheritance from network
With the reworked validation we weren't correctly pulling in network-wide settings anymore as the list of optional fields has now been trimmed down to correctly align with the type of instances being run. Introduce an internal networkFields list which lists the properties to be inherited from the network, then ensure the user doesn't get to set those when linked to a managed network and finally use that list to import those properties from the network if set there. Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
1 parent b030aad commit 974eb2b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

internal/server/device/nic_physical.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ func (d *nicPhysical) validateConfig(instConf instance.ConfigReader, partialVali
141141
// managed: no
142142
// shortdesc: The managed network to link the device to (instead of specifying the `nictype` directly)
143143
if d.config["network"] != "" {
144+
// List of properties we import from the parent network.
145+
networkFields := []string{"gvrp", "mtu", "vlan", "vlan.tagged"}
146+
144147
requiredFields = append(requiredFields, "network")
145148

146-
bannedKeys := []string{"nictype", "parent", "mtu", "vlan", "vlan.tagged", "gvrp"}
149+
bannedKeys := append([]string{"nictype", "parent"}, networkFields...)
147150
for _, bannedKey := range bannedKeys {
148151
if d.config[bannedKey] != "" {
149152
return fmt.Errorf("Cannot use %q property in conjunction with %q property", bannedKey, "network")
@@ -171,8 +174,8 @@ func (d *nicPhysical) validateConfig(instConf instance.ConfigReader, partialVali
171174
// Get actual parent device from network's parent setting.
172175
d.config["parent"] = netConfig["parent"]
173176

174-
// Copy certain keys verbatim from the network's settings.
175-
for _, field := range optionalFields {
177+
// Copy certain keys verbatim from the parent network's settings.
178+
for _, field := range networkFields {
176179
_, found := netConfig[field]
177180
if found {
178181
d.config[field] = netConfig[field]

0 commit comments

Comments
 (0)