chiark / gitweb /
resolved: properly process SRV records
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 16:23:00 +0000 (18:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 16:23:34 +0000 (18:23 +0200)
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-rr.c
src/resolve/resolved-dns-rr.h

index 05c62a4..024ab0d 100644 (file)
@@ -499,6 +499,22 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star
 
         switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
 
+        case DNS_TYPE_SRV:
+                r = dns_packet_append_uint16(p, rr->srv.priority, NULL);
+                if (r < 0)
+                        goto fail;
+
+                r = dns_packet_append_uint16(p, rr->srv.weight, NULL);
+                if (r < 0)
+                        goto fail;
+
+                r = dns_packet_append_uint16(p, rr->srv.port, NULL);
+                if (r < 0)
+                        goto fail;
+
+                r = dns_packet_append_name(p, rr->srv.name, NULL);
+                break;
+
         case DNS_TYPE_PTR:
         case DNS_TYPE_NS:
         case DNS_TYPE_CNAME:
@@ -600,7 +616,6 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star
                 r = dns_packet_append_uint16(p, rr->loc.altitude, NULL);
                 break;
 
-        case DNS_TYPE_SRV:
         case DNS_TYPE_SSHFP:
         case _DNS_TYPE_INVALID: /* unparseable */
         default:
@@ -951,6 +966,19 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
 
         switch (rr->key->type) {
 
+        case DNS_TYPE_SRV:
+                r = dns_packet_read_uint16(p, &rr->srv.priority, NULL);
+                if (r < 0)
+                        goto fail;
+                r = dns_packet_read_uint16(p, &rr->srv.weight, NULL);
+                if (r < 0)
+                        goto fail;
+                r = dns_packet_read_uint16(p, &rr->srv.port, NULL);
+                if (r < 0)
+                        goto fail;
+                r = dns_packet_read_name(p, &rr->srv.name, NULL);
+                break;
+
         case DNS_TYPE_PTR:
         case DNS_TYPE_NS:
         case DNS_TYPE_CNAME:
@@ -1071,7 +1099,6 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
                 }
         }
 
-        case DNS_TYPE_SRV:
         case DNS_TYPE_SSHFP:
         default:
                 r = dns_packet_read(p, rdlength, &d, NULL);
index d282244..9ef3135 100644 (file)
@@ -234,31 +234,42 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
 
         if (rr->key) {
                 switch(rr->key->type) {
+
+                case DNS_TYPE_SRV:
+                        free(rr->srv.name);
+                        break;
+
                 case DNS_TYPE_PTR:
                 case DNS_TYPE_NS:
                 case DNS_TYPE_CNAME:
                 case DNS_TYPE_DNAME:
                         free(rr->ptr.name);
                         break;
+
                 case DNS_TYPE_HINFO:
                         free(rr->hinfo.cpu);
                         free(rr->hinfo.os);
                         break;
-                case DNS_TYPE_SPF:
+
                 case DNS_TYPE_TXT:
+                case DNS_TYPE_SPF:
                         strv_free(rr->txt.strings);
                         break;
+
                 case DNS_TYPE_SOA:
                         free(rr->soa.mname);
                         free(rr->soa.rname);
                         break;
+
                 case DNS_TYPE_MX:
                         free(rr->mx.exchange);
                         break;
+
                 case DNS_TYPE_LOC:
                 case DNS_TYPE_A:
                 case DNS_TYPE_AAAA:
                         break;
+
                 default:
                         free(rr->generic.data);
                 }
@@ -317,6 +328,15 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
 
         switch (a->key->type) {
 
+        case DNS_TYPE_SRV:
+                r = dns_name_equal(a->srv.name, b->srv.name);
+                if (r <= 0)
+                        return r;
+
+                return a->srv.priority == b->srv.priority &&
+                       a->srv.weight == b->srv.weight &&
+                       a->srv.port == b->srv.port;
+
         case DNS_TYPE_PTR:
         case DNS_TYPE_NS:
         case DNS_TYPE_CNAME:
@@ -356,6 +376,7 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
                        a->soa.retry   == b->soa.retry &&
                        a->soa.expire  == b->soa.expire &&
                        a->soa.minimum == b->soa.minimum;
+
         case DNS_TYPE_MX:
                 if (a->mx.priority != b->mx.priority)
                         return 0;
@@ -423,6 +444,17 @@ int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
 
         switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
 
+        case DNS_TYPE_SRV:
+                r = asprintf(&s, "%s %u %u %u %s",
+                             k,
+                             rr->srv.priority,
+                             rr->srv.weight,
+                             rr->srv.port,
+                             strna(rr->srv.name));
+                if (r < 0)
+                        return -ENOMEM;
+                break;
+
         case DNS_TYPE_PTR:
         case DNS_TYPE_NS:
         case DNS_TYPE_CNAME:
index 47885fc..a001433 100644 (file)
@@ -86,12 +86,12 @@ struct DnsResourceRecord {
                         uint16_t size;
                 } generic;
 
-                /* struct { */
-                /*         uint16_t priority; */
-                /*         uint16_t weight; */
-                /*         uint16_t port; */
-                /*         char *name; */
-                /* } srv; */
+                struct {
+                        uint16_t priority;
+                        uint16_t weight;
+                        uint16_t port;
+                        char *name;
+                } srv;
 
                 struct {
                         char *name;