summaryrefslogtreecommitdiffstats
path: root/include/dnsjit/core/object/dns.hh
blob: dfe97191b18f92ab0e27a7f37405645222f4d3c3 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Copyright (c) 2018-2021, OARC, Inc.
 * All rights reserved.
 *
 * This file is part of dnsjit.
 *
 * dnsjit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dnsjit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dnsjit.  If not, see <http://www.gnu.org/licenses/>.
 */

//lua:require("dnsjit.core.log")
//lua:require("dnsjit.core.object_h")

typedef struct core_object_dns_label {
    uint8_t is_end;
    uint8_t have_length;
    uint8_t have_offset;
    uint8_t have_extension_bits;
    uint8_t have_dn;
    uint8_t extension_bits;

    uint8_t  length;
    uint16_t offset;
} core_object_dns_label_t;

typedef struct core_object_dns_rr {
    uint8_t have_type;
    uint8_t have_class;
    uint8_t have_ttl;
    uint8_t have_rdlength;
    uint8_t have_rdata;
    uint8_t have_rdata_labels;
    uint8_t have_padding;

    uint16_t type;
    uint16_t class;
    uint32_t ttl;
    uint16_t rdlength;

    size_t labels;
    size_t rdata_offset;
    size_t rdata_labels;
    size_t padding_offset;
    size_t padding_length;
} core_object_dns_rr_t;

typedef struct core_object_dns_q {
    uint8_t have_type;
    uint8_t have_class;

    uint16_t type;
    uint16_t class;

    size_t labels;
} core_object_dns_q_t;

typedef struct core_object_dns {
    const core_object_t* obj_prev;
    int32_t              obj_type;

    int            includes_dnslen;
    const uint8_t *payload, *at;
    size_t         len, left;

    uint8_t have_dnslen;
    uint8_t have_id;
    uint8_t have_qr;
    uint8_t have_opcode;
    uint8_t have_aa;
    uint8_t have_tc;
    uint8_t have_rd;
    uint8_t have_ra;
    uint8_t have_z;
    uint8_t have_ad;
    uint8_t have_cd;
    uint8_t have_rcode;
    uint8_t have_qdcount;
    uint8_t have_ancount;
    uint8_t have_nscount;
    uint8_t have_arcount;

    uint16_t dnslen;
    uint16_t id;
    int8_t   qr;
    uint8_t  opcode;
    uint8_t  aa;
    uint8_t  tc;
    uint8_t  rd;
    uint8_t  ra;
    uint8_t  z;
    uint8_t  ad;
    uint8_t  cd;
    uint8_t  rcode;
    uint16_t qdcount;
    uint16_t ancount;
    uint16_t nscount;
    uint16_t arcount;
} core_object_dns_t;

core_log_t* core_object_dns_log();

core_object_dns_t* core_object_dns_new();
core_object_dns_t* core_object_dns_copy(const core_object_dns_t* self);
void               core_object_dns_free(core_object_dns_t* self);
void               core_object_dns_reset(core_object_dns_t* self, const core_object_t* obj);

int core_object_dns_parse_header(core_object_dns_t* self);
int core_object_dns_parse_q(core_object_dns_t* self, core_object_dns_q_t* q, core_object_dns_label_t* label, size_t labels);
int core_object_dns_parse_rr(core_object_dns_t* self, core_object_dns_rr_t* rr, core_object_dns_label_t* label, size_t labels);