Skip to content

Commit d2f388b

Browse files
davefiddesd-a-v
authored andcommitted
Restart SNTP client when we have an IPv4 or IPv6 address (#26)
This fixes the restarting of the SNTP client when the network interface has a valid IP address. This was broken in changeset 9246ef for IPv4. Note that for IPv6 the SNTP server can take up to 15 seconds to be used due to the async nature of stateless DHCPv6 and SLAAC. For IPv4 it takes effect immediately as the address and SNTP server come in the same packet. Tests: - Verify operation on dual-stack IPv4/IPv6: - DHCPv6 only network (no DHCPv4 server present) - DHCPv4 and DHCPv6 network - Verify operation on IPv4 only stack - Check SNTP restart with LwIP logging enabled - Verify time is requested and received via Wireshark - Verify system time is set Signed-off-by: David J. Fiddes <D.J@fiddes.net>
1 parent 9246ef5 commit d2f388b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

glue-lwip/lwip-git.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,15 @@ static void netif_sta_status_callback (struct netif* netif)
287287
netif_set_default(netif);
288288

289289
// If we have a valid address of any type restart SNTP
290-
if (ip_addr_isany(&netif->ip_addr))
291-
{
290+
bool valid_address = ip_2_ip4(&netif->ip_addr)->addr;
291+
292+
#if LWIP_IPV6
293+
int addrindex;
294+
for (addrindex = 0; addrindex < LWIP_IPV6_NUM_ADDRESSES; addrindex++) {
295+
valid_address |= ip6_addr_isvalid(netif_ip6_addr_state(netif, addrindex));
296+
}
297+
#endif
298+
if (valid_address) {
292299
// restart sntp
293300
sntp_stop();
294301
sntp_init();

0 commit comments

Comments
 (0)