diff options
author | Ronan Pigott <ronan@rjp.ie> | 2024-06-26 02:01:59 +0200 |
---|---|---|
committer | Ronan Pigott <ronan@rjp.ie> | 2024-10-21 18:10:20 +0200 |
commit | ee2108dcd5f62593a3081b57cc92b3535d8096fa (patch) | |
tree | 7c3895f203a88edb8ff39387194ae339babc5928 /src/resolve | |
parent | ndisc: implement ndisc_option_build_encrypted_dns (diff) | |
download | systemd-ee2108dcd5f62593a3081b57cc92b3535d8096fa.tar.xz systemd-ee2108dcd5f62593a3081b57cc92b3535d8096fa.zip |
resolve: move sd-* api into libsystemd-network
This duplicates the svc param constants for the benefit of the
resolved-core library.
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-packet.c | 23 | ||||
-rw-r--r-- | src/resolve/resolved-dns-packet.h | 19 | ||||
-rw-r--r-- | src/resolve/resolved-dns-rr.c | 2 |
3 files changed, 40 insertions, 4 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 1ab09f26d6..f9991d86ab 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -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", diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index ddee259b1f..0b22e557cf 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -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, diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index ed525883f2..6a4bd6aecd 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -2,8 +2,6 @@ #include <math.h> -#include "dns-resolver-internal.h" - #include "alloc-util.h" #include "dns-domain.h" #include "dns-type.h" |