resolved-dns-question.c revision 8013e860b6344cb109e68208a3a91b0fc3cb9ed1
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering This file is part of systemd.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering Copyright 2014 Lennart Poettering
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering systemd is free software; you can redistribute it and/or modify it
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering under the terms of the GNU Lesser General Public License as published by
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering (at your option) any later version.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering systemd is distributed in the hope that it will be useful, but
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering Lesser General Public License for more details.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering You should have received a copy of the GNU Lesser General Public License
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering q = malloc0(offsetof(DnsQuestion, keys) + sizeof(DnsResourceKey*) * n);
15a5e95075a7f6007dd97b2a165c8ed16fe683dfLennart PoetteringDnsQuestion *dns_question_ref(DnsQuestion *q) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart PoetteringDnsQuestion *dns_question_unref(DnsQuestion *q) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_add(DnsQuestion *q, DnsResourceKey *key) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_resource_key_equal(q->keys[i], key);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering q->keys[q->n_keys++] = dns_resource_key_ref(key);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_resource_key_match_rr(q->keys[i], rr);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_matches_cname(DnsQuestion *q, DnsResourceRecord *rr) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {
e9f600f2fb4b0df55c7a8fb4b4d09f9979997223Lennart Poettering r = dns_resource_key_match_cname(q->keys[i], rr);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_is_valid(DnsQuestion *q) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering name = DNS_RESOURCE_KEY_NAME(q->keys[0]);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering /* Check that all keys in this question bear the same name */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(q->keys[i]), name);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_is_superset(DnsQuestion *q, DnsQuestion *other) {
507f22bd0172bff5e5d98145b1419bd472a2c57fZbigniew Jędrzejewski-Szmek /* Checks if all keys in "other" are also contained in "q" */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering if (a->class != b->class && a->class != DNS_CLASS_ANY)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering if (a->type != b->type && a->type != DNS_TYPE_ANY)
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_contains(DnsQuestion *a, DnsResourceKey *k) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (j = 0; j < a->n_keys; j++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_resource_key_equal(a->keys[j], k);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_is_equal(DnsQuestion *a, DnsQuestion *b) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return !b || b->n_keys == 0;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering return a->n_keys == 0;
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering /* Checks if all keys in a are also contained b, and vice versa */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (j = 0; j < a->n_keys; j++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_question_contains(b, a->keys[j]);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (j = 0; j < b->n_keys; j++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering r = dns_question_contains(a, b->keys[j]);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_cname_redirect(DnsQuestion *q, const char *name, DnsQuestion **ret) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering _cleanup_(dns_question_unrefp) DnsQuestion *n = NULL;
4b94f3b8f7693f076e5c85bc2c02cf028192d8deZbigniew Jędrzejewski-Szmek for (i = 0; i < q->n_keys; i++) {
4b94f3b8f7693f076e5c85bc2c02cf028192d8deZbigniew Jędrzejewski-Szmek r = dns_name_equal(DNS_RESOURCE_KEY_NAME(q->keys[i]), name);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering /* Shortcut, the names are already right */
36dd072cdf03dcac0fcd2d6b42f261444dc7ac88Michal Sekletar /* Create a new question, and patch in the new name */
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *k = NULL;
e88baee88fad8bc59d33b55a7a2d640ef9e16cd6Zbigniew Jędrzejewski-Szmek k = dns_resource_key_new(q->keys[i]->class, q->keys[i]->type, name);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_endswith(DnsQuestion *q, const char *suffix) {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek for (i = 0; i < q->n_keys; i++) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering k = dns_name_endswith(DNS_RESOURCE_KEY_NAME(q->keys[i]), suffix);
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poetteringint dns_question_extract_reverse_address(DnsQuestion *q, int *family, union in_addr_union *address) {
ef63833d532dd86bdba63211e6a1363cbb3ef61dLennart Poettering for (i = 0; i < q->n_keys; i++) {