From e29dfb75ca3b625e2203b385ba99b359089d3968 Mon Sep 17 00:00:00 2001 From: geniusgogo <2041245+geniusgogo@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:16:41 +0800 Subject: [PATCH] Fix net (#7034) * fix LWIP_HOOK_IP4_ROUTE_SRC. * fix netdev ping select network card. --- components/net/lwip/port/lwipopts.h | 2 +- components/net/netdev/src/netdev.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/components/net/lwip/port/lwipopts.h b/components/net/lwip/port/lwipopts.h index 7f34333247..795ddd06f6 100644 --- a/components/net/lwip/port/lwipopts.h +++ b/components/net/lwip/port/lwipopts.h @@ -637,7 +637,7 @@ #endif #if RT_USING_LWIP_VER_NUM >= 0x20000 /* >= v2.0.0 */ -#define LWIP_HOOK_IP4_ROUTE_SRC(dest, src) lwip_ip4_route_src(dest, src) +#define LWIP_HOOK_IP4_ROUTE_SRC(src, dest) lwip_ip4_route_src(dest, src) #include "lwip/ip_addr.h" struct netif *lwip_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src); #endif /* RT_USING_LWIP_VER_NUM >= 0x20000 */ diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 09f6c37d9a..44eecea6b8 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -1013,7 +1013,7 @@ int netdev_dhcp_open(char* netdev_name) { rt_kprintf("bad network interface device name(%s).\n", netdev_name); return -1; - } + } netdev_dhcp_enabled(netdev,RT_TRUE); return 0; } @@ -1074,15 +1074,15 @@ int netdev_ifconfig(int argc, char **argv) { netdev_list_if(); } -#ifdef RT_LWIP_DHCP +#ifdef RT_LWIP_DHCP else if(argc == 3) { if (!strcmp(argv[2], "dhcp")) { - netdev_dhcp_open(argv[1]); + netdev_dhcp_open(argv[1]); } } -#endif +#endif else if (argc == 5) { rt_kprintf("config : %s\n", argv[1]); @@ -1094,9 +1094,9 @@ int netdev_ifconfig(int argc, char **argv) else { rt_kprintf("bad parameter! e.g: ifconfig e0 192.168.1.30 192.168.1.1 255.255.255.0\n"); -#ifdef RT_LWIP_DHCP +#ifdef RT_LWIP_DHCP rt_kprintf("bad parameter! e.g: ifconfig e0 dhcp\n"); -#endif +#endif } return 0; @@ -1130,19 +1130,15 @@ int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_ if (netdev_name != RT_NULL) { netdev = netdev_get_by_name(netdev_name); - if (netdev == RT_NULL) - { - netdev = netdev_default; - rt_kprintf("ping: not found specified netif, using default netdev %s.\n", netdev->name); - } } - if (NETDEV_PING_IS_COMMONICABLE(netdev_default)) + if (netdev == RT_NULL) { - /* using default network interface device for ping */ netdev = netdev_default; + rt_kprintf("ping: not found specified netif, using default netdev %s.\n", netdev->name); } - else + + if (!NETDEV_PING_IS_COMMONICABLE(netdev)) { /* using first internet up status network interface device */ netdev = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);