Commit 5b122cf3 authored by Jan Kadlec's avatar Jan Kadlec

Merge branch 'branch-1.4prep' into dsfix.

There were many conflicts, needs a test.

Conflicts:
	src/libknot/updates/xfr-in.c
	src/zscanner/scanner.c
parents b85bc948 eea34622
......@@ -13,6 +13,8 @@
/src/Makefile.in
/src/tests/Makefile
/src/tests/Makefile.in
/src/zscanner/Makefile
/src/zscanner/Makefile.in
/samples/Makefile
/samples/Makefile.in
/doc/Makefile
......@@ -41,18 +43,17 @@
/samples/knot.sample.conf
/src/stamp-*
/doc/html/
# Binaries
/src/tests/unittests
/src/zscanner-tool
/src/knotc
/src/knotd
/src/knot-zcompile
/INSTALL
/m4/libtool.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/lt~obsolete.m4
/INSTALL
# Binaries
/src/tests/unittests
/src/zscanner/zscanner-tool
/src/knotc
/src/knotd
/src/kdig
/src/khost
/src/knsupdate
......@@ -65,8 +66,9 @@
/src/tests/libknot/raw_data_queries.rc
/src/tests/libknot/realdata/
/src/tests/sample_conf.rc
src/zscanner/descriptor.h
src/zscanner/descriptor.c
src/zscanner/test/cases/06-0_INCLUDE.in
src/zscanner/test/cases/06-3_INCLUDE.in
src/zscanner/test/cases/06-4_INCLUDE.in
src/zscanner/test/run_tests.sh
/knot-*/
......@@ -14,3 +14,4 @@ Known bugs
==========
* ACL may not always find the best match so it may behave counter-intuitively.
* Rarely, incremental transfer fails to reschedule
......@@ -235,8 +235,6 @@ src/tests/libknot/wire_tests.h
src/tests/libknot/ztree_tests.c
src/tests/libknot/ztree_tests.h
src/tests/unittests_main.c
src/tests/zscanner/zscanner_tests.c
src/tests/zscanner/zscanner_tests.h
src/utils/common/exec.c
src/utils/common/exec.h
src/utils/common/msg.c
......@@ -262,6 +260,9 @@ src/utils/nsupdate/nsupdate_exec.h
src/utils/nsupdate/nsupdate_main.c
src/utils/nsupdate/nsupdate_params.c
src/utils/nsupdate/nsupdate_params.h
src/zscanner/Makefile.am
src/zscanner/error.c
src/zscanner/error.h
src/zscanner/file_loader.c
src/zscanner/file_loader.h
src/zscanner/scanner.c
......@@ -275,3 +276,4 @@ src/zscanner/test/processing.h
src/zscanner/test/tests.c
src/zscanner/test/tests.h
src/zscanner/test/zscanner-tool.c
src/zscanner/zscanner.h
Knot DNS NEWS
v1.3.0-rc5 - Jul 29, 2013
-------------------------
Features:
* Much faster bootstrap of many zones
Bugfixes:
* Removed deprecated 'knotc -w' option
* Slave ignores out-of-zone records in zone
* Support for obsolete types in zone transfers
* Slave zone file names fixes
* Long transfers being randomly dropped
v1.3.0-rc4 - Jul 15, 2013
-------------------------
Features:
......
# -*- Autoconf -*-
AC_PREREQ([2.60])
AC_INIT([knot], [1.3.0-rc4], [knot-dns@labs.nic.cz])
AC_INIT([knot], [1.3.0-rc5], [knot-dns@labs.nic.cz])
AM_INIT_AUTOMAKE([gnits subdir-objects dist-bzip2 dist-xz -Wall -Werror])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([src/knot/main.c])
......@@ -116,32 +116,26 @@ AC_ARG_ENABLE([debuglevel],
;;
esac], [])
AX_MSG_WAITFORONE
# recvmmsg() (valgrind doesn't support it, so disable for debugging)
# The check for struct mmsghdr is required when libc doesn't have an API but the function links
AC_ARG_ENABLE([recvmmsg],
AS_HELP_STRING([--enable-recvmmsg=yes|no], [enable recvmmsg() network API under Linux (kernel support required) (set to 'no' if you have trouble running server under valgrind) [default=yes]]),
[case "${enableval}" in
yes)
if test "$ax_cv_have_msg_waitforone" = "yes"; then
AC_DEFINE([ENABLE_RECVMMSG], [1], [recvmmsg enabled])
recvmmsg=true
else
recvmmsg=false
fi
AC_CHECK_FUNCS([sendmmsg])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[struct mmsghdr v; recvmmsg(0,0,0,0,0);]])],
[AC_DEFINE(HAVE_RECVMMSG, 1, [Define if struct mmsghdr and recvmmsg() exists.])])
;;
no)
recvmmsg=false
;;
*)
AC_MSG_ERROR([bad value ${enableval} for --enable-recvmmsg])
;;
esac], [
if test "$ax_cv_have_msg_waitforone" = "yes"; then
AC_DEFINE([ENABLE_RECVMMSG], [1], [recvmmsg enabled])
recvmmsg=true
else
recvmmsg=false
fi
esac],
[
AC_CHECK_FUNCS([sendmmsg])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[struct mmsghdr v; recvmmsg(0,0,0,0,0);]])],
[AC_DEFINE(HAVE_RECVMMSG, 1, [Define if struct mmsghdr and recvmmsg() exists.])])
])
# Enable integrity check
......@@ -302,7 +296,7 @@ AC_TYPE_SSIZE_T
AC_DEFINE([DSFMT_MEXP], [521], [DSFMT parameters])
# Checks for library functions.
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise poll posix_memalign pselect pthread_setaffinity_np regcomp select sendmmsg setgroups])
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise poll posix_memalign pselect pthread_setaffinity_np regcomp select setgroups])
# Check for cpu_set_t/cpuset_t compatibility
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[cpu_set_t set; CPU_ZERO(&set);]])],
......@@ -316,12 +310,12 @@ gl_VISIBILITY()
CFLAGS="$CFLAGS $CFLAG_VISIBILITY"
AC_CONFIG_FILES([Makefile
samples/Makefile
src/Makefile
src/tests/Makefile
doc/Makefile
man/Makefile
src/zscanner/test/run_tests.sh
src/Makefile
samples/Makefile
src/tests/Makefile
src/zscanner/Makefile
src/zscanner/test/cases/06-3_INCLUDE.in:src/zscanner/test/cases/06-3_INCLUDE.inin
src/zscanner/test/cases/06-4_INCLUDE.in:src/zscanner/test/cases/06-4_INCLUDE.inin
src/zscanner/test/cases/06-0_INCLUDE.in:src/zscanner/test/cases/06-0_INCLUDE.inin
......@@ -332,4 +326,7 @@ AC_CONFIG_FILES([Makefile
man/knsupdate.1
man/knot.conf.5
])
AC_CONFIG_FILES([src/zscanner/test/run_tests.sh], [chmod a+x src/zscanner/test/run_tests.sh])
AC_OUTPUT
......@@ -274,13 +274,12 @@ Setting to a value greater than @code{0} means that every flow is allowed N resp
It is also possible to configure SLIP interval, which causes every Nth blocked response to be slipped
as a truncated response. Not that some error responses cannot be truncated and are slipped as-is.
For more information, refer to @ref{rate-limit-slip}.
It is advisable to not set slip interval to a value larger than 2, to allow legitimate clients
get at least some level of service.
It is advisable to not set slip interval to a value larger than 1.
Example configuration:
@example
system @{
rate-limit 200; # Each flow is allowed to 200 resp. per second
rate-limit-slip 2; # Every other response is slipped (default)
rate-limit-slip 1; # Every response is slipped (default)
@}
@end example
......@@ -270,7 +270,7 @@ As attacks using DNS/UDP are usually based on a forged source address, an attack
if all responses would be completely blocked. The idea behind SLIP mechanism is to send each Nth response as truncated, thus allowing
client to reconnect via TCP for at least some degree of service. It is worth noting, that some responses can't be truncated (f.e. SERVFAIL).
Default value: @kbd{2}
Default value: @kbd{1}
@node system Example
@subsection system Example
......
......@@ -48,8 +48,6 @@ Parameters:
-v, --verbose Verbose mode - additional runtime
information.
-V, --version Print knot server version.
-w, --wait Wait for the server to finish stop
operations.
-i, --interactive Interactive mode (do not daemonize).
-h, --help Print help and usage.
......
dnl @synopsis AX_MSG_WAITFORONE
dnl @summary Test if the libc/kernel have working recvmmsg MSG_WAITFORONE implementation
dnl @category Misc
dnl
dnl We need recvmmsg to support MSG_WAITFORONE. RHEL 6 (and derivates)
dnl are know for broken implementation
dnl
dnl @version 2013-03-12
dnl @license GPL
dnl @author Ondřej Surý <ondrej@sury.org> and Marek Vavruša <marek@vavrusa.com>
AC_DEFUN([AX_MSG_WAITFORONE],
[
AC_REQUIRE([AC_PROG_CC])
AC_LANG_PUSH([C])
AC_CACHE_CHECK([for recv_mmsg support], [ax_cv_have_msg_waitforone],
[
AC_RUN_IFELSE(
[
AC_LANG_PROGRAM(
[[
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
volatile int _intr = 0;
void sighandle(int s) {
_intr = 1;
}
]],[[
#ifndef MSG_WAITFORONE
return 3; /* Not supported. */
#else
int port = 35353;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) return 1;
struct mmsghdr msgs[2];
struct iovec iovecs[2];
char bufs[2][64];
unsigned i = 0;
memset(msgs, 0, sizeof(msgs));
for (i = 0; i < 2; i++) {
iovecs[i].iov_base = bufs[i];
iovecs[i].iov_len = 64;
msgs[i].msg_hdr.msg_iov = &iovecs[i];
msgs[i].msg_hdr.msg_iovlen = 1;
}
struct sockaddr_in sa; /* Bind to socket. */
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sa.sin_port = htons(port); /* Find free port. */
while (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
if (errno == EADDRINUSE) sa.sin_port = ++port;
else break;
}
int cfd = socket(AF_INET, SOCK_DGRAM, 0); /* Send datagram. */
char pkt[32] = { '\xdf' };
sendto(cfd, pkt, sizeof(pkt), 0, (struct sockaddr*)&sa, sizeof(sa));
/* Broken implementation doesn't respect recvmmsg timeout. */
struct sigaction aset;
memset(&aset, 0, sizeof(struct sigaction));
aset.sa_handler = sighandle;
sigaction(SIGALRM, &aset, NULL);
alarm(1);
int ret = recvmmsg(fd, msgs, 2, MSG_WAITFORONE, NULL);
close(cfd);
close(fd);
if (ret < 0) { /* Completely failed. */
return 2;
}
return _intr; /* OK if not interrupted. */
#endif
]])],
[ax_cv_have_msg_waitforone=yes],
[ax_cv_have_msg_waitforone=no],
[ax_cv_have_msg_waitforone=no])])
AC_LANG_POP([C])
])
......@@ -94,8 +94,8 @@ serves as an example of the configuration for knotc(8) and knotd(8).
# Rate limit SLIP
# Each Nth blocked response will be sent as truncated, this is a way to allow
# legitimate requests to get a chance to reconnect using TCP
# Default: 2
rate-limit-slip 2;
# Default: 1
rate-limit-slip 1;
}
# Includes can be placed anywhere at any level in the configuration file. The
......
......@@ -29,9 +29,6 @@ Verbose mode \- additional runtime information.
\fB\-V\fR, \fB\-\-version\fR
Print knot server version.
.TP
\fB\-w\fR, \fB\-\-wait\fR
Wait for the server to finish stop operation.
.TP
\fB\-i\fR, \fB\-\-interactive\fR
Interactive mode (do not daemonize).
.TP
......
......@@ -88,8 +88,8 @@ system {
# Rate limit SLIP
# Each Nth blocked response will be sent as truncated, this is a way to allow
# legitimate requests to get a chance to reconnect using TCP
# Default: 2
rate-limit-slip 2;
# Default: 1
rate-limit-slip 1;
}
# Includes can be placed anywhere at any level in the configuration file. The
......@@ -183,11 +183,11 @@ groups {
# Section 'control' specifies on which interface to listen for RC commands
control {
# Specifies interface, syntax is exactly the same as in 'interfaces' section
# Default: $(run_dir)/knot.sock
listen-on "knot.sock";
# As an alternative, you can use an IPv4/v6 address and port
# Same syntax as for 'interfaces' items
# listen-on { address 127.0.0.1@5533; }
# Specifies ACL list for remote control
......
......@@ -35,11 +35,11 @@ interfaces {
}
control {
# Specifies interface, syntax is exactly the same as in 'interfaces' section
# Default: knot.sock (relative to rundir)
listen-on "knot.sock";
# As an alternative, you can use an IPv4/v6 address and port
# Same syntax as for 'interfaces' items
# listen-on { address 127.0.0.1@5533; }
# Specifies ACL list for remote control
......
ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4
SUBDIRS = . tests
SUBDIRS = zscanner . tests
sbin_PROGRAMS = knotc knotd
bin_PROGRAMS = kdig khost knsupdate
noinst_PROGRAMS = zscanner-tool
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la libzscanner.la
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la
# $(YACC) will generate header file
AM_CPPFLAGS = -I$(top_srcdir)/src/libknot -DSYSCONFDIR='"$(sysconfdir)"' \
......@@ -14,12 +13,6 @@ AM_YFLAGS = -d
libknotd_la_YFLAGS = -pcf_ -d
libknotd_la_LFLAGS = # TODO: reentrant parser, prefix
EXTRA_DIST = \
zscanner/scanner.rl \
zscanner/scanner_body.rl \
zscanner/test/run_tests.sh \
zscanner/test/cases
BUILT_SOURCES = \
knot/conf/libknotd_la-cf-lex.c \
knot/conf/libknotd_la-cf-parse.c \
......@@ -30,15 +23,6 @@ CLEANFILES = \
knot/conf/libknotd_la-cf-parse.c \
knot/conf/libknotd_la-cf-parse.h
if HAVE_RAGEL
BUILT_SOURCES += zscanner/scanner.c
CLEANFILES += zscanner/scanner.c
zscanner/scanner.c: zscanner/scanner.rl zscanner/scanner_body.rl
$(RAGEL) $(FSM_TYPE) -s -o $@ $(srcdir)/zscanner/scanner.rl
endif
knotc_SOURCES = \
knot/ctl/knotc_main.c
......@@ -283,30 +267,13 @@ libknotd_la_SOURCES = \
knot/zone/estimator.c \
knot/server/server.h
zscanner_tool_SOURCES = \
zscanner/test/zscanner-tool.c \
zscanner/test/tests.h \
zscanner/test/tests.c \
zscanner/test/processing.h \
zscanner/test/processing.c
libzscanner_la_SOURCES = \
zscanner/file_loader.h \
zscanner/file_loader.c \
zscanner/scanner.h \
zscanner/scanner.c \
zscanner/scanner_functions.h \
zscanner/scanner_functions.c
libknotd_la_LIBADD = libknot.la libknots.la @LIBOBJS@
libknots_la_LIBADD = libzscanner.la @LIBOBJS@
libzscanner_la_LIBADD = @LIBOBJS@
libknots_la_LIBADD = zscanner/libzscanner.la @LIBOBJS@
knotd_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
knotc_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
kdig_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
khost_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
knsupdate_LDADD = libknotd.la libknot.la libknots.la libzscanner.la @LIBOBJS@
zscanner_tool_LDADD = libknots.la libknot.la libknotd.la libzscanner.la @LIBOBJS@
knsupdate_LDADD = libknotd.la libknot.la libknots.la zscanner/libzscanner.la @LIBOBJS@
# Create storage and run-time directories
install-data-hook:
......
......@@ -19,88 +19,99 @@
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <limits.h>
#include "common/acl.h"
#include "libknot/util/endian.h"
static inline uint32_t acl_sa_ipv4(sockaddr_t *a) {
static inline uint32_t ipv4_chunk(sockaddr_t *a)
{
/* Stored as big end first. */
return a->addr4.sin_addr.s_addr;
}
static inline uint32_t acl_fill_mask32(short c) {
/*! \todo Consider optimizing using LUT. */
assert(c >= 0 && c <= 32);
unsigned r = 0;
/*! This actually builds big-endian mask
* as we will match against addresses in
* network byte-order (big-endian).
* Otherwise it should be built from
* HO bit -> LO bit.
*/
for (char i = 0; i < c; ++i) {
r |= (1 << i);
}
return r;
static inline uint32_t ipv6_chunk(sockaddr_t *a, uint8_t idx)
{
/* Is byte array, 4x 32bit value. */
return ((uint32_t *)&a->addr6.sin6_addr)[idx];
}
static int acl_compare(void *k1, void *k2)
static inline uint32_t ip_chunk(sockaddr_t *a, uint8_t idx)
{
sockaddr_t* a1 = (sockaddr_t *)k1;
sockaddr_t* a2 = (sockaddr_t *)k2;
if (sockaddr_family(a) == AF_INET)
return ipv4_chunk(a);
/* Check different length, IPv4 goes first. */
int ldiff = a1->len - a2->len;
if (ldiff != 0) {
return ldiff < 0 ? -1 : 1;
}
return ipv6_chunk(a, idx);
}
/* Compare integers if IPv4. */
if (sockaddr_family(a1) == AF_INET) {
/*! \brief Compare chunks using given mask. */
static int cmp_chunk(sockaddr_t *a, sockaddr_t *b, uint8_t idx, uint32_t mask)
{
const uint32_t c1 = ip_chunk(a, idx) & mask;
const uint32_t c2 = ip_chunk(b, idx) & mask;
/* Compute mask .*/
uint32_t mask = acl_fill_mask32(a1->prefix);
if (c1 > c2)
return 1;
if (c1 < c2)
return -1;
return 0;
}
/* Compare address. */
int cmp1 = (acl_sa_ipv4(a1) & mask);
int cmp2 = (acl_sa_ipv4(a2) & mask);
if (cmp1 > cmp2) return 1;
if (cmp1 < cmp2) return -1;
return 0;
/*!
* \brief Calculate bitmask for byte array from the MSB.
*
* \note i.e. 8 means top 8 bits set, 11111111000000000000000000000000
*
* \param nbits number of bits set to 1
* \return mask
*/
static uint32_t acl_fill_mask32(short nbits)
{
assert(nbits >= 0 && nbits <= 32);
uint32_t r = 0;
for (char i = 0; i < nbits; ++i) {
r |= 1 << (31 - i);
}
/* IPv6 matching. */
#ifndef DISABLE_IPV6
if (sockaddr_family(a1) == AF_INET6) {
/* Get mask .*/
short chunk = a1->prefix;
/* Compare address by 32bit chunks. */
uint32_t* a1p = (uint32_t *)(&a1->addr6.sin6_addr);
uint32_t* a2p = (uint32_t *)(&a2->addr6.sin6_addr);
/* Mask 0 = 0 bits to compare from LO->HO (in big-endian).
* Mask 128 = 128 bits to compare.
*/
while (chunk > 0) {
uint32_t mask = 0xffffffff;
if ((size_t)chunk > sizeof(mask) << 3) {
chunk -= sizeof(mask) << 3;
} else {
mask = acl_fill_mask32(chunk);
chunk = 0;
}
int cmp1 = (*(a1p++) & mask);
int cmp2 = (*(a2p++) & mask);
if (cmp1 > cmp2) return 1;
if (cmp1 < cmp2) return -1;
/* Make sure the mask is in network byte order. */
return htonl(r);
}
static int acl_compare(void *k1, void *k2)
{
int ret = 0;
sockaddr_t* a1 = (sockaddr_t *)k1;
sockaddr_t* a2 = (sockaddr_t *)k2;
uint32_t mask = 0xffffffff;
short mask_bits = a1->prefix;
const short chunk_bits = sizeof(mask) * CHAR_BIT;
/* Check different length, IPv4 goes first. */
if (a1->len != a2->len) {
if (a1->len < a2->len)
return -1;
else
return 1;
}
/* At most 4xchunk_bits for IPv6 */
unsigned i = 0;
while (ret == 0 && mask_bits > 0) {
/* Compute mask for current chunk. */
if (mask_bits <= chunk_bits) {
mask = acl_fill_mask32(mask_bits);
mask_bits = 0; /* Last chunk */
} else {
mask_bits -= chunk_bits;
}
return 0;
/* Empty mask - shortcut, we're done. */
if (mask > 0)
ret = cmp_chunk(a1, a2, i, mask);
++i;
}
#endif
return 0;
return ret;
}
acl_t *acl_new(acl_rule_t default_rule, const char *name)
......
......@@ -15,26 +15,20 @@
*/
#include <config.h>
#include "common/descriptor.h"
#include "libknot/util/utils.h" // knot_lookup_table_t
#include <stdio.h> // snprintf
#include <stdlib.h> // strtoul
#include <strings.h> // strcasecmp
/*!
* \brief The last RR type number in the descriptors table.
*/
const int KNOT_RRTYPE_LAST = KNOT_RRTYPE_ANY;
#include <common/descriptor.h>
/*!
* \brief Table with DNS classes.
*/
static knot_lookup_table_t dns_classes[] = {
{ KNOT_CLASS_IN, "IN" },
{ KNOT_CLASS_CH, "CH" },
{ KNOT_CLASS_NONE, "NONE" },
{ KNOT_CLASS_ANY, "ANY" },
{ 0, NULL }
static const char* dns_classes[] = {
[KNOT_CLASS_IN] = "IN",
[KNOT_CLASS_CH] = "CH",
[KNOT_CLASS_NONE] = "NONE",
[KNOT_CLASS_ANY] = "ANY"
};
/*!
......@@ -76,12 +70,12 @@ static const rdata_descriptor_t rdata_descriptors[] = {
KNOT_RDATA_WF_END }, "KEY" },
[KNOT_RRTYPE_AAAA] = { { 16, KNOT_RDATA_WF_END }, "AAAA" },
[KNOT_RRTYPE_LOC] = { { 16, KNOT_RDATA_WF_END }, "LOC" },
[KNOT_RRTYPE_SRV] = { { 6, KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
[KNOT_RRTYPE_SRV] = { { 6, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "SRV" },
[KNOT_RRTYPE_NAPTR] = { { KNOT_RDATA_WF_NAPTR_HEADER,
KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "NAPTR" },
[KNOT_RRTYPE_KX] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
[KNOT_RRTYPE_KX] = { { 2, KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "KX" },
[KNOT_RRTYPE_CERT] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "CERT" },
......@@ -97,10 +91,10 @@ static const rdata_descriptor_t rdata_descriptors[] = {
KNOT_RDATA_WF_END }, "SSHFP" },
[KNOT_RRTYPE_IPSECKEY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "IPSECKEY" },
[KNOT_RRTYPE_RRSIG] = { { 18, KNOT_RDATA_WF_LITERAL_DNAME,
[KNOT_RRTYPE_RRSIG] = { { 18, KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "RRSIG" },
[KNOT_RRTYPE_NSEC] = { { KNOT_RDATA_WF_LITERAL_DNAME,
[KNOT_RRTYPE_NSEC] = { { KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "NSEC" },
[KNOT_RRTYPE_DNSKEY] = { { KNOT_RDATA_WF_REMAINDER,
......@@ -118,7 +112,7 @@ static const rdata_descriptor_t rdata_descriptors[] = {
[KNOT_RRTYPE_NID] = { { 10 }, "NID" },
[KNOT_RRTYPE_L32] = { { 6 }, "L32" },
[KNOT_RRTYPE_L64] = { { 10 }, "L64" },
[KNOT_RRTYPE_LP] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME },
[KNOT_RRTYPE_LP] = { { 2, KNOT_RDATA_WF_UNCOMPRESSED_DNAME },
"LP" },
[KNOT_RRTYPE_EUI48] = { { 6, KNOT_RDATA_WF_END }, "EUI48" },
[KNOT_RRTYPE_EUI64] = { { 8, KNOT_RDATA_WF_END }, "EUI64" },
......@@ -133,18 +127,53 @@ static const rdata_descriptor_t rdata_descriptors[] = {
[KNOT_RRTYPE_AXFR] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "AXFR" },
[KNOT_RRTYPE_ANY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "ANY" },
KNOT_RDATA_WF_END }, "ANY" }
};
/*!
* \brief Some (OBSOLETE) RR type descriptors.
*/
static const rdata_descriptor_t obsolete_rdata_descriptors[] = {
[0] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, NULL },
[KNOT_RRTYPE_MD] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "MD" },
[KNOT_RRTYPE_MF] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "MF" },
[KNOT_RRTYPE_MB] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "MB" },
[KNOT_RRTYPE_MG] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "MG" },
[KNOT_RRTYPE_MR] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "MR" },
[KNOT_RRTYPE_PX] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END }, "PX" },
[KNOT_RRTYPE_NXT] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "NXT" },
};
const rdata_descriptor_t *get_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_ANY && rdata_descriptors[type].type_name != 0) {
if (type <= KNOT_RRTYPE_ANY &&
rdata_descriptors[type].type_name != NULL) {
return &rdata_descriptors[type];
} else {
return &rdata_descriptors[0];
}
}
const rdata_descriptor_t *get_obsolete_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_NXT &&
obsolete_rdata_descriptors[type].type_name != 0) {
return &obsolete_rdata_descriptors[type];
} else {
return &obsolete_rdata_descriptors[0];
}
}
int knot_rrtype_to_string(const uint16_t rrtype,
char *out,
const size_t out_len)
......@@ -153,7 +182,7 @@ int knot_rrtype_to_string(const uint16_t rrtype,
const rdata_descriptor_t *descr = get_rdata_descriptor(rrtype);
if (descr->type_name != 0) {
if (descr->type_name != NULL) {
ret = snprintf(out, out_len, "%s", descr->type_name);
} else {
ret = snprintf(out, out_len, "TYPE%u", rrtype);
......@@ -173,8 +202,8 @@ int knot_rrtype_from_string(const char *name, uint16_t *num)
unsigned long n;
// Try to find name in descriptors table.
for (i = 0; i <= KNOT_RRTYPE_LAST; i++) {
if (rdata_descriptors[i].type_name != 0 &&
for (i = 0; i <= KNOT_RRTYPE_ANY; i++) {