Commit 3eb7278c authored by Daniel Salzman's avatar Daniel Salzman

libknot: add URI and CAA record types support

parent f9ba301d
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 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
......@@ -131,9 +131,15 @@ static const knot_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" },
[KNOT_RRTYPE_URI] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "URI" },
[KNOT_RRTYPE_CAA] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "CAA" },
};
#define MAX_RRTYPE sizeof(rdata_descriptors) / sizeof(knot_rdata_descriptor_t) - 1
/*!
* \brief Some (OBSOLETE) RR type descriptors.
*/
......@@ -161,8 +167,7 @@ static const knot_rdata_descriptor_t obsolete_rdata_descriptors[] = {
_public_
const knot_rdata_descriptor_t *knot_get_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_ANY &&
rdata_descriptors[type].type_name != NULL) {
if (type <= MAX_RRTYPE && rdata_descriptors[type].type_name != NULL) {
return &rdata_descriptors[type];
} else {
return &rdata_descriptors[0];
......@@ -218,7 +223,7 @@ 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_ANY; i++) {
for (i = 0; i <= MAX_RRTYPE; i++) {
if (rdata_descriptors[i].type_name != NULL &&
strcasecmp(rdata_descriptors[i].type_name, name) == 0) {
*num = i;
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 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
......@@ -14,23 +14,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file descriptor.h
* \file
*
* \author Daniel Salzman <daniel.salzman@nic.cz>
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* \addtogroup common_lib
* \addtogroup libknot
* @{
*/
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define KNOT_MAX_RDATA_BLOCKS 8
#define KNOT_MAX_RDATA_DNAMES 2 // update this when defining new RR types
#define KNOT_MAX_RDATA_DNAMES 2 // Update this when defining new RR types!
/*!
* \brief Resource record class codes.
......@@ -115,7 +112,9 @@ enum knot_rr_type {
KNOT_RRTYPE_IXFR = 251, /*!< QTYPE. Incremental zone transfer. */
KNOT_RRTYPE_AXFR = 252, /*!< QTYPE. Authoritative zone transfer. */
KNOT_RRTYPE_ANY = 255 /*!< QTYPE. Any record. */
KNOT_RRTYPE_ANY = 255, /*!< QTYPE. Any record. */
KNOT_RRTYPE_URI = 256, /*!< Uniform resource identifier. */
KNOT_RRTYPE_CAA = 257, /*!< Certification authority restriction. */
};
/*!
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 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
......@@ -549,25 +549,43 @@ static void wire_unknown_to_str(rrset_dump_params_t *p)
p->ret = 0;
}
static void wire_text_to_str(rrset_dump_params_t *p)
static void wire_text_to_str(rrset_dump_params_t *p, bool quote, bool with_header)
{
// First byte is string length.
if (p->in_max < 1) {
return;
size_t in_len = 0;
if (with_header) {
// First byte is string length.
if (p->in_max < 1) {
return;
}
in_len = *(p->in);
p->in++;
p->in_max--;
// Check if the given length makes sense.
if (in_len > p->in_max) {
return;
}
} else {
in_len = p->in_max;
}
size_t in_len = *(p->in);
p->in++;
p->in_max--;
// Check if the given length makes sense.
if (in_len > p->in_max) {
return;
// Check if quotation can ever be disabled (parser protection fallback).
if (!quote) {
for (size_t i = 0; i < in_len; i++) {
if (p->in[i] == ' ') { // Other WS characters are encoded.
quote = true;
break;
}
}
}
// Opening quoatition.
dump_string(p, "\"");
if (p->ret != 0) {
return;
// Opening quotation.
if (quote) {
dump_string(p, "\"");
if (p->ret != 0) {
return;
}
}
// Loop over all characters.
......@@ -605,10 +623,12 @@ static void wire_text_to_str(rrset_dump_params_t *p)
}
}
// Closing quoatition.
dump_string(p, "\"");
if (p->ret != 0) {
return;
// Closing quotation.
if (quote) {
dump_string(p, "\"");
if (p->ret != 0) {
return;
}
}
// String termination.
......@@ -1366,7 +1386,9 @@ static void dnskey_info(const uint8_t *rdata,
2, true, ""); CHECK_RET(p);
#define DUMP_TSIG_DATA wire_len_data_encode_to_str(p, &hex_encode, \
2, true, ""); CHECK_RET(p);
#define DUMP_TEXT wire_text_to_str(p); CHECK_RET(p);
#define DUMP_TEXT wire_text_to_str(p, true, true); CHECK_RET(p);
#define DUMP_LONG_TEXT wire_text_to_str(p, true, false); CHECK_RET(p);
#define DUMP_UNQUOTED wire_text_to_str(p, false, true); CHECK_RET(p);
#define DUMP_BITMAP wire_bitmap_to_str(p); CHECK_RET(p);
#define DUMP_APL wire_apl_to_str(p); CHECK_RET(p);
#define DUMP_LOC wire_loc_to_str(p); CHECK_RET(p);
......@@ -1732,6 +1754,24 @@ static int dump_tsig(DUMP_PARAMS)
DUMP_END;
}
static int dump_uri(DUMP_PARAMS)
{
DUMP_NUM16; DUMP_SPACE;
DUMP_NUM16; DUMP_SPACE;
DUMP_LONG_TEXT; DUMP_SPACE;
DUMP_END;
}
static int dump_caa(DUMP_PARAMS)
{
DUMP_NUM8; DUMP_SPACE;
DUMP_UNQUOTED; DUMP_SPACE;
DUMP_LONG_TEXT; DUMP_SPACE;
DUMP_END;
}
static int dump_unknown(DUMP_PARAMS)
{
if (p->style->wrap) {
......@@ -1876,6 +1916,12 @@ int knot_rrset_txt_dump_data(const knot_rrset_t *rrset,
case KNOT_RRTYPE_TSIG:
ret = dump_tsig(&p);
break;
case KNOT_RRTYPE_URI:
ret = dump_uri(&p);
break;
case KNOT_RRTYPE_CAA:
ret = dump_caa(&p);
break;
default:
ret = dump_unknown(&p);
break;
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 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
......@@ -14,9 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file rrset-dump.h
*
* \author Daniel Salzman <daniel.salzman@nic.cz>
* \file
*
* \brief RRset text dump facility.
*
......
......@@ -57,6 +57,13 @@ l64 L64 10 2001:0DB8:1140:1000
lp LP 10 l64-subnet1.example.com.
eui48 EUI48 00-00-5e-00-53-2a
eui64 EUI64 00-00-5e-ef-10-00-00-2a
; Bind 9.9.5 doesn't support CAA and has wrong URI implementation
;_ftp._tcp URI 10 1 "ftp://ftp1.example.com/public"
;caa CAA 0 issue "ca.example.net"
; CAA 0 iodef "mailto:security@example.com"
; CAA 0 iodef "http://iodef.example.com/"
; CAA 0 issue "ca.example.net; account=230123"
; CAA 128 tbs "Unknown"
; Miscellaneous
empty IN TYPE999 \# 0
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 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
......@@ -93,17 +93,17 @@ int main(int argc, char *argv[])
ok(ret != -1, "get ANY ret");
ok(strcmp(name, "ANY") == 0, "get ANY name");
// 6. TYPE256
descr = knot_get_rdata_descriptor(256);
ok(descr->type_name == 0, "get TYPE256 descriptor name");
// 6. TYPE65535
descr = knot_get_rdata_descriptor(65535);
ok(descr->type_name == 0, "get TYPE65535 descriptor name");
ok(descr->block_types[0] == KNOT_RDATA_WF_REMAINDER,
"get TYPE256 descriptor 1. item type");
"get TYPE65535 descriptor 1. item type");
ok(descr->block_types[1] == KNOT_RDATA_WF_END,
"get TYPE256 descriptor 2. item type");
"get TYPE65535 descriptor 2. item type");
ret = knot_rrtype_to_string(256, name, BUF_LEN);
ok(ret != -1, "get TYPE256 ret");
ok(strcmp(name, "TYPE256") == 0, "get TYPE256 name");
ret = knot_rrtype_to_string(65535, name, BUF_LEN);
ok(ret != -1, "get TYPE65535 ret");
ok(strcmp(name, "TYPE65535") == 0, "get TYPE65535 name");
// Class num to string:
// 7. CLASS0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment