X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd-network%2Fnetwork-internal.c;h=b8e4e21716f596fa43116560ca7ccb5588c4c89f;hp=b90fd1ccc8f656438c30c4480431eb7813cfb53a;hb=2404701e679904979751816930101511d8ec5d49;hpb=7eb08da4b388b920c8a894b1500c9cc7dc1f31ef diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index b90fd1ccc..b8e4e2171 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "strv.h" #include "siphash24.h" @@ -83,10 +82,10 @@ int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8 } bool net_match_config(const struct ether_addr *match_mac, - const char *match_path, - const char *match_driver, - const char *match_type, - const char *match_name, + char * const *match_paths, + char * const *match_drivers, + char * const *match_types, + char * const *match_names, Condition *match_host, Condition *match_virt, Condition *match_kernel, @@ -96,8 +95,7 @@ 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, - bool ignore_name_match) { + const char *dev_name) { if (match_host && !condition_test(match_host)) return false; @@ -114,27 +112,21 @@ bool net_match_config(const struct ether_addr *match_mac, if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN))) return false; - if (match_path && (!dev_path || fnmatch(match_path, dev_path, 0))) + if (!strv_isempty(match_paths) && + (!dev_path || !strv_fnmatch(match_paths, dev_path, 0))) return false; - if (match_driver) { - if (dev_parent_driver && !streq(match_driver, dev_parent_driver)) - return false; - else if (!streq_ptr(match_driver, dev_driver)) - return false; - } + if (!strv_isempty(match_drivers) && + (!dev_driver || !strv_fnmatch(match_drivers, dev_driver, 0))) + return false; - if (match_type && !streq_ptr(match_type, dev_type)) + if (!strv_isempty(match_types) && + (!dev_type || !strv_fnmatch_or_empty(match_types, dev_type, 0))) return false; - 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; - } - } + if (!strv_isempty(match_names) && + (!dev_name || !strv_fnmatch_or_empty(match_names, dev_name, 0))) + return false; return true; } @@ -219,6 +211,49 @@ int config_parse_ifname(const char *unit, return 0; } +int config_parse_ifnames(const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + char ***sv = data; + const char *word, *state; + size_t l; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + FOREACH_WORD(word, l, rvalue, state) { + char *n; + + n = strndup(word, l); + if (!n) + return log_oom(); + + if (!ascii_is_valid(n) || strlen(n) >= IFNAMSIZ) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue); + free(n); + return 0; + } + + r = strv_consume(sv, n); + if (r < 0) + return log_oom(); + } + + return 0; +} + int config_parse_ifalias(const char *unit, const char *filename, unsigned line, @@ -231,7 +266,7 @@ int config_parse_ifalias(const char *unit, void *userdata) { char **s = data; - char *n; + _cleanup_free_ char *n = NULL; assert(filename); assert(lvalue); @@ -245,17 +280,15 @@ int config_parse_ifalias(const char *unit, if (!ascii_is_valid(n) || strlen(n) >= IFALIASZ) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue); - free(n); return 0; } free(*s); - if (*n) + if (*n) { *s = n; - else { - free(n); + n = NULL; + } else *s = NULL; - } return 0; } @@ -399,10 +432,12 @@ void serialize_dhcp_routes(FILE *f, const char *key, struct sd_dhcp_route *route fprintf(f, "%s=", key); - for (i = 0; i < size; i++) - fprintf(f, "%s/%" PRIu8 ",%s%s", inet_ntoa(routes[i].dst_addr), - routes[i].dst_prefixlen, inet_ntoa(routes[i].gw_addr), + for (i = 0; i < size; i++) { + fprintf(f, "%s/%" PRIu8, inet_ntoa(routes[i].dst_addr), + routes[i].dst_prefixlen); + fprintf(f, ",%s%s", inet_ntoa(routes[i].gw_addr), (i < (size - 1)) ? " ": ""); + } fputs("\n", f); }