summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-packet.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-31 23:43:10 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-01 00:58:12 +0200
commitbdf10b5b4d9e7abdc08bdca4b073d021b0043d1f (patch)
tree4ed35b1bc26e5457e471aa829b868878a81d6a49 /src/resolve/resolved-dns-packet.c
parentafbc4f267b45480e46fbcd59e90e399bc3dc7510 (diff)
resolved: handle IDNA domains
Make sure we format UTF-8 labels as IDNA when writing them to DNS packets, and as native UTF-8 when writing them to mDNS or LLMNR packets. When comparing or processing labels always consider native UTF-8 and IDNA formats equivalent.
Diffstat (limited to 'src/resolve/resolved-dns-packet.c')
-rw-r--r--src/resolve/resolved-dns-packet.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index ba6fb3d787..ba056f1f44 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -390,6 +390,7 @@ int dns_packet_append_name(DnsPacket *p, const char *name, size_t *start) {
_cleanup_free_ char *s = NULL;
char label[DNS_LABEL_MAX];
size_t n;
+ int k;
n = PTR_TO_SIZE(hashmap_get(p->names, name));
if (n > 0) {
@@ -414,6 +415,17 @@ int dns_packet_append_name(DnsPacket *p, const char *name, size_t *start) {
if (r < 0)
goto fail;
+ if (p->protocol == DNS_PROTOCOL_DNS)
+ k = dns_label_apply_idna(label, r, label, sizeof(label));
+ else
+ k = dns_label_undo_idna(label, r, label, sizeof(label));
+ if (k < 0) {
+ r = k;
+ goto fail;
+ }
+ if (k > 0)
+ r = k;
+
r = dns_packet_append_label(p, label, r, &n);
if (r < 0)
goto fail;