Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DnsMessage support add and encode raw record #1691

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/protocol/DnsMessage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static inline int __append_record_list(std::string& s, int *count,

switch (record->type)
{
default: // encode unknown types as raw record
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
__append_uint16(record_buf, record->rdlength);
Expand All @@ -115,7 +116,6 @@ static inline int __append_record_list(std::string& s, int *count,

__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);

break;

case DNS_TYPE_SOA:
Expand All @@ -138,7 +138,6 @@ static inline int __append_record_list(std::string& s, int *count,

__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);

break;
}

Expand All @@ -156,12 +155,13 @@ static inline int __append_record_list(std::string& s, int *count,

__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);

break;
}

case DNS_TYPE_MX:
{
auto *mx = (struct dns_record_mx *)record->rdata;

rdata_buf.clear();
__append_uint16(rdata_buf, mx->preference);
ret = __append_name(rdata_buf, mx->exchange);
Expand All @@ -170,12 +170,8 @@ static inline int __append_record_list(std::string& s, int *count,

__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);

break;
}
default:
// TODO not implement
continue;
}

cnt++;
Expand Down
12 changes: 12 additions & 0 deletions src/protocol/DnsMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ class DnsMessage : public ProtocolMessage
return dns_add_mx_record(name, rclass, ttl, preference, exchange, list);
}

int add_raw_record(int section, const char *name, uint16_t type,
uint16_t rclass, uint32_t ttl,
const void *data, uint16_t dlen)
{
struct list_head *list = get_section(section);

if (!list)
return -1;

return dns_add_raw_record(name, type, rclass, ttl, dlen, data, list);
}

// Inner use only
bool is_single_packet() const
{
Expand Down