Skip to content

Commit 809598e

Browse files
committed
netlib: replace DNS ping with gateway ping for connectivity check
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>
1 parent 5478167 commit 809598e

5 files changed

Lines changed: 355 additions & 34 deletions

File tree

include/netutils/netlib.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,41 @@ int netlib_getifstatistics(FAR const char *ifname,
561561
int netlib_check_ifconflict(FAR const char *ifname);
562562
#endif
563563

564-
#ifdef CONFIG_NETUTILS_PING
564+
/**
565+
* @brief
566+
* Check network connectivity by pinging a remote IP address.
567+
* If ip is NULL, ping the gateway of each network interface,
568+
* and optionally the routers from the routing table. If ping
569+
* is disabled, just check the status of the IP network card.
570+
*
571+
* @param ip The ipv4 address to check, or NULL to ping gateways
572+
* @param timeout The max timeout of each ping
573+
* @param retry The retry times of ping
574+
*
575+
* @return
576+
* nums of remote reply of ping; a negative on failure
577+
*/
578+
565579
int netlib_check_ipconnectivity(FAR const char *ip, int timeout, int retry);
580+
581+
#ifdef CONFIG_NETUTILS_PING
582+
583+
/**
584+
* @brief
585+
* Check network connectivity by pinging the default gateway
586+
* of the specified network interface.
587+
*
588+
* @param ifname The name of the interface to use
589+
* @param timeout The timeout of ping
590+
* @param retry The retry times of ping
591+
*
592+
* @return
593+
* nums of gateway reply of ping; a negative on failure.
594+
*/
595+
566596
int netlib_check_ifconnectivity(FAR const char *ifname,
567597
int timeout, int retry);
568598
#else
569-
#define netlib_check_ipconnectivity(i, t, r) 1
570599
#define netlib_check_ifconnectivity(i, t, r) 1
571600
#endif
572601

netutils/netlib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ if(CONFIG_NETUTILS_NETLIB)
158158
list(APPEND SRCS netlib_getiobinfo.c)
159159
endif()
160160

161+
list(APPEND SRCS netlib_checkipconnectivity.c)
162+
161163
if(CONFIG_NETUTILS_PING)
162-
list(APPEND SRCS netlib_checkipconnectivity.c netlib_checkifconnectivity.c)
164+
list(APPEND SRCS netlib_checkifconnectivity.c)
163165
endif()
164166

165167
list(APPEND SRCS netlib_checkhttpconnectivity.c)

netutils/netlib/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ ifeq ($(CONFIG_MM_IOB),y)
157157
CSRCS += netlib_getiobinfo.c
158158
endif
159159

160+
CSRCS += netlib_checkipconnectivity.c
161+
160162
ifeq ($(CONFIG_NETUTILS_PING),y)
161-
CSRCS += netlib_checkipconnectivity.c netlib_checkifconnectivity.c
163+
CSRCS += netlib_checkifconnectivity.c
162164
endif
163165

164166
CSRCS += netlib_checkhttpconnectivity.c

netutils/netlib/netlib_checkifconnectivity.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
* Name: netlib_check_ifconnectivity
4949
*
5050
* Description:
51-
* Check network interface connectivity by pinging the gateway
51+
* Check network connectivity by pinging the default gateway
52+
* of the specified network interface.
5253
*
5354
* Parameters:
5455
* ifname The name of the interface to use
5556
* timeout The timeout of ping
5657
* retry The retry times of ping
5758
*
5859
* Return:
59-
* nums of gateway reply of ping; a nagtive on failure.
60+
* nums of gateway reply of ping; a negative on failure.
6061
*
6162
****************************************************************************/
6263

@@ -86,4 +87,4 @@ int netlib_check_ifconnectivity(FAR const char *ifname,
8687
return netlib_check_ipconnectivity(destip, timeout, retry);
8788
}
8889

89-
#endif /* CONFIG_NETUTILS_PING */
90+
#endif /* CONFIG_NETUTILS_PING */

0 commit comments

Comments
 (0)