From 54e157d9565bf868079920a2b427f289df4be85a Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 27 Jan 2023 12:26:17 -0700 Subject: [PATCH] Fix netplan vlan file: Formatting was bad and caused netplan to fail. Signed-off-by: Jacob Weinstock --- actions/writefile/v1/main.go | 40 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/actions/writefile/v1/main.go b/actions/writefile/v1/main.go index 018c2a7..07e816a 100644 --- a/actions/writefile/v1/main.go +++ b/actions/writefile/v1/main.go @@ -418,7 +418,7 @@ func vlanEnabled(f string) (ifname, netplanTemplate string, err error) { ifname = determineNetIF() // want "eth0.X", where X is between 1 and 4096 // This interface will exist if Hook creates it. Hook will create it if "vlan_id" is set in /proc/cmdline. - exp := `^eth0.(409[0-6]|(40[0-8]|[1-3]\d\d|[1-9]\d|[1-9])\d|[1-9])$` + exp := `^eth([0-9]).(409[0-6]|(40[0-8]|[1-3]\d\d|[1-9]\d|[1-9])\d|[1-9])$` if match, err := regexp.MatchString(exp, ifname); err != nil || !match { return "", "", fmt.Errorf("failed to match interface name %s with regex %s: %w", ifname, exp, err) } @@ -431,19 +431,19 @@ func vlanEnabled(f string) (ifname, netplanTemplate string, err error) { macaddress: {{ .HWAddr }} set-name: mainif - vlans: - vlan{{ .VLANID }}: - id: {{ .VLANID }} - link: mainif - addresses: - - {{ ToString .IPAddr }} - nameservers: - addresses: [{{ ToStringSlice .Nameservers ", " }}] - {{- if .Gateway }} - routes: - - to: default - via: {{ ToString .Gateway }} - {{- end }} + vlans: + vlan{{ .VLANID }}: + id: {{ .VLANID }} + link: mainif + addresses: + - {{ ToString .IPAddr }} + nameservers: + addresses: [{{ ToStringSlice .Nameservers ", " }}] + {{- if .Gateway }} + routes: + - to: default + via: {{ ToString .Gateway }} + {{- end }} ` return ifname, netplanTemplate, nil @@ -544,11 +544,13 @@ func translate(d *dhcpv4.DHCPv4) Info { info.IPAddr = net.IPNet{IP: d.YourIPAddr, Mask: d.SubnetMask()} info.Gateway = d.GetOneOption(dhcpv4.OptionRouter) info.Nameservers = d.DNS() - o := dhcpv4.Options{} - o.FromBytes(d.GetOneOption(dhcpv4.OptionVendorSpecificInformation)) - s := o.Get(dhcpv4.GenericOptionCode(116)) - if vlan, err := strconv.Atoi(string(s)); err == nil { - info.VLANID = vlan + s, err := ioutil.ReadFile("/proc/cmdline") + if err != nil { + fmt.Println("failed to read /proc/cmdline while looking for vlan_id=: ", err) + return info + } + if vlanID, err := getVLANID(string(s)); err == nil { + info.VLANID = vlanID } return info -- 2.34.1