Skip to content

Commit

Permalink
ecs: Optimize ecs-subnet configuration method
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Jun 28, 2023
1 parent 8a9a11d commit e66928f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3414,9 +3414,11 @@ static int _dns_client_setup_server_packet(struct dns_server_info *server_info,

dns_set_OPT_payload_size(packet, DNS_IN_PACKSIZE);
/* dns_add_OPT_TCP_KEEPALIVE(packet, 600); */
if (query->qtype == DNS_T_A && server_info->ecs_ipv4.enable) {
if ((query->qtype == DNS_T_A && server_info->ecs_ipv4.enable) ||
(query->qtype == DNS_T_AAAA && server_info->ecs_ipv6.enable == 0 && server_info->ecs_ipv4.enable)) {
dns_add_OPT_ECS(packet, &server_info->ecs_ipv4.ecs);
} else if (query->qtype == DNS_T_AAAA && server_info->ecs_ipv6.enable) {
} else if ((query->qtype == DNS_T_AAAA && server_info->ecs_ipv6.enable) ||
(query->qtype == DNS_T_A && server_info->ecs_ipv4.enable == 0 && server_info->ecs_ipv6.enable)) {
dns_add_OPT_ECS(packet, &server_info->ecs_ipv6.ecs);
}

Expand Down
17 changes: 14 additions & 3 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2562,9 +2562,6 @@ static int _conf_client_subnet(char *subnet, struct dns_edns_client_subnet *ipv4
*slash = 0;
slash++;
subnet_len = atoi(slash);
if (subnet_len < 0 || subnet_len > 128) {
return -1;
}
}

if (getaddr_by_host(str_subnet, (struct sockaddr *)&addr, &addr_len) != 0) {
Expand All @@ -2573,9 +2570,23 @@ static int _conf_client_subnet(char *subnet, struct dns_edns_client_subnet *ipv4

switch (addr.ss_family) {
case AF_INET:
if (subnet_len < 0 || subnet_len > 32) {
return -1;
}

if (subnet_len == 0) {
subnet_len = 32;
}
ecs = ipv4_ecs;
break;
case AF_INET6:
if (subnet_len < 0 || subnet_len > 128) {
return -1;
}

if (subnet_len == 0) {
subnet_len = 128;
}
ecs = ipv6_ecs;
break;
default:
Expand Down

0 comments on commit e66928f

Please sign in to comment.