commit 7814ccf5ac325814034b7e28df55e69af1ed3fc0
parent cbfb5948d4cadf07e8d5a3988c381be1dc6d024a
Author: Conrad Hoffmann <ch@bitfehler.net>
Date: Tue, 11 Apr 2023 11:20:05 +0200
net::dns: handle NS, SOA, and SRV records
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
Diffstat:
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/net/dns/decode.ha b/net/dns/decode.ha
@@ -197,6 +197,12 @@ fn decode_rdata(dec: *decoder, rtype: rtype, rlen: size) (rdata | format) = {
return decode_cname(&sub);
case rtype::MX =>
return decode_mx(&sub);
+ case rtype::NS =>
+ return decode_ns(&sub);
+ case rtype::SOA =>
+ return decode_soa(&sub);
+ case rtype::SRV =>
+ return decode_srv(&sub);
case rtype::TXT =>
return decode_txt(&sub);
case =>
@@ -237,6 +243,32 @@ fn decode_mx(dec: *decoder) (rdata | format) = {
};
};
+fn decode_ns(dec: *decoder) (rdata | format) = {
+ return ns {
+ name = decode_name(dec)?,
+ };
+};
+
+fn decode_soa(dec: *decoder) (rdata | format) = {
+ return soa {
+ mname = decode_name(dec)?,
+ rname = decode_name(dec)?,
+ serial = decode_u32(dec)?,
+ refresh = decode_u32(dec)?,
+ retry = decode_u32(dec)?,
+ expire = decode_u32(dec)?,
+ };
+};
+
+fn decode_srv(dec: *decoder) (rdata | format) = {
+ return srv {
+ priority = decode_u16(dec)?,
+ weight = decode_u16(dec)?,
+ port = decode_u16(dec)?,
+ target = decode_name(dec)?,
+ };
+};
+
fn decode_txt(dec: *decoder) (rdata | format) = {
let success = false;
let items: txt = [];
diff --git a/net/dns/types.ha b/net/dns/types.ha
@@ -144,6 +144,29 @@ export type mx = struct {
name: []str,
};
+// An NS record.
+export type ns = struct {
+ name: []str,
+};
+
+// An SOA record.
+export type soa = struct {
+ mname: []str,
+ rname: []str,
+ serial: u32,
+ refresh: u32,
+ retry: u32,
+ expire: u32,
+};
+
+// An SRV record.
+export type srv = struct {
+ priority: u16,
+ weight: u16,
+ port: u16,
+ target: []str,
+};
+
// A TXT record.
export type txt = [][]u8;
@@ -151,7 +174,7 @@ export type txt = [][]u8;
export type unknown_rdata = []u8;
// Tagged union of supported rdata types.
-export type rdata = (a | aaaa | cname | mx | txt | unknown_rdata);
+export type rdata = (a | aaaa | cname | mx | ns | soa | srv | txt | unknown_rdata);
// A DNS message, Hare representation. See [[encode]] and [[decode]] for the DNS
// representation.
@@ -198,6 +221,13 @@ fn rrecord_finish(rr: *rrecord) void = {
strings::freeall(cn.name);
case let mx: mx =>
strings::freeall(mx.name);
+ case let ns: ns =>
+ strings::freeall(ns.name);
+ case let so: soa =>
+ strings::freeall(so.mname);
+ strings::freeall(so.rname);
+ case let sr: srv =>
+ strings::freeall(sr.target);
case let tx: txt =>
bytes_free(tx: [][]u8);
case => void;