Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Daniel Kahn Gillmor
Knot DNS Resolver
Commits
f474ee26
Commit
f474ee26
authored
Jan 10, 2016
by
Marek Vavrusa
Browse files
Merge branch 'new-libknot'
parents
d9b82dc9
c93257f3
Changes
59
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
f474ee26
...
...
@@ -15,7 +15,8 @@ BUILD_CFLAGS += --coverage
endif
# Dependencies
$(eval
$(call
find_lib,libknot))
$(eval
$(call
find_lib,libknot,2.1))
$(eval
$(call
find_lib,libzscanner,2.1))
$(eval
$(call
find_lib,libuv,1.0))
$(eval
$(call
find_alt,lua,luajit))
$(eval
$(call
find_lib,cmocka))
...
...
@@ -49,6 +50,9 @@ BUILD_CFLAGS += $(addprefix -I,$(wildcard contrib/ccan/*) contrib/murmurhash3)
info
:
$
(
info Target: Knot DNS Resolver
$(MAJOR)
.
$(MINOR)
.
$(PATCH)
-
$(PLATFORM)
)
$
(
info Compiler:
$(CC)
$(BUILD_CFLAGS)
)
$(info )
$
(
info Variables
)
$
(
info
---------
)
$
(
info HARDENING:
$(HARDENING)
)
$
(
info BUILDMODE:
$(BUILDMODE)
)
$
(
info PREFIX:
$(PREFIX)
)
...
...
@@ -63,14 +67,14 @@ info:
$
(
info Dependencies
)
$
(
info
------------
)
$
(
info
[
$(HAS_libknot)
]
libknot
(
lib
))
$
(
info
[
$(HAS_lua)
]
L
ua
JIT
(
daemon
))
$
(
info
[
$(HAS_lua)
]
l
ua
jit
(
daemon
))
$
(
info
[
$(HAS_libuv)
]
libuv
(
daemon
))
$(info )
$
(
info Optional
)
$
(
info
--------
)
$
(
info
[
$(HAS_doxygen)
]
doxygen
(
doc
))
$
(
info
[
$(HAS_go)
]
Go 1.5+ on amd64
(
modules/go
))
$
(
info
[
$(HAS_geoip)
]
github.com/abh/
geoip
(
modules/tinyweb
))
$
(
info
[
$(HAS_go)
]
go
(
modules/go,
Go 1.5+ on amd64
))
$
(
info
[
$(HAS_geoip)
]
geoip
(
modules/tinyweb
, github.com/abh/geoip
))
$
(
info
[
$(HAS_libmemcached)
]
libmemcached
(
modules/memcached
))
$
(
info
[
$(HAS_hiredis)
]
hiredis
(
modules/redis
))
$
(
info
[
$(HAS_cmocka)
]
cmocka
(
tests/unit
))
...
...
contrib/base32hex.c
0 → 100644
View file @
f474ee26
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"contrib/base32hex.h"
#include
<stdlib.h>
#include
<stdint.h>
/*! \brief Maximal length of binary input to Base32hex encoding. */
#define MAX_BIN_DATA_LEN ((INT32_MAX / 8) * 5)
/*! \brief Base32hex padding character. */
const
uint8_t
base32hex_pad
=
'='
;
/*! \brief Base32hex alphabet. */
const
uint8_t
base32hex_enc
[]
=
"0123456789ABCDEFGHIJKLMNOPQRSTUV"
;
/*! \brief Indicates bad Base32hex character. */
#define KO 255
/*! \brief Indicates Base32hex padding character. */
#define PD 32
/*! \brief Transformation and validation table for decoding Base32hex. */
const
uint8_t
base32hex_dec
[
256
]
=
{
[
0
]
=
KO
,
[
43
]
=
KO
,
[
'V'
]
=
31
,
[
129
]
=
KO
,
[
172
]
=
KO
,
[
215
]
=
KO
,
[
1
]
=
KO
,
[
44
]
=
KO
,
[
'W'
]
=
KO
,
[
130
]
=
KO
,
[
173
]
=
KO
,
[
216
]
=
KO
,
[
2
]
=
KO
,
[
45
]
=
KO
,
[
'X'
]
=
KO
,
[
131
]
=
KO
,
[
174
]
=
KO
,
[
217
]
=
KO
,
[
3
]
=
KO
,
[
46
]
=
KO
,
[
'Y'
]
=
KO
,
[
132
]
=
KO
,
[
175
]
=
KO
,
[
218
]
=
KO
,
[
4
]
=
KO
,
[
47
]
=
KO
,
[
'Z'
]
=
KO
,
[
133
]
=
KO
,
[
176
]
=
KO
,
[
219
]
=
KO
,
[
5
]
=
KO
,
[
'0'
]
=
0
,
[
91
]
=
KO
,
[
134
]
=
KO
,
[
177
]
=
KO
,
[
220
]
=
KO
,
[
6
]
=
KO
,
[
'1'
]
=
1
,
[
92
]
=
KO
,
[
135
]
=
KO
,
[
178
]
=
KO
,
[
221
]
=
KO
,
[
7
]
=
KO
,
[
'2'
]
=
2
,
[
93
]
=
KO
,
[
136
]
=
KO
,
[
179
]
=
KO
,
[
222
]
=
KO
,
[
8
]
=
KO
,
[
'3'
]
=
3
,
[
94
]
=
KO
,
[
137
]
=
KO
,
[
180
]
=
KO
,
[
223
]
=
KO
,
[
9
]
=
KO
,
[
'4'
]
=
4
,
[
95
]
=
KO
,
[
138
]
=
KO
,
[
181
]
=
KO
,
[
224
]
=
KO
,
[
10
]
=
KO
,
[
'5'
]
=
5
,
[
96
]
=
KO
,
[
139
]
=
KO
,
[
182
]
=
KO
,
[
225
]
=
KO
,
[
11
]
=
KO
,
[
'6'
]
=
6
,
[
'a'
]
=
10
,
[
140
]
=
KO
,
[
183
]
=
KO
,
[
226
]
=
KO
,
[
12
]
=
KO
,
[
'7'
]
=
7
,
[
'b'
]
=
11
,
[
141
]
=
KO
,
[
184
]
=
KO
,
[
227
]
=
KO
,
[
13
]
=
KO
,
[
'8'
]
=
8
,
[
'c'
]
=
12
,
[
142
]
=
KO
,
[
185
]
=
KO
,
[
228
]
=
KO
,
[
14
]
=
KO
,
[
'9'
]
=
9
,
[
'd'
]
=
13
,
[
143
]
=
KO
,
[
186
]
=
KO
,
[
229
]
=
KO
,
[
15
]
=
KO
,
[
58
]
=
KO
,
[
'e'
]
=
14
,
[
144
]
=
KO
,
[
187
]
=
KO
,
[
230
]
=
KO
,
[
16
]
=
KO
,
[
59
]
=
KO
,
[
'f'
]
=
15
,
[
145
]
=
KO
,
[
188
]
=
KO
,
[
231
]
=
KO
,
[
17
]
=
KO
,
[
60
]
=
KO
,
[
'g'
]
=
16
,
[
146
]
=
KO
,
[
189
]
=
KO
,
[
232
]
=
KO
,
[
18
]
=
KO
,
[
'='
]
=
PD
,
[
'h'
]
=
17
,
[
147
]
=
KO
,
[
190
]
=
KO
,
[
233
]
=
KO
,
[
19
]
=
KO
,
[
62
]
=
KO
,
[
'i'
]
=
18
,
[
148
]
=
KO
,
[
191
]
=
KO
,
[
234
]
=
KO
,
[
20
]
=
KO
,
[
63
]
=
KO
,
[
'j'
]
=
19
,
[
149
]
=
KO
,
[
192
]
=
KO
,
[
235
]
=
KO
,
[
21
]
=
KO
,
[
64
]
=
KO
,
[
'k'
]
=
20
,
[
150
]
=
KO
,
[
193
]
=
KO
,
[
236
]
=
KO
,
[
22
]
=
KO
,
[
'A'
]
=
10
,
[
'l'
]
=
21
,
[
151
]
=
KO
,
[
194
]
=
KO
,
[
237
]
=
KO
,
[
23
]
=
KO
,
[
'B'
]
=
11
,
[
'm'
]
=
22
,
[
152
]
=
KO
,
[
195
]
=
KO
,
[
238
]
=
KO
,
[
24
]
=
KO
,
[
'C'
]
=
12
,
[
'n'
]
=
23
,
[
153
]
=
KO
,
[
196
]
=
KO
,
[
239
]
=
KO
,
[
25
]
=
KO
,
[
'D'
]
=
13
,
[
'o'
]
=
24
,
[
154
]
=
KO
,
[
197
]
=
KO
,
[
240
]
=
KO
,
[
26
]
=
KO
,
[
'E'
]
=
14
,
[
'p'
]
=
25
,
[
155
]
=
KO
,
[
198
]
=
KO
,
[
241
]
=
KO
,
[
27
]
=
KO
,
[
'F'
]
=
15
,
[
'q'
]
=
26
,
[
156
]
=
KO
,
[
199
]
=
KO
,
[
242
]
=
KO
,
[
28
]
=
KO
,
[
'G'
]
=
16
,
[
'r'
]
=
27
,
[
157
]
=
KO
,
[
200
]
=
KO
,
[
243
]
=
KO
,
[
29
]
=
KO
,
[
'H'
]
=
17
,
[
's'
]
=
28
,
[
158
]
=
KO
,
[
201
]
=
KO
,
[
244
]
=
KO
,
[
30
]
=
KO
,
[
'I'
]
=
18
,
[
't'
]
=
29
,
[
159
]
=
KO
,
[
202
]
=
KO
,
[
245
]
=
KO
,
[
31
]
=
KO
,
[
'J'
]
=
19
,
[
'u'
]
=
30
,
[
160
]
=
KO
,
[
203
]
=
KO
,
[
246
]
=
KO
,
[
32
]
=
KO
,
[
'K'
]
=
20
,
[
'v'
]
=
31
,
[
161
]
=
KO
,
[
204
]
=
KO
,
[
247
]
=
KO
,
[
33
]
=
KO
,
[
'L'
]
=
21
,
[
'w'
]
=
KO
,
[
162
]
=
KO
,
[
205
]
=
KO
,
[
248
]
=
KO
,
[
34
]
=
KO
,
[
'M'
]
=
22
,
[
'x'
]
=
KO
,
[
163
]
=
KO
,
[
206
]
=
KO
,
[
249
]
=
KO
,
[
35
]
=
KO
,
[
'N'
]
=
23
,
[
'y'
]
=
KO
,
[
164
]
=
KO
,
[
207
]
=
KO
,
[
250
]
=
KO
,
[
36
]
=
KO
,
[
'O'
]
=
24
,
[
'z'
]
=
KO
,
[
165
]
=
KO
,
[
208
]
=
KO
,
[
251
]
=
KO
,
[
37
]
=
KO
,
[
'P'
]
=
25
,
[
123
]
=
KO
,
[
166
]
=
KO
,
[
209
]
=
KO
,
[
252
]
=
KO
,
[
38
]
=
KO
,
[
'Q'
]
=
26
,
[
124
]
=
KO
,
[
167
]
=
KO
,
[
210
]
=
KO
,
[
253
]
=
KO
,
[
39
]
=
KO
,
[
'R'
]
=
27
,
[
125
]
=
KO
,
[
168
]
=
KO
,
[
211
]
=
KO
,
[
254
]
=
KO
,
[
40
]
=
KO
,
[
'S'
]
=
28
,
[
126
]
=
KO
,
[
169
]
=
KO
,
[
212
]
=
KO
,
[
255
]
=
KO
,
[
41
]
=
KO
,
[
'T'
]
=
29
,
[
127
]
=
KO
,
[
170
]
=
KO
,
[
213
]
=
KO
,
[
42
]
=
KO
,
[
'U'
]
=
30
,
[
128
]
=
KO
,
[
171
]
=
KO
,
[
214
]
=
KO
,
};
int32_t
base32hex_decode
(
const
uint8_t
*
in
,
const
uint32_t
in_len
,
uint8_t
*
out
,
const
uint32_t
out_len
)
{
// Checking inputs.
if
(
in
==
NULL
||
out
==
NULL
)
{
return
-
1
;
}
if
(
in_len
>
INT32_MAX
||
out_len
<
((
in_len
+
7
)
/
8
)
*
5
)
{
return
-
1
;
}
if
((
in_len
%
8
)
!=
0
)
{
return
-
1
;
}
const
uint8_t
*
stop
=
in
+
in_len
;
uint8_t
*
bin
=
out
;
uint8_t
pad_len
=
0
;
uint8_t
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
,
c8
;
// Decoding loop takes 8 characters and creates 5 bytes.
while
(
in
<
stop
)
{
// Filling and transforming 8 Base32hex chars.
c1
=
base32hex_dec
[
in
[
0
]];
c2
=
base32hex_dec
[
in
[
1
]];
c3
=
base32hex_dec
[
in
[
2
]];
c4
=
base32hex_dec
[
in
[
3
]];
c5
=
base32hex_dec
[
in
[
4
]];
c6
=
base32hex_dec
[
in
[
5
]];
c7
=
base32hex_dec
[
in
[
6
]];
c8
=
base32hex_dec
[
in
[
7
]];
// Check 8. char if is bad or padding.
if
(
c8
>=
PD
)
{
if
(
c8
==
PD
&&
pad_len
==
0
)
{
pad_len
=
1
;
}
else
{
return
-
1
;
}
}
// Check 7. char if is bad or padding (if so, 6. must be too).
if
(
c7
>=
PD
)
{
if
(
c7
==
PD
&&
c6
==
PD
&&
pad_len
==
1
)
{
pad_len
=
3
;
}
else
{
return
-
1
;
}
}
// Check 6. char if is bad or padding.
if
(
c6
>=
PD
)
{
if
(
!
(
c6
==
PD
&&
pad_len
==
3
))
{
return
-
1
;
}
}
// Check 5. char if is bad or padding.
if
(
c5
>=
PD
)
{
if
(
c5
==
PD
&&
pad_len
==
3
)
{
pad_len
=
4
;
}
else
{
return
-
1
;
}
}
// Check 4. char if is bad or padding (if so, 3. must be too).
if
(
c4
>=
PD
)
{
if
(
c4
==
PD
&&
c3
==
PD
&&
pad_len
==
4
)
{
pad_len
=
6
;
}
else
{
return
-
1
;
}
}
// Check 3. char if is bad or padding.
if
(
c3
>=
PD
)
{
if
(
!
(
c3
==
PD
&&
pad_len
==
6
))
{
return
-
1
;
}
}
// 1. and 2. chars must not be padding.
if
(
c2
>=
PD
||
c1
>=
PD
)
{
return
-
1
;
}
// Computing of output data based on padding length.
switch
(
pad_len
)
{
case
0
:
bin
[
4
]
=
(
c7
<<
5
)
+
c8
;
case
1
:
bin
[
3
]
=
(
c5
<<
7
)
+
(
c6
<<
2
)
+
(
c7
>>
3
);
case
3
:
bin
[
2
]
=
(
c4
<<
4
)
+
(
c5
>>
1
);
case
4
:
bin
[
1
]
=
(
c2
<<
6
)
+
(
c3
<<
1
)
+
(
c4
>>
4
);
case
6
:
bin
[
0
]
=
(
c1
<<
3
)
+
(
c2
>>
2
);
}
// Update output end.
switch
(
pad_len
)
{
case
0
:
bin
+=
5
;
break
;
case
1
:
bin
+=
4
;
break
;
case
3
:
bin
+=
3
;
break
;
case
4
:
bin
+=
2
;
break
;
case
6
:
bin
+=
1
;
break
;
}
in
+=
8
;
}
return
(
bin
-
out
);
}
lib/dnssec/packet/pkt
.h
→
contrib/base32hex
.h
View file @
f474ee26
/* Copyright (C) 201
5
CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 201
1
CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
...
...
@@ -13,15 +13,40 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Base32hex implementation (RFC 4648).
*
* \note Input Base32hex string can contain a-v characters. These characters
* are considered as A-V equivalent.
*
* \addtogroup contrib
* @{
*/
#pragma once
#include
<
libknot/packet/pk
t.h>
#include
<
stdin
t.h>
/**
* Check whether packet contains given type.
* @param pkt Packet to seek through.
* @param type RR type to search for.
* @return True if found.
/*!
* \brief Decodes text data using Base32hex.
*
* \note Input data needn't be terminated with '\0'.
*
* \note Input data must be continuous Base32hex string!
*
* \param in Input text data.
* \param in_len Length of input string.
* \param out Output data buffer.
* \param out_len Size of output buffer.
*
* \retval >=0 length of output data.
* \retval KNOT_E* if error.
*/
bool
_knot_pkt_has_type
(
const
knot_pkt_t
*
pkt
,
uint16_t
type
);
int32_t
base32hex_decode
(
const
uint8_t
*
in
,
const
uint32_t
in_len
,
uint8_t
*
out
,
const
uint32_t
out_len
);
/*! @} */
contrib/contrib.mk
View file @
f474ee26
...
...
@@ -4,7 +4,8 @@ contrib_SOURCES := \
contrib/ccan/isaac/isaac.c
\
contrib/ccan/json/json.c
\
contrib/ucw/mempool.c
\
contrib/murmurhash3/murmurhash3.c
contrib/murmurhash3/murmurhash3.c
\
contrib/base32hex.c
contrib_CFLAGS
:=
-fPIC
contrib_TARGET
:=
$(
abspath
contrib
)
/contrib
$(AREXT)
$(eval
$(call
make_static,contrib,contrib))
contrib/wire.h
0 → 100644
View file @
f474ee26
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Wire integer operations.
*
* \addtogroup contrib
* @{
*/
#pragma once
#include
<stdint.h>
#include
<string.h>
#if defined(__linux__)
# include <endian.h>
# ifndef be64toh
# include <arpa/inet.h>
# include <byteswap.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# define be16toh(x) ntohs(x)
# define be32toh(x) ntohl(x)
# define be64toh(x) bswap_64 (x)
# define le16toh(x) (x)
# define le32toh(x) (x)
# define le64toh(x) (x)
# else
# define be16toh(x) (x)
# define be32toh(x) (x)
# define be64toh(x) (x)
# define le16toh(x) ntohs(x)
# define le32toh(x) ntohl(x)
# define le64toh(x) bswap_64 (x)
# endif
# endif
#elif defined(__FreeBSD__) || defined(__NetBSD__)
# include <sys/endian.h>
#elif defined(__OpenBSD__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define be16toh(x) OSSwapBigToHostInt16(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define htobe16(x) OSSwapHostToBigInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
#endif
/*!
* \brief Reads 2 bytes from the wireformat data.
*
* \param pos Data to read the 2 bytes from.
*
* \return The 2 bytes read, in host byte order.
*/
inline
static
uint16_t
wire_read_u16
(
const
uint8_t
*
pos
)
{
return
be16toh
(
*
(
uint16_t
*
)
pos
);
}
/*!
* \brief Reads 4 bytes from the wireformat data.
*
* \param pos Data to read the 4 bytes from.
*
* \return The 4 bytes read, in host byte order.
*/
inline
static
uint32_t
wire_read_u32
(
const
uint8_t
*
pos
)
{
return
be32toh
(
*
(
uint32_t
*
)
pos
);
}
/*!
* \brief Reads 6 bytes from the wireformat data.
*
* \param pos Data to read the 6 bytes from.
*
* \return The 6 bytes read, in host byte order.
*/
inline
static
uint64_t
wire_read_u48
(
const
uint8_t
*
pos
)
{
uint64_t
input
=
0
;
memcpy
((
uint8_t
*
)
&
input
+
1
,
pos
,
6
);
return
be64toh
(
input
)
>>
8
;
}
/*!
* \brief Read 8 bytes from the wireformat data.
*
* \param pos Data to read the 8 bytes from.
*
* \return The 8 bytes read, in host byte order.
*/
inline
static
uint64_t
wire_read_u64
(
const
uint8_t
*
pos
)
{
return
be64toh
(
*
(
uint64_t
*
)
pos
);
}
/*!
* \brief Writes 2 bytes in wireformat.
*
* The data are stored in network byte order (big endian).
*
* \param pos Position where to put the 2 bytes.
* \param data Data to put.
*/
inline
static
void
wire_write_u16
(
uint8_t
*
pos
,
uint16_t
data
)
{
*
(
uint16_t
*
)
pos
=
htobe16
(
data
);
}
/*!
* \brief Writes 4 bytes in wireformat.
*
* The data are stored in network byte order (big endian).
*
* \param pos Position where to put the 4 bytes.
* \param data Data to put.
*/
inline
static
void
wire_write_u32
(
uint8_t
*
pos
,
uint32_t
data
)
{
*
(
uint32_t
*
)
pos
=
htobe32
(
data
);
}
/*!
* \brief Writes 6 bytes in wireformat.
*
* The data are stored in network byte order (big endian).
*
* \param pos Position where to put the 4 bytes.
* \param data Data to put.
*/
inline
static
void
wire_write_u48
(
uint8_t
*
pos
,
uint64_t
data
)
{
uint64_t
swapped
=
htobe64
(
data
<<
8
);
memcpy
(
pos
,
(
uint8_t
*
)
&
swapped
+
1
,
6
);
}
/*!
* \brief Writes 8 bytes in wireformat.
*
* The data are stored in network byte order (big endian).
*
* \param pos Position where to put the 8 bytes.
* \param data Data to put.
*/
inline
static
void
wire_write_u64
(
uint8_t
*
pos
,
uint64_t
data
)
{
*
(
uint64_t
*
)
pos
=
htobe64
(
data
);
}
/*! @} */
daemon/bindings.c
View file @
f474ee26
...
...
@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<assert.h>
#include
<uv.h>
#include
<contrib/cleanup.h>
#include
<libknot/descriptor.h>
...
...
@@ -334,11 +335,11 @@ static int cache_backends(lua_State *L)
static
int
cache_count
(
lua_State
*
L
)
{
struct
engine
*
engine
=
engine_luaget
(
L
);
const
name
db_api_t
*
storage
=
engine
->
resolver
.
cache
.
api
;
const
knot_
db_api_t
*
storage
=
engine
->
resolver
.
cache
.
api
;
/* Fetch item count */
struct
kr_cache_txn
txn
;
int
ret
=
kr_cache_txn_begin
(
&
engine
->
resolver
.
cache
,
&
txn
,
NAME
DB_RDONLY
);
int
ret
=
kr_cache_txn_begin
(
&
engine
->
resolver
.
cache
,
&
txn
,
KNOT_
DB_RDONLY
);
if
(
ret
!=
0
)
{
format_error
(
L
,
kr_strerror
(
ret
));
lua_error
(
L
);
...
...
daemon/daemon.mk
View file @
f474ee26
...
...
@@ -24,7 +24,7 @@ bindings-install: $(kresd_DIST) $(DESTDIR)$(MODULEDIR)
kresd_CFLAGS
:=
-fPIE
kresd_DEPEND
:=
$(libkres)
$(contrib)
kresd_LIBS
:=
$(libkres_TARGET)
$(contrib_TARGET)
$(libknot_LIBS)
$(libdnssec_LIBS)
$(libuv_LIBS)
$(lua_LIBS)
kresd_LIBS
:=
$(libkres_TARGET)
$(contrib_TARGET)
$(libknot_LIBS)
$(libzscanner_LIBS)
$(libdnssec_LIBS)
$(libuv_LIBS)
$(lua_LIBS)
# Make binary
ifeq
($(HAS_lua)|$(HAS_libuv), yes|yes)
...
...
daemon/engine.c
View file @
f474ee26
...
...
@@ -21,9 +21,9 @@
#include
<unistd.h>
#include
<grp.h>
#include
<pwd.h>
#include
<libknot/internal/
mempattern.h>
/*
#include <libknot/
internal/namedb/namedb_trie.h> @todo Not supported (doesn't keep value copy) */
#include
<
libknot/internal/namedb/namedb_lmdb
.h>
/*
#include <libknot/internal/
namedb/knot_db_trie.h> @todo Not supported (doesn't keep value copy) */
#include
<libknot/
db/db_lmdb.h>
#include
<
zscanner/scanner
.h>
#include
"daemon/engine.h"
#include
"daemon/bindings.h"
...
...
@@ -177,7 +177,7 @@ static int l_option(lua_State *L)
unsigned
opt_code
=
0
;
if
(
lua_isstring
(
L
,
1
))
{
const
char
*
opt
=
lua_tostring
(
L
,
1
);
for
(
const
lookup_t
able_t
*
it
=
kr_query_flag_names
();
it
->
name
;
++
it
)
{
for
(
const
knot_
lookup_t
*
it
=
kr_query_flag_names
();
it
->
name
;
++
it
)
{
if
(
strcmp
(
it
->
name
,
opt
)
==
0
)
{
opt_code
=
it
->
id
;
break
;
...
...
@@ -200,6 +200,52 @@ static int l_option(lua_State *L)
return
1
;
}
/** Enable/disable trust anchor. */
static
int
l_trustanchor
(
lua_State
*
L
)
{
struct
engine
*
engine
=
engine_luaget
(
L
);
const
char
*
anchor
=
lua_tostring
(
L
,
1
);
bool
enable
=
lua_isboolean
(
L
,
2
)
?
lua_toboolean
(
L
,
2
)
:
true
;
if
(
!
anchor
||
strlen
(
anchor
)
==
0
)
{
return
0
;
}
/* If disabling, parse the owner string only. */
if
(
!
enable
)
{
knot_dname_t
*
owner
=
knot_dname_from_str
(
NULL
,
anchor
,
KNOT_DNAME_MAXLEN
);
if
(
!
owner
)
{
lua_pushstring
(
L
,
"invalid trust anchor owner"
);
lua_error
(
L
);
}
lua_pushboolean
(
L
,
kr_ta_del
(
&
engine
->
resolver
.
trust_anchors
,
owner
)
==
0
);
free
(
owner
);
return
1
;
}
/* Parse the record */
zs_scanner_t
*
zs
=
malloc
(
sizeof
(
*
zs
));
if
(
!
zs
||
zs_init
(
zs
,
"."
,
1
,
0
)
!=
0
)
{
free
(
zs
);
lua_pushstring
(
L
,
"not enough memory"
);
lua_error
(
L
);
}
int
ok
=
zs_set_input_string
(
zs
,
anchor
,
strlen
(
anchor
))
==
0
&&
zs_parse_all
(
zs
)
==
0
;
/* Add it to TA set and cleanup */
if
(
ok
)
{
ok
=
kr_ta_add
(
&
engine
->
resolver
.
trust_anchors
,
zs
->
r_owner
,
zs
->
r_type
,
zs
->
r_ttl
,
zs
->
r_data
,
zs
->
r_data_length
)
==
0
;
}
zs_deinit
(
zs
);
free
(
zs
);
/* Report errors */
if
(
!
ok
)
{
lua_pushstring
(
L
,
"failed to process trust anchor RR"
);
lua_error
(
L
);
}
lua_pushboolean
(
L
,
true
);
return
1
;
}
/** Unpack JSON object to table */
static
void
l_unpack_json
(
lua_State
*
L
,
JsonNode
*
table
)
{
...
...
@@ -320,9 +366,9 @@ static int l_trampoline(lua_State *L)
*/
/** @internal Make lmdb options. */
void
*
name
db_lmdb_mkopts
(
const
char
*
conf
,
size_t
maxsize
)
void
*
knot_
db_lmdb_mkopts
(
const
char
*
conf
,
size_t
maxsize
)
{
struct
name
db_lmdb_opts
*
opts
=
malloc
(
sizeof
(
*
opts
));
struct
knot_
db_lmdb_opts
*
opts
=
malloc
(
sizeof
(
*
opts
));
if
(
opts
)
{
memset
(
opts
,
0
,
sizeof
(
*
opts
));
opts
->
path
=
(
conf
&&
strlen
(
conf
))
?
conf
:
"."
;
...
...
@@ -366,7 +412,7 @@ static int init_resolver(struct engine *engine)
/* Initialize storage backends */
struct
storage_api
lmdb
=
{
"lmdb://"
,
name
db_lmdb_api
,
name
db_lmdb_mkopts
"lmdb://"
,
knot_
db_lmdb_api
,
knot_
db_lmdb_mkopts
};
return
array_push
(
engine
->
storage_registry
,
lmdb
);
...