Skip to content

netlib: replace DNS ping with gateway ping for connectivity check#3465

Open
zhhyu7 wants to merge 2 commits intoapache:masterfrom
zhhyu7:upstream-3
Open

netlib: replace DNS ping with gateway ping for connectivity check#3465
zhhyu7 wants to merge 2 commits intoapache:masterfrom
zhhyu7:upstream-3

Conversation

@zhhyu7
Copy link
Copy Markdown
Contributor

@zhhyu7 zhhyu7 commented Apr 27, 2026

Summary

Refactor netlib_check_ipconnectivity() to use gateway/router ping instead of DNS server ping for network connectivity checks. Add IPv6 support.

Impact

  • When ip is NULL, ping the default gateway of each interface (via getifaddrs) instead of the hardcoded DNS server address
  • Add IPv6 ping support (icmpv6_ping) alongside existing IPv4 ping
  • Add routing table fallback: ping routers from /proc/net/route and /proc/net/ipv6route when gateway ping fails
  • For point-to-point/tunnel interfaces (no ARP), treat as reachable directly
  • When ping is disabled at build time, fall back to checking network card status instead of always returning 1
  • Auto-detect IPv4/IPv6 when a specific IP is provided
  • netlib_checkipconnectivity.c no longer depends on CONFIG_NETUTILS_PING to compile
  • Improve doxygen-style comments in netlib.h; fix typo "nagtive" → "negative"

Testing

  • Build tested with combinations of CONFIG_NETUTILS_PING, CONFIG_NETUTILS_PING6, CONFIG_NETDEV_IFINDEX, and HAVE_ROUTE_PROCFS enabled/disabled
  • Verified ntpclient caller (netlib_check_ipconnectivity(NULL, 1, 1)) works correctly with the new gateway ping logic
  • Tested on board with IPv4-only, IPv6-only, and dual-stack network interfaces
  • Verified fallback path when ping is disabled at build time

Update the column ruler and field labels in route_ipv6_entry comment
to match the actual output: lowercase to uppercase, remove colons.
Consistent with Nuttx definition

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
@masc2008
Copy link
Copy Markdown
Contributor

looks good to me.

jerpelea
jerpelea previously approved these changes Apr 30, 2026
Comment thread include/netutils/netlib.h Outdated

#ifdef CONFIG_NETUTILS_PING
/**
* @brief
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix, this is not the Description comment/decoration adopted by NuttX. See netutils/netlib/netlib_checkifconnectivity.c line 50 that you are editing for reference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread include/netutils/netlib.h Outdated
Comment on lines +583 to +594
/**
* @brief
* Check network connectivity by pinging the default gateway
* of the specified network interface.
*
* @param ifname The name of the interface to use
* @param timeout The timeout of ping
* @param retry The retry times of ping
*
* @return
* nums of gateway reply of ping; a negative on failure.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

xiaoxiang781216
xiaoxiang781216 previously approved these changes May 2, 2026
Refactor netlib_check_ipconnectivity() to use gateway/router ping instead
of DNS server ping for network connectivity checks. Add IPv6 support.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
@zhhyu7 zhhyu7 dismissed stale reviews from xiaoxiang781216 and jerpelea via debde5c May 6, 2026 02:01
@zhhyu7 zhhyu7 requested a review from acassis May 6, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants