resolved-dns-question.c revision 45ec7efb6c2560c80dfa752bc9d3733749dc52cb
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering This file is part of systemd.
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering Copyright 2014 Lennart Poettering
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering systemd is free software; you can redistribute it and/or modify it
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering under the terms of the GNU Lesser General Public License as published by
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering (at your option) any later version.
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering systemd is distributed in the hope that it will be useful, but
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering Lesser General Public License for more details.
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering You should have received a copy of the GNU Lesser General Public License
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart PoetteringDnsQuestion *dns_question_new(unsigned n) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering q = malloc0(offsetof(DnsQuestion, keys) + sizeof(DnsResourceKey*) * n);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart PoetteringDnsQuestion *dns_question_ref(DnsQuestion *q) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart PoetteringDnsQuestion *dns_question_unref(DnsQuestion *q) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (i = 0; i < q->n_keys; i++)
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_add(DnsQuestion *q, DnsResourceKey *key) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (i = 0; i < q->n_keys; i++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_resource_key_equal(q->keys[i], key);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering q->keys[q->n_keys++] = dns_resource_key_ref(key);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (i = 0; i < q->n_keys; i++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_resource_key_match_rr(q->keys[i], rr);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_matches_cname(DnsQuestion *q, DnsResourceRecord *rr) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (i = 0; i < q->n_keys; i++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_resource_key_match_cname(q->keys[i], rr);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_is_valid(DnsQuestion *q) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering name = DNS_RESOURCE_KEY_NAME(q->keys[0]);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering /* Check that all keys in this question bear the same name */
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(q->keys[i]), name);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_is_superset(DnsQuestion *q, DnsQuestion *other) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering /* Checks if all keys in "other" are also contained in "q" */
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (i = 0; i < q->n_keys; i++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering if (a->class != b->class && a->class != DNS_CLASS_ANY)
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering if (a->type != b->type && a->type != DNS_TYPE_ANY)
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_contains(DnsQuestion *a, DnsResourceKey *k) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (j = 0; j < a->n_keys; j++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_resource_key_equal(a->keys[j], k);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_is_equal(DnsQuestion *a, DnsQuestion *b) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering return !b || b->n_keys == 0;
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering return a->n_keys == 0;
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering /* Checks if all keys in a are also contained b, and vice versa */
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (j = 0; j < a->n_keys; j++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_question_contains(b, a->keys[j]);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering for (j = 0; j < b->n_keys; j++) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering r = dns_question_contains(a, b->keys[j]);
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poetteringint dns_question_cname_redirect(DnsQuestion *q, const DnsResourceRecord *cname, DnsQuestion **ret) {
71dc3ed1d95dfe246004018c2ca85156fc73c146Lennart Poettering _cleanup_(dns_question_unrefp) DnsQuestion *n = NULL;
*ret = n;
for (i = 0; i < q->n_keys; i++) {
same = false;
if (same) {
return -ENOMEM;
for (i = 0; i < q->n_keys; i++) {
return -ENOMEM;
r = dns_question_add(n, k);
*ret = n;
n = NULL;
assert(q);
return NULL;
return -EAFNOSUPPORT;
return -ENOMEM;
if (!key)
return -ENOMEM;
if (!key)
return -ENOMEM;
*ret = q;
q = NULL;
assert(a);
return -EAFNOSUPPORT;
return -ENOMEM;
if (!key)
return -ENOMEM;
*ret = q;
q = NULL;
return -ENOMEM;
if (!key)
return -ENOMEM;
if (with_txt) {
if (!key)
return -ENOMEM;
*ret = q;
q = NULL;