diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/resolve/resolved-dns-packet.c | 30 | ||||
-rw-r--r-- | src/resolve/resolved-dns-rr.c | 27 | ||||
-rw-r--r-- | src/resolve/resolved-dns-rr.h | 6 |
3 files changed, 58 insertions, 5 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 217bdafcb8..3d64c27ceb 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -21,6 +21,7 @@ #include "utf8.h" #include "util.h" +#include "strv.h" #include "resolved-dns-domain.h" #include "resolved-dns-packet.h" @@ -512,6 +513,18 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star r = dns_packet_append_string(p, rr->hinfo.os, NULL); break; + case DNS_TYPE_TXT: { + char **s; + + STRV_FOREACH(s, rr->txt.strings) { + r = dns_packet_append_string(p, *s, NULL); + if (r < 0) + goto fail; + } + + break; + } + case DNS_TYPE_A: r = dns_packet_append_blob(p, &rr->a.in_addr, sizeof(struct in_addr), NULL); break; @@ -556,7 +569,6 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star r = dns_packet_append_name(p, rr->mx.exchange, NULL); break; - case DNS_TYPE_TXT: case DNS_TYPE_SRV: case DNS_TYPE_DNAME: case DNS_TYPE_SSHFP: @@ -921,6 +933,21 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) { r = dns_packet_read_string(p, &rr->hinfo.os, NULL); break; + case DNS_TYPE_TXT: { + char *s; + + while (p->rindex < p->size) { + r = dns_packet_read_string(p, &s, NULL); + if (r < 0) + goto fail; + + r = strv_consume(&rr->txt.strings, s); + if (r < 0) + goto fail; + }; + break; + } + case DNS_TYPE_A: r = dns_packet_read_blob(p, &rr->a.in_addr, sizeof(struct in_addr), NULL); break; @@ -965,7 +992,6 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) { r = dns_packet_read_name(p, &rr->mx.exchange, NULL); break; - case DNS_TYPE_TXT: case DNS_TYPE_SRV: case DNS_TYPE_DNAME: case DNS_TYPE_SSHFP: diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index 2e13b9c51a..9131b4b349 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -19,6 +19,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "strv.h" + #include "resolved-dns-domain.h" #include "resolved-dns-rr.h" @@ -234,6 +236,8 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) { else if (rr->key->type == DNS_TYPE_HINFO) { free(rr->hinfo.cpu); free(rr->hinfo.os); + } else if (rr->key->type == DNS_TYPE_TXT) { + strv_free(rr->txt.strings); } else if (rr->key->type == DNS_TYPE_SOA) { free(rr->soa.mname); free(rr->soa.rname); @@ -305,6 +309,15 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor return strcaseeq(a->hinfo.cpu, b->hinfo.cpu) && strcaseeq(a->hinfo.os, b->hinfo.os); + case DNS_TYPE_TXT: { + int i; + + for (i = 0; a->txt.strings[i] || b->txt.strings[i]; i++) + if (!streq_ptr(a->txt.strings[i], b->txt.strings[i])) + return false; + return true; + } + case DNS_TYPE_A: return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0; @@ -364,6 +377,20 @@ int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) { return -ENOMEM; break; + case DNS_TYPE_TXT: { + _cleanup_free_ char *t; + + t = strv_join_quoted(rr->txt.strings); + if (!t) + return -ENOMEM; + + s = strjoin(k, " ", t, NULL); + if (!s) + return -ENOMEM; + + break; + } + case DNS_TYPE_A: { _cleanup_free_ char *x = NULL; diff --git a/src/resolve/resolved-dns-rr.h b/src/resolve/resolved-dns-rr.h index 359d662a60..92ffeab203 100644 --- a/src/resolve/resolved-dns-rr.h +++ b/src/resolve/resolved-dns-rr.h @@ -98,9 +98,9 @@ struct DnsResourceRecord { char *os; } hinfo; - /* struct { */ - /* char **list; */ - /* } txt; */ + struct { + char **strings; + } txt; struct { struct in_addr in_addr; |