mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
resolved: LOC records
LOC records have a version field. So far only version 0 has been published, but if a record with a different version was encountered, our only recourse is to treat it as an unknown type. This is implemented with the 'unparseable' flag, which causes the serialization/deserialization and printing function to cause the record as a blob. The flag can be used if other packet types cannot be parsed for whatever reason.
This commit is contained in:
parent
9de3e32940
commit
0dae31d468
@ -4775,7 +4775,8 @@ systemd_resolved_LDADD = \
|
||||
libsystemd-network.la \
|
||||
libsystemd-label.la \
|
||||
libsystemd-internal.la \
|
||||
libsystemd-shared.la
|
||||
libsystemd-shared.la \
|
||||
-lm
|
||||
|
||||
rootlibexec_PROGRAMS += \
|
||||
systemd-resolved
|
||||
@ -4863,7 +4864,8 @@ systemd_resolve_host_SOURCES = \
|
||||
|
||||
systemd_resolve_host_LDADD = \
|
||||
libsystemd-internal.la \
|
||||
libsystemd-shared.la
|
||||
libsystemd-shared.la \
|
||||
-lm
|
||||
|
||||
rootlibexec_PROGRAMS += \
|
||||
systemd-resolve-host
|
||||
|
@ -497,7 +497,7 @@ int dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *star
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
switch (rr->key->type) {
|
||||
switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
|
||||
|
||||
case DNS_TYPE_PTR:
|
||||
case DNS_TYPE_NS:
|
||||
@ -570,10 +570,40 @@ 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_LOC:
|
||||
r = dns_packet_append_uint8(p, rr->loc.version, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint8(p, rr->loc.size, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint8(p, rr->loc.horiz_pre, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint8(p, rr->loc.vert_pre, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint16(p, rr->loc.latitude, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint16(p, rr->loc.longitude, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_append_uint16(p, rr->loc.altitude, NULL);
|
||||
break;
|
||||
|
||||
case DNS_TYPE_SRV:
|
||||
case DNS_TYPE_DNAME:
|
||||
case DNS_TYPE_SSHFP:
|
||||
case _DNS_TYPE_INVALID: /* unparseable */
|
||||
default:
|
||||
|
||||
r = dns_packet_append_blob(p, rr->generic.data, rr->generic.size, NULL);
|
||||
break;
|
||||
}
|
||||
@ -994,6 +1024,49 @@ 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_LOC: {
|
||||
uint8_t t;
|
||||
size_t pos;
|
||||
|
||||
r = dns_packet_read_uint8(p, &t, &pos);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
if (t == 0) {
|
||||
rr->loc.version = t;
|
||||
|
||||
r = dns_packet_read_uint8(p, &rr->loc.size, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_read_uint8(p, &rr->loc.horiz_pre, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_read_uint8(p, &rr->loc.vert_pre, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_read_uint32(p, &rr->loc.latitude, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_read_uint32(p, &rr->loc.longitude, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = dns_packet_read_uint32(p, &rr->loc.altitude, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
break;
|
||||
} else {
|
||||
dns_packet_rewind(p, pos);
|
||||
rr->unparseable = true;
|
||||
/* fall through */
|
||||
}
|
||||
}
|
||||
|
||||
case DNS_TYPE_SRV:
|
||||
case DNS_TYPE_DNAME:
|
||||
case DNS_TYPE_SSHFP:
|
||||
|
@ -19,6 +19,8 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "strv.h"
|
||||
|
||||
#include "resolved-dns-domain.h"
|
||||
@ -252,6 +254,7 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
|
||||
case DNS_TYPE_MX:
|
||||
free(rr->mx.exchange);
|
||||
break;
|
||||
case DNS_TYPE_LOC:
|
||||
case DNS_TYPE_A:
|
||||
case DNS_TYPE_AAAA:
|
||||
break;
|
||||
@ -357,12 +360,54 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
|
||||
|
||||
return dns_name_equal(a->mx.exchange, b->mx.exchange);
|
||||
|
||||
case DNS_TYPE_LOC:
|
||||
assert(a->loc.version == b->loc.version);
|
||||
|
||||
return a->loc.size == b->loc.size &&
|
||||
a->loc.horiz_pre == b->loc.horiz_pre &&
|
||||
a->loc.vert_pre == b->loc.vert_pre &&
|
||||
a->loc.latitude == b->loc.latitude &&
|
||||
a->loc.longitude == b->loc.longitude &&
|
||||
a->loc.altitude == b->loc.altitude;
|
||||
|
||||
default:
|
||||
return a->generic.size == b->generic.size &&
|
||||
memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
static char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
|
||||
uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
|
||||
char *s;
|
||||
char NS = latitude >= 1U<<31 ? 'N' : 'S';
|
||||
char EW = longitude >= 1U<<31 ? 'E' : 'W';
|
||||
|
||||
int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
|
||||
int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
|
||||
double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
|
||||
double siz = (size >> 4) * exp10((double) (size & 0xF));
|
||||
double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
|
||||
double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
|
||||
|
||||
if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
|
||||
(lat / 60000 / 60),
|
||||
(lat / 60000) % 60,
|
||||
(lat % 60000) / 1000.,
|
||||
NS,
|
||||
(lon / 60000 / 60),
|
||||
(lon / 60000) % 60,
|
||||
(lon % 60000) / 1000.,
|
||||
EW,
|
||||
alt / 100.,
|
||||
siz / 100.,
|
||||
hor / 100.,
|
||||
ver / 100.) < 0)
|
||||
return NULL;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
|
||||
_cleanup_free_ char *k = NULL;
|
||||
char *s;
|
||||
@ -374,7 +419,7 @@ int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
switch (rr->key->type) {
|
||||
switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
|
||||
|
||||
case DNS_TYPE_PTR:
|
||||
case DNS_TYPE_NS:
|
||||
@ -455,6 +500,26 @@ int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
|
||||
return -ENOMEM;
|
||||
break;
|
||||
|
||||
case DNS_TYPE_LOC: {
|
||||
_cleanup_free_ char *loc;
|
||||
assert(rr->loc.version == 0);
|
||||
|
||||
loc = format_location(rr->loc.latitude,
|
||||
rr->loc.longitude,
|
||||
rr->loc.altitude,
|
||||
rr->loc.size,
|
||||
rr->loc.horiz_pre,
|
||||
rr->loc.vert_pre);
|
||||
if (!loc)
|
||||
return -ENOMEM;
|
||||
|
||||
s = strjoin(k, " ", loc, NULL);
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
_cleanup_free_ char *x = NULL;
|
||||
|
||||
@ -513,6 +578,7 @@ static const struct {
|
||||
{ DNS_TYPE_MX, "MX" },
|
||||
{ DNS_TYPE_TXT, "TXT" },
|
||||
{ DNS_TYPE_AAAA, "AAAA" },
|
||||
{ DNS_TYPE_LOC, "LOC" },
|
||||
{ DNS_TYPE_SRV, "SRV" },
|
||||
{ DNS_TYPE_SSHFP, "SSHFP" },
|
||||
{ DNS_TYPE_SPF, "SPF" },
|
||||
|
@ -51,6 +51,7 @@ enum {
|
||||
DNS_TYPE_MX = 0x0F,
|
||||
DNS_TYPE_TXT = 0x10,
|
||||
DNS_TYPE_AAAA = 0x1C,
|
||||
DNS_TYPE_LOC = 0x1D,
|
||||
DNS_TYPE_SRV = 0x21,
|
||||
DNS_TYPE_DNAME = 0x27,
|
||||
DNS_TYPE_SSHFP = 0x2C,
|
||||
@ -78,6 +79,7 @@ struct DnsResourceRecord {
|
||||
unsigned n_ref;
|
||||
DnsResourceKey *key;
|
||||
uint32_t ttl;
|
||||
bool unparseable;
|
||||
union {
|
||||
struct {
|
||||
void *data;
|
||||
@ -126,6 +128,16 @@ struct DnsResourceRecord {
|
||||
uint16_t priority;
|
||||
char *exchange;
|
||||
} mx;
|
||||
|
||||
struct {
|
||||
uint8_t version;
|
||||
uint8_t size;
|
||||
uint8_t horiz_pre;
|
||||
uint8_t vert_pre;
|
||||
uint32_t latitude;
|
||||
uint32_t longitude;
|
||||
uint32_t altitude;
|
||||
} loc;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user