Skip to content

Commit 5c01bde

Browse files
lhespressxcguang
authored andcommitted
fix(dns): Fix a bug of the seq number is overflow, if we don't have found an unused entry and table is full, use the oldest completed one.
1 parent 1998485 commit 5c01bde

File tree

1 file changed

+16
-1
lines changed
  • third_party/lwip/core

1 file changed

+16
-1
lines changed

third_party/lwip/core/dns.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,17 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
896896
if ((dns_seqno - pEntry->seqno) > lseq) {
897897
lseq = dns_seqno - pEntry->seqno;
898898
lseqi = i;
899+
} else {
900+
if (pEntry->seqno >= (0xFF - DNS_TABLE_SIZE)) {
901+
static u8 index = 0;
902+
if ((pEntry->seqno - (0xFF - DNS_TABLE_SIZE)) == index) {
903+
index ++;
904+
lseqi = i;
905+
if (index == DNS_TABLE_SIZE) {
906+
index = 0;
907+
}
908+
}
909+
}
899910
}
900911
}
901912
}
@@ -918,13 +929,17 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
918929

919930
/* fill the entry */
920931
pEntry->state = DNS_STATE_NEW;
921-
pEntry->seqno = dns_seqno++;
932+
pEntry->seqno = dns_seqno;
922933
pEntry->found = found;
923934
pEntry->arg = callback_arg;
924935
namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1);
925936
MEMCPY(pEntry->name, name, namelen);
926937
pEntry->name[namelen] = 0;
927938

939+
dns_seqno ++;
940+
if (dns_seqno == 0xFF) {
941+
dns_seqno = 0;
942+
}
928943
/* force to send query without waiting timer */
929944
dns_check_entry(i);
930945

0 commit comments

Comments
 (0)