代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/lwip 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From c0eadfbe825041cd2b399392f511b4b3e757a0e1 Mon Sep 17 00:00:00 2001
From: Lemmy Huang <huangliming5@huawei.com>
Date: Fri, 12 Jul 2024 16:46:30 +0800
Subject: [PATCH 1/2] cleancode: refactor offload
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
---
src/core/ipv4/icmp.c | 8 ++---
src/core/ipv4/ip4.c | 12 +++----
src/core/ipv4/ip4_frag.c | 16 ++++-----
src/core/ipv6/ip6.c | 8 ++---
src/core/pbuf.c | 2 +-
src/core/tcp.c | 61 +++++++++++++++++++++++-----------
src/core/tcp_in.c | 8 ++---
src/core/tcp_out.c | 12 +++----
src/core/udp.c | 31 ++++++++++--------
src/include/lwip/pbuf.h | 2 +-
src/include/lwipgz_offload.h | 63 +++++++++++++++++++-----------------
src/include/lwipopts.h | 43 ++++++++++++------------
src/netif/ethernet.c | 10 +++---
13 files changed, 155 insertions(+), 121 deletions(-)
diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c
index fa0795d..fd024c5 100644
--- a/src/core/ipv4/icmp.c
+++ b/src/core/ipv4/icmp.c
@@ -51,7 +51,7 @@
#include <string.h>
-#if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW
+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_GEN_IP
#include "lwipgz_offload.h"
#endif
@@ -247,11 +247,11 @@ icmp_input(struct pbuf *p, struct netif *inp)
IPH_CHKSUM_SET(iphdr, 0);
#if CHECKSUM_GEN_IP
IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_GEN_IP) {
-#if CHECKSUM_GEN_IP_HW
+#if OFFLOAD_CHECKSUM_GEN_IP
if (netif_get_txol_flags(inp) & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
- iph_cksum_set(p, hlen, 1);
+ ol_chksum_gen_ip(p, hlen, 1);
} else {
- iph_cksum_set(p, hlen, 0);
+ ol_chksum_gen_ip(p, hlen, 0);
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, hlen));
}
#else
diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c
index 1d3d954..ad8638e 100644
--- a/src/core/ipv4/ip4.c
+++ b/src/core/ipv4/ip4.c
@@ -59,7 +59,7 @@
#include <string.h>
-#if GAZELLE_ENABLE && (CHECKSUM_CHECK_IP_HW || CHECKSUM_GEN_IP_HW)
+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_CHECK_IP || OFFLOAD_CHECKSUM_GEN_IP)
#include "lwipgz_offload.h"
#endif
@@ -544,10 +544,10 @@ ip4_input(struct pbuf *p, struct netif *inp)
/* verify checksum */
#if CHECKSUM_CHECK_IP
IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_IP) {
-#if CHECKSUM_CHECK_IP_HW
+#if OFFLOAD_CHECKSUM_CHECK_IP
u64_t ret;
if (netif_get_rxol_flags(inp) & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM) {
- ret = is_cksum_ipbad(p);
+ ret = ol_chksum_check_ip(p);
} else {
ret = (u64_t)inet_chksum(iphdr, iphdr_hlen);
}
@@ -1019,11 +1019,11 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d
IPH_CHKSUM_SET(iphdr, 0);
#if CHECKSUM_GEN_IP
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
-#if CHECKSUM_GEN_IP_HW
+#if OFFLOAD_CHECKSUM_GEN_IP
if (netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
- iph_cksum_set(p, ip_hlen, 1);
+ ol_chksum_gen_ip(p, ip_hlen, 1);
} else {
- iph_cksum_set(p, ip_hlen, 0);
+ ol_chksum_gen_ip(p, ip_hlen, 0);
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
}
#else
diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c
index e209303..c24f710 100644
--- a/src/core/ipv4/ip4_frag.c
+++ b/src/core/ipv4/ip4_frag.c
@@ -52,7 +52,7 @@
#include <string.h>
-#if GAZELLE_ENABLE && CHECKSUM_GEN_IP_HW
+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_GEN_IP
#include "lwipgz_offload.h"
#endif
@@ -642,11 +642,11 @@ ip4_reass(struct pbuf *p)
/* @todo: do we need to set/calculate the correct checksum? */
#if CHECKSUM_GEN_IP
IF__NETIF_CHECKSUM_ENABLED(netif_default, NETIF_CHECKSUM_GEN_IP) {
-#if CHECKSUM_GEN_IP_HW
+#if OFFLOAD_CHECKSUM_GEN_IP
if (netif_get_txol_flags(netif_default) & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
- iph_cksum_set(p, IP_HLEN, 1);
+ ol_chksum_gen_ip(p, IP_HLEN, 1);
} else {
- iph_cksum_set(p, IP_HLEN, 0);
+ ol_chksum_gen_ip(p, IP_HLEN, 0);
IPH_CHKSUM_SET(fraghdr, inet_chksum(fraghdr, IP_HLEN));
}
#else
@@ -889,12 +889,12 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
IPH_CHKSUM_SET(iphdr, 0);
#if CHECKSUM_GEN_IP
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
-#if CHECKSUM_GEN_IP_HW
+#if OFFLOAD_CHECKSUM_GEN_IP
if (netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
- iph_cksum_set(p, IP_HLEN, 1);
- iph_cksum_set(rambuf, IP_HLEN, 1);
+ ol_chksum_gen_ip(p, IP_HLEN, 1);
+ ol_chksum_gen_ip(rambuf, IP_HLEN, 1);
} else {
- iph_cksum_set(p, IP_HLEN, 0);
+ ol_chksum_gen_ip(p, IP_HLEN, 0);
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
}
diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c
index f568d85..4866f25 100644
--- a/src/core/ipv6/ip6.c
+++ b/src/core/ipv6/ip6.c
@@ -60,7 +60,7 @@
#include "lwip/debug.h"
#include "lwip/stats.h"
-#if GAZELLE_ENABLE && (CHECKSUM_CHECK_IP_HW || CHECKSUM_GEN_IP_HW)
+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_CHECK_IP || OFFLOAD_CHECKSUM_GEN_IP)
#include "lwipgz_offload.h"
#endif
@@ -1226,9 +1226,9 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
/* src cannot be NULL here */
ip6_addr_copy_to_packed(ip6hdr->src, *src);
-#if CHECKSUM_GEN_IP_HW
- iph_cksum_set(p, IP6_HLEN, 0);
-#endif /* CHECKSUM_GEN_IP_HW */
+#if OFFLOAD_CHECKSUM_GEN_IP
+ ol_chksum_gen_ip(p, IP6_HLEN, 0);
+#endif /* OFFLOAD_CHECKSUM_GEN_IP */
} else {
/* IP header already included in p */
diff --git a/src/core/pbuf.c b/src/core/pbuf.c
index 586da07..32ffaeb 100644
--- a/src/core/pbuf.c
+++ b/src/core/pbuf.c
@@ -1038,7 +1038,7 @@ pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_
len = p_to->len - offset_to;
}
-#if GAZELLE_ENABLE && (CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW)
+#if GAZELLE_ENABLE && (OFFLOAD_CHECKSUM_CHECK_IP || OFFLOAD_CHECKSUM_GEN_IP)
pbuf_offload_copy(p_to, p_from);
#endif
diff --git a/src/core/tcp.c b/src/core/tcp.c
index 4c1304b..a35f19a 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -189,19 +189,21 @@ PER_THREAD u8_t tcp_active_pcbs_changed;
/** Timer counter to handle calling slow-timer from tcp_tmr() */
static PER_THREAD u8_t tcp_timer;
static PER_THREAD u8_t tcp_timer_ctr;
-#if GAZELLE_ENABLE
+
+#if GAZELLE_TCP_NEW_PORT
static u16_t tcp_new_port(struct tcp_pcb *pcb);
static pthread_mutex_t g_tcp_port_mutex = PTHREAD_MUTEX_INITIALIZER;
static u8_t port_state[TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START + 1] = {0};
+
void release_port(u16_t port)
{
if (port >= TCP_LOCAL_PORT_RANGE_START && port <= TCP_LOCAL_PORT_RANGE_END) {
port_state[port - TCP_LOCAL_PORT_RANGE_START] = 0;
}
}
-#else /* GAZELLE_ENABLE */
+#else /* GAZELLE_TCP_NEW_PORT */
static u16_t tcp_new_port(void);
-#endif /* GAZELLE_ENABLE */
+#endif /* GAZELLE_TCP_NEW_PORT */
#if GAZELLE_TCP_PCB_HASH
PER_THREAD struct tcp_hash_table *tcp_active_htable; /* key: lport/fport/lip/fip */
@@ -255,6 +257,8 @@ tcp_free(struct tcp_pcb *pcb)
rte_memzone_free(sock->same_node_tx_ring_mz);
}
vdev_unreg_done(pcb);
+#endif
+#if GAZELLE_TCP_NEW_PORT
release_port(pcb->local_port);
#endif
LWIP_ASSERT("tcp_free: LISTEN", pcb->state != LISTEN);
@@ -759,7 +763,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
#endif /* LWIP_IPV6 && LWIP_IPV6_SCOPES */
if (port == 0) {
-#if GAZELLE_ENABLE
+#if GAZELLE_TCP_NEW_PORT
port = tcp_new_port(pcb);
#else
port = tcp_new_port();
@@ -995,11 +999,12 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u16_t backlog, err_t *err)
/* copy over ext_args to listening pcb */
memcpy(&lpcb->ext_args, &pcb->ext_args, sizeof(pcb->ext_args));
#endif
-#if GAZELLE_ENABLE
+#if GAZELLE_TCP_NEW_PORT
/* pcb transfer to lpcb and reg into tcp_listen_pcbs. freeing pcb shouldn't release sock table in here.
* local_port=0 avoid to release sock table in tcp_free */
pcb->local_port = 0;
-
+#endif /* GAZELLE_TCP_NEW_PORT */
+#if GAZELLE_ENABLE
char name[RING_NAME_LEN];
snprintf(name, sizeof(name), "listen_rx_ring_%u", lpcb->local_port);
if (rte_ring_lookup(name) != NULL) {
@@ -1008,7 +1013,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u16_t backlog, err_t *err)
} else {
same_node_ring_create(&lpcb->listen_rx_ring, SAME_NODE_RING_SIZE, lpcb->local_port, "listen", "rx");
}
-#endif
+#endif /* GAZELLE_ENABLE */
tcp_free(pcb);
#if LWIP_CALLBACK_API
lpcb->accept = tcp_accept_null;
@@ -1121,13 +1126,9 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
*
* @return a new (free) local TCP port number
*/
-#if GAZELLE_ENABLE
+#if GAZELLE_TCP_NEW_PORT
static u16_t
tcp_new_port(struct tcp_pcb *pcb)
-#else
-static u16_t
-tcp_new_port(void)
-#endif
{
u16_t n = 0;
u16_t tmp_port = 0;
@@ -1140,16 +1141,11 @@ tcp_new_port(void)
}
if (__atomic_load_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) {
-#if GAZELLE_ENABLE
if (port_in_stack_queue((gz_addr_t *)&pcb->remote_ip, (gz_addr_t *)&pcb->local_ip, pcb->remote_port, tcp_port)) {
tmp_port = tcp_port;
__atomic_store_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE);
break;
}
-#else
- __atomic_store_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE);
- break;
-#endif
}
n++;
@@ -1163,6 +1159,35 @@ tcp_new_port(void)
return tmp_port;
}
+#else /* GAZELLE_TCP_NEW_PORT */
+static u16_t
+tcp_new_port(void)
+{
+ u8_t i;
+ u16_t n = 0;
+ struct tcp_pcb *pcb;
+
+again:
+ tcp_port++;
+ if (tcp_port == TCP_LOCAL_PORT_RANGE_END) {
+ tcp_port = TCP_LOCAL_PORT_RANGE_START;
+ }
+ /* Check all PCB lists. */
+ for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
+ for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {
+ if (pcb->local_port == tcp_port) {
+ n++;
+ if (n > (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) {
+ return 0;
+ }
+ goto again;
+ }
+ }
+ }
+ return tcp_port;
+}
+#endif /* GAZELLE_TCP_NEW_PORT */
+
/**
* @ingroup tcp_raw
* Connects to another host. The function given as the "connected"
@@ -1243,7 +1268,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
old_local_port = pcb->local_port;
if (pcb->local_port == 0) {
-#if GAZELLE_ENABLE
+#if GAZELLE_TCP_NEW_PORT
pcb->local_port = tcp_new_port(pcb);
#else
pcb->local_port = tcp_new_port();
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index 7288d2f..05c97d0 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -65,9 +65,9 @@
#include <string.h>
-#if GAZELLE_ENABLE && CHECKSUM_CHECK_TCP_HW
+#if GAZELLE_ENABLE && OFFLOAD_CHECKSUM_CHECK_TCP
#include <lwipgz_offload.h>
-#endif /* CHECKSUM_CHECK_TCP_HW */
+#endif /* OFFLOAD_CHECKSUM_CHECK_TCP */
#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
@@ -203,10 +203,10 @@ tcp_input(struct pbuf *p, struct netif *inp)
#if CHECKSUM_CHECK_TCP
IF__NETIF_CHECKSUM_ENABLED(inp, NETIF_CHECKSUM_CHECK_TCP) {
/* Verify TCP checksum. */
-#if CHECKSUM_CHECK_TCP_HW
+#if OFFLOAD_CHECKSUM_CHECK_TCP
u64_t ret;
if (netif_get_rxol_flags(inp) & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) {
- ret = is_cksum_bad(p);
+ ret = ol_chksum_check_tcp(p);
} else {
ret = (u64_t)ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
ip_current_src_addr(), ip_current_dest_addr());
diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index aaa3872..4cf1a62 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -83,7 +83,7 @@
#if GAZELLE_ENABLE
#include "lwipgz_sock.h"
#include <rte_prefetch.h>
-#if CHECKSUM_GEN_TCP_HW
+#if OFFLOAD_CHECKSUM_GEN_TCP
#include "lwipgz_offload.h"
#endif
#endif
@@ -1939,9 +1939,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif
#if CHECKSUM_GEN_TCP
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) {
-#if CHECKSUM_GEN_TCP_HW
+#if OFFLOAD_CHECKSUM_GEN_TCP
if (netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) {
- tcph_cksum_set(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr));
+ ol_chksum_gen_tcp(seg->p, TCPH_HDRLEN_BYTES(seg->tcphdr));
} else {
#if TCP_CHECKSUM_ON_COPY
u32_t acc;
@@ -2014,7 +2014,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif
seg->tcphdr->chksum = ip_chksum_pseudo(seg->p, IP_PROTO_TCP,
seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip);
#endif /* TCP_CHECKSUM_ON_COPY */
-#endif /* CHECKSUM_GEN_TCP_HW */
+#endif /* OFFLOAD_CHECKSUM_GEN_TCP */
}
#endif /* CHECKSUM_GEN_TCP */
#if !GAZELLE_ENABLE
@@ -2405,9 +2405,9 @@ tcp_output_control_segment_netif(const struct tcp_pcb *pcb, struct pbuf *p,
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_TCP) {
struct tcp_hdr *tcphdr = (struct tcp_hdr *)p->payload;
tcphdr->chksum = 0;
-#if CHECKSUM_GEN_TCP_HW
+#if OFFLOAD_CHECKSUM_GEN_TCP
if (netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) {
- tcph_cksum_set(p, TCPH_HDRLEN_BYTES(tcphdr));
+ ol_chksum_gen_tcp(p, TCPH_HDRLEN_BYTES(tcphdr));
} else {
tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
src, dst);
diff --git a/src/core/udp.c b/src/core/udp.c
index 0d09e7e..a86f5ec 100644
--- a/src/core/udp.c
+++ b/src/core/udp.c
@@ -83,7 +83,7 @@
/* last local UDP port */
static u16_t udp_port = UDP_LOCAL_PORT_RANGE_START;
-#if GAZELLE_UDP_ENABLE
+#if GAZELLE_UDP_NEW_PORT
static pthread_mutex_t g_udp_port_mutex = PTHREAD_MUTEX_INITIALIZER;
static u8_t port_state[UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START + 1] = {0};
static void udp_release_port(u16_t port)
@@ -92,7 +92,7 @@ static void udp_release_port(u16_t port)
port_state[port - UDP_LOCAL_PORT_RANGE_START] = 0;
}
}
-#endif
+#endif /* GAZELLE_UDP_NEW_PORT */
/* The list of UDP PCBs */
/* exported in udp.h (was static) */
@@ -118,7 +118,7 @@ udp_init(void)
*
* @return a new (free) local UDP port number
*/
-#if GAZELLE_UDP_ENABLE
+#if GAZELLE_UDP_NEW_PORT
static u16_t
udp_new_port(struct udp_pcb *dst_pcb)
{
@@ -148,7 +148,7 @@ udp_new_port(struct udp_pcb *dst_pcb)
return tmp_port;
}
-#else
+#else /* GAZELLE_UDP_NEW_PORT */
static u16_t
udp_new_port(void)
{
@@ -170,7 +170,7 @@ again:
}
return udp_port;
}
-#endif
+#endif /* GAZELLE_UDP_NEW_PORT */
/** Common code to see if the current input packet matches the pcb
* (current input packet is accessed via ip(4/6)_current_* macros)
@@ -433,21 +433,21 @@ udp_input(struct pbuf *p, struct netif *inp)
#endif /* LWIP_UDPLITE */
{
if (udphdr->chksum != 0) {
-#if CHECKSUM_CHECK_UDP_HW
+#if OFFLOAD_CHECKSUM_CHECK_UDP
u64_t ret = 0;
if (netif_get_rxol_flags(inp) & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) {
- ret = is_cksum_bad(p);
+ ret = ol_chksum_check_udp(p);
} else {
ret = ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len,
ip_current_src_addr(),
ip_current_dest_addr());
}
if (ret != 0) {
-#else /* CHECKSUM_CHECK_UDP_HW */
+#else /* OFFLOAD_CHECKSUM_CHECK_UDP */
if (ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len,
ip_current_src_addr(),
ip_current_dest_addr()) != 0) {
-#endif /* CHECKSUM_CHECK_UDP_HW */
+#endif /* OFFLOAD_CHECKSUM_CHECK_UDP */
goto chkerr;
}
}
@@ -994,19 +994,19 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
} else
#endif /* LWIP_CHECKSUM_ON_COPY */
{
-#if CHECKSUM_GEN_UDP_HW
+#if OFFLOAD_CHECKSUM_GEN_UDP
if ( (netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
(netif->mtu) && (p->tot_len <= netif->mtu)) {
- udph_cksum_set(q, UDP_HLEN);
+ ol_chksum_gen_udp(q, UDP_HLEN);
udpchksum = 0;
} else {
udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
src_ip, dst_ip);
}
-#else /* CHECKSUM_GEN_UDP_HW */
+#else /* OFFLOAD_CHECKSUM_GEN_UDP */
udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
src_ip, dst_ip);
-#endif /* CHECKSUM_GEN_UDP_HW */
+#endif /* OFFLOAD_CHECKSUM_GEN_UDP */
}
/* chksum zero must become 0xffff, as zero means 'no checksum' */
@@ -1363,12 +1363,15 @@ udp_remove(struct udp_pcb *pcb)
}
}
}
+
#if GAZELLE_UDP_ENABLE
struct gazelle_quintuple qtuple = {0};
qtuple.src_port = lwip_htons(pcb->local_port);
vdev_reg_xmit(REG_RING_UDP_BIND_CLOSE, &qtuple);
+#endif /* GAZELLE_UDP_ENABLE */
+#if GAZELLE_UDP_NEW_PORT
udp_release_port(pcb->local_port);
-#endif
+#endif /* GAZELLE_UDP_NEW_PORT */
memp_free(MEMP_UDP_PCB, pcb);
}
diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h
index 2bb9675..16fe999 100644
--- a/src/include/lwip/pbuf.h
+++ b/src/include/lwip/pbuf.h
@@ -224,7 +224,7 @@ struct pbuf {
/** For incoming packets, this contains the input netif's index */
u8_t if_idx;
-#if GAZELLE_ENABLE && CHECKSUM_OFFLOAD_ALL
+#if GAZELLE_ENABLE
volatile u8_t allow_append;
pthread_spinlock_t pbuf_lock;
struct tcp_pcb *pcb;
diff --git a/src/include/lwipgz_offload.h b/src/include/lwipgz_offload.h
index 0b9d8ee..19b0190 100644
--- a/src/include/lwipgz_offload.h
+++ b/src/include/lwipgz_offload.h
@@ -38,12 +38,11 @@
#if GAZELLE_ENABLE
#include <stdbool.h>
#include <rte_ethdev.h>
-#include "dpdk_version.h"
-
-#if CHECKSUM_OFFLOAD_ALL
#include <rte_mbuf_core.h>
+#include <rte_ip.h>
+
+#include "dpdk_version.h"
#include "lwip/pbuf.h"
-#endif
#define PBUF_TO_MBUF(p) ((struct rte_mbuf *)RTE_PTR_SUB(p, sizeof(struct rte_mbuf)))
@@ -61,53 +60,57 @@ static inline void pbuf_set_vlan(struct pbuf *p, u16_t vlan_tci)
PBUF_TO_MBUF(p)->vlan_tci = vlan_tci;
}
-#if CHECKSUM_CHECK_IP_HW
-// for ip4_input
-static inline u64_t is_cksum_ipbad(struct pbuf *p) {
+#if OFFLOAD_CHECKSUM_CHECK_IP
+// replaces inet_chksum() for ip4_input
+static inline u64_t ol_chksum_check_ip(struct pbuf *p)
+{
return PBUF_TO_MBUF(p)->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD);
}
-#endif /* CHECKSUM_CHECK_IP_HW */
-
-#if (CHECKSUM_CHECK_TCP_HW || CHECKSUM_CHECK_UDP_HW)
-// for tcp_input and udp_input
-static inline u64_t is_cksum_bad(struct pbuf *p) {
- return PBUF_TO_MBUF(p)->ol_flags & (RTE_MBUF_F_RX_L4_CKSUM_BAD);
-}
-#endif /* (CHECKSUM_CHECK_TCP_HW || CHECKSUM_CHECK_UDP_HW) */
+#endif /* OFFLOAD_CHECKSUM_CHECK_IP */
-#if CHECKSUM_GEN_IP_HW
-static inline void ethh_cksum_set(struct pbuf *p, u16_t len) {
+#if OFFLOAD_CHECKSUM_GEN_IP
+static inline void ol_chksum_gen_eth(struct pbuf *p, u16_t len)
+{
PBUF_TO_MBUF(p)->l2_len = len;
}
-// replaces IPH_CHKSUM_SET
-static inline void iph_cksum_set(struct pbuf *p, u16_t len, bool do_ipcksum) {
+// replaces inet_chksum() for ip4_output
+static inline void ol_chksum_gen_ip(struct pbuf *p, u16_t len, bool do_ipcksum)
+{
PBUF_TO_MBUF(p)->ol_flags |= ((len == IP_HLEN) ? RTE_MBUF_F_TX_IPV4 : RTE_MBUF_F_TX_IPV6);
if (do_ipcksum) {
PBUF_TO_MBUF(p)->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
}
PBUF_TO_MBUF(p)->l3_len = len;
}
-#endif /* CHECKSUM_GEN_IP_HW */
+#endif /* OFFLOAD_CHECKSUM_GEN_IP */
-// replace ip_chksum_pseudo
-#if (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_UDP_HW)
-#include <rte_ip.h>
+#if OFFLOAD_CHECKSUM_CHECK_TCP || OFFLOAD_CHECKSUM_CHECK_UDP
+// replace ip_chksum_pseudo() for tcp_input
+static inline u64_t ol_chksum_check_l4(struct pbuf *p)
+{
+ return PBUF_TO_MBUF(p)->ol_flags & (RTE_MBUF_F_RX_L4_CKSUM_BAD);
+}
+#define ol_chksum_check_tcp ol_chksum_check_l4
+#define ol_chksum_check_udp ol_chksum_check_l4
+#endif
-#if CHECKSUM_GEN_TCP_HW
-static inline void tcph_cksum_set(struct pbuf *p, u16_t len) {
+#if OFFLOAD_CHECKSUM_GEN_TCP
+// replace ip_chksum_pseudo() for tcp_output
+static inline void ol_chksum_gen_tcp(struct pbuf *p, u16_t len)
+{
PBUF_TO_MBUF(p)->l4_len = len;
PBUF_TO_MBUF(p)->ol_flags |= RTE_MBUF_F_TX_TCP_CKSUM;
}
-#endif /* CHECKSUM_GEN_TCP_HW */
+#endif /* OFFLOAD_CHECKSUM_GEN_TCP */
-#if CHECKSUM_GEN_UDP_HW
-static inline void udph_cksum_set(struct pbuf *p, u16_t len) {
+#if OFFLOAD_CHECKSUM_GEN_UDP
+static inline void ol_chksum_gen_udp(struct pbuf *p, u16_t len)
+{
PBUF_TO_MBUF(p)->l4_len = len;
PBUF_TO_MBUF(p)->ol_flags |= RTE_MBUF_F_TX_UDP_CKSUM;
}
-#endif /* CHECKSUM_GEN_UDP_HW */
-#endif /* (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_UDP_HW) */
+#endif /* OFFLOAD_CHECKSUM_GEN_UDP */
#endif /* GAZELLE_ENABLE */
#endif /* __LWIPGZ_OFFLOAD_H__ */
diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
index caccf63..e001657 100644
--- a/src/include/lwipopts.h
+++ b/src/include/lwipopts.h
@@ -53,13 +53,15 @@
#define GAZELLE_TCP_PCB_HASH 1
#define GAZELLE_TCP_ACTIVE_HTABLE_SIZE (GAZELLE_MAX_CLIENTS >> 1)
-#define GAZELLE_TCP_MAX_DATA_ACK_NUM 256
+#define GAZELLE_TCP_NEW_PORT 1
+
#define GAZELLE_TCP_MAX_PBUF_CHAIN_LEN 40
#define GAZELLE_TCP_MIN_TSO_SEG_LEN 256
#define GAZELLE_UDP_ENABLE 1
+#define GAZELLE_UDP_NEW_PORT 1
/*
@@ -69,25 +71,26 @@
*/
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1 /* checksum ability check before checksum*/
-// rx cksum
-#define CHECKSUM_CHECK_IP 1 /* master switch */
-#define CHECKSUM_CHECK_TCP 1 /* master switch */
-#define CHECKSUM_CHECK_UDP 1 /* master switch */
-// tx cksum
-#define CHECKSUM_GEN_IP 1 /* master switch */
-#define CHECKSUM_GEN_TCP 1 /* master switch */
-#define CHECKSUM_GEN_UDP 1 /* master switch */
-
-// rx offload cksum
-#define CHECKSUM_CHECK_IP_HW (1 && CHECKSUM_CHECK_IP) /* hardware switch */
-#define CHECKSUM_CHECK_TCP_HW (1 && CHECKSUM_CHECK_TCP) /* hardware switch */
-#define CHECKSUM_CHECK_UDP_HW (1 && CHECKSUM_CHECK_UDP) /* hardware switch */
-// tx offload cksum
-#define CHECKSUM_GEN_IP_HW (1 && CHECKSUM_GEN_IP) /* hardware switch */
-#define CHECKSUM_GEN_TCP_HW (1 && CHECKSUM_GEN_TCP) /* hardware switch */
-#define CHECKSUM_GEN_UDP_HW (1 && CHECKSUM_GEN_UDP) /* hardware switch */
-
-#define CHECKSUM_OFFLOAD_ALL (CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW || CHECKSUM_CHECK_IP_HW || CHECKSUM_CHECK_TCP_HW || CHECKSUM_CHECK_UDP_HW || CHECKSUM_GEN_UDP_HW)
+/* master switch */
+#define CHECKSUM_CHECK_IP 1
+#define CHECKSUM_GEN_IP 1
+
+#define CHECKSUM_CHECK_TCP 1
+#define CHECKSUM_GEN_TCP 1
+
+#define CHECKSUM_CHECK_UDP 1
+#define CHECKSUM_GEN_UDP 1
+
+/* hardware switch */
+#define OFFLOAD_CHECKSUM_CHECK_IP (1 && CHECKSUM_CHECK_IP)
+#define OFFLOAD_CHECKSUM_GEN_IP (1 && CHECKSUM_GEN_IP)
+
+#define OFFLOAD_CHECKSUM_CHECK_TCP (1 && CHECKSUM_CHECK_TCP)
+#define OFFLOAD_CHECKSUM_GEN_TCP (1 && CHECKSUM_GEN_TCP)
+
+#define OFFLOAD_CHECKSUM_CHECK_UDP (1 && CHECKSUM_CHECK_UDP)
+#define OFFLOAD_CHECKSUM_GEN_UDP (1 && CHECKSUM_GEN_UDP)
+
/*
---------------------------------------
diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c
index 385a50a..beae698 100644
--- a/src/netif/ethernet.c
+++ b/src/netif/ethernet.c
@@ -56,7 +56,7 @@
#include "netif/ppp/pppoe.h"
#endif /* PPPOE_SUPPORT */
-#if GAZELLE_ENABLE && (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_IP_HW)
+#if OFFLOAD_CHECKSUM_GEN_IP
#include "lwipgz_offload.h"
#endif
@@ -340,11 +340,11 @@ ethernet_output(struct netif * netif, struct pbuf * p,
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
("ethernet_output: sending packet %p\n", (void *)p));
-#if CHECKSUM_GEN_IP_HW || CHECKSUM_GEN_TCP_HW
- if (netif->vlan_enable && !(netif->txol_flags & RTE_ETH_TX_OFFLOAD_VLAN_INSERT)) {
- ethh_cksum_set(p, sizeof(*ethhdr) + SIZEOF_VLAN_HDR);
+#if OFFLOAD_CHECKSUM_GEN_IP
+ if (netif->vlan_enable && !(netif_get_txol_flags(netif) & RTE_ETH_TX_OFFLOAD_VLAN_INSERT)) {
+ ol_chksum_gen_eth(p, sizeof(*ethhdr) + SIZEOF_VLAN_HDR);
} else {
- ethh_cksum_set(p, sizeof(*ethhdr));
+ ol_chksum_gen_eth(p, sizeof(*ethhdr));
}
#endif
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。