- r = rtnl_set_properties(ctx->rtnl, ifindex, config->name, config->mac, config->mtu);
+ if (ctx->enable_name_policy && config->name_policy) {
+ NamePolicy *policy;
+
+ for (policy = config->name_policy; !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
+ switch (*policy) {
+ case NAMEPOLICY_ONBOARD:
+ new_name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
+ break;
+ case NAMEPOLICY_SLOT:
+ new_name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
+ break;
+ case NAMEPOLICY_PATH:
+ new_name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
+ break;
+ case NAMEPOLICY_MAC:
+ new_name = udev_device_get_property_value(device, "ID_NET_NAME_MAC");
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (new_name)
+ *name = new_name; /* a name was set by a policy */
+ else if (config->name)
+ *name = config->name; /* a name was set manually in the config */
+ else
+ *name = NULL;
+
+ switch (config->mac_policy) {
+ case MACPOLICY_PERSISTENT:
+ if (!mac_is_permanent(device)) {
+ r = get_mac(device, false, &generated_mac);
+ if (r < 0)
+ return r;
+ mac = &generated_mac;
+ }
+ break;
+ case MACPOLICY_RANDOM:
+ if (!mac_is_random(device)) {
+ r = get_mac(device, true, &generated_mac);
+ if (r < 0)
+ return r;
+ mac = &generated_mac;
+ }
+ break;
+ default:
+ mac = config->mac;
+ }
+
+ r = rtnl_set_link_properties(ctx->rtnl, ifindex, mac, config->mtu);