dns: support domain compress.

This commit is contained in:
Nick Peng
2022-04-05 21:21:33 +08:00
parent 24661c2419
commit 92af4c05c0
4 changed files with 570 additions and 358 deletions

886
src/dns.c

File diff suppressed because it is too large Load Diff

View File

@@ -113,11 +113,15 @@ struct dns_head {
unsigned short nrcount; /* number of addititional resource entries */ unsigned short nrcount; /* number of addititional resource entries */
} __attribute__((packed, aligned(2))); } __attribute__((packed, aligned(2)));
struct dns_rrs { #define DNS_PACKET_DICT_SIZE 16
unsigned short next; struct dns_packet_dict_item {
unsigned short len; unsigned pos;
dns_type_t type; unsigned int hash;
unsigned char data[0]; };
struct dns_packet_dict {
short dict_count;
struct dns_packet_dict_item names[DNS_PACKET_DICT_SIZE];
}; };
/* packet haed */ /* packet haed */
@@ -130,21 +134,24 @@ struct dns_packet {
unsigned short optcount; unsigned short optcount;
unsigned short optional; unsigned short optional;
unsigned short payloadsize; unsigned short payloadsize;
struct dns_packet_dict namedict;
int size; int size;
int len; int len;
unsigned char data[0]; unsigned char data[0];
}; };
/* RRS encode/decode context */ struct dns_rrs {
struct dns_data_context { struct dns_packet *packet;
unsigned char *data; unsigned short next;
unsigned char *ptr; unsigned short len;
unsigned int maxsize; dns_type_t type;
unsigned char data[0];
}; };
/* packet encode/decode context */ /* packet encode/decode context */
struct dns_context { struct dns_context {
struct dns_packet *packet; struct dns_packet *packet;
struct dns_packet_dict *namedict;
unsigned char *data; unsigned char *data;
unsigned int maxsize; unsigned int maxsize;
unsigned char *ptr; unsigned char *ptr;
@@ -234,4 +241,12 @@ int dns_encode(unsigned char *data, int size, struct dns_packet *packet);
int dns_packet_init(struct dns_packet *packet, int size, struct dns_head *head); int dns_packet_init(struct dns_packet *packet, int size, struct dns_head *head);
struct dns_update_param {
int id;
int ip_ttl;
int cname_ttl;
};
int dns_packet_update(unsigned char *data, int size, struct dns_update_param *param);
#endif #endif

View File

@@ -1176,11 +1176,13 @@ static int _config_iplist_rule(char *subnet, enum address_rule rule)
static int _config_qtype_soa(void *data, int argc, char *argv[]) static int _config_qtype_soa(void *data, int argc, char *argv[])
{ {
struct dns_qtype_soa_list *soa_list; struct dns_qtype_soa_list *soa_list;
int i = 0;
if (argc <= 1) { if (argc <= 1) {
return -1; return -1;
} }
for (int i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
soa_list = malloc(sizeof(*soa_list)); soa_list = malloc(sizeof(*soa_list));
if (soa_list == NULL) { if (soa_list == NULL) {
tlog(TLOG_ERROR, "cannot malloc memory"); tlog(TLOG_ERROR, "cannot malloc memory");

View File

@@ -1049,6 +1049,7 @@ void print_stack(void)
{ {
const size_t max_buffer = 30; const size_t max_buffer = 30;
void *buffer[max_buffer]; void *buffer[max_buffer];
int idx = 0;
struct backtrace_state state = {buffer, buffer + max_buffer}; struct backtrace_state state = {buffer, buffer + max_buffer};
_Unwind_Backtrace(unwind_callback, &state); _Unwind_Backtrace(unwind_callback, &state);
@@ -1058,7 +1059,7 @@ void print_stack(void)
} }
tlog(TLOG_FATAL, "Stack:"); tlog(TLOG_FATAL, "Stack:");
for (int idx = 0; idx < frame_num; ++idx) { for (idx = 0; idx < frame_num; ++idx) {
const void *addr = buffer[idx]; const void *addr = buffer[idx];
const char *symbol = ""; const char *symbol = "";