From adaa45eebeaf1a772ba57bca76ef9bd04ef7fb90 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Fri, 26 Mar 2021 10:04:37 +0800 Subject: [PATCH 1/8] [fix] the overflow problem of lwip rx thread mailbox. --- .../net/lwip-1.4.1/src/netif/ethernetif.c | 10 ++-- .../net/lwip-2.0.2/src/netif/ethernetif.c | 6 +-- .../net/lwip-2.1.2/src/netif/ethernetif.c | 52 +++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index f2570f9e2b..4f01c407a8 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -156,16 +156,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -648,7 +648,7 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; @@ -664,7 +664,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index b93acb1fcf..47146f0b3b 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -173,7 +173,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } return ERR_OK; } @@ -697,7 +697,7 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; @@ -713,7 +713,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 52bd0fb7b6..df3f7cd6ce 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -163,16 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -182,7 +182,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) extern int lwip_ping_recv(int s, int *ttl); extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, +int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp) { int s, ttl, recv_len, result = 0; @@ -197,7 +197,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, struct addrinfo hint, *res = RT_NULL; struct sockaddr_in *h = RT_NULL; struct in_addr ina; - + RT_ASSERT(netif); RT_ASSERT(host); RT_ASSERT(ping_resp); @@ -216,7 +216,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, return -RT_ERROR; } rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - + /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { @@ -284,7 +284,7 @@ const struct netdev_ops lwip_netdev_ops = lwip_netdev_set_addr_info, #ifdef RT_LWIP_DNS lwip_netdev_set_dns_server, -#else +#else NULL, #endif /* RT_LWIP_DNS */ @@ -323,7 +323,7 @@ static int netdev_add(struct netif *lwip_netif) { return -ERR_IF; } - + #ifdef SAL_USING_LWIP extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); /* set the lwIP network interface device protocol family information */ @@ -332,7 +332,7 @@ static int netdev_add(struct netif *lwip_netif) rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); result = netdev_register(netdev, name, (void *)lwip_netif); - + /* Update netdev info after registered */ netdev->flags = lwip_netif->flags; netdev->mtu = lwip_netif->mtu; @@ -375,7 +375,7 @@ static int netdev_flags_sync(struct netif *lwip_netif) { return -ERR_IF; } - + netdev->mtu = lwip_netif->mtu; netdev->flags |= lwip_netif->flags; @@ -438,7 +438,7 @@ static err_t eth_netif_device_init(struct netif *netif) /* copy device flags to netif flags */ netif->flags = (ethif->flags & 0xff); netif->mtu = ETHERNET_MTU; - + /* set output */ netif->output = etharp_output; @@ -530,7 +530,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* set linkoutput */ netif->linkoutput = ethernetif_linkoutput; - + /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); @@ -550,7 +550,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ ipaddr.addr = inet_addr(RT_LWIP_IPADDR); gw.addr = inet_addr(RT_LWIP_GWADDR); netmask.addr = inet_addr(RT_LWIP_MSKADDR); -#else +#else IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); @@ -699,10 +699,10 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; - + p = device->eth_rx(&(device->parent)); if (p != RT_NULL) { @@ -715,7 +715,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { @@ -725,9 +725,9 @@ static void eth_rx_thread_entry(void* parameter) } #endif -/* this function does not need, - * use eth_system_device_init_private() - * call by lwip_system_init(). +/* this function does not need, + * use eth_system_device_init_private() + * call by lwip_system_init(). */ int eth_system_device_init(void) { @@ -874,22 +874,22 @@ void list_if(void) ip6_addr_t *addr; int addr_state; int i; - + addr = (ip6_addr_t *)&netif->ip6_addr[0]; addr_state = netif->ip6_addr_state[0]; - - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - + for(i=1; iip6_addr[i]; addr_state = netif->ip6_addr_state[i]; - - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); } - + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ From 154d73a4e76f954ad67d94455e6000a3d168fbf6 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Wed, 31 Mar 2021 13:37:19 +0800 Subject: [PATCH 2/8] [fix] iperf speed test have been stable. --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 1 + .../net/lwip-1.4.1/src/netif/ethernetif.c | 17 ++++++++++++----- .../lwip-2.0.2/src/include/netif/ethernetif.h | 1 + .../net/lwip-2.0.2/src/netif/ethernetif.c | 17 ++++++++++++----- .../lwip-2.1.2/src/include/netif/ethernetif.h | 1 + .../net/lwip-2.1.2/src/netif/ethernetif.c | 17 ++++++++++++----- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 1c969e6e25..b3ca8e2ffb 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4f01c407a8..30e7ee5f6d 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -550,10 +550,16 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -646,9 +652,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -664,7 +671,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 244bafdd1b..d294c36813 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 47146f0b3b..0146286b2a 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -599,10 +599,16 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -695,9 +701,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -713,7 +720,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 244bafdd1b..d294c36813 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index df3f7cd6ce..e2f8512d53 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -601,10 +601,16 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -697,9 +703,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -715,7 +722,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { From 4431c4796fb3e26fb66c012feb8bf47f3292b473 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Wed, 31 Mar 2021 14:59:12 +0800 Subject: [PATCH 3/8] [fix] remove the possible critical zone risk --- .../net/lwip-1.4.1/src/include/netif/ethernetif.h | 2 +- components/net/lwip-1.4.1/src/netif/ethernetif.c | 12 ++++++++++-- .../net/lwip-2.0.2/src/include/netif/ethernetif.h | 2 +- components/net/lwip-2.0.2/src/netif/ethernetif.c | 12 ++++++++++-- .../net/lwip-2.1.2/src/include/netif/ethernetif.h | 2 +- components/net/lwip-2.1.2/src/netif/ethernetif.c | 12 ++++++++++-- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index b3ca8e2ffb..650ad32eff 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 30e7ee5f6d..94d1f8d907 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -469,6 +469,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -556,10 +558,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -652,7 +656,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index d294c36813..1459e3241d 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 0146286b2a..28e3822cf7 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -511,6 +511,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -605,10 +607,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -701,7 +705,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index d294c36813..1459e3241d 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index e2f8512d53..09a84f61e5 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -514,6 +514,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -607,10 +609,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -703,7 +707,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) From 2b549d93c88bd0dd55429457f0da9eb199374b3a Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Tue, 6 Apr 2021 10:46:31 +0800 Subject: [PATCH 4/8] [fix] change from enter critical area into disable interrupt. --- components/net/lwip-1.4.1/src/netif/ethernetif.c | 5 +++-- components/net/lwip-2.0.2/src/netif/ethernetif.c | 5 +++-- components/net/lwip-2.1.2/src/netif/ethernetif.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 94d1f8d907..4565f5e528 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -638,6 +638,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -657,10 +658,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 28e3822cf7..1c0f3ca9b2 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -687,6 +687,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -706,10 +707,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 09a84f61e5..751a7bbdac 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -689,6 +689,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -708,10 +709,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) From 3db7a98a18e461236d418e0670de5d8905b11749 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Tue, 6 Apr 2021 11:41:14 +0800 Subject: [PATCH 5/8] [update] change the file encoding to UTF-8. --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-1.4.1/src/netif/ethernetif.c | 40 +++++++++---------- .../lwip-2.0.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.0.2/src/netif/ethernetif.c | 32 +++++++-------- .../lwip-2.1.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.1.2/src/netif/ethernetif.c | 32 +++++++-------- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 650ad32eff..5d278a906e 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4565f5e528..9654a0c255 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -59,9 +59,9 @@ #define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) #ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 +#define RT_ETHERNETIF_THREAD_PREORITY 0x90 #else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY +#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY #endif #ifndef LWIP_NO_TX_THREAD @@ -70,8 +70,8 @@ */ struct eth_tx_msg { - struct netif *netif; - struct pbuf *buf; + struct netif *netif; + struct pbuf *buf; }; static struct rt_mailbox eth_tx_thread_mb; @@ -368,7 +368,7 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) struct eth_tx_msg msg; struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; /* send a message to eth tx thread */ @@ -382,13 +382,13 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) #else struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } + if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) + { + return ERR_IF; + } #endif return ERR_OK; } @@ -481,16 +481,16 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ netif->name[1] = name[1]; /* set hw address to 6 */ - netif->hwaddr_len = 6; + netif->hwaddr_len = 6; /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; + netif->mtu = ETHERNET_MTU; /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; + netif->output = etharp_output; + netif->linkoutput = ethernetif_linkoutput; #if LWIP_NETIF_HOSTNAME /* Initialize interface hostname */ @@ -587,12 +587,12 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); + if (up == RT_TRUE) + netifapi_netif_set_link_up(dev->netif); + else + netifapi_netif_set_link_down(dev->netif); - return RT_EOK; + return RT_EOK; } #endif @@ -666,7 +666,7 @@ static void eth_rx_thread_entry(void* parameter) /* receive all of buffer */ while(1) { - if(device->eth_rx == RT_NULL) break; + if(device->eth_rx == RT_NULL) break; p = device->eth_rx(&(device->parent)); if (p != RT_NULL) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 1459e3241d..66bb8c717e 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 1c0f3ca9b2..e723dcb920 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -884,27 +884,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 1459e3241d..66bb8c717e 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 751a7bbdac..2172bc978d 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -886,27 +886,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; From f083c67f22ac6413fd163b19da841687dbb5e17e Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Sat, 10 Apr 2021 18:07:09 +0800 Subject: [PATCH 6/8] [update] ignore format check for lwip files. --- .ignore_format.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.ignore_format.yml b/.ignore_format.yml index 4a0e8bbec7..5af47eedd4 100644 --- a/.ignore_format.yml +++ b/.ignore_format.yml @@ -1,4 +1,4 @@ -# files format check exclude path, please follow the instructions below to modify; +# files format check exclude path, please follow the instructions below to modify; # If you need to exclude an entire folder, add the folder path in dir_path; # If you need to exclude a file, add the path to the file in file_path. @@ -6,4 +6,7 @@ file_path: - bsp/allwinner_tina/libcpu/cpu.c dir_path: -- tools \ No newline at end of file +- tools +- components/net/lwip-1.4.1 +- components/net/lwip-2.0.2 +- components/net/lwip-2.1.2 \ No newline at end of file From ad9c4ea15b40258de874130c7a6c704e3f870856 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Thu, 15 Apr 2021 12:43:56 +0800 Subject: [PATCH 7/8] [restore] Restore format --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-1.4.1/src/netif/ethernetif.c | 40 +++++++++---------- .../lwip-2.0.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.0.2/src/netif/ethernetif.c | 32 +++++++-------- .../lwip-2.1.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.1.2/src/netif/ethernetif.c | 32 +++++++-------- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 5d278a906e..650ad32eff 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 9654a0c255..4565f5e528 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -59,9 +59,9 @@ #define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) #ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 +#define RT_ETHERNETIF_THREAD_PREORITY 0x90 #else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY +#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY #endif #ifndef LWIP_NO_TX_THREAD @@ -70,8 +70,8 @@ */ struct eth_tx_msg { - struct netif *netif; - struct pbuf *buf; + struct netif *netif; + struct pbuf *buf; }; static struct rt_mailbox eth_tx_thread_mb; @@ -368,7 +368,7 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) struct eth_tx_msg msg; struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; /* send a message to eth tx thread */ @@ -382,13 +382,13 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) #else struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } + if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) + { + return ERR_IF; + } #endif return ERR_OK; } @@ -481,16 +481,16 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ netif->name[1] = name[1]; /* set hw address to 6 */ - netif->hwaddr_len = 6; + netif->hwaddr_len = 6; /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; + netif->mtu = ETHERNET_MTU; /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; + netif->output = etharp_output; + netif->linkoutput = ethernetif_linkoutput; #if LWIP_NETIF_HOSTNAME /* Initialize interface hostname */ @@ -587,12 +587,12 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); + if (up == RT_TRUE) + netifapi_netif_set_link_up(dev->netif); + else + netifapi_netif_set_link_down(dev->netif); - return RT_EOK; + return RT_EOK; } #endif @@ -666,7 +666,7 @@ static void eth_rx_thread_entry(void* parameter) /* receive all of buffer */ while(1) { - if(device->eth_rx == RT_NULL) break; + if(device->eth_rx == RT_NULL) break; p = device->eth_rx(&(device->parent)); if (p != RT_NULL) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 66bb8c717e..1459e3241d 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index e723dcb920..1c0f3ca9b2 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -884,27 +884,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 66bb8c717e..1459e3241d 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 2172bc978d..751a7bbdac 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -886,27 +886,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; From 962a97b683f46d701419533f79955470fa1ab431 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Thu, 15 Apr 2021 12:50:54 +0800 Subject: [PATCH 8/8] [restore] Restore format --- .../net/lwip-2.1.2/src/netif/ethernetif.c | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 751a7bbdac..81dd792f29 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -163,16 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -182,7 +182,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) extern int lwip_ping_recv(int s, int *ttl); extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, +int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp) { int s, ttl, recv_len, result = 0; @@ -197,7 +197,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, struct addrinfo hint, *res = RT_NULL; struct sockaddr_in *h = RT_NULL; struct in_addr ina; - + RT_ASSERT(netif); RT_ASSERT(host); RT_ASSERT(ping_resp); @@ -216,7 +216,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, return -RT_ERROR; } rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - + /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { @@ -284,7 +284,7 @@ const struct netdev_ops lwip_netdev_ops = lwip_netdev_set_addr_info, #ifdef RT_LWIP_DNS lwip_netdev_set_dns_server, -#else +#else NULL, #endif /* RT_LWIP_DNS */ @@ -323,7 +323,7 @@ static int netdev_add(struct netif *lwip_netif) { return -ERR_IF; } - + #ifdef SAL_USING_LWIP extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); /* set the lwIP network interface device protocol family information */ @@ -332,7 +332,7 @@ static int netdev_add(struct netif *lwip_netif) rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); result = netdev_register(netdev, name, (void *)lwip_netif); - + /* Update netdev info after registered */ netdev->flags = lwip_netif->flags; netdev->mtu = lwip_netif->mtu; @@ -375,7 +375,7 @@ static int netdev_flags_sync(struct netif *lwip_netif) { return -ERR_IF; } - + netdev->mtu = lwip_netif->mtu; netdev->flags |= lwip_netif->flags; @@ -438,7 +438,7 @@ static err_t eth_netif_device_init(struct netif *netif) /* copy device flags to netif flags */ netif->flags = (ethif->flags & 0xff); netif->mtu = ETHERNET_MTU; - + /* set output */ netif->output = etharp_output; @@ -532,7 +532,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* set linkoutput */ netif->linkoutput = ethernetif_linkoutput; - + /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); @@ -552,7 +552,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ ipaddr.addr = inet_addr(RT_LWIP_IPADDR); gw.addr = inet_addr(RT_LWIP_GWADDR); netmask.addr = inet_addr(RT_LWIP_MSKADDR); -#else +#else IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); @@ -715,10 +715,10 @@ static void eth_rx_thread_entry(void* parameter) rt_hw_interrupt_enable(level); /* receive all of buffer */ - while(1) + while (1) { if(device->eth_rx == RT_NULL) break; - + p = device->eth_rx(&(device->parent)); if (p != RT_NULL) { @@ -741,9 +741,9 @@ static void eth_rx_thread_entry(void* parameter) } #endif -/* this function does not need, - * use eth_system_device_init_private() - * call by lwip_system_init(). +/* this function does not need, + * use eth_system_device_init_private() + * call by lwip_system_init(). */ int eth_system_device_init(void) { @@ -890,22 +890,22 @@ void list_if(void) ip6_addr_t *addr; int addr_state; int i; - + addr = (ip6_addr_t *)&netif->ip6_addr[0]; addr_state = netif->ip6_addr_state[0]; - - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - + for(i=1; iip6_addr[i]; addr_state = netif->ip6_addr_state[i]; - - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); } - + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */