commit cbfb5948d4cadf07e8d5a3988c381be1dc6d024a
parent e1f44d28d232640ea2553def2f7cf3418bd66278
Author: Conrad Hoffmann <ch@bitfehler.net>
Date: Tue, 4 Apr 2023 21:51:32 +0200
net::dns: add support for CNAME records
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
Diffstat:
2 files changed, 16 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::CNAME =>
+ return decode_cname(&sub);
case rtype::MX =>
return decode_mx(&sub);
case rtype::TXT =>
@@ -222,6 +224,12 @@ fn decode_aaaa(dec: *decoder) (rdata | format) = {
return ip: aaaa;
};
+fn decode_cname(dec: *decoder) (rdata | format) = {
+ return cname {
+ name = decode_name(dec)?,
+ };
+};
+
fn decode_mx(dec: *decoder) (rdata | format) = {
return mx {
priority = decode_u16(dec)?,
diff --git a/net/dns/types.ha b/net/dns/types.ha
@@ -133,6 +133,11 @@ export type a = ip::addr4;
// An AAAA record.
export type aaaa = ip::addr6;
+// A CNAME record.
+export type cname = struct {
+ name: []str,
+};
+
// An MX record.
export type mx = struct {
priority: u16,
@@ -146,7 +151,7 @@ export type txt = [][]u8;
export type unknown_rdata = []u8;
// Tagged union of supported rdata types.
-export type rdata = (a | aaaa | mx | txt | unknown_rdata);
+export type rdata = (a | aaaa | cname | mx | txt | unknown_rdata);
// A DNS message, Hare representation. See [[encode]] and [[decode]] for the DNS
// representation.
@@ -189,6 +194,8 @@ fn rrecords_free(rrs: []rrecord) void = {
fn rrecord_finish(rr: *rrecord) void = {
strings::freeall(rr.name);
match (rr.rdata) {
+ case let cn: cname =>
+ strings::freeall(cn.name);
case let mx: mx =>
strings::freeall(mx.name);
case let tx: txt =>