test: add test case for ptr, suppress log.

This commit is contained in:
Nick Peng
2023-04-04 23:58:42 +08:00
parent fbdcb7ba41
commit d4e1da9955
8 changed files with 227 additions and 53 deletions

View File

@@ -21,7 +21,7 @@ OBJS=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_co
# cflags
ifndef CFLAGS
ifdef DEBUG
CFLAGS = -g
CFLAGS = -g -DDEBUG
else
CFLAGS = -O2
endif

View File

@@ -849,7 +849,7 @@ int dns_get_A(struct dns_rrs *rrs, char *domain, int maxsize, int *ttl, unsigned
return _dns_get_RAW(rrs, domain, maxsize, ttl, addr, &len);
}
int dns_add_PTR(struct dns_packet *packet, dns_rr_type type, const char *domain, int ttl, char *cname)
int dns_add_PTR(struct dns_packet *packet, dns_rr_type type, const char *domain, int ttl, const char *cname)
{
int rr_len = strnlen(cname, DNS_MAX_CNAME_LEN) + 1;
return _dns_add_RAW(packet, type, DNS_T_PTR, domain, ttl, cname, rr_len);
@@ -1862,7 +1862,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
while (context->ptr - start < rr_len) {
if (_dns_left_len(context) < 4) {
tlog(TLOG_WARN, "data length is invalid, %d:%d", _dns_left_len(context),
tlog(TLOG_DEBUG, "data length is invalid, %d:%d", _dns_left_len(context),
(int)(context->ptr - context->data));
return -1;
}
@@ -1870,7 +1870,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
opt_len = _dns_read_short(&context->ptr);
if (_dns_left_len(context) < opt_len) {
tlog(TLOG_ERROR, "read opt data failed, opt_code = %d, opt_len = %d", opt_code, opt_len);
tlog(TLOG_DEBUG, "read opt data failed, opt_code = %d, opt_len = %d", opt_code, opt_len);
return -1;
}

View File

@@ -257,7 +257,7 @@ int dns_add_A(struct dns_packet *packet, dns_rr_type type, const char *domain, i
unsigned char addr[DNS_RR_A_LEN]);
int dns_get_A(struct dns_rrs *rrs, char *domain, int maxsize, int *ttl, unsigned char addr[DNS_RR_A_LEN]);
int dns_add_PTR(struct dns_packet *packet, dns_rr_type type, const char *domain, int ttl, char *cname);
int dns_add_PTR(struct dns_packet *packet, dns_rr_type type, const char *domain, int ttl, const char *cname);
int dns_get_PTR(struct dns_rrs *rrs, char *domain, int maxsize, int *ttl, char *cname, int cname_size);
int dns_add_AAAA(struct dns_packet *packet, dns_rr_type type, const char *domain, int ttl,

View File

@@ -1814,7 +1814,7 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info)
if (connect(fd, &server_info->addr, server_info->ai_addrlen) != 0) {
if (errno == ENETUNREACH || errno == EHOSTUNREACH || errno == ECONNREFUSED) {
tlog(TLOG_WARN, "connect %s failed, %s", server_info->ip, strerror(errno));
tlog(TLOG_INFO, "connect %s failed, %s", server_info->ip, strerror(errno));
goto errout;
}
@@ -3375,6 +3375,7 @@ static int _dns_client_send_packet(struct dns_query_struct *query, void *packet,
if (server_info->fd <= 0) {
ret = _dns_client_create_socket(server_info);
if (ret != 0) {
server_info->prohibit = 1;
continue;
}
}