1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 06:52:22 +03:00

resolved: properly process SRV records

This commit is contained in:
Lennart Poettering 2014-07-31 18:23:00 +02:00
parent c0eb11cfd0
commit 9c92ce6d67
3 changed files with 68 additions and 9 deletions

View 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) { 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_PTR:
case DNS_TYPE_NS: case DNS_TYPE_NS:
case DNS_TYPE_CNAME: 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); r = dns_packet_append_uint16(p, rr->loc.altitude, NULL);
break; break;
case DNS_TYPE_SRV:
case DNS_TYPE_SSHFP: case DNS_TYPE_SSHFP:
case _DNS_TYPE_INVALID: /* unparseable */ case _DNS_TYPE_INVALID: /* unparseable */
default: default:
@ -951,6 +966,19 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
switch (rr->key->type) { 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_PTR:
case DNS_TYPE_NS: case DNS_TYPE_NS:
case DNS_TYPE_CNAME: 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: case DNS_TYPE_SSHFP:
default: default:
r = dns_packet_read(p, rdlength, &d, NULL); r = dns_packet_read(p, rdlength, &d, NULL);

View File

@ -234,31 +234,42 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
if (rr->key) { if (rr->key) {
switch(rr->key->type) { switch(rr->key->type) {
case DNS_TYPE_SRV:
free(rr->srv.name);
break;
case DNS_TYPE_PTR: case DNS_TYPE_PTR:
case DNS_TYPE_NS: case DNS_TYPE_NS:
case DNS_TYPE_CNAME: case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME: case DNS_TYPE_DNAME:
free(rr->ptr.name); free(rr->ptr.name);
break; break;
case DNS_TYPE_HINFO: case DNS_TYPE_HINFO:
free(rr->hinfo.cpu); free(rr->hinfo.cpu);
free(rr->hinfo.os); free(rr->hinfo.os);
break; break;
case DNS_TYPE_SPF:
case DNS_TYPE_TXT: case DNS_TYPE_TXT:
case DNS_TYPE_SPF:
strv_free(rr->txt.strings); strv_free(rr->txt.strings);
break; break;
case DNS_TYPE_SOA: case DNS_TYPE_SOA:
free(rr->soa.mname); free(rr->soa.mname);
free(rr->soa.rname); free(rr->soa.rname);
break; break;
case DNS_TYPE_MX: case DNS_TYPE_MX:
free(rr->mx.exchange); free(rr->mx.exchange);
break; break;
case DNS_TYPE_LOC: case DNS_TYPE_LOC:
case DNS_TYPE_A: case DNS_TYPE_A:
case DNS_TYPE_AAAA: case DNS_TYPE_AAAA:
break; break;
default: default:
free(rr->generic.data); free(rr->generic.data);
} }
@ -317,6 +328,15 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
switch (a->key->type) { 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_PTR:
case DNS_TYPE_NS: case DNS_TYPE_NS:
case DNS_TYPE_CNAME: 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.retry == b->soa.retry &&
a->soa.expire == b->soa.expire && a->soa.expire == b->soa.expire &&
a->soa.minimum == b->soa.minimum; a->soa.minimum == b->soa.minimum;
case DNS_TYPE_MX: case DNS_TYPE_MX:
if (a->mx.priority != b->mx.priority) if (a->mx.priority != b->mx.priority)
return 0; 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) { 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_PTR:
case DNS_TYPE_NS: case DNS_TYPE_NS:
case DNS_TYPE_CNAME: case DNS_TYPE_CNAME:

View File

@ -86,12 +86,12 @@ struct DnsResourceRecord {
uint16_t size; uint16_t size;
} generic; } generic;
/* struct { */ struct {
/* uint16_t priority; */ uint16_t priority;
/* uint16_t weight; */ uint16_t weight;
/* uint16_t port; */ uint16_t port;
/* char *name; */ char *name;
/* } srv; */ } srv;
struct { struct {
char *name; char *name;