1195972f6Sopenharmony_ciFrom 388525230f809bfa61fe31921b54ebfb6aae57ec Mon Sep 17 00:00:00 2001 2195972f6Sopenharmony_ciFrom: jiangheng <jiangheng12@huawei.com> 3195972f6Sopenharmony_ciDate: Fri, 31 Dec 2021 17:32:49 +0800 4195972f6Sopenharmony_ciSubject: [PATCH] adapt lstack 5195972f6Sopenharmony_ci 6195972f6Sopenharmony_ci--- 7195972f6Sopenharmony_ci src/Makefile | 5 +- 8195972f6Sopenharmony_ci src/api/api_lib.c | 2 + 9195972f6Sopenharmony_ci src/api/api_msg.c | 46 +++ 10195972f6Sopenharmony_ci src/api/dir.mk | 2 +- 11195972f6Sopenharmony_ci src/api/perf.c | 182 ++++++++++++ 12195972f6Sopenharmony_ci src/api/posix_api.c | 156 ++++++++++ 13195972f6Sopenharmony_ci src/api/sockets.c | 558 ++++++++++++++++++++++++++++++++++- 14195972f6Sopenharmony_ci src/api/sys_arch.c | 379 ++++++++++++++++++++++++ 15195972f6Sopenharmony_ci src/api/tcpip.c | 34 ++- 16195972f6Sopenharmony_ci src/core/dir.mk | 8 +- 17195972f6Sopenharmony_ci src/core/init.c | 4 +- 18195972f6Sopenharmony_ci src/core/ip.c | 2 +- 19195972f6Sopenharmony_ci src/core/ipv4/ip4.c | 14 + 20195972f6Sopenharmony_ci src/core/ipv6/ip6.c | 10 + 21195972f6Sopenharmony_ci src/core/mem.c | 6 +- 22195972f6Sopenharmony_ci src/core/memp.c | 4 + 23195972f6Sopenharmony_ci src/core/netif.c | 8 +- 24195972f6Sopenharmony_ci src/core/pbuf.c | 4 + 25195972f6Sopenharmony_ci src/core/stats.c | 13 +- 26195972f6Sopenharmony_ci src/core/tcp.c | 196 +++++++++++- 27195972f6Sopenharmony_ci src/core/tcp_in.c | 101 ++++++- 28195972f6Sopenharmony_ci src/core/tcp_out.c | 25 +- 29195972f6Sopenharmony_ci src/core/timeouts.c | 18 +- 30195972f6Sopenharmony_ci src/core/udp.c | 15 + 31195972f6Sopenharmony_ci src/include/arch/cc.h | 80 ++++- 32195972f6Sopenharmony_ci src/include/arch/perf.h | 155 ++++++++++ 33195972f6Sopenharmony_ci src/include/arch/sys_arch.h | 92 +++++- 34195972f6Sopenharmony_ci src/include/eventpoll.h | 72 +++++ 35195972f6Sopenharmony_ci src/include/hlist.h | 233 +++++++++++++++ 36195972f6Sopenharmony_ci src/include/list.h | 110 +++++++ 37195972f6Sopenharmony_ci src/include/lwip/api.h | 35 +++ 38195972f6Sopenharmony_ci src/include/lwip/debug.h | 1 + 39195972f6Sopenharmony_ci src/include/lwip/def.h | 15 + 40195972f6Sopenharmony_ci src/include/lwip/ip.h | 8 +- 41195972f6Sopenharmony_ci src/include/lwip/memp.h | 17 ++ 42195972f6Sopenharmony_ci src/include/lwip/netif.h | 4 +- 43195972f6Sopenharmony_ci src/include/lwip/opt.h | 62 +++- 44195972f6Sopenharmony_ci src/include/lwip/priv/memp_std.h | 7 + 45195972f6Sopenharmony_ci src/include/lwip/priv/sockets_priv.h | 49 +-- 46195972f6Sopenharmony_ci src/include/lwip/priv/tcp_priv.h | 162 +++++++++- 47195972f6Sopenharmony_ci src/include/lwip/prot/ip4.h | 15 + 48195972f6Sopenharmony_ci src/include/lwip/sockets.h | 67 ++++- 49195972f6Sopenharmony_ci src/include/lwip/stats.h | 4 +- 50195972f6Sopenharmony_ci src/include/lwip/tcp.h | 94 +++++- 51195972f6Sopenharmony_ci src/include/lwip/tcpip.h | 2 +- 52195972f6Sopenharmony_ci src/include/lwip/timeouts.h | 4 + 53195972f6Sopenharmony_ci src/include/lwiplog.h | 81 +++++ 54195972f6Sopenharmony_ci src/include/lwipopts.h | 253 ++++++++++++---- 55195972f6Sopenharmony_ci src/include/lwipsock.h | 155 ++++++++++ 56195972f6Sopenharmony_ci src/include/memp_def.h | 66 +++++ 57195972f6Sopenharmony_ci src/include/posix_api.h | 88 ++++++ 58195972f6Sopenharmony_ci src/include/reg_sock.h | 62 ++++ 59195972f6Sopenharmony_ci src/netif/dir.mk | 2 +- 60195972f6Sopenharmony_ci 53 files changed, 3581 insertions(+), 206 deletions(-) 61195972f6Sopenharmony_ci create mode 100644 src/api/perf.c 62195972f6Sopenharmony_ci create mode 100644 src/api/posix_api.c 63195972f6Sopenharmony_ci create mode 100644 src/api/sys_arch.c 64195972f6Sopenharmony_ci create mode 100644 src/include/arch/perf.h 65195972f6Sopenharmony_ci create mode 100644 src/include/eventpoll.h 66195972f6Sopenharmony_ci create mode 100644 src/include/hlist.h 67195972f6Sopenharmony_ci create mode 100644 src/include/list.h 68195972f6Sopenharmony_ci create mode 100644 src/include/lwiplog.h 69195972f6Sopenharmony_ci create mode 100644 src/include/lwipsock.h 70195972f6Sopenharmony_ci create mode 100644 src/include/memp_def.h 71195972f6Sopenharmony_ci create mode 100644 src/include/posix_api.h 72195972f6Sopenharmony_ci create mode 100644 src/include/reg_sock.h 73195972f6Sopenharmony_ci 74195972f6Sopenharmony_cidiff --git a/src/Makefile b/src/Makefile 75195972f6Sopenharmony_ciindex 3ecf8d2..1676a71 100644 76195972f6Sopenharmony_ci--- a/src/Makefile 77195972f6Sopenharmony_ci+++ b/src/Makefile 78195972f6Sopenharmony_ci@@ -2,7 +2,7 @@ LWIP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 79195972f6Sopenharmony_ci ROOT_DIR := $(dir $(abspath $(LWIP_DIR))) 80195972f6Sopenharmony_ci 81195972f6Sopenharmony_ci LWIP_INC = $(LWIP_DIR)/include 82195972f6Sopenharmony_ci-#DPDK_INCLUDE_FILE ?= /usr/include/dpdk 83195972f6Sopenharmony_ci+DPDK_INCLUDE_FILE ?= /usr/include/dpdk 84195972f6Sopenharmony_ci 85195972f6Sopenharmony_ci SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC 86195972f6Sopenharmony_ci 87195972f6Sopenharmony_ci@@ -10,7 +10,8 @@ CC = gcc 88195972f6Sopenharmony_ci AR = ar 89195972f6Sopenharmony_ci OPTIMIZATION = -O3 90195972f6Sopenharmony_ci INC = -I$(LWIP_DIR) \ 91195972f6Sopenharmony_ci- -I$(LWIP_INC) 92195972f6Sopenharmony_ci+ -I$(LWIP_INC) \ 93195972f6Sopenharmony_ci+ -I$(DPDK_INCLUDE_FILE) 94195972f6Sopenharmony_ci 95195972f6Sopenharmony_ci CFLAGS = -g $(OPTIMIZATION) $(INC) $(SEC_FLAGS) 96195972f6Sopenharmony_ci ARFLAGS = crDP 97195972f6Sopenharmony_cidiff --git a/src/api/api_lib.c b/src/api/api_lib.c 98195972f6Sopenharmony_ciindex ffa14d6..ba9f3c5 100644 99195972f6Sopenharmony_ci--- a/src/api/api_lib.c 100195972f6Sopenharmony_ci+++ b/src/api/api_lib.c 101195972f6Sopenharmony_ci@@ -1061,7 +1061,9 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1 102195972f6Sopenharmony_ci /* For locking the core: this _can_ be delayed on low memory/low send buffer, 103195972f6Sopenharmony_ci but if it is, this is done inside api_msg.c:do_write(), so we can use the 104195972f6Sopenharmony_ci non-blocking version here. */ 105195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_DATA_SEND); 106195972f6Sopenharmony_ci err = netconn_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); 107195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("lwip_netconn_do_write", PERF_LAYER_TCP); 108195972f6Sopenharmony_ci if (err == ERR_OK) { 109195972f6Sopenharmony_ci if (bytes_written != NULL) { 110195972f6Sopenharmony_ci *bytes_written = API_MSG_VAR_REF(msg).msg.w.offset; 111195972f6Sopenharmony_cidiff --git a/src/api/api_msg.c b/src/api/api_msg.c 112195972f6Sopenharmony_ciindex 3f08e03..d5a738f 100644 113195972f6Sopenharmony_ci--- a/src/api/api_msg.c 114195972f6Sopenharmony_ci+++ b/src/api/api_msg.c 115195972f6Sopenharmony_ci@@ -54,6 +54,11 @@ 116195972f6Sopenharmony_ci #include "lwip/mld6.h" 117195972f6Sopenharmony_ci #include "lwip/priv/tcpip_priv.h" 118195972f6Sopenharmony_ci 119195972f6Sopenharmony_ci+#if USE_LIBOS 120195972f6Sopenharmony_ci+#include "lwip/sockets.h" 121195972f6Sopenharmony_ci+#include "lwipsock.h" 122195972f6Sopenharmony_ci+#endif 123195972f6Sopenharmony_ci+ 124195972f6Sopenharmony_ci #include <string.h> 125195972f6Sopenharmony_ci 126195972f6Sopenharmony_ci /* netconns are polled once per second (e.g. continue write on memory error) */ 127195972f6Sopenharmony_ci@@ -452,6 +457,14 @@ err_tcp(void *arg, err_t err) 128195972f6Sopenharmony_ci old_state = conn->state; 129195972f6Sopenharmony_ci conn->state = NETCONN_NONE; 130195972f6Sopenharmony_ci 131195972f6Sopenharmony_ci+#if USE_LIBOS 132195972f6Sopenharmony_ci+ if (CONN_TYPE_IS_HOST(conn)) { 133195972f6Sopenharmony_ci+ LWIP_DEBUGF(API_MSG_DEBUG, 134195972f6Sopenharmony_ci+ ("linux localhost connection already success, ignore lwip err_tcp fd=%d\n", conn->socket)); 135195972f6Sopenharmony_ci+ return; 136195972f6Sopenharmony_ci+ } 137195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 138195972f6Sopenharmony_ci+ 139195972f6Sopenharmony_ci SYS_ARCH_UNPROTECT(lev); 140195972f6Sopenharmony_ci 141195972f6Sopenharmony_ci /* Notify the user layer about a connection error. Used to signal select. */ 142195972f6Sopenharmony_ci@@ -595,6 +608,10 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) 143195972f6Sopenharmony_ci API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0); 144195972f6Sopenharmony_ci } 145195972f6Sopenharmony_ci 146195972f6Sopenharmony_ci+#if USE_LIBOS 147195972f6Sopenharmony_ci+ LWIP_DEBUGF(API_MSG_DEBUG, ("libos incoming connection established\n")); 148195972f6Sopenharmony_ci+ SET_CONN_TYPE_LIBOS(newconn); 149195972f6Sopenharmony_ci+#endif 150195972f6Sopenharmony_ci return ERR_OK; 151195972f6Sopenharmony_ci } 152195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 153195972f6Sopenharmony_ci@@ -1315,6 +1332,31 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err) 154195972f6Sopenharmony_ci return ERR_VAL; 155195972f6Sopenharmony_ci } 156195972f6Sopenharmony_ci 157195972f6Sopenharmony_ci+#if USE_LIBOS 158195972f6Sopenharmony_ci+ if (CONN_TYPE_IS_HOST(conn)) { 159195972f6Sopenharmony_ci+ LWIP_DEBUGF(API_MSG_DEBUG, 160195972f6Sopenharmony_ci+ ("libos outgoing connection abort fd=%d\n", conn->socket)); 161195972f6Sopenharmony_ci+ return ERR_ABRT; 162195972f6Sopenharmony_ci+ } 163195972f6Sopenharmony_ci+ 164195972f6Sopenharmony_ci+ LWIP_DEBUGF(API_MSG_DEBUG, ("libos outgoing connection established\n")); 165195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_INPRG(conn) && CONN_TYPE_HAS_HOST(conn)) { 166195972f6Sopenharmony_ci+ int s = conn->socket; 167195972f6Sopenharmony_ci+ struct lwip_sock *sock = get_socket_without_errno(s); 168195972f6Sopenharmony_ci+ 169195972f6Sopenharmony_ci+ if (!!sock && !!sock->epoll_data) { 170195972f6Sopenharmony_ci+ struct epoll_event ee = {0}; 171195972f6Sopenharmony_ci+ ee.data.fd = s; 172195972f6Sopenharmony_ci+ ee.events |= EPOLLIN | EPOLLOUT | EPOLLERR; 173195972f6Sopenharmony_ci+ posix_api->epoll_ctl_fn(sock->epoll_data->fd, EPOLL_CTL_DEL, s, &ee); 174195972f6Sopenharmony_ci+ posix_api->shutdown_fn(s, SHUT_RDWR); 175195972f6Sopenharmony_ci+ LWIP_DEBUGF(API_MSG_DEBUG, 176195972f6Sopenharmony_ci+ ("linux outgoing connection abort fd=%d\n", s)); 177195972f6Sopenharmony_ci+ } 178195972f6Sopenharmony_ci+ } 179195972f6Sopenharmony_ci+ SET_CONN_TYPE_LIBOS(conn); 180195972f6Sopenharmony_ci+#endif 181195972f6Sopenharmony_ci+ 182195972f6Sopenharmony_ci LWIP_ASSERT("conn->state == NETCONN_CONNECT", conn->state == NETCONN_CONNECT); 183195972f6Sopenharmony_ci LWIP_ASSERT("(conn->current_msg != NULL) || conn->in_non_blocking_connect", 184195972f6Sopenharmony_ci (conn->current_msg != NULL) || IN_NONBLOCKING_CONNECT(conn)); 185195972f6Sopenharmony_ci@@ -1338,6 +1380,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err) 186195972f6Sopenharmony_ci if (was_blocking) { 187195972f6Sopenharmony_ci sys_sem_signal(op_completed_sem); 188195972f6Sopenharmony_ci } 189195972f6Sopenharmony_ci+ 190195972f6Sopenharmony_ci return ERR_OK; 191195972f6Sopenharmony_ci } 192195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 193195972f6Sopenharmony_ci@@ -1372,6 +1415,7 @@ lwip_netconn_do_connect(void *m) 194195972f6Sopenharmony_ci #endif /* LWIP_UDP */ 195195972f6Sopenharmony_ci #if LWIP_TCP 196195972f6Sopenharmony_ci case NETCONN_TCP: 197195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_SEND); 198195972f6Sopenharmony_ci /* Prevent connect while doing any other action. */ 199195972f6Sopenharmony_ci if (msg->conn->state == NETCONN_CONNECT) { 200195972f6Sopenharmony_ci err = ERR_ALREADY; 201195972f6Sopenharmony_ci@@ -1389,6 +1433,7 @@ lwip_netconn_do_connect(void *m) 202195972f6Sopenharmony_ci err = ERR_INPROGRESS; 203195972f6Sopenharmony_ci } else { 204195972f6Sopenharmony_ci msg->conn->current_msg = msg; 205195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); 206195972f6Sopenharmony_ci /* sys_sem_signal() is called from lwip_netconn_do_connected (or err_tcp()), 207195972f6Sopenharmony_ci when the connection is established! */ 208195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 209195972f6Sopenharmony_ci@@ -1402,6 +1447,7 @@ lwip_netconn_do_connect(void *m) 210195972f6Sopenharmony_ci } 211195972f6Sopenharmony_ci } 212195972f6Sopenharmony_ci } 213195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); 214195972f6Sopenharmony_ci break; 215195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 216195972f6Sopenharmony_ci default: 217195972f6Sopenharmony_cidiff --git a/src/api/dir.mk b/src/api/dir.mk 218195972f6Sopenharmony_ciindex 72142ab..afbf863 100644 219195972f6Sopenharmony_ci--- a/src/api/dir.mk 220195972f6Sopenharmony_ci+++ b/src/api/dir.mk 221195972f6Sopenharmony_ci@@ -1,3 +1,3 @@ 222195972f6Sopenharmony_ci-SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c 223195972f6Sopenharmony_ci+SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c perf.c posix_api.c sys_arch.c 224195972f6Sopenharmony_ci 225195972f6Sopenharmony_ci $(eval $(call register_dir, api, $(SRC))) 226195972f6Sopenharmony_cidiff --git a/src/api/perf.c b/src/api/perf.c 227195972f6Sopenharmony_cinew file mode 100644 228195972f6Sopenharmony_ciindex 0000000..1c2a273 229195972f6Sopenharmony_ci--- /dev/null 230195972f6Sopenharmony_ci+++ b/src/api/perf.c 231195972f6Sopenharmony_ci@@ -0,0 +1,182 @@ 232195972f6Sopenharmony_ci+/* 233195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 234195972f6Sopenharmony_ci+ * All rights reserved. 235195972f6Sopenharmony_ci+ * 236195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 237195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 238195972f6Sopenharmony_ci+ * 239195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 240195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 241195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 242195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 243195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 244195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 245195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 246195972f6Sopenharmony_ci+ * 247195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 248195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 249195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 250195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 251195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 252195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 253195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 254195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 255195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 256195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 257195972f6Sopenharmony_ci+ * 258195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 259195972f6Sopenharmony_ci+ * 260195972f6Sopenharmony_ci+ * Author: Huawei Technologies 261195972f6Sopenharmony_ci+ * 262195972f6Sopenharmony_ci+ */ 263195972f6Sopenharmony_ci+ 264195972f6Sopenharmony_ci+#include "arch/perf.h" 265195972f6Sopenharmony_ci+ 266195972f6Sopenharmony_ci+#include <signal.h> 267195972f6Sopenharmony_ci+ 268195972f6Sopenharmony_ci+#include <lwip/stats.h> 269195972f6Sopenharmony_ci+ 270195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 271195972f6Sopenharmony_ci+ 272195972f6Sopenharmony_ci+#define SIG_FUNC_NUM 3 273195972f6Sopenharmony_ci+ 274195972f6Sopenharmony_ci+#define SIG_STATS_DISPLAY 38 275195972f6Sopenharmony_ci+#define SIG_PERF_BEGIN 39 276195972f6Sopenharmony_ci+#define SIG_PERF_END 40 277195972f6Sopenharmony_ci+ 278195972f6Sopenharmony_ci+typedef void (*pSignalFunc) (int); 279195972f6Sopenharmony_ci+static void signal_stats_display(int s); 280195972f6Sopenharmony_ci+static void signal_perf_begin(int s); 281195972f6Sopenharmony_ci+static void signal_perf_end(int s); 282195972f6Sopenharmony_ci+ 283195972f6Sopenharmony_ci+uint32_t g_record_perf; 284195972f6Sopenharmony_ci+__thread uint64_t g_timeTaken[PERF_POINT_END]; 285195972f6Sopenharmony_ci+__thread int g_perfPoint[PERF_LAYER_END]; 286195972f6Sopenharmony_ci+__thread struct timespec tvStart[PERF_LAYER_END]; 287195972f6Sopenharmony_ci+volatile uint64_t g_perfMaxtime[PERF_POINT_END]; 288195972f6Sopenharmony_ci+volatile uint64_t g_astPacketCnt[PERF_POINT_END]; 289195972f6Sopenharmony_ci+volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; 290195972f6Sopenharmony_ci+ 291195972f6Sopenharmony_ci+char *g_ppLayerName[PERF_POINT_END] = { 292195972f6Sopenharmony_ci+ "IP_RECV", 293195972f6Sopenharmony_ci+ "TCP_DATA_RECV", 294195972f6Sopenharmony_ci+ "UDP_PARTIAL", 295195972f6Sopenharmony_ci+ "TCP_SYN_RECV", 296195972f6Sopenharmony_ci+ "TCP_SYN_ACK_SEND", 297195972f6Sopenharmony_ci+ "TCP_ACK_RECV", 298195972f6Sopenharmony_ci+ "TCP_SYN_SEND", 299195972f6Sopenharmony_ci+ "TCP_SYN_ACK_RECV", 300195972f6Sopenharmony_ci+ "TCP_ACK_SEND", 301195972f6Sopenharmony_ci+ "TCP_DATA_SEND", 302195972f6Sopenharmony_ci+ "IP_SEND" 303195972f6Sopenharmony_ci+}; 304195972f6Sopenharmony_ci+ 305195972f6Sopenharmony_ci+static int gsig_arr[SIG_FUNC_NUM] = { 306195972f6Sopenharmony_ci+ SIG_STATS_DISPLAY, 307195972f6Sopenharmony_ci+ SIG_PERF_BEGIN, 308195972f6Sopenharmony_ci+ SIG_PERF_END 309195972f6Sopenharmony_ci+}; 310195972f6Sopenharmony_ci+ 311195972f6Sopenharmony_ci+static pSignalFunc g_Funcs[SIG_FUNC_NUM] = { 312195972f6Sopenharmony_ci+ signal_stats_display, 313195972f6Sopenharmony_ci+ signal_perf_begin, 314195972f6Sopenharmony_ci+ signal_perf_end, 315195972f6Sopenharmony_ci+}; 316195972f6Sopenharmony_ci+ 317195972f6Sopenharmony_ci+static void print_perf_data_and_reset() 318195972f6Sopenharmony_ci+{ 319195972f6Sopenharmony_ci+ int i; 320195972f6Sopenharmony_ci+ printf("\n********* PERF DATA START*************\n"); 321195972f6Sopenharmony_ci+ for (i = 0; i < PERF_POINT_END; i++) { 322195972f6Sopenharmony_ci+ printf("%-20s Total: PacketProcTime: %-15"PRIu64", Maxtime: %-15"PRIu64", packetCnt: %-15"PRIu64"\n", 323195972f6Sopenharmony_ci+ g_ppLayerName[i], __sync_fetch_and_or(&g_astPacketProcTime[i], 0), 324195972f6Sopenharmony_ci+ __sync_fetch_and_or(&g_perfMaxtime[i], 0), 325195972f6Sopenharmony_ci+ __sync_fetch_and_or(&g_astPacketCnt[i], 0)); 326195972f6Sopenharmony_ci+ 327195972f6Sopenharmony_ci+ if (__sync_fetch_and_or(&g_astPacketProcTime[i], 0) && __sync_fetch_and_or(&g_astPacketCnt[i], 0)) { 328195972f6Sopenharmony_ci+ printf("%-20s Average: PacketProcTime: %-15lf, MaxTime: %-15"PRIu64"\n", g_ppLayerName[i], 329195972f6Sopenharmony_ci+ (double)__sync_fetch_and_or(&g_astPacketProcTime[i], 0) / (double)__sync_fetch_and_or(&g_astPacketCnt[i], 0), 330195972f6Sopenharmony_ci+ __sync_or_and_fetch(&g_perfMaxtime[i], 0)); 331195972f6Sopenharmony_ci+ } 332195972f6Sopenharmony_ci+ 333195972f6Sopenharmony_ci+ __sync_fetch_and_and (&g_astPacketProcTime[i], 0); 334195972f6Sopenharmony_ci+ __sync_fetch_and_and (&g_astPacketCnt[i], 0); 335195972f6Sopenharmony_ci+ __sync_fetch_and_and (&g_perfMaxtime[i], 0); 336195972f6Sopenharmony_ci+ } 337195972f6Sopenharmony_ci+ printf("\n********* PERF DATA END*************\n"); 338195972f6Sopenharmony_ci+} 339195972f6Sopenharmony_ci+ 340195972f6Sopenharmony_ci+static void signal_stats_display(int s) 341195972f6Sopenharmony_ci+{ 342195972f6Sopenharmony_ci+ struct sigaction s_test; 343195972f6Sopenharmony_ci+ printf("Received signal %d, stats display.\n", s); 344195972f6Sopenharmony_ci+ stats_display(); 345195972f6Sopenharmony_ci+ s_test.sa_handler = (void *) signal_stats_display; 346195972f6Sopenharmony_ci+ if (sigemptyset(&s_test.sa_mask) != 0) { 347195972f6Sopenharmony_ci+ printf("sigemptyset failed.\n"); 348195972f6Sopenharmony_ci+ } 349195972f6Sopenharmony_ci+ s_test.sa_flags = SA_RESETHAND; 350195972f6Sopenharmony_ci+ if (sigaction(s, &s_test, NULL) != 0) { 351195972f6Sopenharmony_ci+ printf("Could not register %d signal handler.\n", s); 352195972f6Sopenharmony_ci+ } 353195972f6Sopenharmony_ci+} 354195972f6Sopenharmony_ci+ 355195972f6Sopenharmony_ci+static void signal_perf_begin(int s) 356195972f6Sopenharmony_ci+{ 357195972f6Sopenharmony_ci+ struct sigaction s_test; 358195972f6Sopenharmony_ci+ printf("Received signal %d, perf_begin.\n", s); 359195972f6Sopenharmony_ci+ g_record_perf = 1; 360195972f6Sopenharmony_ci+ s_test.sa_handler = (void *) signal_perf_begin; 361195972f6Sopenharmony_ci+ if (sigemptyset(&s_test.sa_mask) != 0) { 362195972f6Sopenharmony_ci+ printf("sigemptyset failed.\n"); 363195972f6Sopenharmony_ci+ } 364195972f6Sopenharmony_ci+ s_test.sa_flags = SA_RESETHAND; 365195972f6Sopenharmony_ci+ if (sigaction(s, &s_test, NULL) != 0) { 366195972f6Sopenharmony_ci+ printf("Could not register %d signal handler.\n", s); 367195972f6Sopenharmony_ci+ } 368195972f6Sopenharmony_ci+} 369195972f6Sopenharmony_ci+ 370195972f6Sopenharmony_ci+static void signal_perf_end(int s) 371195972f6Sopenharmony_ci+{ 372195972f6Sopenharmony_ci+ struct sigaction s_test; 373195972f6Sopenharmony_ci+ printf("Received signal %d, perf_end\n", s); 374195972f6Sopenharmony_ci+ g_record_perf = 0; 375195972f6Sopenharmony_ci+ print_perf_data_and_reset(); 376195972f6Sopenharmony_ci+ s_test.sa_handler = (void *) signal_perf_end; 377195972f6Sopenharmony_ci+ if (sigemptyset(&s_test.sa_mask) != 0) { 378195972f6Sopenharmony_ci+ printf("sigemptyset failed.\n"); 379195972f6Sopenharmony_ci+ } 380195972f6Sopenharmony_ci+ s_test.sa_flags = SA_RESETHAND; 381195972f6Sopenharmony_ci+ if (sigaction(s, &s_test, NULL) != 0) { 382195972f6Sopenharmony_ci+ printf("Could not register %d signal handler.\n", s); 383195972f6Sopenharmony_ci+ } 384195972f6Sopenharmony_ci+} 385195972f6Sopenharmony_ci+ 386195972f6Sopenharmony_ci+int check_layer_point(int layer, int point) 387195972f6Sopenharmony_ci+{ 388195972f6Sopenharmony_ci+ if (point == g_perfPoint[layer]) { 389195972f6Sopenharmony_ci+ return 1; 390195972f6Sopenharmony_ci+ } 391195972f6Sopenharmony_ci+ return 0; 392195972f6Sopenharmony_ci+} 393195972f6Sopenharmony_ci+ 394195972f6Sopenharmony_ci+int perf_init(void) 395195972f6Sopenharmony_ci+{ 396195972f6Sopenharmony_ci+ int i; 397195972f6Sopenharmony_ci+ struct sigaction s_test; 398195972f6Sopenharmony_ci+ for (i = 0; i < SIG_FUNC_NUM; i++) { 399195972f6Sopenharmony_ci+ s_test.sa_handler = (void *) g_Funcs[i]; 400195972f6Sopenharmony_ci+ if (sigemptyset(&s_test.sa_mask) != 0) { 401195972f6Sopenharmony_ci+ printf("sigemptyset failed.\n"); 402195972f6Sopenharmony_ci+ return 1; 403195972f6Sopenharmony_ci+ } 404195972f6Sopenharmony_ci+ 405195972f6Sopenharmony_ci+ s_test.sa_flags = SA_RESETHAND; 406195972f6Sopenharmony_ci+ if (sigaction(gsig_arr[i], &s_test, NULL) != 0) { 407195972f6Sopenharmony_ci+ printf("Could not register %d signal handler.\n", gsig_arr[i]); 408195972f6Sopenharmony_ci+ return 1; 409195972f6Sopenharmony_ci+ } 410195972f6Sopenharmony_ci+ } 411195972f6Sopenharmony_ci+ return 0; 412195972f6Sopenharmony_ci+} 413195972f6Sopenharmony_ci+#endif 414195972f6Sopenharmony_cidiff --git a/src/api/posix_api.c b/src/api/posix_api.c 415195972f6Sopenharmony_cinew file mode 100644 416195972f6Sopenharmony_ciindex 0000000..a917cea 417195972f6Sopenharmony_ci--- /dev/null 418195972f6Sopenharmony_ci+++ b/src/api/posix_api.c 419195972f6Sopenharmony_ci@@ -0,0 +1,156 @@ 420195972f6Sopenharmony_ci+/* 421195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 422195972f6Sopenharmony_ci+ * All rights reserved. 423195972f6Sopenharmony_ci+ * 424195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 425195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 426195972f6Sopenharmony_ci+ * 427195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 428195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 429195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 430195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 431195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 432195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 433195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 434195972f6Sopenharmony_ci+ * 435195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 436195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 437195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 438195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 439195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 440195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 441195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 442195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 443195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 444195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 445195972f6Sopenharmony_ci+ * 446195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 447195972f6Sopenharmony_ci+ * 448195972f6Sopenharmony_ci+ * Author: Huawei Technologies 449195972f6Sopenharmony_ci+ * 450195972f6Sopenharmony_ci+ */ 451195972f6Sopenharmony_ci+ 452195972f6Sopenharmony_ci+#define _GNU_SOURCE 453195972f6Sopenharmony_ci+#include <dlfcn.h> 454195972f6Sopenharmony_ci+#include <fcntl.h> 455195972f6Sopenharmony_ci+#include <sys/epoll.h> 456195972f6Sopenharmony_ci+#include <sys/socket.h> 457195972f6Sopenharmony_ci+#include <sys/stat.h> 458195972f6Sopenharmony_ci+#include <unistd.h> 459195972f6Sopenharmony_ci+ 460195972f6Sopenharmony_ci+#include <rte_log.h> 461195972f6Sopenharmony_ci+ 462195972f6Sopenharmony_ci+#include "lwip/err.h" 463195972f6Sopenharmony_ci+#include "lwipsock.h" 464195972f6Sopenharmony_ci+ 465195972f6Sopenharmony_ci+posix_api_t *posix_api; 466195972f6Sopenharmony_ci+posix_api_t posix_api_val; 467195972f6Sopenharmony_ci+ 468195972f6Sopenharmony_ci+static int chld_is_epfd(int fd) 469195972f6Sopenharmony_ci+{ 470195972f6Sopenharmony_ci+ return 0; 471195972f6Sopenharmony_ci+} 472195972f6Sopenharmony_ci+ 473195972f6Sopenharmony_ci+static struct lwip_sock *chld_get_socket(int fd) 474195972f6Sopenharmony_ci+{ 475195972f6Sopenharmony_ci+ return NULL; 476195972f6Sopenharmony_ci+} 477195972f6Sopenharmony_ci+ 478195972f6Sopenharmony_ci+void posix_api_fork(void) 479195972f6Sopenharmony_ci+{ 480195972f6Sopenharmony_ci+ /* lstack helper api */ 481195972f6Sopenharmony_ci+ posix_api->is_chld = 1; 482195972f6Sopenharmony_ci+ posix_api->is_epfd = chld_is_epfd; 483195972f6Sopenharmony_ci+ posix_api->get_socket = chld_get_socket; 484195972f6Sopenharmony_ci+} 485195972f6Sopenharmony_ci+ 486195972f6Sopenharmony_ci+static int chose_dlsym_handle(void *__restrict* khandle) 487195972f6Sopenharmony_ci+{ 488195972f6Sopenharmony_ci+ void *dlhandle; 489195972f6Sopenharmony_ci+ int (*gazelle_epoll_create)(int size); 490195972f6Sopenharmony_ci+ dlhandle = dlopen ("liblstack.so", RTLD_LAZY); 491195972f6Sopenharmony_ci+ if (dlhandle == NULL) { 492195972f6Sopenharmony_ci+ return ERR_IF; 493195972f6Sopenharmony_ci+ } 494195972f6Sopenharmony_ci+ 495195972f6Sopenharmony_ci+ gazelle_epoll_create = dlsym(dlhandle, "epoll_create"); 496195972f6Sopenharmony_ci+ if (gazelle_epoll_create == NULL) { 497195972f6Sopenharmony_ci+ return ERR_MEM; 498195972f6Sopenharmony_ci+ } 499195972f6Sopenharmony_ci+ 500195972f6Sopenharmony_ci+ dlclose(dlhandle); 501195972f6Sopenharmony_ci+ 502195972f6Sopenharmony_ci+ *khandle = RTLD_NEXT; 503195972f6Sopenharmony_ci+ if (dlsym(*khandle, "epoll_create") == gazelle_epoll_create) { 504195972f6Sopenharmony_ci+ RTE_LOG(ERR, EAL, "posix api use RTLD_DEFAULT\n"); 505195972f6Sopenharmony_ci+ *khandle = RTLD_DEFAULT; 506195972f6Sopenharmony_ci+ } else { 507195972f6Sopenharmony_ci+ RTE_LOG(ERR, EAL, "posix api use RTLD_NEXT\n"); 508195972f6Sopenharmony_ci+ } 509195972f6Sopenharmony_ci+ 510195972f6Sopenharmony_ci+ return ERR_OK; 511195972f6Sopenharmony_ci+} 512195972f6Sopenharmony_ci+ 513195972f6Sopenharmony_ci+int posix_api_init(void) 514195972f6Sopenharmony_ci+{ 515195972f6Sopenharmony_ci+/* the symbol we use here won't be NULL, so we don't need dlerror() 516195972f6Sopenharmony_ci+ to test error */ 517195972f6Sopenharmony_ci+#define CHECK_DLSYM_RET_RETURN(ret) do { \ 518195972f6Sopenharmony_ci+ if ((ret) == NULL) \ 519195972f6Sopenharmony_ci+ goto err_out; \ 520195972f6Sopenharmony_ci+ } while (0) 521195972f6Sopenharmony_ci+ 522195972f6Sopenharmony_ci+ posix_api = &posix_api_val; 523195972f6Sopenharmony_ci+ 524195972f6Sopenharmony_ci+ void *__restrict handle; 525195972f6Sopenharmony_ci+ int ret = chose_dlsym_handle(&handle); 526195972f6Sopenharmony_ci+ if (ret != ERR_OK) { 527195972f6Sopenharmony_ci+ return ret; 528195972f6Sopenharmony_ci+ } 529195972f6Sopenharmony_ci+ 530195972f6Sopenharmony_ci+ /* glibc standard api */ 531195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->socket_fn = dlsym(handle, "socket")); 532195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->accept_fn = dlsym(handle, "accept")); 533195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->accept4_fn = dlsym(handle, "accept4")); 534195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->bind_fn = dlsym(handle, "bind")); 535195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->listen_fn = dlsym(handle, "listen")); 536195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->connect_fn = dlsym(handle, "connect")); 537195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->setsockopt_fn = dlsym(handle, "setsockopt")); 538195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->getsockopt_fn = dlsym(handle, "getsockopt")); 539195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->getpeername_fn = dlsym(handle, "getpeername")); 540195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->getsockname_fn = dlsym(handle, "getsockname")); 541195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->shutdown_fn = dlsym(handle, "shutdown")); 542195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->close_fn = dlsym(handle, "close")); 543195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->read_fn = dlsym(handle, "read")); 544195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->write_fn = dlsym(handle, "write")); 545195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->recv_fn = dlsym(handle, "recv")); 546195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->send_fn = dlsym(handle, "send")); 547195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->recv_msg = dlsym(handle, "recvmsg")); 548195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->send_msg = dlsym(handle, "sendmsg")); 549195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->recv_from = dlsym(handle, "recvfrom")); 550195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->send_to = dlsym(handle, "sendto")); 551195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->fcntl_fn = dlsym(handle, "fcntl")); 552195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->fcntl64_fn = dlsym(handle, "fcntl64")); 553195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->pipe_fn = dlsym(handle, "pipe")); 554195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_create_fn = dlsym(handle, "epoll_create")); 555195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_ctl_fn = dlsym(handle, "epoll_ctl")); 556195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->epoll_wait_fn = dlsym(handle, "epoll_wait")); 557195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->fork_fn = dlsym(handle, "fork")); 558195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->eventfd_fn = dlsym(handle, "eventfd")); 559195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->sigaction_fn = dlsym(handle, "sigaction")); 560195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); 561195972f6Sopenharmony_ci+ CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); 562195972f6Sopenharmony_ci+ 563195972f6Sopenharmony_ci+ /* lstack helper api */ 564195972f6Sopenharmony_ci+ posix_api->get_socket = get_socket; 565195972f6Sopenharmony_ci+ posix_api->is_epfd = lwip_is_epfd; 566195972f6Sopenharmony_ci+ posix_api->epoll_close_fn = lwip_epoll_close; 567195972f6Sopenharmony_ci+ 568195972f6Sopenharmony_ci+ /* support fork */ 569195972f6Sopenharmony_ci+ posix_api->is_chld = 0; 570195972f6Sopenharmony_ci+ return ERR_OK; 571195972f6Sopenharmony_ci+ 572195972f6Sopenharmony_ci+err_out: 573195972f6Sopenharmony_ci+ return ERR_MEM; 574195972f6Sopenharmony_ci+#undef CHECK_DLSYM_RET_RETURN 575195972f6Sopenharmony_ci+} 576195972f6Sopenharmony_cidiff --git a/src/api/sockets.c b/src/api/sockets.c 577195972f6Sopenharmony_ciindex 7852635..3262c1b 100644 578195972f6Sopenharmony_ci--- a/src/api/sockets.c 579195972f6Sopenharmony_ci+++ b/src/api/sockets.c 580195972f6Sopenharmony_ci@@ -62,6 +62,11 @@ 581195972f6Sopenharmony_ci #include <stdarg.h> 582195972f6Sopenharmony_ci #endif 583195972f6Sopenharmony_ci 584195972f6Sopenharmony_ci+#if USE_LIBOS 585195972f6Sopenharmony_ci+#include <stdarg.h> 586195972f6Sopenharmony_ci+#include "lwipsock.h" 587195972f6Sopenharmony_ci+#endif 588195972f6Sopenharmony_ci+ 589195972f6Sopenharmony_ci #include <string.h> 590195972f6Sopenharmony_ci 591195972f6Sopenharmony_ci #ifdef LWIP_HOOK_FILENAME 592195972f6Sopenharmony_ci@@ -85,13 +90,29 @@ 593195972f6Sopenharmony_ci #define API_SELECT_CB_VAR_ALLOC(name, retblock) API_VAR_ALLOC_EXT(struct lwip_select_cb, MEMP_SELECT_CB, name, retblock) 594195972f6Sopenharmony_ci #define API_SELECT_CB_VAR_FREE(name) API_VAR_FREE(MEMP_SELECT_CB, name) 595195972f6Sopenharmony_ci 596195972f6Sopenharmony_ci+#if USE_LIBOS 597195972f6Sopenharmony_ci+enum KERNEL_LWIP_PATH { 598195972f6Sopenharmony_ci+ PATH_KERNEL = 0, 599195972f6Sopenharmony_ci+ PATH_LWIP, 600195972f6Sopenharmony_ci+ PATH_ERR, 601195972f6Sopenharmony_ci+}; 602195972f6Sopenharmony_ci+#endif 603195972f6Sopenharmony_ci+ 604195972f6Sopenharmony_ci #if LWIP_IPV4 605195972f6Sopenharmony_ci+#if USE_LIBOS 606195972f6Sopenharmony_ci+#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ 607195972f6Sopenharmony_ci+ (sin)->sin_family = AF_INET; \ 608195972f6Sopenharmony_ci+ (sin)->sin_port = lwip_htons((port)); \ 609195972f6Sopenharmony_ci+ inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ 610195972f6Sopenharmony_ci+ memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) 611195972f6Sopenharmony_ci+#else 612195972f6Sopenharmony_ci #define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ 613195972f6Sopenharmony_ci (sin)->sin_len = sizeof(struct sockaddr_in); \ 614195972f6Sopenharmony_ci (sin)->sin_family = AF_INET; \ 615195972f6Sopenharmony_ci (sin)->sin_port = lwip_htons((port)); \ 616195972f6Sopenharmony_ci inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ 617195972f6Sopenharmony_ci memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) 618195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 619195972f6Sopenharmony_ci #define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \ 620195972f6Sopenharmony_ci inet_addr_to_ip4addr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \ 621195972f6Sopenharmony_ci (port) = lwip_ntohs((sin)->sin_port); }while(0) 622195972f6Sopenharmony_ci@@ -257,7 +278,12 @@ static void lwip_socket_drop_registered_mld6_memberships(int s); 623195972f6Sopenharmony_ci #endif /* LWIP_IPV6_MLD */ 624195972f6Sopenharmony_ci 625195972f6Sopenharmony_ci /** The global array of available sockets */ 626195972f6Sopenharmony_ci+#if USE_LIBOS 627195972f6Sopenharmony_ci+uint32_t sockets_num; 628195972f6Sopenharmony_ci+struct lwip_sock *sockets; 629195972f6Sopenharmony_ci+#else 630195972f6Sopenharmony_ci static struct lwip_sock sockets[NUM_SOCKETS]; 631195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 632195972f6Sopenharmony_ci 633195972f6Sopenharmony_ci #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 634195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 635195972f6Sopenharmony_ci@@ -285,7 +311,7 @@ static struct lwip_select_cb *select_cb_list; 636195972f6Sopenharmony_ci 637195972f6Sopenharmony_ci /* Forward declaration of some functions */ 638195972f6Sopenharmony_ci #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 639195972f6Sopenharmony_ci-static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); 640195972f6Sopenharmony_ci+void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); 641195972f6Sopenharmony_ci #define DEFAULT_SOCKET_EVENTCB event_callback 642195972f6Sopenharmony_ci static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent); 643195972f6Sopenharmony_ci #else 644195972f6Sopenharmony_ci@@ -411,7 +437,13 @@ static struct lwip_sock * 645195972f6Sopenharmony_ci tryget_socket_unconn_nouse(int fd) 646195972f6Sopenharmony_ci { 647195972f6Sopenharmony_ci int s = fd - LWIP_SOCKET_OFFSET; 648195972f6Sopenharmony_ci- if ((s < 0) || (s >= NUM_SOCKETS)) { 649195972f6Sopenharmony_ci+ 650195972f6Sopenharmony_ci+#if USE_LIBOS 651195972f6Sopenharmony_ci+ if ((s < 0) || (s >= sockets_num)) 652195972f6Sopenharmony_ci+#else 653195972f6Sopenharmony_ci+ if ((s < 0) || (s >= NUM_SOCKETS)) 654195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 655195972f6Sopenharmony_ci+ { 656195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("tryget_socket_unconn(%d): invalid\n", fd)); 657195972f6Sopenharmony_ci return NULL; 658195972f6Sopenharmony_ci } 659195972f6Sopenharmony_ci@@ -475,8 +507,13 @@ tryget_socket(int fd) 660195972f6Sopenharmony_ci * @param fd externally used socket index 661195972f6Sopenharmony_ci * @return struct lwip_sock for the socket or NULL if not found 662195972f6Sopenharmony_ci */ 663195972f6Sopenharmony_ci+#if USE_LIBOS 664195972f6Sopenharmony_ci+struct lwip_sock * 665195972f6Sopenharmony_ci+get_socket(int fd) 666195972f6Sopenharmony_ci+#else 667195972f6Sopenharmony_ci static struct lwip_sock * 668195972f6Sopenharmony_ci get_socket(int fd) 669195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 670195972f6Sopenharmony_ci { 671195972f6Sopenharmony_ci struct lwip_sock *sock = tryget_socket(fd); 672195972f6Sopenharmony_ci if (!sock) { 673195972f6Sopenharmony_ci@@ -489,6 +526,24 @@ get_socket(int fd) 674195972f6Sopenharmony_ci return sock; 675195972f6Sopenharmony_ci } 676195972f6Sopenharmony_ci 677195972f6Sopenharmony_ci+#if USE_LIBOS 678195972f6Sopenharmony_ci+/** 679195972f6Sopenharmony_ci+ * Map a externally used socket index to the internal socket representation. 680195972f6Sopenharmony_ci+ * 681195972f6Sopenharmony_ci+ * @param s externally used socket index 682195972f6Sopenharmony_ci+ * @return struct lwip_sock for the socket or NULL if not found without 683195972f6Sopenharmony_ci+ * checking. 684195972f6Sopenharmony_ci+ */ 685195972f6Sopenharmony_ci+struct lwip_sock * 686195972f6Sopenharmony_ci+get_socket_by_fd(int fd) 687195972f6Sopenharmony_ci+{ 688195972f6Sopenharmony_ci+ if ((fd < LWIP_SOCKET_OFFSET) || (fd >= sockets_num + LWIP_SOCKET_OFFSET)) { 689195972f6Sopenharmony_ci+ return NULL; 690195972f6Sopenharmony_ci+ } 691195972f6Sopenharmony_ci+ return &sockets[fd - LWIP_SOCKET_OFFSET]; 692195972f6Sopenharmony_ci+} 693195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 694195972f6Sopenharmony_ci+ 695195972f6Sopenharmony_ci /** 696195972f6Sopenharmony_ci * Allocate a new socket for a given netconn. 697195972f6Sopenharmony_ci * 698195972f6Sopenharmony_ci@@ -504,6 +559,62 @@ alloc_socket(struct netconn *newconn, int accepted) 699195972f6Sopenharmony_ci SYS_ARCH_DECL_PROTECT(lev); 700195972f6Sopenharmony_ci LWIP_UNUSED_ARG(accepted); 701195972f6Sopenharmony_ci 702195972f6Sopenharmony_ci+#if USE_LIBOS 703195972f6Sopenharmony_ci+ int type, protocol = 0, domain = AF_INET; 704195972f6Sopenharmony_ci+ switch (NETCONNTYPE_GROUP(newconn->type)) { 705195972f6Sopenharmony_ci+ case NETCONN_RAW: 706195972f6Sopenharmony_ci+ type = SOCK_RAW; 707195972f6Sopenharmony_ci+ break; 708195972f6Sopenharmony_ci+ case NETCONN_UDPLITE: 709195972f6Sopenharmony_ci+ case NETCONN_UDP: 710195972f6Sopenharmony_ci+ type = SOCK_DGRAM; 711195972f6Sopenharmony_ci+ break; 712195972f6Sopenharmony_ci+ case NETCONN_TCP: 713195972f6Sopenharmony_ci+ type = SOCK_STREAM; 714195972f6Sopenharmony_ci+ break; 715195972f6Sopenharmony_ci+ default: 716195972f6Sopenharmony_ci+ type = -1; 717195972f6Sopenharmony_ci+ break; 718195972f6Sopenharmony_ci+ } 719195972f6Sopenharmony_ci+ 720195972f6Sopenharmony_ci+ SYS_ARCH_PROTECT(lev); 721195972f6Sopenharmony_ci+ i = posix_api->socket_fn(domain, type, protocol); 722195972f6Sopenharmony_ci+ if (i == -1) { 723195972f6Sopenharmony_ci+ goto err; 724195972f6Sopenharmony_ci+ } 725195972f6Sopenharmony_ci+ 726195972f6Sopenharmony_ci+ if ((i < LWIP_SOCKET_OFFSET) || (i >= sockets_num + LWIP_SOCKET_OFFSET)) { 727195972f6Sopenharmony_ci+ goto err; 728195972f6Sopenharmony_ci+ } 729195972f6Sopenharmony_ci+ 730195972f6Sopenharmony_ci+ if (!sockets[i].conn && (sockets[i].select_waiting == 0)) { 731195972f6Sopenharmony_ci+ /*initialize state as NETCONN_HOST | NETCONN_LIBOS, 732195972f6Sopenharmony_ci+ *if connection accepted and alloc_socket called, it can be only NETCONN_LIBOS*/ 733195972f6Sopenharmony_ci+ if (accepted) 734195972f6Sopenharmony_ci+ SET_CONN_TYPE_LIBOS(newconn); 735195972f6Sopenharmony_ci+ else 736195972f6Sopenharmony_ci+ SET_CONN_TYPE_LIBOS_OR_HOST(newconn); 737195972f6Sopenharmony_ci+ sockets[i].conn = newconn; 738195972f6Sopenharmony_ci+ /* The socket is not yet known to anyone, so no need to protect 739195972f6Sopenharmony_ci+ after having marked it as used. */ 740195972f6Sopenharmony_ci+ SYS_ARCH_UNPROTECT(lev); 741195972f6Sopenharmony_ci+ sockets[i].lastdata.pbuf = NULL; 742195972f6Sopenharmony_ci+ sockets[i].rcvevent = 0; 743195972f6Sopenharmony_ci+ /* TCP sendbuf is empty, but the socket is not yet writable until connected 744195972f6Sopenharmony_ci+ * (unless it has been created by accept()). */ 745195972f6Sopenharmony_ci+ sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); 746195972f6Sopenharmony_ci+ sockets[i].errevent = 0; 747195972f6Sopenharmony_ci+ sockets[i].epoll_data = NULL; 748195972f6Sopenharmony_ci+ init_list_node_null(&sockets[i].list); 749195972f6Sopenharmony_ci+ return i + LWIP_SOCKET_OFFSET; 750195972f6Sopenharmony_ci+ } 751195972f6Sopenharmony_ci+ 752195972f6Sopenharmony_ci+err: 753195972f6Sopenharmony_ci+ posix_api->close_fn(i); 754195972f6Sopenharmony_ci+ SYS_ARCH_UNPROTECT(lev); 755195972f6Sopenharmony_ci+ return -1; 756195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 757195972f6Sopenharmony_ci+ 758195972f6Sopenharmony_ci /* allocate a new socket identifier */ 759195972f6Sopenharmony_ci for (i = 0; i < NUM_SOCKETS; ++i) { 760195972f6Sopenharmony_ci /* Protect socket array */ 761195972f6Sopenharmony_ci@@ -535,6 +646,8 @@ alloc_socket(struct netconn *newconn, int accepted) 762195972f6Sopenharmony_ci SYS_ARCH_UNPROTECT(lev); 763195972f6Sopenharmony_ci } 764195972f6Sopenharmony_ci return -1; 765195972f6Sopenharmony_ci+ 766195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 767195972f6Sopenharmony_ci } 768195972f6Sopenharmony_ci 769195972f6Sopenharmony_ci /** Free a socket (under lock) 770195972f6Sopenharmony_ci@@ -629,10 +742,43 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 771195972f6Sopenharmony_ci SYS_ARCH_DECL_PROTECT(lev); 772195972f6Sopenharmony_ci 773195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s)); 774195972f6Sopenharmony_ci+#if USE_LIBOS 775195972f6Sopenharmony_ci+ int sys_errno = 0; 776195972f6Sopenharmony_ci+ 777195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 778195972f6Sopenharmony_ci+ /*AF_UNIX case*/ 779195972f6Sopenharmony_ci+ if (!sock) { 780195972f6Sopenharmony_ci+ if (rearm_accept_fd(s) < 0) { 781195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, 782195972f6Sopenharmony_ci+ ("failed to rearm accept fd=%d errno=%d\n", s, errno)); 783195972f6Sopenharmony_ci+ } 784195972f6Sopenharmony_ci+ return posix_api->accept_fn(s, addr, addrlen); 785195972f6Sopenharmony_ci+ } 786195972f6Sopenharmony_ci+ 787195972f6Sopenharmony_ci+ /*for AF_INET, we may try both linux and lwip*/ 788195972f6Sopenharmony_ci+ if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 789195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 790195972f6Sopenharmony_ci+ set_errno(EINVAL); 791195972f6Sopenharmony_ci+ return -1; 792195972f6Sopenharmony_ci+ } 793195972f6Sopenharmony_ci+ 794195972f6Sopenharmony_ci+ if (rearm_accept_fd(s) < 0) { 795195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, 796195972f6Sopenharmony_ci+ ("failed to rearm accept fd=%d errno=%d\n", s, errno)); 797195972f6Sopenharmony_ci+ } 798195972f6Sopenharmony_ci+ 799195972f6Sopenharmony_ci+ /* raise accept syscall in palce */ 800195972f6Sopenharmony_ci+ newsock = posix_api->accept_fn(s, addr, addrlen); 801195972f6Sopenharmony_ci+ if (newsock >= 0) { 802195972f6Sopenharmony_ci+ return newsock; 803195972f6Sopenharmony_ci+ } 804195972f6Sopenharmony_ci+ sys_errno = errno; 805195972f6Sopenharmony_ci+#else 806195972f6Sopenharmony_ci sock = get_socket(s); 807195972f6Sopenharmony_ci if (!sock) { 808195972f6Sopenharmony_ci return -1; 809195972f6Sopenharmony_ci } 810195972f6Sopenharmony_ci+#endif 811195972f6Sopenharmony_ci 812195972f6Sopenharmony_ci /* wait for a new connection */ 813195972f6Sopenharmony_ci err = netconn_accept(sock->conn, &newconn); 814195972f6Sopenharmony_ci@@ -646,6 +792,9 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 815195972f6Sopenharmony_ci sock_set_errno(sock, err_to_errno(err)); 816195972f6Sopenharmony_ci } 817195972f6Sopenharmony_ci done_socket(sock); 818195972f6Sopenharmony_ci+#if USE_LIBOS 819195972f6Sopenharmony_ci+ set_errno(sys_errno); 820195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 821195972f6Sopenharmony_ci return -1; 822195972f6Sopenharmony_ci } 823195972f6Sopenharmony_ci LWIP_ASSERT("newconn != NULL", newconn != NULL); 824195972f6Sopenharmony_ci@@ -657,7 +806,11 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 825195972f6Sopenharmony_ci done_socket(sock); 826195972f6Sopenharmony_ci return -1; 827195972f6Sopenharmony_ci } 828195972f6Sopenharmony_ci+#if USE_LIBOS 829195972f6Sopenharmony_ci+ LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < sockets_num + LWIP_SOCKET_OFFSET)); 830195972f6Sopenharmony_ci+#else 831195972f6Sopenharmony_ci LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET)); 832195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 833195972f6Sopenharmony_ci nsock = &sockets[newsock - LWIP_SOCKET_OFFSET]; 834195972f6Sopenharmony_ci 835195972f6Sopenharmony_ci /* See event_callback: If data comes in right away after an accept, even 836195972f6Sopenharmony_ci@@ -695,9 +848,11 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 837195972f6Sopenharmony_ci } 838195972f6Sopenharmony_ci 839195972f6Sopenharmony_ci IPADDR_PORT_TO_SOCKADDR(&tempaddr, &naddr, port); 840195972f6Sopenharmony_ci+#if !USE_LIBOS 841195972f6Sopenharmony_ci if (*addrlen > tempaddr.sa.sa_len) { 842195972f6Sopenharmony_ci *addrlen = tempaddr.sa.sa_len; 843195972f6Sopenharmony_ci } 844195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 845195972f6Sopenharmony_ci MEMCPY(addr, &tempaddr, *addrlen); 846195972f6Sopenharmony_ci 847195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock)); 848195972f6Sopenharmony_ci@@ -720,11 +875,24 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen) 849195972f6Sopenharmony_ci ip_addr_t local_addr; 850195972f6Sopenharmony_ci u16_t local_port; 851195972f6Sopenharmony_ci err_t err; 852195972f6Sopenharmony_ci- 853195972f6Sopenharmony_ci+#if USE_LIBOS 854195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 855195972f6Sopenharmony_ci+ /*AF_UNIX case*/ 856195972f6Sopenharmony_ci+ if (!sock) { 857195972f6Sopenharmony_ci+ return posix_api->bind_fn(s, name, namelen); 858195972f6Sopenharmony_ci+ } 859195972f6Sopenharmony_ci+ /*for AF_INET, we may try both linux and lwip*/ 860195972f6Sopenharmony_ci+ if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 861195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 862195972f6Sopenharmony_ci+ set_errno(EINVAL); 863195972f6Sopenharmony_ci+ return -1; 864195972f6Sopenharmony_ci+ } 865195972f6Sopenharmony_ci+#else 866195972f6Sopenharmony_ci sock = get_socket(s); 867195972f6Sopenharmony_ci if (!sock) { 868195972f6Sopenharmony_ci return -1; 869195972f6Sopenharmony_ci } 870195972f6Sopenharmony_ci+#endif 871195972f6Sopenharmony_ci 872195972f6Sopenharmony_ci if (!SOCK_ADDR_TYPE_MATCH(name, sock)) { 873195972f6Sopenharmony_ci /* sockaddr does not match socket type (IPv4/IPv6) */ 874195972f6Sopenharmony_ci@@ -744,6 +912,18 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen) 875195972f6Sopenharmony_ci ip_addr_debug_print_val(SOCKETS_DEBUG, local_addr); 876195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", local_port)); 877195972f6Sopenharmony_ci 878195972f6Sopenharmony_ci+#if USE_LIBOS 879195972f6Sopenharmony_ci+ /* Supports kernel NIC IP address. */ 880195972f6Sopenharmony_ci+ int ret = posix_api->bind_fn(s, name, namelen); 881195972f6Sopenharmony_ci+ if (ret < 0) { 882195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("bind syscall failed\n")); 883195972f6Sopenharmony_ci+ /* bind must succeed on both linux and libos */ 884195972f6Sopenharmony_ci+ if (!is_host_ipv4(local_addr.addr)) { 885195972f6Sopenharmony_ci+ return ret; 886195972f6Sopenharmony_ci+ } 887195972f6Sopenharmony_ci+ } 888195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 889195972f6Sopenharmony_ci+ 890195972f6Sopenharmony_ci #if LWIP_IPV4 && LWIP_IPV6 891195972f6Sopenharmony_ci /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ 892195972f6Sopenharmony_ci if (IP_IS_V6_VAL(local_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&local_addr))) { 893195972f6Sopenharmony_ci@@ -776,10 +956,29 @@ lwip_close(int s) 894195972f6Sopenharmony_ci 895195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s)); 896195972f6Sopenharmony_ci 897195972f6Sopenharmony_ci+#if USE_LIBOS 898195972f6Sopenharmony_ci+ int ret; 899195972f6Sopenharmony_ci+ if (posix_api->is_epfd(s)) { 900195972f6Sopenharmony_ci+ return posix_api->epoll_close_fn(s); 901195972f6Sopenharmony_ci+ } 902195972f6Sopenharmony_ci+ 903195972f6Sopenharmony_ci+ ret = posix_api->close_fn(s); 904195972f6Sopenharmony_ci+ if (ret < 0) 905195972f6Sopenharmony_ci+ return ret; 906195972f6Sopenharmony_ci+ if (posix_api->is_chld == 0) 907195972f6Sopenharmony_ci+ clean_host_fd(s); 908195972f6Sopenharmony_ci+ 909195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 910195972f6Sopenharmony_ci+ /*AF_UNIX case*/ 911195972f6Sopenharmony_ci+ if (!sock) { 912195972f6Sopenharmony_ci+ return ret; 913195972f6Sopenharmony_ci+ } 914195972f6Sopenharmony_ci+#else 915195972f6Sopenharmony_ci sock = get_socket(s); 916195972f6Sopenharmony_ci if (!sock) { 917195972f6Sopenharmony_ci return -1; 918195972f6Sopenharmony_ci } 919195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 920195972f6Sopenharmony_ci 921195972f6Sopenharmony_ci if (sock->conn != NULL) { 922195972f6Sopenharmony_ci is_tcp = NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP; 923195972f6Sopenharmony_ci@@ -803,6 +1002,13 @@ lwip_close(int s) 924195972f6Sopenharmony_ci return -1; 925195972f6Sopenharmony_ci } 926195972f6Sopenharmony_ci 927195972f6Sopenharmony_ci+#if USE_LIBOS 928195972f6Sopenharmony_ci+ sock->epoll = LIBOS_EPOLLNONE; 929195972f6Sopenharmony_ci+ sock->events = 0; 930195972f6Sopenharmony_ci+ sock->epoll_data = NULL; 931195972f6Sopenharmony_ci+ list_del_node_null(&sock->list); 932195972f6Sopenharmony_ci+#endif 933195972f6Sopenharmony_ci+ 934195972f6Sopenharmony_ci free_socket(sock, is_tcp); 935195972f6Sopenharmony_ci set_errno(0); 936195972f6Sopenharmony_ci return 0; 937195972f6Sopenharmony_ci@@ -814,10 +1020,28 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) 938195972f6Sopenharmony_ci struct lwip_sock *sock; 939195972f6Sopenharmony_ci err_t err; 940195972f6Sopenharmony_ci 941195972f6Sopenharmony_ci+#if USE_LIBOS 942195972f6Sopenharmony_ci+ int ret; 943195972f6Sopenharmony_ci+ 944195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 945195972f6Sopenharmony_ci+ if (!sock) { 946195972f6Sopenharmony_ci+ return posix_api->connect_fn(s, name, namelen); 947195972f6Sopenharmony_ci+ } 948195972f6Sopenharmony_ci+ 949195972f6Sopenharmony_ci+ /* raise connect syscall in place */ 950195972f6Sopenharmony_ci+ ADD_CONN_TYPE_INPRG(sock->conn); 951195972f6Sopenharmony_ci+ ret = posix_api->connect_fn(s, name, namelen); 952195972f6Sopenharmony_ci+ if (!ret) { 953195972f6Sopenharmony_ci+ SET_CONN_TYPE_HOST(sock->conn); 954195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("linux connect succeed fd=%d\n", s)); 955195972f6Sopenharmony_ci+ return ret; 956195972f6Sopenharmony_ci+ } 957195972f6Sopenharmony_ci+#else 958195972f6Sopenharmony_ci sock = get_socket(s); 959195972f6Sopenharmony_ci if (!sock) { 960195972f6Sopenharmony_ci return -1; 961195972f6Sopenharmony_ci } 962195972f6Sopenharmony_ci+#endif 963195972f6Sopenharmony_ci 964195972f6Sopenharmony_ci if (!SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock)) { 965195972f6Sopenharmony_ci /* sockaddr does not match socket type (IPv4/IPv6) */ 966195972f6Sopenharmony_ci@@ -862,6 +1086,11 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) 967195972f6Sopenharmony_ci return -1; 968195972f6Sopenharmony_ci } 969195972f6Sopenharmony_ci 970195972f6Sopenharmony_ci+#if USE_LIBOS 971195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("libos connect succeed fd=%d\n",s)); 972195972f6Sopenharmony_ci+ SET_CONN_TYPE_LIBOS(sock->conn); 973195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 974195972f6Sopenharmony_ci+ 975195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s)); 976195972f6Sopenharmony_ci sock_set_errno(sock, 0); 977195972f6Sopenharmony_ci done_socket(sock); 978195972f6Sopenharmony_ci@@ -884,10 +1113,29 @@ lwip_listen(int s, int backlog) 979195972f6Sopenharmony_ci 980195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog)); 981195972f6Sopenharmony_ci 982195972f6Sopenharmony_ci+#if USE_LIBOS 983195972f6Sopenharmony_ci+ int ret; 984195972f6Sopenharmony_ci+ 985195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 986195972f6Sopenharmony_ci+ /*AF_UNIX case*/ 987195972f6Sopenharmony_ci+ if (!sock) { 988195972f6Sopenharmony_ci+ return posix_api->listen_fn(s, backlog); 989195972f6Sopenharmony_ci+ } 990195972f6Sopenharmony_ci+ /*for AF_INET, we may try both linux and lwip*/ 991195972f6Sopenharmony_ci+ if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 992195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 993195972f6Sopenharmony_ci+ set_errno(EADDRINUSE); 994195972f6Sopenharmony_ci+ return -1; 995195972f6Sopenharmony_ci+ } 996195972f6Sopenharmony_ci+ 997195972f6Sopenharmony_ci+ if ((ret = posix_api->listen_fn(s, backlog)) == -1) 998195972f6Sopenharmony_ci+ return ret; 999195972f6Sopenharmony_ci+#else 1000195972f6Sopenharmony_ci sock = get_socket(s); 1001195972f6Sopenharmony_ci if (!sock) { 1002195972f6Sopenharmony_ci return -1; 1003195972f6Sopenharmony_ci } 1004195972f6Sopenharmony_ci+#endif 1005195972f6Sopenharmony_ci 1006195972f6Sopenharmony_ci /* limit the "backlog" parameter to fit in an u8_t */ 1007195972f6Sopenharmony_ci backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff); 1008195972f6Sopenharmony_ci@@ -919,6 +1167,9 @@ static ssize_t 1009195972f6Sopenharmony_ci lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 1010195972f6Sopenharmony_ci { 1011195972f6Sopenharmony_ci u8_t apiflags = NETCONN_NOAUTORCVD; 1012195972f6Sopenharmony_ci+#if USE_LIBOS 1013195972f6Sopenharmony_ci+ apiflags = 0; 1014195972f6Sopenharmony_ci+#endif 1015195972f6Sopenharmony_ci ssize_t recvd = 0; 1016195972f6Sopenharmony_ci ssize_t recv_left = (len <= SSIZE_MAX) ? (ssize_t)len : SSIZE_MAX; 1017195972f6Sopenharmony_ci 1018195972f6Sopenharmony_ci@@ -938,6 +1189,13 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 1019195972f6Sopenharmony_ci /* Check if there is data left from the last recv operation. */ 1020195972f6Sopenharmony_ci if (sock->lastdata.pbuf) { 1021195972f6Sopenharmony_ci p = sock->lastdata.pbuf; 1022195972f6Sopenharmony_ci+#if USE_LIBOS 1023195972f6Sopenharmony_ci+ if ((flags & MSG_PEEK) == 0) { 1024195972f6Sopenharmony_ci+ if ((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) { 1025195972f6Sopenharmony_ci+ del_epoll_event(sock->conn, EPOLLIN); 1026195972f6Sopenharmony_ci+ } 1027195972f6Sopenharmony_ci+ } 1028195972f6Sopenharmony_ci+#endif 1029195972f6Sopenharmony_ci } else { 1030195972f6Sopenharmony_ci /* No data was left from the previous operation, so we try to get 1031195972f6Sopenharmony_ci some from the network. */ 1032195972f6Sopenharmony_ci@@ -1008,10 +1266,22 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 1033195972f6Sopenharmony_ci /* @todo: do we need to support peeking more than one pbuf? */ 1034195972f6Sopenharmony_ci } while ((recv_left > 0) && !(flags & MSG_PEEK)); 1035195972f6Sopenharmony_ci lwip_recv_tcp_done: 1036195972f6Sopenharmony_ci- if ((recvd > 0) && !(flags & MSG_PEEK)) { 1037195972f6Sopenharmony_ci- /* ensure window update after copying all data */ 1038195972f6Sopenharmony_ci- netconn_tcp_recvd(sock->conn, (size_t)recvd); 1039195972f6Sopenharmony_ci+#if USE_LIBOS 1040195972f6Sopenharmony_ci+ if (apiflags & NETCONN_NOAUTORCVD) 1041195972f6Sopenharmony_ci+#endif 1042195972f6Sopenharmony_ci+ { 1043195972f6Sopenharmony_ci+ if ((recvd > 0) && !(flags & MSG_PEEK)) { 1044195972f6Sopenharmony_ci+ /* ensure window update after copying all data */ 1045195972f6Sopenharmony_ci+ netconn_tcp_recvd(sock->conn, (size_t)recvd); 1046195972f6Sopenharmony_ci+ } 1047195972f6Sopenharmony_ci } 1048195972f6Sopenharmony_ci+#if USE_LIBOS 1049195972f6Sopenharmony_ci+ if ((flags & MSG_PEEK) == 0) { 1050195972f6Sopenharmony_ci+ if (((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) && sock->lastdata.pbuf) { 1051195972f6Sopenharmony_ci+ add_epoll_event(sock->conn, EPOLLIN); 1052195972f6Sopenharmony_ci+ } 1053195972f6Sopenharmony_ci+ } 1054195972f6Sopenharmony_ci+#endif 1055195972f6Sopenharmony_ci sock_set_errno(sock, 0); 1056195972f6Sopenharmony_ci return recvd; 1057195972f6Sopenharmony_ci } 1058195972f6Sopenharmony_ci@@ -1040,11 +1310,13 @@ lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port, 1059195972f6Sopenharmony_ci #endif /* LWIP_IPV4 && LWIP_IPV6 */ 1060195972f6Sopenharmony_ci 1061195972f6Sopenharmony_ci IPADDR_PORT_TO_SOCKADDR(&saddr, fromaddr, port); 1062195972f6Sopenharmony_ci+#if !USE_LIBOS 1063195972f6Sopenharmony_ci if (*fromlen < saddr.sa.sa_len) { 1064195972f6Sopenharmony_ci truncated = 1; 1065195972f6Sopenharmony_ci } else if (*fromlen > saddr.sa.sa_len) { 1066195972f6Sopenharmony_ci *fromlen = saddr.sa.sa_len; 1067195972f6Sopenharmony_ci } 1068195972f6Sopenharmony_ci+#endif 1069195972f6Sopenharmony_ci MEMCPY(from, &saddr, *fromlen); 1070195972f6Sopenharmony_ci return truncated; 1071195972f6Sopenharmony_ci } 1072195972f6Sopenharmony_ci@@ -1194,6 +1466,43 @@ lwip_recvfrom_udp_raw(struct lwip_sock *sock, int flags, struct msghdr *msg, u16 1073195972f6Sopenharmony_ci return ERR_OK; 1074195972f6Sopenharmony_ci } 1075195972f6Sopenharmony_ci 1076195972f6Sopenharmony_ci+#if USE_LIBOS 1077195972f6Sopenharmony_ci+static inline enum KERNEL_LWIP_PATH select_path(int s) 1078195972f6Sopenharmony_ci+{ 1079195972f6Sopenharmony_ci+ struct lwip_sock *sock; 1080195972f6Sopenharmony_ci+ 1081195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 1082195972f6Sopenharmony_ci+ /*AF_UNIX case*/ 1083195972f6Sopenharmony_ci+ if (!sock) { 1084195972f6Sopenharmony_ci+ if (rearm_host_fd(s) < 0) { 1085195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to rearm fd=%d errno=%d\n", s, errno)); 1086195972f6Sopenharmony_ci+ } 1087195972f6Sopenharmony_ci+ return PATH_KERNEL; 1088195972f6Sopenharmony_ci+ } 1089195972f6Sopenharmony_ci+ 1090195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_INPRG(sock->conn)) { 1091195972f6Sopenharmony_ci+ set_errno(EWOULDBLOCK); 1092195972f6Sopenharmony_ci+ return PATH_ERR; 1093195972f6Sopenharmony_ci+ } 1094195972f6Sopenharmony_ci+ 1095195972f6Sopenharmony_ci+ /*for AF_INET, we can try erther linux or lwip*/ 1096195972f6Sopenharmony_ci+ if (CONN_TYPE_IS_HOST(sock->conn)) { 1097195972f6Sopenharmony_ci+ if (rearm_host_fd(s) < 0) { 1098195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to rearm read fd=%d errno=%d\n", s, errno)); 1099195972f6Sopenharmony_ci+ } 1100195972f6Sopenharmony_ci+ return PATH_KERNEL; 1101195972f6Sopenharmony_ci+ } 1102195972f6Sopenharmony_ci+ 1103195972f6Sopenharmony_ci+ if (!CONN_TYPE_IS_LIBOS(sock->conn)) { 1104195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type is not libos bit type=%x", netconn_type(sock->conn))); 1105195972f6Sopenharmony_ci+ set_errno(EINVAL); 1106195972f6Sopenharmony_ci+ return PATH_ERR; 1107195972f6Sopenharmony_ci+ } 1108195972f6Sopenharmony_ci+ 1109195972f6Sopenharmony_ci+ return PATH_LWIP; 1110195972f6Sopenharmony_ci+} 1111195972f6Sopenharmony_ci+#endif 1112195972f6Sopenharmony_ci+ 1113195972f6Sopenharmony_ci ssize_t 1114195972f6Sopenharmony_ci lwip_recvfrom(int s, void *mem, size_t len, int flags, 1115195972f6Sopenharmony_ci struct sockaddr *from, socklen_t *fromlen) 1116195972f6Sopenharmony_ci@@ -1201,6 +1510,15 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, 1117195972f6Sopenharmony_ci struct lwip_sock *sock; 1118195972f6Sopenharmony_ci ssize_t ret; 1119195972f6Sopenharmony_ci 1120195972f6Sopenharmony_ci+#if USE_LIBOS 1121195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1122195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1123195972f6Sopenharmony_ci+ return -1; 1124195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1125195972f6Sopenharmony_ci+ return posix_api->recv_from(s, mem, len, flags, from, fromlen); 1126195972f6Sopenharmony_ci+ } 1127195972f6Sopenharmony_ci+#endif 1128195972f6Sopenharmony_ci+ 1129195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %"SZT_F", 0x%x, ..)\n", s, mem, len, flags)); 1130195972f6Sopenharmony_ci sock = get_socket(s); 1131195972f6Sopenharmony_ci if (!sock) { 1132195972f6Sopenharmony_ci@@ -1250,6 +1568,14 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, 1133195972f6Sopenharmony_ci ssize_t 1134195972f6Sopenharmony_ci lwip_read(int s, void *mem, size_t len) 1135195972f6Sopenharmony_ci { 1136195972f6Sopenharmony_ci+#if USE_LIBOS 1137195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1138195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1139195972f6Sopenharmony_ci+ return -1; 1140195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1141195972f6Sopenharmony_ci+ return posix_api->read_fn(s, mem, len); 1142195972f6Sopenharmony_ci+ } 1143195972f6Sopenharmony_ci+#endif 1144195972f6Sopenharmony_ci return lwip_recvfrom(s, mem, len, 0, NULL, NULL); 1145195972f6Sopenharmony_ci } 1146195972f6Sopenharmony_ci 1147195972f6Sopenharmony_ci@@ -1283,6 +1609,15 @@ lwip_recvmsg(int s, struct msghdr *message, int flags) 1148195972f6Sopenharmony_ci int i; 1149195972f6Sopenharmony_ci ssize_t buflen; 1150195972f6Sopenharmony_ci 1151195972f6Sopenharmony_ci+#if USE_LIBOS 1152195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1153195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1154195972f6Sopenharmony_ci+ return -1; 1155195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1156195972f6Sopenharmony_ci+ return posix_api->recv_msg(s, message, flags); 1157195972f6Sopenharmony_ci+ } 1158195972f6Sopenharmony_ci+#endif 1159195972f6Sopenharmony_ci+ 1160195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvmsg(%d, message=%p, flags=0x%x)\n", s, (void *)message, flags)); 1161195972f6Sopenharmony_ci LWIP_ERROR("lwip_recvmsg: invalid message pointer", message != NULL, return ERR_ARG;); 1162195972f6Sopenharmony_ci LWIP_ERROR("lwip_recvmsg: unsupported flags", (flags & ~(MSG_PEEK|MSG_DONTWAIT)) == 0, 1163195972f6Sopenharmony_ci@@ -1427,6 +1762,15 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags) 1164195972f6Sopenharmony_ci #endif 1165195972f6Sopenharmony_ci err_t err = ERR_OK; 1166195972f6Sopenharmony_ci 1167195972f6Sopenharmony_ci+#if USE_LIBOS 1168195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1169195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1170195972f6Sopenharmony_ci+ return -1; 1171195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1172195972f6Sopenharmony_ci+ return posix_api->send_msg(s, msg, flags); 1173195972f6Sopenharmony_ci+ } 1174195972f6Sopenharmony_ci+#endif 1175195972f6Sopenharmony_ci+ 1176195972f6Sopenharmony_ci sock = get_socket(s); 1177195972f6Sopenharmony_ci if (!sock) { 1178195972f6Sopenharmony_ci return -1; 1179195972f6Sopenharmony_ci@@ -1436,10 +1780,10 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags) 1180195972f6Sopenharmony_ci sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); 1181195972f6Sopenharmony_ci LWIP_ERROR("lwip_sendmsg: invalid msghdr iov", msg->msg_iov != NULL, 1182195972f6Sopenharmony_ci sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); 1183195972f6Sopenharmony_ci- LWIP_ERROR("lwip_sendmsg: maximum iovs exceeded", (msg->msg_iovlen > 0) && (msg->msg_iovlen <= IOV_MAX), 1184195972f6Sopenharmony_ci- sock_set_errno(sock, EMSGSIZE); done_socket(sock); return -1;); 1185195972f6Sopenharmony_ci- LWIP_ERROR("lwip_sendmsg: unsupported flags", (flags & ~(MSG_DONTWAIT | MSG_MORE)) == 0, 1186195972f6Sopenharmony_ci- sock_set_errno(sock, EOPNOTSUPP); done_socket(sock); return -1;); 1187195972f6Sopenharmony_ci+ //LWIP_ERROR("lwip_sendmsg: maximum iovs exceeded", (msg->msg_iovlen > 0) && (msg->msg_iovlen <= IOV_MAX), 1188195972f6Sopenharmony_ci+ // sock_set_errno(sock, EMSGSIZE); done_socket(sock); return -1;); 1189195972f6Sopenharmony_ci+ //LWIP_ERROR("lwip_sendmsg: unsupported flags", (flags & ~(MSG_DONTWAIT | MSG_MORE)) == 0, 1190195972f6Sopenharmony_ci+ // sock_set_errno(sock, EOPNOTSUPP); done_socket(sock); return -1;); 1191195972f6Sopenharmony_ci 1192195972f6Sopenharmony_ci LWIP_UNUSED_ARG(msg->msg_control); 1193195972f6Sopenharmony_ci LWIP_UNUSED_ARG(msg->msg_controllen); 1194195972f6Sopenharmony_ci@@ -1590,6 +1934,15 @@ lwip_sendto(int s, const void *data, size_t size, int flags, 1195195972f6Sopenharmony_ci u16_t remote_port; 1196195972f6Sopenharmony_ci struct netbuf buf; 1197195972f6Sopenharmony_ci 1198195972f6Sopenharmony_ci+#if USE_LIBOS 1199195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1200195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1201195972f6Sopenharmony_ci+ return -1; 1202195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1203195972f6Sopenharmony_ci+ return posix_api->send_to(s, data, size, flags, to, tolen); 1204195972f6Sopenharmony_ci+ } 1205195972f6Sopenharmony_ci+#endif 1206195972f6Sopenharmony_ci+ 1207195972f6Sopenharmony_ci sock = get_socket(s); 1208195972f6Sopenharmony_ci if (!sock) { 1209195972f6Sopenharmony_ci return -1; 1210195972f6Sopenharmony_ci@@ -1688,6 +2041,11 @@ lwip_socket(int domain, int type, int protocol) 1211195972f6Sopenharmony_ci 1212195972f6Sopenharmony_ci LWIP_UNUSED_ARG(domain); /* @todo: check this */ 1213195972f6Sopenharmony_ci 1214195972f6Sopenharmony_ci+#if USE_LIBOS 1215195972f6Sopenharmony_ci+ if ((domain != AF_INET && domain != AF_UNSPEC) || posix_api->is_chld) 1216195972f6Sopenharmony_ci+ return posix_api->socket_fn(domain, type, protocol); 1217195972f6Sopenharmony_ci+#endif 1218195972f6Sopenharmony_ci+ 1219195972f6Sopenharmony_ci /* create a netconn */ 1220195972f6Sopenharmony_ci switch (type) { 1221195972f6Sopenharmony_ci case SOCK_RAW: 1222195972f6Sopenharmony_ci@@ -1744,6 +2102,14 @@ lwip_socket(int domain, int type, int protocol) 1223195972f6Sopenharmony_ci ssize_t 1224195972f6Sopenharmony_ci lwip_write(int s, const void *data, size_t size) 1225195972f6Sopenharmony_ci { 1226195972f6Sopenharmony_ci+#if USE_LIBOS 1227195972f6Sopenharmony_ci+ enum KERNEL_LWIP_PATH path = select_path(s); 1228195972f6Sopenharmony_ci+ if (path == PATH_ERR) { 1229195972f6Sopenharmony_ci+ return -1; 1230195972f6Sopenharmony_ci+ } else if (path == PATH_KERNEL) { 1231195972f6Sopenharmony_ci+ return posix_api->write_fn(s, data, size); 1232195972f6Sopenharmony_ci+ } 1233195972f6Sopenharmony_ci+#endif 1234195972f6Sopenharmony_ci return lwip_send(s, data, size, 0); 1235195972f6Sopenharmony_ci } 1236195972f6Sopenharmony_ci 1237195972f6Sopenharmony_ci@@ -2479,7 +2845,7 @@ lwip_poll_should_wake(const struct lwip_select_cb *scb, int fd, int has_recveven 1238195972f6Sopenharmony_ci * NETCONN_EVT_ERROR 1239195972f6Sopenharmony_ci * This requirement will be asserted in select_check_waiters() 1240195972f6Sopenharmony_ci */ 1241195972f6Sopenharmony_ci-static void 1242195972f6Sopenharmony_ci+void 1243195972f6Sopenharmony_ci event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 1244195972f6Sopenharmony_ci { 1245195972f6Sopenharmony_ci int s, check_waiters; 1246195972f6Sopenharmony_ci@@ -2528,23 +2894,38 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 1247195972f6Sopenharmony_ci if (sock->rcvevent > 1) { 1248195972f6Sopenharmony_ci check_waiters = 0; 1249195972f6Sopenharmony_ci } 1250195972f6Sopenharmony_ci+#if USE_LIBOS 1251195972f6Sopenharmony_ci+ add_epoll_event(conn, EPOLLIN); 1252195972f6Sopenharmony_ci+#endif 1253195972f6Sopenharmony_ci break; 1254195972f6Sopenharmony_ci case NETCONN_EVT_RCVMINUS: 1255195972f6Sopenharmony_ci sock->rcvevent--; 1256195972f6Sopenharmony_ci check_waiters = 0; 1257195972f6Sopenharmony_ci+#if USE_LIBOS 1258195972f6Sopenharmony_ci+ del_epoll_event(conn, EPOLLIN); 1259195972f6Sopenharmony_ci+#endif 1260195972f6Sopenharmony_ci break; 1261195972f6Sopenharmony_ci case NETCONN_EVT_SENDPLUS: 1262195972f6Sopenharmony_ci if (sock->sendevent) { 1263195972f6Sopenharmony_ci check_waiters = 0; 1264195972f6Sopenharmony_ci } 1265195972f6Sopenharmony_ci sock->sendevent = 1; 1266195972f6Sopenharmony_ci+#if USE_LIBOS 1267195972f6Sopenharmony_ci+ add_epoll_event(conn, EPOLLOUT); 1268195972f6Sopenharmony_ci+#endif 1269195972f6Sopenharmony_ci break; 1270195972f6Sopenharmony_ci case NETCONN_EVT_SENDMINUS: 1271195972f6Sopenharmony_ci sock->sendevent = 0; 1272195972f6Sopenharmony_ci check_waiters = 0; 1273195972f6Sopenharmony_ci+#if USE_LIBOS 1274195972f6Sopenharmony_ci+ del_epoll_event(conn, EPOLLOUT); 1275195972f6Sopenharmony_ci+#endif 1276195972f6Sopenharmony_ci break; 1277195972f6Sopenharmony_ci case NETCONN_EVT_ERROR: 1278195972f6Sopenharmony_ci sock->errevent = 1; 1279195972f6Sopenharmony_ci+#if USE_LIBOS 1280195972f6Sopenharmony_ci+ add_epoll_event(conn, EPOLLERR); 1281195972f6Sopenharmony_ci+#endif 1282195972f6Sopenharmony_ci break; 1283195972f6Sopenharmony_ci default: 1284195972f6Sopenharmony_ci LWIP_ASSERT("unknown event", 0); 1285195972f6Sopenharmony_ci@@ -2739,9 +3120,11 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local) 1286195972f6Sopenharmony_ci ip_addr_debug_print_val(SOCKETS_DEBUG, naddr); 1287195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", port)); 1288195972f6Sopenharmony_ci 1289195972f6Sopenharmony_ci+#if !USE_LIBOS 1290195972f6Sopenharmony_ci if (*namelen > saddr.sa.sa_len) { 1291195972f6Sopenharmony_ci *namelen = saddr.sa.sa_len; 1292195972f6Sopenharmony_ci } 1293195972f6Sopenharmony_ci+#endif 1294195972f6Sopenharmony_ci MEMCPY(name, &saddr, *namelen); 1295195972f6Sopenharmony_ci 1296195972f6Sopenharmony_ci sock_set_errno(sock, 0); 1297195972f6Sopenharmony_ci@@ -2752,12 +3135,41 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local) 1298195972f6Sopenharmony_ci int 1299195972f6Sopenharmony_ci lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen) 1300195972f6Sopenharmony_ci { 1301195972f6Sopenharmony_ci+#if USE_LIBOS 1302195972f6Sopenharmony_ci+ struct lwip_sock *sock; 1303195972f6Sopenharmony_ci+ 1304195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 1305195972f6Sopenharmony_ci+ if (!sock) { 1306195972f6Sopenharmony_ci+ return posix_api->getpeername_fn(s, name, namelen); 1307195972f6Sopenharmony_ci+ } 1308195972f6Sopenharmony_ci+ /*for AF_INET, if has only host type bit, just call linux api, 1309195972f6Sopenharmony_ci+ *if has libos and host type bits, it's a not connected fd, call 1310195972f6Sopenharmony_ci+ *linux api and return -1(errno == ENOTCONN) is also ok*/ 1311195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1312195972f6Sopenharmony_ci+ return posix_api->getpeername_fn(s, name, namelen); 1313195972f6Sopenharmony_ci+ } 1314195972f6Sopenharmony_ci+#endif 1315195972f6Sopenharmony_ci+ 1316195972f6Sopenharmony_ci return lwip_getaddrname(s, name, namelen, 0); 1317195972f6Sopenharmony_ci } 1318195972f6Sopenharmony_ci 1319195972f6Sopenharmony_ci int 1320195972f6Sopenharmony_ci lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen) 1321195972f6Sopenharmony_ci { 1322195972f6Sopenharmony_ci+#if USE_LIBOS 1323195972f6Sopenharmony_ci+ struct lwip_sock *sock; 1324195972f6Sopenharmony_ci+ 1325195972f6Sopenharmony_ci+ sock = posix_api->get_socket(s); 1326195972f6Sopenharmony_ci+ if (!sock) { 1327195972f6Sopenharmony_ci+ return posix_api->getsockname_fn(s, name, namelen); 1328195972f6Sopenharmony_ci+ } 1329195972f6Sopenharmony_ci+ /*for AF_INET, if has only host type bit, just call linux api, 1330195972f6Sopenharmony_ci+ *if has libos and host type bits, also call linux api*/ 1331195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1332195972f6Sopenharmony_ci+ return posix_api->getsockname_fn(s, name, namelen); 1333195972f6Sopenharmony_ci+ } 1334195972f6Sopenharmony_ci+#endif 1335195972f6Sopenharmony_ci+ 1336195972f6Sopenharmony_ci return lwip_getaddrname(s, name, namelen, 1); 1337195972f6Sopenharmony_ci } 1338195972f6Sopenharmony_ci 1339195972f6Sopenharmony_ci@@ -2765,15 +3177,28 @@ int 1340195972f6Sopenharmony_ci lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) 1341195972f6Sopenharmony_ci { 1342195972f6Sopenharmony_ci int err; 1343195972f6Sopenharmony_ci- struct lwip_sock *sock = get_socket(s); 1344195972f6Sopenharmony_ci #if !LWIP_TCPIP_CORE_LOCKING 1345195972f6Sopenharmony_ci err_t cberr; 1346195972f6Sopenharmony_ci LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); 1347195972f6Sopenharmony_ci #endif /* !LWIP_TCPIP_CORE_LOCKING */ 1348195972f6Sopenharmony_ci 1349195972f6Sopenharmony_ci+#if USE_LIBOS 1350195972f6Sopenharmony_ci+ struct lwip_sock *sock = posix_api->get_socket(s); 1351195972f6Sopenharmony_ci+ 1352195972f6Sopenharmony_ci+ if (!sock) { 1353195972f6Sopenharmony_ci+ return posix_api->getsockopt_fn(s, level, optname, optval, optlen); 1354195972f6Sopenharmony_ci+ } 1355195972f6Sopenharmony_ci+ /*for AF_INET, we return linux result? */ 1356195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1357195972f6Sopenharmony_ci+ return posix_api->getsockopt_fn(s, level, optname, optval, optlen); 1358195972f6Sopenharmony_ci+ } 1359195972f6Sopenharmony_ci+#else 1360195972f6Sopenharmony_ci+ struct lwip_sock *sock = get_socket(s); 1361195972f6Sopenharmony_ci+ 1362195972f6Sopenharmony_ci if (!sock) { 1363195972f6Sopenharmony_ci return -1; 1364195972f6Sopenharmony_ci } 1365195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1366195972f6Sopenharmony_ci 1367195972f6Sopenharmony_ci if ((NULL == optval) || (NULL == optlen)) { 1368195972f6Sopenharmony_ci sock_set_errno(sock, EFAULT); 1369195972f6Sopenharmony_ci@@ -3211,15 +3636,30 @@ int 1370195972f6Sopenharmony_ci lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) 1371195972f6Sopenharmony_ci { 1372195972f6Sopenharmony_ci int err = 0; 1373195972f6Sopenharmony_ci- struct lwip_sock *sock = get_socket(s); 1374195972f6Sopenharmony_ci #if !LWIP_TCPIP_CORE_LOCKING 1375195972f6Sopenharmony_ci err_t cberr; 1376195972f6Sopenharmony_ci LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); 1377195972f6Sopenharmony_ci #endif /* !LWIP_TCPIP_CORE_LOCKING */ 1378195972f6Sopenharmony_ci 1379195972f6Sopenharmony_ci+#if USE_LIBOS 1380195972f6Sopenharmony_ci+ struct lwip_sock *sock = posix_api->get_socket(s); 1381195972f6Sopenharmony_ci+ 1382195972f6Sopenharmony_ci+ if (!sock) { 1383195972f6Sopenharmony_ci+ return posix_api->setsockopt_fn(s, level, optname, optval, optlen); 1384195972f6Sopenharmony_ci+ } 1385195972f6Sopenharmony_ci+ /*for AF_INET, we may try both linux and lwip*/ 1386195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1387195972f6Sopenharmony_ci+ if (posix_api->setsockopt_fn(s, level, optname, optval, optlen) < 0) { 1388195972f6Sopenharmony_ci+ return -1; 1389195972f6Sopenharmony_ci+ } 1390195972f6Sopenharmony_ci+ } 1391195972f6Sopenharmony_ci+#else 1392195972f6Sopenharmony_ci+ struct lwip_sock *sock = get_socket(s); 1393195972f6Sopenharmony_ci+ 1394195972f6Sopenharmony_ci if (!sock) { 1395195972f6Sopenharmony_ci return -1; 1396195972f6Sopenharmony_ci } 1397195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1398195972f6Sopenharmony_ci 1399195972f6Sopenharmony_ci if (NULL == optval) { 1400195972f6Sopenharmony_ci sock_set_errno(sock, EFAULT); 1401195972f6Sopenharmony_ci@@ -3333,6 +3773,7 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ 1402195972f6Sopenharmony_ci case SO_KEEPALIVE: 1403195972f6Sopenharmony_ci #if SO_REUSE 1404195972f6Sopenharmony_ci case SO_REUSEADDR: 1405195972f6Sopenharmony_ci+ case SO_REUSEPORT: 1406195972f6Sopenharmony_ci #endif /* SO_REUSE */ 1407195972f6Sopenharmony_ci if ((optname == SO_BROADCAST) && 1408195972f6Sopenharmony_ci (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_UDP)) { 1409195972f6Sopenharmony_ci@@ -3745,6 +4186,29 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ 1410195972f6Sopenharmony_ci return err; 1411195972f6Sopenharmony_ci } 1412195972f6Sopenharmony_ci 1413195972f6Sopenharmony_ci+#if USE_LIBOS 1414195972f6Sopenharmony_ci+int 1415195972f6Sopenharmony_ci+lwip_ioctl(int s, long cmd, ...) 1416195972f6Sopenharmony_ci+{ 1417195972f6Sopenharmony_ci+ struct lwip_sock *sock = posix_api->get_socket(s); 1418195972f6Sopenharmony_ci+ u8_t val; 1419195972f6Sopenharmony_ci+ 1420195972f6Sopenharmony_ci+ int ret = -1; 1421195972f6Sopenharmony_ci+ void *argp; 1422195972f6Sopenharmony_ci+ va_list ap; 1423195972f6Sopenharmony_ci+ 1424195972f6Sopenharmony_ci+ va_start(ap, cmd); 1425195972f6Sopenharmony_ci+ argp = va_arg(ap, void *); 1426195972f6Sopenharmony_ci+ va_end(ap); 1427195972f6Sopenharmony_ci+ 1428195972f6Sopenharmony_ci+ if (!sock) { 1429195972f6Sopenharmony_ci+ return posix_api->ioctl_fn(s, cmd, argp); 1430195972f6Sopenharmony_ci+ } 1431195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1432195972f6Sopenharmony_ci+ if ((ret = posix_api->ioctl_fn(s, cmd, argp)) == -1) 1433195972f6Sopenharmony_ci+ return ret; 1434195972f6Sopenharmony_ci+ } 1435195972f6Sopenharmony_ci+#else 1436195972f6Sopenharmony_ci int 1437195972f6Sopenharmony_ci lwip_ioctl(int s, long cmd, void *argp) 1438195972f6Sopenharmony_ci { 1439195972f6Sopenharmony_ci@@ -3757,6 +4221,7 @@ lwip_ioctl(int s, long cmd, void *argp) 1440195972f6Sopenharmony_ci if (!sock) { 1441195972f6Sopenharmony_ci return -1; 1442195972f6Sopenharmony_ci } 1443195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1444195972f6Sopenharmony_ci 1445195972f6Sopenharmony_ci switch (cmd) { 1446195972f6Sopenharmony_ci #if LWIP_SO_RCVBUF || LWIP_FIONREAD_LINUXMODE 1447195972f6Sopenharmony_ci@@ -3839,6 +4304,26 @@ lwip_ioctl(int s, long cmd, void *argp) 1448195972f6Sopenharmony_ci * the flag O_NONBLOCK is implemented for F_SETFL. 1449195972f6Sopenharmony_ci */ 1450195972f6Sopenharmony_ci int 1451195972f6Sopenharmony_ci+#if USE_LIBOS 1452195972f6Sopenharmony_ci+lwip_fcntl(int s, int cmd, ...) 1453195972f6Sopenharmony_ci+{ 1454195972f6Sopenharmony_ci+ struct lwip_sock *sock = posix_api->get_socket(s); 1455195972f6Sopenharmony_ci+ int val, ret = -1; 1456195972f6Sopenharmony_ci+ int op_mode = 0; 1457195972f6Sopenharmony_ci+ va_list ap; 1458195972f6Sopenharmony_ci+ 1459195972f6Sopenharmony_ci+ va_start(ap, cmd); 1460195972f6Sopenharmony_ci+ val = va_arg(ap, int); 1461195972f6Sopenharmony_ci+ va_end(ap); 1462195972f6Sopenharmony_ci+ 1463195972f6Sopenharmony_ci+ if (!sock) { 1464195972f6Sopenharmony_ci+ return posix_api->fcntl_fn(s, cmd, val); 1465195972f6Sopenharmony_ci+ } 1466195972f6Sopenharmony_ci+ if (CONN_TYPE_HAS_HOST(sock->conn)) { 1467195972f6Sopenharmony_ci+ if ((ret = posix_api->fcntl_fn(s, cmd, val)) == -1) 1468195972f6Sopenharmony_ci+ return ret; 1469195972f6Sopenharmony_ci+ } 1470195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 1471195972f6Sopenharmony_ci lwip_fcntl(int s, int cmd, int val) 1472195972f6Sopenharmony_ci { 1473195972f6Sopenharmony_ci struct lwip_sock *sock = get_socket(s); 1474195972f6Sopenharmony_ci@@ -3848,6 +4333,7 @@ lwip_fcntl(int s, int cmd, int val) 1475195972f6Sopenharmony_ci if (!sock) { 1476195972f6Sopenharmony_ci return -1; 1477195972f6Sopenharmony_ci } 1478195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1479195972f6Sopenharmony_ci 1480195972f6Sopenharmony_ci switch (cmd) { 1481195972f6Sopenharmony_ci case F_GETFL: 1482195972f6Sopenharmony_ci@@ -4163,4 +4649,50 @@ lwip_socket_drop_registered_mld6_memberships(int s) 1483195972f6Sopenharmony_ci } 1484195972f6Sopenharmony_ci #endif /* LWIP_IPV6_MLD */ 1485195972f6Sopenharmony_ci 1486195972f6Sopenharmony_ci+#if USE_LIBOS 1487195972f6Sopenharmony_ci+void lwip_sock_init(void) 1488195972f6Sopenharmony_ci+{ 1489195972f6Sopenharmony_ci+ if (sockets_num == 0) { 1490195972f6Sopenharmony_ci+ sockets_num = NUM_SOCKETS; 1491195972f6Sopenharmony_ci+ sockets = calloc(sockets_num, sizeof(struct lwip_sock)); 1492195972f6Sopenharmony_ci+ LWIP_ASSERT("sockets != NULL", sockets != NULL); 1493195972f6Sopenharmony_ci+ memset(sockets, 0, sockets_num * sizeof(struct lwip_sock)); 1494195972f6Sopenharmony_ci+ } 1495195972f6Sopenharmony_ci+ return; 1496195972f6Sopenharmony_ci+} 1497195972f6Sopenharmony_ci+ 1498195972f6Sopenharmony_ci+//modify from lwip_close 1499195972f6Sopenharmony_ci+void lwip_exit(void) 1500195972f6Sopenharmony_ci+{ 1501195972f6Sopenharmony_ci+ int i, is_tcp; 1502195972f6Sopenharmony_ci+ struct lwip_sock *sock; 1503195972f6Sopenharmony_ci+ 1504195972f6Sopenharmony_ci+ if (memp_pools[MEMP_SYS_MBOX] == NULL) { 1505195972f6Sopenharmony_ci+ return; 1506195972f6Sopenharmony_ci+ } 1507195972f6Sopenharmony_ci+ 1508195972f6Sopenharmony_ci+ for (i = 0; i < sockets_num; i++) { 1509195972f6Sopenharmony_ci+ sock = &sockets[i]; 1510195972f6Sopenharmony_ci+ if (!sock->conn) 1511195972f6Sopenharmony_ci+ continue; 1512195972f6Sopenharmony_ci+#if LWIP_IGMP 1513195972f6Sopenharmony_ci+ /* drop all possibly joined IGMP memberships */ 1514195972f6Sopenharmony_ci+ lwip_socket_drop_registered_memberships(i); 1515195972f6Sopenharmony_ci+#endif /* LWIP_IGMP */ 1516195972f6Sopenharmony_ci+ /* 1517195972f6Sopenharmony_ci+ * process is exiting, call netconn_delete to 1518195972f6Sopenharmony_ci+ * close tcp connection, and ignore the return value 1519195972f6Sopenharmony_ci+ */ 1520195972f6Sopenharmony_ci+ is_tcp = NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP; 1521195972f6Sopenharmony_ci+ netconn_delete(sock->conn); 1522195972f6Sopenharmony_ci+ free_socket(sock, is_tcp); 1523195972f6Sopenharmony_ci+ } 1524195972f6Sopenharmony_ci+ 1525195972f6Sopenharmony_ci+ free(sockets); 1526195972f6Sopenharmony_ci+ sockets = NULL; 1527195972f6Sopenharmony_ci+ sockets_num = 0; 1528195972f6Sopenharmony_ci+} 1529195972f6Sopenharmony_ci+ 1530195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1531195972f6Sopenharmony_ci+ 1532195972f6Sopenharmony_ci #endif /* LWIP_SOCKET */ 1533195972f6Sopenharmony_cidiff --git a/src/api/sys_arch.c b/src/api/sys_arch.c 1534195972f6Sopenharmony_cinew file mode 100644 1535195972f6Sopenharmony_ciindex 0000000..55561b1 1536195972f6Sopenharmony_ci--- /dev/null 1537195972f6Sopenharmony_ci+++ b/src/api/sys_arch.c 1538195972f6Sopenharmony_ci@@ -0,0 +1,379 @@ 1539195972f6Sopenharmony_ci+/* 1540195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 1541195972f6Sopenharmony_ci+ * All rights reserved. 1542195972f6Sopenharmony_ci+ * 1543195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 1544195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 1545195972f6Sopenharmony_ci+ * 1546195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 1547195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 1548195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 1549195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 1550195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 1551195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 1552195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 1553195972f6Sopenharmony_ci+ * 1554195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1555195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1556195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 1557195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1558195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 1559195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1560195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1561195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 1562195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 1563195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 1564195972f6Sopenharmony_ci+ * 1565195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 1566195972f6Sopenharmony_ci+ * 1567195972f6Sopenharmony_ci+ * Author: Huawei Technologies 1568195972f6Sopenharmony_ci+ * 1569195972f6Sopenharmony_ci+ */ 1570195972f6Sopenharmony_ci+ 1571195972f6Sopenharmony_ci+#define _GNU_SOURCE 1572195972f6Sopenharmony_ci+#include <pthread.h> 1573195972f6Sopenharmony_ci+#include <string.h> 1574195972f6Sopenharmony_ci+#include <time.h> 1575195972f6Sopenharmony_ci+#include <unistd.h> 1576195972f6Sopenharmony_ci+ 1577195972f6Sopenharmony_ci+#include <rte_memzone.h> 1578195972f6Sopenharmony_ci+#include <rte_ring.h> 1579195972f6Sopenharmony_ci+ 1580195972f6Sopenharmony_ci+#include "lwip/err.h" 1581195972f6Sopenharmony_ci+#include "lwip/mem.h" 1582195972f6Sopenharmony_ci+#include "lwip/memp.h" 1583195972f6Sopenharmony_ci+#include "lwip/opt.h" 1584195972f6Sopenharmony_ci+#include "lwip/sys.h" 1585195972f6Sopenharmony_ci+#include "lwip/timeouts.h" 1586195972f6Sopenharmony_ci+#include "arch/sys_arch.h" 1587195972f6Sopenharmony_ci+ 1588195972f6Sopenharmony_ci+struct sys_mutex { 1589195972f6Sopenharmony_ci+ volatile unsigned int m; 1590195972f6Sopenharmony_ci+}; 1591195972f6Sopenharmony_ci+ 1592195972f6Sopenharmony_ci+struct sys_mutex lstack_mutex; 1593195972f6Sopenharmony_ci+ 1594195972f6Sopenharmony_ci+struct sys_sem lstack_sem; 1595195972f6Sopenharmony_ci+ 1596195972f6Sopenharmony_ci+#define MAX_THREAD_NAME 64 1597195972f6Sopenharmony_ci+#define MBOX_NAME_PREFIX "_mbox_0x" 1598195972f6Sopenharmony_ci+#define MAX_MBOX_NAME_LEN (sizeof(MBOX_NAME_PREFIX) + 32) // log(UINT64_MAX) < 32 1599195972f6Sopenharmony_ci+ 1600195972f6Sopenharmony_ci+struct sys_thread { 1601195972f6Sopenharmony_ci+ struct sys_thread *next; 1602195972f6Sopenharmony_ci+ char name[MAX_THREAD_NAME]; 1603195972f6Sopenharmony_ci+ lwip_thread_fn fn; 1604195972f6Sopenharmony_ci+ void *arg; 1605195972f6Sopenharmony_ci+ int stacksize; 1606195972f6Sopenharmony_ci+ int prio; 1607195972f6Sopenharmony_ci+ pthread_t tid; 1608195972f6Sopenharmony_ci+}; 1609195972f6Sopenharmony_ci+ 1610195972f6Sopenharmony_ci+ 1611195972f6Sopenharmony_ci+struct sys_mem_stats { 1612195972f6Sopenharmony_ci+ uint32_t tot_len; 1613195972f6Sopenharmony_ci+}; 1614195972f6Sopenharmony_ci+ 1615195972f6Sopenharmony_ci+static PER_THREAD struct sys_mem_stats hugepage_stats; 1616195972f6Sopenharmony_ci+ 1617195972f6Sopenharmony_ci+static PER_THREAD uint64_t cycles_per_ms __attribute__((aligned(64))); 1618195972f6Sopenharmony_ci+static PER_THREAD uint64_t sys_start_ms __attribute__((aligned(64))); 1619195972f6Sopenharmony_ci+ 1620195972f6Sopenharmony_ci+/* 1621195972f6Sopenharmony_ci+ * Mailbox 1622195972f6Sopenharmony_ci+ * */ 1623195972f6Sopenharmony_ci+static int mbox_wait_func(void) 1624195972f6Sopenharmony_ci+{ 1625195972f6Sopenharmony_ci+#if LWIP_TIMERS 1626195972f6Sopenharmony_ci+ sys_timer_run(); 1627195972f6Sopenharmony_ci+#endif /* LWIP_TIMER */ 1628195972f6Sopenharmony_ci+ return eth_dev_poll(); 1629195972f6Sopenharmony_ci+} 1630195972f6Sopenharmony_ci+ 1631195972f6Sopenharmony_ci+err_t sys_mbox_new(struct sys_mbox **mb, int size) 1632195972f6Sopenharmony_ci+{ 1633195972f6Sopenharmony_ci+ int ret; 1634195972f6Sopenharmony_ci+ struct sys_mbox *mbox; 1635195972f6Sopenharmony_ci+ 1636195972f6Sopenharmony_ci+ mbox = (struct sys_mbox *)memp_malloc(MEMP_SYS_MBOX); 1637195972f6Sopenharmony_ci+ if (mbox == NULL) { 1638195972f6Sopenharmony_ci+ return ERR_MEM; 1639195972f6Sopenharmony_ci+ } 1640195972f6Sopenharmony_ci+ 1641195972f6Sopenharmony_ci+ mbox->flags = RING_F_SP_ENQ | RING_F_SC_DEQ; 1642195972f6Sopenharmony_ci+ 1643195972f6Sopenharmony_ci+ ret = snprintf(mbox->name, sizeof(mbox->name), MBOX_NAME_PREFIX"%"PRIXPTR, (uintptr_t)mbox); 1644195972f6Sopenharmony_ci+ if (ret < 0) { 1645195972f6Sopenharmony_ci+ memp_free(MEMP_SYS_MBOX, mbox); 1646195972f6Sopenharmony_ci+ return ERR_VAL; 1647195972f6Sopenharmony_ci+ } 1648195972f6Sopenharmony_ci+ 1649195972f6Sopenharmony_ci+ mbox->size = size; 1650195972f6Sopenharmony_ci+ mbox->socket_id = rte_socket_id(); 1651195972f6Sopenharmony_ci+ mbox->ring = rte_ring_create(mbox->name, mbox->size, mbox->socket_id, mbox->flags); 1652195972f6Sopenharmony_ci+ if (!mbox->ring) { 1653195972f6Sopenharmony_ci+ RTE_LOG(ERR, EAL, "cannot create rte_ring for mbox\n"); 1654195972f6Sopenharmony_ci+ memp_free(MEMP_SYS_MBOX, mbox); 1655195972f6Sopenharmony_ci+ return ERR_MEM; 1656195972f6Sopenharmony_ci+ } 1657195972f6Sopenharmony_ci+ mbox->wait_fn = mbox_wait_func; 1658195972f6Sopenharmony_ci+ *mb = mbox; 1659195972f6Sopenharmony_ci+ 1660195972f6Sopenharmony_ci+ return ERR_OK; 1661195972f6Sopenharmony_ci+} 1662195972f6Sopenharmony_ci+ 1663195972f6Sopenharmony_ci+void sys_mbox_free(struct sys_mbox **mb) 1664195972f6Sopenharmony_ci+{ 1665195972f6Sopenharmony_ci+ struct sys_mbox *mbox = *mb; 1666195972f6Sopenharmony_ci+ rte_ring_free(mbox->ring); 1667195972f6Sopenharmony_ci+ memp_free(MEMP_SYS_MBOX, mbox); 1668195972f6Sopenharmony_ci+} 1669195972f6Sopenharmony_ci+ 1670195972f6Sopenharmony_ci+err_t sys_mbox_trypost(struct sys_mbox **mb, void *msg) 1671195972f6Sopenharmony_ci+{ 1672195972f6Sopenharmony_ci+ unsigned int n; 1673195972f6Sopenharmony_ci+ struct sys_mbox *mbox = *mb; 1674195972f6Sopenharmony_ci+ 1675195972f6Sopenharmony_ci+ n = rte_ring_sp_enqueue_bulk(mbox->ring, &msg, 1, NULL); 1676195972f6Sopenharmony_ci+ if (!n) 1677195972f6Sopenharmony_ci+ return ERR_BUF; 1678195972f6Sopenharmony_ci+ return ERR_OK; 1679195972f6Sopenharmony_ci+} 1680195972f6Sopenharmony_ci+ 1681195972f6Sopenharmony_ci+void sys_mbox_post(struct sys_mbox **mb, void *msg) 1682195972f6Sopenharmony_ci+{ 1683195972f6Sopenharmony_ci+ struct sys_mbox *mbox = *mb; 1684195972f6Sopenharmony_ci+ 1685195972f6Sopenharmony_ci+ /* NOTE: sys_mbox_post is used on mbox defined in src/api/tcpip.c. 1686195972f6Sopenharmony_ci+ * If the ring size of mbox is greater than MEMP_NUM_TCPIP_MSG_API, 1687195972f6Sopenharmony_ci+ * enqueue failure will never happen. 1688195972f6Sopenharmony_ci+ * */ 1689195972f6Sopenharmony_ci+ if (!rte_ring_sp_enqueue_bulk(mbox->ring, &msg, 1, NULL)) { 1690195972f6Sopenharmony_ci+ LWIP_ASSERT("It is failed to post msg into mbox", 0); 1691195972f6Sopenharmony_ci+ } 1692195972f6Sopenharmony_ci+} 1693195972f6Sopenharmony_ci+ 1694195972f6Sopenharmony_ci+err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg) 1695195972f6Sopenharmony_ci+{ 1696195972f6Sopenharmony_ci+ return sys_mbox_trypost(q, msg); 1697195972f6Sopenharmony_ci+} 1698195972f6Sopenharmony_ci+ 1699195972f6Sopenharmony_ci+uint32_t sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg) 1700195972f6Sopenharmony_ci+{ 1701195972f6Sopenharmony_ci+ unsigned int n; 1702195972f6Sopenharmony_ci+ struct sys_mbox *mbox = *mb; 1703195972f6Sopenharmony_ci+ 1704195972f6Sopenharmony_ci+ n = rte_ring_sc_dequeue_bulk(mbox->ring, msg, 1, NULL); 1705195972f6Sopenharmony_ci+ if (!n) { 1706195972f6Sopenharmony_ci+ *msg = NULL; 1707195972f6Sopenharmony_ci+ return SYS_MBOX_EMPTY; 1708195972f6Sopenharmony_ci+ } 1709195972f6Sopenharmony_ci+ 1710195972f6Sopenharmony_ci+ return 0; 1711195972f6Sopenharmony_ci+} 1712195972f6Sopenharmony_ci+ 1713195972f6Sopenharmony_ci+uint32_t sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, uint32_t timeout) 1714195972f6Sopenharmony_ci+{ 1715195972f6Sopenharmony_ci+ unsigned int n; 1716195972f6Sopenharmony_ci+ uint32_t poll_ts = 0; 1717195972f6Sopenharmony_ci+ uint32_t time_needed = 0; 1718195972f6Sopenharmony_ci+ struct sys_mbox *mbox = *mb; 1719195972f6Sopenharmony_ci+ 1720195972f6Sopenharmony_ci+ n = rte_ring_sc_dequeue_bulk(mbox->ring, msg, 1, NULL); 1721195972f6Sopenharmony_ci+ 1722195972f6Sopenharmony_ci+ if (timeout > 0) 1723195972f6Sopenharmony_ci+ poll_ts = sys_now(); 1724195972f6Sopenharmony_ci+ 1725195972f6Sopenharmony_ci+ while (!n) { 1726195972f6Sopenharmony_ci+ if (timeout > 0) { 1727195972f6Sopenharmony_ci+ time_needed = sys_now() - poll_ts; 1728195972f6Sopenharmony_ci+ if (time_needed >= timeout) { 1729195972f6Sopenharmony_ci+ return SYS_ARCH_TIMEOUT; 1730195972f6Sopenharmony_ci+ } 1731195972f6Sopenharmony_ci+ } 1732195972f6Sopenharmony_ci+ 1733195972f6Sopenharmony_ci+ (void)mbox->wait_fn(); 1734195972f6Sopenharmony_ci+ 1735195972f6Sopenharmony_ci+ n = rte_ring_sc_dequeue_bulk(mbox->ring, msg, 1, NULL); 1736195972f6Sopenharmony_ci+ } 1737195972f6Sopenharmony_ci+ 1738195972f6Sopenharmony_ci+ return time_needed; 1739195972f6Sopenharmony_ci+} 1740195972f6Sopenharmony_ci+ 1741195972f6Sopenharmony_ci+int sys_mbox_empty(struct sys_mbox *mb) 1742195972f6Sopenharmony_ci+{ 1743195972f6Sopenharmony_ci+ return rte_ring_count(mb->ring) == 0; 1744195972f6Sopenharmony_ci+} 1745195972f6Sopenharmony_ci+ 1746195972f6Sopenharmony_ci+/* 1747195972f6Sopenharmony_ci+ * Threads 1748195972f6Sopenharmony_ci+ * */ 1749195972f6Sopenharmony_ci+sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio) 1750195972f6Sopenharmony_ci+{ 1751195972f6Sopenharmony_ci+ int err; 1752195972f6Sopenharmony_ci+ pthread_t tid; 1753195972f6Sopenharmony_ci+ struct sys_thread *thread; 1754195972f6Sopenharmony_ci+ 1755195972f6Sopenharmony_ci+ thread = (struct sys_thread *)malloc(sizeof(struct sys_thread)); 1756195972f6Sopenharmony_ci+ if (thread == NULL) { 1757195972f6Sopenharmony_ci+ LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: malloc sys_thread failed\n")); 1758195972f6Sopenharmony_ci+ rte_exit(EXIT_FAILURE, "malloc sys_thread failed\n"); 1759195972f6Sopenharmony_ci+ } 1760195972f6Sopenharmony_ci+ 1761195972f6Sopenharmony_ci+ err = pthread_create(&tid, NULL, (void*(*)(void *))function, arg); 1762195972f6Sopenharmony_ci+ if (err > 0) { 1763195972f6Sopenharmony_ci+ LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create failed\n")); 1764195972f6Sopenharmony_ci+ rte_exit(EXIT_FAILURE, "pthread_create failed\n"); 1765195972f6Sopenharmony_ci+ } 1766195972f6Sopenharmony_ci+ 1767195972f6Sopenharmony_ci+ err = pthread_setname_np(tid, name); 1768195972f6Sopenharmony_ci+ if (err > 0) { 1769195972f6Sopenharmony_ci+ LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_setname_np failed\n")); 1770195972f6Sopenharmony_ci+ } 1771195972f6Sopenharmony_ci+ thread->tid = tid; 1772195972f6Sopenharmony_ci+ thread->stacksize = stacksize; 1773195972f6Sopenharmony_ci+ thread->prio = prio; 1774195972f6Sopenharmony_ci+ 1775195972f6Sopenharmony_ci+ return thread; 1776195972f6Sopenharmony_ci+} 1777195972f6Sopenharmony_ci+ 1778195972f6Sopenharmony_ci+/* 1779195972f6Sopenharmony_ci+ * Semaphore 1780195972f6Sopenharmony_ci+ * */ 1781195972f6Sopenharmony_ci+err_t sys_sem_new(struct sys_sem **sem, uint8_t count) 1782195972f6Sopenharmony_ci+{ 1783195972f6Sopenharmony_ci+ *sem = (struct sys_sem *)memp_malloc(MEMP_SYS_SEM); 1784195972f6Sopenharmony_ci+ if ((*sem) == NULL) { 1785195972f6Sopenharmony_ci+ return ERR_MEM; 1786195972f6Sopenharmony_ci+ } 1787195972f6Sopenharmony_ci+ (*sem)->c = 0; 1788195972f6Sopenharmony_ci+ (*sem)->wait_fn = mbox_wait_func; 1789195972f6Sopenharmony_ci+ return ERR_OK; 1790195972f6Sopenharmony_ci+} 1791195972f6Sopenharmony_ci+ 1792195972f6Sopenharmony_ci+void sys_sem_signal(struct sys_sem **s) 1793195972f6Sopenharmony_ci+{ 1794195972f6Sopenharmony_ci+ struct sys_sem *sem = NULL; 1795195972f6Sopenharmony_ci+ LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); 1796195972f6Sopenharmony_ci+ sem = *s; 1797195972f6Sopenharmony_ci+ ++(sem->c); 1798195972f6Sopenharmony_ci+} 1799195972f6Sopenharmony_ci+ 1800195972f6Sopenharmony_ci+static uint32_t cond_wait(struct sys_sem *sem, uint32_t timeout) 1801195972f6Sopenharmony_ci+{ 1802195972f6Sopenharmony_ci+ uint32_t used_ms = 0; 1803195972f6Sopenharmony_ci+ uint32_t poll_ts; 1804195972f6Sopenharmony_ci+ 1805195972f6Sopenharmony_ci+ if (timeout == 0) { 1806195972f6Sopenharmony_ci+ (void)sem->wait_fn(); 1807195972f6Sopenharmony_ci+ return 0; 1808195972f6Sopenharmony_ci+ } 1809195972f6Sopenharmony_ci+ 1810195972f6Sopenharmony_ci+ poll_ts = sys_now(); 1811195972f6Sopenharmony_ci+ 1812195972f6Sopenharmony_ci+ while (used_ms < timeout) { 1813195972f6Sopenharmony_ci+ if (sem->c > 0) 1814195972f6Sopenharmony_ci+ return timeout - used_ms; 1815195972f6Sopenharmony_ci+ 1816195972f6Sopenharmony_ci+ (void)sem->wait_fn(); 1817195972f6Sopenharmony_ci+ used_ms = sys_now() - poll_ts; 1818195972f6Sopenharmony_ci+ } 1819195972f6Sopenharmony_ci+ 1820195972f6Sopenharmony_ci+ return SYS_ARCH_TIMEOUT; 1821195972f6Sopenharmony_ci+} 1822195972f6Sopenharmony_ci+ 1823195972f6Sopenharmony_ci+uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout) 1824195972f6Sopenharmony_ci+{ 1825195972f6Sopenharmony_ci+ uint32_t time_needed = 0; 1826195972f6Sopenharmony_ci+ struct sys_sem *sem = NULL; 1827195972f6Sopenharmony_ci+ LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); 1828195972f6Sopenharmony_ci+ sem = *s; 1829195972f6Sopenharmony_ci+ 1830195972f6Sopenharmony_ci+ while (sem->c <= 0) { 1831195972f6Sopenharmony_ci+ if (timeout > 0) { 1832195972f6Sopenharmony_ci+ time_needed = cond_wait(sem, timeout); 1833195972f6Sopenharmony_ci+ 1834195972f6Sopenharmony_ci+ if (time_needed == SYS_ARCH_TIMEOUT) { 1835195972f6Sopenharmony_ci+ return SYS_ARCH_TIMEOUT; 1836195972f6Sopenharmony_ci+ } 1837195972f6Sopenharmony_ci+ } else { 1838195972f6Sopenharmony_ci+ cond_wait(sem, 0); 1839195972f6Sopenharmony_ci+ } 1840195972f6Sopenharmony_ci+ } 1841195972f6Sopenharmony_ci+ 1842195972f6Sopenharmony_ci+ sem->c--; 1843195972f6Sopenharmony_ci+ return time_needed; 1844195972f6Sopenharmony_ci+} 1845195972f6Sopenharmony_ci+ 1846195972f6Sopenharmony_ci+void sys_sem_free(struct sys_sem **s) 1847195972f6Sopenharmony_ci+{ 1848195972f6Sopenharmony_ci+ if ((s != NULL) && (*s != SYS_SEM_NULL)) 1849195972f6Sopenharmony_ci+ memp_free(MEMP_SYS_SEM, *s); 1850195972f6Sopenharmony_ci+} 1851195972f6Sopenharmony_ci+ 1852195972f6Sopenharmony_ci+/* 1853195972f6Sopenharmony_ci+ * Mutex 1854195972f6Sopenharmony_ci+ * */ 1855195972f6Sopenharmony_ci+err_t sys_mutex_new(struct sys_mutex **mutex) 1856195972f6Sopenharmony_ci+{ 1857195972f6Sopenharmony_ci+ return ERR_OK; 1858195972f6Sopenharmony_ci+} 1859195972f6Sopenharmony_ci+ 1860195972f6Sopenharmony_ci+void sys_mutex_lock(struct sys_mutex **mutex) 1861195972f6Sopenharmony_ci+{ 1862195972f6Sopenharmony_ci+} 1863195972f6Sopenharmony_ci+ 1864195972f6Sopenharmony_ci+void sys_mutex_unlock(struct sys_mutex **mutex) 1865195972f6Sopenharmony_ci+{ 1866195972f6Sopenharmony_ci+} 1867195972f6Sopenharmony_ci+ 1868195972f6Sopenharmony_ci+void sys_mutex_free(struct sys_mutex **mutex) 1869195972f6Sopenharmony_ci+{ 1870195972f6Sopenharmony_ci+} 1871195972f6Sopenharmony_ci+ 1872195972f6Sopenharmony_ci+/* Timer from DPDK */ 1873195972f6Sopenharmony_ci+void sys_calibrate_tsc(void) 1874195972f6Sopenharmony_ci+{ 1875195972f6Sopenharmony_ci+#define MS_PER_SEC 1E3 1876195972f6Sopenharmony_ci+ uint64_t freq = rte_get_tsc_hz(); 1877195972f6Sopenharmony_ci+ 1878195972f6Sopenharmony_ci+ cycles_per_ms = (freq + MS_PER_SEC - 1) / MS_PER_SEC; 1879195972f6Sopenharmony_ci+ sys_start_ms = rte_rdtsc() / cycles_per_ms; 1880195972f6Sopenharmony_ci+} 1881195972f6Sopenharmony_ci+ 1882195972f6Sopenharmony_ci+uint32_t sys_now(void) 1883195972f6Sopenharmony_ci+{ 1884195972f6Sopenharmony_ci+ uint64_t cur_ms = rte_rdtsc() / cycles_per_ms; 1885195972f6Sopenharmony_ci+ return (uint32_t)(cur_ms - sys_start_ms); 1886195972f6Sopenharmony_ci+} 1887195972f6Sopenharmony_ci+ 1888195972f6Sopenharmony_ci+/* 1889195972f6Sopenharmony_ci+ * Critical section 1890195972f6Sopenharmony_ci+ * */ 1891195972f6Sopenharmony_ci+sys_prot_t sys_arch_protect(void) 1892195972f6Sopenharmony_ci+{ 1893195972f6Sopenharmony_ci+ return 0; 1894195972f6Sopenharmony_ci+} 1895195972f6Sopenharmony_ci+ 1896195972f6Sopenharmony_ci+void sys_arch_unprotect(sys_prot_t pval) 1897195972f6Sopenharmony_ci+{ 1898195972f6Sopenharmony_ci+} 1899195972f6Sopenharmony_ci+ 1900195972f6Sopenharmony_ci+/* 1901195972f6Sopenharmony_ci+ * Hugepage memory manager 1902195972f6Sopenharmony_ci+ * */ 1903195972f6Sopenharmony_ci+uint8_t *sys_hugepage_malloc(const char *name, uint32_t size) 1904195972f6Sopenharmony_ci+{ 1905195972f6Sopenharmony_ci+ const struct rte_memzone *mz; 1906195972f6Sopenharmony_ci+ 1907195972f6Sopenharmony_ci+ mz = rte_memzone_reserve(name, size, rte_socket_id(), 0); 1908195972f6Sopenharmony_ci+ if (mz == NULL) { 1909195972f6Sopenharmony_ci+ rte_exit(EXIT_FAILURE, "failed to reserver memory for mempool[%s]\n", name); 1910195972f6Sopenharmony_ci+ return NULL; 1911195972f6Sopenharmony_ci+ } 1912195972f6Sopenharmony_ci+ 1913195972f6Sopenharmony_ci+ memset(mz->addr, 0, mz->len); 1914195972f6Sopenharmony_ci+ hugepage_stats.tot_len += mz->len; 1915195972f6Sopenharmony_ci+ 1916195972f6Sopenharmony_ci+ return (uint8_t*)mz->addr; 1917195972f6Sopenharmony_ci+} 1918195972f6Sopenharmony_cidiff --git a/src/api/tcpip.c b/src/api/tcpip.c 1919195972f6Sopenharmony_ciindex a7e312a..d3d0b55 100644 1920195972f6Sopenharmony_ci--- a/src/api/tcpip.c 1921195972f6Sopenharmony_ci+++ b/src/api/tcpip.c 1922195972f6Sopenharmony_ci@@ -56,13 +56,13 @@ 1923195972f6Sopenharmony_ci #define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name) 1924195972f6Sopenharmony_ci 1925195972f6Sopenharmony_ci /* global variables */ 1926195972f6Sopenharmony_ci-static tcpip_init_done_fn tcpip_init_done; 1927195972f6Sopenharmony_ci-static void *tcpip_init_done_arg; 1928195972f6Sopenharmony_ci-static sys_mbox_t tcpip_mbox; 1929195972f6Sopenharmony_ci+static PER_THREAD tcpip_init_done_fn tcpip_init_done; 1930195972f6Sopenharmony_ci+static PER_THREAD void *tcpip_init_done_arg; 1931195972f6Sopenharmony_ci+static PER_THREAD sys_mbox_t tcpip_mbox; 1932195972f6Sopenharmony_ci 1933195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 1934195972f6Sopenharmony_ci /** The global semaphore to lock the stack. */ 1935195972f6Sopenharmony_ci-sys_mutex_t lock_tcpip_core; 1936195972f6Sopenharmony_ci+PER_THREAD sys_mutex_t lock_tcpip_core; 1937195972f6Sopenharmony_ci #endif /* LWIP_TCPIP_CORE_LOCKING */ 1938195972f6Sopenharmony_ci 1939195972f6Sopenharmony_ci static void tcpip_thread_handle_msg(struct tcpip_msg *msg); 1940195972f6Sopenharmony_ci@@ -123,8 +123,13 @@ again: 1941195972f6Sopenharmony_ci * 1942195972f6Sopenharmony_ci * @param arg unused argument 1943195972f6Sopenharmony_ci */ 1944195972f6Sopenharmony_ci+#if USE_LIBOS 1945195972f6Sopenharmony_ci+__attribute__((unused)) static void 1946195972f6Sopenharmony_ci+tcpip_thread(void *arg) 1947195972f6Sopenharmony_ci+#else 1948195972f6Sopenharmony_ci static void 1949195972f6Sopenharmony_ci tcpip_thread(void *arg) 1950195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 1951195972f6Sopenharmony_ci { 1952195972f6Sopenharmony_ci struct tcpip_msg *msg; 1953195972f6Sopenharmony_ci LWIP_UNUSED_ARG(arg); 1954195972f6Sopenharmony_ci@@ -242,6 +247,9 @@ tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn) 1955195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING_INPUT 1956195972f6Sopenharmony_ci err_t ret; 1957195972f6Sopenharmony_ci LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp)); 1958195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMERS 1959195972f6Sopenharmony_ci+ sys_timer_run(); 1960195972f6Sopenharmony_ci+#endif 1961195972f6Sopenharmony_ci LOCK_TCPIP_CORE(); 1962195972f6Sopenharmony_ci ret = input_fn(p, inp); 1963195972f6Sopenharmony_ci UNLOCK_TCPIP_CORE(); 1964195972f6Sopenharmony_ci@@ -321,6 +329,9 @@ tcpip_callback(tcpip_callback_fn function, void *ctx) 1965195972f6Sopenharmony_ci msg->msg.cb.function = function; 1966195972f6Sopenharmony_ci msg->msg.cb.ctx = ctx; 1967195972f6Sopenharmony_ci 1968195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMER 1969195972f6Sopenharmony_ci+ sys_timer_run(); 1970195972f6Sopenharmony_ci+#endif 1971195972f6Sopenharmony_ci sys_mbox_post(&tcpip_mbox, msg); 1972195972f6Sopenharmony_ci return ERR_OK; 1973195972f6Sopenharmony_ci } 1974195972f6Sopenharmony_ci@@ -357,6 +368,9 @@ tcpip_try_callback(tcpip_callback_fn function, void *ctx) 1975195972f6Sopenharmony_ci msg->msg.cb.function = function; 1976195972f6Sopenharmony_ci msg->msg.cb.ctx = ctx; 1977195972f6Sopenharmony_ci 1978195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMER 1979195972f6Sopenharmony_ci+ sys_timer_run(); 1980195972f6Sopenharmony_ci+#endif 1981195972f6Sopenharmony_ci if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) { 1982195972f6Sopenharmony_ci memp_free(MEMP_TCPIP_MSG_API, msg); 1983195972f6Sopenharmony_ci return ERR_MEM; 1984195972f6Sopenharmony_ci@@ -438,6 +452,9 @@ tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem) 1985195972f6Sopenharmony_ci { 1986195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 1987195972f6Sopenharmony_ci LWIP_UNUSED_ARG(sem); 1988195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMERS 1989195972f6Sopenharmony_ci+ sys_timer_run(); 1990195972f6Sopenharmony_ci+#endif 1991195972f6Sopenharmony_ci LOCK_TCPIP_CORE(); 1992195972f6Sopenharmony_ci fn(apimsg); 1993195972f6Sopenharmony_ci UNLOCK_TCPIP_CORE(); 1994195972f6Sopenharmony_ci@@ -475,6 +492,9 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call) 1995195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 1996195972f6Sopenharmony_ci err_t err; 1997195972f6Sopenharmony_ci LOCK_TCPIP_CORE(); 1998195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMERS 1999195972f6Sopenharmony_ci+ sys_timer_run(); 2000195972f6Sopenharmony_ci+#endif 2001195972f6Sopenharmony_ci err = fn(call); 2002195972f6Sopenharmony_ci UNLOCK_TCPIP_CORE(); 2003195972f6Sopenharmony_ci return err; 2004195972f6Sopenharmony_ci@@ -537,6 +557,10 @@ tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx) 2005195972f6Sopenharmony_ci msg->type = TCPIP_MSG_CALLBACK_STATIC; 2006195972f6Sopenharmony_ci msg->msg.cb.function = function; 2007195972f6Sopenharmony_ci msg->msg.cb.ctx = ctx; 2008195972f6Sopenharmony_ci+ 2009195972f6Sopenharmony_ci+#if USE_LIBOS && LWIP_TIMER 2010195972f6Sopenharmony_ci+ sys_timer_run(); 2011195972f6Sopenharmony_ci+#endif 2012195972f6Sopenharmony_ci return (struct tcpip_callback_msg *)msg; 2013195972f6Sopenharmony_ci } 2014195972f6Sopenharmony_ci 2015195972f6Sopenharmony_ci@@ -614,7 +638,9 @@ tcpip_init(tcpip_init_done_fn initfunc, void *arg) 2016195972f6Sopenharmony_ci } 2017195972f6Sopenharmony_ci #endif /* LWIP_TCPIP_CORE_LOCKING */ 2018195972f6Sopenharmony_ci 2019195972f6Sopenharmony_ci+#if !USE_LIBOS 2020195972f6Sopenharmony_ci sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO); 2021195972f6Sopenharmony_ci+#endif 2022195972f6Sopenharmony_ci } 2023195972f6Sopenharmony_ci 2024195972f6Sopenharmony_ci /** 2025195972f6Sopenharmony_cidiff --git a/src/core/dir.mk b/src/core/dir.mk 2026195972f6Sopenharmony_ciindex e5a055b..ebc01a5 100644 2027195972f6Sopenharmony_ci--- a/src/core/dir.mk 2028195972f6Sopenharmony_ci+++ b/src/core/dir.mk 2029195972f6Sopenharmony_ci@@ -1,6 +1,6 @@ 2030195972f6Sopenharmony_ci-SRC = inet_chksum.c init.c ip.c mem.c memp.c netif.c pbuf.c \ 2031195972f6Sopenharmony_ci- raw.c stats.c tcp.c tcp_in.c tcp_out.c timeouts.c udp.c \ 2032195972f6Sopenharmony_ci- ipv4/etharp.c ipv4/icmp.c ipv4/ip4_addr.c ipv4/ip4.c \ 2033195972f6Sopenharmony_ci- ipv4/ip4_frag.c 2034195972f6Sopenharmony_ci+SRC = def.c inet_chksum.c init.c ip.c mem.c memp.c netif.c pbuf.c \ 2035195972f6Sopenharmony_ci+ raw.c tcp.c tcp_in.c tcp_out.c timeouts.c udp.c stats.c\ 2036195972f6Sopenharmony_ci+ ipv4/icmp.c ipv4/ip4_addr.c ipv4/ip4_frag.c ipv4/etharp.c \ 2037195972f6Sopenharmony_ci+ ipv4/ip4.c 2038195972f6Sopenharmony_ci 2039195972f6Sopenharmony_ci $(eval $(call register_dir, core, $(SRC))) 2040195972f6Sopenharmony_cidiff --git a/src/core/init.c b/src/core/init.c 2041195972f6Sopenharmony_ciindex 3620e1d..60e1c68 100644 2042195972f6Sopenharmony_ci--- a/src/core/init.c 2043195972f6Sopenharmony_ci+++ b/src/core/init.c 2044195972f6Sopenharmony_ci@@ -343,9 +343,7 @@ lwip_init(void) 2045195972f6Sopenharmony_ci 2046195972f6Sopenharmony_ci /* Modules initialization */ 2047195972f6Sopenharmony_ci stats_init(); 2048195972f6Sopenharmony_ci-#if !NO_SYS 2049195972f6Sopenharmony_ci- sys_init(); 2050195972f6Sopenharmony_ci-#endif /* !NO_SYS */ 2051195972f6Sopenharmony_ci+ 2052195972f6Sopenharmony_ci mem_init(); 2053195972f6Sopenharmony_ci memp_init(); 2054195972f6Sopenharmony_ci pbuf_init(); 2055195972f6Sopenharmony_cidiff --git a/src/core/ip.c b/src/core/ip.c 2056195972f6Sopenharmony_ciindex 18514cf..0d39d2d 100644 2057195972f6Sopenharmony_ci--- a/src/core/ip.c 2058195972f6Sopenharmony_ci+++ b/src/core/ip.c 2059195972f6Sopenharmony_ci@@ -61,7 +61,7 @@ 2060195972f6Sopenharmony_ci #include "lwip/ip.h" 2061195972f6Sopenharmony_ci 2062195972f6Sopenharmony_ci /** Global data for both IPv4 and IPv6 */ 2063195972f6Sopenharmony_ci-struct ip_globals ip_data; 2064195972f6Sopenharmony_ci+PER_THREAD struct ip_globals ip_data; 2065195972f6Sopenharmony_ci 2066195972f6Sopenharmony_ci #if LWIP_IPV4 && LWIP_IPV6 2067195972f6Sopenharmony_ci 2068195972f6Sopenharmony_cidiff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c 2069195972f6Sopenharmony_ciindex 26c26a9..c83afbe 100644 2070195972f6Sopenharmony_ci--- a/src/core/ipv4/ip4.c 2071195972f6Sopenharmony_ci+++ b/src/core/ipv4/ip4.c 2072195972f6Sopenharmony_ci@@ -282,7 +282,9 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) 2073195972f6Sopenharmony_ci { 2074195972f6Sopenharmony_ci struct netif *netif; 2075195972f6Sopenharmony_ci 2076195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2077195972f6Sopenharmony_ci PERF_START; 2078195972f6Sopenharmony_ci+#endif 2079195972f6Sopenharmony_ci LWIP_UNUSED_ARG(inp); 2080195972f6Sopenharmony_ci 2081195972f6Sopenharmony_ci if (!ip4_canforward(p)) { 2082195972f6Sopenharmony_ci@@ -344,7 +346,9 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) 2083195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.ipforwdatagrams); 2084195972f6Sopenharmony_ci IP_STATS_INC(ip.xmit); 2085195972f6Sopenharmony_ci 2086195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2087195972f6Sopenharmony_ci PERF_STOP("ip4_forward"); 2088195972f6Sopenharmony_ci+#endif 2089195972f6Sopenharmony_ci /* don't fragment if interface has mtu set to 0 [loopif] */ 2090195972f6Sopenharmony_ci if (netif->mtu && (p->tot_len > netif->mtu)) { 2091195972f6Sopenharmony_ci if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) { 2092195972f6Sopenharmony_ci@@ -438,6 +442,8 @@ ip4_input(struct pbuf *p, struct netif *inp) 2093195972f6Sopenharmony_ci 2094195972f6Sopenharmony_ci LWIP_ASSERT_CORE_LOCKED(); 2095195972f6Sopenharmony_ci 2096195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2097195972f6Sopenharmony_ci+ 2098195972f6Sopenharmony_ci IP_STATS_INC(ip.recv); 2099195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.ipinreceives); 2100195972f6Sopenharmony_ci 2101195972f6Sopenharmony_ci@@ -700,13 +706,19 @@ ip4_input(struct pbuf *p, struct netif *inp) 2102195972f6Sopenharmony_ci case IP_PROTO_UDPLITE: 2103195972f6Sopenharmony_ci #endif /* LWIP_UDPLITE */ 2104195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.ipindelivers); 2105195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_IP); 2106195972f6Sopenharmony_ci udp_input(p, inp); 2107195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2108195972f6Sopenharmony_ci break; 2109195972f6Sopenharmony_ci #endif /* LWIP_UDP */ 2110195972f6Sopenharmony_ci #if LWIP_TCP 2111195972f6Sopenharmony_ci case IP_PROTO_TCP: 2112195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.ipindelivers); 2113195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_IP); 2114195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); 2115195972f6Sopenharmony_ci tcp_input(p, inp); 2116195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); 2117195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2118195972f6Sopenharmony_ci break; 2119195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 2120195972f6Sopenharmony_ci #if LWIP_ICMP 2121195972f6Sopenharmony_ci@@ -755,6 +767,8 @@ ip4_input(struct pbuf *p, struct netif *inp) 2122195972f6Sopenharmony_ci ip4_addr_set_any(ip4_current_src_addr()); 2123195972f6Sopenharmony_ci ip4_addr_set_any(ip4_current_dest_addr()); 2124195972f6Sopenharmony_ci 2125195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("ip4_input", PERF_LAYER_IP); 2126195972f6Sopenharmony_ci+ 2127195972f6Sopenharmony_ci return ERR_OK; 2128195972f6Sopenharmony_ci } 2129195972f6Sopenharmony_ci 2130195972f6Sopenharmony_cidiff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c 2131195972f6Sopenharmony_ciindex 060d5f3..9d904ec 100644 2132195972f6Sopenharmony_ci--- a/src/core/ipv6/ip6.c 2133195972f6Sopenharmony_ci+++ b/src/core/ipv6/ip6.c 2134195972f6Sopenharmony_ci@@ -522,6 +522,8 @@ ip6_input(struct pbuf *p, struct netif *inp) 2135195972f6Sopenharmony_ci 2136195972f6Sopenharmony_ci LWIP_ASSERT_CORE_LOCKED(); 2137195972f6Sopenharmony_ci 2138195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2139195972f6Sopenharmony_ci+ 2140195972f6Sopenharmony_ci IP6_STATS_INC(ip6.recv); 2141195972f6Sopenharmony_ci 2142195972f6Sopenharmony_ci /* identify the IP header */ 2143195972f6Sopenharmony_ci@@ -1069,12 +1071,18 @@ options_done: 2144195972f6Sopenharmony_ci #if LWIP_UDPLITE 2145195972f6Sopenharmony_ci case IP6_NEXTH_UDPLITE: 2146195972f6Sopenharmony_ci #endif /* LWIP_UDPLITE */ 2147195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_IP); 2148195972f6Sopenharmony_ci udp_input(p, inp); 2149195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2150195972f6Sopenharmony_ci break; 2151195972f6Sopenharmony_ci #endif /* LWIP_UDP */ 2152195972f6Sopenharmony_ci #if LWIP_TCP 2153195972f6Sopenharmony_ci case IP6_NEXTH_TCP: 2154195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_IP); 2155195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); 2156195972f6Sopenharmony_ci tcp_input(p, inp); 2157195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); 2158195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); 2159195972f6Sopenharmony_ci break; 2160195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 2161195972f6Sopenharmony_ci #if LWIP_ICMP6 2162195972f6Sopenharmony_ci@@ -1115,6 +1123,8 @@ ip6_input_cleanup: 2163195972f6Sopenharmony_ci ip6_addr_set_zero(ip6_current_src_addr()); 2164195972f6Sopenharmony_ci ip6_addr_set_zero(ip6_current_dest_addr()); 2165195972f6Sopenharmony_ci 2166195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("ip6_input", PERF_LAYER_IP); 2167195972f6Sopenharmony_ci+ 2168195972f6Sopenharmony_ci return ERR_OK; 2169195972f6Sopenharmony_ci } 2170195972f6Sopenharmony_ci 2171195972f6Sopenharmony_cidiff --git a/src/core/mem.c b/src/core/mem.c 2172195972f6Sopenharmony_ciindex 315fb3c..84b3fcc 100644 2173195972f6Sopenharmony_ci--- a/src/core/mem.c 2174195972f6Sopenharmony_ci+++ b/src/core/mem.c 2175195972f6Sopenharmony_ci@@ -381,9 +381,9 @@ LWIP_DECLARE_MEMORY_ALIGNED(ram_heap, MEM_SIZE_ALIGNED + (2U * SIZEOF_STRUCT_MEM 2176195972f6Sopenharmony_ci #endif /* LWIP_RAM_HEAP_POINTER */ 2177195972f6Sopenharmony_ci 2178195972f6Sopenharmony_ci /** pointer to the heap (ram_heap): for alignment, ram is now a pointer instead of an array */ 2179195972f6Sopenharmony_ci-static u8_t *ram; 2180195972f6Sopenharmony_ci+static PER_THREAD u8_t *ram; 2181195972f6Sopenharmony_ci /** the last entry, always unused! */ 2182195972f6Sopenharmony_ci-static struct mem *ram_end; 2183195972f6Sopenharmony_ci+static PER_THREAD struct mem *ram_end; 2184195972f6Sopenharmony_ci 2185195972f6Sopenharmony_ci /** concurrent access protection */ 2186195972f6Sopenharmony_ci #if !NO_SYS 2187195972f6Sopenharmony_ci@@ -418,7 +418,7 @@ static volatile u8_t mem_free_count; 2188195972f6Sopenharmony_ci #endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */ 2189195972f6Sopenharmony_ci 2190195972f6Sopenharmony_ci /** pointer to the lowest free block, this is used for faster search */ 2191195972f6Sopenharmony_ci-static struct mem * LWIP_MEM_LFREE_VOLATILE lfree; 2192195972f6Sopenharmony_ci+static PER_THREAD struct mem * LWIP_MEM_LFREE_VOLATILE lfree; 2193195972f6Sopenharmony_ci 2194195972f6Sopenharmony_ci #if MEM_SANITY_CHECK 2195195972f6Sopenharmony_ci static void mem_sanity(void); 2196195972f6Sopenharmony_cidiff --git a/src/core/memp.c b/src/core/memp.c 2197195972f6Sopenharmony_ciindex 352ce5a..454ba32 100644 2198195972f6Sopenharmony_ci--- a/src/core/memp.c 2199195972f6Sopenharmony_ci+++ b/src/core/memp.c 2200195972f6Sopenharmony_ci@@ -78,10 +78,14 @@ 2201195972f6Sopenharmony_ci #define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_DECLARE(name,num,size,desc) 2202195972f6Sopenharmony_ci #include "lwip/priv/memp_std.h" 2203195972f6Sopenharmony_ci 2204195972f6Sopenharmony_ci+#if USE_LIBOS 2205195972f6Sopenharmony_ci+PER_THREAD struct memp_desc* memp_pools[MEMP_MAX] = {NULL}; 2206195972f6Sopenharmony_ci+#else 2207195972f6Sopenharmony_ci const struct memp_desc *const memp_pools[MEMP_MAX] = { 2208195972f6Sopenharmony_ci #define LWIP_MEMPOOL(name,num,size,desc) &memp_ ## name, 2209195972f6Sopenharmony_ci #include "lwip/priv/memp_std.h" 2210195972f6Sopenharmony_ci }; 2211195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 2212195972f6Sopenharmony_ci 2213195972f6Sopenharmony_ci #ifdef LWIP_HOOK_FILENAME 2214195972f6Sopenharmony_ci #include LWIP_HOOK_FILENAME 2215195972f6Sopenharmony_cidiff --git a/src/core/netif.c b/src/core/netif.c 2216195972f6Sopenharmony_ciindex 088b50e..70392cb 100644 2217195972f6Sopenharmony_ci--- a/src/core/netif.c 2218195972f6Sopenharmony_ci+++ b/src/core/netif.c 2219195972f6Sopenharmony_ci@@ -107,12 +107,12 @@ static netif_ext_callback_t *ext_callback; 2220195972f6Sopenharmony_ci #endif 2221195972f6Sopenharmony_ci 2222195972f6Sopenharmony_ci #if !LWIP_SINGLE_NETIF 2223195972f6Sopenharmony_ci-struct netif *netif_list; 2224195972f6Sopenharmony_ci+PER_THREAD struct netif *netif_list; 2225195972f6Sopenharmony_ci #endif /* !LWIP_SINGLE_NETIF */ 2226195972f6Sopenharmony_ci-struct netif *netif_default; 2227195972f6Sopenharmony_ci+PER_THREAD struct netif *netif_default; 2228195972f6Sopenharmony_ci 2229195972f6Sopenharmony_ci #define netif_index_to_num(index) ((index) - 1) 2230195972f6Sopenharmony_ci-static u8_t netif_num; 2231195972f6Sopenharmony_ci+static PER_THREAD u8_t netif_num; 2232195972f6Sopenharmony_ci 2233195972f6Sopenharmony_ci #if LWIP_NUM_NETIF_CLIENT_DATA > 0 2234195972f6Sopenharmony_ci static u8_t netif_client_id; 2235195972f6Sopenharmony_ci@@ -138,7 +138,7 @@ static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const i 2236195972f6Sopenharmony_ci #endif 2237195972f6Sopenharmony_ci 2238195972f6Sopenharmony_ci 2239195972f6Sopenharmony_ci-static struct netif loop_netif; 2240195972f6Sopenharmony_ci+static PER_THREAD struct netif loop_netif; 2241195972f6Sopenharmony_ci 2242195972f6Sopenharmony_ci /** 2243195972f6Sopenharmony_ci * Initialize a lwip network interface structure for a loopback interface 2244195972f6Sopenharmony_cidiff --git a/src/core/pbuf.c b/src/core/pbuf.c 2245195972f6Sopenharmony_ciindex 7638dfd..27afc28 100644 2246195972f6Sopenharmony_ci--- a/src/core/pbuf.c 2247195972f6Sopenharmony_ci+++ b/src/core/pbuf.c 2248195972f6Sopenharmony_ci@@ -737,7 +737,9 @@ pbuf_free(struct pbuf *p) 2249195972f6Sopenharmony_ci } 2250195972f6Sopenharmony_ci LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p)); 2251195972f6Sopenharmony_ci 2252195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2253195972f6Sopenharmony_ci PERF_START; 2254195972f6Sopenharmony_ci+#endif 2255195972f6Sopenharmony_ci 2256195972f6Sopenharmony_ci count = 0; 2257195972f6Sopenharmony_ci /* de-allocate all consecutive pbufs from the head of the chain that 2258195972f6Sopenharmony_ci@@ -794,7 +796,9 @@ pbuf_free(struct pbuf *p) 2259195972f6Sopenharmony_ci p = NULL; 2260195972f6Sopenharmony_ci } 2261195972f6Sopenharmony_ci } 2262195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2263195972f6Sopenharmony_ci PERF_STOP("pbuf_free"); 2264195972f6Sopenharmony_ci+#endif 2265195972f6Sopenharmony_ci /* return number of de-allocated pbufs */ 2266195972f6Sopenharmony_ci return count; 2267195972f6Sopenharmony_ci } 2268195972f6Sopenharmony_cidiff --git a/src/core/stats.c b/src/core/stats.c 2269195972f6Sopenharmony_ciindex 34e9b27..f7e0604 100644 2270195972f6Sopenharmony_ci--- a/src/core/stats.c 2271195972f6Sopenharmony_ci+++ b/src/core/stats.c 2272195972f6Sopenharmony_ci@@ -47,7 +47,7 @@ 2273195972f6Sopenharmony_ci 2274195972f6Sopenharmony_ci #include <string.h> 2275195972f6Sopenharmony_ci 2276195972f6Sopenharmony_ci-struct stats_ lwip_stats; 2277195972f6Sopenharmony_ci+PER_THREAD struct stats_ lwip_stats; 2278195972f6Sopenharmony_ci 2279195972f6Sopenharmony_ci void 2280195972f6Sopenharmony_ci stats_init(void) 2281195972f6Sopenharmony_ci@@ -59,6 +59,17 @@ stats_init(void) 2282195972f6Sopenharmony_ci #endif /* LWIP_DEBUG */ 2283195972f6Sopenharmony_ci } 2284195972f6Sopenharmony_ci 2285195972f6Sopenharmony_ci+int get_mib2_stats(char *buf) 2286195972f6Sopenharmony_ci+{ 2287195972f6Sopenharmony_ci+ int len = 0; 2288195972f6Sopenharmony_ci+#if MIB2_STATS 2289195972f6Sopenharmony_ci+ len = (long)&((struct stats_mib2 *)0)->udpindatagrams; 2290195972f6Sopenharmony_ci+ /* we just need the ip&tcp, others not needed. */ 2291195972f6Sopenharmony_ci+ memcpy(buf, &lwip_stats.mib2, len); 2292195972f6Sopenharmony_ci+#endif 2293195972f6Sopenharmony_ci+ return len; 2294195972f6Sopenharmony_ci+} 2295195972f6Sopenharmony_ci+ 2296195972f6Sopenharmony_ci #if LWIP_STATS_DISPLAY 2297195972f6Sopenharmony_ci void 2298195972f6Sopenharmony_ci stats_display_proto(struct stats_proto *proto, const char *name) 2299195972f6Sopenharmony_cidiff --git a/src/core/tcp.c b/src/core/tcp.c 2300195972f6Sopenharmony_ciindex 371db2b..9e75810 100644 2301195972f6Sopenharmony_ci--- a/src/core/tcp.c 2302195972f6Sopenharmony_ci+++ b/src/core/tcp.c 2303195972f6Sopenharmony_ci@@ -113,6 +113,7 @@ 2304195972f6Sopenharmony_ci #include "lwip/nd6.h" 2305195972f6Sopenharmony_ci 2306195972f6Sopenharmony_ci #include <string.h> 2307195972f6Sopenharmony_ci+#include <pthread.h> 2308195972f6Sopenharmony_ci 2309195972f6Sopenharmony_ci #ifdef LWIP_HOOK_FILENAME 2310195972f6Sopenharmony_ci #include LWIP_HOOK_FILENAME 2311195972f6Sopenharmony_ci@@ -157,36 +158,50 @@ static const char *const tcp_state_str[] = { 2312195972f6Sopenharmony_ci 2313195972f6Sopenharmony_ci /* last local TCP port */ 2314195972f6Sopenharmony_ci static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START; 2315195972f6Sopenharmony_ci+static pthread_mutex_t g_tcp_port_mutex = PTHREAD_MUTEX_INITIALIZER; 2316195972f6Sopenharmony_ci 2317195972f6Sopenharmony_ci /* Incremented every coarse grained timer shot (typically every 500 ms). */ 2318195972f6Sopenharmony_ci-u32_t tcp_ticks; 2319195972f6Sopenharmony_ci-static const u8_t tcp_backoff[13] = 2320195972f6Sopenharmony_ci+PER_THREAD u32_t tcp_ticks; 2321195972f6Sopenharmony_ci+static PER_THREAD const u8_t tcp_backoff[13] = 2322195972f6Sopenharmony_ci { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; 2323195972f6Sopenharmony_ci /* Times per slowtmr hits */ 2324195972f6Sopenharmony_ci-static const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }; 2325195972f6Sopenharmony_ci+static PER_THREAD const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }; 2326195972f6Sopenharmony_ci 2327195972f6Sopenharmony_ci /* The TCP PCB lists. */ 2328195972f6Sopenharmony_ci 2329195972f6Sopenharmony_ci /** List of all TCP PCBs bound but not yet (connected || listening) */ 2330195972f6Sopenharmony_ci-struct tcp_pcb *tcp_bound_pcbs; 2331195972f6Sopenharmony_ci+PER_THREAD struct tcp_pcb *tcp_bound_pcbs; 2332195972f6Sopenharmony_ci /** List of all TCP PCBs in LISTEN state */ 2333195972f6Sopenharmony_ci-union tcp_listen_pcbs_t tcp_listen_pcbs; 2334195972f6Sopenharmony_ci+PER_THREAD union tcp_listen_pcbs_t tcp_listen_pcbs; 2335195972f6Sopenharmony_ci /** List of all TCP PCBs that are in a state in which 2336195972f6Sopenharmony_ci * they accept or send data. */ 2337195972f6Sopenharmony_ci-struct tcp_pcb *tcp_active_pcbs; 2338195972f6Sopenharmony_ci+PER_THREAD struct tcp_pcb *tcp_active_pcbs; 2339195972f6Sopenharmony_ci /** List of all TCP PCBs in TIME-WAIT state */ 2340195972f6Sopenharmony_ci-struct tcp_pcb *tcp_tw_pcbs; 2341195972f6Sopenharmony_ci+PER_THREAD struct tcp_pcb *tcp_tw_pcbs; 2342195972f6Sopenharmony_ci 2343195972f6Sopenharmony_ci /** An array with all (non-temporary) PCB lists, mainly used for smaller code size */ 2344195972f6Sopenharmony_ci-struct tcp_pcb **const tcp_pcb_lists[] = {&tcp_listen_pcbs.pcbs, &tcp_bound_pcbs, 2345195972f6Sopenharmony_ci- &tcp_active_pcbs, &tcp_tw_pcbs 2346195972f6Sopenharmony_ci-}; 2347195972f6Sopenharmony_ci+PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS] = {NULL, NULL, NULL, NULL}; 2348195972f6Sopenharmony_ci+ 2349195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2350195972f6Sopenharmony_ci+#define INIT_TCP_HTABLE(ht_ptr) \ 2351195972f6Sopenharmony_ci+ do { \ 2352195972f6Sopenharmony_ci+ int _i; \ 2353195972f6Sopenharmony_ci+ (ht_ptr)->size = TCP_HTABLE_SIZE; \ 2354195972f6Sopenharmony_ci+ for (_i = 0; _i < TCP_HTABLE_SIZE; ++_i) { \ 2355195972f6Sopenharmony_ci+ if (sys_mutex_new(&(ht_ptr)->array[_i].mutex) != ERR_OK) \ 2356195972f6Sopenharmony_ci+ LWIP_ASSERT("failed to create ht->array[].mutex", 0);\ 2357195972f6Sopenharmony_ci+ INIT_HLIST_HEAD(&(ht_ptr)->array[_i].chain); \ 2358195972f6Sopenharmony_ci+ }\ 2359195972f6Sopenharmony_ci+ } while (0) 2360195972f6Sopenharmony_ci+ 2361195972f6Sopenharmony_ci+PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ 2362195972f6Sopenharmony_ci+#endif 2363195972f6Sopenharmony_ci 2364195972f6Sopenharmony_ci-u8_t tcp_active_pcbs_changed; 2365195972f6Sopenharmony_ci+PER_THREAD u8_t tcp_active_pcbs_changed; 2366195972f6Sopenharmony_ci 2367195972f6Sopenharmony_ci /** Timer counter to handle calling slow-timer from tcp_tmr() */ 2368195972f6Sopenharmony_ci-static u8_t tcp_timer; 2369195972f6Sopenharmony_ci-static u8_t tcp_timer_ctr; 2370195972f6Sopenharmony_ci+static PER_THREAD u8_t tcp_timer; 2371195972f6Sopenharmony_ci+static PER_THREAD u8_t tcp_timer_ctr; 2372195972f6Sopenharmony_ci static u16_t tcp_new_port(void); 2373195972f6Sopenharmony_ci 2374195972f6Sopenharmony_ci static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb); 2375195972f6Sopenharmony_ci@@ -200,9 +215,20 @@ static void tcp_ext_arg_invoke_callbacks_destroyed(struct tcp_pcb_ext_args *ext_ 2376195972f6Sopenharmony_ci void 2377195972f6Sopenharmony_ci tcp_init(void) 2378195972f6Sopenharmony_ci { 2379195972f6Sopenharmony_ci+ tcp_pcb_lists[0] = &tcp_listen_pcbs.pcbs; 2380195972f6Sopenharmony_ci+ tcp_pcb_lists[1] = &tcp_bound_pcbs; 2381195972f6Sopenharmony_ci+ tcp_pcb_lists[2] = &tcp_active_pcbs; 2382195972f6Sopenharmony_ci+ tcp_pcb_lists[3] = &tcp_tw_pcbs; 2383195972f6Sopenharmony_ci+ 2384195972f6Sopenharmony_ci #ifdef LWIP_RAND 2385195972f6Sopenharmony_ci tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND()); 2386195972f6Sopenharmony_ci #endif /* LWIP_RAND */ 2387195972f6Sopenharmony_ci+ 2388195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2389195972f6Sopenharmony_ci+ tcp_active_htable = (struct tcp_hash_table*)mem_malloc(sizeof(struct tcp_hash_table)); 2390195972f6Sopenharmony_ci+ LWIP_ASSERT("malloc tcp_active_htable mem failed.", tcp_active_htable != NULL); 2391195972f6Sopenharmony_ci+ INIT_TCP_HTABLE(tcp_active_htable); 2392195972f6Sopenharmony_ci+#endif 2393195972f6Sopenharmony_ci } 2394195972f6Sopenharmony_ci 2395195972f6Sopenharmony_ci /** Free a tcp pcb */ 2396195972f6Sopenharmony_ci@@ -361,6 +387,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) 2397195972f6Sopenharmony_ci pcb->local_port, pcb->remote_port); 2398195972f6Sopenharmony_ci 2399195972f6Sopenharmony_ci tcp_pcb_purge(pcb); 2400195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2401195972f6Sopenharmony_ci+ TCP_RMV_ACTIVE_HASH(pcb); 2402195972f6Sopenharmony_ci+#endif 2403195972f6Sopenharmony_ci TCP_RMV_ACTIVE(pcb); 2404195972f6Sopenharmony_ci /* Deallocate the pcb since we already sent a RST for it */ 2405195972f6Sopenharmony_ci if (tcp_input_pcb == pcb) { 2406195972f6Sopenharmony_ci@@ -395,6 +424,9 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data) 2407195972f6Sopenharmony_ci tcp_free_listen(pcb); 2408195972f6Sopenharmony_ci break; 2409195972f6Sopenharmony_ci case SYN_SENT: 2410195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2411195972f6Sopenharmony_ci+ TCP_PCB_REMOVE_ACTIVE_HASH(pcb); 2412195972f6Sopenharmony_ci+#endif 2413195972f6Sopenharmony_ci TCP_PCB_REMOVE_ACTIVE(pcb); 2414195972f6Sopenharmony_ci tcp_free(pcb); 2415195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.tcpattemptfails); 2416195972f6Sopenharmony_ci@@ -494,6 +526,7 @@ tcp_close(struct tcp_pcb *pcb) 2417195972f6Sopenharmony_ci /* Set a flag not to receive any more data... */ 2418195972f6Sopenharmony_ci tcp_set_flags(pcb, TF_RXCLOSED); 2419195972f6Sopenharmony_ci } 2420195972f6Sopenharmony_ci+ 2421195972f6Sopenharmony_ci /* ... and close */ 2422195972f6Sopenharmony_ci return tcp_close_shutdown(pcb, 1); 2423195972f6Sopenharmony_ci } 2424195972f6Sopenharmony_ci@@ -599,6 +632,9 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) 2425195972f6Sopenharmony_ci } else { 2426195972f6Sopenharmony_ci send_rst = reset; 2427195972f6Sopenharmony_ci local_port = pcb->local_port; 2428195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2429195972f6Sopenharmony_ci+ TCP_PCB_REMOVE_ACTIVE_HASH(pcb); 2430195972f6Sopenharmony_ci+#endif 2431195972f6Sopenharmony_ci TCP_PCB_REMOVE_ACTIVE(pcb); 2432195972f6Sopenharmony_ci } 2433195972f6Sopenharmony_ci if (pcb->unacked != NULL) { 2434195972f6Sopenharmony_ci@@ -880,6 +916,11 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err) 2435195972f6Sopenharmony_ci } 2436195972f6Sopenharmony_ci } 2437195972f6Sopenharmony_ci #endif /* SO_REUSE */ 2438195972f6Sopenharmony_ci+ 2439195972f6Sopenharmony_ci+#if USE_LIBOS 2440195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_LISTEN, pcb); 2441195972f6Sopenharmony_ci+#endif 2442195972f6Sopenharmony_ci+ 2443195972f6Sopenharmony_ci lpcb = (struct tcp_pcb_listen *)memp_malloc(MEMP_TCP_PCB_LISTEN); 2444195972f6Sopenharmony_ci if (lpcb == NULL) { 2445195972f6Sopenharmony_ci res = ERR_MEM; 2446195972f6Sopenharmony_ci@@ -1015,6 +1056,7 @@ tcp_new_port(void) 2447195972f6Sopenharmony_ci u16_t n = 0; 2448195972f6Sopenharmony_ci struct tcp_pcb *pcb; 2449195972f6Sopenharmony_ci 2450195972f6Sopenharmony_ci+ pthread_mutex_lock(&g_tcp_port_mutex); 2451195972f6Sopenharmony_ci again: 2452195972f6Sopenharmony_ci tcp_port++; 2453195972f6Sopenharmony_ci if (tcp_port == TCP_LOCAL_PORT_RANGE_END) { 2454195972f6Sopenharmony_ci@@ -1032,6 +1074,8 @@ again: 2455195972f6Sopenharmony_ci } 2456195972f6Sopenharmony_ci } 2457195972f6Sopenharmony_ci } 2458195972f6Sopenharmony_ci+ pthread_mutex_unlock(&g_tcp_port_mutex); 2459195972f6Sopenharmony_ci+ 2460195972f6Sopenharmony_ci return tcp_port; 2461195972f6Sopenharmony_ci } 2462195972f6Sopenharmony_ci 2463195972f6Sopenharmony_ci@@ -1142,6 +1186,10 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, 2464195972f6Sopenharmony_ci #endif /* SO_REUSE */ 2465195972f6Sopenharmony_ci } 2466195972f6Sopenharmony_ci 2467195972f6Sopenharmony_ci+#if USE_LIBOS 2468195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_CONNECT, pcb); 2469195972f6Sopenharmony_ci+#endif 2470195972f6Sopenharmony_ci+ 2471195972f6Sopenharmony_ci iss = tcp_next_iss(pcb); 2472195972f6Sopenharmony_ci pcb->rcv_nxt = 0; 2473195972f6Sopenharmony_ci pcb->snd_nxt = iss; 2474195972f6Sopenharmony_ci@@ -1174,6 +1222,9 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, 2475195972f6Sopenharmony_ci if (old_local_port != 0) { 2476195972f6Sopenharmony_ci TCP_RMV(&tcp_bound_pcbs, pcb); 2477195972f6Sopenharmony_ci } 2478195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2479195972f6Sopenharmony_ci+ TCP_REG_ACTIVE_HASH(pcb); 2480195972f6Sopenharmony_ci+#endif 2481195972f6Sopenharmony_ci TCP_REG_ACTIVE(pcb); 2482195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.tcpactiveopens); 2483195972f6Sopenharmony_ci 2484195972f6Sopenharmony_ci@@ -1389,11 +1440,26 @@ tcp_slowtmr_start: 2485195972f6Sopenharmony_ci if (prev != NULL) { 2486195972f6Sopenharmony_ci LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs); 2487195972f6Sopenharmony_ci prev->next = pcb->next; 2488195972f6Sopenharmony_ci+#if USE_LIBOS 2489195972f6Sopenharmony_ci+ if (pcb->next) 2490195972f6Sopenharmony_ci+ pcb->next->prev = prev; 2491195972f6Sopenharmony_ci+ //dont set next NULL, it will be used below 2492195972f6Sopenharmony_ci+ pcb->prev = NULL; 2493195972f6Sopenharmony_ci+#endif 2494195972f6Sopenharmony_ci } else { 2495195972f6Sopenharmony_ci /* This PCB was the first. */ 2496195972f6Sopenharmony_ci LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb); 2497195972f6Sopenharmony_ci tcp_active_pcbs = pcb->next; 2498195972f6Sopenharmony_ci+#if USE_LIBOS 2499195972f6Sopenharmony_ci+ if (pcb->next) 2500195972f6Sopenharmony_ci+ pcb->next->prev = NULL; 2501195972f6Sopenharmony_ci+ //dont set next NULL, it will be used below 2502195972f6Sopenharmony_ci+ pcb->prev = NULL; 2503195972f6Sopenharmony_ci+#endif 2504195972f6Sopenharmony_ci } 2505195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2506195972f6Sopenharmony_ci+ TCP_RMV_ACTIVE_HASH(pcb); 2507195972f6Sopenharmony_ci+#endif 2508195972f6Sopenharmony_ci 2509195972f6Sopenharmony_ci if (pcb_reset) { 2510195972f6Sopenharmony_ci tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip, 2511195972f6Sopenharmony_ci@@ -1404,6 +1470,9 @@ tcp_slowtmr_start: 2512195972f6Sopenharmony_ci last_state = pcb->state; 2513195972f6Sopenharmony_ci pcb2 = pcb; 2514195972f6Sopenharmony_ci pcb = pcb->next; 2515195972f6Sopenharmony_ci+#if USE_LIBOS 2516195972f6Sopenharmony_ci+ pcb2->next = NULL; 2517195972f6Sopenharmony_ci+#endif 2518195972f6Sopenharmony_ci tcp_free(pcb2); 2519195972f6Sopenharmony_ci 2520195972f6Sopenharmony_ci tcp_active_pcbs_changed = 0; 2521195972f6Sopenharmony_ci@@ -1455,13 +1524,28 @@ tcp_slowtmr_start: 2522195972f6Sopenharmony_ci if (prev != NULL) { 2523195972f6Sopenharmony_ci LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs); 2524195972f6Sopenharmony_ci prev->next = pcb->next; 2525195972f6Sopenharmony_ci+#if USE_LIBOS 2526195972f6Sopenharmony_ci+ if (pcb->next) 2527195972f6Sopenharmony_ci+ pcb->next->prev = prev; 2528195972f6Sopenharmony_ci+ //dont set next NULL, it will be used below 2529195972f6Sopenharmony_ci+ pcb->prev = NULL; 2530195972f6Sopenharmony_ci+#endif 2531195972f6Sopenharmony_ci } else { 2532195972f6Sopenharmony_ci /* This PCB was the first. */ 2533195972f6Sopenharmony_ci LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb); 2534195972f6Sopenharmony_ci tcp_tw_pcbs = pcb->next; 2535195972f6Sopenharmony_ci+#if USE_LIBOS 2536195972f6Sopenharmony_ci+ if (pcb->next) 2537195972f6Sopenharmony_ci+ pcb->next->prev = NULL; 2538195972f6Sopenharmony_ci+ //dont set next NULL, it will be used below 2539195972f6Sopenharmony_ci+ pcb->prev = NULL; 2540195972f6Sopenharmony_ci+#endif 2541195972f6Sopenharmony_ci } 2542195972f6Sopenharmony_ci pcb2 = pcb; 2543195972f6Sopenharmony_ci pcb = pcb->next; 2544195972f6Sopenharmony_ci+#if USE_LIBOS 2545195972f6Sopenharmony_ci+ pcb2->next = NULL; 2546195972f6Sopenharmony_ci+#endif 2547195972f6Sopenharmony_ci tcp_free(pcb2); 2548195972f6Sopenharmony_ci } else { 2549195972f6Sopenharmony_ci prev = pcb; 2550195972f6Sopenharmony_ci@@ -2210,6 +2294,14 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb) 2551195972f6Sopenharmony_ci LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane()); 2552195972f6Sopenharmony_ci } 2553195972f6Sopenharmony_ci 2554195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2555195972f6Sopenharmony_ci+void 2556195972f6Sopenharmony_ci+tcp_pcb_remove_hash(struct tcp_hash_table *htb, struct tcp_pcb *pcb) 2557195972f6Sopenharmony_ci+{ 2558195972f6Sopenharmony_ci+ TCP_RMV_HASH(htb, pcb); 2559195972f6Sopenharmony_ci+} 2560195972f6Sopenharmony_ci+#endif /* TCP_PCB_HASH */ 2561195972f6Sopenharmony_ci+ 2562195972f6Sopenharmony_ci /** 2563195972f6Sopenharmony_ci * Calculates a new initial sequence number for new connections. 2564195972f6Sopenharmony_ci * 2565195972f6Sopenharmony_ci@@ -2384,6 +2476,84 @@ tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t 2566195972f6Sopenharmony_ci return ERR_VAL; 2567195972f6Sopenharmony_ci } 2568195972f6Sopenharmony_ci 2569195972f6Sopenharmony_ci+uint32_t tcp_get_conn_num(void) 2570195972f6Sopenharmony_ci+{ 2571195972f6Sopenharmony_ci+ struct tcp_pcb *pcb = NULL; 2572195972f6Sopenharmony_ci+ struct tcp_pcb_listen *pcbl = NULL; 2573195972f6Sopenharmony_ci+ uint32_t conn_num = 0; 2574195972f6Sopenharmony_ci+ 2575195972f6Sopenharmony_ci+ for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { 2576195972f6Sopenharmony_ci+ conn_num++; 2577195972f6Sopenharmony_ci+ } 2578195972f6Sopenharmony_ci+ 2579195972f6Sopenharmony_ci+ for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { 2580195972f6Sopenharmony_ci+ conn_num++; 2581195972f6Sopenharmony_ci+ } 2582195972f6Sopenharmony_ci+ 2583195972f6Sopenharmony_ci+ for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { 2584195972f6Sopenharmony_ci+ conn_num++; 2585195972f6Sopenharmony_ci+ } 2586195972f6Sopenharmony_ci+ 2587195972f6Sopenharmony_ci+ return conn_num; 2588195972f6Sopenharmony_ci+} 2589195972f6Sopenharmony_ci+ 2590195972f6Sopenharmony_ci+void tcp_get_conn(char *buf, int32_t len, uint32_t *conn_num) 2591195972f6Sopenharmony_ci+{ 2592195972f6Sopenharmony_ci+ int tmp_len = 0; 2593195972f6Sopenharmony_ci+ char *tmp_buf = buf; 2594195972f6Sopenharmony_ci+ struct tcp_pcb_dp tdp; 2595195972f6Sopenharmony_ci+ struct tcp_pcb *pcb = NULL; 2596195972f6Sopenharmony_ci+ struct tcp_pcb_listen *pcbl = NULL; 2597195972f6Sopenharmony_ci+ 2598195972f6Sopenharmony_ci+#define COPY_TDP(b, l) \ 2599195972f6Sopenharmony_ci+ do { \ 2600195972f6Sopenharmony_ci+ if (l + sizeof(tdp) <= len) { \ 2601195972f6Sopenharmony_ci+ memcpy(b, &tdp, sizeof(tdp)); \ 2602195972f6Sopenharmony_ci+ b += sizeof(tdp); \ 2603195972f6Sopenharmony_ci+ l += sizeof(tdp); \ 2604195972f6Sopenharmony_ci+ *conn_num += 1; \ 2605195972f6Sopenharmony_ci+ } else \ 2606195972f6Sopenharmony_ci+ return; \ 2607195972f6Sopenharmony_ci+ } while(0); 2608195972f6Sopenharmony_ci+ 2609195972f6Sopenharmony_ci+ *conn_num = 0; 2610195972f6Sopenharmony_ci+ 2611195972f6Sopenharmony_ci+ for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { 2612195972f6Sopenharmony_ci+ tdp.state = ACTIVE_LIST; 2613195972f6Sopenharmony_ci+ tdp.lip = pcb->local_ip.addr; 2614195972f6Sopenharmony_ci+ tdp.rip = pcb->remote_ip.addr; 2615195972f6Sopenharmony_ci+ tdp.l_port = pcb->local_port; 2616195972f6Sopenharmony_ci+ tdp.r_port = pcb->remote_port; 2617195972f6Sopenharmony_ci+ tdp.s_next = pcb->snd_queuelen; 2618195972f6Sopenharmony_ci+ /* lwip not cache rcv buf. Set it to 0. */ 2619195972f6Sopenharmony_ci+ tdp.r_next = 0; 2620195972f6Sopenharmony_ci+ tdp.tcp_sub_state = pcb->state; 2621195972f6Sopenharmony_ci+ COPY_TDP(tmp_buf, tmp_len); 2622195972f6Sopenharmony_ci+ } 2623195972f6Sopenharmony_ci+ 2624195972f6Sopenharmony_ci+ for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { 2625195972f6Sopenharmony_ci+ tdp.state = LISTEN_LIST; 2626195972f6Sopenharmony_ci+ tdp.lip = pcbl->local_ip.addr; 2627195972f6Sopenharmony_ci+ tdp.rip = pcbl->remote_ip.addr; 2628195972f6Sopenharmony_ci+ tdp.l_port = pcbl->local_port; 2629195972f6Sopenharmony_ci+ tdp.tcp_sub_state = pcbl->state; 2630195972f6Sopenharmony_ci+ COPY_TDP(tmp_buf, tmp_len); 2631195972f6Sopenharmony_ci+ } 2632195972f6Sopenharmony_ci+ 2633195972f6Sopenharmony_ci+ for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { 2634195972f6Sopenharmony_ci+ tdp.state = TIME_WAIT_LIST; 2635195972f6Sopenharmony_ci+ tdp.lip = pcb->local_ip.addr; 2636195972f6Sopenharmony_ci+ tdp.rip = pcb->remote_ip.addr; 2637195972f6Sopenharmony_ci+ tdp.l_port = pcb->local_port; 2638195972f6Sopenharmony_ci+ tdp.r_port = pcb->remote_port; 2639195972f6Sopenharmony_ci+ tdp.s_next = pcb->snd_queuelen; 2640195972f6Sopenharmony_ci+ /* lwip not cache rcv buf. Set it to 0. */ 2641195972f6Sopenharmony_ci+ tdp.r_next = 0; 2642195972f6Sopenharmony_ci+ tdp.tcp_sub_state = pcb->state; 2643195972f6Sopenharmony_ci+ COPY_TDP(tmp_buf, tmp_len); 2644195972f6Sopenharmony_ci+ } 2645195972f6Sopenharmony_ci+} 2646195972f6Sopenharmony_ci+ 2647195972f6Sopenharmony_ci #if TCP_QUEUE_OOSEQ 2648195972f6Sopenharmony_ci /* Free all ooseq pbufs (and possibly reset SACK state) */ 2649195972f6Sopenharmony_ci void 2650195972f6Sopenharmony_cidiff --git a/src/core/tcp_in.c b/src/core/tcp_in.c 2651195972f6Sopenharmony_ciindex 2202e38..2b4c160 100644 2652195972f6Sopenharmony_ci--- a/src/core/tcp_in.c 2653195972f6Sopenharmony_ci+++ b/src/core/tcp_in.c 2654195972f6Sopenharmony_ci@@ -71,21 +71,22 @@ 2655195972f6Sopenharmony_ci /* These variables are global to all functions involved in the input 2656195972f6Sopenharmony_ci processing of TCP segments. They are set by the tcp_input() 2657195972f6Sopenharmony_ci function. */ 2658195972f6Sopenharmony_ci-static struct tcp_seg inseg; 2659195972f6Sopenharmony_ci-static struct tcp_hdr *tcphdr; 2660195972f6Sopenharmony_ci-static u16_t tcphdr_optlen; 2661195972f6Sopenharmony_ci-static u16_t tcphdr_opt1len; 2662195972f6Sopenharmony_ci-static u8_t *tcphdr_opt2; 2663195972f6Sopenharmony_ci-static u16_t tcp_optidx; 2664195972f6Sopenharmony_ci-static u32_t seqno, ackno; 2665195972f6Sopenharmony_ci-static tcpwnd_size_t recv_acked; 2666195972f6Sopenharmony_ci-static u16_t tcplen; 2667195972f6Sopenharmony_ci-static u8_t flags; 2668195972f6Sopenharmony_ci- 2669195972f6Sopenharmony_ci-static u8_t recv_flags; 2670195972f6Sopenharmony_ci-static struct pbuf *recv_data; 2671195972f6Sopenharmony_ci- 2672195972f6Sopenharmony_ci-struct tcp_pcb *tcp_input_pcb; 2673195972f6Sopenharmony_ci+static PER_THREAD struct tcp_seg inseg; 2674195972f6Sopenharmony_ci+static PER_THREAD struct tcp_hdr *tcphdr; 2675195972f6Sopenharmony_ci+static PER_THREAD u16_t tcphdr_optlen; 2676195972f6Sopenharmony_ci+static PER_THREAD u16_t tcphdr_opt1len; 2677195972f6Sopenharmony_ci+static PER_THREAD u8_t *tcphdr_opt2; 2678195972f6Sopenharmony_ci+static PER_THREAD u16_t tcp_optidx; 2679195972f6Sopenharmony_ci+static PER_THREAD u32_t seqno; 2680195972f6Sopenharmony_ci+static PER_THREAD u32_t ackno; 2681195972f6Sopenharmony_ci+static PER_THREAD tcpwnd_size_t recv_acked; 2682195972f6Sopenharmony_ci+static PER_THREAD u16_t tcplen; 2683195972f6Sopenharmony_ci+static PER_THREAD u8_t flags; 2684195972f6Sopenharmony_ci+ 2685195972f6Sopenharmony_ci+static PER_THREAD u8_t recv_flags; 2686195972f6Sopenharmony_ci+static PER_THREAD struct pbuf *recv_data; 2687195972f6Sopenharmony_ci+ 2688195972f6Sopenharmony_ci+PER_THREAD struct tcp_pcb *tcp_input_pcb; 2689195972f6Sopenharmony_ci 2690195972f6Sopenharmony_ci /* Forward declarations. */ 2691195972f6Sopenharmony_ci static err_t tcp_process(struct tcp_pcb *pcb); 2692195972f6Sopenharmony_ci@@ -126,11 +127,20 @@ tcp_input(struct pbuf *p, struct netif *inp) 2693195972f6Sopenharmony_ci u8_t hdrlen_bytes; 2694195972f6Sopenharmony_ci err_t err; 2695195972f6Sopenharmony_ci 2696195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2697195972f6Sopenharmony_ci+ u32_t idx; 2698195972f6Sopenharmony_ci+ struct hlist_head *head; 2699195972f6Sopenharmony_ci+ struct hlist_node *node; 2700195972f6Sopenharmony_ci+ pcb = NULL; 2701195972f6Sopenharmony_ci+#endif 2702195972f6Sopenharmony_ci+ 2703195972f6Sopenharmony_ci LWIP_UNUSED_ARG(inp); 2704195972f6Sopenharmony_ci LWIP_ASSERT_CORE_LOCKED(); 2705195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: invalid pbuf", p != NULL); 2706195972f6Sopenharmony_ci 2707195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2708195972f6Sopenharmony_ci PERF_START; 2709195972f6Sopenharmony_ci+#endif 2710195972f6Sopenharmony_ci 2711195972f6Sopenharmony_ci TCP_STATS_INC(tcp.recv); 2712195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.tcpinsegs); 2713195972f6Sopenharmony_ci@@ -247,7 +257,15 @@ tcp_input(struct pbuf *p, struct netif *inp) 2714195972f6Sopenharmony_ci for an active connection. */ 2715195972f6Sopenharmony_ci prev = NULL; 2716195972f6Sopenharmony_ci 2717195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2718195972f6Sopenharmony_ci+ idx = TUPLE4_HASH_FN( ip_current_dest_addr()->addr, tcphdr->dest, 2719195972f6Sopenharmony_ci+ ip_current_src_addr()->addr, tcphdr->src) & 2720195972f6Sopenharmony_ci+ (tcp_active_htable->size - 1); 2721195972f6Sopenharmony_ci+ head = &tcp_active_htable->array[idx].chain; 2722195972f6Sopenharmony_ci+ tcppcb_hlist_for_each(pcb, node, head) { 2723195972f6Sopenharmony_ci+#else 2724195972f6Sopenharmony_ci for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { 2725195972f6Sopenharmony_ci+#endif 2726195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED); 2727195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT); 2728195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN); 2729195972f6Sopenharmony_ci@@ -263,6 +281,7 @@ tcp_input(struct pbuf *p, struct netif *inp) 2730195972f6Sopenharmony_ci pcb->local_port == tcphdr->dest && 2731195972f6Sopenharmony_ci ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()) && 2732195972f6Sopenharmony_ci ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) { 2733195972f6Sopenharmony_ci+#if !TCP_PCB_HASH 2734195972f6Sopenharmony_ci /* Move this PCB to the front of the list so that subsequent 2735195972f6Sopenharmony_ci lookups will be faster (we exploit locality in TCP segment 2736195972f6Sopenharmony_ci arrivals). */ 2737195972f6Sopenharmony_ci@@ -275,9 +294,14 @@ tcp_input(struct pbuf *p, struct netif *inp) 2738195972f6Sopenharmony_ci TCP_STATS_INC(tcp.cachehit); 2739195972f6Sopenharmony_ci } 2740195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: pcb->next != pcb (after cache)", pcb->next != pcb); 2741195972f6Sopenharmony_ci+#endif 2742195972f6Sopenharmony_ci break; 2743195972f6Sopenharmony_ci } 2744195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2745195972f6Sopenharmony_ci+ pcb = NULL; 2746195972f6Sopenharmony_ci+#else 2747195972f6Sopenharmony_ci prev = pcb; 2748195972f6Sopenharmony_ci+#endif 2749195972f6Sopenharmony_ci } 2750195972f6Sopenharmony_ci 2751195972f6Sopenharmony_ci if (pcb == NULL) { 2752195972f6Sopenharmony_ci@@ -363,8 +387,15 @@ tcp_input(struct pbuf *p, struct netif *inp) 2753195972f6Sopenharmony_ci arrivals). */ 2754195972f6Sopenharmony_ci if (prev != NULL) { 2755195972f6Sopenharmony_ci ((struct tcp_pcb_listen *)prev)->next = lpcb->next; 2756195972f6Sopenharmony_ci+#if USE_LIBOS 2757195972f6Sopenharmony_ci+ if (lpcb->next) 2758195972f6Sopenharmony_ci+ lpcb->next->prev = (struct tcp_pcb_listen *)prev; 2759195972f6Sopenharmony_ci+#endif 2760195972f6Sopenharmony_ci /* our successor is the remainder of the listening list */ 2761195972f6Sopenharmony_ci lpcb->next = tcp_listen_pcbs.listen_pcbs; 2762195972f6Sopenharmony_ci+#if USE_LIBOS 2763195972f6Sopenharmony_ci+ lpcb->prev = NULL; 2764195972f6Sopenharmony_ci+#endif 2765195972f6Sopenharmony_ci /* put this listening pcb at the head of the listening list */ 2766195972f6Sopenharmony_ci tcp_listen_pcbs.listen_pcbs = lpcb; 2767195972f6Sopenharmony_ci } else { 2768195972f6Sopenharmony_ci@@ -445,6 +476,9 @@ tcp_input(struct pbuf *p, struct netif *inp) 2769195972f6Sopenharmony_ci application that the connection is dead before we 2770195972f6Sopenharmony_ci deallocate the PCB. */ 2771195972f6Sopenharmony_ci TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_RST); 2772195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2773195972f6Sopenharmony_ci+ tcp_pcb_remove_hash(tcp_active_htable, pcb); 2774195972f6Sopenharmony_ci+#endif 2775195972f6Sopenharmony_ci tcp_pcb_remove(&tcp_active_pcbs, pcb); 2776195972f6Sopenharmony_ci tcp_free(pcb); 2777195972f6Sopenharmony_ci } else { 2778195972f6Sopenharmony_ci@@ -550,7 +584,19 @@ tcp_input(struct pbuf *p, struct netif *inp) 2779195972f6Sopenharmony_ci goto aborted; 2780195972f6Sopenharmony_ci } 2781195972f6Sopenharmony_ci /* Try to send something out. */ 2782195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 2783195972f6Sopenharmony_ci+ if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV)) { 2784195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_TCP); 2785195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND); 2786195972f6Sopenharmony_ci+ } 2787195972f6Sopenharmony_ci+#endif 2788195972f6Sopenharmony_ci tcp_output(pcb); 2789195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 2790195972f6Sopenharmony_ci+ if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND)) { 2791195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("tcp_in", PERF_LAYER_TCP); 2792195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); 2793195972f6Sopenharmony_ci+ } 2794195972f6Sopenharmony_ci+#endif 2795195972f6Sopenharmony_ci #if TCP_INPUT_DEBUG 2796195972f6Sopenharmony_ci #if TCP_DEBUG 2797195972f6Sopenharmony_ci tcp_debug_print_state(pcb->state); 2798195972f6Sopenharmony_ci@@ -583,7 +629,9 @@ aborted: 2799195972f6Sopenharmony_ci } 2800195972f6Sopenharmony_ci 2801195972f6Sopenharmony_ci LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane()); 2802195972f6Sopenharmony_ci+#ifndef LWIP_PERF 2803195972f6Sopenharmony_ci PERF_STOP("tcp_input"); 2804195972f6Sopenharmony_ci+#endif 2805195972f6Sopenharmony_ci return; 2806195972f6Sopenharmony_ci dropped: 2807195972f6Sopenharmony_ci TCP_STATS_INC(tcp.drop); 2808195972f6Sopenharmony_ci@@ -610,6 +658,9 @@ tcp_input_delayed_close(struct tcp_pcb *pcb) 2809195972f6Sopenharmony_ci ensure the application doesn't continue using the PCB. */ 2810195972f6Sopenharmony_ci TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_CLSD); 2811195972f6Sopenharmony_ci } 2812195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2813195972f6Sopenharmony_ci+ tcp_pcb_remove_hash(tcp_active_htable, pcb); 2814195972f6Sopenharmony_ci+#endif 2815195972f6Sopenharmony_ci tcp_pcb_remove(&tcp_active_pcbs, pcb); 2816195972f6Sopenharmony_ci tcp_free(pcb); 2817195972f6Sopenharmony_ci return 1; 2818195972f6Sopenharmony_ci@@ -649,6 +700,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 2819195972f6Sopenharmony_ci tcp_rst((const struct tcp_pcb *)pcb, ackno, seqno + tcplen, ip_current_dest_addr(), 2820195972f6Sopenharmony_ci ip_current_src_addr(), tcphdr->dest, tcphdr->src); 2821195972f6Sopenharmony_ci } else if (flags & TCP_SYN) { 2822195972f6Sopenharmony_ci+ PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); 2823195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest)); 2824195972f6Sopenharmony_ci #if TCP_LISTEN_BACKLOG 2825195972f6Sopenharmony_ci if (pcb->accepts_pending >= pcb->backlog) { 2826195972f6Sopenharmony_ci@@ -695,6 +747,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 2827195972f6Sopenharmony_ci npcb->netif_idx = pcb->netif_idx; 2828195972f6Sopenharmony_ci /* Register the new PCB so that we can begin receiving segments 2829195972f6Sopenharmony_ci for it. */ 2830195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2831195972f6Sopenharmony_ci+ TCP_REG_ACTIVE_HASH(npcb); 2832195972f6Sopenharmony_ci+#endif 2833195972f6Sopenharmony_ci TCP_REG_ACTIVE(npcb); 2834195972f6Sopenharmony_ci 2835195972f6Sopenharmony_ci /* Parse any options in the SYN. */ 2836195972f6Sopenharmony_ci@@ -715,13 +770,18 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) 2837195972f6Sopenharmony_ci } 2838195972f6Sopenharmony_ci #endif 2839195972f6Sopenharmony_ci 2840195972f6Sopenharmony_ci+ PERF_PAUSE(PERF_LAYER_TCP); 2841195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_SEND); 2842195972f6Sopenharmony_ci /* Send a SYN|ACK together with the MSS option. */ 2843195972f6Sopenharmony_ci rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK); 2844195972f6Sopenharmony_ci if (rc != ERR_OK) { 2845195972f6Sopenharmony_ci tcp_abandon(npcb, 0); 2846195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); 2847195972f6Sopenharmony_ci return; 2848195972f6Sopenharmony_ci } 2849195972f6Sopenharmony_ci tcp_output(npcb); 2850195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("tcp_output", PERF_LAYER_TCP); 2851195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); 2852195972f6Sopenharmony_ci } 2853195972f6Sopenharmony_ci return; 2854195972f6Sopenharmony_ci } 2855195972f6Sopenharmony_ci@@ -858,6 +918,7 @@ tcp_process(struct tcp_pcb *pcb) 2856195972f6Sopenharmony_ci /* received SYN ACK with expected sequence number? */ 2857195972f6Sopenharmony_ci if ((flags & TCP_ACK) && (flags & TCP_SYN) 2858195972f6Sopenharmony_ci && (ackno == pcb->lastack + 1)) { 2859195972f6Sopenharmony_ci+ PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); 2860195972f6Sopenharmony_ci pcb->rcv_nxt = seqno + 1; 2861195972f6Sopenharmony_ci pcb->rcv_ann_right_edge = pcb->rcv_nxt; 2862195972f6Sopenharmony_ci pcb->lastack = ackno; 2863195972f6Sopenharmony_ci@@ -925,6 +986,7 @@ tcp_process(struct tcp_pcb *pcb) 2864195972f6Sopenharmony_ci /* expected ACK number? */ 2865195972f6Sopenharmony_ci if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { 2866195972f6Sopenharmony_ci pcb->state = ESTABLISHED; 2867195972f6Sopenharmony_ci+ PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_RECV); 2868195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); 2869195972f6Sopenharmony_ci #if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG 2870195972f6Sopenharmony_ci if (pcb->listener == NULL) { 2871195972f6Sopenharmony_ci@@ -995,6 +1057,9 @@ tcp_process(struct tcp_pcb *pcb) 2872195972f6Sopenharmony_ci ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); 2873195972f6Sopenharmony_ci tcp_ack_now(pcb); 2874195972f6Sopenharmony_ci tcp_pcb_purge(pcb); 2875195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2876195972f6Sopenharmony_ci+ TCP_RMV_ACTIVE_HASH(pcb); 2877195972f6Sopenharmony_ci+#endif 2878195972f6Sopenharmony_ci TCP_RMV_ACTIVE(pcb); 2879195972f6Sopenharmony_ci pcb->state = TIME_WAIT; 2880195972f6Sopenharmony_ci TCP_REG(&tcp_tw_pcbs, pcb); 2881195972f6Sopenharmony_ci@@ -1013,6 +1078,9 @@ tcp_process(struct tcp_pcb *pcb) 2882195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_2 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); 2883195972f6Sopenharmony_ci tcp_ack_now(pcb); 2884195972f6Sopenharmony_ci tcp_pcb_purge(pcb); 2885195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2886195972f6Sopenharmony_ci+ TCP_RMV_ACTIVE_HASH(pcb); 2887195972f6Sopenharmony_ci+#endif 2888195972f6Sopenharmony_ci TCP_RMV_ACTIVE(pcb); 2889195972f6Sopenharmony_ci pcb->state = TIME_WAIT; 2890195972f6Sopenharmony_ci TCP_REG(&tcp_tw_pcbs, pcb); 2891195972f6Sopenharmony_ci@@ -1023,6 +1091,9 @@ tcp_process(struct tcp_pcb *pcb) 2892195972f6Sopenharmony_ci if ((flags & TCP_ACK) && ackno == pcb->snd_nxt && pcb->unsent == NULL) { 2893195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); 2894195972f6Sopenharmony_ci tcp_pcb_purge(pcb); 2895195972f6Sopenharmony_ci+#if TCP_PCB_HASH 2896195972f6Sopenharmony_ci+ TCP_RMV_ACTIVE_HASH(pcb); 2897195972f6Sopenharmony_ci+#endif 2898195972f6Sopenharmony_ci TCP_RMV_ACTIVE(pcb); 2899195972f6Sopenharmony_ci pcb->state = TIME_WAIT; 2900195972f6Sopenharmony_ci TCP_REG(&tcp_tw_pcbs, pcb); 2901195972f6Sopenharmony_cidiff --git a/src/core/tcp_out.c b/src/core/tcp_out.c 2902195972f6Sopenharmony_ciindex 8149d39..dac498e 100644 2903195972f6Sopenharmony_ci--- a/src/core/tcp_out.c 2904195972f6Sopenharmony_ci+++ b/src/core/tcp_out.c 2905195972f6Sopenharmony_ci@@ -271,7 +271,7 @@ tcp_pbuf_prealloc(pbuf_layer layer, u16_t length, u16_t max_length, 2906195972f6Sopenharmony_ci return p; 2907195972f6Sopenharmony_ci } 2908195972f6Sopenharmony_ci #else /* TCP_OVERSIZE */ 2909195972f6Sopenharmony_ci-#define tcp_pbuf_prealloc(layer, length, mx, os, pcb, api, fst) pbuf_alloc((layer), (length), PBUF_RAM) 2910195972f6Sopenharmony_ci+#define tcp_pbuf_prealloc(layer, length, mx, os, pcb, api, fst) pbuf_alloc((layer), (length), PBUF_POOL) 2911195972f6Sopenharmony_ci #endif /* TCP_OVERSIZE */ 2912195972f6Sopenharmony_ci 2913195972f6Sopenharmony_ci #if TCP_CHECKSUM_ON_COPY 2914195972f6Sopenharmony_ci@@ -640,7 +640,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) 2915195972f6Sopenharmony_ci ((struct pbuf_rom *)p2)->payload = (const u8_t *)arg + pos; 2916195972f6Sopenharmony_ci 2917195972f6Sopenharmony_ci /* Second, allocate a pbuf for the headers. */ 2918195972f6Sopenharmony_ci- if ((p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) { 2919195972f6Sopenharmony_ci+ if ((p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_POOL)) == NULL) { 2920195972f6Sopenharmony_ci /* If allocation fails, we have to deallocate the data pbuf as 2921195972f6Sopenharmony_ci * well. */ 2922195972f6Sopenharmony_ci pbuf_free(p2); 2923195972f6Sopenharmony_ci@@ -1458,6 +1458,11 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif 2924195972f6Sopenharmony_ci err_t err; 2925195972f6Sopenharmony_ci u16_t len; 2926195972f6Sopenharmony_ci u32_t *opts; 2927195972f6Sopenharmony_ci+ 2928195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 2929195972f6Sopenharmony_ci+ int tmpPoint; 2930195972f6Sopenharmony_ci+#endif 2931195972f6Sopenharmony_ci+ 2932195972f6Sopenharmony_ci #if TCP_CHECKSUM_ON_COPY 2933195972f6Sopenharmony_ci int seg_chksum_was_swapped = 0; 2934195972f6Sopenharmony_ci #endif 2935195972f6Sopenharmony_ci@@ -1604,6 +1609,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif 2936195972f6Sopenharmony_ci #endif /* CHECKSUM_GEN_TCP */ 2937195972f6Sopenharmony_ci TCP_STATS_INC(tcp.xmit); 2938195972f6Sopenharmony_ci 2939195972f6Sopenharmony_ci+ PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); 2940195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); 2941195972f6Sopenharmony_ci+ 2942195972f6Sopenharmony_ci NETIF_SET_HINTS(netif, &(pcb->netif_hints)); 2943195972f6Sopenharmony_ci err = ip_output_if(seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 2944195972f6Sopenharmony_ci pcb->tos, IP_PROTO_TCP, netif); 2945195972f6Sopenharmony_ci@@ -1618,6 +1626,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif 2946195972f6Sopenharmony_ci } 2947195972f6Sopenharmony_ci #endif 2948195972f6Sopenharmony_ci 2949195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); 2950195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_TCP, tmpPoint); 2951195972f6Sopenharmony_ci+ 2952195972f6Sopenharmony_ci return err; 2953195972f6Sopenharmony_ci } 2954195972f6Sopenharmony_ci 2955195972f6Sopenharmony_ci@@ -2024,6 +2035,10 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) 2956195972f6Sopenharmony_ci u8_t optlen, optflags = 0; 2957195972f6Sopenharmony_ci u8_t num_sacks = 0; 2958195972f6Sopenharmony_ci 2959195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 2960195972f6Sopenharmony_ci+ int tmpPoint; 2961195972f6Sopenharmony_ci+#endif 2962195972f6Sopenharmony_ci+ 2963195972f6Sopenharmony_ci LWIP_ASSERT("tcp_send_empty_ack: invalid pcb", pcb != NULL); 2964195972f6Sopenharmony_ci 2965195972f6Sopenharmony_ci #if LWIP_TCP_TIMESTAMPS 2966195972f6Sopenharmony_ci@@ -2040,6 +2055,9 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) 2967195972f6Sopenharmony_ci } 2968195972f6Sopenharmony_ci #endif 2969195972f6Sopenharmony_ci 2970195972f6Sopenharmony_ci+ PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); 2971195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); 2972195972f6Sopenharmony_ci+ 2973195972f6Sopenharmony_ci p = tcp_output_alloc_header(pcb, optlen, 0, lwip_htonl(pcb->snd_nxt)); 2974195972f6Sopenharmony_ci if (p == NULL) { 2975195972f6Sopenharmony_ci /* let tcp_fasttmr retry sending this ACK */ 2976195972f6Sopenharmony_ci@@ -2064,6 +2082,9 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) 2977195972f6Sopenharmony_ci tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW); 2978195972f6Sopenharmony_ci } 2979195972f6Sopenharmony_ci 2980195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); 2981195972f6Sopenharmony_ci+ PERF_RESUME(PERF_LAYER_TCP, tmpPoint); 2982195972f6Sopenharmony_ci+ 2983195972f6Sopenharmony_ci return err; 2984195972f6Sopenharmony_ci } 2985195972f6Sopenharmony_ci 2986195972f6Sopenharmony_cidiff --git a/src/core/timeouts.c b/src/core/timeouts.c 2987195972f6Sopenharmony_ciindex f37acfe..0542a32 100644 2988195972f6Sopenharmony_ci--- a/src/core/timeouts.c 2989195972f6Sopenharmony_ci+++ b/src/core/timeouts.c 2990195972f6Sopenharmony_ci@@ -119,9 +119,9 @@ const int lwip_num_cyclic_timers = LWIP_ARRAYSIZE(lwip_cyclic_timers); 2991195972f6Sopenharmony_ci #if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM 2992195972f6Sopenharmony_ci 2993195972f6Sopenharmony_ci /** The one and only timeout list */ 2994195972f6Sopenharmony_ci-static struct sys_timeo *next_timeout; 2995195972f6Sopenharmony_ci+static PER_THREAD struct sys_timeo *next_timeout; 2996195972f6Sopenharmony_ci 2997195972f6Sopenharmony_ci-static u32_t current_timeout_due_time; 2998195972f6Sopenharmony_ci+static PER_THREAD u32_t current_timeout_due_time; 2999195972f6Sopenharmony_ci 3000195972f6Sopenharmony_ci #if LWIP_TESTMODE 3001195972f6Sopenharmony_ci struct sys_timeo** 3002195972f6Sopenharmony_ci@@ -133,7 +133,7 @@ sys_timeouts_get_next_timeout(void) 3003195972f6Sopenharmony_ci 3004195972f6Sopenharmony_ci #if LWIP_TCP 3005195972f6Sopenharmony_ci /** global variable that shows if the tcp timer is currently scheduled or not */ 3006195972f6Sopenharmony_ci-static int tcpip_tcp_timer_active; 3007195972f6Sopenharmony_ci+static PER_THREAD int tcpip_tcp_timer_active; 3008195972f6Sopenharmony_ci 3009195972f6Sopenharmony_ci /** 3010195972f6Sopenharmony_ci * Timer callback function that calls tcp_tmr() and reschedules itself. 3011195972f6Sopenharmony_ci@@ -442,6 +442,18 @@ sys_timeouts_sleeptime(void) 3012195972f6Sopenharmony_ci } 3013195972f6Sopenharmony_ci } 3014195972f6Sopenharmony_ci 3015195972f6Sopenharmony_ci+#if USE_LIBOS 3016195972f6Sopenharmony_ci+void sys_timer_run(void) 3017195972f6Sopenharmony_ci+{ 3018195972f6Sopenharmony_ci+ u32_t sleeptime; 3019195972f6Sopenharmony_ci+ 3020195972f6Sopenharmony_ci+ sleeptime = sys_timeouts_sleeptime(); 3021195972f6Sopenharmony_ci+ if (sleeptime == 0) { 3022195972f6Sopenharmony_ci+ sys_check_timeouts(); 3023195972f6Sopenharmony_ci+ } 3024195972f6Sopenharmony_ci+} 3025195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 3026195972f6Sopenharmony_ci+ 3027195972f6Sopenharmony_ci #else /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */ 3028195972f6Sopenharmony_ci /* Satisfy the TCP code which calls this function */ 3029195972f6Sopenharmony_ci void 3030195972f6Sopenharmony_cidiff --git a/src/core/udp.c b/src/core/udp.c 3031195972f6Sopenharmony_ciindex 0b609d3..a5f76b9 100644 3032195972f6Sopenharmony_ci--- a/src/core/udp.c 3033195972f6Sopenharmony_ci+++ b/src/core/udp.c 3034195972f6Sopenharmony_ci@@ -207,7 +207,11 @@ udp_input(struct pbuf *p, struct netif *inp) 3035195972f6Sopenharmony_ci LWIP_ASSERT("udp_input: invalid pbuf", p != NULL); 3036195972f6Sopenharmony_ci LWIP_ASSERT("udp_input: invalid netif", inp != NULL); 3037195972f6Sopenharmony_ci 3038195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 3039195972f6Sopenharmony_ci+ PERF_START(PERF_LAYER_UDP, PERF_POINT_UDP); 3040195972f6Sopenharmony_ci+#else 3041195972f6Sopenharmony_ci PERF_START; 3042195972f6Sopenharmony_ci+#endif 3043195972f6Sopenharmony_ci 3044195972f6Sopenharmony_ci UDP_STATS_INC(udp.recv); 3045195972f6Sopenharmony_ci 3046195972f6Sopenharmony_ci@@ -428,7 +432,12 @@ udp_input(struct pbuf *p, struct netif *inp) 3047195972f6Sopenharmony_ci pbuf_free(p); 3048195972f6Sopenharmony_ci } 3049195972f6Sopenharmony_ci end: 3050195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 3051195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); 3052195972f6Sopenharmony_ci+#else 3053195972f6Sopenharmony_ci PERF_STOP("udp_input"); 3054195972f6Sopenharmony_ci+#endif 3055195972f6Sopenharmony_ci+ 3056195972f6Sopenharmony_ci return; 3057195972f6Sopenharmony_ci #if CHECKSUM_CHECK_UDP 3058195972f6Sopenharmony_ci chkerr: 3059195972f6Sopenharmony_ci@@ -438,7 +447,13 @@ chkerr: 3060195972f6Sopenharmony_ci UDP_STATS_INC(udp.drop); 3061195972f6Sopenharmony_ci MIB2_STATS_INC(mib2.udpinerrors); 3062195972f6Sopenharmony_ci pbuf_free(p); 3063195972f6Sopenharmony_ci+ 3064195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 3065195972f6Sopenharmony_ci+ PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); 3066195972f6Sopenharmony_ci+#else 3067195972f6Sopenharmony_ci PERF_STOP("udp_input"); 3068195972f6Sopenharmony_ci+#endif 3069195972f6Sopenharmony_ci+ 3070195972f6Sopenharmony_ci #endif /* CHECKSUM_CHECK_UDP */ 3071195972f6Sopenharmony_ci } 3072195972f6Sopenharmony_ci 3073195972f6Sopenharmony_cidiff --git a/src/include/arch/cc.h b/src/include/arch/cc.h 3074195972f6Sopenharmony_ciindex 52b76f9..33c24b4 100644 3075195972f6Sopenharmony_ci--- a/src/include/arch/cc.h 3076195972f6Sopenharmony_ci+++ b/src/include/arch/cc.h 3077195972f6Sopenharmony_ci@@ -1,7 +1,81 @@ 3078195972f6Sopenharmony_ci-#ifndef LWIP_CC_H 3079195972f6Sopenharmony_ci-#define LWIP_CC_H 3080195972f6Sopenharmony_ci+/* 3081195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3082195972f6Sopenharmony_ci+ * All rights reserved. 3083195972f6Sopenharmony_ci+ * 3084195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3085195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3086195972f6Sopenharmony_ci+ * 3087195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3088195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3089195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3090195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3091195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3092195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3093195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3094195972f6Sopenharmony_ci+ * 3095195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3096195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3097195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3098195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3099195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3100195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3101195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3102195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3103195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3104195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3105195972f6Sopenharmony_ci+ * 3106195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3107195972f6Sopenharmony_ci+ * 3108195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3109195972f6Sopenharmony_ci+ * 3110195972f6Sopenharmony_ci+ */ 3111195972f6Sopenharmony_ci 3112195972f6Sopenharmony_ci+#ifndef LWIP_ARCH_CC_H 3113195972f6Sopenharmony_ci+#define LWIP_ARCH_CC_H 3114195972f6Sopenharmony_ci 3115195972f6Sopenharmony_ci+#include <stdint.h> 3116195972f6Sopenharmony_ci+#include <stdlib.h> 3117195972f6Sopenharmony_ci+#include <sys/time.h> 3118195972f6Sopenharmony_ci+#include <sys/types.h> 3119195972f6Sopenharmony_ci 3120195972f6Sopenharmony_ci-#endif /* LWIP_CC_H */ 3121195972f6Sopenharmony_ci+#include "lwiplog.h" 3122195972f6Sopenharmony_ci 3123195972f6Sopenharmony_ci+#define LWIP_NOASSERT 3124195972f6Sopenharmony_ci+ 3125195972f6Sopenharmony_ci+#define LWIP_ERRNO_STDINCLUDE 1 3126195972f6Sopenharmony_ci+#define MEMP_MEMORY_BASE_PLACEHOLDER 0 3127195972f6Sopenharmony_ci+#define MEMZONE_NAMESIZE 32 3128195972f6Sopenharmony_ci+ 3129195972f6Sopenharmony_ci+#define LWIP_RAND() ((uint32_t)rand()) 3130195972f6Sopenharmony_ci+ 3131195972f6Sopenharmony_ci+extern uint8_t *sys_hugepage_malloc(const char *name, uint32_t size); 3132195972f6Sopenharmony_ci+ 3133195972f6Sopenharmony_ci+#define LWIP_DECLARE_MEMP_BASE_ALIGNED(name, __size)\ 3134195972f6Sopenharmony_ci+PER_THREAD uint8_t *memp_memory_##name##_base; \ 3135195972f6Sopenharmony_ci+void alloc_memp_##name##_base(void) \ 3136195972f6Sopenharmony_ci+{ \ 3137195972f6Sopenharmony_ci+ memp_ ## name.desc = memp_desc_ ## name; \ 3138195972f6Sopenharmony_ci+ memp_ ## name.stats = &memp_stat ## name; \ 3139195972f6Sopenharmony_ci+ memp_ ## name.size = memp_size ## name; \ 3140195972f6Sopenharmony_ci+ memp_ ## name.num = memp_num ## name; \ 3141195972f6Sopenharmony_ci+ memp_ ## name.tab = &memp_tab_ ## name; \ 3142195972f6Sopenharmony_ci+ memp_pools[MEMP_##name] = &memp_ ## name; \ 3143195972f6Sopenharmony_ci+ \ 3144195972f6Sopenharmony_ci+ char mpname[MEMZONE_NAMESIZE] = {0}; \ 3145195972f6Sopenharmony_ci+ snprintf(mpname, MEMZONE_NAMESIZE, "%ld_%s", gettid(), #name); \ 3146195972f6Sopenharmony_ci+ memp_memory_##name##_base = \ 3147195972f6Sopenharmony_ci+ sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(__size)); \ 3148195972f6Sopenharmony_ci+ memp_pools[MEMP_##name]->base = memp_memory_##name##_base; \ 3149195972f6Sopenharmony_ci+} 3150195972f6Sopenharmony_ci+ 3151195972f6Sopenharmony_ci+#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \ 3152195972f6Sopenharmony_ci+PER_THREAD uint8_t *variable_name; \ 3153195972f6Sopenharmony_ci+void alloc_memory_##variable_name(void) \ 3154195972f6Sopenharmony_ci+{ \ 3155195972f6Sopenharmony_ci+ char mpname[MEMZONE_NAMESIZE] = {0}; \ 3156195972f6Sopenharmony_ci+ snprintf(mpname, MEMZONE_NAMESIZE, "%ld_%s", gettid(), #variable_name); \ 3157195972f6Sopenharmony_ci+ (variable_name) = \ 3158195972f6Sopenharmony_ci+ sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(size)); \ 3159195972f6Sopenharmony_ci+} 3160195972f6Sopenharmony_ci+ 3161195972f6Sopenharmony_ci+#endif /* LWIP_ARCH_CC_H */ 3162195972f6Sopenharmony_cidiff --git a/src/include/arch/perf.h b/src/include/arch/perf.h 3163195972f6Sopenharmony_cinew file mode 100644 3164195972f6Sopenharmony_ciindex 0000000..e505da7 3165195972f6Sopenharmony_ci--- /dev/null 3166195972f6Sopenharmony_ci+++ b/src/include/arch/perf.h 3167195972f6Sopenharmony_ci@@ -0,0 +1,155 @@ 3168195972f6Sopenharmony_ci+/* 3169195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3170195972f6Sopenharmony_ci+ * All rights reserved. 3171195972f6Sopenharmony_ci+ * 3172195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3173195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3174195972f6Sopenharmony_ci+ * 3175195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3176195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3177195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3178195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3179195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3180195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3181195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3182195972f6Sopenharmony_ci+ * 3183195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3184195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3185195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3186195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3187195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3188195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3189195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3190195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3191195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3192195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3193195972f6Sopenharmony_ci+ * 3194195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3195195972f6Sopenharmony_ci+ * 3196195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3197195972f6Sopenharmony_ci+ * 3198195972f6Sopenharmony_ci+ */ 3199195972f6Sopenharmony_ci+ 3200195972f6Sopenharmony_ci+#ifndef LWIP_ARCH_PERF_H 3201195972f6Sopenharmony_ci+#define LWIP_ARCH_PERF_H 3202195972f6Sopenharmony_ci+ 3203195972f6Sopenharmony_ci+#include <time.h> 3204195972f6Sopenharmony_ci+ 3205195972f6Sopenharmony_ci+#include "lwip/debug.h" 3206195972f6Sopenharmony_ci+ 3207195972f6Sopenharmony_ci+#if LWIP_RECORD_PERF 3208195972f6Sopenharmony_ci+enum PERF_POINT { 3209195972f6Sopenharmony_ci+ PERF_POINT_IP_RECV, 3210195972f6Sopenharmony_ci+ PERF_POINT_TCP_RECV, 3211195972f6Sopenharmony_ci+ PERF_POINT_UDP, 3212195972f6Sopenharmony_ci+ PERF_POINT_TCP_SYN_RECV, 3213195972f6Sopenharmony_ci+ PERF_POINT_TCP_SYN_ACK_SEND, 3214195972f6Sopenharmony_ci+ PERF_POINT_TCP_ACK_RECV, 3215195972f6Sopenharmony_ci+ PERF_POINT_TCP_SYN_SEND, 3216195972f6Sopenharmony_ci+ PERF_POINT_TCP_SYN_ACK_RECV, 3217195972f6Sopenharmony_ci+ PERF_POINT_TCP_ACK_SEND, 3218195972f6Sopenharmony_ci+ PERF_POINT_TCP_DATA_SEND, 3219195972f6Sopenharmony_ci+ PERF_POINT_IP_SEND, 3220195972f6Sopenharmony_ci+ PERF_POINT_END 3221195972f6Sopenharmony_ci+}; 3222195972f6Sopenharmony_ci+ 3223195972f6Sopenharmony_ci+enum PERF_LAYER { 3224195972f6Sopenharmony_ci+ PERF_LAYER_IP, 3225195972f6Sopenharmony_ci+ PERF_LAYER_TCP, 3226195972f6Sopenharmony_ci+ PERF_LAYER_UDP, 3227195972f6Sopenharmony_ci+ PERF_LAYER_END 3228195972f6Sopenharmony_ci+}; 3229195972f6Sopenharmony_ci+ 3230195972f6Sopenharmony_ci+extern uint32_t g_record_perf; 3231195972f6Sopenharmony_ci+ 3232195972f6Sopenharmony_ci+extern __thread uint64_t g_timeTaken[PERF_POINT_END]; 3233195972f6Sopenharmony_ci+extern __thread int g_perfPoint[PERF_LAYER_END]; 3234195972f6Sopenharmony_ci+extern __thread struct timespec tvStart[PERF_LAYER_END]; 3235195972f6Sopenharmony_ci+ 3236195972f6Sopenharmony_ci+extern char *g_ppLayerName[PERF_POINT_END]; 3237195972f6Sopenharmony_ci+extern volatile uint64_t g_perfMaxtime[PERF_POINT_END]; 3238195972f6Sopenharmony_ci+extern volatile uint64_t g_astPacketCnt[PERF_POINT_END]; 3239195972f6Sopenharmony_ci+extern volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; 3240195972f6Sopenharmony_ci+ 3241195972f6Sopenharmony_ci+#define PERF_START(layer, point) do {\ 3242195972f6Sopenharmony_ci+ g_perfPoint[(layer)] = (point);\ 3243195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("set point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ 3244195972f6Sopenharmony_ci+ clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ 3245195972f6Sopenharmony_ci+ g_timeTaken[(point)] = 0;\ 3246195972f6Sopenharmony_ci+} while (0) 3247195972f6Sopenharmony_ci+ 3248195972f6Sopenharmony_ci+#define PERF_UPDATE_POINT(layer, point) do {\ 3249195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("old point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ 3250195972f6Sopenharmony_ci+ g_timeTaken[(point)] = g_timeTaken[g_perfPoint[(layer)]];\ 3251195972f6Sopenharmony_ci+ g_timeTaken[g_perfPoint[(layer)]] = 0;\ 3252195972f6Sopenharmony_ci+ g_perfPoint[(layer)] = (point);\ 3253195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("new point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ 3254195972f6Sopenharmony_ci+} while (0) 3255195972f6Sopenharmony_ci+ 3256195972f6Sopenharmony_ci+#define PERF_PAUSE(layer) do {\ 3257195972f6Sopenharmony_ci+ struct timespec tvEnd;\ 3258195972f6Sopenharmony_ci+ clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ 3259195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause layer%d\n", layer));\ 3260195972f6Sopenharmony_ci+ g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ 3261195972f6Sopenharmony_ci+ * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ 3262195972f6Sopenharmony_ci+} while (0) 3263195972f6Sopenharmony_ci+ 3264195972f6Sopenharmony_ci+#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do {\ 3265195972f6Sopenharmony_ci+ struct timespec tvEnd;\ 3266195972f6Sopenharmony_ci+ clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ 3267195972f6Sopenharmony_ci+ g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ 3268195972f6Sopenharmony_ci+ * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ 3269195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ 3270195972f6Sopenharmony_ci+ (pause_point) = g_perfPoint[(layer)];\ 3271195972f6Sopenharmony_ci+} while (0) 3272195972f6Sopenharmony_ci+ 3273195972f6Sopenharmony_ci+ 3274195972f6Sopenharmony_ci+#define PERF_RESUME(layer, point) do {\ 3275195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf resule point %d:%s\n", layer, g_ppLayerName[point]));\ 3276195972f6Sopenharmony_ci+ clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ 3277195972f6Sopenharmony_ci+ g_perfPoint[(layer)] = (point);\ 3278195972f6Sopenharmony_ci+} while (0) 3279195972f6Sopenharmony_ci+ 3280195972f6Sopenharmony_ci+ 3281195972f6Sopenharmony_ci+/* x is a prompt */ 3282195972f6Sopenharmony_ci+#define PERF_STOP_INCREASE_COUNT(x, layer) do {\ 3283195972f6Sopenharmony_ci+ if (g_record_perf)\ 3284195972f6Sopenharmony_ci+ {\ 3285195972f6Sopenharmony_ci+ struct timespec tvEnd;\ 3286195972f6Sopenharmony_ci+ int i = 2;\ 3287195972f6Sopenharmony_ci+ uint32_t oldValue = 0;\ 3288195972f6Sopenharmony_ci+ clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ 3289195972f6Sopenharmony_ci+ g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ 3290195972f6Sopenharmony_ci+ * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ 3291195972f6Sopenharmony_ci+ while (i && !oldValue)\ 3292195972f6Sopenharmony_ci+ {\ 3293195972f6Sopenharmony_ci+ oldValue = __sync_or_and_fetch(&g_perfMaxtime[g_perfPoint[(layer)]], 0);\ 3294195972f6Sopenharmony_ci+ if (oldValue >= g_timeTaken[g_perfPoint[(layer)]])\ 3295195972f6Sopenharmony_ci+ {\ 3296195972f6Sopenharmony_ci+ break;\ 3297195972f6Sopenharmony_ci+ }\ 3298195972f6Sopenharmony_ci+ oldValue = __sync_val_compare_and_swap(&g_perfMaxtime[g_perfPoint[(layer)]],\ 3299195972f6Sopenharmony_ci+ oldValue, g_timeTaken[g_perfPoint[(layer)]]);\ 3300195972f6Sopenharmony_ci+ i--;\ 3301195972f6Sopenharmony_ci+ }\ 3302195972f6Sopenharmony_ci+ __sync_fetch_and_add(&g_astPacketCnt[g_perfPoint[(layer)]], 1);\ 3303195972f6Sopenharmony_ci+ __sync_fetch_and_add(&g_astPacketProcTime[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]);\ 3304195972f6Sopenharmony_ci+ LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("Time for %s is: %ld\n",\ 3305195972f6Sopenharmony_ci+ g_ppLayerName[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]));\ 3306195972f6Sopenharmony_ci+ }\ 3307195972f6Sopenharmony_ci+} while (0) 3308195972f6Sopenharmony_ci+ 3309195972f6Sopenharmony_ci+ 3310195972f6Sopenharmony_ci+int check_layer_point(int layer, int point); 3311195972f6Sopenharmony_ci+int perf_init(); 3312195972f6Sopenharmony_ci+ 3313195972f6Sopenharmony_ci+#else 3314195972f6Sopenharmony_ci+#define PERF_START(layer, point) do { } while (0) 3315195972f6Sopenharmony_ci+#define PERF_UPDATE_POINT(layer, point) do { } while (0) 3316195972f6Sopenharmony_ci+#define PERF_PAUSE(layer) do { } while (0) 3317195972f6Sopenharmony_ci+#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do { } while (0) 3318195972f6Sopenharmony_ci+#define PERF_RESUME(layer, point) do { } while (0) 3319195972f6Sopenharmony_ci+#define PERF_STOP_INCREASE_COUNT(x, layer) do { } while (0) 3320195972f6Sopenharmony_ci+#endif 3321195972f6Sopenharmony_ci+ 3322195972f6Sopenharmony_ci+#endif /* LWIP_ARCH_PERF_H */ 3323195972f6Sopenharmony_cidiff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h 3324195972f6Sopenharmony_ciindex 3f555ee..b8a0d28 100644 3325195972f6Sopenharmony_ci--- a/src/include/arch/sys_arch.h 3326195972f6Sopenharmony_ci+++ b/src/include/arch/sys_arch.h 3327195972f6Sopenharmony_ci@@ -1,7 +1,93 @@ 3328195972f6Sopenharmony_ci-#ifndef LWIP_SYS_ARCH_H 3329195972f6Sopenharmony_ci-#define LWIP_SYS_ARCH_H 3330195972f6Sopenharmony_ci+/* 3331195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3332195972f6Sopenharmony_ci+ * All rights reserved. 3333195972f6Sopenharmony_ci+ * 3334195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3335195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3336195972f6Sopenharmony_ci+ * 3337195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3338195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3339195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3340195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3341195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3342195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3343195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3344195972f6Sopenharmony_ci+ * 3345195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3346195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3347195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3348195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3349195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3350195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3351195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3352195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3353195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3354195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3355195972f6Sopenharmony_ci+ * 3356195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3357195972f6Sopenharmony_ci+ * 3358195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3359195972f6Sopenharmony_ci+ * 3360195972f6Sopenharmony_ci+ */ 3361195972f6Sopenharmony_ci 3362195972f6Sopenharmony_ci+#ifndef LWIP_ARCH_SYS_ARCH_H 3363195972f6Sopenharmony_ci+#define LWIP_ARCH_SYS_ARCH_H 3364195972f6Sopenharmony_ci 3365195972f6Sopenharmony_ci+#include <rte_cycles.h> 3366195972f6Sopenharmony_ci+#include <rte_debug.h> 3367195972f6Sopenharmony_ci 3368195972f6Sopenharmony_ci-#endif /* LWIP_SYS_ARCH_H */ 3369195972f6Sopenharmony_ci+#define SYS_MBOX_NULL NULL 3370195972f6Sopenharmony_ci+#define SYS_SEM_NULL NULL 3371195972f6Sopenharmony_ci+typedef uint32_t sys_prot_t; 3372195972f6Sopenharmony_ci 3373195972f6Sopenharmony_ci+struct sys_sem { 3374195972f6Sopenharmony_ci+ volatile unsigned int c; 3375195972f6Sopenharmony_ci+ int (*wait_fn)(void); 3376195972f6Sopenharmony_ci+}; 3377195972f6Sopenharmony_ci+ 3378195972f6Sopenharmony_ci+#define MBOX_NAME_LEN 64 3379195972f6Sopenharmony_ci+struct sys_mbox { 3380195972f6Sopenharmony_ci+ struct rte_ring *ring; 3381195972f6Sopenharmony_ci+ char name[MBOX_NAME_LEN]; 3382195972f6Sopenharmony_ci+ int size; 3383195972f6Sopenharmony_ci+ int socket_id; 3384195972f6Sopenharmony_ci+ unsigned flags; 3385195972f6Sopenharmony_ci+ int (*wait_fn)(void); 3386195972f6Sopenharmony_ci+}; 3387195972f6Sopenharmony_ci+ 3388195972f6Sopenharmony_ci+typedef struct sys_sem *sys_sem_t; 3389195972f6Sopenharmony_ci+#define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL)) 3390195972f6Sopenharmony_ci+#define sys_sem_valid_val(sem) ((sem) != NULL) 3391195972f6Sopenharmony_ci+#define sys_sem_set_invalid(sem) do { if ((sem) != NULL) { *(sem) = NULL; }} while(0) 3392195972f6Sopenharmony_ci+#define sys_sem_set_invalid_val(sem) do { (sem) = NULL; } while(0) 3393195972f6Sopenharmony_ci+ 3394195972f6Sopenharmony_ci+struct sys_mutex; 3395195972f6Sopenharmony_ci+typedef struct sys_mutex *sys_mutex_t; 3396195972f6Sopenharmony_ci+#define sys_mutex_valid(mutex) sys_sem_valid(mutex) 3397195972f6Sopenharmony_ci+#define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex) 3398195972f6Sopenharmony_ci+ 3399195972f6Sopenharmony_ci+typedef struct sys_mbox *sys_mbox_t; 3400195972f6Sopenharmony_ci+#define sys_mbox_valid(mbox) sys_sem_valid(mbox) 3401195972f6Sopenharmony_ci+#define sys_mbox_valid_val(mbox) sys_sem_valid_val(mbox) 3402195972f6Sopenharmony_ci+#define sys_mbox_set_invalid(mbox) sys_sem_set_invalid(mbox) 3403195972f6Sopenharmony_ci+#define sys_mbox_set_invalid_val(mbox) sys_sem_set_invalid_val(mbox) 3404195972f6Sopenharmony_ci+int sys_mbox_empty(struct sys_mbox *); 3405195972f6Sopenharmony_ci+ 3406195972f6Sopenharmony_ci+struct sys_thread; 3407195972f6Sopenharmony_ci+typedef struct sys_thread *sys_thread_t; 3408195972f6Sopenharmony_ci+ 3409195972f6Sopenharmony_ci+extern int eth_dev_poll(void); 3410195972f6Sopenharmony_ci+ 3411195972f6Sopenharmony_ci+void sys_calibrate_tsc(void); 3412195972f6Sopenharmony_ci+uint32_t sys_now(void); 3413195972f6Sopenharmony_ci+__attribute__((always_inline)) inline int update_timeout(int timeout, uint32_t poll_ts) 3414195972f6Sopenharmony_ci+{ 3415195972f6Sopenharmony_ci+ uint32_t used_ms = sys_now() - poll_ts; 3416195972f6Sopenharmony_ci+ if (timeout > 0 && used_ms < timeout) { 3417195972f6Sopenharmony_ci+ return timeout; 3418195972f6Sopenharmony_ci+ } else { 3419195972f6Sopenharmony_ci+ return 0; 3420195972f6Sopenharmony_ci+ } 3421195972f6Sopenharmony_ci+} 3422195972f6Sopenharmony_ci+ 3423195972f6Sopenharmony_ci+#endif /* LWIP_ARCH_SYS_ARCH_H */ 3424195972f6Sopenharmony_cidiff --git a/src/include/eventpoll.h b/src/include/eventpoll.h 3425195972f6Sopenharmony_cinew file mode 100644 3426195972f6Sopenharmony_ciindex 0000000..01f8d64 3427195972f6Sopenharmony_ci--- /dev/null 3428195972f6Sopenharmony_ci+++ b/src/include/eventpoll.h 3429195972f6Sopenharmony_ci@@ -0,0 +1,72 @@ 3430195972f6Sopenharmony_ci+/* 3431195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3432195972f6Sopenharmony_ci+ * All rights reserved. 3433195972f6Sopenharmony_ci+ * 3434195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3435195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3436195972f6Sopenharmony_ci+ * 3437195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3438195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3439195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3440195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3441195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3442195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3443195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3444195972f6Sopenharmony_ci+ * 3445195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3446195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3447195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3448195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3449195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3450195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3451195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3452195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3453195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3454195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3455195972f6Sopenharmony_ci+ * 3456195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3457195972f6Sopenharmony_ci+ * 3458195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3459195972f6Sopenharmony_ci+ * 3460195972f6Sopenharmony_ci+ */ 3461195972f6Sopenharmony_ci+ 3462195972f6Sopenharmony_ci+#ifndef __EVENTPOLL_H__ 3463195972f6Sopenharmony_ci+#define __EVENTPOLL_H__ 3464195972f6Sopenharmony_ci+ 3465195972f6Sopenharmony_ci+#include <sys/epoll.h> 3466195972f6Sopenharmony_ci+ 3467195972f6Sopenharmony_ci+#include "lwip/api.h" 3468195972f6Sopenharmony_ci+#include "list.h" 3469195972f6Sopenharmony_ci+ 3470195972f6Sopenharmony_ci+#define MAX_EPOLLFDS 32 3471195972f6Sopenharmony_ci+ 3472195972f6Sopenharmony_ci+#define LIBOS_EPOLLNONE (0x0) 3473195972f6Sopenharmony_ci+#define LIBOS_BADEP (NULL) 3474195972f6Sopenharmony_ci+ 3475195972f6Sopenharmony_ci+struct event_queue { 3476195972f6Sopenharmony_ci+ struct list_node events; 3477195972f6Sopenharmony_ci+ /* total number of sockets have events */ 3478195972f6Sopenharmony_ci+ int num_events; 3479195972f6Sopenharmony_ci+}; 3480195972f6Sopenharmony_ci+ 3481195972f6Sopenharmony_ci+struct event_array { 3482195972f6Sopenharmony_ci+ sys_mbox_t mbox; 3483195972f6Sopenharmony_ci+ volatile int num_events; 3484195972f6Sopenharmony_ci+ struct epoll_event events[0]; 3485195972f6Sopenharmony_ci+}; 3486195972f6Sopenharmony_ci+ 3487195972f6Sopenharmony_ci+struct libos_epoll { 3488195972f6Sopenharmony_ci+ struct event_queue *libos_queue; 3489195972f6Sopenharmony_ci+ struct event_array *host_queue; 3490195972f6Sopenharmony_ci+ int num_hostfds; 3491195972f6Sopenharmony_ci+ int hints; 3492195972f6Sopenharmony_ci+ int fd; /* self fd */ 3493195972f6Sopenharmony_ci+ int efd; /* eventfd */ 3494195972f6Sopenharmony_ci+}; 3495195972f6Sopenharmony_ci+ 3496195972f6Sopenharmony_ci+extern int add_epoll_event(struct netconn*, uint32_t); 3497195972f6Sopenharmony_ci+extern int del_epoll_event(struct netconn*, uint32_t); 3498195972f6Sopenharmony_ci+extern int lwip_epoll_close(int); 3499195972f6Sopenharmony_ci+extern int lwip_is_epfd(int); 3500195972f6Sopenharmony_ci+ 3501195972f6Sopenharmony_ci+#endif /* __EVENTPOLL_H__ */ 3502195972f6Sopenharmony_cidiff --git a/src/include/hlist.h b/src/include/hlist.h 3503195972f6Sopenharmony_cinew file mode 100644 3504195972f6Sopenharmony_ciindex 0000000..7059488 3505195972f6Sopenharmony_ci--- /dev/null 3506195972f6Sopenharmony_ci+++ b/src/include/hlist.h 3507195972f6Sopenharmony_ci@@ -0,0 +1,233 @@ 3508195972f6Sopenharmony_ci+/* 3509195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3510195972f6Sopenharmony_ci+ * All rights reserved. 3511195972f6Sopenharmony_ci+ * 3512195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3513195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3514195972f6Sopenharmony_ci+ * 3515195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3516195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3517195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3518195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3519195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3520195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3521195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3522195972f6Sopenharmony_ci+ * 3523195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3524195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3525195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3526195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3527195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3528195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3529195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3530195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3531195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3532195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3533195972f6Sopenharmony_ci+ * 3534195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3535195972f6Sopenharmony_ci+ * 3536195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3537195972f6Sopenharmony_ci+ * 3538195972f6Sopenharmony_ci+ */ 3539195972f6Sopenharmony_ci+ 3540195972f6Sopenharmony_ci+#ifndef __HLIST_H__ 3541195972f6Sopenharmony_ci+#define __HLIST_H__ 3542195972f6Sopenharmony_ci+ 3543195972f6Sopenharmony_ci+#include "list.h" 3544195972f6Sopenharmony_ci+ 3545195972f6Sopenharmony_ci+//#if TCP_PCB_HASH 3546195972f6Sopenharmony_ci+struct hlist_node { 3547195972f6Sopenharmony_ci+ /** 3548195972f6Sopenharmony_ci+ * @pprev: point the previous node's next pointer 3549195972f6Sopenharmony_ci+ */ 3550195972f6Sopenharmony_ci+ struct hlist_node *next; 3551195972f6Sopenharmony_ci+ struct hlist_node **pprev; 3552195972f6Sopenharmony_ci+}; 3553195972f6Sopenharmony_ci+ 3554195972f6Sopenharmony_ci+struct hlist_head { 3555195972f6Sopenharmony_ci+ struct hlist_node *first; 3556195972f6Sopenharmony_ci+}; 3557195972f6Sopenharmony_ci+ 3558195972f6Sopenharmony_ci+struct hlist_tail { 3559195972f6Sopenharmony_ci+ struct hlist_node *end; 3560195972f6Sopenharmony_ci+}; 3561195972f6Sopenharmony_ci+ 3562195972f6Sopenharmony_ci+struct hlist_ctl { 3563195972f6Sopenharmony_ci+ struct hlist_head head; 3564195972f6Sopenharmony_ci+ struct hlist_tail tail; 3565195972f6Sopenharmony_ci+}; 3566195972f6Sopenharmony_ci+ 3567195972f6Sopenharmony_ci+#define INIT_HLIST_CTRL(ptr) {(ptr)->head.first = NULL; (ptr)->tail.end = NULL;} 3568195972f6Sopenharmony_ci+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) 3569195972f6Sopenharmony_ci+#define INIT_HLIST_NODE(ptr) {(ptr)->next = NULL; (ptr)->pprev = NULL;} 3570195972f6Sopenharmony_ci+#define hlist_entry(ptr, type, member) \ 3571195972f6Sopenharmony_ci+ container_of(ptr, type, member) 3572195972f6Sopenharmony_ci+ 3573195972f6Sopenharmony_ci+/** 3574195972f6Sopenharmony_ci+ * hlist_for_each_entry - iterate over list of given type 3575195972f6Sopenharmony_ci+ * @tpos: the type * to use as a loop cursor. 3576195972f6Sopenharmony_ci+ * @pos: the &struct hlist_node to use as a loop cursor. 3577195972f6Sopenharmony_ci+ * @head: the head for your list. 3578195972f6Sopenharmony_ci+ * @member: the name of the hlist_node within the struct. 3579195972f6Sopenharmony_ci+ */ 3580195972f6Sopenharmony_ci+#define hlist_for_each_entry(tpos, pos, head, member) \ 3581195972f6Sopenharmony_ci+ for (pos = (head)->first; \ 3582195972f6Sopenharmony_ci+ pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ 3583195972f6Sopenharmony_ci+ pos = (pos)->next) 3584195972f6Sopenharmony_ci+ 3585195972f6Sopenharmony_ci+/** 3586195972f6Sopenharmony_ci+ * next must be != NULL 3587195972f6Sopenharmony_ci+ * add n node before next node 3588195972f6Sopenharmony_ci+ * 3589195972f6Sopenharmony_ci+ * @n: new node 3590195972f6Sopenharmony_ci+ * @next: node in the hlist 3591195972f6Sopenharmony_ci+ */ 3592195972f6Sopenharmony_ci+static inline void hlist_add_before(struct hlist_node *n, struct hlist_node *next) 3593195972f6Sopenharmony_ci+{ 3594195972f6Sopenharmony_ci+ n->pprev = next->pprev; 3595195972f6Sopenharmony_ci+ n->next = next; 3596195972f6Sopenharmony_ci+ next->pprev = &n->next; 3597195972f6Sopenharmony_ci+ *(n->pprev) = n; 3598195972f6Sopenharmony_ci+} 3599195972f6Sopenharmony_ci+ 3600195972f6Sopenharmony_ci+static inline int hlist_empty(const struct hlist_head *h) 3601195972f6Sopenharmony_ci+{ 3602195972f6Sopenharmony_ci+ return !h->first; 3603195972f6Sopenharmony_ci+} 3604195972f6Sopenharmony_ci+ 3605195972f6Sopenharmony_ci+static inline int hlist_unhashed(const struct hlist_node *h) 3606195972f6Sopenharmony_ci+{ 3607195972f6Sopenharmony_ci+ return !h->pprev; 3608195972f6Sopenharmony_ci+} 3609195972f6Sopenharmony_ci+ 3610195972f6Sopenharmony_ci+static inline void hlist_del_init(struct hlist_node *n) 3611195972f6Sopenharmony_ci+{ 3612195972f6Sopenharmony_ci+ struct hlist_node *next = n->next; 3613195972f6Sopenharmony_ci+ struct hlist_node **pprev = n->pprev; 3614195972f6Sopenharmony_ci+ 3615195972f6Sopenharmony_ci+ if (pprev == NULL) { 3616195972f6Sopenharmony_ci+ return; 3617195972f6Sopenharmony_ci+ } 3618195972f6Sopenharmony_ci+ 3619195972f6Sopenharmony_ci+ *pprev = next; 3620195972f6Sopenharmony_ci+ if (next != NULL) { 3621195972f6Sopenharmony_ci+ next->pprev = pprev; 3622195972f6Sopenharmony_ci+ } 3623195972f6Sopenharmony_ci+ 3624195972f6Sopenharmony_ci+ n->next = NULL; 3625195972f6Sopenharmony_ci+ n->pprev = NULL; 3626195972f6Sopenharmony_ci+} 3627195972f6Sopenharmony_ci+ 3628195972f6Sopenharmony_ci+static inline void hlist_ctl_del(struct hlist_ctl *ctl, struct hlist_node *n) 3629195972f6Sopenharmony_ci+{ 3630195972f6Sopenharmony_ci+ if (ctl->head.first == ctl->tail.end) { 3631195972f6Sopenharmony_ci+ ctl->head.first = NULL; 3632195972f6Sopenharmony_ci+ ctl->tail.end = NULL; 3633195972f6Sopenharmony_ci+ return; 3634195972f6Sopenharmony_ci+ } 3635195972f6Sopenharmony_ci+ 3636195972f6Sopenharmony_ci+ if (ctl->tail.end == n) { 3637195972f6Sopenharmony_ci+ ctl->tail.end = (struct hlist_node *)n->pprev; 3638195972f6Sopenharmony_ci+ } 3639195972f6Sopenharmony_ci+ 3640195972f6Sopenharmony_ci+ hlist_del_init(n); 3641195972f6Sopenharmony_ci+} 3642195972f6Sopenharmony_ci+ 3643195972f6Sopenharmony_ci+static inline struct hlist_node *hlist_pop_tail(struct hlist_ctl *ctl) 3644195972f6Sopenharmony_ci+{ 3645195972f6Sopenharmony_ci+ if (hlist_empty(&ctl->head)) { 3646195972f6Sopenharmony_ci+ return NULL; 3647195972f6Sopenharmony_ci+ } 3648195972f6Sopenharmony_ci+ 3649195972f6Sopenharmony_ci+ if (ctl->head.first == ctl->tail.end) { 3650195972f6Sopenharmony_ci+ struct hlist_node *ret = ctl->tail.end; 3651195972f6Sopenharmony_ci+ ctl->tail.end = NULL; 3652195972f6Sopenharmony_ci+ ctl->head.first = NULL; 3653195972f6Sopenharmony_ci+ return ret; 3654195972f6Sopenharmony_ci+ } 3655195972f6Sopenharmony_ci+ 3656195972f6Sopenharmony_ci+ struct hlist_node *temp = ctl->tail.end; 3657195972f6Sopenharmony_ci+ 3658195972f6Sopenharmony_ci+ struct hlist_node **ptailPrev = ctl->tail.end->pprev; 3659195972f6Sopenharmony_ci+ *ptailPrev = NULL; 3660195972f6Sopenharmony_ci+ 3661195972f6Sopenharmony_ci+ ctl->tail.end = (struct hlist_node *)ptailPrev; 3662195972f6Sopenharmony_ci+ temp->pprev = NULL; 3663195972f6Sopenharmony_ci+ return temp; 3664195972f6Sopenharmony_ci+} 3665195972f6Sopenharmony_ci+ 3666195972f6Sopenharmony_ci+static inline void hlist_add_after(struct hlist_node *n, struct hlist_node *next) 3667195972f6Sopenharmony_ci+{ 3668195972f6Sopenharmony_ci+ next->next = n->next; 3669195972f6Sopenharmony_ci+ n->next = next; 3670195972f6Sopenharmony_ci+ next->pprev = &n->next; 3671195972f6Sopenharmony_ci+ if (next->next) { 3672195972f6Sopenharmony_ci+ next->next->pprev = &next->next; 3673195972f6Sopenharmony_ci+ } 3674195972f6Sopenharmony_ci+} 3675195972f6Sopenharmony_ci+ 3676195972f6Sopenharmony_ci+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) 3677195972f6Sopenharmony_ci+{ 3678195972f6Sopenharmony_ci+ struct hlist_node *first = h->first; 3679195972f6Sopenharmony_ci+ 3680195972f6Sopenharmony_ci+ n->next = first; 3681195972f6Sopenharmony_ci+ if (first != NULL) { 3682195972f6Sopenharmony_ci+ first->pprev = &n->next; 3683195972f6Sopenharmony_ci+ } 3684195972f6Sopenharmony_ci+ 3685195972f6Sopenharmony_ci+ h->first = n; 3686195972f6Sopenharmony_ci+ n->pprev = &h->first; 3687195972f6Sopenharmony_ci+} 3688195972f6Sopenharmony_ci+ 3689195972f6Sopenharmony_ci+static inline struct hlist_node *hlist_pop_head(struct hlist_ctl *ctl) 3690195972f6Sopenharmony_ci+{ 3691195972f6Sopenharmony_ci+ if (hlist_empty(&ctl->head)) { 3692195972f6Sopenharmony_ci+ return NULL; 3693195972f6Sopenharmony_ci+ } 3694195972f6Sopenharmony_ci+ 3695195972f6Sopenharmony_ci+ struct hlist_node *temp = ctl->head.first; 3696195972f6Sopenharmony_ci+ hlist_ctl_del(ctl, temp); 3697195972f6Sopenharmony_ci+ return temp; 3698195972f6Sopenharmony_ci+} 3699195972f6Sopenharmony_ci+ 3700195972f6Sopenharmony_ci+static inline void hlist_ctl_add_tail(struct hlist_ctl *ctl, struct hlist_node *node) 3701195972f6Sopenharmony_ci+{ 3702195972f6Sopenharmony_ci+ if (hlist_empty(&ctl->head)) { 3703195972f6Sopenharmony_ci+ hlist_add_head(node, &ctl->head); 3704195972f6Sopenharmony_ci+ ctl->tail.end = ctl->head.first; 3705195972f6Sopenharmony_ci+ return; 3706195972f6Sopenharmony_ci+ } 3707195972f6Sopenharmony_ci+ 3708195972f6Sopenharmony_ci+ ctl->tail.end->next = node; 3709195972f6Sopenharmony_ci+ 3710195972f6Sopenharmony_ci+ node->pprev = &(ctl->tail.end->next); 3711195972f6Sopenharmony_ci+ node->next = NULL; 3712195972f6Sopenharmony_ci+ ctl->tail.end = node; 3713195972f6Sopenharmony_ci+} 3714195972f6Sopenharmony_ci+ 3715195972f6Sopenharmony_ci+static inline void hlist_ctl_add_head(struct hlist_node *node, struct hlist_ctl *ctl) 3716195972f6Sopenharmony_ci+{ 3717195972f6Sopenharmony_ci+ hlist_add_head(node, &ctl->head); 3718195972f6Sopenharmony_ci+ if (ctl->tail.end == NULL) { 3719195972f6Sopenharmony_ci+ ctl->tail.end = ctl->head.first; 3720195972f6Sopenharmony_ci+ } 3721195972f6Sopenharmony_ci+} 3722195972f6Sopenharmony_ci+ 3723195972f6Sopenharmony_ci+static inline void hlist_ctl_add_before(struct hlist_node *n, struct hlist_node *next, struct hlist_ctl *ctl) 3724195972f6Sopenharmony_ci+{ 3725195972f6Sopenharmony_ci+ hlist_add_before(n, next); 3726195972f6Sopenharmony_ci+ if (next == ctl->head.first) { 3727195972f6Sopenharmony_ci+ ctl->head.first = n; 3728195972f6Sopenharmony_ci+ } 3729195972f6Sopenharmony_ci+} 3730195972f6Sopenharmony_ci+ 3731195972f6Sopenharmony_ci+static inline void hlist_ctl_add_after(struct hlist_node *n, struct hlist_node *next, struct hlist_ctl *ctl) 3732195972f6Sopenharmony_ci+{ 3733195972f6Sopenharmony_ci+ hlist_add_after(n, next); 3734195972f6Sopenharmony_ci+ if (n == ctl->tail.end) { 3735195972f6Sopenharmony_ci+ ctl->tail.end = next; 3736195972f6Sopenharmony_ci+ } 3737195972f6Sopenharmony_ci+} 3738195972f6Sopenharmony_ci+//#endif /* TCP_PCB_HASH */ 3739195972f6Sopenharmony_ci+ 3740195972f6Sopenharmony_ci+#endif /* __HLIST_H__ */ 3741195972f6Sopenharmony_cidiff --git a/src/include/list.h b/src/include/list.h 3742195972f6Sopenharmony_cinew file mode 100644 3743195972f6Sopenharmony_ciindex 0000000..11f94c2 3744195972f6Sopenharmony_ci--- /dev/null 3745195972f6Sopenharmony_ci+++ b/src/include/list.h 3746195972f6Sopenharmony_ci@@ -0,0 +1,110 @@ 3747195972f6Sopenharmony_ci+/* 3748195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3749195972f6Sopenharmony_ci+ * All rights reserved. 3750195972f6Sopenharmony_ci+ * 3751195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 3752195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 3753195972f6Sopenharmony_ci+ * 3754195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 3755195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 3756195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 3757195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 3758195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 3759195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 3760195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 3761195972f6Sopenharmony_ci+ * 3762195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 3763195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 3764195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 3765195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3766195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 3767195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3768195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3769195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 3770195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 3771195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 3772195972f6Sopenharmony_ci+ * 3773195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 3774195972f6Sopenharmony_ci+ * 3775195972f6Sopenharmony_ci+ * Author: Huawei Technologies 3776195972f6Sopenharmony_ci+ * 3777195972f6Sopenharmony_ci+ */ 3778195972f6Sopenharmony_ci+ 3779195972f6Sopenharmony_ci+#ifndef __LIST_H__ 3780195972f6Sopenharmony_ci+#define __LIST_H__ 3781195972f6Sopenharmony_ci+ 3782195972f6Sopenharmony_ci+#ifndef NULL 3783195972f6Sopenharmony_ci+#ifdef __cplusplus 3784195972f6Sopenharmony_ci+#define NULL 0 3785195972f6Sopenharmony_ci+#else 3786195972f6Sopenharmony_ci+#define NULL ((void *)0) 3787195972f6Sopenharmony_ci+#endif 3788195972f6Sopenharmony_ci+#endif 3789195972f6Sopenharmony_ci+ 3790195972f6Sopenharmony_ci+struct list_node { 3791195972f6Sopenharmony_ci+ struct list_node *prev; 3792195972f6Sopenharmony_ci+ struct list_node *next; 3793195972f6Sopenharmony_ci+}; 3794195972f6Sopenharmony_ci+ 3795195972f6Sopenharmony_ci+static inline void init_list_node_null(struct list_node *n) 3796195972f6Sopenharmony_ci+{ 3797195972f6Sopenharmony_ci+ n->prev = NULL; 3798195972f6Sopenharmony_ci+ n->next = NULL; 3799195972f6Sopenharmony_ci+} 3800195972f6Sopenharmony_ci+ 3801195972f6Sopenharmony_ci+static inline void init_list_node(struct list_node *n) 3802195972f6Sopenharmony_ci+{ 3803195972f6Sopenharmony_ci+ n->prev = n; 3804195972f6Sopenharmony_ci+ n->next = n; 3805195972f6Sopenharmony_ci+} 3806195972f6Sopenharmony_ci+ 3807195972f6Sopenharmony_ci+static inline void list_add_node(struct list_node *h, struct list_node *n) 3808195972f6Sopenharmony_ci+{ 3809195972f6Sopenharmony_ci+ n->next = h; 3810195972f6Sopenharmony_ci+ n->prev = h->prev; 3811195972f6Sopenharmony_ci+ h->prev->next = n; 3812195972f6Sopenharmony_ci+ h->prev = n; 3813195972f6Sopenharmony_ci+} 3814195972f6Sopenharmony_ci+ 3815195972f6Sopenharmony_ci+static inline void list_del_node(struct list_node *n) 3816195972f6Sopenharmony_ci+{ 3817195972f6Sopenharmony_ci+ struct list_node *prev = n->prev; 3818195972f6Sopenharmony_ci+ struct list_node *next = n->next; 3819195972f6Sopenharmony_ci+ next->prev = prev; 3820195972f6Sopenharmony_ci+ prev->next = next; 3821195972f6Sopenharmony_ci+} 3822195972f6Sopenharmony_ci+ 3823195972f6Sopenharmony_ci+static inline void list_del_node_init(struct list_node *n) 3824195972f6Sopenharmony_ci+{ 3825195972f6Sopenharmony_ci+ list_del_node(n); 3826195972f6Sopenharmony_ci+ init_list_node(n); 3827195972f6Sopenharmony_ci+} 3828195972f6Sopenharmony_ci+ 3829195972f6Sopenharmony_ci+static inline void list_del_node_null(struct list_node *n) 3830195972f6Sopenharmony_ci+{ 3831195972f6Sopenharmony_ci+ if ((n->next) && (n->prev)) { 3832195972f6Sopenharmony_ci+ list_del_node(n); 3833195972f6Sopenharmony_ci+ } 3834195972f6Sopenharmony_ci+ init_list_node_null(n); 3835195972f6Sopenharmony_ci+} 3836195972f6Sopenharmony_ci+ 3837195972f6Sopenharmony_ci+static inline int list_is_null(const struct list_node *n) 3838195972f6Sopenharmony_ci+{ 3839195972f6Sopenharmony_ci+ return (n->prev == NULL) && (n->next == NULL); 3840195972f6Sopenharmony_ci+} 3841195972f6Sopenharmony_ci+ 3842195972f6Sopenharmony_ci+static inline int list_is_empty(const struct list_node *h) 3843195972f6Sopenharmony_ci+{ 3844195972f6Sopenharmony_ci+ return h == h->next; 3845195972f6Sopenharmony_ci+} 3846195972f6Sopenharmony_ci+ 3847195972f6Sopenharmony_ci+#define list_for_each_safe(pos, n, head) \ 3848195972f6Sopenharmony_ci+ for (pos = (head)->next, n = (pos)->next; pos != (head); pos = n, n = (pos)->next) 3849195972f6Sopenharmony_ci+ 3850195972f6Sopenharmony_ci+#ifndef container_of 3851195972f6Sopenharmony_ci+#define container_of(ptr, type, member) ({ \ 3852195972f6Sopenharmony_ci+ typeof( ((type *)0)->member ) *__mptr = (ptr); \ 3853195972f6Sopenharmony_ci+ (type *)((char *)__mptr - offsetof(type,member));}) 3854195972f6Sopenharmony_ci+#endif /* container_of */ 3855195972f6Sopenharmony_ci+ 3856195972f6Sopenharmony_ci+#endif /* __LIST_H__ */ 3857195972f6Sopenharmony_cidiff --git a/src/include/lwip/api.h b/src/include/lwip/api.h 3858195972f6Sopenharmony_ciindex c2afaf2..6dec8c0 100644 3859195972f6Sopenharmony_ci--- a/src/include/lwip/api.h 3860195972f6Sopenharmony_ci+++ b/src/include/lwip/api.h 3861195972f6Sopenharmony_ci@@ -140,8 +140,43 @@ enum netconn_type { 3862195972f6Sopenharmony_ci /** Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ 3863195972f6Sopenharmony_ci , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */ 3864195972f6Sopenharmony_ci #endif /* LWIP_IPV6 */ 3865195972f6Sopenharmony_ci+ 3866195972f6Sopenharmony_ci+#if USE_LIBOS 3867195972f6Sopenharmony_ci+ /*here must bigger than 0xff, because (type & 0xff) is for lwip inner use*/ 3868195972f6Sopenharmony_ci+ , NETCONN_LIBOS = 0x100 3869195972f6Sopenharmony_ci+ , NETCONN_HOST = 0x200 3870195972f6Sopenharmony_ci+ , NETCONN_INPRG = 0x400 3871195972f6Sopenharmony_ci+ , NETCONN_STACK = NETCONN_LIBOS | NETCONN_HOST | NETCONN_INPRG 3872195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 3873195972f6Sopenharmony_ci }; 3874195972f6Sopenharmony_ci 3875195972f6Sopenharmony_ci+#ifdef USE_LIBOS 3876195972f6Sopenharmony_ci+#define SET_CONN_TYPE_LIBOS_OR_HOST(conn) do { \ 3877195972f6Sopenharmony_ci+ conn->type &= ~(NETCONN_STACK); \ 3878195972f6Sopenharmony_ci+ conn->type |= (NETCONN_LIBOS | NETCONN_HOST); } while (0) 3879195972f6Sopenharmony_ci+#define SET_CONN_TYPE_LIBOS(conn) do { \ 3880195972f6Sopenharmony_ci+ conn->type &= ~(NETCONN_STACK); \ 3881195972f6Sopenharmony_ci+ conn->type |= NETCONN_LIBOS; } while (0) 3882195972f6Sopenharmony_ci+#define SET_CONN_TYPE_HOST(conn) do { \ 3883195972f6Sopenharmony_ci+ conn->type &= ~(NETCONN_STACK); \ 3884195972f6Sopenharmony_ci+ conn->type |= NETCONN_HOST; } while (0) 3885195972f6Sopenharmony_ci+#define ADD_CONN_TYPE_INPRG(conn) do { \ 3886195972f6Sopenharmony_ci+ conn->type |= NETCONN_INPRG; } while(0) 3887195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_LIBOS_AND_HOST(conn) ((conn->type & (NETCONN_LIBOS | NETCONN_HOST)) == (NETCONN_LIBOS | NETCONN_HOST)) 3888195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_LIBOS(conn) (conn->type & NETCONN_LIBOS) 3889195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_HOST(conn) (conn->type & NETCONN_HOST) 3890195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_INPRG(conn) (!!(conn->type & NETCONN_INPRG)) 3891195972f6Sopenharmony_ci+#define CONN_TYPE_IS_LIBOS(conn) (!!(NETCONN_LIBOS == (conn->type & NETCONN_STACK))) 3892195972f6Sopenharmony_ci+#define CONN_TYPE_IS_HOST(conn) (!!(NETCONN_HOST == (conn->type & NETCONN_STACK))) 3893195972f6Sopenharmony_ci+#else 3894195972f6Sopenharmony_ci+#define SET_CONN_TYPE_LIBOS_OR_HOST(conn) do {} while (0) 3895195972f6Sopenharmony_ci+#define SET_CONN_TYPE_LIBOS(conn) do {} while (0) 3896195972f6Sopenharmony_ci+#define SET_CONN_TYPE_HOST(conn) do {} while (0) 3897195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_LIBOS_AND_HOST(conn) (0) 3898195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_LIBOS(conn) (0) 3899195972f6Sopenharmony_ci+#define CONN_TYPE_HAS_HOST(conn) (0) 3900195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 3901195972f6Sopenharmony_ci+ 3902195972f6Sopenharmony_ci /** Current state of the netconn. Non-TCP netconns are always 3903195972f6Sopenharmony_ci * in state NETCONN_NONE! */ 3904195972f6Sopenharmony_ci enum netconn_state { 3905195972f6Sopenharmony_cidiff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h 3906195972f6Sopenharmony_ciindex 579fd24..f47cbfe 100644 3907195972f6Sopenharmony_ci--- a/src/include/lwip/debug.h 3908195972f6Sopenharmony_ci+++ b/src/include/lwip/debug.h 3909195972f6Sopenharmony_ci@@ -145,6 +145,7 @@ 3910195972f6Sopenharmony_ci ((debug) & LWIP_DBG_ON) && \ 3911195972f6Sopenharmony_ci ((debug) & LWIP_DBG_TYPES_ON) && \ 3912195972f6Sopenharmony_ci ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ 3913195972f6Sopenharmony_ci+ LWIP_PLATFORM_LOG(debug, STRIP_BRACES(ESC_ARGS message)); \ 3914195972f6Sopenharmony_ci LWIP_PLATFORM_DIAG(message); \ 3915195972f6Sopenharmony_ci if ((debug) & LWIP_DBG_HALT) { \ 3916195972f6Sopenharmony_ci while(1); \ 3917195972f6Sopenharmony_cidiff --git a/src/include/lwip/def.h b/src/include/lwip/def.h 3918195972f6Sopenharmony_ciindex dfb266d..fea7187 100644 3919195972f6Sopenharmony_ci--- a/src/include/lwip/def.h 3920195972f6Sopenharmony_ci+++ b/src/include/lwip/def.h 3921195972f6Sopenharmony_ci@@ -116,6 +116,21 @@ u32_t lwip_htonl(u32_t x); 3922195972f6Sopenharmony_ci 3923195972f6Sopenharmony_ci /* Provide usual function names as macros for users, but this can be turned off */ 3924195972f6Sopenharmony_ci #ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 3925195972f6Sopenharmony_ci+ 3926195972f6Sopenharmony_ci+/* avoid conflicts with netinet/in.h */ 3927195972f6Sopenharmony_ci+#ifdef htons 3928195972f6Sopenharmony_ci+#undef htons 3929195972f6Sopenharmony_ci+#endif 3930195972f6Sopenharmony_ci+#ifdef ntohs 3931195972f6Sopenharmony_ci+#undef ntohs 3932195972f6Sopenharmony_ci+#endif 3933195972f6Sopenharmony_ci+#ifdef htonl 3934195972f6Sopenharmony_ci+#undef htonl 3935195972f6Sopenharmony_ci+#endif 3936195972f6Sopenharmony_ci+#ifdef ntohl 3937195972f6Sopenharmony_ci+#undef ntohl 3938195972f6Sopenharmony_ci+#endif 3939195972f6Sopenharmony_ci+ 3940195972f6Sopenharmony_ci #define htons(x) lwip_htons(x) 3941195972f6Sopenharmony_ci #define ntohs(x) lwip_ntohs(x) 3942195972f6Sopenharmony_ci #define htonl(x) lwip_htonl(x) 3943195972f6Sopenharmony_cidiff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h 3944195972f6Sopenharmony_ciindex 653c3b2..d560f6b 100644 3945195972f6Sopenharmony_ci--- a/src/include/lwip/ip.h 3946195972f6Sopenharmony_ci+++ b/src/include/lwip/ip.h 3947195972f6Sopenharmony_ci@@ -96,9 +96,15 @@ struct ip_pcb { 3948195972f6Sopenharmony_ci /* 3949195972f6Sopenharmony_ci * Option flags per-socket. These are the same like SO_XXX in sockets.h 3950195972f6Sopenharmony_ci */ 3951195972f6Sopenharmony_ci+#if USE_LIBOS 3952195972f6Sopenharmony_ci+#define SOF_REUSEADDR 0x02U /* allow local address reuse */ 3953195972f6Sopenharmony_ci+#define SOF_KEEPALIVE 0x09U /* keep connections alive */ 3954195972f6Sopenharmony_ci+#define SOF_BROADCAST 0x06U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ 3955195972f6Sopenharmony_ci+#else 3956195972f6Sopenharmony_ci #define SOF_REUSEADDR 0x04U /* allow local address reuse */ 3957195972f6Sopenharmony_ci #define SOF_KEEPALIVE 0x08U /* keep connections alive */ 3958195972f6Sopenharmony_ci #define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ 3959195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 3960195972f6Sopenharmony_ci 3961195972f6Sopenharmony_ci /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */ 3962195972f6Sopenharmony_ci #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE) 3963195972f6Sopenharmony_ci@@ -125,7 +131,7 @@ struct ip_globals 3964195972f6Sopenharmony_ci /** Destination IP address of current_header */ 3965195972f6Sopenharmony_ci ip_addr_t current_iphdr_dest; 3966195972f6Sopenharmony_ci }; 3967195972f6Sopenharmony_ci-extern struct ip_globals ip_data; 3968195972f6Sopenharmony_ci+extern PER_THREAD struct ip_globals ip_data; 3969195972f6Sopenharmony_ci 3970195972f6Sopenharmony_ci 3971195972f6Sopenharmony_ci /** Get the interface that accepted the current packet. 3972195972f6Sopenharmony_cidiff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h 3973195972f6Sopenharmony_ciindex 1630b26..64d8f31 100644 3974195972f6Sopenharmony_ci--- a/src/include/lwip/memp.h 3975195972f6Sopenharmony_ci+++ b/src/include/lwip/memp.h 3976195972f6Sopenharmony_ci@@ -58,7 +58,11 @@ typedef enum { 3977195972f6Sopenharmony_ci #include "lwip/priv/memp_priv.h" 3978195972f6Sopenharmony_ci #include "lwip/stats.h" 3979195972f6Sopenharmony_ci 3980195972f6Sopenharmony_ci+#if USE_LIBOS 3981195972f6Sopenharmony_ci+extern PER_THREAD struct memp_desc* memp_pools[MEMP_MAX]; 3982195972f6Sopenharmony_ci+#else 3983195972f6Sopenharmony_ci extern const struct memp_desc* const memp_pools[MEMP_MAX]; 3984195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 3985195972f6Sopenharmony_ci 3986195972f6Sopenharmony_ci /** 3987195972f6Sopenharmony_ci * @ingroup mempool 3988195972f6Sopenharmony_ci@@ -92,6 +96,18 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX]; 3989195972f6Sopenharmony_ci * To relocate a pool, declare it as extern in cc.h. Example for GCC: 3990195972f6Sopenharmony_ci * extern u8_t \_\_attribute\_\_((section(".onchip_mem"))) memp_memory_my_private_pool_base[]; 3991195972f6Sopenharmony_ci */ 3992195972f6Sopenharmony_ci+#if USE_LIBOS 3993195972f6Sopenharmony_ci+#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ 3994195972f6Sopenharmony_ci+ PER_THREAD struct memp_desc memp_ ## name = {0}; \ 3995195972f6Sopenharmony_ci+ PER_THREAD char memp_desc_ ## name[] = desc; \ 3996195972f6Sopenharmony_ci+ PER_THREAD struct stats_mem memp_stat ## name = {0}; \ 3997195972f6Sopenharmony_ci+ PER_THREAD u16_t memp_size ## name = size; \ 3998195972f6Sopenharmony_ci+ PER_THREAD u16_t memp_num ## name = num; \ 3999195972f6Sopenharmony_ci+ PER_THREAD struct memp *memp_tab_ ## name = NULL; \ 4000195972f6Sopenharmony_ci+ LWIP_DECLARE_MEMP_BASE_ALIGNED(name, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); 4001195972f6Sopenharmony_ci+ 4002195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 4003195972f6Sopenharmony_ci+ 4004195972f6Sopenharmony_ci #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ 4005195972f6Sopenharmony_ci LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \ 4006195972f6Sopenharmony_ci \ 4007195972f6Sopenharmony_ci@@ -108,6 +124,7 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX]; 4008195972f6Sopenharmony_ci &memp_tab_ ## name \ 4009195972f6Sopenharmony_ci }; 4010195972f6Sopenharmony_ci 4011195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4012195972f6Sopenharmony_ci #endif /* MEMP_MEM_MALLOC */ 4013195972f6Sopenharmony_ci 4014195972f6Sopenharmony_ci /** 4015195972f6Sopenharmony_cidiff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h 4016195972f6Sopenharmony_ciindex 9a16ded..057c51f 100644 4017195972f6Sopenharmony_ci--- a/src/include/lwip/netif.h 4018195972f6Sopenharmony_ci+++ b/src/include/lwip/netif.h 4019195972f6Sopenharmony_ci@@ -406,11 +406,11 @@ struct netif { 4020195972f6Sopenharmony_ci #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) 4021195972f6Sopenharmony_ci #else /* LWIP_SINGLE_NETIF */ 4022195972f6Sopenharmony_ci /** The list of network interfaces. */ 4023195972f6Sopenharmony_ci-extern struct netif *netif_list; 4024195972f6Sopenharmony_ci+extern PER_THREAD struct netif *netif_list; 4025195972f6Sopenharmony_ci #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) 4026195972f6Sopenharmony_ci #endif /* LWIP_SINGLE_NETIF */ 4027195972f6Sopenharmony_ci /** The default network interface. */ 4028195972f6Sopenharmony_ci-extern struct netif *netif_default; 4029195972f6Sopenharmony_ci+extern PER_THREAD struct netif *netif_default; 4030195972f6Sopenharmony_ci 4031195972f6Sopenharmony_ci void netif_init(void); 4032195972f6Sopenharmony_ci 4033195972f6Sopenharmony_cidiff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h 4034195972f6Sopenharmony_ciindex d8c82d1..8294cdd 100644 4035195972f6Sopenharmony_ci--- a/src/include/lwip/opt.h 4036195972f6Sopenharmony_ci+++ b/src/include/lwip/opt.h 4037195972f6Sopenharmony_ci@@ -533,6 +533,22 @@ 4038195972f6Sopenharmony_ci #endif 4039195972f6Sopenharmony_ci 4040195972f6Sopenharmony_ci /** 4041195972f6Sopenharmony_ci+ * MEMP_NUM_SYS_SEM: the number of struct sys_sems. 4042195972f6Sopenharmony_ci+ * (only needed if you use the sequential API, like api_lib.c) 4043195972f6Sopenharmony_ci+ */ 4044195972f6Sopenharmony_ci+#if !defined MEMP_NUM_SYS_SEM || defined __DOXYGEN__ 4045195972f6Sopenharmony_ci+#define MEMP_NUM_SYS_SEM 128 4046195972f6Sopenharmony_ci+#endif 4047195972f6Sopenharmony_ci+ 4048195972f6Sopenharmony_ci+/** 4049195972f6Sopenharmony_ci+ * MEMP_NUM_SYS_MBOX: the number of struct sys_sems. 4050195972f6Sopenharmony_ci+ * (only needed if you use the sequential API, like api_lib.c) 4051195972f6Sopenharmony_ci+ */ 4052195972f6Sopenharmony_ci+#if !defined MEMP_NUM_SYS_MBOX || defined __DOXYGEN__ 4053195972f6Sopenharmony_ci+#define MEMP_NUM_SYS_MBOX 128 4054195972f6Sopenharmony_ci+#endif 4055195972f6Sopenharmony_ci+ 4056195972f6Sopenharmony_ci+/** 4057195972f6Sopenharmony_ci * MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb. 4058195972f6Sopenharmony_ci * (Only needed if you have LWIP_MPU_COMPATIBLE==1 and use the socket API. 4059195972f6Sopenharmony_ci * In that case, you need one per thread calling lwip_select.) 4060195972f6Sopenharmony_ci@@ -2232,7 +2248,7 @@ 4061195972f6Sopenharmony_ci * MIB2_STATS==1: Stats for SNMP MIB2. 4062195972f6Sopenharmony_ci */ 4063195972f6Sopenharmony_ci #if !defined MIB2_STATS || defined __DOXYGEN__ 4064195972f6Sopenharmony_ci-#define MIB2_STATS 0 4065195972f6Sopenharmony_ci+#define MIB2_STATS 1 4066195972f6Sopenharmony_ci #endif 4067195972f6Sopenharmony_ci 4068195972f6Sopenharmony_ci #else 4069195972f6Sopenharmony_ci@@ -3422,6 +3438,10 @@ 4070195972f6Sopenharmony_ci #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 4071195972f6Sopenharmony_ci #endif 4072195972f6Sopenharmony_ci 4073195972f6Sopenharmony_ci+#ifndef PERF_OUTPUT_DEBUG 4074195972f6Sopenharmony_ci+ #define PERF_OUTPUT_DEBUG LWIP_DBG_OFF 4075195972f6Sopenharmony_ci+#endif 4076195972f6Sopenharmony_ci+ 4077195972f6Sopenharmony_ci /** 4078195972f6Sopenharmony_ci * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. 4079195972f6Sopenharmony_ci */ 4080195972f6Sopenharmony_ci@@ -3502,6 +3522,46 @@ 4081195972f6Sopenharmony_ci #define LWIP_TESTMODE 0 4082195972f6Sopenharmony_ci #endif 4083195972f6Sopenharmony_ci 4084195972f6Sopenharmony_ci+/** 4085195972f6Sopenharmony_ci+ * EPOLL_DEBUG: Enable debugging in epoll.c. 4086195972f6Sopenharmony_ci+ */ 4087195972f6Sopenharmony_ci+#if !defined EPOLL_DEBUG || defined __DOXYGEN__ && USE_LIBOS 4088195972f6Sopenharmony_ci+#define EPOLL_DEBUG LWIP_DBG_OFF 4089195972f6Sopenharmony_ci+#endif 4090195972f6Sopenharmony_ci+/** 4091195972f6Sopenharmony_ci+ * @} 4092195972f6Sopenharmony_ci+ */ 4093195972f6Sopenharmony_ci+ 4094195972f6Sopenharmony_ci+/** 4095195972f6Sopenharmony_ci+ * ETHDEV_DEBUG: Enable debugging in ethdev.c. 4096195972f6Sopenharmony_ci+ */ 4097195972f6Sopenharmony_ci+#if !defined ETHDEV_DEBUG || defined __DOXYGEN__ && USE_LIBOS 4098195972f6Sopenharmony_ci+#define ETHDEV_DEBUG LWIP_DBG_OFF 4099195972f6Sopenharmony_ci+#endif 4100195972f6Sopenharmony_ci+/** 4101195972f6Sopenharmony_ci+ * @} 4102195972f6Sopenharmony_ci+ */ 4103195972f6Sopenharmony_ci+ 4104195972f6Sopenharmony_ci+/** 4105195972f6Sopenharmony_ci+ * ETHDEV_DEBUG: Enable debugging in ethdev.c. 4106195972f6Sopenharmony_ci+ */ 4107195972f6Sopenharmony_ci+#if !defined SYSCALL_DEBUG || defined __DOXYGEN__ && USE_LIBOS 4108195972f6Sopenharmony_ci+#define SYSCALL_DEBUG LWIP_DBG_OFF 4109195972f6Sopenharmony_ci+#endif 4110195972f6Sopenharmony_ci+/** 4111195972f6Sopenharmony_ci+ * @} 4112195972f6Sopenharmony_ci+ */ 4113195972f6Sopenharmony_ci+ 4114195972f6Sopenharmony_ci+/** 4115195972f6Sopenharmony_ci+ * CONTROL_DEBUG: Enable debugging in control_plane.c. 4116195972f6Sopenharmony_ci+ */ 4117195972f6Sopenharmony_ci+#if !defined CONTROL_DEBUG || defined __DOXYGEN__ && USE_LIBOS 4118195972f6Sopenharmony_ci+#define CONTROL_DEBUG LWIP_DBG_ON 4119195972f6Sopenharmony_ci+#endif 4120195972f6Sopenharmony_ci+/** 4121195972f6Sopenharmony_ci+ * @} 4122195972f6Sopenharmony_ci+ */ 4123195972f6Sopenharmony_ci+ 4124195972f6Sopenharmony_ci /* 4125195972f6Sopenharmony_ci -------------------------------------------------- 4126195972f6Sopenharmony_ci ---------- Performance tracking options ---------- 4127195972f6Sopenharmony_cidiff --git a/src/include/lwip/priv/memp_std.h b/src/include/lwip/priv/memp_std.h 4128195972f6Sopenharmony_ciindex 669ad4d..395ac0c 100644 4129195972f6Sopenharmony_ci--- a/src/include/lwip/priv/memp_std.h 4130195972f6Sopenharmony_ci+++ b/src/include/lwip/priv/memp_std.h 4131195972f6Sopenharmony_ci@@ -122,6 +122,13 @@ LWIP_MEMPOOL(MLD6_GROUP, MEMP_NUM_MLD6_GROUP, sizeof(struct mld_group), 4132195972f6Sopenharmony_ci #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 4133195972f6Sopenharmony_ci 4134195972f6Sopenharmony_ci 4135195972f6Sopenharmony_ci+#if USE_LIBOS 4136195972f6Sopenharmony_ci+#if !LWIP_NETCONN_SEM_PER_THREAD 4137195972f6Sopenharmony_ci+LWIP_MEMPOOL(SYS_SEM, MEMP_NUM_SYS_SEM, sizeof(struct sys_sem), "SYS_SEM") 4138195972f6Sopenharmony_ci+#endif 4139195972f6Sopenharmony_ci+ 4140195972f6Sopenharmony_ci+LWIP_MEMPOOL(SYS_MBOX, MEMP_NUM_SYS_MBOX, sizeof(struct sys_mbox), "SYS_MBOX") 4141195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4142195972f6Sopenharmony_ci /* 4143195972f6Sopenharmony_ci * A list of pools of pbuf's used by LWIP. 4144195972f6Sopenharmony_ci * 4145195972f6Sopenharmony_cidiff --git a/src/include/lwip/priv/sockets_priv.h b/src/include/lwip/priv/sockets_priv.h 4146195972f6Sopenharmony_ciindex d8f9904..7268a17 100644 4147195972f6Sopenharmony_ci--- a/src/include/lwip/priv/sockets_priv.h 4148195972f6Sopenharmony_ci+++ b/src/include/lwip/priv/sockets_priv.h 4149195972f6Sopenharmony_ci@@ -45,56 +45,17 @@ 4150195972f6Sopenharmony_ci #include "lwip/sockets.h" 4151195972f6Sopenharmony_ci #include "lwip/sys.h" 4152195972f6Sopenharmony_ci 4153195972f6Sopenharmony_ci+/* move some definitions to the lwipsock.h for libnet to use, and 4154195972f6Sopenharmony_ci+ * at the same time avoid conflict between lwip/sockets.h and sys/socket.h 4155195972f6Sopenharmony_ci+ */ 4156195972f6Sopenharmony_ci+#include "lwipsock.h" 4157195972f6Sopenharmony_ci+ 4158195972f6Sopenharmony_ci #ifdef __cplusplus 4159195972f6Sopenharmony_ci extern "C" { 4160195972f6Sopenharmony_ci #endif 4161195972f6Sopenharmony_ci 4162195972f6Sopenharmony_ci #define NUM_SOCKETS MEMP_NUM_NETCONN 4163195972f6Sopenharmony_ci 4164195972f6Sopenharmony_ci-/** This is overridable for the rare case where more than 255 threads 4165195972f6Sopenharmony_ci- * select on the same socket... 4166195972f6Sopenharmony_ci- */ 4167195972f6Sopenharmony_ci-#ifndef SELWAIT_T 4168195972f6Sopenharmony_ci-#define SELWAIT_T u8_t 4169195972f6Sopenharmony_ci-#endif 4170195972f6Sopenharmony_ci- 4171195972f6Sopenharmony_ci-union lwip_sock_lastdata { 4172195972f6Sopenharmony_ci- struct netbuf *netbuf; 4173195972f6Sopenharmony_ci- struct pbuf *pbuf; 4174195972f6Sopenharmony_ci-}; 4175195972f6Sopenharmony_ci- 4176195972f6Sopenharmony_ci-/** Contains all internal pointers and states used for a socket */ 4177195972f6Sopenharmony_ci-struct lwip_sock { 4178195972f6Sopenharmony_ci- /** sockets currently are built on netconns, each socket has one netconn */ 4179195972f6Sopenharmony_ci- struct netconn *conn; 4180195972f6Sopenharmony_ci- /** data that was left from the previous read */ 4181195972f6Sopenharmony_ci- union lwip_sock_lastdata lastdata; 4182195972f6Sopenharmony_ci-#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 4183195972f6Sopenharmony_ci- /** number of times data was received, set by event_callback(), 4184195972f6Sopenharmony_ci- tested by the receive and select functions */ 4185195972f6Sopenharmony_ci- s16_t rcvevent; 4186195972f6Sopenharmony_ci- /** number of times data was ACKed (free send buffer), set by event_callback(), 4187195972f6Sopenharmony_ci- tested by select */ 4188195972f6Sopenharmony_ci- u16_t sendevent; 4189195972f6Sopenharmony_ci- /** error happened for this socket, set by event_callback(), tested by select */ 4190195972f6Sopenharmony_ci- u16_t errevent; 4191195972f6Sopenharmony_ci- /** counter of how many threads are waiting for this socket using select */ 4192195972f6Sopenharmony_ci- SELWAIT_T select_waiting; 4193195972f6Sopenharmony_ci-#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ 4194195972f6Sopenharmony_ci-#if LWIP_NETCONN_FULLDUPLEX 4195195972f6Sopenharmony_ci- /* counter of how many threads are using a struct lwip_sock (not the 'int') */ 4196195972f6Sopenharmony_ci- u8_t fd_used; 4197195972f6Sopenharmony_ci- /* status of pending close/delete actions */ 4198195972f6Sopenharmony_ci- u8_t fd_free_pending; 4199195972f6Sopenharmony_ci-#define LWIP_SOCK_FD_FREE_TCP 1 4200195972f6Sopenharmony_ci-#define LWIP_SOCK_FD_FREE_FREE 2 4201195972f6Sopenharmony_ci-#endif 4202195972f6Sopenharmony_ci-}; 4203195972f6Sopenharmony_ci- 4204195972f6Sopenharmony_ci-#ifndef set_errno 4205195972f6Sopenharmony_ci-#define set_errno(err) do { if (err) { errno = (err); } } while(0) 4206195972f6Sopenharmony_ci-#endif 4207195972f6Sopenharmony_ci- 4208195972f6Sopenharmony_ci #if !LWIP_TCPIP_CORE_LOCKING 4209195972f6Sopenharmony_ci /** Maximum optlen used by setsockopt/getsockopt */ 4210195972f6Sopenharmony_ci #define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq)) 4211195972f6Sopenharmony_cidiff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h 4212195972f6Sopenharmony_ciindex 72f9126..192edc4 100644 4213195972f6Sopenharmony_ci--- a/src/include/lwip/priv/tcp_priv.h 4214195972f6Sopenharmony_ci+++ b/src/include/lwip/priv/tcp_priv.h 4215195972f6Sopenharmony_ci@@ -323,25 +323,42 @@ struct tcp_seg { 4216195972f6Sopenharmony_ci #endif /* LWIP_WND_SCALE */ 4217195972f6Sopenharmony_ci 4218195972f6Sopenharmony_ci /* Global variables: */ 4219195972f6Sopenharmony_ci-extern struct tcp_pcb *tcp_input_pcb; 4220195972f6Sopenharmony_ci-extern u32_t tcp_ticks; 4221195972f6Sopenharmony_ci-extern u8_t tcp_active_pcbs_changed; 4222195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_pcb *tcp_input_pcb; 4223195972f6Sopenharmony_ci+extern PER_THREAD u32_t tcp_ticks; 4224195972f6Sopenharmony_ci+extern PER_THREAD u8_t tcp_active_pcbs_changed; 4225195972f6Sopenharmony_ci 4226195972f6Sopenharmony_ci /* The TCP PCB lists. */ 4227195972f6Sopenharmony_ci union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ 4228195972f6Sopenharmony_ci struct tcp_pcb_listen *listen_pcbs; 4229195972f6Sopenharmony_ci struct tcp_pcb *pcbs; 4230195972f6Sopenharmony_ci }; 4231195972f6Sopenharmony_ci-extern struct tcp_pcb *tcp_bound_pcbs; 4232195972f6Sopenharmony_ci-extern union tcp_listen_pcbs_t tcp_listen_pcbs; 4233195972f6Sopenharmony_ci-extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a 4234195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_pcb *tcp_bound_pcbs; 4235195972f6Sopenharmony_ci+extern PER_THREAD union tcp_listen_pcbs_t tcp_listen_pcbs; 4236195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a 4237195972f6Sopenharmony_ci state in which they accept or send 4238195972f6Sopenharmony_ci data. */ 4239195972f6Sopenharmony_ci-extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ 4240195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ 4241195972f6Sopenharmony_ci 4242195972f6Sopenharmony_ci #define NUM_TCP_PCB_LISTS_NO_TIME_WAIT 3 4243195972f6Sopenharmony_ci #define NUM_TCP_PCB_LISTS 4 4244195972f6Sopenharmony_ci-extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]; 4245195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_pcb ** tcp_pcb_lists[NUM_TCP_PCB_LISTS]; 4246195972f6Sopenharmony_ci+ 4247195972f6Sopenharmony_ci+#if USE_LIBOS 4248195972f6Sopenharmony_ci+#include "reg_sock.h" 4249195972f6Sopenharmony_ci+static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pcb *pcb) 4250195972f6Sopenharmony_ci+{ 4251195972f6Sopenharmony_ci+ LWIP_ASSERT("Invalid parameter", pcb != NULL); 4252195972f6Sopenharmony_ci+ 4253195972f6Sopenharmony_ci+ struct libnet_quintuple qtuple; 4254195972f6Sopenharmony_ci+ qtuple.protocol = 0; 4255195972f6Sopenharmony_ci+ qtuple.src_ip = pcb->local_ip.addr; 4256195972f6Sopenharmony_ci+ qtuple.src_port = lwip_htons(pcb->local_port); 4257195972f6Sopenharmony_ci+ qtuple.dst_ip = pcb->remote_ip.addr; 4258195972f6Sopenharmony_ci+ qtuple.dst_port = lwip_htons(pcb->remote_port); 4259195972f6Sopenharmony_ci+ 4260195972f6Sopenharmony_ci+ return vdev_reg_xmit(reg_type, &qtuple); 4261195972f6Sopenharmony_ci+} 4262195972f6Sopenharmony_ci+#endif 4263195972f6Sopenharmony_ci 4264195972f6Sopenharmony_ci /* Axioms about the above lists: 4265195972f6Sopenharmony_ci 1) Every TCP PCB that is not CLOSED is in one of the lists. 4266195972f6Sopenharmony_ci@@ -355,6 +372,54 @@ extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]; 4267195972f6Sopenharmony_ci #define TCP_DEBUG_PCB_LISTS 0 4268195972f6Sopenharmony_ci #endif 4269195972f6Sopenharmony_ci #if TCP_DEBUG_PCB_LISTS 4270195972f6Sopenharmony_ci+#if USE_LIBOS 4271195972f6Sopenharmony_ci+#define TCP_REG(pcbs, npcb) do {\ 4272195972f6Sopenharmony_ci+ struct tcp_pcb *tcp_tmp_pcb; \ 4273195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", (npcb), (npcb)->local_port)); \ 4274195972f6Sopenharmony_ci+ for (tcp_tmp_pcb = *(pcbs); \ 4275195972f6Sopenharmony_ci+ tcp_tmp_pcb != NULL; \ 4276195972f6Sopenharmony_ci+ tcp_tmp_pcb = tcp_tmp_pcb->next) { \ 4277195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ 4278195972f6Sopenharmony_ci+ } \ 4279195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ 4280195972f6Sopenharmony_ci+ if (*pcbs) \ 4281195972f6Sopenharmony_ci+ (*pcbs)->prev = npcb; \ 4282195972f6Sopenharmony_ci+ (npcb)->prev = NULL; \ 4283195972f6Sopenharmony_ci+ (npcb)->next = *(pcbs); \ 4284195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ 4285195972f6Sopenharmony_ci+ *(pcbs) = (npcb); \ 4286195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ 4287195972f6Sopenharmony_ci+ tcp_timer_needed(); \ 4288195972f6Sopenharmony_ci+ } while(0) 4289195972f6Sopenharmony_ci+#define TCP_RMV(pcbs, npcb) do { \ 4290195972f6Sopenharmony_ci+ if (pcb->state == LISTEN) \ 4291195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 4292195972f6Sopenharmony_ci+ else \ 4293195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 4294195972f6Sopenharmony_ci+ struct tcp_pcb *tcp_tmp_pcb; \ 4295195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ 4296195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (npcb), *(pcbs))); \ 4297195972f6Sopenharmony_ci+ if(*(pcbs) == (npcb)) { \ 4298195972f6Sopenharmony_ci+ *(pcbs) = (*pcbs)->next; \ 4299195972f6Sopenharmony_ci+ if (*pcbs) \ 4300195972f6Sopenharmony_ci+ (*pcbs)->prev = NULL; \ 4301195972f6Sopenharmony_ci+ } else { \ 4302195972f6Sopenharmony_ci+ struct tcp_pcb *prev, *next; \ 4303195972f6Sopenharmony_ci+ prev = npcb->prev; \ 4304195972f6Sopenharmony_ci+ next = npcb->next; \ 4305195972f6Sopenharmony_ci+ if (prev) \ 4306195972f6Sopenharmony_ci+ prev->next = next; \ 4307195972f6Sopenharmony_ci+ if (next) \ 4308195972f6Sopenharmony_ci+ next->prev = prev; \ 4309195972f6Sopenharmony_ci+ } \ 4310195972f6Sopenharmony_ci+ } \ 4311195972f6Sopenharmony_ci+ (npcb)->prev = NULL; \ 4312195972f6Sopenharmony_ci+ (npcb)->next = NULL; \ 4313195972f6Sopenharmony_ci+ LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ 4314195972f6Sopenharmony_ci+ LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (npcb), *(pcbs))); \ 4315195972f6Sopenharmony_ci+ } while(0) 4316195972f6Sopenharmony_ci+ 4317195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 4318195972f6Sopenharmony_ci #define TCP_REG(pcbs, npcb) do {\ 4319195972f6Sopenharmony_ci struct tcp_pcb *tcp_tmp_pcb; \ 4320195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \ 4321195972f6Sopenharmony_ci@@ -387,8 +452,65 @@ extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]; 4322195972f6Sopenharmony_ci LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ 4323195972f6Sopenharmony_ci } while(0) 4324195972f6Sopenharmony_ci 4325195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4326195972f6Sopenharmony_ci #else /* LWIP_DEBUG */ 4327195972f6Sopenharmony_ci 4328195972f6Sopenharmony_ci+#if TCP_PCB_HASH 4329195972f6Sopenharmony_ci+#define TCP_REG_HASH(pcbs, npcb) \ 4330195972f6Sopenharmony_ci+ do { \ 4331195972f6Sopenharmony_ci+ u32_t idx; \ 4332195972f6Sopenharmony_ci+ struct hlist_head *hd; \ 4333195972f6Sopenharmony_ci+ struct tcp_hash_table *htb = pcbs; \ 4334195972f6Sopenharmony_ci+ idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ 4335195972f6Sopenharmony_ci+ (npcb)->remote_ip.addr, (npcb)->remote_port) & \ 4336195972f6Sopenharmony_ci+ (htb->size - 1); \ 4337195972f6Sopenharmony_ci+ hd = &htb->array[idx].chain; \ 4338195972f6Sopenharmony_ci+ hlist_add_head(&(npcb)->tcp_node, hd); \ 4339195972f6Sopenharmony_ci+ tcp_timer_needed(); \ 4340195972f6Sopenharmony_ci+ } while (0) 4341195972f6Sopenharmony_ci+ 4342195972f6Sopenharmony_ci+#define TCP_RMV_HASH(pcbs, npcb) \ 4343195972f6Sopenharmony_ci+ do { \ 4344195972f6Sopenharmony_ci+ hlist_del_init(&(npcb)->tcp_node); \ 4345195972f6Sopenharmony_ci+ } while (0) 4346195972f6Sopenharmony_ci+#endif /* TCP_PCB_HASH */ 4347195972f6Sopenharmony_ci+ 4348195972f6Sopenharmony_ci+#if USE_LIBOS 4349195972f6Sopenharmony_ci+#define TCP_REG(pcbs, npcb) \ 4350195972f6Sopenharmony_ci+ do { \ 4351195972f6Sopenharmony_ci+ if (*pcbs) \ 4352195972f6Sopenharmony_ci+ (*pcbs)->prev = npcb; \ 4353195972f6Sopenharmony_ci+ (npcb)->prev = NULL; \ 4354195972f6Sopenharmony_ci+ (npcb)->next = *pcbs; \ 4355195972f6Sopenharmony_ci+ *(pcbs) = (npcb); \ 4356195972f6Sopenharmony_ci+ tcp_timer_needed(); \ 4357195972f6Sopenharmony_ci+ } while (0) 4358195972f6Sopenharmony_ci+ 4359195972f6Sopenharmony_ci+#define TCP_RMV(pcbs, npcb) \ 4360195972f6Sopenharmony_ci+ do { \ 4361195972f6Sopenharmony_ci+ if (pcb->state == LISTEN) \ 4362195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_LISTEN_CLOSE, npcb); \ 4363195972f6Sopenharmony_ci+ else \ 4364195972f6Sopenharmony_ci+ vdev_reg_done(REG_RING_TCP_CONNECT_CLOSE, npcb);\ 4365195972f6Sopenharmony_ci+ if(*(pcbs) == (npcb)) { \ 4366195972f6Sopenharmony_ci+ (*(pcbs)) = (*pcbs)->next; \ 4367195972f6Sopenharmony_ci+ if (*pcbs) \ 4368195972f6Sopenharmony_ci+ (*pcbs)->prev = NULL; \ 4369195972f6Sopenharmony_ci+ } \ 4370195972f6Sopenharmony_ci+ else { \ 4371195972f6Sopenharmony_ci+ struct tcp_pcb *prev, *next; \ 4372195972f6Sopenharmony_ci+ prev = npcb->prev; \ 4373195972f6Sopenharmony_ci+ next = npcb->next; \ 4374195972f6Sopenharmony_ci+ if (prev) \ 4375195972f6Sopenharmony_ci+ prev->next = next; \ 4376195972f6Sopenharmony_ci+ if (next) \ 4377195972f6Sopenharmony_ci+ next->prev = prev; \ 4378195972f6Sopenharmony_ci+ } \ 4379195972f6Sopenharmony_ci+ (npcb)->prev = NULL; \ 4380195972f6Sopenharmony_ci+ (npcb)->next = NULL; \ 4381195972f6Sopenharmony_ci+ } while(0) 4382195972f6Sopenharmony_ci+ 4383195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 4384195972f6Sopenharmony_ci #define TCP_REG(pcbs, npcb) \ 4385195972f6Sopenharmony_ci do { \ 4386195972f6Sopenharmony_ci (npcb)->next = *pcbs; \ 4387195972f6Sopenharmony_ci@@ -415,8 +537,32 @@ extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]; 4388195972f6Sopenharmony_ci (npcb)->next = NULL; \ 4389195972f6Sopenharmony_ci } while(0) 4390195972f6Sopenharmony_ci 4391195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4392195972f6Sopenharmony_ci #endif /* LWIP_DEBUG */ 4393195972f6Sopenharmony_ci 4394195972f6Sopenharmony_ci+ 4395195972f6Sopenharmony_ci+#if TCP_PCB_HASH 4396195972f6Sopenharmony_ci+#define TCP_REG_ACTIVE_HASH(npcb) \ 4397195972f6Sopenharmony_ci+ do { \ 4398195972f6Sopenharmony_ci+ TCP_REG_HASH(tcp_active_htable, npcb); \ 4399195972f6Sopenharmony_ci+ tcp_active_pcbs_changed = 1; \ 4400195972f6Sopenharmony_ci+ } while (0) 4401195972f6Sopenharmony_ci+ 4402195972f6Sopenharmony_ci+#define TCP_RMV_ACTIVE_HASH(npcb) \ 4403195972f6Sopenharmony_ci+ do { \ 4404195972f6Sopenharmony_ci+ TCP_RMV_HASH(tcp_active_htable, npcb); \ 4405195972f6Sopenharmony_ci+ tcp_active_pcbs_changed = 1; \ 4406195972f6Sopenharmony_ci+ } while (0) 4407195972f6Sopenharmony_ci+ 4408195972f6Sopenharmony_ci+#define TCP_PCB_REMOVE_ACTIVE_HASH(pcb) \ 4409195972f6Sopenharmony_ci+ do { \ 4410195972f6Sopenharmony_ci+ tcp_pcb_remove_hash(tcp_active_htable, pcb); \ 4411195972f6Sopenharmony_ci+ tcp_active_pcbs_changed = 1; \ 4412195972f6Sopenharmony_ci+ } while (0) 4413195972f6Sopenharmony_ci+ 4414195972f6Sopenharmony_ci+void tcp_pcb_remove_hash(struct tcp_hash_table *htb, struct tcp_pcb *pcb); 4415195972f6Sopenharmony_ci+#endif /* TCP_PCB_HASH */ 4416195972f6Sopenharmony_ci+ 4417195972f6Sopenharmony_ci #define TCP_REG_ACTIVE(npcb) \ 4418195972f6Sopenharmony_ci do { \ 4419195972f6Sopenharmony_ci TCP_REG(&tcp_active_pcbs, npcb); \ 4420195972f6Sopenharmony_cidiff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h 4421195972f6Sopenharmony_ciindex 9347461..c9ad89c 100644 4422195972f6Sopenharmony_ci--- a/src/include/lwip/prot/ip4.h 4423195972f6Sopenharmony_ci+++ b/src/include/lwip/prot/ip4.h 4424195972f6Sopenharmony_ci@@ -81,6 +81,21 @@ struct ip_hdr { 4425195972f6Sopenharmony_ci PACK_STRUCT_FIELD(u16_t _id); 4426195972f6Sopenharmony_ci /* fragment offset field */ 4427195972f6Sopenharmony_ci PACK_STRUCT_FIELD(u16_t _offset); 4428195972f6Sopenharmony_ci+ 4429195972f6Sopenharmony_ci+/* avoid conflicts with netinet/ip.h */ 4430195972f6Sopenharmony_ci+#ifdef IP_RF 4431195972f6Sopenharmony_ci+#undef IP_RF 4432195972f6Sopenharmony_ci+#endif 4433195972f6Sopenharmony_ci+#ifdef IP_DF 4434195972f6Sopenharmony_ci+#undef IP_DF 4435195972f6Sopenharmony_ci+#endif 4436195972f6Sopenharmony_ci+#ifdef IP_MF 4437195972f6Sopenharmony_ci+#undef IP_MF 4438195972f6Sopenharmony_ci+#endif 4439195972f6Sopenharmony_ci+#ifdef IP_OFFMASK 4440195972f6Sopenharmony_ci+#undef IP_OFFMASK 4441195972f6Sopenharmony_ci+#endif 4442195972f6Sopenharmony_ci+ 4443195972f6Sopenharmony_ci #define IP_RF 0x8000U /* reserved fragment flag */ 4444195972f6Sopenharmony_ci #define IP_DF 0x4000U /* don't fragment flag */ 4445195972f6Sopenharmony_ci #define IP_MF 0x2000U /* more fragments flag */ 4446195972f6Sopenharmony_cidiff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h 4447195972f6Sopenharmony_ciindex d70d36c..345e26c 100644 4448195972f6Sopenharmony_ci--- a/src/include/lwip/sockets.h 4449195972f6Sopenharmony_ci+++ b/src/include/lwip/sockets.h 4450195972f6Sopenharmony_ci@@ -57,6 +57,11 @@ extern "C" { 4451195972f6Sopenharmony_ci 4452195972f6Sopenharmony_ci /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED 4453195972f6Sopenharmony_ci to prevent this code from redefining it. */ 4454195972f6Sopenharmony_ci+#if USE_LIBOS 4455195972f6Sopenharmony_ci+#define SA_FAMILY_T_DEFINED 4456195972f6Sopenharmony_ci+ typedef u16_t sa_family_t; 4457195972f6Sopenharmony_ci+#endif 4458195972f6Sopenharmony_ci+ 4459195972f6Sopenharmony_ci #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) 4460195972f6Sopenharmony_ci typedef u8_t sa_family_t; 4461195972f6Sopenharmony_ci #endif 4462195972f6Sopenharmony_ci@@ -69,7 +74,9 @@ typedef u16_t in_port_t; 4463195972f6Sopenharmony_ci #if LWIP_IPV4 4464195972f6Sopenharmony_ci /* members are in network byte order */ 4465195972f6Sopenharmony_ci struct sockaddr_in { 4466195972f6Sopenharmony_ci+#if !USE_LIBOS 4467195972f6Sopenharmony_ci u8_t sin_len; 4468195972f6Sopenharmony_ci+#endif 4469195972f6Sopenharmony_ci sa_family_t sin_family; 4470195972f6Sopenharmony_ci in_port_t sin_port; 4471195972f6Sopenharmony_ci struct in_addr sin_addr; 4472195972f6Sopenharmony_ci@@ -90,7 +97,9 @@ struct sockaddr_in6 { 4473195972f6Sopenharmony_ci #endif /* LWIP_IPV6 */ 4474195972f6Sopenharmony_ci 4475195972f6Sopenharmony_ci struct sockaddr { 4476195972f6Sopenharmony_ci+#if !USE_LIBOS 4477195972f6Sopenharmony_ci u8_t sa_len; 4478195972f6Sopenharmony_ci+#endif 4479195972f6Sopenharmony_ci sa_family_t sa_family; 4480195972f6Sopenharmony_ci char sa_data[14]; 4481195972f6Sopenharmony_ci }; 4482195972f6Sopenharmony_ci@@ -189,6 +198,9 @@ struct ifreq { 4483195972f6Sopenharmony_ci #define SOCK_DGRAM 2 4484195972f6Sopenharmony_ci #define SOCK_RAW 3 4485195972f6Sopenharmony_ci 4486195972f6Sopenharmony_ci+#if USE_LIBOS 4487195972f6Sopenharmony_ci+#include <asm/socket.h> 4488195972f6Sopenharmony_ci+#else 4489195972f6Sopenharmony_ci /* 4490195972f6Sopenharmony_ci * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) 4491195972f6Sopenharmony_ci */ 4492195972f6Sopenharmony_ci@@ -221,6 +233,12 @@ struct ifreq { 4493195972f6Sopenharmony_ci #define SO_BINDTODEVICE 0x100b /* bind to device */ 4494195972f6Sopenharmony_ci 4495195972f6Sopenharmony_ci /* 4496195972f6Sopenharmony_ci+ * Level number for (get/set)sockopt() to apply to socket itself. 4497195972f6Sopenharmony_ci+ */ 4498195972f6Sopenharmony_ci+#define SOL_SOCKET 0xfff /* options for socket level */ 4499195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4500195972f6Sopenharmony_ci+ 4501195972f6Sopenharmony_ci+/* 4502195972f6Sopenharmony_ci * Structure used for manipulating linger option. 4503195972f6Sopenharmony_ci */ 4504195972f6Sopenharmony_ci struct linger { 4505195972f6Sopenharmony_ci@@ -228,11 +246,6 @@ struct linger { 4506195972f6Sopenharmony_ci int l_linger; /* linger time in seconds */ 4507195972f6Sopenharmony_ci }; 4508195972f6Sopenharmony_ci 4509195972f6Sopenharmony_ci-/* 4510195972f6Sopenharmony_ci- * Level number for (get/set)sockopt() to apply to socket itself. 4511195972f6Sopenharmony_ci- */ 4512195972f6Sopenharmony_ci-#define SOL_SOCKET 0xfff /* options for socket level */ 4513195972f6Sopenharmony_ci- 4514195972f6Sopenharmony_ci 4515195972f6Sopenharmony_ci #define AF_UNSPEC 0 4516195972f6Sopenharmony_ci #define AF_INET 2 4517195972f6Sopenharmony_ci@@ -276,11 +289,20 @@ struct linger { 4518195972f6Sopenharmony_ci /* 4519195972f6Sopenharmony_ci * Options for level IPPROTO_TCP 4520195972f6Sopenharmony_ci */ 4521195972f6Sopenharmony_ci+#if USE_LIBOS 4522195972f6Sopenharmony_ci+/* come from netinet/tcp.h */ 4523195972f6Sopenharmony_ci+#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 4524195972f6Sopenharmony_ci+#define TCP_KEEPALIVE 0x24 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ 4525195972f6Sopenharmony_ci+#define TCP_KEEPIDLE 0x04 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ 4526195972f6Sopenharmony_ci+#define TCP_KEEPINTVL 0x05 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ 4527195972f6Sopenharmony_ci+#define TCP_KEEPCNT 0x06 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ 4528195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 4529195972f6Sopenharmony_ci #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 4530195972f6Sopenharmony_ci #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ 4531195972f6Sopenharmony_ci #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ 4532195972f6Sopenharmony_ci #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ 4533195972f6Sopenharmony_ci #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ 4534195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4535195972f6Sopenharmony_ci #endif /* LWIP_TCP */ 4536195972f6Sopenharmony_ci 4537195972f6Sopenharmony_ci #if LWIP_IPV6 4538195972f6Sopenharmony_ci@@ -483,12 +505,30 @@ typedef struct fd_set 4539195972f6Sopenharmony_ci unsigned char fd_bits [(FD_SETSIZE+7)/8]; 4540195972f6Sopenharmony_ci } fd_set; 4541195972f6Sopenharmony_ci 4542195972f6Sopenharmony_ci-#elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) 4543195972f6Sopenharmony_ci+#elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) && !USE_LIBOS 4544195972f6Sopenharmony_ci #error "external FD_SETSIZE too small for number of sockets" 4545195972f6Sopenharmony_ci #else 4546195972f6Sopenharmony_ci #define LWIP_SELECT_MAXNFDS FD_SETSIZE 4547195972f6Sopenharmony_ci #endif /* FD_SET */ 4548195972f6Sopenharmony_ci 4549195972f6Sopenharmony_ci+#if USE_LIBOS 4550195972f6Sopenharmony_ci+#if !defined(POLLIN) && !defined(POLLOUT) 4551195972f6Sopenharmony_ci+/* come from bits/poll.h */ 4552195972f6Sopenharmony_ci+#define POLLIN 0x001 4553195972f6Sopenharmony_ci+#define POLLOUT 0x004 4554195972f6Sopenharmony_ci+#define POLLERR 0x008 4555195972f6Sopenharmony_ci+#define POLLNVAL 0x020 4556195972f6Sopenharmony_ci+/* Below values are unimplemented */ 4557195972f6Sopenharmony_ci+#define POLLRDNORM 0x040 4558195972f6Sopenharmony_ci+#define POLLRDBAND 0x080 4559195972f6Sopenharmony_ci+#define POLLPRI 0x002 4560195972f6Sopenharmony_ci+#define POLLWRNORM 0x100 4561195972f6Sopenharmony_ci+#define POLLWRBAND 0x200 4562195972f6Sopenharmony_ci+#define POLLHUP 0x010 4563195972f6Sopenharmony_ci+#endif 4564195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4565195972f6Sopenharmony_ci+ 4566195972f6Sopenharmony_ci+#if LWIP_SOCKET_POLL 4567195972f6Sopenharmony_ci /* poll-related defines and types */ 4568195972f6Sopenharmony_ci /* @todo: find a better way to guard the definition of these defines and types if already defined */ 4569195972f6Sopenharmony_ci #if !defined(POLLIN) && !defined(POLLOUT) 4570195972f6Sopenharmony_ci@@ -511,6 +551,7 @@ struct pollfd 4571195972f6Sopenharmony_ci short revents; 4572195972f6Sopenharmony_ci }; 4573195972f6Sopenharmony_ci #endif 4574195972f6Sopenharmony_ci+#endif /* LWIP_SOCKET_POLL */ 4575195972f6Sopenharmony_ci 4576195972f6Sopenharmony_ci /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided 4577195972f6Sopenharmony_ci * by your system, set this to 0 and include <sys/time.h> in cc.h */ 4578195972f6Sopenharmony_ci@@ -603,8 +644,15 @@ int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptse 4579195972f6Sopenharmony_ci #if LWIP_SOCKET_POLL 4580195972f6Sopenharmony_ci int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); 4581195972f6Sopenharmony_ci #endif 4582195972f6Sopenharmony_ci+ 4583195972f6Sopenharmony_ci+#if USE_LIBOS 4584195972f6Sopenharmony_ci+int lwip_ioctl(int s, long cmd, ...); 4585195972f6Sopenharmony_ci+int lwip_fcntl(int s, int cmd, ...); 4586195972f6Sopenharmony_ci+#else 4587195972f6Sopenharmony_ci int lwip_ioctl(int s, long cmd, void *argp); 4588195972f6Sopenharmony_ci int lwip_fcntl(int s, int cmd, int val); 4589195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4590195972f6Sopenharmony_ci+ 4591195972f6Sopenharmony_ci const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); 4592195972f6Sopenharmony_ci int lwip_inet_pton(int af, const char *src, void *dst); 4593195972f6Sopenharmony_ci 4594195972f6Sopenharmony_ci@@ -670,10 +718,17 @@ int lwip_inet_pton(int af, const char *src, void *dst); 4595195972f6Sopenharmony_ci #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) 4596195972f6Sopenharmony_ci /** @ingroup socket */ 4597195972f6Sopenharmony_ci #define close(s) lwip_close(s) 4598195972f6Sopenharmony_ci+ 4599195972f6Sopenharmony_ci+#if USE_LIBOS 4600195972f6Sopenharmony_ci+#define fcntl(s,cmd...) lwip_fcntl(s,cmd) 4601195972f6Sopenharmony_ci+#define ioctl(s,cmd...) lwip_ioctl(s,cmd) 4602195972f6Sopenharmony_ci+#else 4603195972f6Sopenharmony_ci /** @ingroup socket */ 4604195972f6Sopenharmony_ci #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) 4605195972f6Sopenharmony_ci /** @ingroup socket */ 4606195972f6Sopenharmony_ci #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) 4607195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4608195972f6Sopenharmony_ci+ 4609195972f6Sopenharmony_ci #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ 4610195972f6Sopenharmony_ci #endif /* LWIP_COMPAT_SOCKETS != 2 */ 4611195972f6Sopenharmony_ci 4612195972f6Sopenharmony_cidiff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h 4613195972f6Sopenharmony_ciindex b570dba..4470531 100644 4614195972f6Sopenharmony_ci--- a/src/include/lwip/stats.h 4615195972f6Sopenharmony_ci+++ b/src/include/lwip/stats.h 4616195972f6Sopenharmony_ci@@ -301,7 +301,7 @@ struct stats_ { 4617195972f6Sopenharmony_ci }; 4618195972f6Sopenharmony_ci 4619195972f6Sopenharmony_ci /** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */ 4620195972f6Sopenharmony_ci-extern struct stats_ lwip_stats; 4621195972f6Sopenharmony_ci+extern PER_THREAD struct stats_ lwip_stats; 4622195972f6Sopenharmony_ci 4623195972f6Sopenharmony_ci /** Init statistics */ 4624195972f6Sopenharmony_ci void stats_init(void); 4625195972f6Sopenharmony_ci@@ -467,6 +467,8 @@ void stats_init(void); 4626195972f6Sopenharmony_ci #define MIB2_STATS_INC(x) 4627195972f6Sopenharmony_ci #endif 4628195972f6Sopenharmony_ci 4629195972f6Sopenharmony_ci+int get_mib2_stats(char *buf); 4630195972f6Sopenharmony_ci+ 4631195972f6Sopenharmony_ci /* Display of statistics */ 4632195972f6Sopenharmony_ci #if LWIP_STATS_DISPLAY 4633195972f6Sopenharmony_ci void stats_display(void); 4634195972f6Sopenharmony_cidiff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h 4635195972f6Sopenharmony_ciindex daf7599..4f86b46 100644 4636195972f6Sopenharmony_ci--- a/src/include/lwip/tcp.h 4637195972f6Sopenharmony_ci+++ b/src/include/lwip/tcp.h 4638195972f6Sopenharmony_ci@@ -51,6 +51,11 @@ 4639195972f6Sopenharmony_ci #include "lwip/ip6.h" 4640195972f6Sopenharmony_ci #include "lwip/ip6_addr.h" 4641195972f6Sopenharmony_ci 4642195972f6Sopenharmony_ci+#if TCP_PCB_HASH 4643195972f6Sopenharmony_ci+#include "lwip/sys.h" 4644195972f6Sopenharmony_ci+#include "hlist.h" 4645195972f6Sopenharmony_ci+#endif 4646195972f6Sopenharmony_ci+ 4647195972f6Sopenharmony_ci #ifdef __cplusplus 4648195972f6Sopenharmony_ci extern "C" { 4649195972f6Sopenharmony_ci #endif 4650195972f6Sopenharmony_ci@@ -209,15 +214,27 @@ typedef u16_t tcpflags_t; 4651195972f6Sopenharmony_ci /** 4652195972f6Sopenharmony_ci * members common to struct tcp_pcb and struct tcp_listen_pcb 4653195972f6Sopenharmony_ci */ 4654195972f6Sopenharmony_ci+#if USE_LIBOS 4655195972f6Sopenharmony_ci #define TCP_PCB_COMMON(type) \ 4656195972f6Sopenharmony_ci type *next; /* for the linked list */ \ 4657195972f6Sopenharmony_ci+ type *prev; /* for the linked list */ \ 4658195972f6Sopenharmony_ci void *callback_arg; \ 4659195972f6Sopenharmony_ci TCP_PCB_EXTARGS \ 4660195972f6Sopenharmony_ci enum tcp_state state; /* TCP state */ \ 4661195972f6Sopenharmony_ci u8_t prio; \ 4662195972f6Sopenharmony_ci /* ports are in host byte order */ \ 4663195972f6Sopenharmony_ci u16_t local_port 4664195972f6Sopenharmony_ci- 4665195972f6Sopenharmony_ci+ 4666195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 4667195972f6Sopenharmony_ci+#define TCP_PCB_COMMON(type) \ 4668195972f6Sopenharmony_ci+ type *next; /* for the linked list */ \ 4669195972f6Sopenharmony_ci+ void *callback_arg; \ 4670195972f6Sopenharmony_ci+ TCP_PCB_EXTARGS \ 4671195972f6Sopenharmony_ci+ enum tcp_state state; /* TCP state */ \ 4672195972f6Sopenharmony_ci+ u8_t prio; \ 4673195972f6Sopenharmony_ci+ /* ports are in host byte order */ \ 4674195972f6Sopenharmony_ci+ u16_t local_port 4675195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4676195972f6Sopenharmony_ci 4677195972f6Sopenharmony_ci /** the TCP protocol control block for listening pcbs */ 4678195972f6Sopenharmony_ci struct tcp_pcb_listen { 4679195972f6Sopenharmony_ci@@ -244,6 +261,9 @@ struct tcp_pcb { 4680195972f6Sopenharmony_ci IP_PCB; 4681195972f6Sopenharmony_ci /** protocol specific PCB members */ 4682195972f6Sopenharmony_ci TCP_PCB_COMMON(struct tcp_pcb); 4683195972f6Sopenharmony_ci+#if TCP_PCB_HASH 4684195972f6Sopenharmony_ci+ struct hlist_node tcp_node; 4685195972f6Sopenharmony_ci+#endif 4686195972f6Sopenharmony_ci 4687195972f6Sopenharmony_ci /* ports are in host byte order */ 4688195972f6Sopenharmony_ci u16_t remote_port; 4689195972f6Sopenharmony_ci@@ -388,6 +408,58 @@ struct tcp_pcb { 4690195972f6Sopenharmony_ci #endif 4691195972f6Sopenharmony_ci }; 4692195972f6Sopenharmony_ci 4693195972f6Sopenharmony_ci+#if TCP_PCB_HASH 4694195972f6Sopenharmony_ci+#define TCP_HTABLE_SIZE MEMP_NUM_NETCONN*12 4695195972f6Sopenharmony_ci+ 4696195972f6Sopenharmony_ci+struct tcp_hashbucket 4697195972f6Sopenharmony_ci+{ 4698195972f6Sopenharmony_ci+ sys_mutex_t mutex; 4699195972f6Sopenharmony_ci+ struct hlist_head chain; 4700195972f6Sopenharmony_ci+}; 4701195972f6Sopenharmony_ci+ 4702195972f6Sopenharmony_ci+struct tcp_hash_table 4703195972f6Sopenharmony_ci+{ 4704195972f6Sopenharmony_ci+ u32_t size; 4705195972f6Sopenharmony_ci+ struct tcp_hashbucket array[TCP_HTABLE_SIZE]; 4706195972f6Sopenharmony_ci+}; 4707195972f6Sopenharmony_ci+ 4708195972f6Sopenharmony_ci+extern PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */ 4709195972f6Sopenharmony_ci+ 4710195972f6Sopenharmony_ci+#define JHASH_INITVAL 0xdeadbeef 4711195972f6Sopenharmony_ci+ 4712195972f6Sopenharmony_ci+static inline unsigned int rol32(unsigned int word, unsigned int shift) 4713195972f6Sopenharmony_ci+{ 4714195972f6Sopenharmony_ci+ return (word << shift) | (word >> (32 - shift)); 4715195972f6Sopenharmony_ci+} 4716195972f6Sopenharmony_ci+ 4717195972f6Sopenharmony_ci+#define __jhash_final(a, b, c) \ 4718195972f6Sopenharmony_ci+{ \ 4719195972f6Sopenharmony_ci+ c ^= b; c -= rol32(b, 14); \ 4720195972f6Sopenharmony_ci+ a ^= c; a -= rol32(c, 11); \ 4721195972f6Sopenharmony_ci+ b ^= a; b -= rol32(a, 25); \ 4722195972f6Sopenharmony_ci+ c ^= b; c -= rol32(b, 16); \ 4723195972f6Sopenharmony_ci+ a ^= c; a -= rol32(c, 4); \ 4724195972f6Sopenharmony_ci+ b ^= a; b -= rol32(a, 14); \ 4725195972f6Sopenharmony_ci+ c ^= b; c -= rol32(b, 24); \ 4726195972f6Sopenharmony_ci+} 4727195972f6Sopenharmony_ci+ 4728195972f6Sopenharmony_ci+static inline unsigned int jhash_3words(unsigned int a, unsigned int b, unsigned int c) 4729195972f6Sopenharmony_ci+{ 4730195972f6Sopenharmony_ci+ a += JHASH_INITVAL; 4731195972f6Sopenharmony_ci+ b += JHASH_INITVAL;; 4732195972f6Sopenharmony_ci+ 4733195972f6Sopenharmony_ci+ __jhash_final(a, b, c); 4734195972f6Sopenharmony_ci+ 4735195972f6Sopenharmony_ci+ return c; 4736195972f6Sopenharmony_ci+} 4737195972f6Sopenharmony_ci+ 4738195972f6Sopenharmony_ci+#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) 4739195972f6Sopenharmony_ci+ 4740195972f6Sopenharmony_ci+#define tcppcb_hlist_for_each(tcppcb, node, list) \ 4741195972f6Sopenharmony_ci+ hlist_for_each_entry(tcppcb, node, list, tcp_node) 4742195972f6Sopenharmony_ci+ 4743195972f6Sopenharmony_ci+#endif /* TCP_PCB_HASH */ 4744195972f6Sopenharmony_ci+ 4745195972f6Sopenharmony_ci #if LWIP_EVENT_API 4746195972f6Sopenharmony_ci 4747195972f6Sopenharmony_ci enum lwip_event { 4748195972f6Sopenharmony_ci@@ -481,6 +553,26 @@ err_t tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_add 4749195972f6Sopenharmony_ci 4750195972f6Sopenharmony_ci #define tcp_dbg_get_tcp_state(pcb) ((pcb)->state) 4751195972f6Sopenharmony_ci 4752195972f6Sopenharmony_ci+enum tcp_list_state { 4753195972f6Sopenharmony_ci+ ACTIVE_LIST, 4754195972f6Sopenharmony_ci+ LISTEN_LIST, 4755195972f6Sopenharmony_ci+ TIME_WAIT_LIST, 4756195972f6Sopenharmony_ci+}; 4757195972f6Sopenharmony_ci+ 4758195972f6Sopenharmony_ci+struct tcp_pcb_dp { 4759195972f6Sopenharmony_ci+ uint32_t state; 4760195972f6Sopenharmony_ci+ uint32_t lip; 4761195972f6Sopenharmony_ci+ uint32_t rip; 4762195972f6Sopenharmony_ci+ uint16_t l_port; 4763195972f6Sopenharmony_ci+ uint16_t r_port; 4764195972f6Sopenharmony_ci+ uint32_t r_next; 4765195972f6Sopenharmony_ci+ uint32_t s_next; 4766195972f6Sopenharmony_ci+ uint32_t tcp_sub_state; 4767195972f6Sopenharmony_ci+}; 4768195972f6Sopenharmony_ci+ 4769195972f6Sopenharmony_ci+void tcp_get_conn(char *buf, int32_t len, uint32_t *conn_num); 4770195972f6Sopenharmony_ci+uint32_t tcp_get_conn_num(void); 4771195972f6Sopenharmony_ci+ 4772195972f6Sopenharmony_ci /* for compatibility with older implementation */ 4773195972f6Sopenharmony_ci #define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6) 4774195972f6Sopenharmony_ci 4775195972f6Sopenharmony_cidiff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h 4776195972f6Sopenharmony_ciindex 0b8880a..d2c2440 100644 4777195972f6Sopenharmony_ci--- a/src/include/lwip/tcpip.h 4778195972f6Sopenharmony_ci+++ b/src/include/lwip/tcpip.h 4779195972f6Sopenharmony_ci@@ -51,7 +51,7 @@ extern "C" { 4780195972f6Sopenharmony_ci 4781195972f6Sopenharmony_ci #if LWIP_TCPIP_CORE_LOCKING 4782195972f6Sopenharmony_ci /** The global semaphore to lock the stack. */ 4783195972f6Sopenharmony_ci-extern sys_mutex_t lock_tcpip_core; 4784195972f6Sopenharmony_ci+extern PER_THREAD sys_mutex_t lock_tcpip_core; 4785195972f6Sopenharmony_ci #if !defined LOCK_TCPIP_CORE || defined __DOXYGEN__ 4786195972f6Sopenharmony_ci /** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ 4787195972f6Sopenharmony_ci #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) 4788195972f6Sopenharmony_cidiff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h 4789195972f6Sopenharmony_ciindex b601f9e..b451554 100644 4790195972f6Sopenharmony_ci--- a/src/include/lwip/timeouts.h 4791195972f6Sopenharmony_ci+++ b/src/include/lwip/timeouts.h 4792195972f6Sopenharmony_ci@@ -119,6 +119,10 @@ struct sys_timeo** sys_timeouts_get_next_timeout(void); 4793195972f6Sopenharmony_ci void lwip_cyclic_timer(void *arg); 4794195972f6Sopenharmony_ci #endif 4795195972f6Sopenharmony_ci 4796195972f6Sopenharmony_ci+#if USE_LIBOS 4797195972f6Sopenharmony_ci+void sys_timer_run(void); 4798195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 4799195972f6Sopenharmony_ci+ 4800195972f6Sopenharmony_ci #endif /* LWIP_TIMERS */ 4801195972f6Sopenharmony_ci 4802195972f6Sopenharmony_ci #ifdef __cplusplus 4803195972f6Sopenharmony_cidiff --git a/src/include/lwiplog.h b/src/include/lwiplog.h 4804195972f6Sopenharmony_cinew file mode 100644 4805195972f6Sopenharmony_ciindex 0000000..363e516 4806195972f6Sopenharmony_ci--- /dev/null 4807195972f6Sopenharmony_ci+++ b/src/include/lwiplog.h 4808195972f6Sopenharmony_ci@@ -0,0 +1,81 @@ 4809195972f6Sopenharmony_ci+/* 4810195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 4811195972f6Sopenharmony_ci+ * All rights reserved. 4812195972f6Sopenharmony_ci+ * 4813195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 4814195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 4815195972f6Sopenharmony_ci+ * 4816195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 4817195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 4818195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 4819195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 4820195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 4821195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 4822195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 4823195972f6Sopenharmony_ci+ * 4824195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 4825195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 4826195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 4827195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 4828195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 4829195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4830195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4831195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4832195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 4833195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 4834195972f6Sopenharmony_ci+ * 4835195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 4836195972f6Sopenharmony_ci+ * 4837195972f6Sopenharmony_ci+ * Author: Huawei Technologies 4838195972f6Sopenharmony_ci+ * 4839195972f6Sopenharmony_ci+ */ 4840195972f6Sopenharmony_ci+ 4841195972f6Sopenharmony_ci+#ifndef __LWIPLOG_H__ 4842195972f6Sopenharmony_ci+#define __LWIPLOG_H__ 4843195972f6Sopenharmony_ci+ 4844195972f6Sopenharmony_ci+#include <stdio.h> 4845195972f6Sopenharmony_ci+#include <sys/syscall.h> 4846195972f6Sopenharmony_ci+ 4847195972f6Sopenharmony_ci+#include <rte_log.h> 4848195972f6Sopenharmony_ci+ 4849195972f6Sopenharmony_ci+#include "lwipopts.h" 4850195972f6Sopenharmony_ci+ 4851195972f6Sopenharmony_ci+#define gettid() syscall(__NR_gettid) 4852195972f6Sopenharmony_ci+ 4853195972f6Sopenharmony_ci+#if USE_DPDK_LOG 4854195972f6Sopenharmony_ci+ 4855195972f6Sopenharmony_ci+#define LWIP_LOG_WARN LWIP_DBG_LEVEL_WARNING 4856195972f6Sopenharmony_ci+#define LWIP_LOG_ERROR LWIP_DBG_LEVEL_SERIOUS 4857195972f6Sopenharmony_ci+#define LWIP_LOG_FATAL LWIP_DBG_LEVEL_SEVERE 4858195972f6Sopenharmony_ci+ 4859195972f6Sopenharmony_ci+#define LWIP_PLATFORM_LOG(level, fmt, ...) \ 4860195972f6Sopenharmony_ci+do { \ 4861195972f6Sopenharmony_ci+ if ((level) & LWIP_LOG_FATAL) { \ 4862195972f6Sopenharmony_ci+ RTE_LOG(ERR, EAL, fmt, ##__VA_ARGS__); \ 4863195972f6Sopenharmony_ci+ abort(); \ 4864195972f6Sopenharmony_ci+ } else if ((level) & LWIP_LOG_ERROR) { \ 4865195972f6Sopenharmony_ci+ RTE_LOG(ERR, EAL, fmt, ##__VA_ARGS__); \ 4866195972f6Sopenharmony_ci+ } else if ((level) & LWIP_LOG_WARN) { \ 4867195972f6Sopenharmony_ci+ RTE_LOG(WARNING, EAL, fmt, ##__VA_ARGS__); \ 4868195972f6Sopenharmony_ci+ } else { \ 4869195972f6Sopenharmony_ci+ RTE_LOG(INFO, EAL, fmt, ##__VA_ARGS__); \ 4870195972f6Sopenharmony_ci+ } \ 4871195972f6Sopenharmony_ci+} while(0) 4872195972f6Sopenharmony_ci+ 4873195972f6Sopenharmony_ci+ 4874195972f6Sopenharmony_ci+#define LWIP_PLATFORM_DIAG(x) 4875195972f6Sopenharmony_ci+ 4876195972f6Sopenharmony_ci+#define ESC_ARGS(...) __VA_ARGS__ 4877195972f6Sopenharmony_ci+#define STRIP_BRACES(args) args 4878195972f6Sopenharmony_ci+ 4879195972f6Sopenharmony_ci+#define LWIP_PLATFORM_ASSERT(x) \ 4880195972f6Sopenharmony_ci+do { LWIP_PLATFORM_LOG(LWIP_LOG_FATAL, "Assertion \"%s\" failed at line %d in %s\n", \ 4881195972f6Sopenharmony_ci+ x, __LINE__, __FILE__); abort();} while(0) 4882195972f6Sopenharmony_ci+ 4883195972f6Sopenharmony_ci+#else 4884195972f6Sopenharmony_ci+ 4885195972f6Sopenharmony_ci+#define LWIP_PLATFORM_LOG(debug, message) 4886195972f6Sopenharmony_ci+ 4887195972f6Sopenharmony_ci+#endif /* USE_DPDK_LOG */ 4888195972f6Sopenharmony_ci+ 4889195972f6Sopenharmony_ci+#endif /* __LWIPLOG_H__ */ 4890195972f6Sopenharmony_cidiff --git a/src/include/lwipopts.h b/src/include/lwipopts.h 4891195972f6Sopenharmony_ciindex 4ab26f2..8893a5f 100644 4892195972f6Sopenharmony_ci--- a/src/include/lwipopts.h 4893195972f6Sopenharmony_ci+++ b/src/include/lwipopts.h 4894195972f6Sopenharmony_ci@@ -1,8 +1,8 @@ 4895195972f6Sopenharmony_ci /* 4896195972f6Sopenharmony_ci- * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 4897195972f6Sopenharmony_ci- * All rights reserved. 4898195972f6Sopenharmony_ci- * 4899195972f6Sopenharmony_ci- * Redistribution and use in source and binary forms, with or without modification, 4900195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 4901195972f6Sopenharmony_ci+ * All rights reserved. 4902195972f6Sopenharmony_ci+ * 4903195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 4904195972f6Sopenharmony_ci * are permitted provided that the following conditions are met: 4905195972f6Sopenharmony_ci * 4906195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, 4907195972f6Sopenharmony_ci@@ -11,70 +11,193 @@ 4908195972f6Sopenharmony_ci * this list of conditions and the following disclaimer in the documentation 4909195972f6Sopenharmony_ci * and/or other materials provided with the distribution. 4910195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products 4911195972f6Sopenharmony_ci- * derived from this software without specific prior written permission. 4912195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 4913195972f6Sopenharmony_ci * 4914195972f6Sopenharmony_ci- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 4915195972f6Sopenharmony_ci- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 4916195972f6Sopenharmony_ci- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 4917195972f6Sopenharmony_ci- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 4918195972f6Sopenharmony_ci- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 4919195972f6Sopenharmony_ci- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4920195972f6Sopenharmony_ci- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4921195972f6Sopenharmony_ci- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4922195972f6Sopenharmony_ci- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 4923195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 4924195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 4925195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 4926195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 4927195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 4928195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4929195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4930195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4931195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 4932195972f6Sopenharmony_ci * OF SUCH DAMAGE. 4933195972f6Sopenharmony_ci * 4934195972f6Sopenharmony_ci * This file is part of the lwIP TCP/IP stack. 4935195972f6Sopenharmony_ci- * 4936195972f6Sopenharmony_ci- * Author: Simon Goldschmidt 4937195972f6Sopenharmony_ci+ * 4938195972f6Sopenharmony_ci+ * Author: Huawei Technologies 4939195972f6Sopenharmony_ci * 4940195972f6Sopenharmony_ci */ 4941195972f6Sopenharmony_ci-#ifndef LWIP_HDR_LWIPOPTS_H__ 4942195972f6Sopenharmony_ci-#define LWIP_HDR_LWIPOPTS_H__ 4943195972f6Sopenharmony_ci- 4944195972f6Sopenharmony_ci-/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */ 4945195972f6Sopenharmony_ci-#define NO_SYS 1 4946195972f6Sopenharmony_ci-#define LWIP_NETCONN 0 4947195972f6Sopenharmony_ci-#define LWIP_SOCKET 0 4948195972f6Sopenharmony_ci-#define SYS_LIGHTWEIGHT_PROT 0 4949195972f6Sopenharmony_ci- 4950195972f6Sopenharmony_ci-#define LWIP_IPV6 1 4951195972f6Sopenharmony_ci-#define IPV6_FRAG_COPYHEADER 1 4952195972f6Sopenharmony_ci-#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0 4953195972f6Sopenharmony_ci- 4954195972f6Sopenharmony_ci-/* Enable some protocols to test them */ 4955195972f6Sopenharmony_ci-#define LWIP_DHCP 1 4956195972f6Sopenharmony_ci-#define LWIP_AUTOIP 1 4957195972f6Sopenharmony_ci- 4958195972f6Sopenharmony_ci-#define LWIP_IGMP 1 4959195972f6Sopenharmony_ci-#define LWIP_DNS 1 4960195972f6Sopenharmony_ci- 4961195972f6Sopenharmony_ci-#define LWIP_ALTCP 1 4962195972f6Sopenharmony_ci- 4963195972f6Sopenharmony_ci-/* Turn off checksum verification of fuzzed data */ 4964195972f6Sopenharmony_ci-#define CHECKSUM_CHECK_IP 0 4965195972f6Sopenharmony_ci-#define CHECKSUM_CHECK_UDP 0 4966195972f6Sopenharmony_ci-#define CHECKSUM_CHECK_TCP 0 4967195972f6Sopenharmony_ci-#define CHECKSUM_CHECK_ICMP 0 4968195972f6Sopenharmony_ci-#define CHECKSUM_CHECK_ICMP6 0 4969195972f6Sopenharmony_ci- 4970195972f6Sopenharmony_ci-/* Minimal changes to opt.h required for tcp unit tests: */ 4971195972f6Sopenharmony_ci-#define MEM_SIZE 16000 4972195972f6Sopenharmony_ci-#define TCP_SND_QUEUELEN 40 4973195972f6Sopenharmony_ci-#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN 4974195972f6Sopenharmony_ci-#define TCP_OVERSIZE 1 4975195972f6Sopenharmony_ci-#define TCP_SND_BUF (12 * TCP_MSS) 4976195972f6Sopenharmony_ci-#define TCP_WND (10 * TCP_MSS) 4977195972f6Sopenharmony_ci-#define LWIP_WND_SCALE 1 4978195972f6Sopenharmony_ci-#define TCP_RCV_SCALE 2 4979195972f6Sopenharmony_ci-#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */ 4980195972f6Sopenharmony_ci- 4981195972f6Sopenharmony_ci-/* Minimal changes to opt.h required for etharp unit tests: */ 4982195972f6Sopenharmony_ci-#define ETHARP_SUPPORT_STATIC_ENTRIES 1 4983195972f6Sopenharmony_ci- 4984195972f6Sopenharmony_ci-#define LWIP_NUM_NETIF_CLIENT_DATA 1 4985195972f6Sopenharmony_ci-#define LWIP_SNMP 1 4986195972f6Sopenharmony_ci-#define MIB2_STATS 1 4987195972f6Sopenharmony_ci-#define LWIP_MDNS_RESPONDER 1 4988195972f6Sopenharmony_ci- 4989195972f6Sopenharmony_ci-#endif /* LWIP_HDR_LWIPOPTS_H__ */ 4990195972f6Sopenharmony_ci+ 4991195972f6Sopenharmony_ci+#ifndef __LWIPOPTS_H__ 4992195972f6Sopenharmony_ci+#define __LWIPOPTS_H__ 4993195972f6Sopenharmony_ci+ 4994195972f6Sopenharmony_ci+#define LWIP_TCPIP_CORE_LOCKING 1 4995195972f6Sopenharmony_ci+ 4996195972f6Sopenharmony_ci+#define LWIP_NETCONN_SEM_PER_THREAD 0 4997195972f6Sopenharmony_ci+ 4998195972f6Sopenharmony_ci+#define LWIP_TCP 1 4999195972f6Sopenharmony_ci+ 5000195972f6Sopenharmony_ci+#define LWIP_SO_SENTIMEO 0 5001195972f6Sopenharmony_ci+ 5002195972f6Sopenharmony_ci+#define LIP_SO_LINGER 0 5003195972f6Sopenharmony_ci+ 5004195972f6Sopenharmony_ci+#define MEMP_USE_CUSTOM_POOLS 0 5005195972f6Sopenharmony_ci+#define MEM_USE_POOLS 0 5006195972f6Sopenharmony_ci+ 5007195972f6Sopenharmony_ci+#define PER_TCP_PCB_BUFFER (16 * 128) 5008195972f6Sopenharmony_ci+ 5009195972f6Sopenharmony_ci+#define MAX_CLIENTS (20000) 5010195972f6Sopenharmony_ci+ 5011195972f6Sopenharmony_ci+#define RESERVED_CLIENTS (2000) 5012195972f6Sopenharmony_ci+ 5013195972f6Sopenharmony_ci+#define MEMP_NUM_TCP_PCB (MAX_CLIENTS + RESERVED_CLIENTS) 5014195972f6Sopenharmony_ci+ 5015195972f6Sopenharmony_ci+/* we use PBUF_POOL instead of PBUF_RAM in tcp_write, so reduce PBUF_RAM size, 5016195972f6Sopenharmony_ci+ * and do NOT let PBUF_POOL_BUFSIZE less then TCP_MSS 5017195972f6Sopenharmony_ci+*/ 5018195972f6Sopenharmony_ci+#define MEM_SIZE (((PER_TCP_PCB_BUFFER + 128) * MEMP_NUM_TCP_SEG) >> 2) 5019195972f6Sopenharmony_ci+ 5020195972f6Sopenharmony_ci+#define MEMP_NUM_TCP_PCB_LISTEN 3000 5021195972f6Sopenharmony_ci+ 5022195972f6Sopenharmony_ci+#define MEMP_NUM_TCP_SEG (128 * 128 * 2) 5023195972f6Sopenharmony_ci+ 5024195972f6Sopenharmony_ci+#define MEMP_NUM_NETCONN (MAX_CLIENTS + RESERVED_CLIENTS) 5025195972f6Sopenharmony_ci+ 5026195972f6Sopenharmony_ci+#define MEMP_NUM_SYS_SEM (MAX_CLIENTS + RESERVED_CLIENTS) 5027195972f6Sopenharmony_ci+ 5028195972f6Sopenharmony_ci+#define MEMP_NUM_SYS_MBOX (MAX_CLIENTS + RESERVED_CLIENTS) 5029195972f6Sopenharmony_ci+ 5030195972f6Sopenharmony_ci+#define PBUF_POOL_SIZE (MAX_CLIENTS * 2) 5031195972f6Sopenharmony_ci+ 5032195972f6Sopenharmony_ci+#define MEMP_MEM_MALLOC 0 5033195972f6Sopenharmony_ci+ 5034195972f6Sopenharmony_ci+#define LWIP_ARP 1 5035195972f6Sopenharmony_ci+ 5036195972f6Sopenharmony_ci+#define ETHARP_SUPPORT_STATIC_ENTRIES 1 5037195972f6Sopenharmony_ci+ 5038195972f6Sopenharmony_ci+#define LWIP_IPV4 1 5039195972f6Sopenharmony_ci+ 5040195972f6Sopenharmony_ci+#define IP_FORWARD 0 5041195972f6Sopenharmony_ci+ 5042195972f6Sopenharmony_ci+#define IP_REASSEMBLY 1 5043195972f6Sopenharmony_ci+ 5044195972f6Sopenharmony_ci+#define LWIP_UDP 0 5045195972f6Sopenharmony_ci+ 5046195972f6Sopenharmony_ci+#define LWIP_TCP 1 5047195972f6Sopenharmony_ci+ 5048195972f6Sopenharmony_ci+#define IP_HLEN 20 5049195972f6Sopenharmony_ci+ 5050195972f6Sopenharmony_ci+#define TCP_HLEN 20 5051195972f6Sopenharmony_ci+ 5052195972f6Sopenharmony_ci+#define FRAME_MTU 1500 5053195972f6Sopenharmony_ci+ 5054195972f6Sopenharmony_ci+#define TCP_MSS (FRAME_MTU - IP_HLEN - TCP_HLEN) 5055195972f6Sopenharmony_ci+ 5056195972f6Sopenharmony_ci+#define TCP_WND (40 * TCP_MSS) 5057195972f6Sopenharmony_ci+ 5058195972f6Sopenharmony_ci+#define TCP_SND_BUF (5 * TCP_MSS) 5059195972f6Sopenharmony_ci+ 5060195972f6Sopenharmony_ci+#define TCP_SND_QUEUELEN (8191) 5061195972f6Sopenharmony_ci+ 5062195972f6Sopenharmony_ci+#define TCP_SNDLOWAT (TCP_SND_BUF / 5) 5063195972f6Sopenharmony_ci+ 5064195972f6Sopenharmony_ci+#define TCP_SNDQUEUELOWAT (TCP_SND_QUEUELEN / 5) 5065195972f6Sopenharmony_ci+ 5066195972f6Sopenharmony_ci+#define TCP_LISTEN_BACKLOG 1 5067195972f6Sopenharmony_ci+ 5068195972f6Sopenharmony_ci+#define TCP_DEFAULT_LISTEN_BACKLOG 0xff 5069195972f6Sopenharmony_ci+ 5070195972f6Sopenharmony_ci+#define TCP_OVERSIZE 0 5071195972f6Sopenharmony_ci+ 5072195972f6Sopenharmony_ci+#define LWIP_NETIF_API 1 5073195972f6Sopenharmony_ci+ 5074195972f6Sopenharmony_ci+#define DEFAULT_TCP_RECVMBOX_SIZE 128 5075195972f6Sopenharmony_ci+ 5076195972f6Sopenharmony_ci+#define DEFAULT_ACCEPTMBOX_SIZE 1024 5077195972f6Sopenharmony_ci+ 5078195972f6Sopenharmony_ci+#define LWIP_NETCONN 1 5079195972f6Sopenharmony_ci+ 5080195972f6Sopenharmony_ci+#define LWIP_TCPIP_TIMEOUT 0 5081195972f6Sopenharmony_ci+ 5082195972f6Sopenharmony_ci+#define LWIP_SOCKET 1 5083195972f6Sopenharmony_ci+ 5084195972f6Sopenharmony_ci+#define LWIP_TCP_KEEPALIVE 1 5085195972f6Sopenharmony_ci+ 5086195972f6Sopenharmony_ci+#define LWIP_STATS 1 5087195972f6Sopenharmony_ci+ 5088195972f6Sopenharmony_ci+#define LWIP_STATS_DISPLAY 1 5089195972f6Sopenharmony_ci+ 5090195972f6Sopenharmony_ci+#define CHECKSUM_GEN_IP 1 /* master switch */ 5091195972f6Sopenharmony_ci+ 5092195972f6Sopenharmony_ci+#define CHECKSUM_GEN_TCP 1 /* master switch */ 5093195972f6Sopenharmony_ci+ 5094195972f6Sopenharmony_ci+#define CHECKSUM_CHECK_IP 1 /* master switch */ 5095195972f6Sopenharmony_ci+ 5096195972f6Sopenharmony_ci+#define CHECKSUM_CHECK_TCP 1 /* master switch */ 5097195972f6Sopenharmony_ci+ 5098195972f6Sopenharmony_ci+#define LWIP_TIMEVAL_PRIVATE 0 5099195972f6Sopenharmony_ci+ 5100195972f6Sopenharmony_ci+#define USE_LIBOS 1 5101195972f6Sopenharmony_ci+ 5102195972f6Sopenharmony_ci+#define LWIP_DEBUG 1 5103195972f6Sopenharmony_ci+ 5104195972f6Sopenharmony_ci+#define LWIP_PERF 1 5105195972f6Sopenharmony_ci+ 5106195972f6Sopenharmony_ci+#define LWIP_RECORD_PERF 0 5107195972f6Sopenharmony_ci+ 5108195972f6Sopenharmony_ci+#define LWIP_SOCKET_POLL 0 5109195972f6Sopenharmony_ci+ 5110195972f6Sopenharmony_ci+#define USE_LIBOS_ZC_RING 0 5111195972f6Sopenharmony_ci+ 5112195972f6Sopenharmony_ci+#define SO_REUSE 1 5113195972f6Sopenharmony_ci+ 5114195972f6Sopenharmony_ci+#define SIOCSHIWAT 1 5115195972f6Sopenharmony_ci+ 5116195972f6Sopenharmony_ci+#define O_NONBLOCK 04000 /* same as define in bits/fcntl-linux.h */ 5117195972f6Sopenharmony_ci+ 5118195972f6Sopenharmony_ci+#define O_NDELAY O_NONBLOCK 5119195972f6Sopenharmony_ci+ 5120195972f6Sopenharmony_ci+#define FIONBIO 0x5421 /* same as define in asm-generic/ioctls.h */ 5121195972f6Sopenharmony_ci+ 5122195972f6Sopenharmony_ci+#define LWIP_SUPPORT_CUSTOM_PBUF 1 5123195972f6Sopenharmony_ci+ 5124195972f6Sopenharmony_ci+#define MEM_LIBC_MALLOC 0 5125195972f6Sopenharmony_ci+ 5126195972f6Sopenharmony_ci+#define LWIP_TIMERS 1 5127195972f6Sopenharmony_ci+ 5128195972f6Sopenharmony_ci+#define TCPIP_MBOX_SIZE (MEMP_NUM_TCPIP_MSG_API) 5129195972f6Sopenharmony_ci+ 5130195972f6Sopenharmony_ci+#define TCP_PCB_HASH 1 5131195972f6Sopenharmony_ci+ 5132195972f6Sopenharmony_ci+#define USE_DPDK_LOG 1 5133195972f6Sopenharmony_ci+ 5134195972f6Sopenharmony_ci+#define LWIP_EPOOL_WAIT_MAX_EVENTS 30 5135195972f6Sopenharmony_ci+ 5136195972f6Sopenharmony_ci+#define ARP_TABLE_SIZE 512 5137195972f6Sopenharmony_ci+ 5138195972f6Sopenharmony_ci+/* 5139195972f6Sopenharmony_ci+ --------------------------------------- 5140195972f6Sopenharmony_ci+ ------- Syscall thread options -------- 5141195972f6Sopenharmony_ci+ --------------------------------------- 5142195972f6Sopenharmony_ci+*/ 5143195972f6Sopenharmony_ci+#define USE_SYSCALL_THREAD 1 5144195972f6Sopenharmony_ci+ 5145195972f6Sopenharmony_ci+#define MAX_BLOCKING_ACCEPT_FD (100) 5146195972f6Sopenharmony_ci+ 5147195972f6Sopenharmony_ci+#define MAX_BLOCKING_CONNECT_FD (100) 5148195972f6Sopenharmony_ci+ 5149195972f6Sopenharmony_ci+#define MAX_BLOCKING_EPOLL_FD (100) 5150195972f6Sopenharmony_ci+ 5151195972f6Sopenharmony_ci+#define MAX_SYSCALL_EVENTS (MAX_BLOCKING_ACCEPT_FD + MAX_BLOCKING_CONNECT_FD + MAX_BLOCKING_EPOLL_FD) 5152195972f6Sopenharmony_ci+ 5153195972f6Sopenharmony_ci+#define MAX_HOST_FD (MAX_CLIENTS + RESERVED_CLIENTS) 5154195972f6Sopenharmony_ci+ 5155195972f6Sopenharmony_ci+#if USE_LIBOS 5156195972f6Sopenharmony_ci+#define PER_THREAD __thread 5157195972f6Sopenharmony_ci+#else 5158195972f6Sopenharmony_ci+#define PER_THREAD 5159195972f6Sopenharmony_ci+#endif 5160195972f6Sopenharmony_ci+ 5161195972f6Sopenharmony_ci+#endif /* __LWIPOPTS_H__ */ 5162195972f6Sopenharmony_cidiff --git a/src/include/lwipsock.h b/src/include/lwipsock.h 5163195972f6Sopenharmony_cinew file mode 100644 5164195972f6Sopenharmony_ciindex 0000000..dbc67b9 5165195972f6Sopenharmony_ci--- /dev/null 5166195972f6Sopenharmony_ci+++ b/src/include/lwipsock.h 5167195972f6Sopenharmony_ci@@ -0,0 +1,155 @@ 5168195972f6Sopenharmony_ci+/* 5169195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 5170195972f6Sopenharmony_ci+ * All rights reserved. 5171195972f6Sopenharmony_ci+ * 5172195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 5173195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 5174195972f6Sopenharmony_ci+ * 5175195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 5176195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 5177195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 5178195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 5179195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 5180195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 5181195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 5182195972f6Sopenharmony_ci+ * 5183195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 5184195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 5185195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 5186195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5187195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 5188195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5189195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5190195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 5191195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 5192195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 5193195972f6Sopenharmony_ci+ * 5194195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 5195195972f6Sopenharmony_ci+ * 5196195972f6Sopenharmony_ci+ * Author: Huawei Technologies 5197195972f6Sopenharmony_ci+ * 5198195972f6Sopenharmony_ci+ */ 5199195972f6Sopenharmony_ci+ 5200195972f6Sopenharmony_ci+#ifndef __LWIPSOCK_H__ 5201195972f6Sopenharmony_ci+#define __LWIPSOCK_H__ 5202195972f6Sopenharmony_ci+ 5203195972f6Sopenharmony_ci+#include "lwip/opt.h" 5204195972f6Sopenharmony_ci+#include "lwip/api.h" 5205195972f6Sopenharmony_ci+ 5206195972f6Sopenharmony_ci+#include "posix_api.h" 5207195972f6Sopenharmony_ci+#include "eventpoll.h" 5208195972f6Sopenharmony_ci+ 5209195972f6Sopenharmony_ci+/* move some definitions to the lwipsock.h for libnet to use, and 5210195972f6Sopenharmony_ci+ * at the same time avoid conflict between lwip/sockets.h and sys/socket.h 5211195972f6Sopenharmony_ci+ */ 5212195972f6Sopenharmony_ci+ 5213195972f6Sopenharmony_ci+/* -------------------------------------------------- 5214195972f6Sopenharmony_ci+ * the following definition is copied from lwip/priv/tcpip_priv.h 5215195972f6Sopenharmony_ci+ * -------------------------------------------------- 5216195972f6Sopenharmony_ci+ */ 5217195972f6Sopenharmony_ci+ 5218195972f6Sopenharmony_ci+/** This is overridable for the rare case where more than 255 threads 5219195972f6Sopenharmony_ci+ * select on the same socket... 5220195972f6Sopenharmony_ci+ */ 5221195972f6Sopenharmony_ci+#ifndef SELWAIT_T 5222195972f6Sopenharmony_ci+#define SELWAIT_T u8_t 5223195972f6Sopenharmony_ci+#endif 5224195972f6Sopenharmony_ci+ 5225195972f6Sopenharmony_ci+union lwip_sock_lastdata { 5226195972f6Sopenharmony_ci+ struct netbuf *netbuf; 5227195972f6Sopenharmony_ci+ struct pbuf *pbuf; 5228195972f6Sopenharmony_ci+}; 5229195972f6Sopenharmony_ci+ 5230195972f6Sopenharmony_ci+/** Contains all internal pointers and states used for a socket */ 5231195972f6Sopenharmony_ci+struct lwip_sock { 5232195972f6Sopenharmony_ci+ /** sockets currently are built on netconns, each socket has one netconn */ 5233195972f6Sopenharmony_ci+ struct netconn *conn; 5234195972f6Sopenharmony_ci+ /** data that was left from the previous read */ 5235195972f6Sopenharmony_ci+ union lwip_sock_lastdata lastdata; 5236195972f6Sopenharmony_ci+#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 5237195972f6Sopenharmony_ci+ /** number of times data was received, set by event_callback(), 5238195972f6Sopenharmony_ci+ tested by the receive and select functions */ 5239195972f6Sopenharmony_ci+ s16_t rcvevent; 5240195972f6Sopenharmony_ci+ /** number of times data was ACKed (free send buffer), set by event_callback(), 5241195972f6Sopenharmony_ci+ tested by select */ 5242195972f6Sopenharmony_ci+ u16_t sendevent; 5243195972f6Sopenharmony_ci+ /** error happened for this socket, set by event_callback(), tested by select */ 5244195972f6Sopenharmony_ci+ u16_t errevent; 5245195972f6Sopenharmony_ci+ /** counter of how many threads are waiting for this socket using select */ 5246195972f6Sopenharmony_ci+ SELWAIT_T select_waiting; 5247195972f6Sopenharmony_ci+#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ 5248195972f6Sopenharmony_ci+#if LWIP_NETCONN_FULLDUPLEX 5249195972f6Sopenharmony_ci+ /* counter of how many threads are using a struct lwip_sock (not the 'int') */ 5250195972f6Sopenharmony_ci+ u8_t fd_used; 5251195972f6Sopenharmony_ci+ /* status of pending close/delete actions */ 5252195972f6Sopenharmony_ci+ u8_t fd_free_pending; 5253195972f6Sopenharmony_ci+#define LWIP_SOCK_FD_FREE_TCP 1 5254195972f6Sopenharmony_ci+#define LWIP_SOCK_FD_FREE_FREE 2 5255195972f6Sopenharmony_ci+#endif 5256195972f6Sopenharmony_ci+ 5257195972f6Sopenharmony_ci+#if USE_LIBOS 5258195972f6Sopenharmony_ci+ struct list_node list; 5259195972f6Sopenharmony_ci+ /* registered events */ 5260195972f6Sopenharmony_ci+ uint32_t epoll; 5261195972f6Sopenharmony_ci+ /* available events */ 5262195972f6Sopenharmony_ci+ uint32_t events; 5263195972f6Sopenharmony_ci+ epoll_data_t ep_data; 5264195972f6Sopenharmony_ci+ /* libos_epoll pointer in use */ 5265195972f6Sopenharmony_ci+ struct libos_epoll *epoll_data; 5266195972f6Sopenharmony_ci+#endif 5267195972f6Sopenharmony_ci+}; 5268195972f6Sopenharmony_ci+ 5269195972f6Sopenharmony_ci+#ifndef set_errno 5270195972f6Sopenharmony_ci+#define set_errno(err) do { if (err) { errno = (err); } } while(0) 5271195972f6Sopenharmony_ci+#endif 5272195972f6Sopenharmony_ci+ 5273195972f6Sopenharmony_ci+ 5274195972f6Sopenharmony_ci+/* -------------------------------------------------- 5275195972f6Sopenharmony_ci+ * --------------- LIBNET references ---------------- 5276195972f6Sopenharmony_ci+ * -------------------------------------------------- 5277195972f6Sopenharmony_ci+ */ 5278195972f6Sopenharmony_ci+#if USE_LIBOS 5279195972f6Sopenharmony_ci+extern uint32_t sockets_num; 5280195972f6Sopenharmony_ci+extern struct lwip_sock *sockets; 5281195972f6Sopenharmony_ci+/** 5282195972f6Sopenharmony_ci+ * Map a externally used socket index to the internal socket representation. 5283195972f6Sopenharmony_ci+ * 5284195972f6Sopenharmony_ci+ * @param s externally used socket index 5285195972f6Sopenharmony_ci+ * @return struct lwip_sock for the socket or NULL if not found 5286195972f6Sopenharmony_ci+ */ 5287195972f6Sopenharmony_ci+static inline struct lwip_sock * 5288195972f6Sopenharmony_ci+get_socket_without_errno(int s) 5289195972f6Sopenharmony_ci+{ 5290195972f6Sopenharmony_ci+ struct lwip_sock *sock = NULL; 5291195972f6Sopenharmony_ci+ 5292195972f6Sopenharmony_ci+ s -= LWIP_SOCKET_OFFSET; 5293195972f6Sopenharmony_ci+ 5294195972f6Sopenharmony_ci+ if ((s < 0) || (s >= sockets_num)) { 5295195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s + LWIP_SOCKET_OFFSET)); 5296195972f6Sopenharmony_ci+ return NULL; 5297195972f6Sopenharmony_ci+ } 5298195972f6Sopenharmony_ci+ 5299195972f6Sopenharmony_ci+ sock = &sockets[s]; 5300195972f6Sopenharmony_ci+ 5301195972f6Sopenharmony_ci+ if (!sock->conn) { 5302195972f6Sopenharmony_ci+ LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s + LWIP_SOCKET_OFFSET)); 5303195972f6Sopenharmony_ci+ return NULL; 5304195972f6Sopenharmony_ci+ } 5305195972f6Sopenharmony_ci+ 5306195972f6Sopenharmony_ci+ return sock; 5307195972f6Sopenharmony_ci+} 5308195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 5309195972f6Sopenharmony_ci+ 5310195972f6Sopenharmony_ci+struct lwip_sock *get_socket(int s); 5311195972f6Sopenharmony_ci+struct lwip_sock *get_socket_by_fd(int s); 5312195972f6Sopenharmony_ci+void lwip_sock_init(void); 5313195972f6Sopenharmony_ci+void lwip_exit(void); 5314195972f6Sopenharmony_ci+ 5315195972f6Sopenharmony_ci+extern int is_host_ipv4(uint32_t ipv4); 5316195972f6Sopenharmony_ci+extern int rearm_host_fd(int fd); 5317195972f6Sopenharmony_ci+extern int rearm_accept_fd(int fd); 5318195972f6Sopenharmony_ci+extern void unarm_host_fd(int fd); 5319195972f6Sopenharmony_ci+extern void clean_host_fd(int fd); 5320195972f6Sopenharmony_ci+extern int arm_host_fd(struct libos_epoll *ep, int op, int fd, struct epoll_event *event); 5321195972f6Sopenharmony_ci+ 5322195972f6Sopenharmony_ci+#endif /* __LWIPSOCK_H__ */ 5323195972f6Sopenharmony_cidiff --git a/src/include/memp_def.h b/src/include/memp_def.h 5324195972f6Sopenharmony_cinew file mode 100644 5325195972f6Sopenharmony_ciindex 0000000..082f685 5326195972f6Sopenharmony_ci--- /dev/null 5327195972f6Sopenharmony_ci+++ b/src/include/memp_def.h 5328195972f6Sopenharmony_ci@@ -0,0 +1,66 @@ 5329195972f6Sopenharmony_ci+/* 5330195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 5331195972f6Sopenharmony_ci+ * All rights reserved. 5332195972f6Sopenharmony_ci+ * 5333195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 5334195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 5335195972f6Sopenharmony_ci+ * 5336195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 5337195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 5338195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 5339195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 5340195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 5341195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 5342195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 5343195972f6Sopenharmony_ci+ * 5344195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 5345195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 5346195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 5347195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5348195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 5349195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5350195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5351195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 5352195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 5353195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 5354195972f6Sopenharmony_ci+ * 5355195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 5356195972f6Sopenharmony_ci+ * 5357195972f6Sopenharmony_ci+ * Author: Huawei Technologies 5358195972f6Sopenharmony_ci+ * 5359195972f6Sopenharmony_ci+ */ 5360195972f6Sopenharmony_ci+ 5361195972f6Sopenharmony_ci+#ifndef __MEMP_DEF_H__ 5362195972f6Sopenharmony_ci+#define __MEMP_DEF_H__ 5363195972f6Sopenharmony_ci+ 5364195972f6Sopenharmony_ci+#include "lwip/opt.h" 5365195972f6Sopenharmony_ci+#include "arch/cc.h" 5366195972f6Sopenharmony_ci+ 5367195972f6Sopenharmony_ci+#define LWIP_MEMPOOL_BASE_DECLARE(name) \ 5368195972f6Sopenharmony_ci+ extern void alloc_memp_##name##_base(void); 5369195972f6Sopenharmony_ci+ 5370195972f6Sopenharmony_ci+#define LWIP_MEM_MEMORY_DECLARE(name) \ 5371195972f6Sopenharmony_ci+ extern void alloc_memory_##name(void); 5372195972f6Sopenharmony_ci+ 5373195972f6Sopenharmony_ci+#define LWIP_MEMPOOL_BASE_INIT(name) \ 5374195972f6Sopenharmony_ci+ alloc_memp_##name##_base(); 5375195972f6Sopenharmony_ci+ 5376195972f6Sopenharmony_ci+#define LWIP_MEM_MEMORY_INIT(name) \ 5377195972f6Sopenharmony_ci+ alloc_memory_##name(); 5378195972f6Sopenharmony_ci+ 5379195972f6Sopenharmony_ci+#define LWIP_MEMPOOL(name, num, size, desc) LWIP_MEMPOOL_BASE_DECLARE(name) 5380195972f6Sopenharmony_ci+#include <lwip/priv/memp_std.h> 5381195972f6Sopenharmony_ci+#undef LWIP_MEMPOOL 5382195972f6Sopenharmony_ci+ 5383195972f6Sopenharmony_ci+static inline void hugepage_init(void) 5384195972f6Sopenharmony_ci+{ 5385195972f6Sopenharmony_ci+#define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_BASE_INIT(name) 5386195972f6Sopenharmony_ci+#include "lwip/priv/memp_std.h" 5387195972f6Sopenharmony_ci+ 5388195972f6Sopenharmony_ci+#if !MEM_LIBC_MALLOC 5389195972f6Sopenharmony_ci+ LWIP_MEM_MEMORY_DECLARE(ram_heap) 5390195972f6Sopenharmony_ci+ LWIP_MEM_MEMORY_INIT(ram_heap) 5391195972f6Sopenharmony_ci+#endif /* MEM_LIBC_MALLOC */ 5392195972f6Sopenharmony_ci+} 5393195972f6Sopenharmony_ci+ 5394195972f6Sopenharmony_ci+#endif /* __MEMP_DEF_H__ */ 5395195972f6Sopenharmony_cidiff --git a/src/include/posix_api.h b/src/include/posix_api.h 5396195972f6Sopenharmony_cinew file mode 100644 5397195972f6Sopenharmony_ciindex 0000000..8aa8516 5398195972f6Sopenharmony_ci--- /dev/null 5399195972f6Sopenharmony_ci+++ b/src/include/posix_api.h 5400195972f6Sopenharmony_ci@@ -0,0 +1,88 @@ 5401195972f6Sopenharmony_ci+/* 5402195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 5403195972f6Sopenharmony_ci+ * All rights reserved. 5404195972f6Sopenharmony_ci+ * 5405195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 5406195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 5407195972f6Sopenharmony_ci+ * 5408195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 5409195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 5410195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 5411195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 5412195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 5413195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 5414195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 5415195972f6Sopenharmony_ci+ * 5416195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 5417195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 5418195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 5419195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5420195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 5421195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5422195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5423195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 5424195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 5425195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 5426195972f6Sopenharmony_ci+ * 5427195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 5428195972f6Sopenharmony_ci+ * 5429195972f6Sopenharmony_ci+ * Author: Huawei Technologies 5430195972f6Sopenharmony_ci+ * 5431195972f6Sopenharmony_ci+ */ 5432195972f6Sopenharmony_ci+ 5433195972f6Sopenharmony_ci+#ifndef __POSIX_API_H__ 5434195972f6Sopenharmony_ci+#define __POSIX_API_H__ 5435195972f6Sopenharmony_ci+ 5436195972f6Sopenharmony_ci+#include <signal.h> 5437195972f6Sopenharmony_ci+#include <poll.h> 5438195972f6Sopenharmony_ci+#include <sys/epoll.h> 5439195972f6Sopenharmony_ci+#include <sys/eventfd.h> 5440195972f6Sopenharmony_ci+ 5441195972f6Sopenharmony_ci+typedef struct { 5442195972f6Sopenharmony_ci+ void *handle; 5443195972f6Sopenharmony_ci+ int (*socket_fn)(int domain, int type, int protocol); 5444195972f6Sopenharmony_ci+ int (*accept_fn)(int s, struct sockaddr*, socklen_t*); 5445195972f6Sopenharmony_ci+ int (*accept4_fn)(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); 5446195972f6Sopenharmony_ci+ int (*bind_fn)(int s, const struct sockaddr*, socklen_t); 5447195972f6Sopenharmony_ci+ int (*listen_fn)(int s, int backlog); 5448195972f6Sopenharmony_ci+ int (*connect_fn)(int s, const struct sockaddr *name, socklen_t namelen); 5449195972f6Sopenharmony_ci+ int (*getpeername_fn)(int s, struct sockaddr *name, socklen_t *namelen); 5450195972f6Sopenharmony_ci+ int (*getsockname_fn)(int s, struct sockaddr *name, socklen_t *namelen); 5451195972f6Sopenharmony_ci+ int (*setsockopt_fn)(int s, int level, int optname, const void *optval, socklen_t optlen); 5452195972f6Sopenharmony_ci+ int (*getsockopt_fn)(int s, int level, int optname, void *optval, socklen_t *optlen); 5453195972f6Sopenharmony_ci+ int (*shutdown_fn)(int s, int how); 5454195972f6Sopenharmony_ci+ int (*close_fn)(int fd); 5455195972f6Sopenharmony_ci+ pid_t (*fork_fn)(void); 5456195972f6Sopenharmony_ci+ ssize_t (*read_fn)(int fd, void *mem, size_t len); 5457195972f6Sopenharmony_ci+ ssize_t (*write_fn)(int fd, const void *data, size_t len); 5458195972f6Sopenharmony_ci+ ssize_t (*recv_fn)(int sockfd, void *buf, size_t len, int flags); 5459195972f6Sopenharmony_ci+ ssize_t (*send_fn)(int sockfd, const void *buf, size_t len, int flags); 5460195972f6Sopenharmony_ci+ ssize_t (*recv_msg)(int sockfd, const struct msghdr *msg, int flags); 5461195972f6Sopenharmony_ci+ ssize_t (*send_msg)(int sockfd, const struct msghdr *msg, int flags); 5462195972f6Sopenharmony_ci+ ssize_t (*recv_from)(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); 5463195972f6Sopenharmony_ci+ ssize_t (*send_to)(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, 5464195972f6Sopenharmony_ci+ socklen_t addrlen); 5465195972f6Sopenharmony_ci+ int (*fcntl_fn)(int fd, int cmd, ...); 5466195972f6Sopenharmony_ci+ int (*fcntl64_fn)(int fd, int cmd, ...); 5467195972f6Sopenharmony_ci+ int (*pipe_fn)(int pipefd[2]); 5468195972f6Sopenharmony_ci+ int (*epoll_create_fn)(int size); 5469195972f6Sopenharmony_ci+ int (*epoll_ctl_fn)(int epfd, int op, int fd, struct epoll_event *event); 5470195972f6Sopenharmony_ci+ int (*epoll_wait_fn)(int epfd, struct epoll_event *events, int maxevents, int timeout); 5471195972f6Sopenharmony_ci+ int (*epoll_close_fn)(int epfd); 5472195972f6Sopenharmony_ci+ int (*eventfd_fn)(unsigned int initval, int flags); 5473195972f6Sopenharmony_ci+ int (*is_epfd)(int fd); 5474195972f6Sopenharmony_ci+ struct lwip_sock* (*get_socket)(int fd); 5475195972f6Sopenharmony_ci+ int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); 5476195972f6Sopenharmony_ci+ int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); 5477195972f6Sopenharmony_ci+ int (*ioctl_fn)(int fd, int cmd, ...); 5478195972f6Sopenharmony_ci+ 5479195972f6Sopenharmony_ci+ int is_chld; 5480195972f6Sopenharmony_ci+} posix_api_t; 5481195972f6Sopenharmony_ci+ 5482195972f6Sopenharmony_ci+posix_api_t *posix_api; 5483195972f6Sopenharmony_ci+ 5484195972f6Sopenharmony_ci+int posix_api_init(void); 5485195972f6Sopenharmony_ci+void posix_api_free(void); 5486195972f6Sopenharmony_ci+void posix_api_fork(void); 5487195972f6Sopenharmony_ci+ 5488195972f6Sopenharmony_ci+#endif /* __POSIX_API_H__ */ 5489195972f6Sopenharmony_cidiff --git a/src/include/reg_sock.h b/src/include/reg_sock.h 5490195972f6Sopenharmony_cinew file mode 100644 5491195972f6Sopenharmony_ciindex 0000000..76d4c48 5492195972f6Sopenharmony_ci--- /dev/null 5493195972f6Sopenharmony_ci+++ b/src/include/reg_sock.h 5494195972f6Sopenharmony_ci@@ -0,0 +1,62 @@ 5495195972f6Sopenharmony_ci+/* 5496195972f6Sopenharmony_ci+ * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 5497195972f6Sopenharmony_ci+ * All rights reserved. 5498195972f6Sopenharmony_ci+ * 5499195972f6Sopenharmony_ci+ * Redistribution and use in source and binary forms, with or without modification, 5500195972f6Sopenharmony_ci+ * are permitted provided that the following conditions are met: 5501195972f6Sopenharmony_ci+ * 5502195972f6Sopenharmony_ci+ * 1. Redistributions of source code must retain the above copyright notice, 5503195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer. 5504195972f6Sopenharmony_ci+ * 2. Redistributions in binary form must reproduce the above copyright notice, 5505195972f6Sopenharmony_ci+ * this list of conditions and the following disclaimer in the documentation 5506195972f6Sopenharmony_ci+ * and/or other materials provided with the distribution. 5507195972f6Sopenharmony_ci+ * 3. The name of the author may not be used to endorse or promote products 5508195972f6Sopenharmony_ci+ * derived from this software without specific prior written permission. 5509195972f6Sopenharmony_ci+ * 5510195972f6Sopenharmony_ci+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 5511195972f6Sopenharmony_ci+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 5512195972f6Sopenharmony_ci+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 5513195972f6Sopenharmony_ci+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5514195972f6Sopenharmony_ci+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 5515195972f6Sopenharmony_ci+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5516195972f6Sopenharmony_ci+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5517195972f6Sopenharmony_ci+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 5518195972f6Sopenharmony_ci+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 5519195972f6Sopenharmony_ci+ * OF SUCH DAMAGE. 5520195972f6Sopenharmony_ci+ * 5521195972f6Sopenharmony_ci+ * This file is part of the lwIP TCP/IP stack. 5522195972f6Sopenharmony_ci+ * 5523195972f6Sopenharmony_ci+ * Author: Huawei Technologies 5524195972f6Sopenharmony_ci+ * 5525195972f6Sopenharmony_ci+ */ 5526195972f6Sopenharmony_ci+ 5527195972f6Sopenharmony_ci+#ifndef __REG_SOCK_H__ 5528195972f6Sopenharmony_ci+#define __REG_SOCK_H__ 5529195972f6Sopenharmony_ci+ 5530195972f6Sopenharmony_ci+enum reg_ring_type { 5531195972f6Sopenharmony_ci+ REG_RING_TCP_LISTEN = 0, 5532195972f6Sopenharmony_ci+ REG_RING_TCP_LISTEN_CLOSE, 5533195972f6Sopenharmony_ci+ REG_RING_TCP_CONNECT, 5534195972f6Sopenharmony_ci+ REG_RING_TCP_CONNECT_CLOSE, 5535195972f6Sopenharmony_ci+ RING_REG_MAX, 5536195972f6Sopenharmony_ci+}; 5537195972f6Sopenharmony_ci+ 5538195972f6Sopenharmony_ci+struct libnet_quintuple { 5539195972f6Sopenharmony_ci+ uint32_t protocol; 5540195972f6Sopenharmony_ci+ /* net byte order */ 5541195972f6Sopenharmony_ci+ uint16_t src_port; 5542195972f6Sopenharmony_ci+ uint16_t dst_port; 5543195972f6Sopenharmony_ci+ uint32_t src_ip; 5544195972f6Sopenharmony_ci+ uint32_t dst_ip; 5545195972f6Sopenharmony_ci+}; 5546195972f6Sopenharmony_ci+ 5547195972f6Sopenharmony_ci+struct reg_ring_msg { 5548195972f6Sopenharmony_ci+ enum reg_ring_type type; 5549195972f6Sopenharmony_ci+ 5550195972f6Sopenharmony_ci+ uint32_t tid; 5551195972f6Sopenharmony_ci+ struct libnet_quintuple qtuple; 5552195972f6Sopenharmony_ci+}; 5553195972f6Sopenharmony_ci+ 5554195972f6Sopenharmony_ci+extern int vdev_reg_xmit(enum reg_ring_type type, struct libnet_quintuple *qtuple); 5555195972f6Sopenharmony_ci+ 5556195972f6Sopenharmony_ci+#endif /* __REG_SOCK_H__ */ 5557195972f6Sopenharmony_ci\ No newline at end of file 5558195972f6Sopenharmony_cidiff --git a/src/netif/dir.mk b/src/netif/dir.mk 5559195972f6Sopenharmony_ciindex 233c79a..f585d5e 100644 5560195972f6Sopenharmony_ci--- a/src/netif/dir.mk 5561195972f6Sopenharmony_ci+++ b/src/netif/dir.mk 5562195972f6Sopenharmony_ci@@ -1,3 +1,3 @@ 5563195972f6Sopenharmony_ci-SRC = ethernet.c 5564195972f6Sopenharmony_ci+SRC = ethernet.c 5565195972f6Sopenharmony_ci 5566195972f6Sopenharmony_ci $(eval $(call register_dir, netif, $(SRC))) 5567195972f6Sopenharmony_ci-- 5568195972f6Sopenharmony_ci1.8.3.1 5569195972f6Sopenharmony_ci 5570