in google_guest_agent/network/manager/dhclient_linux.go [407:454]
func partitionInterfaces(ctx context.Context, interfaces, ipv6Interfaces []string) ([]string, []string, []string, error) {
var obtainIpv4Interfaces []string
var obtainIpv6Interfaces []string
var releaseIpv6Interfaces []string
for i, iface := range interfaces {
if !shouldManageInterface(i == 0) {
// Do not setup anything for this interface to avoid duplicate processes.
logger.Debugf("ManagePrimaryNIC is disabled, skipping dhclient launch for %s", iface)
continue
}
if isInvalid(iface) {
continue
}
// On 18.04 we fallback to dhclient as networkctl is very old and has not reload support for example.
// Default netplan config will take care of it, do not launch dhclient for primary NIC on 18.04.
if (i == 0) && isUbuntu1804() {
logger.Debugf("ManagePrimaryNIC is enabled, but skipping primary nic as its managed by default OS config")
continue
}
// Check for IPv4 interfaces for which to obtain a lease.
processExists, err := dhclientProcessExists(ctx, iface, ipv4)
if err != nil {
return nil, nil, nil, err
}
if !processExists {
obtainIpv4Interfaces = append(obtainIpv4Interfaces, iface)
}
// Check for IPv6 interfaces for which to obtain a lease.
processExists, err = dhclientProcessExists(ctx, iface, ipv6)
if err != nil {
return nil, nil, nil, err
}
if slices.Contains(ipv6Interfaces, iface) && !processExists {
// Obtain a lease and spin up the DHClient process.
obtainIpv6Interfaces = append(obtainIpv6Interfaces, iface)
} else if !slices.Contains(ipv6Interfaces, iface) && processExists {
// Release the lease since the DHClient IPv6 process is running,
// but the interface is no longer IPv6.
releaseIpv6Interfaces = append(releaseIpv6Interfaces, iface)
}
}
return obtainIpv4Interfaces, obtainIpv6Interfaces, releaseIpv6Interfaces, nil
}