From 7433a6892652fcedbd8d7ceef66272035d1b0201 Mon Sep 17 00:00:00 2001 From: Marcelo Guerrero Date: Thu, 5 Oct 2023 14:44:29 +0200 Subject: [PATCH] Fix checks for vlan parameters Add back check when vlan is zero and qos is not zero. Remove check when vlan is zero and qos and proto are not in config since default values are now set. Signed-off-by: Marcelo Guerrero --- pkg/config/config.go | 9 +++++---- pkg/config/config_test.go | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 4677a93e2..6b7e59183 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -79,10 +79,6 @@ func LoadConf(bytes []byte) (*sriovtypes.NetConf, error) { return nil, fmt.Errorf("LoadConf(): vlan id %d invalid: value must be in the range 0-4094", *n.Vlan) } - if *n.Vlan == 0 && (n.VlanQoS != nil || n.VlanProto != nil) { - return nil, fmt.Errorf("LoadConf(): non-zero vlan id must be configured to set vlan Qos and/or Proto") - } - if n.VlanQoS == nil { qos := 0 n.VlanQoS = &qos @@ -93,6 +89,11 @@ func LoadConf(bytes []byte) (*sriovtypes.NetConf, error) { return nil, fmt.Errorf("LoadConf(): vlan QoS PCP %d invalid: value must be in the range 0-7", *n.VlanQoS) } + // validate non-zero value for vlan id if vlan qos is set to a non-zero value + if *n.VlanQoS != 0 && *n.Vlan == 0 { + return nil, fmt.Errorf("LoadConf(): non-zero vlan id must be configured to set vlan QoS to a non-zero value") + } + if n.VlanProto == nil { proto := sriovtypes.Proto8021q n.VlanProto = &proto diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f3a642bec..d76dc85a4 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -109,13 +109,11 @@ var _ = Describe("Config", func() { Entry("valid vlan ID", &validVlanID, nil, nil, false), Entry("invalid vlan ID", &invalidVlanID, nil, nil, true), Entry("vlan ID equal to zero and QoS set", &zeroVlanID, &validQoS, nil, true), - Entry("vlan ID equal to zero and Proto set", &zeroVlanID, nil, &valid8021qProto, true), Entry("invalid QoS", &validVlanID, &invalidQoS, nil, true), Entry("invalid Proto", &validVlanID, nil, &invalidProto, true), Entry("valid 802.1q Proto", &validVlanID, nil, &valid8021qProto, false), Entry("valid 802.1ad Proto", &validVlanID, nil, &valid8021adProto, false), Entry("no vlan ID and QoS set", nil, &validQoS, nil, true), - Entry("no vlan ID and Proto set", nil, nil, &valid8021adProto, true), ) It("Assuming device is allocated", func() {