func()

in cmd/core_plugin/network/dhclient/dhclient_linux.go [239:293]


func (ds *dhclientService) setupEthernet(ctx context.Context, opts *service.Options, config *cfg.Sections) error {
	// If the dhclient command is configured, run it and return the error.
	if ok, err := runConfiguredCommand(ctx, config); ok {
		return err
	}

	partitions, err := newInterfacePartitions(opts.NICConfigs)
	if err != nil {
		return fmt.Errorf("error partitioning interfaces: %w", err)
	}

	// Release IPv6 leases.
	for _, nicConfig := range partitions.releaseIpv6 {
		if err := ds.runDhclient(ctx, nicConfig.Interface.Name(), ipv6, releaseLease); err != nil {
			return fmt.Errorf("failed to run dhclient: %w", err)
		}
	}

	// Setup IPV4.
	for _, nic := range partitions.obtainIpv4 {
		if err := ds.runDhclient(ctx, nic.Interface.Name(), ipv4, obtainLease); err != nil {
			return fmt.Errorf("failed to run dhclient: %w", err)
		}
	}

	// Setup IPV6.
	if len(partitions.obtainIpv6) != 0 {
		if err := ds.setupIPV6Interfaces(ctx, opts, partitions); err != nil {
			return fmt.Errorf("failed to setup IPv6 interfaces: %w", err)
		}
	}

	// Setup all nics routes.
	for _, nic := range opts.NICConfigs {
		galog.Debugf("Attempting to add any missing route for nic: %s", nic.Interface.Name())

		if nic.ExtraAddresses == nil {
			galog.V(2).Debugf("No extra addresses to add routes for: %s", nic.Interface.Name())
			continue
		}

		data, err := route.MissingRoutes(ctx, nic.Interface.Name(), nic.ExtraAddresses.MergedMap())
		if err != nil {
			return fmt.Errorf("failed to list missing routes: %w", err)
		}

		for _, addMe := range data {
			if err := route.Add(ctx, addMe); err != nil {
				return fmt.Errorf("failed to add route: %w", err)
			}
		}
	}

	return nil
}