summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Wang <[email protected]>2026-09-11 15:42:32 +0800
committerBernard Xiong <[email protected]>2026-10-03 12:59:43 +0800
commitf1cc628cf27cd1435d14fab77ffeabedb602969b (patch)
treef74608a6b217549fd5a35a65a52fad6a577bf4cb
parent4422241f095ddeed33e7041865545e8bb70a50c3 (diff)
[lwip] add lwIP 2.2.1 as a selectable version alongside 1.4.1/2.0.3/2.1.2
- Kconfig: RT_USING_LWIP221 choice, RT_USING_LWIP_VER_NUM=0x20201 - SConscript for lwip-2.2.1 (acd.c, mdns split files, tftp.c) - replay RTT patch set from lwip-2.1.2 onto 2.2.1 - import RTT ping.c and tftp_port.c (adapted to 2.2.x TFTP API) - SAL: version-gated netconn socket accessor (callback_arg union >= 2.2.0) - lwipopts: DHCP ACD (RFC 5227) and MEMP_NUM_SYS_TIMEOUT version gates
-rw-r--r--components/net/lwip/.clang-format-ignore3
-rw-r--r--components/net/lwip/Kconfig6
-rw-r--r--components/net/lwip/lwip-2.2.1/SConscript262
-rw-r--r--components/net/lwip/lwip-2.2.1/src/api/sockets.c22
-rw-r--r--components/net/lwip/lwip-2.2.1/src/apps/altcp_tls/altcp_tls_mbedtls.c6
-rw-r--r--components/net/lwip/lwip-2.2.1/src/apps/ping/ping.c247
-rw-r--r--components/net/lwip/lwip-2.2.1/src/apps/tftp/tftp_port.c82
-rw-r--r--components/net/lwip/lwip-2.2.1/src/core/dns.c71
-rw-r--r--components/net/lwip/lwip-2.2.1/src/core/ipv4/dhcp.c9
-rw-r--r--components/net/lwip/lwip-2.2.1/src/core/ipv6/dhcp6.c9
-rw-r--r--components/net/lwip/lwip-2.2.1/src/core/ipv6/nd6.c23
-rw-r--r--components/net/lwip/lwip-2.2.1/src/core/netif.c62
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/arch.h4
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/ip_addr.h2
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/netif.h6
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/priv/sockets_priv.h9
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/prot/ieee.h2
-rw-r--r--components/net/lwip/lwip-2.2.1/src/include/lwip/sockets.h17
-rw-r--r--components/net/lwip/lwip-2.2.1/src/netif/lowpan6.c2
-rw-r--r--components/net/lwip/lwip-2.2.1/src/netif/ppp/ppp.c30
-rw-r--r--components/net/lwip/port/lwipopts.h22
-rw-r--r--components/net/sal/impl/af_inet_lwip.c97
22 files changed, 933 insertions, 60 deletions
diff --git a/components/net/lwip/.clang-format-ignore b/components/net/lwip/.clang-format-ignore
index 291db62104..20edbfe7d6 100644
--- a/components/net/lwip/.clang-format-ignore
+++ b/components/net/lwip/.clang-format-ignore
@@ -7,4 +7,5 @@
/lwip-1.4.1/
/lwip-2.0.3/
-/lwip-2.1.2/ \ No newline at end of file
+/lwip-2.1.2/
+/lwip-2.2.1/ \ No newline at end of file
diff --git a/components/net/lwip/Kconfig b/components/net/lwip/Kconfig
index 374f4d565f..9a1096e8ec 100644
--- a/components/net/lwip/Kconfig
+++ b/components/net/lwip/Kconfig
@@ -28,6 +28,9 @@ if RT_USING_LWIP
config RT_USING_LWIP212
bool "lwIP v2.1.2"
+ config RT_USING_LWIP221
+ bool "lwIP v2.2.1"
+
# online version
if !RT_USING_LWIP_LOCAL_VERSION
config RT_USING_LWIP_LATEST
@@ -39,6 +42,7 @@ if RT_USING_LWIP
config RT_USING_LWIP_VER_NUM
hex
default 0x99999 if RT_USING_LWIP_LATEST
+ default 0x20201 if RT_USING_LWIP221
default 0x20102 if RT_USING_LWIP212
default 0x20003 if RT_USING_LWIP203
default 0x10401 if RT_USING_LWIP141
@@ -48,7 +52,7 @@ if RT_USING_LWIP
bool "IPV6 protocol"
default n
select NETDEV_USING_IPV6
- select NETDEV_IPV6_SCOPES if RT_USING_LWIP212
+ select NETDEV_IPV6_SCOPES if RT_USING_LWIP212 || RT_USING_LWIP221
endif
config RT_LWIP_MEM_ALIGNMENT
diff --git a/components/net/lwip/lwip-2.2.1/SConscript b/components/net/lwip/lwip-2.2.1/SConscript
new file mode 100644
index 0000000000..e258ad5a3f
--- /dev/null
+++ b/components/net/lwip/lwip-2.2.1/SConscript
@@ -0,0 +1,262 @@
+from building import *
+
+# get current directory
+cwd = GetCurrentDir()
+
+# 1. The minimum set of files needed for lwIP.
+lwipcore_SRCS = Split("""
+src/core/init.c
+src/core/def.c
+src/core/dns.c
+src/core/inet_chksum.c
+src/core/ip.c
+src/core/memp.c
+src/core/netif.c
+src/core/pbuf.c
+src/core/raw.c
+src/core/stats.c
+src/core/sys.c
+src/core/tcp.c
+src/core/tcp_in.c
+src/core/tcp_out.c
+src/core/timeouts.c
+src/core/udp.c
+""")
+
+# 1.1
+lwipcore_altcp_SRCS = Split("""
+src/core/altcp.c
+src/core/altcp_alloc.c
+src/core/altcp_tcp.c
+""")
+
+# 1.2
+lwipcore4_SRCS = Split("""
+src/core/ipv4/acd.c
+src/core/ipv4/autoip.c
+src/core/ipv4/dhcp.c
+src/core/ipv4/etharp.c
+src/core/ipv4/icmp.c
+src/core/ipv4/igmp.c
+src/core/ipv4/ip4_frag.c
+src/core/ipv4/ip4.c
+src/core/ipv4/ip4_addr.c
+""")
+
+# 1.3
+lwipcore6_SRCS = Split("""
+src/core/ipv6/dhcp6.c
+src/core/ipv6/ethip6.c
+src/core/ipv6/icmp6.c
+src/core/ipv6/inet6.c
+src/core/ipv6/ip6.c
+src/core/ipv6/ip6_addr.c
+src/core/ipv6/ip6_frag.c
+src/core/ipv6/mld6.c
+src/core/ipv6/nd6.c
+""")
+
+# 2. APIFILES: The files which implement the sequential and socket APIs.
+lwipapi_SRCS = Split("""
+src/api/api_lib.c
+src/api/api_msg.c
+src/api/err.c
+src/api/if_api.c
+src/api/netbuf.c
+src/api/netdb.c
+src/api/netifapi.c
+src/api/sockets.c
+src/api/tcpip.c
+""")
+
+# 3. Files implementing various generic network interface functions
+lwipnetif_SRCS = Split("""
+src/netif/ethernet.c
+""")
+
+# 3.1 Files implementing an IEEE 802.1D bridge by using a multilayer netif approach
+lwipnetif_bridgeif_SRCS = Split("""
+src/netif/bridgeif.c
+src/netif/bridgeif_fdb.c
+""")
+
+# 3.2 A generic implementation of the SLIP (Serial Line IP) protocol.
+lwipnetif_slipif_SRCS = Split("""
+src/netif/slipif.c
+""")
+
+# 4. 6LoWPAN
+lwipsixlowpan_SRCS = Split("""
+src/netif/lowpan6.c
+""")
+
+# 4.1 A 6LoWPAN over Bluetooth Low Energy (BLE) implementation as netif,
+# according to RFC-7668.
+lwipsixlowpan_ble_SRCS = Split("""
+src/netif/lowpan6_ble.c
+""")
+
+# 4.2 Common 6LowPAN routines for IPv6.
+lwipsixlowpan_ipv6_SRCS = Split("""
+src/netif/lowpan6_common.c
+""")
+
+# 4.3 A netif implementing the ZigBee Encapsulation Protocol (ZEP).
+lwipsixlowpan_zep_SRCS = Split("""
+src/netif/zepif.c
+""")
+
+# 5. PPP
+lwipppp_SRCS = Split("""
+src/netif/ppp/auth.c
+src/netif/ppp/ccp.c
+src/netif/ppp/chap-md5.c
+src/netif/ppp/chap_ms.c
+src/netif/ppp/chap-new.c
+src/netif/ppp/demand.c
+src/netif/ppp/eap.c
+src/netif/ppp/ecp.c
+src/netif/ppp/eui64.c
+src/netif/ppp/fsm.c
+src/netif/ppp/ipcp.c
+src/netif/ppp/ipv6cp.c
+src/netif/ppp/lcp.c
+src/netif/ppp/magic.c
+src/netif/ppp/mppe.c
+src/netif/ppp/multilink.c
+src/netif/ppp/ppp.c
+src/netif/ppp/pppapi.c
+src/netif/ppp/pppcrypt.c
+src/netif/ppp/pppoe.c
+src/netif/ppp/pppol2tp.c
+src/netif/ppp/pppos.c
+src/netif/ppp/upap.c
+src/netif/ppp/utils.c
+src/netif/ppp/vj.c
+src/netif/ppp/polarssl/arc4.c
+src/netif/ppp/polarssl/des.c
+src/netif/ppp/polarssl/md4.c
+src/netif/ppp/polarssl/md5.c
+src/netif/ppp/polarssl/sha1.c
+""")
+
+# 6. SNMPv3 agent
+lwipsnmp_SRCS = Split("""
+src/apps/snmp/snmp_asn1.c
+src/apps/snmp/snmp_core.c
+src/apps/snmp/snmp_mib2.c
+src/apps/snmp/snmp_mib2_icmp.c
+src/apps/snmp/snmp_mib2_interfaces.c
+src/apps/snmp/snmp_mib2_ip.c
+src/apps/snmp/snmp_mib2_snmp.c
+src/apps/snmp/snmp_mib2_system.c
+src/apps/snmp/snmp_mib2_tcp.c
+src/apps/snmp/snmp_mib2_udp.c
+src/apps/snmp/snmp_snmpv2_framework.c
+src/apps/snmp/snmp_snmpv2_usm.c
+src/apps/snmp/snmp_msg.c
+src/apps/snmp/snmpv3.c
+src/apps/snmp/snmp_netconn.c
+src/apps/snmp/snmp_pbuf_stream.c
+src/apps/snmp/snmp_raw.c
+src/apps/snmp/snmp_scalar.c
+src/apps/snmp/snmp_table.c
+src/apps/snmp/snmp_threadsync.c
+src/apps/snmp/snmp_traps.c
+""")
+
+# 7. HTTP server + client
+lwiphttp_SRCS = Split("""
+src/apps/http/altcp_proxyconnect.c
+src/apps/http/fs.c
+src/apps/http/http_client.c
+src/apps/http/httpd.c
+""")
+
+# 8. MAKEFSDATA HTTP server host utility
+lwipmakefsdata_SRCS = Split("""
+src/apps/http/makefsdata/makefsdata.c
+""")
+
+# 9. IPERF server
+lwipiperf_SRCS = Split("""
+src/apps/lwiperf/lwiperf.c
+""")
+
+# 10. SMTP client
+lwipsmtp_SRCS = Split("""
+src/apps/smtp/smtp.c
+""")
+
+# 11. SNTP client
+lwipsntp_SRCS = Split("""
+src/apps/sntp/sntp.c
+""")
+
+# 12. MDNS responder
+lwipmdns_SRCS = Split("""
+src/apps/mdns/mdns.c
+src/apps/mdns/mdns_domain.c
+src/apps/mdns/mdns_out.c
+""")
+
+# 13. NetBIOS name server
+lwipnetbios_SRCS = Split("""
+src/apps/netbiosns/netbiosns.c
+""")
+
+# 14. TFTP server files
+lwiptftp_SRCS = Split("""
+src/apps/tftp/tftp.c
+src/apps/tftp/tftp_port.c
+""")
+
+# 15. MQTT client files
+lwipmqtt_SRCS = Split("""
+src/apps/mqtt/mqtt.c
+""")
+
+# 16. ARM MBEDTLS related files of lwIP rep
+lwipmbedtls_SRCS = Split("""
+src/apps/altcp_tls/altcp_tls_mbedtls.c
+src/apps/altcp_tls/altcp_tls_mbedtls_mem.c
+src/apps/snmp/snmpv3_mbedtls.c
+""")
+
+# 17. ping
+lwipping_SRCS = Split("""
+src/apps/ping/ping.c
+""")
+
+src = []
+src += lwipcore_SRCS
+src += lwipcore_altcp_SRCS
+src += lwipapi_SRCS
+src += lwipnetif_SRCS
+src += lwipsixlowpan_SRCS
+
+src += lwipcore4_SRCS
+
+path = [cwd + '/src/include',
+ cwd + '/src/include/netif']
+
+if not GetDepend('RT_USING_SAL'):
+ path += [cwd + '/src/include/compat/posix']
+
+if GetDepend(['RT_LWIP_SNMP']):
+ src += lwipsnmp_SRCS
+ path += [cwd + '/src/apps/snmp']
+
+if GetDepend(['RT_LWIP_PPP']):
+ src += lwipppp_SRCS
+ path += [cwd + '/src/netif/ppp']
+
+if GetDepend(['RT_USING_LWIP_IPV6']):
+ src += lwipcore6_SRCS
+
+if GetDepend(['RT_LWIP_USING_PING']):
+ src += lwipping_SRCS
+
+group = DefineGroup('lwIP', src, depend = ['RT_USING_LWIP', 'RT_USING_LWIP221'], CPPPATH = path)
+
+Return('group')
diff --git a/components/net/lwip/lwip-2.2.1/src/api/sockets.c b/components/net/lwip/lwip-2.2.1/src/api/sockets.c
index b97bdd7e0b..de0745214f 100644
--- a/components/net/lwip/lwip-2.2.1/src/api/sockets.c
+++ b/components/net/lwip/lwip-2.2.1/src/api/sockets.c
@@ -509,6 +509,25 @@ tryget_socket(int fd)
}
/**
+ * Same as tryget_socket but a global routine.
+ *
+ * @param fd externally used socket index
+ * @return struct lwip_sock for the socket or NULL if not found
+ */
+struct lwip_sock *
+lwip_tryget_socket(int fd)
+{
+ struct lwip_sock *sock = tryget_socket_unconn(fd);
+ if (sock != NULL) {
+ if (sock->conn) {
+ return sock;
+ }
+ done_socket(sock);
+ }
+ return NULL;
+}
+
+/**
* Map a externally used socket index to the internal socket representation.
*
* @param fd externally used socket index
@@ -569,6 +588,9 @@ alloc_socket(struct netconn *newconn, int accepted)
sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1);
sockets[i].errevent = 0;
#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
+#ifdef SAL_USING_POSIX
+ rt_wqueue_init(&sockets[i].wait_head);
+#endif
return i + LWIP_SOCKET_OFFSET;
}
SYS_ARCH_UNPROTECT(lev);
diff --git a/components/net/lwip/lwip-2.2.1/src/apps/altcp_tls/altcp_tls_mbedtls.c b/components/net/lwip/lwip-2.2.1/src/apps/altcp_tls/altcp_tls_mbedtls.c
index 9e6191269d..14ad18dffb 100644
--- a/components/net/lwip/lwip-2.2.1/src/apps/altcp_tls/altcp_tls_mbedtls.c
+++ b/components/net/lwip/lwip-2.2.1/src/apps/altcp_tls/altcp_tls_mbedtls.c
@@ -838,7 +838,11 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
altcp_mbedtls_free_config(conf);
return NULL;
}
- mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE);
+ if (!is_server && have_ca) {
+ mbedtls_ssl_conf_authmode(&conf->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
+ } else {
+ mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE);
+ }
mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
#if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF
diff --git a/components/net/lwip/lwip-2.2.1/src/apps/ping/ping.c b/components/net/lwip/lwip-2.2.1/src/apps/ping/ping.c
new file mode 100644
index 0000000000..b4a7b769a2
--- /dev/null
+++ b/components/net/lwip/lwip-2.2.1/src/apps/ping/ping.c
@@ -0,0 +1,247 @@
+/*
+ * netutils: ping implementation
+ */
+
+#include <rtthread.h>
+
+#ifdef RT_LWIP_ICMP /* don't build if not configured for use in rtconfig.h */
+#include <lwip/opt.h>
+#include <lwip/init.h>
+#include <lwip/mem.h>
+#include <lwip/icmp.h>
+#include <lwip/netif.h>
+#include <lwip/sys.h>
+#include <lwip/inet.h>
+#include <lwip/inet_chksum.h>
+#include <lwip/ip.h>
+#include <lwip/netdb.h>
+#include <lwip/sockets.h>
+
+/**
+ * PING_DEBUG: Enable debugging for PING.
+ */
+#ifndef PING_DEBUG
+#define PING_DEBUG LWIP_DBG_ON
+#endif
+
+/** ping receive timeout - in milliseconds */
+#define PING_RCV_TIMEO (2 * RT_TICK_PER_SECOND)
+/** ping delay - in milliseconds */
+#define PING_DELAY (1 * RT_TICK_PER_SECOND)
+
+/** ping identifier - must fit on a u16_t */
+#ifndef PING_ID
+#define PING_ID 0xAFAF
+#endif
+
+/** ping additional data size to include in the packet */
+#ifndef PING_DATA_SIZE
+#define PING_DATA_SIZE 32
+#endif
+
+/* ping variables */
+static u16_t ping_seq_num;
+struct _ip_addr
+{
+ rt_uint8_t addr0, addr1, addr2, addr3;
+};
+
+/** Prepare a echo ICMP request */
+static void ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
+{
+ size_t i;
+ size_t data_len = len - sizeof(struct icmp_echo_hdr);
+
+ ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+ ICMPH_CODE_SET(iecho, 0);
+ iecho->chksum = 0;
+ iecho->id = PING_ID;
+ iecho->seqno = htons(++ping_seq_num);
+
+ /* fill the additional data buffer with some data */
+ for (i = 0; i < data_len; i++)
+ {
+ ((char*) iecho)[sizeof(struct icmp_echo_hdr) + i] = (char) i;
+ }
+
+#ifdef RT_LWIP_USING_HW_CHECKSUM
+ iecho->chksum = 0;
+#else
+ iecho->chksum = inet_chksum(iecho, len);
+#endif
+
+}
+
+/* Ping using the socket ip */
+err_t lwip_ping_send(int s, ip_addr_t *addr, int size)
+{
+ int err;
+ struct icmp_echo_hdr *iecho;
+ struct sockaddr_in to;
+ int ping_size = sizeof(struct icmp_echo_hdr) + size;
+ LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
+
+ iecho = rt_malloc(ping_size);
+ if (iecho == RT_NULL)
+ {
+ return ERR_MEM;
+ }
+
+ ping_prepare_echo(iecho, (u16_t) ping_size);
+
+ to.sin_len = sizeof(to);
+ to.sin_family = AF_INET;
+#if LWIP_IPV4 && LWIP_IPV6
+ to.sin_addr.s_addr = addr->u_addr.ip4.addr;
+#elif LWIP_IPV4
+ to.sin_addr.s_addr = addr->addr;
+#elif LWIP_IPV6
+#error Not supported IPv6.
+#endif
+
+ err = lwip_sendto(s, iecho, ping_size, 0, (struct sockaddr*) &to, sizeof(to));
+ rt_free(iecho);
+
+ return (err == ping_size ? ERR_OK : ERR_VAL);
+}
+
+int lwip_ping_recv(int s, int *ttl)
+{
+ char buf[64];
+ int fromlen = sizeof(struct sockaddr_in), len;
+ struct sockaddr_in from;
+ struct ip_hdr *iphdr;
+ struct icmp_echo_hdr *iecho;
+
+ while ((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*) &from, (socklen_t*) &fromlen)) > 0)
+ {
+ if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr)))
+ {
+ iphdr = (struct ip_hdr *) buf;
+ iecho = (struct icmp_echo_hdr *) (buf + (IPH_HL(iphdr) * 4));
+ if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num)))
+ {
+ *ttl = iphdr->_ttl;
+ return len;
+ }
+ }
+ }
+
+ return len;
+}
+
+#ifndef RT_USING_NETDEV
+
+/* using the lwIP custom ping */
+rt_err_t ping(char* target_name, rt_uint32_t times, rt_size_t size)
+{
+
+#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
+ int timeout = (int)PING_RCV_TIMEO;
+#else
+ struct timeval timeout = { PING_RCV_TIMEO / RT_TICK_PER_SECOND, PING_RCV_TIMEO % RT_TICK_PER_SECOND };
+#endif /* LWIP_SO_SNDRCVTIMEO_NONSTANDARD */
+
+ int s, ttl, recv_len;
+ ip_addr_t target_addr;
+ rt_uint32_t send_times;
+ rt_tick_t recv_start_tick;
+ struct addrinfo hint, *res = NULL;
+ struct sockaddr_in *h = NULL;
+ struct in_addr ina;
+
+ send_times = 0;
+ ping_seq_num = 0;
+
+ if (size == 0)
+ {
+ size = PING_DATA_SIZE;
+ }
+
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_family = AF_INET;
+ /* convert URL to IP */
+ if (lwip_getaddrinfo(target_name, NULL, &hint, &res) != 0)
+ {
+ rt_kprintf("ping: unknown host %s\n", target_name);
+ return -RT_ERROR;
+ }
+ h = (struct sockaddr_in *)res->ai_addr;
+ memcpy(&ina, &h->sin_addr, sizeof(ina));
+ lwip_freeaddrinfo(res);
+ if (inet_aton(inet_ntoa(ina), &target_addr) == 0)
+ {
+ rt_kprintf("ping: unknown host %s\n", target_name);
+ return -RT_ERROR;
+ }
+ /* new a socket */
+ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
+ {
+ rt_kprintf("ping: create socket failed\n");
+ return -RT_ERROR;
+ }
+
+ lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+
+ while (1)
+ {
+ int elapsed_time;
+
+ if (lwip_ping_send(s, &target_addr, size) == ERR_OK)
+ {
+ recv_start_tick = rt_tick_get();
+ if ((recv_len = lwip_ping_recv(s, &ttl)) >= 0)
+ {
+ elapsed_time = (rt_tick_get() - recv_start_tick) * 1000UL / RT_TICK_PER_SECOND;
+ rt_kprintf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n", recv_len, inet_ntoa(ina), send_times,
+ ttl, elapsed_time);
+ }
+ else
+ {
+ rt_kprintf("From %s icmp_seq=%d timeout\n", inet_ntoa(ina), send_times);
+ }
+ }
+ else
+ {
+ rt_kprintf("Send %s - error\n", inet_ntoa(ina));
+ }
+
+ send_times++;
+ if (send_times >= times)
+ {
+ /* send ping times reached, stop */
+ break;
+ }
+
+ rt_thread_delay(PING_DELAY); /* take a delay */
+ }
+
+ lwip_close(s);
+
+ return RT_EOK;
+}
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+
+FINSH_FUNCTION_EXPORT(ping, ping network host);
+
+int cmd_ping(int argc, char **argv)
+{
+ if (argc == 1)
+ {
+ rt_kprintf("Please input: ping <host address>\n");
+ }
+ else
+ {
+ ping(argv[1], 4, 0);
+ }
+
+ return 0;
+}
+MSH_CMD_EXPORT_ALIAS(cmd_ping, ping, ping network host);
+#endif /* RT_USING_FINSH */
+
+#endif /* RT_USING_NETDEV */
+
+#endif /* RT_LWIP_ICMP */
+
diff --git a/components/net/lwip/lwip-2.2.1/src/apps/tftp/tftp_port.c b/components/net/lwip/lwip-2.2.1/src/apps/tftp/tftp_port.c
new file mode 100644
index 0000000000..94b8e9de90
--- /dev/null
+++ b/components/net/lwip/lwip-2.2.1/src/apps/tftp/tftp_port.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2017-08-17 armink first version.
+ */
+
+
+#include <rtthread.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <lwip/apps/tftp_server.h>
+
+static struct tftp_context ctx;
+
+/* lwIP 2.2.x: tftp.c invokes ctx->error without NULL-check; the callback
+ * is effectively mandatory (see tftp.c recv error path). */
+static void tftp_error(void* handle, int err, const char* msg, int size)
+{
+ LWIP_UNUSED_ARG(handle);
+ rt_kprintf("TFTP error: %d, %.*s\n", err, size, msg);
+}
+
+static void* tftp_open(const char* fname, const char* mode, u8_t write)
+{
+ int fd = -1;
+
+ if (!rt_strcmp(mode, "octet"))
+ {
+ if (write)
+ {
+ fd = open(fname, O_WRONLY | O_CREAT, 0);
+ }
+ else
+ {
+ fd = open(fname, O_RDONLY, 0);
+ }
+ }
+ else
+ {
+ rt_kprintf("tftp: No support this mode(%s).", mode);
+ }
+
+ return (void *) fd;
+}
+
+static int tftp_write(void* handle, struct pbuf* p)
+{
+ int fd = (int) handle;
+
+ return write(fd, p->payload, p->len);
+}
+
+#if defined(RT_USING_FINSH)
+#include <finsh.h>
+
+static void tftp_server(uint8_t argc, char **argv)
+{
+ ctx.open = tftp_open;
+ ctx.close = (void (*)(void *)) close;
+ ctx.read = (int (*)(void *, void *, int)) read;
+ ctx.write = tftp_write;
+ ctx.error = tftp_error; /* lwIP 2.2.x 新增,必填 */
+
+ if (tftp_init_server(&ctx) == ERR_OK) /* lwIP 2.2.x: tftp_init → tftp_init_server */
+ {
+ rt_kprintf("TFTP server start successfully.\n");
+ }
+ else
+ {
+ rt_kprintf("TFTP server start failed.\n");
+ }
+}
+FINSH_FUNCTION_EXPORT(tftp_server, start tftp server.);
+
+MSH_CMD_EXPORT(tftp_server, start tftp server.);
+
+#endif /* defined(RT_USING_FINSH) */
diff --git a/components/net/lwip/lwip-2.2.1/src/core/dns.c b/components/net/lwip/lwip-2.2.1/src/core/dns.c
index 6540f143ba..5e8c18a4c7 100644
--- a/components/net/lwip/lwip-2.2.1/src/core/dns.c
+++ b/components/net/lwip/lwip-2.2.1/src/core/dns.c
@@ -97,6 +97,12 @@
#include <string.h>
+#include <rtthread.h>
+
+#ifdef RT_USING_NETDEV
+#include "netdev.h"
+#endif
+
/** Random generator function to create random TXIDs and source ports for queries */
#ifndef DNS_RAND_TXID
#if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0)
@@ -298,7 +304,9 @@ static u8_t dns_last_pcb_idx;
static u8_t dns_seqno;
static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS];
+#ifndef RT_USING_NETDEV
static ip_addr_t dns_servers[DNS_MAX_SERVERS];
+#endif
#if LWIP_IPV4
const ip_addr_t dns_mquery_v4group = DNS_MQUERY_IPV4_GROUP_INIT;
@@ -362,9 +370,25 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
{
if (numdns < DNS_MAX_SERVERS) {
if (dnsserver != NULL) {
+#ifdef RT_USING_NETDEV
+ struct netif *netif = NULL;
+
+ /* set network interface device DNS server address */
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ netdev_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
+ }
+#else
dns_servers[numdns] = (*dnsserver);
+#endif /* RT_USING_NETDEV */
} else {
+#ifdef RT_USING_NETDEV
+ struct netif *netif = NULL;
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ netdev_set_dns_server(netdev_get_by_name(netif->name), numdns, IP_ADDR_ANY);
+ }
+#else
dns_servers[numdns] = *IP_ADDR_ANY;
+#endif
}
}
}
@@ -381,7 +405,11 @@ const ip_addr_t *
dns_getserver(u8_t numdns)
{
if (numdns < DNS_MAX_SERVERS) {
+#ifdef RT_USING_NETDEV
+ return &netdev_default->dns_servers[numdns];
+#else
return &dns_servers[numdns];
+#endif
} else {
return IP_ADDR_ANY;
}
@@ -775,11 +803,19 @@ dns_send(u8_t idx)
u8_t n;
u8_t pcb_idx;
struct dns_table_entry *entry = &dns_table[idx];
+ const ip_addr_t *dns_addr;
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
(u16_t)(entry->server_idx), entry->name));
LWIP_ASSERT("dns server out of array", entry->server_idx < DNS_MAX_SERVERS);
- if (ip_addr_isany_val(dns_servers[entry->server_idx])
+
+#ifdef RT_USING_NETDEV
+ dns_addr = &netdev_default->dns_servers[entry->server_idx];
+#else
+ dns_addr = &dns_servers[entry->server_idx];
+#endif
+
+ if (ip_addr_isany(dns_addr)
#if LWIP_DNS_SUPPORT_MDNS_QUERIES
&& !entry->is_mdns
#endif
@@ -864,7 +900,11 @@ dns_send(u8_t idx)
#endif /* LWIP_DNS_SUPPORT_MDNS_QUERIES */
{
dst_port = DNS_SERVER_PORT;
- dst = &dns_servers[entry->server_idx];
+ dst = dns_addr;
+#ifdef RT_USING_NETDEV
+ /* set netif index for this pcb, specify the network interface corresponding to the DNS server */
+ dns_pcbs[pcb_idx]->netif_idx = netif_get_index((struct netif *)netdev_default->user_data);
+#endif
}
err = udp_sendto(dns_pcbs[pcb_idx], p, dst, dst_port);
@@ -1045,8 +1085,15 @@ dns_backupserver_available(struct dns_table_entry *pentry)
u8_t ret = 0;
if (pentry) {
- if ((pentry->server_idx + 1 < DNS_MAX_SERVERS) && !ip_addr_isany_val(dns_servers[pentry->server_idx + 1])) {
- ret = 1;
+ if ((pentry->server_idx + 1 < DNS_MAX_SERVERS)) {
+#ifdef RT_USING_NETDEV
+ const ip_addr_t *dns_addr = &netdev_default->dns_servers[pentry->server_idx + 1];
+#else
+ const ip_addr_t *dns_addr = &dns_servers[pentry->server_idx + 1];
+#endif
+ if (!ip_addr_isany(dns_addr)) {
+ ret = 1;
+ }
}
}
@@ -1235,9 +1282,16 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
if (!entry->is_mdns)
#endif /* LWIP_DNS_SUPPORT_MDNS_QUERIES */
{
+#ifdef RT_USING_NETDEV
+ const ip_addr_t *dns_addr = &netdev_default->dns_servers[entry->server_idx];
+#else
+ const ip_addr_t *dns_addr = &dns_servers[entry->server_idx];
+#endif
/* Check whether response comes from the same network address to which the
question was sent. (RFC 5452) */
- if (!ip_addr_eq(addr, &dns_servers[entry->server_idx])) {
+ /* RT-Thread: compare against the per-device server selected above
+ * (ip_addr_eq is upstream 2.2.1's renamed ip_addr_cmp). */
+ if (!ip_addr_eq(addr, dns_addr)) {
goto ignore_packet; /* ignore this packet */
}
}
@@ -1643,8 +1697,13 @@ dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, dns_found_call
if (!is_mdns)
#endif /* LWIP_DNS_SUPPORT_MDNS_QUERIES */
{
+#ifdef RT_USING_NETDEV
+ const ip_addr_t *dns_addr = &netdev_default->dns_servers[0];
+#else
+ const ip_addr_t *dns_addr = &dns_servers[0];
+#endif
/* prevent calling found callback if no server is set, return error instead */
- if (ip_addr_isany_val(dns_servers[0])) {
+ if (ip_addr_isany(dns_addr)) {
return ERR_VAL;
}
}
diff --git a/components/net/lwip/lwip-2.2.1/src/core/ipv4/dhcp.c b/components/net/lwip/lwip-2.2.1/src/core/ipv4/dhcp.c
index 12e00683dd..b52b660fb3 100644
--- a/components/net/lwip/lwip-2.2.1/src/core/ipv4/dhcp.c
+++ b/components/net/lwip/lwip-2.2.1/src/core/ipv4/dhcp.c
@@ -740,7 +740,16 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
ip_addr_t dns_addr;
ip_addr_set_ip4_u32_val(dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
+#ifdef RT_USING_NETDEV
+ extern struct netdev *netdev_get_by_name(const char *name);
+ extern void netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ /* Here we only need to set the dns server of the corresponding network device,
+ * but do not need to configure all network devices.
+ */
+ netdev_set_dns_server(netdev_get_by_name(netif->name), n, &dns_addr);
+#else
dns_setserver(n, &dns_addr);
+#endif
}
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
}
diff --git a/components/net/lwip/lwip-2.2.1/src/core/ipv6/dhcp6.c b/components/net/lwip/lwip-2.2.1/src/core/ipv6/dhcp6.c
index e6a7e64da9..0829d9c297 100644
--- a/components/net/lwip/lwip-2.2.1/src/core/ipv6/dhcp6.c
+++ b/components/net/lwip/lwip-2.2.1/src/core/ipv6/dhcp6.c
@@ -547,7 +547,16 @@ dhcp6_handle_config_reply(struct netif *netif, struct pbuf *p_msg_in)
}
ip6_addr_assign_zone(dns_addr6, IP6_UNKNOWN, netif);
/* @todo: do we need a different offset than DHCP(v4)? */
+#ifdef RT_USING_NETDEV
+ extern struct netdev *netdev_get_by_name(const char *name);
+ extern void netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ /* Here we only need to set the dns server of the corresponding network device,
+ * but do not need to configure all network devices.
+ */
+ netdev_set_dns_server(netdev_get_by_name(netif->name), n, &dns_addr);
+#else
dns_setserver(n, &dns_addr);
+#endif
}
}
/* @ todo: parse and set Domain Search List */
diff --git a/components/net/lwip/lwip-2.2.1/src/core/ipv6/nd6.c b/components/net/lwip/lwip-2.2.1/src/core/ipv6/nd6.c
index f7b5f56361..40dfd869f0 100644
--- a/components/net/lwip/lwip-2.2.1/src/core/ipv6/nd6.c
+++ b/components/net/lwip/lwip-2.2.1/src/core/ipv6/nd6.c
@@ -791,14 +791,37 @@ nd6_input(struct pbuf *p, struct netif *inp)
if (htonl(rdnss_opt->lifetime) > 0) {
/* TODO implement Lifetime > 0 */
+#ifdef RT_USING_NETDEV
+ extern struct netdev *netdev_get_by_name(const char *name);
+ extern void netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ /* Here we only need to set the dns server of the corresponding network device,
+ * but do not need to configure all network devices.
+ */
+ netdev_set_dns_server(netdev_get_by_name(inp->name), rdnss_server_idx++, &rdnss_address);
+#else
dns_setserver(rdnss_server_idx++, &rdnss_address);
+#endif
} else {
/* TODO implement DNS removal in dns.c */
u8_t s;
for (s = 0; s < DNS_MAX_SERVERS; s++) {
const ip_addr_t *addr = dns_getserver(s);
+ /* RT-Thread: clear only the matching server of this device
+ * (ip_addr_eq is upstream 2.2.1's renamed ip_addr_cmp). */
if(ip_addr_eq(addr, &rdnss_address)) {
+#ifdef RT_USING_NETDEV
+ extern struct netdev *netdev_get_by_name(const char *name);
+ extern void netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ /* Here we only need to set the dns server of the corresponding network device,
+ * but do not need to configure all network devices.
+ */
+ netdev_set_dns_server(netdev_get_by_name(inp->name), s, IP_ADDR_ANY);
+#else
+ /* RT-Thread: RT 2.1.2 wrote IP_ADDR_ANY here; upstream 2.2.1 passes NULL.
+ * dns_setserver() maps a NULL server back to IP_ADDR_ANY (core/dns.c),
+ * so both forms clear the server — kept the upstream form. */
dns_setserver(s, NULL);
+#endif
}
}
}
diff --git a/components/net/lwip/lwip-2.2.1/src/core/netif.c b/components/net/lwip/lwip-2.2.1/src/core/netif.c
index 98e0553f86..8a0f7af368 100644
--- a/components/net/lwip/lwip-2.2.1/src/core/netif.c
+++ b/components/net/lwip/lwip-2.2.1/src/core/netif.c
@@ -93,6 +93,13 @@
#include "lwip/nd6.h"
#endif
+#include <rtthread.h>
+
+#ifdef RT_USING_NETDEV
+#include "lwip/netdb.h"
+#include <netdev.h>
+#endif /* RT_USING_NETDEV */
+
#if LWIP_NETIF_STATUS_CALLBACK
#define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
#else
@@ -502,6 +509,12 @@ netif_do_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr, ip_addr_t *ol
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4);
NETIF_STATUS_CALLBACK(netif);
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread sal network interface device set IP address operations */
+ netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), &netif->ip_addr);
+#endif /* RT_USING_NETDEV */
+
return 1; /* address changed */
}
return 0; /* address unchanged */
@@ -562,6 +575,12 @@ netif_do_set_netmask(struct netif *netif, const ip4_addr_t *netmask, ip_addr_t *
ip4_addr2_16(netif_ip4_netmask(netif)),
ip4_addr3_16(netif_ip4_netmask(netif)),
ip4_addr4_16(netif_ip4_netmask(netif))));
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set netmask address */
+ netdev_low_level_set_netmask(netdev_get_by_name(netif->name), &netif->netmask);
+#endif /* RT_USING_NETDEV */
+
return 1; /* netmask changed */
}
return 0; /* netmask unchanged */
@@ -624,6 +643,12 @@ netif_do_set_gw(struct netif *netif, const ip4_addr_t *gw, ip_addr_t *old_gw)
ip4_addr2_16(netif_ip4_gw(netif)),
ip4_addr3_16(netif_ip4_gw(netif)),
ip4_addr4_16(netif_ip4_gw(netif))));
+
+#ifdef RT_USING_NETDEV
+ /* rt_thread network interface device set gateway address */
+ netdev_low_level_set_gw(netdev_get_by_name(netif->name), &netif->gw);
+#endif /* RT_USING_NETDEV */
+
return 1; /* gateway changed */
}
return 0; /* gateway unchanged */
@@ -893,6 +918,11 @@ netif_set_up(struct netif *netif)
#if LWIP_IPV6
nd6_restart_netif(netif);
#endif /* LWIP_IPV6 */
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set up status */
+ netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_TRUE);
+#endif /* RT_USING_NETDEV */
}
}
@@ -975,6 +1005,11 @@ netif_set_down(struct netif *netif)
#endif /* LWIP_IPV6 */
NETIF_STATUS_CALLBACK(netif);
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set down status */
+ netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_FALSE);
+#endif /* RT_USING_NETDEV */
}
}
@@ -1045,6 +1080,11 @@ netif_set_link_up(struct netif *netif)
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
}
#endif
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set link up status */
+ netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_TRUE);
+#endif /* RT_USING_NETDEV */
}
}
@@ -1082,6 +1122,11 @@ netif_set_link_down(struct netif *netif)
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
}
#endif
+
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set link down status */
+ netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_FALSE);
+#endif /* RT_USING_NETDEV */
}
}
@@ -1595,6 +1640,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
* zone field, so this should not create any compatibility problems. */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif);
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[0], netif->ip6_addr[0]);
+#endif /* RT_USING_NETDEV */
+
/* Set address state. */
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
/* Will perform duplicate address detection (DAD). */
@@ -1638,6 +1688,10 @@ netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chos
for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[i], netif->ip6_addr[i]);
+#endif /* RT_USING_NETDEV */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif);
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) {
@@ -1763,8 +1817,12 @@ netif_find(const char *name)
return NULL;
}
- num = (u8_t)atoi(&name[2]);
- if (!num && (name[2] != '0')) {
+ /* RT-Thread netif names are "e0", "e1" ... (2 chars, see NETIF_NAMESIZE),
+ * not upstream's "en0" style where the number starts at name[2].
+ * Keep RT's &name[1] offset; upstream 2.2.1 added an atoi-failure check
+ * which is adapted here for the 2-char naming convention. */
+ num = (u8_t)atoi(&name[1]);
+ if (!num && (name[1] != '0')) {
/* this means atoi has failed */
return NULL;
}
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/arch.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/arch.h
index c659a80c7f..1fc3f4b753 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/arch.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/arch.h
@@ -196,7 +196,9 @@ typedef uintptr_t mem_ptr_t;
#define LWIP_NO_UNISTD_H 0
#endif
#if !LWIP_NO_UNISTD_H
-#include <unistd.h>
+#include "sys/types.h"
+#else
+typedef int ssize_t;
#endif
#else /* SSIZE_MAX */
typedef int ssize_t;
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/ip_addr.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/ip_addr.h
index 06454a4ac4..6789dc097e 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/ip_addr.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/ip_addr.h
@@ -461,6 +461,8 @@ extern const ip_addr_t ip6_addr_any;
#define IP_ANY_TYPE IP_ADDR_ANY
#endif
+struct netif *lwip_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/netif.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/netif.h
index 0cde2c2ad2..3d4f4761cd 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/netif.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/netif.h
@@ -67,7 +67,9 @@ extern "C" {
* netif can be identified by in APIs. Composed of
* 2 chars, 3 (max) digits, and 1 \0
*/
+#ifndef NETIF_NAMESIZE
#define NETIF_NAMESIZE 6
+#endif
/**
* @defgroup netif_flags Flags
@@ -353,7 +355,9 @@ struct netif {
/** flags (@see @ref netif_flags) */
u8_t flags;
/** descriptive abbreviation */
- char name[2];
+ /* RT-Thread: widened from upstream's char name[2] to NETIF_NAMESIZE so the
+ * full "e0"-style name can be stored (consumed by ethernetif.c rt_strncpy). */
+ char name[NETIF_NAMESIZE];
/** number of this interface. Used for @ref if_api and @ref netifapi_netif,
* as well as for IPv6 zones */
u8_t num;
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/priv/sockets_priv.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/priv/sockets_priv.h
index c604734c25..b40f70794c 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/priv/sockets_priv.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/priv/sockets_priv.h
@@ -63,6 +63,11 @@ union lwip_sock_lastdata {
struct pbuf *pbuf;
};
+#include <rtthread.h>
+#ifdef SAL_USING_POSIX
+#include <ipc/waitqueue.h>
+#endif
+
/** Contains all internal pointers and states used for a socket */
struct lwip_sock {
/** sockets currently are built on netconns, each socket has one netconn */
@@ -89,6 +94,10 @@ struct lwip_sock {
#define LWIP_SOCK_FD_FREE_TCP 1
#define LWIP_SOCK_FD_FREE_FREE 2
#endif
+
+#ifdef SAL_USING_POSIX
+ rt_wqueue_t wait_head;
+#endif
};
#ifndef set_errno
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/prot/ieee.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/prot/ieee.h
index cd4d2dea30..dce8bebce1 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/prot/ieee.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/prot/ieee.h
@@ -68,6 +68,8 @@ enum lwip_ieee_eth_type {
ETHTYPE_PPPOE = 0x8864U,
/** Jumbo Frames */
ETHTYPE_JUMBO = 0x8870U,
+ /** EAPOL, EAP over LAN */
+ ETHTYPE_EAPOL = 0x888EU,
/** Process field network */
ETHTYPE_PROFINET = 0x8892U,
/** Ethernet for control automation technology */
diff --git a/components/net/lwip/lwip-2.2.1/src/include/lwip/sockets.h b/components/net/lwip/lwip-2.2.1/src/include/lwip/sockets.h
index b6f3d524f1..dd5137e7b6 100644
--- a/components/net/lwip/lwip-2.2.1/src/include/lwip/sockets.h
+++ b/components/net/lwip/lwip-2.2.1/src/include/lwip/sockets.h
@@ -436,6 +436,8 @@ typedef struct ipv6_mreq {
#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
+#endif
+#ifndef SIOCATMARK
#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
#endif
@@ -498,9 +500,22 @@ typedef struct fd_set
#define LWIP_SELECT_MAXNFDS FD_SETSIZE
#endif /* FD_SET */
+#if LWIP_SOCKET_SELECT
/* poll-related defines and types */
/* @todo: find a better way to guard the definition of these defines and types if already defined */
#if !defined(POLLIN) && !defined(POLLOUT)
+#ifdef RT_USING_MUSLLIBC
+#define POLLIN 0x001 /**< There is data to read. */
+#define POLLPRI 0x002 /**< There is urgent data to read. */
+#define POLLOUT 0x004 /**< Writing is now possible. */
+#define POLLERR 0x008 /**< Error condition. */
+#define POLLHUP 0x010 /**< Hang up. */
+#define POLLNVAL 0x020 /**< Invalid polling request. */
+#define POLLRDNORM 0x040 /**< Normal data may be read. */
+#define POLLRDBAND 0x080 /**< Priority data may be read. */
+#define POLLWRNORM 0x100 /**< Writing normal data is possible. */
+#define POLLWRBAND 0x200 /**< Writing priority data is possible. */
+#else
#define POLLIN 0x1
#define POLLOUT 0x2
#define POLLERR 0x4
@@ -512,6 +527,7 @@ typedef struct fd_set
#define POLLWRNORM 0x80
#define POLLWRBAND 0x100
#define POLLHUP 0x200
+#endif /* RT_USING_MUSLLIBC */
typedef unsigned int nfds_t;
struct pollfd
{
@@ -520,6 +536,7 @@ struct pollfd
short revents;
};
#endif
+#endif
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
* by your system, set this to 0 and include <sys/time.h> in cc.h */
diff --git a/components/net/lwip/lwip-2.2.1/src/netif/lowpan6.c b/components/net/lwip/lwip-2.2.1/src/netif/lowpan6.c
index 8eb751c04b..a7da63de1f 100644
--- a/components/net/lwip/lwip-2.2.1/src/netif/lowpan6.c
+++ b/components/net/lwip/lwip-2.2.1/src/netif/lowpan6.c
@@ -50,7 +50,7 @@
#include "netif/lowpan6.h"
-#if LWIP_IPV6
+#if LWIP_IPV6 && LWIP_6LOWPAN
#include "lwip/ip.h"
#include "lwip/pbuf.h"
diff --git a/components/net/lwip/lwip-2.2.1/src/netif/ppp/ppp.c b/components/net/lwip/lwip-2.2.1/src/netif/ppp/ppp.c
index 1cd5958e34..83500e8b3d 100644
--- a/components/net/lwip/lwip-2.2.1/src/netif/ppp/ppp.c
+++ b/components/net/lwip/lwip-2.2.1/src/netif/ppp/ppp.c
@@ -24,7 +24,8 @@
*
******************************************************************************
* REVISION HISTORY
-*
+* 24-09-12 Evlers <[email protected]>
+* add support for independent dns services for multiple network devices
* 03-01-01 Marc Boucher <[email protected]>
* Ported to lwIP.
* 97-11-05 Guy Lancaster <[email protected]>, Global Election Systems Inc.
@@ -134,6 +135,9 @@
#if PPP_IPV6_SUPPORT
#include "netif/ppp/ipv6cp.h"
#endif /* PPP_IPV6_SUPPORT */
+#ifdef RT_USING_NETDEV
+#include "netdev.h"
+#endif /* RT_USING_NETDEV */
/*************************/
/*** LOCAL DEFINITIONS ***/
@@ -469,8 +473,7 @@ static void ppp_do_connect(void *arg) {
* ppp_netif_init_cb - netif init callback
*/
static err_t ppp_netif_init_cb(struct netif *netif) {
- netif->name[0] = 'p';
- netif->name[1] = 'p';
+ rt_strncpy(netif->name, "pp", sizeof(netif->name));
#if PPP_IPV4_SUPPORT
netif->output = ppp_netif_output_ip4;
#endif /* PPP_IPV4_SUPPORT */
@@ -1123,9 +1126,20 @@ int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
LWIP_UNUSED_ARG(pcb);
ip_addr_set_ip4_u32_val(ns, ns1);
+#ifdef RT_USING_NETDEV
+ /* Here we only need to set the dns server of the corresponding network device,
+ * but do not need to configure all network cards.
+ */
+ netdev_set_dns_server(netdev_get_by_name(pcb->netif->name), 0, &ns);
+#else
dns_setserver(0, &ns);
+#endif
ip_addr_set_ip4_u32_val(ns, ns2);
+#ifdef RT_USING_NETDEV
+ netdev_set_dns_server(netdev_get_by_name(pcb->netif->name), 1, &ns);
+#else
dns_setserver(1, &ns);
+#endif
return 1;
}
@@ -1140,13 +1154,23 @@ int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
nsa = dns_getserver(0);
ip_addr_set_ip4_u32_val(nsb, ns1);
+ /* RT-Thread: clear the DNS server of the device owning this PCB
+ * (ip_addr_eq is upstream 2.2.1's renamed ip_addr_cmp). */
if (ip_addr_eq(nsa, &nsb)) {
+#ifdef RT_USING_NETDEV
+ netdev_set_dns_server(netdev_get_by_name(pcb->netif->name), 0, IP_ADDR_ANY);
+#else
dns_setserver(0, IP_ADDR_ANY);
+#endif
}
nsa = dns_getserver(1);
ip_addr_set_ip4_u32_val(nsb, ns2);
if (ip_addr_eq(nsa, &nsb)) {
+#ifdef RT_USING_NETDEV
+ netdev_set_dns_server(netdev_get_by_name(pcb->netif->name), 1, IP_ADDR_ANY);
+#else
dns_setserver(1, IP_ADDR_ANY);
+#endif
}
return 1;
}
diff --git a/components/net/lwip/port/lwipopts.h b/components/net/lwip/port/lwipopts.h
index b9b841b8bb..424430c665 100644
--- a/components/net/lwip/port/lwipopts.h
+++ b/components/net/lwip/port/lwipopts.h
@@ -464,9 +464,18 @@
#define LWIP_DHCP 0
#endif
-/* 1 if you want to do an ARP check on the offered address
- (recommended). */
-#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
+/* 2.2.0 replaces DHCP_DOES_ARP_CHECK with ACD (RFC 5227 address conflict
+ * detection). The legacy macro is silently unused in 2.2.x, so map the
+ * intent onto the new option by version. This also makes the behavior
+ * explicit against upstream default drift: the 2.2.1 release default for
+ * LWIP_DHCP_DOES_ACD_CHECK is (LWIP_DHCP) (opt.h), i.e. same intent as
+ * RT's 2.1.2 DHCP_DOES_ARP_CHECK. Requires acd.c in the build
+ * (see lwip-2.2.1/SConscript). */
+#if RT_USING_LWIP_VER_NUM >= 0x20200
+#define LWIP_DHCP_DOES_ACD_CHECK (LWIP_DHCP)
+#else
+#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
+#endif
/* ---------- AUTOIP options ------- */
#define LWIP_AUTOIP 0
@@ -595,11 +604,18 @@
#endif
/* MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. */
+#if RT_USING_LWIP_VER_NUM >= 0x20200
+/* lwIP 2.2.x changed the pool formula (LWIP_ACD, LWIP_IPV6_DHCP6,
+ * PPP_NUM_TIMEOUTS_PER_PCB). Do not derive it here; fall back to the
+ * upstream opt.h default (MEMP_NUM_SYS_TIMEOUT == LWIP_NUM_SYS_TIMEOUT_INTERNAL,
+ * opt.h:527 in 2.2.1) which always matches its own code. */
+#else
#if RT_USING_LWIP_VER_NUM == 0x20102
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD)))
#else
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2*LWIP_IPV6)) : 0))
#endif
+#endif
/*
* LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names.
diff --git a/components/net/sal/impl/af_inet_lwip.c b/components/net/sal/impl/af_inet_lwip.c
index 876dfba535..7759611170 100644
--- a/components/net/sal/impl/af_inet_lwip.c
+++ b/components/net/sal/impl/af_inet_lwip.c
@@ -39,6 +39,16 @@
#endif
#endif
+/* lwIP 2.2.0 merged netconn::socket into the callback_arg union
+ * (see include/lwip/api.h); older lwIP keeps a plain int socket member.
+ * Route all accesses through this accessor so the file compiles against
+ * every supported lwIP version. */
+#if RT_USING_LWIP_VER_NUM >= 0x20200
+#define SAL_NETCONN_SOCKET(conn) ((conn)->callback_arg.socket)
+#else
+#define SAL_NETCONN_SOCKET(conn) ((conn)->socket)
+#endif
+
#ifdef SAL_USING_LWIP
#ifdef SAL_USING_POSIX
@@ -51,7 +61,8 @@
*
* NOTE: please make sure the definitions same in lwip::net_socket.c
*/
-struct lwip_sock {
+struct lwip_sock
+{
/** sockets currently are built on netconns, each socket has one netconn */
struct netconn *conn;
/** data that was left from the previous read */
@@ -68,9 +79,9 @@ struct lwip_sock {
u16_t errevent;
/** last error that occurred on this socket */
#if LWIP_VERSION < 0x2000000
- int err;
+ int err;
#else
- u8_t err;
+ u8_t err;
#endif
/** counter of how many threads are waiting for this socket using select */
SELWAIT_T select_waiting;
@@ -83,6 +94,10 @@ static RT_DEFINE_SPINLOCK(_spinlock);
extern struct lwip_sock *lwip_tryget_socket(int s);
+/* lwIP 2.2.0 merged netconn::socket into the callback_arg union; the
+ * SAL_NETCONN_SOCKET accessor above hides that difference per lwIP version.
+ * The decrement trick below keeps its original meaning: negative values
+ * count pending RCVPLUS events before accept(). */
static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
{
int s;
@@ -95,7 +110,7 @@ static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len
/* Get socket */
if (conn)
{
- s = conn->socket;
+ s = SAL_NETCONN_SOCKET(conn);
if (s < 0)
{
/* Data comes in right away after an accept, even though
@@ -104,16 +119,17 @@ static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len
* will use the data later. Note that only receive events
* can happen before the new socket is set up. */
SYS_ARCH_PROTECT(lev);
- if (conn->socket < 0)
+ if (SAL_NETCONN_SOCKET(conn) < 0)
{
if (evt == NETCONN_EVT_RCVPLUS)
{
- conn->socket--;
+ SAL_NETCONN_SOCKET(conn)
+ --;
}
SYS_ARCH_UNPROTECT(lev);
return;
}
- s = conn->socket;
+ s = SAL_NETCONN_SOCKET(conn);
SYS_ARCH_UNPROTECT(lev);
}
@@ -153,21 +169,25 @@ static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len
}
#if LWIP_VERSION >= 0x20100ff
- if ((void*)(sock->lastdata.pbuf) || (sock->rcvevent > 0))
+ if ((void *)(sock->lastdata.pbuf) || (sock->rcvevent > 0))
#else
- if ((void*)(sock->lastdata) || (sock->rcvevent > 0))
+ if ((void *)(sock->lastdata) || (sock->rcvevent > 0))
#endif
event |= POLLIN;
if (sock->sendevent)
+ {
event |= POLLOUT;
+ }
if (sock->errevent)
+ {
event |= POLLERR;
+ }
SYS_ARCH_UNPROTECT(lev);
if (event)
{
- rt_wqueue_wakeup(&sock->wait_head, (void*)(size_t)event);
+ rt_wqueue_wakeup(&sock->wait_head, (void *)(size_t)event);
}
}
#endif /* SAL_USING_POSIX */
@@ -252,7 +272,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
struct sal_socket *sal_sock;
sal_sock = sal_get_socket((int)(size_t)file->vnode->data);
- if(!sal_sock)
+ if (!sal_sock)
{
return -1;
}
@@ -267,9 +287,9 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
level = rt_spin_lock_irqsave(&_spinlock);
#if LWIP_VERSION >= 0x20100ff
- if ((void*)(sock->lastdata.pbuf) || sock->rcvevent)
+ if ((void *)(sock->lastdata.pbuf) || sock->rcvevent)
#else
- if ((void*)(sock->lastdata) || sock->rcvevent)
+ if ((void *)(sock->lastdata) || sock->rcvevent)
#endif
{
mask |= POLLIN;
@@ -291,51 +311,48 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
}
#endif
-static const struct sal_socket_ops lwip_socket_ops =
-{
- .socket = inet_socket,
+static const struct sal_socket_ops lwip_socket_ops = {
+ .socket = inet_socket,
.closesocket = lwip_close,
- .bind = lwip_bind,
- .listen = lwip_listen,
- .connect = lwip_connect,
- .accept = inet_accept,
- .sendto = (int (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t))lwip_sendto,
+ .bind = lwip_bind,
+ .listen = lwip_listen,
+ .connect = lwip_connect,
+ .accept = inet_accept,
+ .sendto = (int (*)(int, const void *, size_t, int, const struct sockaddr *, socklen_t))lwip_sendto,
#if LWIP_VERSION >= 0x20102ff
- .sendmsg = (int (*)(int, const struct msghdr *, int))lwip_sendmsg,
- .recvmsg = (int (*)(int, struct msghdr *, int))lwip_recvmsg,
+ .sendmsg = (int (*)(int, const struct msghdr *, int))lwip_sendmsg,
+ .recvmsg = (int (*)(int, struct msghdr *, int))lwip_recvmsg,
#endif
- .recvfrom = (int (*)(int, void *, size_t, int, struct sockaddr *, socklen_t *))lwip_recvfrom,
- .getsockopt = lwip_getsockopt,
+ .recvfrom = (int (*)(int, void *, size_t, int, struct sockaddr *, socklen_t *))lwip_recvfrom,
+ .getsockopt = lwip_getsockopt,
//TODO fix on 1.4.1
- .setsockopt = lwip_setsockopt,
- .shutdown = lwip_shutdown,
+ .setsockopt = lwip_setsockopt,
+ .shutdown = lwip_shutdown,
.getpeername = lwip_getpeername,
.getsockname = inet_getsockname,
.ioctlsocket = inet_ioctlsocket,
- .socketpair = RT_NULL,
+ .socketpair = RT_NULL,
#ifdef SAL_USING_POSIX
- .poll = inet_poll,
+ .poll = inet_poll,
#endif
};
-static const struct sal_netdb_ops lwip_netdb_ops =
-{
- .gethostbyname = lwip_gethostbyname,
+static const struct sal_netdb_ops lwip_netdb_ops = {
+ .gethostbyname = lwip_gethostbyname,
.gethostbyname_r = lwip_gethostbyname_r,
- .getaddrinfo = lwip_getaddrinfo,
- .freeaddrinfo = lwip_freeaddrinfo,
+ .getaddrinfo = lwip_getaddrinfo,
+ .freeaddrinfo = lwip_freeaddrinfo,
};
-static const struct sal_proto_family lwip_inet_family =
-{
- .family = AF_INET,
+static const struct sal_proto_family lwip_inet_family = {
+ .family = AF_INET,
#if LWIP_VERSION > 0x2000000
.sec_family = AF_INET6,
#else
.sec_family = AF_INET,
#endif
- .skt_ops = &lwip_socket_ops,
- .netdb_ops = &lwip_netdb_ops,
+ .skt_ops = &lwip_socket_ops,
+ .netdb_ops = &lwip_netdb_ops,
};
/* Set lwIP network interface device protocol family information */
@@ -343,7 +360,7 @@ int sal_lwip_netdev_set_pf_info(struct netdev *netdev)
{
RT_ASSERT(netdev);
- netdev->sal_user_data = (void *) &lwip_inet_family;
+ netdev->sal_user_data = (void *)&lwip_inet_family;
return 0;
}