func()

in google_guest_agent/network/manager/network_manager_linux.go [227:272]


func (n *networkManager) writeVLANConfigs(nics *Interfaces) error {
	for _, curr := range nics.VlanInterfaces {
		iface := n.vlanInterfaceName(curr.ParentInterfaceID, curr.Vlan)
		cfgFile := n.networkManagerConfigFilePath(iface)
		connID := fmt.Sprintf("google-guest-agent-%s", iface)

		nmCfg := nmConfig{
			GuestAgent: guestAgentSection{
				ManagedByGuestAgent: true,
			},
			Connection: nmConnectionSection{
				InterfaceName: iface,
				ID:            connID,
				ConnType:      "vlan",
			},
			Vlan: &nmVlan{
				// 1 is NM_VLAN_FLAG_REORDER_HEADERS.
				Flags:  1,
				ID:     curr.Vlan,
				Parent: curr.ParentInterfaceID,
			},
			Ipv4: nmIPv4Section{
				Method: "auto",
			},
			Ipv6: nmIPv6Section{
				Method: "auto",
				MTU:    curr.MTU,
			},
			Ethernet: &nmEthernet{
				OverrideMacAddress: curr.Mac,
				MTU:                curr.MTU,
			},
		}

		if err := writeIniFile(cfgFile, &nmCfg); err != nil {
			return fmt.Errorf("error writing vlan config for %q: %v", iface, err)
		}

		// If the permission is not properly set nmcli will fail to load the file correctly.
		if err := os.Chmod(cfgFile, nmConfigFileMode); err != nil {
			return fmt.Errorf("error updating permissions for %s: %w", cfgFile, err)
		}
	}

	return nil
}