]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: move sd-* api into libsystemd-network 30952/head
authorRonan Pigott <ronan@rjp.ie>
Wed, 26 Jun 2024 00:01:59 +0000 (17:01 -0700)
committerRonan Pigott <ronan@rjp.ie>
Mon, 21 Oct 2024 16:10:20 +0000 (09:10 -0700)
This duplicates the svc param constants for the benefit of the
resolved-core library.

src/libsystemd-network/dns-resolver-internal.h [moved from src/shared/dns-resolver-internal.h with 100% similarity]
src/libsystemd-network/meson.build
src/libsystemd-network/sd-dns-resolver.c [moved from src/shared/sd-dns-resolver.c with 100% similarity]
src/libsystemd-network/sd-dns-resolver.h [moved from src/systemd/sd-dns-resolver.h with 100% similarity]
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-packet.h
src/resolve/resolved-dns-rr.c
src/shared/meson.build
src/systemd/meson.build

index 718495cd8eb5558a7d263e34844aad1c532ccab3..262ce9c4effa100aead588cab89508265bab32c8 100644 (file)
@@ -23,6 +23,7 @@ sources = files(
         'sd-dhcp-server.c',
         'sd-dhcp6-client.c',
         'sd-dhcp6-lease.c',
+        'sd-dns-resolver.c',
         'sd-ipv4acd.c',
         'sd-ipv4ll.c',
         'sd-lldp-rx.c',
index 1ab09f26d6e304a1f114ba3538fb738609acfad0..f9991d86aba0284f142a8d18b895e45a224f271e 100644 (file)
@@ -4,8 +4,6 @@
 #  include <gcrypt.h>
 #endif
 
-#include "dns-resolver-internal.h"
-
 #include "alloc-util.h"
 #include "dns-domain.h"
 #include "escape.h"
@@ -2883,6 +2881,27 @@ size_t dns_packet_size_unfragmented(DnsPacket *p) {
         return LESS_BY(p->fragsize, udp_header_size(p->family));
 }
 
+static const char* const dns_svc_param_key_table[_DNS_SVC_PARAM_KEY_MAX_DEFINED] = {
+        [DNS_SVC_PARAM_KEY_MANDATORY]       = "mandatory",
+        [DNS_SVC_PARAM_KEY_ALPN]            = "alpn",
+        [DNS_SVC_PARAM_KEY_NO_DEFAULT_ALPN] = "no-default-alpn",
+        [DNS_SVC_PARAM_KEY_PORT]            = "port",
+        [DNS_SVC_PARAM_KEY_IPV4HINT]        = "ipv4hint",
+        [DNS_SVC_PARAM_KEY_ECH]             = "ech",
+        [DNS_SVC_PARAM_KEY_IPV6HINT]        = "ipv6hint",
+        [DNS_SVC_PARAM_KEY_DOHPATH]         = "dohpath",
+        [DNS_SVC_PARAM_KEY_OHTTP]           = "ohttp",
+};
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(dns_svc_param_key, int);
+
+const char* format_dns_svc_param_key(uint16_t i, char buf[static DECIMAL_STR_MAX(uint16_t)+3]) {
+        const char *p = dns_svc_param_key_to_string(i);
+        if (p)
+                return p;
+
+        return snprintf_ok(buf, DECIMAL_STR_MAX(uint16_t)+3, "key%i", i);
+}
+
 static const char* const dns_rcode_table[_DNS_RCODE_MAX_DEFINED] = {
         [DNS_RCODE_SUCCESS]   = "SUCCESS",
         [DNS_RCODE_FORMERR]   = "FORMERR",
index ddee259b1f94e0b70ce72fa8e94eb4d054e15753..0b22e557cf65a80e9c0e3416a6a578531821b556 100644 (file)
@@ -370,6 +370,25 @@ DnsProtocol dns_protocol_from_string(const char *s) _pure_;
 
 extern const struct hash_ops dns_packet_hash_ops;
 
+/* https://www.iana.org/assignments/dns-svcb/dns-svcb.xhtml#dns-svcparamkeys */
+enum {
+        DNS_SVC_PARAM_KEY_MANDATORY       = 0, /* RFC 9460 § 8 */
+        DNS_SVC_PARAM_KEY_ALPN            = 1, /* RFC 9460 § 7.1 */
+        DNS_SVC_PARAM_KEY_NO_DEFAULT_ALPN = 2, /* RFC 9460 § 7.1 */
+        DNS_SVC_PARAM_KEY_PORT            = 3, /* RFC 9460 § 7.2 */
+        DNS_SVC_PARAM_KEY_IPV4HINT        = 4, /* RFC 9460 § 7.3 */
+        DNS_SVC_PARAM_KEY_ECH             = 5, /* RFC 9460 */
+        DNS_SVC_PARAM_KEY_IPV6HINT        = 6, /* RFC 9460 § 7.3  */
+        DNS_SVC_PARAM_KEY_DOHPATH         = 7, /* RFC 9461 */
+        DNS_SVC_PARAM_KEY_OHTTP           = 8,
+        _DNS_SVC_PARAM_KEY_MAX_DEFINED,
+        DNS_SVC_PARAM_KEY_INVALID         = 65535 /* RFC 9460 */
+};
+
+const char* dns_svc_param_key_to_string(int i) _const_;
+const char* format_dns_svc_param_key(uint16_t i, char buf[static DECIMAL_STR_MAX(uint16_t)+3]);
+#define FORMAT_DNS_SVC_PARAM_KEY(i) format_dns_svc_param_key(i, (char [DECIMAL_STR_MAX(uint16_t)+3]) {})
+
 static inline uint64_t SD_RESOLVED_FLAGS_MAKE(
                 DnsProtocol protocol,
                 int family,
index ed525883f20a09d376f093e38e9267ad74f6f638..6a4bd6aecdd6a2c26296546689f3eb4ef06b4a98 100644 (file)
@@ -2,8 +2,6 @@
 
 #include <math.h>
 
-#include "dns-resolver-internal.h"
-
 #include "alloc-util.h"
 #include "dns-domain.h"
 #include "dns-type.h"
index 548b26d8c39fa8cac5e8cf24621bc69858c1078f..8fc39429e5e96f2882270fc2d2c7ee663c8e622d 100644 (file)
@@ -154,7 +154,6 @@ shared_sources = files(
         'resize-fs.c',
         'resolve-util.c',
         'rm-rf.c',
-        'sd-dns-resolver.c',
         'securebits-util.c',
         'selinux-util.c',
         'serialize.c',
index edcbc873e9a00a461b642cfd1a171e0d5c14ab99..06ba4cbc075c58a5ca8425dfce40e86272519133 100644 (file)
@@ -35,7 +35,6 @@ _not_installed_headers = [
         'sd-dhcp6-lease.h',
         'sd-dhcp6-option.h',
         'sd-dhcp6-protocol.h',
-        'sd-dns-resolver.h',
         'sd-ipv4acd.h',
         'sd-ipv4ll.h',
         'sd-lldp-rx.h',