Skip to content

Commit f8155c4

Browse files
jnohlgardsmira
authored andcommitted
feat: add parsing of vlanNNNN:ethX style VLAN cmdline args
Check for invalid VLAN ID numbers during cmdline parsing Fixes #9552 Signed-off-by: Joakim Nohlgård <[email protected]> Signed-off-by: Dmitriy Matrenichev <[email protected]> (cherry picked from commit 78353f7)
1 parent ea19f15 commit f8155c4

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

internal/app/machined/pkg/controllers/network/cmdline.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,18 @@ func ParseCmdlineNetwork(cmdline *procfs.Cmdline) (CmdlineNetworking, error) {
337337

338338
_, vlanNumberString, ok := strings.Cut(vlanName, ".")
339339
if !ok {
340-
return settings, fmt.Errorf("malformed vlan commandline argument: %s", *vlanSettings)
340+
vlanNumberString, ok = strings.CutPrefix(vlanName, "vlan")
341+
if !ok {
342+
return settings, fmt.Errorf("malformed vlan commandline argument: %s", *vlanSettings)
343+
}
341344
}
342345

343346
vlanID, err := strconv.Atoi(vlanNumberString)
344347

348+
if vlanID < 1 || 4095 < vlanID {
349+
return settings, fmt.Errorf("invalid vlanID=%d, must be in the range 1..4095: %s", vlanID, *vlanSettings)
350+
}
351+
345352
if err != nil || vlanNumberString == "" {
346353
return settings, errors.New("unable to parse vlan")
347354
}

internal/app/machined/pkg/controllers/network/cmdline_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package network_test
66

77
import (
8+
"fmt"
89
"net"
910
"net/netip"
1011
"sort"
@@ -432,6 +433,58 @@ func (suite *CmdlineSuite) TestParse() {
432433
},
433434
},
434435
},
436+
{
437+
name: "vlan configuration with alternative link name vlan0008",
438+
cmdline: "vlan=vlan0008:eth1",
439+
expectedSettings: network.CmdlineNetworking{
440+
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
441+
{
442+
Name: "eth1.8",
443+
Logical: true,
444+
Up: true,
445+
Kind: netconfig.LinkKindVLAN,
446+
Type: nethelpers.LinkEther,
447+
ParentName: "eth1",
448+
ConfigLayer: netconfig.ConfigCmdline,
449+
VLAN: netconfig.VLANSpec{
450+
VID: 8,
451+
Protocol: nethelpers.VLANProtocol8021Q,
452+
},
453+
},
454+
},
455+
},
456+
},
457+
{
458+
name: "vlan configuration with alternative link name vlan1",
459+
cmdline: "vlan=vlan4095:eth1",
460+
expectedSettings: network.CmdlineNetworking{
461+
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
462+
{
463+
Name: "eth1.4095",
464+
Logical: true,
465+
Up: true,
466+
Kind: netconfig.LinkKindVLAN,
467+
Type: nethelpers.LinkEther,
468+
ParentName: "eth1",
469+
ConfigLayer: netconfig.ConfigCmdline,
470+
VLAN: netconfig.VLANSpec{
471+
VID: 4095,
472+
Protocol: nethelpers.VLANProtocol8021Q,
473+
},
474+
},
475+
},
476+
},
477+
},
478+
{
479+
name: "vlan configuration with invalid vlan ID 4096",
480+
cmdline: "vlan=eth1.4096:eth1",
481+
expectedError: fmt.Sprintf("invalid vlanID=%d, must be in the range 1..4095: %s", 4096, "eth1.4096:eth1"),
482+
},
483+
{
484+
name: "vlan configuration with invalid vlan ID 0",
485+
cmdline: "vlan=eth1.0:eth1",
486+
expectedError: fmt.Sprintf("invalid vlanID=%d, must be in the range 1..4095: %s", 0, "eth1.0:eth1"),
487+
},
435488
{
436489
name: "multiple ip configurations",
437490
cmdline: "ip=172.20.0.2::172.20.0.1:255.255.255.0::eth1::::: ip=eth3:dhcp ip=:::::eth4:dhcp::::",

0 commit comments

Comments
 (0)