in google_guest_agent/network/manager/wicked_linux.go [119:171]
func (n *wicked) SetupVlanInterface(ctx context.Context, cfg *cfg.Sections, nics *Interfaces) error {
var keepMe []string
// Make sure the dhclient route priority is in a different range of ethernet nics.
priority := 20200
for _, curr := range nics.VlanInterfaces {
iface := fmt.Sprintf("gcp.%s.%d", curr.ParentInterfaceID, curr.Vlan)
configLines := []string{
googleComment,
"BOOTPROTO=dhcp", // NOTE: 'dhcp' is the dhcp4+dhcp6 option.
"VLAN=yes",
"ETHTOOL_OPTIONS=reorder_hdr off",
fmt.Sprintf("DEVICE=%s", iface),
fmt.Sprintf("MTU=%d", curr.MTU),
fmt.Sprintf("LLADDR=%s", curr.Mac),
fmt.Sprintf("ETHERDEVICE=%s", curr.ParentInterfaceID),
fmt.Sprintf("VLAN_ID=%d", curr.Vlan),
fmt.Sprintf("DHCLIENT_ROUTE_PRIORITY=%d", priority),
}
ifcfg, err := os.Create(n.ifcfgFilePath(iface))
if err != nil {
return fmt.Errorf("failed to create vlan's ifcfg file: %+v", err)
}
content := strings.Join(configLines, "\n")
writeLen, err := ifcfg.WriteString(content)
if err != nil {
return fmt.Errorf("error writing vlan's icfg file for %s: %v", iface, err)
}
contentLen := len(content)
if writeLen != contentLen {
return fmt.Errorf("error writing vlan's ifcfg file, wrote %d bytes, config content size is %d bytes",
writeLen, contentLen)
}
if err = run.Quiet(ctx, n.wickedCommand, "ifup", iface); err != nil {
return fmt.Errorf("error enabling vlan's interfaces: %v", err)
}
priority += 100
keepMe = append(keepMe, iface)
}
if err := n.cleanupVlanInterfaces(ctx, keepMe); err != nil {
return fmt.Errorf("failed to cleanup vlan interfaces: %+v", err)
}
return nil
}