resolved-dns-rr.c revision abf126a355e2f2b62b6c51ab3bb37895d1e3eee7
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <math.h>
#include "strv.h"
#include "dns-domain.h"
#include "resolved-dns-rr.h"
#include "resolved-dns-packet.h"
#include "dns-type.h"
DnsResourceKey *k;
size_t l;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
DnsResourceKey *k;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
if (!k)
return NULL;
k->n_ref++;
return k;
}
if (!k)
return NULL;
if (k->n_ref == 1) {
free(k);
} else
k->n_ref--;
return NULL;
}
int r;
if (r <= 0)
return r;
return 0;
return 0;
return 1;
}
return 0;
return 0;
}
return 0;
return 0;
}
static unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
const DnsResourceKey *k = i;
unsigned long ul;
return ul;
}
static int dns_resource_key_compare_func(const void *a, const void *b) {
const DnsResourceKey *x = a, *y = b;
int ret;
if (ret != 0)
return ret;
return -1;
return 1;
return -1;
return 1;
return 0;
}
const struct hash_ops dns_resource_key_hash_ops = {
};
const char *c, *t;
char *s;
if (!c) {
c = cbuf;
}
if (!t){
t = tbuf;
}
return -ENOMEM;
*ret = s;
return 0;
}
if (!rr)
return NULL;
return rr;
}
if (!key)
return NULL;
return dns_resource_record_new(key);
}
if (!rr)
return NULL;
return rr;
}
if (!rr)
return NULL;
return NULL;
}
case DNS_TYPE_SRV:
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
break;
case DNS_TYPE_HINFO:
break;
case DNS_TYPE_TXT:
case DNS_TYPE_SPF:
break;
case DNS_TYPE_SOA:
break;
case DNS_TYPE_MX:
break;
case DNS_TYPE_DS:
break;
case DNS_TYPE_SSHFP:
break;
case DNS_TYPE_DNSKEY:
break;
case DNS_TYPE_RRSIG:
break;
case DNS_TYPE_LOC:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
break;
default:
}
}
return NULL;
}
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
int r;
if (r < 0)
return r;
if (!key)
return -ENOMEM;
if (!rr)
return -ENOMEM;
return -ENOMEM;
return 0;
}
int r;
assert(a);
assert(b);
if (r <= 0)
return r;
if (a->unparseable != b->unparseable)
return 0;
case DNS_TYPE_SRV:
if (r <= 0)
return r;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_SOA:
if (r <= 0)
return r;
if (r <= 0)
return r;
case DNS_TYPE_MX:
return 0;
case DNS_TYPE_LOC:
case DNS_TYPE_DS:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
case DNS_TYPE_RRSIG:
/* do the fast comparisons first */
return false;
default:
}
}
char *s;
if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
NS,
EW,
alt / 100.,
siz / 100.,
hor / 100.,
ver / 100.) < 0)
return NULL;
return s;
}
return -EINVAL;
return -EINVAL;
return 0;
}
char *s;
int r;
if (r < 0)
return r;
case DNS_TYPE_SRV:
r = asprintf(&s, "%s %u %u %u %s",
k,
if (r < 0)
return -ENOMEM;
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
if (!s)
return -ENOMEM;
break;
case DNS_TYPE_HINFO:
if (!s)
return -ENOMEM;
break;
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
if (!t)
return -ENOMEM;
if (!s)
return -ENOMEM;
break;
case DNS_TYPE_A: {
_cleanup_free_ char *x = NULL;
if (r < 0)
return r;
if (!s)
return -ENOMEM;
break;
}
case DNS_TYPE_AAAA:
if (r < 0)
return r;
if (!s)
return -ENOMEM;
break;
case DNS_TYPE_SOA:
r = asprintf(&s, "%s %s %s %u %u %u %u %u",
k,
if (r < 0)
return -ENOMEM;
break;
case DNS_TYPE_MX:
r = asprintf(&s, "%s %u %s",
k,
if (r < 0)
return -ENOMEM;
break;
case DNS_TYPE_LOC:
if (!t)
return -ENOMEM;
if (!s)
return -ENOMEM;
break;
case DNS_TYPE_DS:
if (!t)
return -ENOMEM;
r = asprintf(&s, "%s %u %u %u %s",
k,
t);
if (r < 0)
return -ENOMEM;
break;
case DNS_TYPE_SSHFP:
if (!t)
return -ENOMEM;
r = asprintf(&s, "%s %u %u %s",
k,
t);
if (r < 0)
return -ENOMEM;
break;
case DNS_TYPE_DNSKEY: {
const char *alg;
if (!t)
return -ENOMEM;
r = asprintf(&s, "%s %u 3 %.*s%.*u %s",
k,
t);
if (r < 0)
return -ENOMEM;
break;
}
case DNS_TYPE_RRSIG: {
if (!t)
return -ENOMEM;
if (r < 0)
return r;
if (r < 0)
return r;
/* TYPE?? follows
* http://tools.ietf.org/html/rfc3597#section-5 */
r = asprintf(&s, "%s %s%.*u %.*s%.*u %u %u %s %s %u %s %s",
k,
type ?: "TYPE",
t);
if (r < 0)
return -ENOMEM;
break;
}
default:
if (!t)
return -ENOMEM;
if (!s)
return -ENOMEM;
break;
}
*ret = s;
return 0;
}
switch (class) {
case DNS_CLASS_IN:
return "IN";
case DNS_CLASS_ANY:
return "ANY";
}
return NULL;
}
assert(s);
if (strcaseeq(s, "IN"))
*class = DNS_CLASS_IN;
else if (strcaseeq(s, "ANY"))
*class = DNS_TYPE_ANY;
else
return -EINVAL;
return 0;
}