summaryrefslogtreecommitdiffstats
path: root/lib/proto.h
blob: 875fe8e309e55aa604265aef17fcc752313b6ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*  Copyright (C) CZ.NIC, z.s.p.o. <knot-resolver@labs.nic.cz>
 *  SPDX-License-Identifier: GPL-3.0-or-later
 */
#pragma once

#include <stdint.h>

#include "lib/defines.h"

/** DNS transport protocol map
 *
 * This macro is used to generate `enum kr_proto` as well as other additional
 * data on protocols, like name string constants.
 *
 * It defines DNS transport protocols for use by `session2` (to define sequences
 * of protocol layers) and `rules` (to filter requests based on them). To find
 * out more, see the individual usages.
 *
 * Parameters for XX are:
 *   1. Constant name (for e.g. KR_PROTO_* enum value identifiers)
 *   2. Variable name (for e.g. kr_proto_* array identifiers, like those defined
 *      in `session2.c`)
 *   3. Human-readable name for logging */
#define KR_PROTO_MAP(XX) \
    XX(UDP53, udp53, "DNS UDP") \
    XX(TCP53, tcp53, "DNS TCP") \
    XX(DOT, dot, "DNS-over-TLS") \
    XX(DOH, doh, "DNS-over-HTTPS") \
    XX(DOQ, doq, "DNS-over-QUIC") /* unused for now */ \
    //

/** DNS protocol set - mutually exclusive options, contrary to
 * kr_request_qsource_flags
 *
 * The XDP flag is not discerned here, as it could apply to any protocol. (Not
 * right now, but libknot does support it for TCP, so that would complete
 * everything)
 */
enum kr_proto {
	KR_PROTO_INTERNAL = 0, /// no protocol, e.g. useful to mark internal requests
#define XX(cid, vid, name) KR_PROTO_ ## cid,
	KR_PROTO_MAP(XX)
#undef XX
	KR_PROTO_COUNT,
};

/** Gets the constant string name of the specified transport protocol. */
KR_EXPORT
const char *kr_proto_name(enum kr_proto p);

/** Bitmap of enum kr_proto options. */
typedef uint8_t kr_proto_set;
static_assert(sizeof(kr_proto_set) * 8 >= KR_PROTO_COUNT, "bad combination of type sizes");