teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0206-resolvectl-warn-if-the-global-mDNS-or-LLMNR-support-.patch

ac3a84
From 4b911f2d385feb8153dacaf923108fc6d00fa149 Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Fri, 4 Nov 2022 13:11:55 +0900
ac3a84
Subject: [PATCH] resolvectl: warn if the global mDNS or LLMNR support level is
ac3a84
 lower than the requested one
ac3a84
ac3a84
(cherry picked from commit c38a03df4af78721f45947ffa2013554d81954a4)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/resolve/resolvectl.c | 37 +++++++++++++++++++++++++++++++++++++
ac3a84
 1 file changed, 37 insertions(+)
ac3a84
ac3a84
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
ac3a84
index 2a7347ca27..c52773508f 100644
ac3a84
--- a/src/resolve/resolvectl.c
ac3a84
+++ b/src/resolve/resolvectl.c
ac3a84
@@ -32,6 +32,7 @@
ac3a84
 #include "pretty-print.h"
ac3a84
 #include "process-util.h"
ac3a84
 #include "resolvconf-compat.h"
ac3a84
+#include "resolve-util.h"
ac3a84
 #include "resolvectl.h"
ac3a84
 #include "resolved-def.h"
ac3a84
 #include "resolved-dns-packet.h"
ac3a84
@@ -2280,6 +2281,8 @@ static int verb_default_route(int argc, char **argv, void *userdata) {
ac3a84
 
ac3a84
 static int verb_llmnr(int argc, char **argv, void *userdata) {
ac3a84
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ac3a84
+        _cleanup_free_ char *global_llmnr_support_str = NULL;
ac3a84
+        ResolveSupport global_llmnr_support, llmnr_support;
ac3a84
         sd_bus *bus = ASSERT_PTR(userdata);
ac3a84
         int r;
ac3a84
 
ac3a84
@@ -2295,6 +2298,22 @@ static int verb_llmnr(int argc, char **argv, void *userdata) {
ac3a84
         if (argc < 3)
ac3a84
                 return status_ifindex(bus, arg_ifindex, NULL, STATUS_LLMNR, NULL);
ac3a84
 
ac3a84
+        llmnr_support = resolve_support_from_string(argv[2]);
ac3a84
+        if (llmnr_support < 0)
ac3a84
+                return log_error_errno(llmnr_support, "Invalid LLMNR setting: %s", argv[2]);
ac3a84
+
ac3a84
+        r = bus_get_property_string(bus, bus_resolve_mgr, "LLMNR", &error, &global_llmnr_support_str);
ac3a84
+        if (r < 0)
ac3a84
+                return log_error_errno(r, "Failed to get the global LLMNR support state: %s", bus_error_message(&error, r));
ac3a84
+
ac3a84
+        global_llmnr_support = resolve_support_from_string(global_llmnr_support_str);
ac3a84
+        if (global_llmnr_support < 0)
ac3a84
+                return log_error_errno(global_llmnr_support, "Received invalid global LLMNR setting: %s", global_llmnr_support_str);
ac3a84
+
ac3a84
+        if (global_llmnr_support < llmnr_support)
ac3a84
+                log_warning("Setting LLMNR support level \"%s\" for \"%s\", but the global support level is \"%s\".",
ac3a84
+                            argv[2], arg_ifname, global_llmnr_support_str);
ac3a84
+
ac3a84
         r = bus_call_method(bus, bus_resolve_mgr, "SetLinkLLMNR", &error, NULL, "is", arg_ifindex, argv[2]);
ac3a84
         if (r < 0 && sd_bus_error_has_name(&error, BUS_ERROR_LINK_BUSY)) {
ac3a84
                 sd_bus_error_free(&error);
ac3a84
@@ -2314,6 +2333,8 @@ static int verb_llmnr(int argc, char **argv, void *userdata) {
ac3a84
 
ac3a84
 static int verb_mdns(int argc, char **argv, void *userdata) {
ac3a84
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ac3a84
+        _cleanup_free_ char *global_mdns_support_str = NULL;
ac3a84
+        ResolveSupport global_mdns_support, mdns_support;
ac3a84
         sd_bus *bus = ASSERT_PTR(userdata);
ac3a84
         int r;
ac3a84
 
ac3a84
@@ -2329,6 +2350,22 @@ static int verb_mdns(int argc, char **argv, void *userdata) {
ac3a84
         if (argc < 3)
ac3a84
                 return status_ifindex(bus, arg_ifindex, NULL, STATUS_MDNS, NULL);
ac3a84
 
ac3a84
+        mdns_support = resolve_support_from_string(argv[2]);
ac3a84
+        if (mdns_support < 0)
ac3a84
+                return log_error_errno(mdns_support, "Invalid mDNS setting: %s", argv[2]);
ac3a84
+
ac3a84
+        r = bus_get_property_string(bus, bus_resolve_mgr, "MulticastDNS", &error, &global_mdns_support_str);
ac3a84
+        if (r < 0)
ac3a84
+                return log_error_errno(r, "Failed to get the global mDNS support state: %s", bus_error_message(&error, r));
ac3a84
+
ac3a84
+        global_mdns_support = resolve_support_from_string(global_mdns_support_str);
ac3a84
+        if (global_mdns_support < 0)
ac3a84
+                return log_error_errno(global_mdns_support, "Received invalid global mDNS setting: %s", global_mdns_support_str);
ac3a84
+
ac3a84
+        if (global_mdns_support < mdns_support)
ac3a84
+                log_warning("Setting mDNS support level \"%s\" for \"%s\", but the global support level is \"%s\".",
ac3a84
+                            argv[2], arg_ifname, global_mdns_support_str);
ac3a84
+
ac3a84
         r = bus_call_method(bus, bus_resolve_mgr, "SetLinkMulticastDNS", &error, NULL, "is", arg_ifindex, argv[2]);
ac3a84
         if (r < 0 && sd_bus_error_has_name(&error, BUS_ERROR_LINK_BUSY)) {
ac3a84
                 sd_bus_error_free(&error);