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: v249-rc2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7875170f01991a1d28cfe284cc7075630cd69055;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. --- diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c index b3f1e12fa61..93ded6d5643 100644 --- a/src/resolve/resolvconf-compat.c +++ b/src/resolve/resolvconf-compat.c @@ -211,7 +211,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 23f4ff1077b..7d13ed39050 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -104,18 +104,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(); @@ -138,6 +131,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 468a87957dd..1d0f1473483 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);