commit 8464ed48f4b0608da339399022654e9ed4e92c5a
parent 73ae82e5eb1de4c49ab029cebe20328f3698c57e
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 23 Jun 2021 12:54:53 -0400
net::dns: simplify decode_rrecord
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/net/dns/decode.ha b/net/dns/decode.ha
@@ -33,9 +33,7 @@ fn decode_rrecords(
out: *[]rrecord,
) (void | format) = {
for (let i = 0z; i < count; i += 1) {
- let r = rrecord { ... };
- decode_rrecord(dec, &r)?;
- append(*out, r);
+ append(*out, decode_rrecord(dec)?);
};
};
@@ -65,7 +63,7 @@ fn decode_u32(dec: *decoder) (u32 | format) = {
fn decode_header(dec: *decoder, head: *header) (void | format) = {
head.id = decode_u16(dec)?;
- let rawop = decode_u16(dec)?;
+ const rawop = decode_u16(dec)?;
decode_op(rawop, &head.op);
head.qdcount = decode_u16(dec)?;
head.ancount = decode_u16(dec)?;
@@ -86,10 +84,10 @@ fn decode_op(in: u16, out: *op) void = {
fn decode_name(dec: *decoder) ([]str | format) = {
let names: []str = [];
for (true) {
- let z = dec.cur[0];
+ const z = dec.cur[0];
if (z & 0b11000000 == 0b11000000) {
- let offs = decode_u16(dec)? & ~0b1100000000000000u16;
- let sub = decoder {
+ const offs = decode_u16(dec)? & ~0b1100000000000000u16;
+ const sub = decoder {
buf = dec.buf,
cur = dec.buf[offs..],
...
@@ -102,7 +100,7 @@ fn decode_name(dec: *decoder) ([]str | format) = {
break;
};
- let name = dec.cur[..z];
+ const name = dec.cur[..z];
dec.cur = dec.cur[z..];
for (let i = 0z; i < len(name); i += 1) {
if (!ascii::isascii(name[i]: u32: rune)) {
@@ -124,13 +122,20 @@ fn decode_question(dec: *decoder) (question | format) = {
};
};
-fn decode_rrecord(dec: *decoder, r: *rrecord) (void | format) = {
- r.name = decode_name(dec)?;
- r.rtype = decode_u16(dec)?: rtype;
- r.class = decode_u16(dec)?: class;
- r.ttl = decode_u32(dec)?;
- let rdz = decode_u16(dec)?;
- r.rdata = decode_rdata(dec, r.rtype, rdz)?;
+fn decode_rrecord(dec: *decoder) (rrecord | format) = {
+ const name = decode_name(dec)?;
+ const rtype = decode_u16(dec)?: rtype;
+ const class = decode_u16(dec)?: class;
+ const ttl = decode_u32(dec)?;
+ const rlen = decode_u16(dec)?;
+ const rdata = decode_rdata(dec, rtype, rlen)?;
+ return rrecord {
+ name = name,
+ rtype = rtype,
+ class = class,
+ ttl = ttl,
+ rdata = rdata
+ };
};
fn decode_rdata(dec: *decoder, rtype: rtype, rlen: size) (rdata | format) = {
diff --git a/net/dns/encode.ha b/net/dns/encode.ha
@@ -118,9 +118,9 @@ fn encode_op(op: *op) u16 =
ra = true,
rcode = rcode::SERVER_FAILURE,
};
- let enc = op_encode(&opcode);
+ let enc = encode_op(&opcode);
let opcode2 = op { ... };
- op_decode(enc, &opcode2);
+ decode_op(enc, &opcode2);
assert(opcode.qr == opcode2.qr && opcode.opcode == opcode2.opcode &&
opcode.aa == opcode2.aa && opcode.tc == opcode2.tc &&
opcode.rd == opcode2.rd && opcode.ra == opcode2.ra &&