Skip to content

Commit 7a0417f

Browse files
committed
dns_server: try refresh NDP by sending ICMP ping.
1 parent d61bbb5 commit 7a0417f

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/dns_server.c

+30-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#define CACHE_AUTO_ENABLE_SIZE (1024 * 1024 * 128)
8080
#define EXPIRED_DOMAIN_PREFETCH_TIME (3600 * 8)
8181
#define DNS_MAX_DOMAIN_REFETCH_NUM 64
82-
#define DNS_SERVER_NEIGHBOR_CACHE_MAX_NUM 8192
82+
#define DNS_SERVER_NEIGHBOR_CACHE_MAX_NUM (1024 * 8)
8383
#define DNS_SERVER_NEIGHBOR_CACHE_TIMEOUT (3600 * 1)
8484
#define DNS_SERVER_NEIGHBOR_CACHE_NOMAC_TIMEOUT 60
8585

@@ -3619,13 +3619,36 @@ static struct dns_client_rules *_dns_server_get_client_rules_by_mac(uint8_t *net
36193619
args.netaddr = netaddr;
36203620
args.netaddr_len = netaddr_len;
36213621

3622-
ret = netlink_get_neighbors(family, _dns_server_neighbors_callback, &args);
3623-
if (ret < 0) {
3624-
goto add_cache;
3625-
}
3622+
for (int i = 0; i < 2; i++) {
3623+
ret = netlink_get_neighbors(family, _dns_server_neighbors_callback, &args);
3624+
if (ret < 0) {
3625+
goto add_cache;
3626+
}
3627+
3628+
if (ret != 1) {
3629+
/* FIXME: ugly force refresh NDP table by sending ICMP message.*/
3630+
if (i == 0) {
3631+
char host[DNS_MAX_CNAME_LEN] = {0};
3632+
if (family == AF_INET) {
3633+
snprintf(host, sizeof(host), "%d.%d.%d.%d", netaddr[0], netaddr[1], netaddr[2], netaddr[3]);
3634+
} else if (family == AF_INET6) {
3635+
snprintf(host, sizeof(host),
3636+
"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x", netaddr[0],
3637+
netaddr[1], netaddr[2], netaddr[3], netaddr[4], netaddr[5], netaddr[6], netaddr[7],
3638+
netaddr[8], netaddr[9], netaddr[10], netaddr[11], netaddr[12], netaddr[13], netaddr[14],
3639+
netaddr[15]);
3640+
}
3641+
struct ping_host_struct *ping_host = fast_ping_start(PING_TYPE_ICMP, host, 0, 10, 1000, NULL, NULL);
3642+
if (ping_host) {
3643+
/* wait for NDP*/
3644+
usleep(100);
3645+
fast_ping_stop(ping_host);
3646+
continue;
3647+
}
3648+
}
36263649

3627-
if (ret != 1) {
3628-
goto add_cache;
3650+
goto add_cache;
3651+
}
36293652
}
36303653

36313654
if (args.group_mac == NULL) {
@@ -7384,7 +7407,6 @@ static int _dns_server_recv(struct dns_server_conn_head *conn, unsigned char *in
73847407
"%d, rcode = %d\n",
73857408
packet->head.qdcount, packet->head.ancount, packet->head.nscount, packet->head.nrcount, inpacket_len,
73867409
packet->head.id, packet->head.tc, packet->head.rd, packet->head.ra, packet->head.rcode);
7387-
73887410
client_rules = _dns_server_get_client_rules(from, from_len);
73897411
request = _dns_server_new_request();
73907412
if (request == NULL) {

0 commit comments

Comments
 (0)