Skip to content

Commit

Permalink
chore: update to v2.1.3_230818 modified by ST
Browse files Browse the repository at this point in the history
  • Loading branch information
fpistm committed Nov 8, 2023
1 parent e779210 commit 4de72d4
Show file tree
Hide file tree
Showing 54 changed files with 548 additions and 291 deletions.
11 changes: 11 additions & 0 deletions FEATURES
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lwIP is a small independent implementation of the TCP/IP protocol suite targeted at embedded systems.

The focus of the lwIP TCP/IP implementation is to reduce resource usage while still having a full scale TCP. This makes lwIP suitable for use in embedded systems with tens of kilobytes of free RAM and room for around 40 kilobytes of code ROM.

Main features include:
- Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE, 6LowPAN (via IEEE 802.15.4, BLE or ZEP; since v2.1.0)
- DHCP client, stateless DHCPv6 (since v2.1.0), DNS client (incl. mDNS hostname resolver), AutoIP/APIPA (Zeroconf), SNMP agent (v1, v2c, v3 (since v2.1.0), private MIB support & MIB compiler)
- APIs: specialized APIs for enhanced performance & zero copy, optional Berkeley-alike socket API
- Extended features: IP forwarding over multiple network interfaces
- Extended TCP features: congestion control, RTT estimation and fast recovery/fast retransmit, sending SACKs (since v2.1.0), "altcp": nearly transparent TLS for any tcp pcb (since v2.1.0)
- Addon applications: HTTP server (HTTPS via altcp), HTTP(S) client (since v2.1.0), SNTP client, SMTP client (SMTPS via altcp), ping, NetBIOS nameserver, mDNS responder, MQTT client (TLS support since v2.1.0), TFTP server, iPerf2 counterpart
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

## Version

This library is based on the version 2.1.2 of the LwIP stack modified by ST: https://github.com/STMicroelectronics/stm32_mw_lwip
This library is based on the LwIP stack modified by ST: [stm32_mw_lwip](https://github.com/STMicroelectronics/stm32_mw_lwip) version [v2.1.3_230818](https://github.com/STMicroelectronics/stm32_mw_lwip/releases/tag/v2.1.3_230818).
31 changes: 31 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Report potential product security vulnerabilities

ST places a high priority on security, and our Product Security Incident
Response Team (PSIRT) is committed to rapidly addressing potential security
vulnerabilities affecting our products. PSIRT's long history and vast experience
in security allows ST to perform clear analyses and provide appropriate guidance
on mitigations and solutions when applicable.

If you wish to report potential security vulnerabilities regarding our products,
**please do not report them through public GitHub issues.** Instead, we
encourage you to report them to our ST PSIRT following the process described at:
**https://www.st.com/content/st_com/en/security/report-vulnerabilities.html**

### IMPORTANT - READ CAREFULLY:

STMicroelectronics International N.V., on behalf of itself, its affiliates and
subsidiaries, (collectively “ST”) takes all potential security vulnerability
reports or other related communications (“Report(s)”) seriously. In order to
review Your Report (the terms “You” and “Yours” include your employer, and all
affiliates, subsidiaries and related persons or entities) and take actions as
deemed appropriate, ST requires that we have the rights and Your permission to
do so.

As such, by submitting Your Report to ST, You agree that You have the right to
do so, and You grant to ST the rights to use the Report for purposes related to
security vulnerability analysis, testing, correction, patching, reporting and
any other related purpose or function.

By submitting Your Report, You agree that ST’s
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
applies to all related communications.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino LwIP
version=2.1.2
version=2.1.3
author=Adam Dunkels <[email protected]>
maintainer=See url
sentence=A Lightweight TCP/IP stack
Expand Down
12 changes: 6 additions & 6 deletions src/api/api_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ netconn_prepare_delete(struct netconn *conn)

API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
#if LWIP_TCP
#if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER
/* get the time we started, which is later compared to
sys_now() + conn->send_timeout */
API_MSG_VAR_REF(msg).msg.sd.time_started = sys_now();
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
#if LWIP_TCP
API_MSG_VAR_REF(msg).msg.sd.polls_left =
((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1;
#endif /* LWIP_TCP */
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
#endif /* LWIP_TCP */
err = netconn_apimsg(lwip_netconn_do_delconn, &API_MSG_VAR_REF(msg));
API_MSG_VAR_FREE(msg);

Expand Down Expand Up @@ -500,7 +500,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)

NETCONN_MBOX_WAITING_INC(conn);
if (netconn_is_nonblocking(conn)) {
if (sys_arch_mbox_tryfetch(&conn->acceptmbox, &accept_ptr) == SYS_ARCH_TIMEOUT) {
if (sys_arch_mbox_tryfetch(&conn->acceptmbox, &accept_ptr) == SYS_MBOX_EMPTY) {
API_MSG_VAR_FREE_ACCEPT(msg);
NETCONN_MBOX_WAITING_DEC(conn);
return ERR_WOULDBLOCK;
Expand Down Expand Up @@ -597,7 +597,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
NETCONN_MBOX_WAITING_INC(conn);
if (netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK) ||
(conn->flags & NETCONN_FLAG_MBOXCLOSED) || (conn->pending_err != ERR_OK)) {
if (sys_arch_mbox_tryfetch(&conn->recvmbox, &buf) == SYS_ARCH_TIMEOUT) {
if (sys_arch_mbox_tryfetch(&conn->recvmbox, &buf) == SYS_MBOX_EMPTY) {
err_t err;
NETCONN_MBOX_WAITING_DEC(conn);
err = netconn_err(conn);
Expand Down Expand Up @@ -1346,7 +1346,7 @@ void
netconn_thread_init(void)
{
sys_sem_t *sem = LWIP_NETCONN_THREAD_SEM_GET();
if ((sem == NULL) || !sys_sem_valid(sem)) {
if (!sys_sem_valid(sem)) {
/* call alloc only once */
LWIP_NETCONN_THREAD_SEM_ALLOC();
LWIP_ASSERT("LWIP_NETCONN_THREAD_SEM_ALLOC() failed", sys_sem_valid(LWIP_NETCONN_THREAD_SEM_GET()));
Expand All @@ -1357,7 +1357,7 @@ void
netconn_thread_cleanup(void)
{
sys_sem_t *sem = LWIP_NETCONN_THREAD_SEM_GET();
if ((sem != NULL) && sys_sem_valid(sem)) {
if (sys_sem_valid(sem)) {
/* call free only once */
LWIP_NETCONN_THREAD_SEM_FREE();
}
Expand Down
3 changes: 3 additions & 0 deletions src/api/api_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
conn->pending_err = ERR_OK;
conn->type = t;
conn->pcb.tcp = NULL;
#if LWIP_NETCONN_FULLDUPLEX
conn->mbox_threads_waiting = 0;
#endif

/* If all sizes are the same, every compiler should optimize this switch to nothing */
switch (NETCONNTYPE_GROUP(t)) {
Expand Down
9 changes: 6 additions & 3 deletions src/api/netdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ lwip_gethostbyname(const char *name)
if (s_hostent.h_addr_list != NULL) {
u8_t idx;
for (idx = 0; s_hostent.h_addr_list[idx]; idx++) {
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa(s_phostent_addr[idx])));
}
}
#endif /* DNS_DEBUG */
Expand Down Expand Up @@ -306,7 +305,11 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
/* service name specified: convert to port number
* @todo?: currently, only ASCII integers (port numbers) are supported (AI_NUMERICSERV)! */
port_nr = atoi(servname);
if ((port_nr <= 0) || (port_nr > 0xffff)) {
if (port_nr == 0 && (servname[0] != '0')) {
/* atoi failed - service was not numeric */
return EAI_SERVICE;
}
if ((port_nr < 0) || (port_nr > 0xffff)) {
return EAI_SERVICE;
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/api/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
err = netconn_peer(newconn, &naddr, &port);
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
netconn_delete(newconn);
free_socket(nsock, 1);
sock_set_errno(sock, err_to_errno(err));
done_socket(sock);
Expand Down Expand Up @@ -2073,7 +2072,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
/* Call lwip_selscan again: there could have been events between
the last scan (without us on the list) and putting us on the list! */
nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset);
if (!nready) {
if (nready < 0) {
set_errno(EBADF);
} else if (!nready) {
/* Still none ready, just wait to be woken */
if (timeout == 0) {
/* Wait forever */
Expand Down Expand Up @@ -2102,15 +2103,15 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
(exceptset && FD_ISSET(i, exceptset))) {
struct lwip_sock *sock;
SYS_ARCH_PROTECT(lev);
sock = tryget_socket_unconn_locked(i);
sock = tryget_socket_unconn_nouse(i);
LWIP_ASSERT("socket gone at the end of select", sock != NULL);
if (sock != NULL) {
/* for now, handle select_waiting==0... */
LWIP_ASSERT("sock->select_waiting > 0", sock->select_waiting > 0);
if (sock->select_waiting > 0) {
sock->select_waiting--;
}
SYS_ARCH_UNPROTECT(lev);
done_socket(sock);
} else {
SYS_ARCH_UNPROTECT(lev);
/* Not a valid socket */
Expand Down Expand Up @@ -2147,6 +2148,11 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
/* See what's set now after waiting */
nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready));
if (nready < 0) {
set_errno(EBADF);
lwip_select_dec_sockets_used(maxfdp1, &used_sockets);
return -1;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ tcpip_thread_poll_one(void)
int ret = 0;
struct tcpip_msg *msg;

if (sys_arch_mbox_tryfetch(&tcpip_mbox, (void **)&msg) != SYS_ARCH_TIMEOUT) {
if (sys_arch_mbox_tryfetch(&tcpip_mbox, (void **)&msg) != SYS_MBOX_EMPTY) {
LOCK_TCPIP_CORE();
if (msg != NULL) {
tcpip_thread_handle_msg(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef int sys_prot_t;

#define LWIP_PROVIDE_ERRNO

#if defined (__GNUC__) & !defined (__CC_ARM)
#if defined (__GNUC__) && !(defined (__CC_ARM) || defined (__ARMCC_VERSION))

#define LWIP_TIMEVAL_PRIVATE 0
#include <sys/time.h>
Expand Down
14 changes: 1 addition & 13 deletions src/arch/sys_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,19 @@
#error "NO_SYS need to be set to 0 to use threaded API"
#endif

#include "cmsis_os.h"
#include "cmsis_os2.h"

#ifdef __cplusplus
extern "C" {
#endif

#if (osCMSIS < 0x20000U)

#define SYS_MBOX_NULL (osMessageQId)0
#define SYS_SEM_NULL (osSemaphoreId)0

typedef osSemaphoreId sys_sem_t;
typedef osSemaphoreId sys_mutex_t;
typedef osMessageQId sys_mbox_t;
typedef osThreadId sys_thread_t;
#else

#define SYS_MBOX_NULL (osMessageQueueId_t)0
#define SYS_SEM_NULL (osSemaphoreId_t)0

typedef osSemaphoreId_t sys_sem_t;
typedef osSemaphoreId_t sys_mutex_t;
typedef osMessageQueueId_t sys_mbox_t;
typedef osThreadId_t sys_thread_t;
#endif

#ifdef __cplusplus
}
Expand Down
36 changes: 36 additions & 0 deletions src/core/altcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,24 @@ altcp_get_port(struct altcp_pcb *conn, int local)
return 0;
}

#if LWIP_TCP_KEEPALIVE
void
altcp_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->fns && conn->fns->keepalive_disable) {
conn->fns->keepalive_disable(conn);
}
}

void
altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count)
{
if (conn && conn->fns && conn->fns->keepalive_enable) {
conn->fns->keepalive_enable(conn, idle, intvl, count);
}
}
#endif

#ifdef LWIP_DEBUG
enum tcp_state
altcp_dbg_get_tcp_state(struct altcp_pcb *conn)
Expand Down Expand Up @@ -666,6 +684,24 @@ altcp_default_get_port(struct altcp_pcb *conn, int local)
return 0;
}

#if LWIP_TCP_KEEPALIVE
void
altcp_default_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->inner_conn) {
altcp_keepalive_disable(conn->inner_conn);
}
}

void
altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count)
{
if (conn && conn->inner_conn) {
altcp_keepalive_enable(conn->inner_conn, idle, intvl, count);
}
}
#endif

#ifdef LWIP_DEBUG
enum tcp_state
altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn)
Expand Down
52 changes: 43 additions & 9 deletions src/core/altcp_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "lwip/altcp_tcp.h"
#include "lwip/priv/altcp_priv.h"
#include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/mem.h"

#include <string.h>
Expand Down Expand Up @@ -160,21 +161,25 @@ static void
altcp_tcp_remove_callbacks(struct tcp_pcb *tpcb)
{
tcp_arg(tpcb, NULL);
tcp_recv(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_err(tpcb, NULL);
tcp_poll(tpcb, NULL, tpcb->pollinterval);
if (tpcb->state != LISTEN) {
tcp_recv(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_err(tpcb, NULL);
tcp_poll(tpcb, NULL, tpcb->pollinterval);
}
}

static void
altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
{
tcp_arg(tpcb, conn);
tcp_recv(tpcb, altcp_tcp_recv);
tcp_sent(tpcb, altcp_tcp_sent);
tcp_err(tpcb, altcp_tcp_err);
/* tcp_poll is set when interval is set by application */
/* listen is set totally different :-) */
/* this might be called for LISTN when close fails... */
if (tpcb->state != LISTEN) {
tcp_recv(tpcb, altcp_tcp_recv);
tcp_sent(tpcb, altcp_tcp_sent);
tcp_err(tpcb, altcp_tcp_err);
/* tcp_poll is set when interval is set by application */
}
}

static void
Expand Down Expand Up @@ -446,6 +451,31 @@ altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio)
}
}

#if LWIP_TCP_KEEPALIVE
static void
altcp_tcp_keepalive_disable(struct altcp_pcb *conn)
{
if (conn && conn->state) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
ALTCP_TCP_ASSERT_CONN(conn);
ip_reset_option(pcb, SOF_KEEPALIVE);
}
}

static void
altcp_tcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t cnt)
{
if (conn && conn->state) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
ALTCP_TCP_ASSERT_CONN(conn);
ip_set_option(pcb, SOF_KEEPALIVE);
pcb->keep_idle = idle ? idle : TCP_KEEPIDLE_DEFAULT;
pcb->keep_intvl = intvl ? intvl : TCP_KEEPINTVL_DEFAULT;
pcb->keep_cnt = cnt ? cnt : TCP_KEEPCNT_DEFAULT;
}
}
#endif

static void
altcp_tcp_dealloc(struct altcp_pcb *conn)
{
Expand Down Expand Up @@ -535,6 +565,10 @@ const struct altcp_functions altcp_tcp_functions = {
altcp_tcp_get_tcp_addrinfo,
altcp_tcp_get_ip,
altcp_tcp_get_port
#if LWIP_TCP_KEEPALIVE
, altcp_tcp_keepalive_disable
, altcp_tcp_keepalive_enable
#endif
#ifdef LWIP_DEBUG
, altcp_tcp_dbg_get_tcp_state
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ PACK_STRUCT_END
#error "NETCONN_MORE != TCP_WRITE_FLAG_MORE"
#endif
#endif /* LWIP_NETCONN && LWIP_TCP */
#if LWIP_SOCKET
#endif /* LWIP_SOCKET */
#if LWIP_NETCONN_FULLDUPLEX && !LWIP_NETCONN_SEM_PER_THREAD
#error "For LWIP_NETCONN_FULLDUPLEX to work, LWIP_NETCONN_SEM_PER_THREAD is required"
#endif


/* Compile-time checks for deprecated options.
Expand Down
Loading

0 comments on commit 4de72d4

Please sign in to comment.