summaryrefslogtreecommitdiff
path: root/components/net/lwip
diff options
context:
space:
mode:
Diffstat (limited to 'components/net/lwip')
-rw-r--r--components/net/lwip/Kconfig7
-rw-r--r--components/net/lwip/port/ethernetif.c38
-rw-r--r--components/net/lwip/port/lwipopts.h9
3 files changed, 54 insertions, 0 deletions
diff --git a/components/net/lwip/Kconfig b/components/net/lwip/Kconfig
index 9a1096e8ec..d98388b4ae 100644
--- a/components/net/lwip/Kconfig
+++ b/components/net/lwip/Kconfig
@@ -243,6 +243,13 @@ if RT_USING_LWIP
bool "Enable netif loopback"
default n
+ config RT_LWIP_USING_LOOPBACK
+ bool "Enable lwIP loopback network interface"
+ depends on RT_USING_NETDEV
+ select RT_LWIP_NETIF_LOOPBACK
+ default y if RT_USING_SMART
+ default n
+
config LWIP_NETIF_LOOPBACK
int
default 1 if RT_LWIP_NETIF_LOOPBACK
diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c
index ecb04a5492..208259386a 100644
--- a/components/net/lwip/port/ethernetif.c
+++ b/components/net/lwip/port/ethernetif.c
@@ -447,6 +447,44 @@ static void netdev_del(struct netif *lwip_netif)
netdev_unregister(netdev);
rt_free(netdev);
}
+
+#ifdef RT_LWIP_USING_LOOPBACK
+static int lwip_loopback_init(void)
+{
+ struct netif *netif = netif_find("lo0");
+ struct netdev *netdev;
+ err_t result;
+
+ if (netif == RT_NULL)
+ {
+ return -RT_ERROR;
+ }
+
+ netif->mtu = 65535;
+ if (netdev_add(netif) != RT_EOK)
+ {
+ return -RT_ERROR;
+ }
+
+ result = netifapi_netif_set_link_up(netif);
+ if (result == ERR_OK && netif_default == RT_NULL)
+ {
+ result = netifapi_netif_set_default(netif);
+ }
+ if (result != ERR_OK)
+ {
+ netdev_del(netif);
+ return -RT_ERROR;
+ }
+
+ netdev = netdev_get_by_name("lo");
+ netdev_low_level_set_dhcp_status(netdev, RT_FALSE);
+ netdev_low_level_set_status(netdev, RT_TRUE);
+ netdev_low_level_set_link_status(netdev, RT_TRUE);
+ return RT_EOK;
+}
+INIT_APP_EXPORT(lwip_loopback_init);
+#endif /* RT_LWIP_USING_LOOPBACK */
#endif /* RT_USING_NETDEV */
static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
diff --git a/components/net/lwip/port/lwipopts.h b/components/net/lwip/port/lwipopts.h
index 7d29d79b6b..52be6900cf 100644
--- a/components/net/lwip/port/lwipopts.h
+++ b/components/net/lwip/port/lwipopts.h
@@ -82,7 +82,11 @@
#define LWIP_DNS 0
#endif
+#ifdef RT_LWIP_USING_LOOPBACK
+#define LWIP_HAVE_LOOPIF 1
+#else
#define LWIP_HAVE_LOOPIF 0
+#endif
#define LWIP_PLATFORM_BYTESWAP 0
@@ -541,7 +545,12 @@
#define LWIP_RAW 0
#endif
+/* A loopback ping queues the request before lwIP generates its reply. */
+#ifdef RT_LWIP_NETIF_LOOPBACK
+#define DEFAULT_RAW_RECVMBOX_SIZE 2
+#else
#define DEFAULT_RAW_RECVMBOX_SIZE 1
+#endif
#define DEFAULT_ACCEPTMBOX_SIZE 10
/* ---------- Statistics options ---------- */