]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: use dns_scope_ifindex() at more places
authorLennart Poettering <lennart@poettering.net>
Tue, 3 Sep 2024 08:49:42 +0000 (10:49 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 11 Sep 2024 19:35:58 +0000 (21:35 +0200)
And add a mirroring dns_scope_ifname()

src/resolve/resolved-dns-scope.c
src/resolve/resolved-dns-scope.h

index 5292b11405c8739f21614f27456d1d70c4d81108..58e08e8dc4c72c6d1590f31665f4144eba56e2a6 100644 (file)
@@ -392,7 +392,7 @@ static int dns_scope_socket(
                 assert(family != AF_UNSPEC);
                 assert(address);
 
-                ifindex = s->link ? s->link->ifindex : 0;
+                ifindex = dns_scope_ifindex(s);
 
                 switch (family) {
                 case AF_INET:
@@ -1450,6 +1450,15 @@ int dns_scope_ifindex(DnsScope *s) {
         return 0;
 }
 
+const char* dns_scope_ifname(DnsScope *s) {
+        assert(s);
+
+        if (s->link)
+                return s->link->ifname;
+
+        return NULL;
+}
+
 static int on_announcement_timeout(sd_event_source *s, usec_t usec, void *userdata) {
         DnsScope *scope = userdata;
 
@@ -1733,8 +1742,8 @@ int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret) {
                         ret,
                         SD_JSON_BUILD_PAIR_STRING("protocol", dns_protocol_to_string(scope->protocol)),
                         SD_JSON_BUILD_PAIR_CONDITION(scope->family != AF_UNSPEC, "family", SD_JSON_BUILD_INTEGER(scope->family)),
-                        SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifindex", SD_JSON_BUILD_INTEGER(scope->link ? scope->link->ifindex : 0)),
-                        SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifname", SD_JSON_BUILD_STRING(scope->link ? scope->link->ifname : NULL)),
+                        SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifindex", SD_JSON_BUILD_INTEGER(dns_scope_ifindex(scope))),
+                        SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifname", SD_JSON_BUILD_STRING(dns_scope_ifname(scope))),
                         SD_JSON_BUILD_PAIR_VARIANT("cache", cache));
 }
 
index 872bc2abe715c03ba64a848fc64a7733442f1730..aefddb9a80fc69be1a7c20e5027fe24046d20e27 100644 (file)
@@ -106,6 +106,7 @@ bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name);
 bool dns_scope_network_good(DnsScope *s);
 
 int dns_scope_ifindex(DnsScope *s);
+const char* dns_scope_ifname(DnsScope *s);
 
 int dns_scope_announce(DnsScope *scope, bool goodbye);