TRIP Routing Daemon
TRIP (RFC 3219) Location Server Implementation
Loading...
Searching...
No Matches
dns.h
Go to the documentation of this file.
1/*
2
3 trip: Modern TRIP LS implementation
4 Copyright (C) 2026 arf20 (Ángel Ruiz Fernandez)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19*/
20
24
25#ifndef _DNS_H
26#define _DNS_H
27
28#include <stdint.h>
29#include <stddef.h>
30#include <sys/types.h>
31
32#define DNS_FLAG_QR(x) (((x) >> 15) & 1)
33#define DNS_FLAG_OPCODE(x) (((x) >> 11) & 0b1111)
34#define DNS_FLAG_AA(x) (((x) >> 10) & 1)
35#define DNS_FLAG_TC(x) (((x) >> 9) & 1)
36#define DNS_FLAG_RD(x) (((x) >> 8) & 1)
37#define DNS_FLAG_RA(x) (((x) >> 7) & 1)
38#define DNS_FLAG_Z(x) (((x) >> 4) & 1)
39#define DNS_FLAG_RCODE(x) ((x) & 0b1111)
40
41#define DNS_SET_FLAG_QR(x) (((x) << 15) & 0b0111111111111111)
42#define DNS_SET_FLAG_OPCODE(x) (((x) << 11) & 0b1000011111111111)
43#define DNS_SET_FLAG_AA(x) (((x) << 10) & 0b1111101111111111)
44#define DNS_SET_FLAG_TC(x) (((x) << 9) & 0b1111110111111111)
45#define DNS_SET_FLAG_RD(x) (((x) << 8) & 0b1111111011111111)
46#define DNS_SET_FLAG_RA(x) (((x) << 7) & 0b1111111101111111)
47#define DNS_SET_FLAG_Z(x) (((x) << 4) & 0b1111111110001111)
48#define DNS_SET_FLAG_RCODE(x) ((x) & 0b1111111111110000)
49
50
51typedef struct __attribute__((packed)) {
52 uint8_t rcode : 4;
53 uint8_t z : 3;
54 uint8_t ra : 1;
55 uint8_t rd : 1;
56 uint8_t tc : 1;
57 uint8_t aa : 1;
58 uint8_t opcode : 4;
59 uint8_t qr : 1;
60} dns_flags_t;
61
62typedef struct __attribute__((packed)) {
63 uint16_t id;
64 dns_flags_t flags;
65 uint16_t qdcount;
66 uint16_t ancount;
67 uint16_t nscount;
68 uint16_t arcount;
69} dns_hdr_t;
70
71enum rcode_e {
72 RCODE_NO_ERROR = 0,
73 RCODE_FORMAT_ERROR,
74 RCODE_SERVER_FAIL,
75 RCODE_NAME_ERROR,
76 RCODE_NOT_IMPLEMENTED,
77 RCODE_REFUSED
78};
79
80typedef struct {
81 char qname[256];
82 uint16_t qtype;
83 uint16_t qclass;
85
86enum qtype_e {
87 TYPE_NAPTR = 35,
88 QTYPE_ALL = 255
89};
90
91enum qclass_e {
92 CLASS_IN = 1,
93 QCLASS_ANY = 256
94};
95
96
97ssize_t dns_parse_hdr(void *buf, size_t len, dns_hdr_t *out);
98
99size_t dns_parse_question(void *buf, size_t len, dns_question_t *q);
100
101ssize_t dns_serialize_error(void *buf, size_t len, const dns_hdr_t *recvhdr,
102 void *recv, size_t recv_size, int error);
103
104
105ssize_t dns_serialize_rdata_naptr(void *buf, size_t len, uint16_t order,
106 uint16_t preference, const char *flags, const char *services,
107 const char *regex);
108
109ssize_t dns_serialize_rr(void *buf, size_t len, const char *qto,
110 uint16_t type, uint16_t class, uint32_t ttl, uint16_t rdlength,
111 void *rdata);
112
113ssize_t dns_serialize_answer(void *buf, size_t len, const dns_hdr_t *recvhdr,
114 void *recv, size_t recv_size, void *rr, size_t rrsize);
115
116#endif /* _DNS_H */
117
struct __attribute__((packed))
Message OPEN optional paramter.
Definition dns.c:37
Definition dns.h:80