summaryrefslogtreecommitdiff
path: root/src/libs6dns
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-04-12 00:09:40 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-04-12 00:09:40 +0000
commit665f12a744dea29a4e5437ecca918ed5d57b5744 (patch)
tree1e327fa9a76cda9c7d67a766f7ab289986f43284 /src/libs6dns
parent8cb636aa0671ac3c23009d8ca75245b2c08168c8 (diff)
downloads6-dns-665f12a744dea29a4e5437ecca918ed5d57b5744.tar.xz
Add CAA record support
Diffstat (limited to 'src/libs6dns')
-rw-r--r--src/libs6dns/deps-lib/s6dns4
-rw-r--r--src/libs6dns/s6dns_analyze_qtype_parse.c1
-rw-r--r--src/libs6dns/s6dns_analyze_record_caa.c22
-rw-r--r--src/libs6dns/s6dns_analyze_rtypetable.c1
-rw-r--r--src/libs6dns/s6dns_fmt_caa.c22
-rw-r--r--src/libs6dns/s6dns_message_get_caa.c24
-rw-r--r--src/libs6dns/s6dns_message_parse_answer_caa.c17
7 files changed, 91 insertions, 0 deletions
diff --git a/src/libs6dns/deps-lib/s6dns b/src/libs6dns/deps-lib/s6dns
index b0ae95d..95c2bf5 100644
--- a/src/libs6dns/deps-lib/s6dns
+++ b/src/libs6dns/deps-lib/s6dns
@@ -23,6 +23,7 @@ s6dns_fmt_hinfo.o
s6dns_fmt_mx.o
s6dns_fmt_soa.o
s6dns_fmt_srv.o
+s6dns_fmt_caa.o
s6dns_message_counts_next.o
s6dns_message_counts_pack.o
s6dns_message_counts_unpack.o
@@ -36,6 +37,7 @@ s6dns_message_get_strings.o
s6dns_message_get_mx.o
s6dns_message_get_soa.o
s6dns_message_get_srv.o
+s6dns_message_get_caa.o
s6dns_message_header_pack.o
s6dns_message_header_unpack.o
s6dns_message_header_zero.o
@@ -46,6 +48,7 @@ s6dns_message_parse_answer_hinfo.o
s6dns_message_parse_answer_mx.o
s6dns_message_parse_answer_soa.o
s6dns_message_parse_answer_srv.o
+s6dns_message_parse_answer_caa.o
s6dns_message_parse_answer_strings.o
s6dns_message_parse.o
s6dns_message_parse_getrr.o
@@ -77,6 +80,7 @@ s6dns_analyze_record_hinfo.o
s6dns_analyze_record_mx.o
s6dns_analyze_record_soa.o
s6dns_analyze_record_srv.o
+s6dns_analyze_record_caa.o
s6dns_analyze_record_domain.o
s6dns_analyze_record_strings.o
s6dns_analyze_record_unknown.o
diff --git a/src/libs6dns/s6dns_analyze_qtype_parse.c b/src/libs6dns/s6dns_analyze_qtype_parse.c
index 4898bfd..0764d47 100644
--- a/src/libs6dns/s6dns_analyze_qtype_parse.c
+++ b/src/libs6dns/s6dns_analyze_qtype_parse.c
@@ -29,6 +29,7 @@ static lookuptable_t const table[] =
{ "SIG", S6DNS_T_SIG },
{ "KEY", S6DNS_T_KEY },
{ "AXFR", S6DNS_T_AXFR },
+ { "CAA", S6DNS_T_CAA },
{ 0, 0 }
} ;
diff --git a/src/libs6dns/s6dns_analyze_record_caa.c b/src/libs6dns/s6dns_analyze_record_caa.c
new file mode 100644
index 0000000..fa8ab91
--- /dev/null
+++ b/src/libs6dns/s6dns_analyze_record_caa.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <skalibs/error.h>
+#include <s6-dns/s6dns-message.h>
+#include <s6-dns/s6dns-fmt.h>
+#include <s6-dns/s6dns-analyze.h>
+
+int s6dns_analyze_record_caa (genwrite_t *gp, s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int start)
+{
+ s6dns_message_rr_caa_t caa ;
+ size_t len ;
+ unsigned int pos = start ;
+ char buf[S6DNS_FMT_CAA] ;
+ if (!s6dns_message_get_caa(&caa, packet, packetlen, &pos, rr->rdlength)) return 0 ;
+ if (rr->rdlength != pos - start) return (errno = EPROTO, 0) ;
+ len = s6dns_fmt_caa(buf, S6DNS_FMT_CAA, &caa) ;
+ if (!len) return 0 ;
+ if ((*gp->put)(gp->target, buf, len) < 0) return 0 ;
+ return 1 ;
+}
diff --git a/src/libs6dns/s6dns_analyze_rtypetable.c b/src/libs6dns/s6dns_analyze_rtypetable.c
index 523fc72..d6b52f0 100644
--- a/src/libs6dns/s6dns_analyze_rtypetable.c
+++ b/src/libs6dns/s6dns_analyze_rtypetable.c
@@ -14,6 +14,7 @@ static s6dns_analyze_rtypetable_t const s6dns_analyze_rtypetable_array[] =
{ 16, "TXT", &s6dns_analyze_record_strings },
{ 28, "AAAA", &s6dns_analyze_record_aaaa },
{ 33, "SRV", &s6dns_analyze_record_srv },
+ { 257, "CAA", &s6dns_analyze_record_caa },
{ 0, "unknown", &s6dns_analyze_record_unknown }
} ;
diff --git a/src/libs6dns/s6dns_fmt_caa.c b/src/libs6dns/s6dns_fmt_caa.c
new file mode 100644
index 0000000..7fbf36b
--- /dev/null
+++ b/src/libs6dns/s6dns_fmt_caa.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <skalibs/uint16.h>
+#include <s6-dns/s6dns-fmt.h>
+
+size_t s6dns_fmt_caa (char *s, size_t max, s6dns_message_rr_caa_t const *caa)
+{
+ size_t len = 0, taglen = strlen(caa->tag), valuelen = strlen(caa->value) ;
+ char fmt[UINT16_FMT] ;
+ size_t r = uint16_fmt(fmt, (uint16_t)caa->flags) ;
+ if (r + taglen + valuelen + 2 > max) return (errno = ENAMETOOLONG, 0) ;
+ memcpy(s + len, fmt, r) ;
+ len += r ; s[len++] = ' ' ;
+ memcpy(s + len, caa->tag, taglen) ;
+ len += taglen ; s[len++] = ' ' ;
+ memcpy(s + len, caa->value, valuelen) ;
+ len += valuelen ;
+ return len ;
+}
diff --git a/src/libs6dns/s6dns_message_get_caa.c b/src/libs6dns/s6dns_message_get_caa.c
new file mode 100644
index 0000000..a97b8c0
--- /dev/null
+++ b/src/libs6dns/s6dns_message_get_caa.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <skalibs/error.h>
+#include <s6-dns/s6dns-message.h>
+
+int s6dns_message_get_caa (s6dns_message_rr_caa_t *caa, char const *packet, unsigned int packetlen, unsigned int *pos, uint16_t rdlength)
+{
+ unsigned char taglen ;
+ if (rdlength < 4) return (errno = EPROTO, 0) ;
+ if (*pos + rdlength > packetlen) return (errno = EPROTO, 0) ;
+ caa->flags = packet[(*pos)++] ;
+ taglen = packet[(*pos)++] ;
+ if (rdlength < taglen + 3 || rdlength > taglen + 257) return (errno = EPROTO, 0) ;
+ memcpy(caa->tag, packet + *pos, taglen) ;
+ caa->tag[taglen] = 0 ;
+ *pos += taglen ;
+ memcpy(caa->value, packet + *pos, rdlength - taglen - 2) ;
+ caa->value[rdlength - taglen - 1] = 0 ;
+ *pos += rdlength - taglen - 2 ;
+ return 1 ;
+}
diff --git a/src/libs6dns/s6dns_message_parse_answer_caa.c b/src/libs6dns/s6dns_message_parse_answer_caa.c
new file mode 100644
index 0000000..3b78b43
--- /dev/null
+++ b/src/libs6dns/s6dns_message_parse_answer_caa.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/genalloc.h>
+#include <s6-dns/s6dns-constants.h>
+#include <s6-dns/s6dns-message.h>
+
+int s6dns_message_parse_answer_caa (s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int pos, unsigned int section, void *stuff)
+{
+ if ((section == 2) && (rr->rtype == S6DNS_T_CAA))
+ {
+ genalloc *data = stuff ;
+ s6dns_message_rr_caa_t caa ;
+ if (!s6dns_message_get_caa(&caa, packet, packetlen, &pos, rr->rdlength)) return 0 ;
+ if (!genalloc_append(s6dns_message_rr_caa_t, data, &caa)) return -1 ;
+ }
+ return 1 ;
+}