From d0251f285bb997cdc0dc1e7ab28ba431bce9c544 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 5 Feb 2024 19:56:58 +0800
Subject: [PATCH] adapt lwip 2.2.0

---
 src/api/api_msg.c      |  8 ++++----
 src/api/sockets.c      | 23 +++++++----------------
 src/core/tcp.c         |  4 ++--
 src/core/tcp_out.c     |  2 +-
 src/include/lwipopts.h |  2 +-
 5 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/src/api/api_msg.c b/src/api/api_msg.c
index adfdd40..a0baaae 100644
--- a/src/api/api_msg.c
+++ b/src/api/api_msg.c
@@ -295,7 +295,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
     SYS_ARCH_INC(conn->recv_avail, len);
 #endif /* LWIP_SO_RCVBUF */
 #if GAZELLE_UDP_ENABLE
-    do_lwip_add_recvlist(conn->socket);
+    do_lwip_add_recvlist(conn->callback_arg.socket);
 #endif /* GAZELLE_UDP_ENABLE */
     /* Register event with callback */
     API_EVENT(conn, NETCONN_EVT_RCVPLUS, len);
@@ -357,7 +357,7 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
     SYS_ARCH_INC(conn->recv_avail, len);
 #endif /* LWIP_SO_RCVBUF */
 #if GAZELLE_ENABLE
-    do_lwip_add_recvlist(conn->socket);
+    do_lwip_add_recvlist(conn->callback_arg.socket);
 #endif
     /* Register event with callback */
     API_EVENT(conn, NETCONN_EVT_RCVPLUS, len);
@@ -491,7 +491,7 @@ err_tcp(void *arg, err_t err)
     /* use trypost to prevent deadlock */
     sys_mbox_trypost(&conn->recvmbox, mbox_msg);
 #if GAZELLE_ENABLE
-    do_lwip_add_recvlist(conn->socket);
+    do_lwip_add_recvlist(conn->callback_arg.socket);
 #endif
   }
   /* pass error message to acceptmbox to wake up pending accept */
diff --git a/src/api/sockets.c b/src/api/sockets.c
index e6868a1..923518c 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -848,7 +848,7 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
   if (pcb == NULL || ret != 0) {
       netconn_delete(newconn);
       free_socket(nsock, 1);
-      sock_set_errno(sock, ENOTCONN);
+      set_errno(ENOTCONN);
       done_socket(sock);
       return -1;
   }
@@ -2840,7 +2840,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
       break;
     case NETCONN_EVT_ERROR:
       if ((conn->pending_err != ERR_OK) && (conn->pending_err != ERR_RST)) {
-          LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("event_callback: have errevent, err=%d, fd=%d\n", conn->pending_err, conn->socket));
+          LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("event_callback: have errevent, err=%d, fd=%d\n", conn->pending_err, conn->callback_arg.socket));
       }
       sock->errevent = 1;
 #if GAZELLE_ENABLE
@@ -4246,7 +4246,7 @@ lwip_fcntl(int s, int cmd, int val)
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_fcntl(%d, UNIMPL: %d, %d)\n", s, cmd, val));
 #if GAZELLE_ENABLE
-      sock_errno(sock, 0); /* not yet implemented, but we return 0 for compatilbe with app */
+      set_errno(0); /* not yet implemented, but we return 0 for compatilbe with app */
       ret = 0;
 #else
       set_errno(ENOSYS); /* not yet implemented */
diff --git a/src/core/tcp.c b/src/core/tcp.c
index a9a6513..69f6953 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -258,7 +258,7 @@ tcp_free(struct tcp_pcb *pcb)
     rte_ring_free(pcb->client_rx_ring);
     rte_ring_free(pcb->client_tx_ring);
     netconn = (struct netconn *)pcb->callback_arg;
-    sock = get_socket(netconn->socket);
+    sock = get_socket(netconn->callback_arg.socket);
     rte_memzone_free(sock->same_node_rx_ring->mz);
     rte_memzone_free(sock->same_node_rx_ring_mz);
     rte_memzone_free(sock->same_node_tx_ring->mz);
@@ -995,7 +995,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u16_t backlog, err_t *err)
   lpcb->next_same_port_pcb = NULL;
 
   struct netconn* conn = pcb->callback_arg;
-  lpcb->socket_fd = conn->socket;
+  lpcb->socket_fd = conn->callback_arg.socket;
   lpcb->master_lpcb = conn->is_master_fd;
 #endif
 
diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index 70c4242..1632a66 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -2501,7 +2501,7 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno,
   
   p = tcp_rst_common(pcb, seqno, ackno, local_ip, remote_ip, local_port, remote_port);
   if (p != NULL) {
-    tcp_output_control_segment(pcb, p, local_ip, remote_ip);
+    tcp_output_control_segment((struct tcp_pcb *)pcb, p, local_ip, remote_ip);
   }
 }
 
diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
index d54ff1e..28b8aca 100644
--- a/src/include/lwipopts.h
+++ b/src/include/lwipopts.h
@@ -107,7 +107,7 @@
 
 #define LWIP_TIMERS 1
 
-#define TCP_SND_BUF (2500 * TCP_MSS)
+#define LWIP_TIMEVAL_PRIVATE 0
 
 /*
    ------------------------------------------------
-- 
2.33.0

