Skip to content

Commit

Permalink
DnsMessage support add and encode raw record (#1691)
Browse files Browse the repository at this point in the history
  • Loading branch information
kedixa authored Feb 7, 2025
1 parent 21b48e6 commit 5fc5722
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit 5fc5722

Please sign in to comment.