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