resolved-dns-packet.h revision 8b757a38611006a751c90933d1810cccaa47e1af
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#pragma once
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/***
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering This file is part of systemd.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Copyright 2014 Lennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is free software; you can redistribute it and/or modify it
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering under the terms of the GNU Lesser General Public License as published by
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (at your option) any later version.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is distributed in the hope that it will be useful, but
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Lesser General Public License for more details.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering You should have received a copy of the GNU Lesser General Public License
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner ***/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "macro.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sparse-endian.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "hashmap.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "in-addr-util.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringtypedef struct DnsPacketHeader DnsPacketHeader;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringtypedef struct DnsPacket DnsPacket;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-rr.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-question.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-answer.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-def.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringtypedef enum DnsProtocol {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_PROTOCOL_DNS,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_PROTOCOL_MDNS,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_PROTOCOL_LLMNR,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _DNS_PROTOCOL_MAX,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _DNS_PROTOCOL_INVALID = -1
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering} DnsProtocol;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstruct DnsPacketHeader {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering uint16_t id;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be16_t flags;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be16_t qdcount;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be16_t ancount;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be16_t nscount;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be16_t arcount;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering};
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_HEADER_SIZE sizeof(DnsPacketHeader)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/* The various DNS protocols deviate in how large a packet can grow,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering but the TCP transport has a 16bit size field, hence that appears to
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering be the absolute maximum. */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_SIZE_MAX 0xFFFF
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/* RFC 1035 say 512 is the maximum, for classic unicast DNS */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_UNICAST_SIZE_MAX 512
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_SIZE_START 512
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstruct DnsPacket {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int n_ref;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DnsProtocol protocol;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering size_t size, allocated, rindex;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering void *_data; /* don't access directly, use DNS_PACKET_DATA()! */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *names; /* For name compression */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Parsed data */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DnsQuestion *question;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DnsAnswer *answer;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Packet reception meta data */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int ifindex;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int family, ipproto;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering union in_addr_union sender, destination;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering uint16_t sender_port, destination_port;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering uint32_t ttl;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool extracted;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering};
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic inline uint8_t* DNS_PACKET_DATA(DnsPacket *p) {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering if (_unlikely_(!p))
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return NULL;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering if (p->_data)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return p->_data;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return ((uint8_t*) p) + ALIGN(sizeof(DnsPacket));
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering}
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_HEADER(p) ((DnsPacketHeader*) DNS_PACKET_DATA(p))
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_ID(p) DNS_PACKET_HEADER(p)->id
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_QR(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 15) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_OPCODE(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 11) & 15)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_AA(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 10) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_TC(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 9) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_RD(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 8) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_RA(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 7) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_AD(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 5) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_CD(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 4) & 1)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_RCODE(p) (be16toh(DNS_PACKET_HEADER(p)->flags) & 15)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/* LLMNR defines some bits differently */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_LLMNR_C(p) DNS_PACKET_AA(p)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_LLMNR_T(p) DNS_PACKET_RD(p)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_QDCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->qdcount)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_ANCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->ancount)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_NSCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->nscount)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_ARCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->arcount)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNS_PACKET_MAKE_FLAGS(qr, opcode, aa, tc, rd, ra, ad, cd, rcode) \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (((uint16_t) !!qr << 15) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) (opcode & 15) << 11) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!aa << 10) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!tc << 9) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!rd << 8) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!ra << 7) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!ad << 5) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) !!cd << 4) | \
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ((uint16_t) (rcode & 15)))
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic inline unsigned DNS_PACKET_RRCOUNT(DnsPacket *p) {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (unsigned) DNS_PACKET_ANCOUNT(p) +
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (unsigned) DNS_PACKET_NSCOUNT(p) +
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (unsigned) DNS_PACKET_ARCOUNT(p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering}
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_new(DnsPacket **p, DnsProtocol protocol, size_t mtu);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_new_query(DnsPacket **p, DnsProtocol protocol, size_t mtu);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringDnsPacket *dns_packet_ref(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringDnsPacket *dns_packet_unref(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(DnsPacket*, dns_packet_unref);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_validate(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_validate_reply(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_validate_query(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_blob(DnsPacket *p, const void *d, size_t sz, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_uint8(DnsPacket *p, uint8_t v, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_uint16(DnsPacket *p, uint16_t v, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_uint32(DnsPacket *p, uint32_t v, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_string(DnsPacket *p, const char *s, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_label(DnsPacket *p, const char *s, size_t l, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_name(DnsPacket *p, const char *name,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool allow_compression, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_key(DnsPacket *p, const DnsResourceKey *key, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_append_rr(DnsPacket *p, const DnsResourceRecord *rr, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read(DnsPacket *p, size_t sz, const void **ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_blob(DnsPacket *p, void *d, size_t sz, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_uint8(DnsPacket *p, uint8_t *ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_uint16(DnsPacket *p, uint16_t *ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_uint32(DnsPacket *p, uint32_t *ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_string(DnsPacket *p, char **ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_name(DnsPacket *p, char **ret,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool allow_compression, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_key(DnsPacket *p, DnsResourceKey **ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringvoid dns_packet_rewind(DnsPacket *p, size_t idx);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_skip_question(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_packet_extract(DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringenum {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_SUCCESS = 0,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_FORMERR = 1,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_SERVFAIL = 2,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_NXDOMAIN = 3,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_NOTIMP = 4,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_REFUSED = 5,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_YXDOMAIN = 6,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_YXRRSET = 7,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_NXRRSET = 8,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_NOTAUTH = 9,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_NOTZONE = 10,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADVERS = 16,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADSIG = 16, /* duplicate value! */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADKEY = 17,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADTIME = 18,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADMODE = 19,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADNAME = 20,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADALG = 21,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNS_RCODE_BADTRUNC = 22,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _DNS_RCODE_MAX_DEFINED
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering};
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringconst char* dns_rcode_to_string(int i) _const_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dns_rcode_from_string(const char *s) _pure_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringconst char* dns_protocol_to_string(DnsProtocol p) _const_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringDnsProtocol dns_protocol_from_string(const char *s) _pure_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define LLMNR_MULTICAST_IPV4_ADDRESS ((struct in_addr) { .s_addr = htobe32(224U << 24 | 252U) })
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define LLMNR_MULTICAST_IPV6_ADDRESS ((struct in6_addr) { .s6_addr = { 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03 } })
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNSKEY_FLAG_ZONE_KEY (1u << 8)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define DNSKEY_FLAG_SEP (1u << 0)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic inline uint16_t dnskey_to_flags(const DnsResourceRecord *rr) {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return (rr->dnskey.zone_key_flag * DNSKEY_FLAG_ZONE_KEY |
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering rr->dnskey.sep_flag * DNSKEY_FLAG_SEP);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering}
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/* http://tools.ietf.org/html/rfc4034#appendix-A.1 */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringenum {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_RSAMD5 = 1,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_DH,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_DSA,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_ECC,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_RSASHA1,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_INDIRECT = 252,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_PRIVATEDNS,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DNSSEC_ALGORITHM_PRIVATEOID,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _DNSSEC_ALGORITHM_MAX_DEFINED
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering};
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringconst char* dnssec_algorithm_to_string(int i) _const_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint dnssec_algorithm_from_string(const char *s) _pure_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic inline uint64_t SD_RESOLVED_FLAGS_MAKE(DnsProtocol protocol, int family) {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Converts a protocol + family into a flags field as used in queries */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering if (protocol == DNS_PROTOCOL_DNS)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return SD_RESOLVED_DNS;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering if (protocol == DNS_PROTOCOL_LLMNR)
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return family == AF_INET6 ? SD_RESOLVED_LLMNR_IPV6 : SD_RESOLVED_LLMNR_IPV4;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering return 0;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering}
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering