commit e25547dd9ccda4ebda96d4d0370709580d1a1c35
parent 7814ccf5ac325814034b7e28df55e69af1ed3fc0
Author: Conrad Hoffmann <ch@bitfehler.net>
Date: Tue, 11 Apr 2023 11:20:06 +0200
net::dns: add support for CAA records
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
Diffstat:
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/net/dns/decode.ha b/net/dns/decode.ha
@@ -193,6 +193,8 @@ fn decode_rdata(dec: *decoder, rtype: rtype, rlen: size) (rdata | format) = {
return decode_a(&sub);
case rtype::AAAA =>
return decode_aaaa(&sub);
+ case rtype::CAA =>
+ return decode_caa(&sub);
case rtype::CNAME =>
return decode_cname(&sub);
case rtype::MX =>
@@ -230,6 +232,33 @@ fn decode_aaaa(dec: *decoder) (rdata | format) = {
return ip: aaaa;
};
+fn decode_caa(dec: *decoder) (rdata | format) = {
+ let flags = decode_u8(dec)?;
+ let tag_len = decode_u8(dec)?;
+
+ if (len(dec.cur) < tag_len) {
+ return format;
+ };
+ let tag = match(strings::fromutf8(dec.cur[..tag_len])) {
+ case let t: str =>
+ yield t;
+ case =>
+ return format;
+ };
+ let value = match (strings::fromutf8(dec.cur[tag_len..])) {
+ case let v: str =>
+ yield v;
+ case =>
+ return format;
+ };
+
+ return caa {
+ flags = flags,
+ tag = strings::dup(tag),
+ value = strings::dup(value),
+ };
+};
+
fn decode_cname(dec: *decoder) (rdata | format) = {
return cname {
name = decode_name(dec)?,
diff --git a/net/dns/types.ha b/net/dns/types.ha
@@ -18,6 +18,7 @@ export type rtype = enum u16 {
AAAA = 28,
SRV = 33,
DNSKEY = 48,
+ CAA = 257,
};
// Question type (superset of [[rtype]]).
@@ -36,6 +37,7 @@ export type qtype = enum u16 {
AXFR = 252,
// *
ALL = 255,
+ CAA = 257,
};
// Class type (e.g. Internet).
@@ -133,6 +135,13 @@ export type a = ip::addr4;
// An AAAA record.
export type aaaa = ip::addr6;
+// A CAA record.
+export type caa = struct {
+ flags: u8,
+ tag: str,
+ value: str,
+};
+
// A CNAME record.
export type cname = struct {
name: []str,
@@ -174,7 +183,7 @@ export type txt = [][]u8;
export type unknown_rdata = []u8;
// Tagged union of supported rdata types.
-export type rdata = (a | aaaa | cname | mx | ns | soa | srv | txt | unknown_rdata);
+export type rdata = (a | aaaa | caa | cname | mx | ns | soa | srv | txt | unknown_rdata);
// A DNS message, Hare representation. See [[encode]] and [[decode]] for the DNS
// representation.
@@ -219,6 +228,9 @@ fn rrecord_finish(rr: *rrecord) void = {
match (rr.rdata) {
case let cn: cname =>
strings::freeall(cn.name);
+ case let ca: caa =>
+ free(ca.tag);
+ free(ca.value);
case let mx: mx =>
strings::freeall(mx.name);
case let ns: ns =>