Skip to content

Commit

Permalink
try fix #180
Browse files Browse the repository at this point in the history
  • Loading branch information
zfl9 committed Jul 12, 2024
1 parent b131599 commit 60a435d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ u16 dns_empty_reply(void *noalias msg, int qnamelen) {
h->answer_count = 0;
h->authority_count = 0;
h->additional_count = 0;
return msg_minlen(qnamelen);
return qnamelen > 0 ? msg_minlen(qnamelen) : sizeof(struct dns_header);
}

// return newlen (0 if failed)
Expand Down
13 changes: 12 additions & 1 deletion src/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn on_query(qmsg: *RcMsg, fdobj: *EvLoop.Fd, src_addr: *const cc.SockAddr, in_qf

if (!dns.check_query(msg, p_ascii_namebuf, &qnamelen)) {
log.warn(@src(), "dns.check_query(fd:%d) failed: invalid query msg", .{fdobj.fd});
return;
return send_reply_xxx(msg, fdobj, src_addr, in_qflags); // make the requester happy
}

const id = dns.get_id(msg);
Expand Down Expand Up @@ -818,6 +818,17 @@ fn send_reply(msg: []const u8, fdobj: *EvLoop.Fd, src_addr: *const cc.SockAddr,
);
}

/// [async]
fn send_reply_xxx(msg: []u8, fdobj: *EvLoop.Fd, src_addr: *const cc.SockAddr, qflags: QueryCtx.Flags) void {
if (msg.len >= dns.header_len())
_ = dns.empty_reply(msg, 0);

if (qflags.has(.from_tcp))
g.evloop.send(fdobj, msg, 0) orelse {} // TODO: error handling
else
_ = cc.sendto(fdobj.fd, msg, 0, src_addr) orelse 0; // TODO: error handling
}

// =========================================================================

/// qctx will be free()
Expand Down

0 comments on commit 60a435d

Please sign in to comment.