in cmd/core_plugin/network/networkd/networkd_linux.go [207:254]
func (sn *Module) Setup(ctx context.Context, opts *service.Options) error {
galog.Info("Setting up systemd-networkd interfaces.")
var keepVlanConfigs []string
// Write the config files.
for index, nic := range opts.NICConfigs {
filePath := sn.networkFile(nic.Interface.Name())
if err := sn.writeEthernetConfig(nic, filePath, true, index == 0); err != nil {
return fmt.Errorf("error writing network configs: %v", err)
}
// Make sure to rollback previously supported and now deprecated .network
// and .netdev config files.
galog.Debugf("Attempting to rollback deprecated .network file for: %s.", nic.Interface.Name())
if _, err := rollbackConfiguration(sn.deprecatedNetworkFile(nic.Interface.Name())); err != nil {
galog.Infof("Failed to rollback .network file: %v.", err)
}
// Setup the interface's VLANs.
for _, vic := range nic.VlanInterfaces {
if err := sn.writeVlanConfig(vic); err != nil {
return fmt.Errorf("error writing vlan configs: %w", err)
}
keepVlanConfigs = append(keepVlanConfigs, vic.InterfaceName())
}
}
// Cleanup any vlan interfaces that are no longer present.
vlanCleanedup, err := sn.cleanupVlanConfigs(keepVlanConfigs)
if err != nil {
return fmt.Errorf("error cleaning up vlan configs: %w", err)
}
// If we've not changed any configuration we shouldn't have to reload
// systemd-networkd.
if len(opts.NICConfigs) == 0 && !vlanCleanedup {
return nil
}
// Attempt to reload systemd-networkd configurations.
if err := sn.Reload(ctx); err != nil {
return fmt.Errorf("error reloading systemd-networkd daemon: %w", err)
}
return nil
}