mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-13 07:14:31 +00:00
Fix bug #50824: Bug in SNTP POLL mode
Ignore all broken packets Stop timeouts only when correct packet is received
This commit is contained in:
parent
ad779e5c9c
commit
13f51a0318
@ -435,10 +435,6 @@ sntp_recv(void *arg, struct udp_pcb* pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
LWIP_UNUSED_ARG(pcb);
|
LWIP_UNUSED_ARG(pcb);
|
||||||
|
|
||||||
/* packet received: stop retry timeout */
|
|
||||||
sys_untimeout(sntp_try_next_server, NULL);
|
|
||||||
sys_untimeout(sntp_request, NULL);
|
|
||||||
|
|
||||||
err = ERR_ARG;
|
err = ERR_ARG;
|
||||||
#if SNTP_CHECK_RESPONSE >= 1
|
#if SNTP_CHECK_RESPONSE >= 1
|
||||||
/* check server address and port */
|
/* check server address and port */
|
||||||
@ -462,8 +458,7 @@ sntp_recv(void *arg, struct udp_pcb* pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
err = SNTP_ERR_KOD;
|
err = SNTP_ERR_KOD;
|
||||||
LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_recv: Received Kiss-of-Death\n"));
|
LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_recv: Received Kiss-of-Death\n"));
|
||||||
} else {
|
} else {
|
||||||
pbuf_copy_partial(p, ×tamps, sizeof(timestamps),
|
pbuf_copy_partial(p, ×tamps, sizeof(timestamps), SNTP_OFFSET_TIMESTAMPS);
|
||||||
SNTP_OFFSET_TIMESTAMPS);
|
|
||||||
#if SNTP_CHECK_RESPONSE >= 2
|
#if SNTP_CHECK_RESPONSE >= 2
|
||||||
/* check originate_timetamp against sntp_last_timestamp_sent */
|
/* check originate_timetamp against sntp_last_timestamp_sent */
|
||||||
if (timestamps.orig.sec != sntp_last_timestamp_sent.sec ||
|
if (timestamps.orig.sec != sntp_last_timestamp_sent.sec ||
|
||||||
@ -493,12 +488,18 @@ sntp_recv(void *arg, struct udp_pcb* pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
err = ERR_TIMEOUT;
|
err = ERR_TIMEOUT;
|
||||||
}
|
}
|
||||||
#endif /* SNTP_CHECK_RESPONSE >= 1 */
|
#endif /* SNTP_CHECK_RESPONSE >= 1 */
|
||||||
|
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
|
||||||
if (err == ERR_OK) {
|
if (err == ERR_OK) {
|
||||||
|
/* correct packet received: process it it */
|
||||||
sntp_process(×tamps);
|
sntp_process(×tamps);
|
||||||
|
|
||||||
/* Set up timeout for next request (only if poll response was received)*/
|
/* Set up timeout for next request (only if poll response was received)*/
|
||||||
if (sntp_opmode == SNTP_OPMODE_POLL) {
|
if (sntp_opmode == SNTP_OPMODE_POLL) {
|
||||||
|
sys_untimeout(sntp_try_next_server, NULL);
|
||||||
|
sys_untimeout(sntp_request, NULL);
|
||||||
|
|
||||||
/* Correct response, reset retry timeout */
|
/* Correct response, reset retry timeout */
|
||||||
SNTP_RESET_RETRY_TIMEOUT();
|
SNTP_RESET_RETRY_TIMEOUT();
|
||||||
|
|
||||||
@ -506,17 +507,14 @@ sntp_recv(void *arg, struct udp_pcb* pcb, struct pbuf *p, const ip_addr_t *addr,
|
|||||||
LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_recv: Scheduled next time request: %"U32_F" ms\n",
|
LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_recv: Scheduled next time request: %"U32_F" ms\n",
|
||||||
(u32_t)SNTP_UPDATE_DELAY));
|
(u32_t)SNTP_UPDATE_DELAY));
|
||||||
}
|
}
|
||||||
} else if (err != ERR_TIMEOUT) {
|
} else if (err == SNTP_ERR_KOD) {
|
||||||
/* Errors are only processed in case of an explicit poll response */
|
/* KOD errors are only processed in case of an explicit poll response */
|
||||||
if (sntp_opmode == SNTP_OPMODE_POLL) {
|
if (sntp_opmode == SNTP_OPMODE_POLL) {
|
||||||
if (err == SNTP_ERR_KOD) {
|
|
||||||
/* Kiss-of-death packet. Use another server or increase UPDATE_DELAY. */
|
/* Kiss-of-death packet. Use another server or increase UPDATE_DELAY. */
|
||||||
sntp_try_next_server(NULL);
|
sntp_try_next_server(NULL);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* another error, try the same server again */
|
/* ignore any broken packet, poll mode: retry after timeout to avoid flooding */
|
||||||
sntp_retry(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user