udev: net_setup - allow matching on OriginalName=

This has been requested repeatedly, so let's give it a go. We explicitly do not allow matching
on names that have already been changed (from a previous udev run, or otherwise), and matching
on unpredictable names (ethX) is discouraged (but not currently disallowed).

We also currently allow:

[Match]
Name=veth0

[Link]
Name=my-name0
SomeOtherSetting=true

Which means that the link file will be applied the first time it is invoked, but
not on subsequent invocations, which may be surprising.
This commit is contained in:
Tom Gundersen
2014-12-04 18:53:47 +01:00
parent 03e8fdb346
commit 7eb08da4b3
8 changed files with 55 additions and 23 deletions
+20 -13
View File
@@ -96,40 +96,47 @@ bool net_match_config(const struct ether_addr *match_mac,
const char *dev_parent_driver,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
const char *dev_name,
bool ignore_name_match) {
if (match_host && !condition_test(match_host))
return 0;
return false;
if (match_virt && !condition_test(match_virt))
return 0;
return false;
if (match_kernel && !condition_test(match_kernel))
return 0;
return false;
if (match_arch && !condition_test(match_arch))
return 0;
return false;
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
return 0;
return false;
if (match_path && (!dev_path || fnmatch(match_path, dev_path, 0)))
return 0;
return false;
if (match_driver) {
if (dev_parent_driver && !streq(match_driver, dev_parent_driver))
return 0;
return false;
else if (!streq_ptr(match_driver, dev_driver))
return 0;
return false;
}
if (match_type && !streq_ptr(match_type, dev_type))
return 0;
return false;
if (match_name && (!dev_name || fnmatch(match_name, dev_name, 0)))
return 0;
if (match_name) {
if (!dev_name || fnmatch(match_name, dev_name, 0))
return false;
else if (ignore_name_match) {
log_warning("ifname (%s) matched config, but is ignored as it is not the original name", dev_name);
return false;
}
}
return 1;
return true;
}
int config_parse_net_condition(const char *unit,
+2 -1
View File
@@ -42,7 +42,8 @@ bool net_match_config(const struct ether_addr *match_mac,
const char *dev_parent_driver,
const char *dev_driver,
const char *dev_type,
const char *dev_name);
const char *dev_name,
bool ignore_name_match);
int config_parse_net_condition(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,