Skip to content

Commit

Permalink
feat: add parsing of vlanNNNN:ethX style VLAN cmdline args
Browse files Browse the repository at this point in the history
Check for invalid VLAN ID numbers during cmdline parsing

Fixes #9552

Signed-off-by: Joakim Nohlgård <joakim@nohlgard.se>
Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
(cherry picked from commit 78353f7)
  • Loading branch information
jnohlgard authored and smira committed Nov 13, 2024
1 parent ea19f15 commit f8155c4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/app/machined/pkg/controllers/network/cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,18 @@ func ParseCmdlineNetwork(cmdline *procfs.Cmdline) (CmdlineNetworking, error) {

_, vlanNumberString, ok := strings.Cut(vlanName, ".")
if !ok {
return settings, fmt.Errorf("malformed vlan commandline argument: %s", *vlanSettings)
vlanNumberString, ok = strings.CutPrefix(vlanName, "vlan")
if !ok {
return settings, fmt.Errorf("malformed vlan commandline argument: %s", *vlanSettings)
}
}

vlanID, err := strconv.Atoi(vlanNumberString)

if vlanID < 1 || 4095 < vlanID {
return settings, fmt.Errorf("invalid vlanID=%d, must be in the range 1..4095: %s", vlanID, *vlanSettings)
}

if err != nil || vlanNumberString == "" {
return settings, errors.New("unable to parse vlan")
}
Expand Down
53 changes: 53 additions & 0 deletions internal/app/machined/pkg/controllers/network/cmdline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package network_test

import (
"fmt"
"net"
"net/netip"
"sort"
Expand Down Expand Up @@ -432,6 +433,58 @@ func (suite *CmdlineSuite) TestParse() {
},
},
},
{
name: "vlan configuration with alternative link name vlan0008",
cmdline: "vlan=vlan0008:eth1",
expectedSettings: network.CmdlineNetworking{
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
Name: "eth1.8",
Logical: true,
Up: true,
Kind: netconfig.LinkKindVLAN,
Type: nethelpers.LinkEther,
ParentName: "eth1",
ConfigLayer: netconfig.ConfigCmdline,
VLAN: netconfig.VLANSpec{
VID: 8,
Protocol: nethelpers.VLANProtocol8021Q,
},
},
},
},
},
{
name: "vlan configuration with alternative link name vlan1",
cmdline: "vlan=vlan4095:eth1",
expectedSettings: network.CmdlineNetworking{
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
Name: "eth1.4095",
Logical: true,
Up: true,
Kind: netconfig.LinkKindVLAN,
Type: nethelpers.LinkEther,
ParentName: "eth1",
ConfigLayer: netconfig.ConfigCmdline,
VLAN: netconfig.VLANSpec{
VID: 4095,
Protocol: nethelpers.VLANProtocol8021Q,
},
},
},
},
},
{
name: "vlan configuration with invalid vlan ID 4096",
cmdline: "vlan=eth1.4096:eth1",
expectedError: fmt.Sprintf("invalid vlanID=%d, must be in the range 1..4095: %s", 4096, "eth1.4096:eth1"),
},
{
name: "vlan configuration with invalid vlan ID 0",
cmdline: "vlan=eth1.0:eth1",
expectedError: fmt.Sprintf("invalid vlanID=%d, must be in the range 1..4095: %s", 0, "eth1.0:eth1"),
},
{
name: "multiple ip configurations",
cmdline: "ip=172.20.0.2::172.20.0.1:255.255.255.0::eth1::::: ip=eth3:dhcp ip=:::::eth4:dhcp::::",
Expand Down

0 comments on commit f8155c4

Please sign in to comment.