From: Mike Crowe Date: Thu, 24 Jun 2021 14:25:58 +0000 (+0100) Subject: resolvectl: Only strip ifname suffixes when being resolvconf X-Git-Tag: v247.8~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d18f706a3816464053003b706bb6b2c27de12d1;p=thirdparty%2Fsystemd.git resolvectl: Only strip ifname suffixes when being resolvconf Only treat interface names containing dots specially when resolvectl is pretending to be resolvconf to fix https://github.com/systemd/systemd/issues/20014 . Move the special suffix-stripping behaviour of ifname_mangle out to the new ifname_resolvconf_mangle to be called from resolvconf only. (cherry picked from commit 7875170f01991a1d28cfe284cc7075630cd69055) (cherry picked from commit 6ec5680beaa8df4b4b87e9aa614d29561c0e98fe) --- diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c index 5bc936faa70..8dc559801dc 100644 --- a/src/resolve/resolvconf-compat.c +++ b/src/resolve/resolvconf-compat.c @@ -212,7 +212,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Expected interface name as argument."); - r = ifname_mangle(argv[optind]); + r = ifname_resolvconf_mangle(argv[optind]); if (r <= 0) return r; diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index b4793357691..3a805245de6 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -100,18 +100,11 @@ static int interface_info_compare(const InterfaceInfo *a, const InterfaceInfo *b int ifname_mangle(const char *s) { _cleanup_free_ char *iface = NULL; - const char *dot; int ifi; assert(s); - dot = strchr(s, '.'); - if (dot) { - log_debug("Ignoring protocol specifier '%s'.", dot + 1); - iface = strndup(s, dot - s); - - } else - iface = strdup(s); + iface = strdup(s); if (!iface) return log_oom(); @@ -134,6 +127,24 @@ int ifname_mangle(const char *s) { return 1; } +int ifname_resolvconf_mangle(const char *s) { + const char *dot; + + assert(s); + + dot = strchr(s, '.'); + if (dot) { + _cleanup_free_ char *iface = NULL; + + log_debug("Ignoring protocol specifier '%s'.", dot + 1); + iface = strndup(s, dot - s); + if (!iface) + return log_oom(); + return ifname_mangle(iface); + } else + return ifname_mangle(s); +} + static void print_source(uint64_t flags, usec_t rtt) { char rtt_str[FORMAT_TIMESTAMP_MAX]; diff --git a/src/resolve/resolvectl.h b/src/resolve/resolvectl.h index 830c81d6923..3d55bf78da1 100644 --- a/src/resolve/resolvectl.h +++ b/src/resolve/resolvectl.h @@ -27,3 +27,4 @@ extern char **arg_set_domain; extern bool arg_ifindex_permissive; int ifname_mangle(const char *s); +int ifname_resolvconf_mangle(const char *s);