From e050402804f5d637603ca41082b9f7a6bcf032a8 Mon Sep 17 00:00:00 2001 From: zhengjiebing Date: Fri, 20 Oct 2023 09:17:09 +0800 Subject: [PATCH 1/4] ipv6 --- 0074-enable-ipv6.patch | 404 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 404 insertions(+) create mode 100644 0074-enable-ipv6.patch diff --git a/0074-enable-ipv6.patch b/0074-enable-ipv6.patch new file mode 100644 index 0000000..657a416 --- /dev/null +++ b/0074-enable-ipv6.patch @@ -0,0 +1,404 @@ +diff -Nur lwip-2.1.3-org/src/api/sockets.c lwip-2.1.3-ipv6/src/api/sockets.c +--- lwip-2.1.3-org/src/api/sockets.c 2023-10-08 10:38:50.335167280 +0800 ++++ lwip-2.1.3-ipv6/src/api/sockets.c 2023-10-16 16:01:44.679167280 +0800 +@@ -113,6 +113,14 @@ + #endif /* LWIP_IPV4 */ + + #if LWIP_IPV6 ++#if GAZELLE_ENABLE ++#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ ++ (sin6)->sin6_family = AF_INET6; \ ++ (sin6)->sin6_port = lwip_htons((port)); \ ++ (sin6)->sin6_flowinfo = 0; \ ++ inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ ++ (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); }while(0) ++#else + #define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ + (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ + (sin6)->sin6_family = AF_INET6; \ +@@ -120,6 +128,8 @@ + (sin6)->sin6_flowinfo = 0; \ + inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ + (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); }while(0) ++#endif /* GAZELLE_ENABLE */ ++ + #define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ + inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ + if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) { \ +@@ -555,8 +565,9 @@ + LWIP_UNUSED_ARG(accepted); + + #if GAZELLE_ENABLE +- int type, protocol = 0, domain = AF_INET; +- switch (NETCONNTYPE_GROUP(newconn->type)) { ++ int type, protocol = 0; ++ int domain = AF_INET; ++ switch (newconn->type) { + case NETCONN_RAW: + type = SOCK_RAW; + break; +@@ -567,6 +578,10 @@ + case NETCONN_TCP: + type = SOCK_STREAM; + break; ++ case NETCONN_TCP_IPV6: ++ type = SOCK_STREAM; ++ domain = AF_INET6; ++ break; + default: + type = -1; + break; +diff -Nur lwip-2.1.3-org/src/core/dir.mk lwip-2.1.3-ipv6/src/core/dir.mk +--- lwip-2.1.3-org/src/core/dir.mk 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/dir.mk 2023-10-08 10:39:36.035167280 +0800 +@@ -1,6 +1,8 @@ + SRC = def.c inet_chksum.c init.c ip.c mem.c memp.c netif.c pbuf.c \ + raw.c tcp.c tcp_in.c tcp_out.c timeouts.c udp.c stats.c\ + ipv4/icmp.c ipv4/ip4_addr.c ipv4/ip4_frag.c ipv4/etharp.c \ +- ipv4/ip4.c ipv4/igmp.c ++ ipv4/ip4.c ipv4/igmp.c ipv6/icmp6.c ipv6/ip6_addr.c ipv6/ip6_frag.c \ ++ ipv6/ethip6.c ipv6/ip6.c ipv6/dhcp6.c ipv6/inet6.c \ ++ ipv6/mld6.c ipv6/nd6.c + + $(eval $(call register_dir, core, $(SRC))) +diff -Nur lwip-2.1.3-org/src/core/init.c lwip-2.1.3-ipv6/src/core/init.c +--- lwip-2.1.3-org/src/core/init.c 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/init.c 2023-10-10 15:57:49.619167280 +0800 +@@ -347,7 +347,9 @@ + mem_init(); + memp_init(); + pbuf_init(); ++#if !GAZELLE_ENABLE + netif_init(); ++#endif /* GAZELLE_ENABLE */ + #if LWIP_IPV4 + ip_init(); + #if LWIP_ARP +diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6_frag.c lwip-2.1.3-ipv6/src/core/ipv6/ip6_frag.c +--- lwip-2.1.3-org/src/core/ipv6/ip6_frag.c 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/ipv6/ip6_frag.c 2023-10-08 10:39:36.035167280 +0800 +@@ -689,6 +689,7 @@ + memp_free(MEMP_FRAG_PBUF, p); + } + ++#if !GAZELLE_ENABLE + /** Free-callback function to free a 'struct pbuf_custom_ref', called by + * pbuf_free. */ + static void +@@ -702,6 +703,7 @@ + } + ip6_frag_free_pbuf_custom_ref(pcr); + } ++#endif + #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ + + /** +@@ -816,7 +818,9 @@ + } + pbuf_ref(p); + pcr->original = p; ++#if !GAZELLE_ENABLE + pcr->pc.custom_free_function = ip6_frag_free_pbuf_custom; ++#endif + + /* Add it to end of rambuf's chain, but using pbuf_cat, not pbuf_chain + * so that it is removed when pbuf_dechain is later called on rambuf. +diff -Nur lwip-2.1.3-org/src/core/tcp.c lwip-2.1.3-ipv6/src/core/tcp.c +--- lwip-2.1.3-org/src/core/tcp.c 2023-10-08 10:38:50.335167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp.c 2023-10-08 10:39:36.035167280 +0800 +@@ -1156,10 +1156,20 @@ + + if (__atomic_load_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) { + #if GAZELLE_ENABLE +- if (port_in_stack_queue(pcb->remote_ip.addr, pcb->local_ip.addr, 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; ++ if (IP_IS_V4_VAL(pcb->local_ip)) { ++ // ipv4 ++ if (port_in_stack_queue(pcb->remote_ip.u_addr.ip4.addr, pcb->local_ip.u_addr.ip4.addr, 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 { ++ // ipv6 ++ if (port_in_stack_queue6((uint32_t *)pcb->remote_ip.u_addr.ip6.addr, (uint32_t *)pcb->local_ip.u_addr.ip6.addr, 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); +diff -Nur lwip-2.1.3-org/src/core/tcp_in.c lwip-2.1.3-ipv6/src/core/tcp_in.c +--- lwip-2.1.3-org/src/core/tcp_in.c 2023-10-08 10:38:50.335167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp_in.c 2023-10-08 10:39:36.035167280 +0800 +@@ -309,9 +309,16 @@ + prev = NULL; + + #if GAZELLE_TCP_PCB_HASH +- idx = TUPLE4_HASH_FN( ip_current_dest_addr()->addr, tcphdr->dest, +- ip_current_src_addr()->addr, tcphdr->src) & ++ if (IP_IS_V4(ip_current_dest_addr())) { ++ idx = TUPLE4_HASH_FN( ip_current_dest_addr()->u_addr.ip4.addr, tcphdr->dest, ++ ip_current_src_addr()->u_addr.ip4.addr, tcphdr->src) & + (tcp_active_htable->size - 1); ++ } else { ++ idx = TUPLE4_HASH_FN6( ip_current_dest_addr()->u_addr.ip6.addr, tcphdr->dest, ++ ip_current_src_addr()->u_addr.ip6.addr, tcphdr->src) & ++ (tcp_active_htable->size - 1); ++ } ++ + head = &tcp_active_htable->array[idx].chain; + tcppcb_hlist_for_each(pcb, node, head) { + #else +diff -Nur lwip-2.1.3-org/src/core/tcp_out.c lwip-2.1.3-ipv6/src/core/tcp_out.c +--- lwip-2.1.3-org/src/core/tcp_out.c 2023-10-08 10:38:50.335167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp_out.c 2023-10-08 10:39:36.035167280 +0800 +@@ -139,7 +139,7 @@ + static struct netif * + tcp_route(const struct tcp_pcb *pcb, const ip_addr_t *src, const ip_addr_t *dst) + { +- LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */ ++ // LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */ + + if ((pcb != NULL) && (pcb->netif_idx != NETIF_NO_INDEX)) { + return netif_get_by_index(pcb->netif_idx); +diff -Nur lwip-2.1.3-org/src/core/udp.c lwip-2.1.3-ipv6/src/core/udp.c +--- lwip-2.1.3-org/src/core/udp.c 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/udp.c 2023-10-16 16:13:40.667167280 +0800 +@@ -132,11 +132,19 @@ + } + + if (__atomic_load_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) { +- if (port_in_stack_queue(dst_pcb->remote_ip.addr, dst_pcb->local_ip.addr, dst_pcb->remote_port, udp_port)) { +- tmp_port = udp_port; +- __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); +- break; +- } ++ if (IP_IS_V4_VAL(dst_pcb->local_ip)) { ++ if (port_in_stack_queue(dst_pcb->remote_ip.u_addr.ip4.addr, dst_pcb->local_ip.u_addr.ip4.addr, dst_pcb->remote_port, udp_port)) { ++ tmp_port = udp_port; ++ __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); ++ break; ++ } ++ } else { ++ if (port_in_stack_queue6((uint32_t *)dst_pcb->remote_ip.u_addr.ip6.addr, (uint32_t *)dst_pcb->local_ip.u_addr.ip6.addr, dst_pcb->remote_port, udp_port)) { ++ tmp_port = udp_port; ++ __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); ++ break; ++ } ++ } + } + n++; + if (n > UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START) { +diff -Nur lwip-2.1.3-org/src/include/dpdk_cksum.h lwip-2.1.3-ipv6/src/include/dpdk_cksum.h +--- lwip-2.1.3-org/src/include/dpdk_cksum.h 2023-10-08 10:38:50.343167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/dpdk_cksum.h 2023-10-08 10:39:36.039167280 +0800 +@@ -97,21 +97,41 @@ + static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, + const ip_addr_t *src, const ip_addr_t *dst) + { +- struct ipv4_psd_header { +- uint32_t src_addr; /* IP address of source host. */ +- uint32_t dst_addr; /* IP address of destination host. */ +- uint8_t zero; /* zero. */ +- uint8_t proto; /* L4 protocol type. */ +- uint16_t len; /* L4 length. */ +- } psd_hdr; +- +- psd_hdr.src_addr = ip4_addr_get_u32(src); +- psd_hdr.dst_addr = ip4_addr_get_u32(dst); +- psd_hdr.proto = proto; +- psd_hdr.len = lwip_htons(proto_len); +- psd_hdr.zero = 0; ++ if (IP_IS_V4_VAL(*src)) { ++ struct ipv4_psd_header { ++ uint32_t src_addr; /* IP address of source host. */ ++ uint32_t dst_addr; /* IP address of destination host. */ ++ uint8_t zero; /* zero. */ ++ uint8_t proto; /* L4 protocol type. */ ++ uint16_t len; /* L4 length. */ ++ } psd_hdr; + +- return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); ++ psd_hdr.src_addr = (*src).u_addr.ip4.addr; ++ psd_hdr.dst_addr = (*dst).u_addr.ip4.addr; ++ psd_hdr.proto = proto; ++ psd_hdr.len = lwip_htons(proto_len); ++ psd_hdr.zero = 0; ++ ++ return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); ++ } else { ++ struct ipv6_psd_header { ++ uint32_t src_addr[4]; /* IP address of source host. */ ++ uint32_t dst_addr[4]; /* IP address of destination host. */ ++ uint8_t zero; /* zero. */ ++ uint8_t proto; /* L4 protocol type. */ ++ uint16_t len; /* L4 length. */ ++ } psd_hdr; ++ ++ memcpy(psd_hdr.src_addr, (*src).u_addr.ip6.addr, sizeof((*src).u_addr.ip6.addr)); ++ memcpy(psd_hdr.dst_addr, (*dst).u_addr.ip6.addr, sizeof((*dst).u_addr.ip6.addr)); ++ psd_hdr.proto = proto; ++ psd_hdr.len = lwip_htons(proto_len); ++ psd_hdr.zero = 0; ++ ++ return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); ++ } ++ ++ return 0; + } + #endif /* (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_UDP_HW) */ + +diff -Nur lwip-2.1.3-org/src/include/lwip/opt.h lwip-2.1.3-ipv6/src/include/lwip/opt.h +--- lwip-2.1.3-org/src/include/lwip/opt.h 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/opt.h 2023-10-08 10:39:36.039167280 +0800 +@@ -2396,7 +2396,7 @@ + * LWIP_IPV6==1: Enable IPv6 + */ + #if !defined LWIP_IPV6 || defined __DOXYGEN__ +-#define LWIP_IPV6 0 ++#define LWIP_IPV6 1 + #endif + + /** +diff -Nur lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h +--- lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h 2023-10-16 16:15:16.711167280 +0800 +@@ -347,11 +347,23 @@ + LWIP_ASSERT("Invalid parameter", pcb != NULL); + + struct gazelle_quintuple qtuple; +- qtuple.protocol = 0; +- qtuple.src_ip = pcb->local_ip.addr; +- qtuple.src_port = lwip_htons(pcb->local_port); +- qtuple.dst_ip = pcb->remote_ip.addr; +- qtuple.dst_port = lwip_htons(pcb->remote_port); ++ ++ if (IP_IS_V4_VAL(pcb->local_ip)) { ++ qtuple.protocol = 0; ++ qtuple.src_ip = pcb->local_ip.u_addr.ip4.addr; ++ qtuple.src_port = lwip_htons(pcb->local_port); ++ qtuple.dst_ip = pcb->remote_ip.u_addr.ip4.addr; ++ qtuple.dst_port = lwip_htons(pcb->remote_port); ++ } else { ++ qtuple.protocol = 1; ++ qtuple.src_port = lwip_htons(pcb->local_port); ++ qtuple.dst_port = lwip_htons(pcb->remote_port); ++ ++ for (int i = 0; i < 4; i++) { ++ qtuple.src_ip6[i] = pcb->local_ip.u_addr.ip6.addr[i]; ++ qtuple.dst_ip6[i] = pcb->remote_ip.u_addr.ip6.addr[i]; ++ } ++ } + + #if GAZELLE_TCP_REUSE_IPPORT + if (reg_type == REG_RING_TCP_CONNECT_CLOSE) { +@@ -474,9 +486,15 @@ + u32_t idx; \ + struct hlist_head *hd; \ + struct tcp_hash_table *htb = pcbs; \ +- idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ +- (npcb)->remote_ip.addr, (npcb)->remote_port) & \ ++ if (IP_IS_V4_VAL((npcb)->local_ip)) { \ ++ idx = TUPLE4_HASH_FN((npcb)->local_ip.u_addr.ip4.addr, (npcb)->local_port, \ ++ (npcb)->remote_ip.u_addr.ip4.addr, (npcb)->remote_port) & \ ++ (htb->size - 1); \ ++ } else { \ ++ idx = TUPLE4_HASH_FN6((npcb)->local_ip.u_addr.ip6.addr, (npcb)->local_port, \ ++ (npcb)->remote_ip.u_addr.ip6.addr, (npcb)->remote_port) & \ + (htb->size - 1); \ ++ } \ + hd = &htb->array[idx].chain; \ + hlist_add_head(&(npcb)->tcp_node, hd); \ + tcp_timer_needed(); \ +diff -Nur lwip-2.1.3-org/src/include/lwip/sockets.h lwip-2.1.3-ipv6/src/include/lwip/sockets.h +--- lwip-2.1.3-org/src/include/lwip/sockets.h 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/sockets.h 2023-10-08 16:46:35.527167280 +0800 +@@ -88,7 +88,9 @@ + + #if LWIP_IPV6 + struct sockaddr_in6 { ++#if !GAZELLE_ENABLE + u8_t sin6_len; /* length of this structure */ ++#endif + sa_family_t sin6_family; /* AF_INET6 */ + in_port_t sin6_port; /* Transport layer port # */ + u32_t sin6_flowinfo; /* IPv6 flow information */ +diff -Nur lwip-2.1.3-org/src/include/lwip/tcp.h lwip-2.1.3-ipv6/src/include/lwip/tcp.h +--- lwip-2.1.3-org/src/include/lwip/tcp.h 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/tcp.h 2023-10-08 10:39:36.039167280 +0800 +@@ -476,8 +476,22 @@ + return c; + } + ++static inline unsigned int jhash_3words6(unsigned int *a, unsigned int *b, unsigned int c) ++{ ++ for (int i = 0; i < 4; i++) { ++ unsigned int e = *((unsigned int *)a + i) + JHASH_INITVAL; ++ unsigned int f = *((unsigned int *)b + i) + JHASH_INITVAL; ++ ++ __jhash_final(e, f, c); ++ } ++ ++ return c; ++} ++ + #define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) + ++#define TUPLE4_HASH_FN6(laddr, lport, faddr, fport) jhash_3words6(laddr, faddr,lport|(fport<<16)) ++ + #define tcppcb_hlist_for_each(tcppcb, node, list) \ + hlist_for_each_entry(tcppcb, node, list, tcp_node) + +diff -Nur lwip-2.1.3-org/src/include/lwipopts.h lwip-2.1.3-ipv6/src/include/lwipopts.h +--- lwip-2.1.3-org/src/include/lwipopts.h 2023-10-08 10:38:50.339167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-08 10:39:36.035167280 +0800 +@@ -62,6 +62,14 @@ + + + /* ++ ------------------------------------- ++ ----------- IPv6 options ----------- ++ ------------------------------------- ++*/ ++#define LWIP_IPV6 1 ++ ++ ++/* + ---------------------------------- + ---------- NIC offloads ---------- + ---------------------------------- +diff -Nur lwip-2.1.3-org/src/include/reg_sock.h lwip-2.1.3-ipv6/src/include/reg_sock.h +--- lwip-2.1.3-org/src/include/reg_sock.h 2023-10-08 10:38:50.343167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/reg_sock.h 2023-10-08 10:39:36.035167280 +0800 +@@ -50,6 +50,9 @@ + uint16_t dst_port; + uint32_t src_ip; + uint32_t dst_ip; ++ ++ uint32_t src_ip6[4]; ++ uint32_t dst_ip6[4]; + }; + + struct reg_ring_msg { +@@ -61,5 +64,7 @@ + + extern int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); + extern bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); ++extern bool port_in_stack_queue6(uint32_t *src_ip, uint32_t *dst_ip, uint16_t src_port, uint16_t dst_port); ++ + + #endif /* __REG_SOCK_H__ */ +diff -Nur lwip-2.1.3-org/.vscode/settings.json lwip-2.1.3-ipv6/.vscode/settings.json +--- lwip-2.1.3-org/.vscode/settings.json 1970-01-01 08:00:00.000000000 +0800 ++++ lwip-2.1.3-ipv6/.vscode/settings.json 2023-10-08 10:39:36.043167280 +0800 +@@ -0,0 +1,5 @@ ++{ ++ "files.associations": { ++ "type_traits": "c" ++ } ++} +\ No newline at end of file -- Gitee From ec9e421e6ef87febe40095f9a00bc3e77169b052 Mon Sep 17 00:00:00 2001 From: zhengjiebing Date: Fri, 20 Oct 2023 09:31:29 +0800 Subject: [PATCH 2/4] ipv6 --- lwip.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/lwip.spec b/lwip.spec index 20ee3a4..9243e04 100644 --- a/lwip.spec +++ b/lwip.spec @@ -85,6 +85,7 @@ Patch9069: 0070-add-CHECKSUM_UDP-when-not-support-OFFLOAD_UDP_CHECKS.patch Patch9070: 0071-fix-pbuf-tot_len-incorrect-after-pbuf_split_64k-is-c.patch Patch9071: 0072-add-O_NONBLOCK-and-FIONBIO-when-not-defined.patch Patch9072: 0073-lstack_lwip-external-api-start-with-do_lwip_-prefix.patch +Patch9073: 0074-enable-ipv6.patch BuildRequires: gcc-c++ dos2unix dpdk-devel -- Gitee From 6f6e736f7a73616565d4a242c18684999b68c682 Mon Sep 17 00:00:00 2001 From: zhengjiebing Date: Tue, 24 Oct 2023 15:18:08 +0800 Subject: [PATCH 3/4] ipv6 --- 0074-enable-ipv6.patch | 333 +++++++++++++++++------------------------ 1 file changed, 138 insertions(+), 195 deletions(-) diff --git a/0074-enable-ipv6.patch b/0074-enable-ipv6.patch index 657a416..a412c19 100644 --- a/0074-enable-ipv6.patch +++ b/0074-enable-ipv6.patch @@ -1,6 +1,6 @@ diff -Nur lwip-2.1.3-org/src/api/sockets.c lwip-2.1.3-ipv6/src/api/sockets.c ---- lwip-2.1.3-org/src/api/sockets.c 2023-10-08 10:38:50.335167280 +0800 -+++ lwip-2.1.3-ipv6/src/api/sockets.c 2023-10-16 16:01:44.679167280 +0800 +--- lwip-2.1.3-org/src/api/sockets.c 2023-10-23 11:23:55.587167280 +0800 ++++ lwip-2.1.3-ipv6/src/api/sockets.c 2023-10-24 10:12:24.763167280 +0800 @@ -113,6 +113,14 @@ #endif /* LWIP_IPV4 */ @@ -16,41 +16,39 @@ diff -Nur lwip-2.1.3-org/src/api/sockets.c lwip-2.1.3-ipv6/src/api/sockets.c #define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ (sin6)->sin6_family = AF_INET6; \ -@@ -120,6 +128,8 @@ +@@ -120,6 +128,7 @@ (sin6)->sin6_flowinfo = 0; \ inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); }while(0) +#endif /* GAZELLE_ENABLE */ -+ #define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) { \ -@@ -555,8 +565,9 @@ - LWIP_UNUSED_ARG(accepted); +@@ -556,7 +565,7 @@ #if GAZELLE_ENABLE -- int type, protocol = 0, domain = AF_INET; + int type, protocol = 0, domain = AF_INET; - switch (NETCONNTYPE_GROUP(newconn->type)) { -+ int type, protocol = 0; -+ int domain = AF_INET; + switch (newconn->type) { case NETCONN_RAW: type = SOCK_RAW; break; -@@ -567,6 +578,10 @@ +@@ -567,6 +576,12 @@ case NETCONN_TCP: type = SOCK_STREAM; break; ++#if LWIP_IPV6 + case NETCONN_TCP_IPV6: + type = SOCK_STREAM; + domain = AF_INET6; + break; ++#endif default: type = -1; break; diff -Nur lwip-2.1.3-org/src/core/dir.mk lwip-2.1.3-ipv6/src/core/dir.mk ---- lwip-2.1.3-org/src/core/dir.mk 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/dir.mk 2023-10-08 10:39:36.035167280 +0800 +--- lwip-2.1.3-org/src/core/dir.mk 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/dir.mk 2023-10-23 13:44:26.939167280 +0800 @@ -1,6 +1,8 @@ SRC = def.c inet_chksum.c init.c ip.c mem.c memp.c netif.c pbuf.c \ raw.c tcp.c tcp_in.c tcp_out.c timeouts.c udp.c stats.c\ @@ -62,8 +60,8 @@ diff -Nur lwip-2.1.3-org/src/core/dir.mk lwip-2.1.3-ipv6/src/core/dir.mk $(eval $(call register_dir, core, $(SRC))) diff -Nur lwip-2.1.3-org/src/core/init.c lwip-2.1.3-ipv6/src/core/init.c ---- lwip-2.1.3-org/src/core/init.c 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/init.c 2023-10-10 15:57:49.619167280 +0800 +--- lwip-2.1.3-org/src/core/init.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/init.c 2023-10-23 13:46:39.139167280 +0800 @@ -347,7 +347,9 @@ mem_init(); memp_init(); @@ -74,9 +72,41 @@ diff -Nur lwip-2.1.3-org/src/core/init.c lwip-2.1.3-ipv6/src/core/init.c #if LWIP_IPV4 ip_init(); #if LWIP_ARP +diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6.c lwip-2.1.3-ipv6/src/core/ipv6/ip6.c +--- lwip-2.1.3-org/src/core/ipv6/ip6.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/ipv6/ip6.c 2023-10-23 21:28:30.231167280 +0800 +@@ -60,6 +60,10 @@ + #include "lwip/debug.h" + #include "lwip/stats.h" + ++#if GAZELLE_ENABLE && (CHECKSUM_CHECK_IP_HW || CHECKSUM_GEN_IP_HW) ++#include "dpdk_cksum.h" ++#endif ++ + #ifdef LWIP_HOOK_FILENAME + #include LWIP_HOOK_FILENAME + #endif +@@ -1270,9 +1274,15 @@ + #endif /* ENABLE_LOOPBACK */ + #if LWIP_IPV6_FRAG + /* don't fragment if interface has mtu set to 0 [loopif] */ +- if (netif_mtu6(netif) && (p->tot_len > nd6_get_destination_mtu(dest, netif))) { +- return ip6_frag(p, netif, dest); ++#if GAZELLE_ENABLE ++ if (!(get_eth_params_tx_ol() & DEV_TX_OFFLOAD_TCP_TSO)) { ++#endif ++ if (netif_mtu6(netif) && (p->tot_len > nd6_get_destination_mtu(dest, netif))) { ++ return ip6_frag(p, netif, dest); ++ } ++#if GAZELLE_ENABLE + } ++#endif + #endif /* LWIP_IPV6_FRAG */ + + LWIP_DEBUGF(IP6_DEBUG, ("netif->output_ip6()\n")); diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6_frag.c lwip-2.1.3-ipv6/src/core/ipv6/ip6_frag.c ---- lwip-2.1.3-org/src/core/ipv6/ip6_frag.c 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/ipv6/ip6_frag.c 2023-10-08 10:39:36.035167280 +0800 +--- lwip-2.1.3-org/src/core/ipv6/ip6_frag.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/ipv6/ip6_frag.c 2023-10-23 15:27:16.491167280 +0800 @@ -689,6 +689,7 @@ memp_free(MEMP_FRAG_PBUF, p); } @@ -89,7 +119,7 @@ diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6_frag.c lwip-2.1.3-ipv6/src/core/ipv6/ } ip6_frag_free_pbuf_custom_ref(pcr); } -+#endif ++#endif /* !GAZELLE_ENABLE */ #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ /** @@ -99,175 +129,90 @@ diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6_frag.c lwip-2.1.3-ipv6/src/core/ipv6/ pcr->original = p; +#if !GAZELLE_ENABLE pcr->pc.custom_free_function = ip6_frag_free_pbuf_custom; -+#endif ++#endif /* !GAZELLE_ENABLE */ /* Add it to end of rambuf's chain, but using pbuf_cat, not pbuf_chain * so that it is removed when pbuf_dechain is later called on rambuf. diff -Nur lwip-2.1.3-org/src/core/tcp.c lwip-2.1.3-ipv6/src/core/tcp.c ---- lwip-2.1.3-org/src/core/tcp.c 2023-10-08 10:38:50.335167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/tcp.c 2023-10-08 10:39:36.035167280 +0800 -@@ -1156,10 +1156,20 @@ +--- lwip-2.1.3-org/src/core/tcp.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp.c 2023-10-23 14:46:12.375167280 +0800 +@@ -1156,7 +1156,7 @@ if (__atomic_load_n(&port_state[tcp_port - TCP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) { #if GAZELLE_ENABLE - if (port_in_stack_queue(pcb->remote_ip.addr, pcb->local_ip.addr, 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; -+ if (IP_IS_V4_VAL(pcb->local_ip)) { -+ // ipv4 -+ if (port_in_stack_queue(pcb->remote_ip.u_addr.ip4.addr, pcb->local_ip.u_addr.ip4.addr, 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 { -+ // ipv6 -+ if (port_in_stack_queue6((uint32_t *)pcb->remote_ip.u_addr.ip6.addr, (uint32_t *)pcb->local_ip.u_addr.ip6.addr, 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); ++ if (port_in_stack_queue(pcb->remote_ip, 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; diff -Nur lwip-2.1.3-org/src/core/tcp_in.c lwip-2.1.3-ipv6/src/core/tcp_in.c ---- lwip-2.1.3-org/src/core/tcp_in.c 2023-10-08 10:38:50.335167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/tcp_in.c 2023-10-08 10:39:36.035167280 +0800 -@@ -309,9 +309,16 @@ +--- lwip-2.1.3-org/src/core/tcp_in.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp_in.c 2023-10-23 15:06:48.523167280 +0800 +@@ -309,8 +309,8 @@ prev = NULL; #if GAZELLE_TCP_PCB_HASH - idx = TUPLE4_HASH_FN( ip_current_dest_addr()->addr, tcphdr->dest, - ip_current_src_addr()->addr, tcphdr->src) & -+ if (IP_IS_V4(ip_current_dest_addr())) { -+ idx = TUPLE4_HASH_FN( ip_current_dest_addr()->u_addr.ip4.addr, tcphdr->dest, -+ ip_current_src_addr()->u_addr.ip4.addr, tcphdr->src) & ++ idx = TUPLE4_HASH_FN( ip_current_dest_addr(), tcphdr->dest, ++ ip_current_src_addr(), tcphdr->src) & (tcp_active_htable->size - 1); -+ } else { -+ idx = TUPLE4_HASH_FN6( ip_current_dest_addr()->u_addr.ip6.addr, tcphdr->dest, -+ ip_current_src_addr()->u_addr.ip6.addr, tcphdr->src) & -+ (tcp_active_htable->size - 1); -+ } -+ head = &tcp_active_htable->array[idx].chain; tcppcb_hlist_for_each(pcb, node, head) { - #else diff -Nur lwip-2.1.3-org/src/core/tcp_out.c lwip-2.1.3-ipv6/src/core/tcp_out.c ---- lwip-2.1.3-org/src/core/tcp_out.c 2023-10-08 10:38:50.335167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/tcp_out.c 2023-10-08 10:39:36.035167280 +0800 -@@ -139,7 +139,7 @@ +--- lwip-2.1.3-org/src/core/tcp_out.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/tcp_out.c 2023-10-23 14:44:18.511167280 +0800 +@@ -139,7 +139,9 @@ static struct netif * tcp_route(const struct tcp_pcb *pcb, const ip_addr_t *src, const ip_addr_t *dst) { -- LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */ -+ // LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */ ++#if LWIP_IPV6 + LWIP_UNUSED_ARG(src); /* in case IPv4-only and source-based routing is disabled */ ++#endif /* LWIP_IPV6 */ if ((pcb != NULL) && (pcb->netif_idx != NETIF_NO_INDEX)) { return netif_get_by_index(pcb->netif_idx); diff -Nur lwip-2.1.3-org/src/core/udp.c lwip-2.1.3-ipv6/src/core/udp.c ---- lwip-2.1.3-org/src/core/udp.c 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/udp.c 2023-10-16 16:13:40.667167280 +0800 -@@ -132,11 +132,19 @@ +--- lwip-2.1.3-org/src/core/udp.c 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/udp.c 2023-10-23 14:45:44.863167280 +0800 +@@ -132,7 +132,7 @@ } if (__atomic_load_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], __ATOMIC_ACQUIRE) == 0) { - if (port_in_stack_queue(dst_pcb->remote_ip.addr, dst_pcb->local_ip.addr, dst_pcb->remote_port, udp_port)) { -- tmp_port = udp_port; -- __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); -- break; -- } -+ if (IP_IS_V4_VAL(dst_pcb->local_ip)) { -+ if (port_in_stack_queue(dst_pcb->remote_ip.u_addr.ip4.addr, dst_pcb->local_ip.u_addr.ip4.addr, dst_pcb->remote_port, udp_port)) { -+ tmp_port = udp_port; -+ __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); -+ break; -+ } -+ } else { -+ if (port_in_stack_queue6((uint32_t *)dst_pcb->remote_ip.u_addr.ip6.addr, (uint32_t *)dst_pcb->local_ip.u_addr.ip6.addr, dst_pcb->remote_port, udp_port)) { -+ tmp_port = udp_port; -+ __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); -+ break; -+ } -+ } - } - n++; - if (n > UDP_LOCAL_PORT_RANGE_END - UDP_LOCAL_PORT_RANGE_START) { ++ if (port_in_stack_queue(dst_pcb->remote_ip, dst_pcb->local_ip, dst_pcb->remote_port, udp_port)) { + tmp_port = udp_port; + __atomic_store_n(&port_state[udp_port - UDP_LOCAL_PORT_RANGE_START], 1, __ATOMIC_RELEASE); + break; diff -Nur lwip-2.1.3-org/src/include/dpdk_cksum.h lwip-2.1.3-ipv6/src/include/dpdk_cksum.h ---- lwip-2.1.3-org/src/include/dpdk_cksum.h 2023-10-08 10:38:50.343167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/dpdk_cksum.h 2023-10-08 10:39:36.039167280 +0800 -@@ -97,21 +97,41 @@ +--- lwip-2.1.3-org/src/include/dpdk_cksum.h 2023-10-23 11:23:55.595167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/dpdk_cksum.h 2023-10-24 10:08:28.203167280 +0800 +@@ -97,16 +97,16 @@ static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dst) { - struct ipv4_psd_header { - uint32_t src_addr; /* IP address of source host. */ - uint32_t dst_addr; /* IP address of destination host. */ -- uint8_t zero; /* zero. */ -- uint8_t proto; /* L4 protocol type. */ -- uint16_t len; /* L4 length. */ -- } psd_hdr; -- ++ struct ip_psd_header { ++ ip_addr_t src_addr; /* IP address of source host. */ ++ ip_addr_t dst_addr; /* IP address of destination host. */ + uint8_t zero; /* zero. */ + uint8_t proto; /* L4 protocol type. */ + uint16_t len; /* L4 length. */ + } psd_hdr; + - psd_hdr.src_addr = ip4_addr_get_u32(src); - psd_hdr.dst_addr = ip4_addr_get_u32(dst); -- psd_hdr.proto = proto; -- psd_hdr.len = lwip_htons(proto_len); -- psd_hdr.zero = 0; -+ if (IP_IS_V4_VAL(*src)) { -+ struct ipv4_psd_header { -+ uint32_t src_addr; /* IP address of source host. */ -+ uint32_t dst_addr; /* IP address of destination host. */ -+ uint8_t zero; /* zero. */ -+ uint8_t proto; /* L4 protocol type. */ -+ uint16_t len; /* L4 length. */ -+ } psd_hdr; - -- return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); -+ psd_hdr.src_addr = (*src).u_addr.ip4.addr; -+ psd_hdr.dst_addr = (*dst).u_addr.ip4.addr; -+ psd_hdr.proto = proto; -+ psd_hdr.len = lwip_htons(proto_len); -+ psd_hdr.zero = 0; -+ -+ return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); -+ } else { -+ struct ipv6_psd_header { -+ uint32_t src_addr[4]; /* IP address of source host. */ -+ uint32_t dst_addr[4]; /* IP address of destination host. */ -+ uint8_t zero; /* zero. */ -+ uint8_t proto; /* L4 protocol type. */ -+ uint16_t len; /* L4 length. */ -+ } psd_hdr; -+ -+ memcpy(psd_hdr.src_addr, (*src).u_addr.ip6.addr, sizeof((*src).u_addr.ip6.addr)); -+ memcpy(psd_hdr.dst_addr, (*dst).u_addr.ip6.addr, sizeof((*dst).u_addr.ip6.addr)); -+ psd_hdr.proto = proto; -+ psd_hdr.len = lwip_htons(proto_len); -+ psd_hdr.zero = 0; -+ -+ return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr)); -+ } -+ -+ return 0; - } - #endif /* (CHECKSUM_GEN_TCP_HW || CHECKSUM_GEN_UDP_HW) */ - -diff -Nur lwip-2.1.3-org/src/include/lwip/opt.h lwip-2.1.3-ipv6/src/include/lwip/opt.h ---- lwip-2.1.3-org/src/include/lwip/opt.h 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwip/opt.h 2023-10-08 10:39:36.039167280 +0800 -@@ -2396,7 +2396,7 @@ - * LWIP_IPV6==1: Enable IPv6 - */ - #if !defined LWIP_IPV6 || defined __DOXYGEN__ --#define LWIP_IPV6 0 -+#define LWIP_IPV6 1 - #endif - - /** ++ ip_addr_copy(psd_hdr.src_addr, *src); ++ ip_addr_copy(psd_hdr.dst_addr, *dst); + psd_hdr.proto = proto; + psd_hdr.len = lwip_htons(proto_len); + psd_hdr.zero = 0; diff -Nur lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h ---- lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h 2023-10-16 16:15:16.711167280 +0800 -@@ -347,11 +347,23 @@ +--- lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h 2023-10-23 11:23:55.595167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h 2023-10-24 09:30:26.355167280 +0800 +@@ -347,11 +347,24 @@ LWIP_ASSERT("Invalid parameter", pcb != NULL); struct gazelle_quintuple qtuple; @@ -276,14 +221,14 @@ diff -Nur lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h lwip-2.1.3-ipv6/src/in - qtuple.src_port = lwip_htons(pcb->local_port); - qtuple.dst_ip = pcb->remote_ip.addr; - qtuple.dst_port = lwip_htons(pcb->remote_port); -+ + if (IP_IS_V4_VAL(pcb->local_ip)) { + qtuple.protocol = 0; -+ qtuple.src_ip = pcb->local_ip.u_addr.ip4.addr; ++ qtuple.src_ip = ip_2_ip4(&pcb->local_ip)->addr; + qtuple.src_port = lwip_htons(pcb->local_port); -+ qtuple.dst_ip = pcb->remote_ip.u_addr.ip4.addr; ++ qtuple.dst_ip = ip_2_ip4(&pcb->local_ip)->addr; + qtuple.dst_port = lwip_htons(pcb->remote_port); + } else { ++#if LWIP_IPV6 + qtuple.protocol = 1; + qtuple.src_port = lwip_htons(pcb->local_port); + qtuple.dst_port = lwip_htons(pcb->remote_port); @@ -292,48 +237,43 @@ diff -Nur lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h lwip-2.1.3-ipv6/src/in + qtuple.src_ip6[i] = pcb->local_ip.u_addr.ip6.addr[i]; + qtuple.dst_ip6[i] = pcb->remote_ip.u_addr.ip6.addr[i]; + } ++#endif + } #if GAZELLE_TCP_REUSE_IPPORT if (reg_type == REG_RING_TCP_CONNECT_CLOSE) { -@@ -474,9 +486,15 @@ +@@ -474,8 +487,8 @@ u32_t idx; \ struct hlist_head *hd; \ struct tcp_hash_table *htb = pcbs; \ - idx = TUPLE4_HASH_FN((npcb)->local_ip.addr, (npcb)->local_port, \ - (npcb)->remote_ip.addr, (npcb)->remote_port) & \ -+ if (IP_IS_V4_VAL((npcb)->local_ip)) { \ -+ idx = TUPLE4_HASH_FN((npcb)->local_ip.u_addr.ip4.addr, (npcb)->local_port, \ -+ (npcb)->remote_ip.u_addr.ip4.addr, (npcb)->remote_port) & \ -+ (htb->size - 1); \ -+ } else { \ -+ idx = TUPLE4_HASH_FN6((npcb)->local_ip.u_addr.ip6.addr, (npcb)->local_port, \ -+ (npcb)->remote_ip.u_addr.ip6.addr, (npcb)->remote_port) & \ ++ idx = TUPLE4_HASH_FN(&((npcb)->local_ip), (npcb)->local_port, \ ++ &((npcb)->remote_ip), (npcb)->remote_port) & \ (htb->size - 1); \ -+ } \ hd = &htb->array[idx].chain; \ hlist_add_head(&(npcb)->tcp_node, hd); \ - tcp_timer_needed(); \ diff -Nur lwip-2.1.3-org/src/include/lwip/sockets.h lwip-2.1.3-ipv6/src/include/lwip/sockets.h ---- lwip-2.1.3-org/src/include/lwip/sockets.h 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwip/sockets.h 2023-10-08 16:46:35.527167280 +0800 +--- lwip-2.1.3-org/src/include/lwip/sockets.h 2023-10-23 11:23:55.595167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/sockets.h 2023-10-23 15:01:56.223167280 +0800 @@ -88,7 +88,9 @@ #if LWIP_IPV6 struct sockaddr_in6 { -+#if !GAZELLE_ENABLE ++#if !GAZELLE_ENABLE u8_t sin6_len; /* length of this structure */ -+#endif ++#endif /* GAZELLE_ENABLE */ sa_family_t sin6_family; /* AF_INET6 */ in_port_t sin6_port; /* Transport layer port # */ u32_t sin6_flowinfo; /* IPv6 flow information */ diff -Nur lwip-2.1.3-org/src/include/lwip/tcp.h lwip-2.1.3-ipv6/src/include/lwip/tcp.h ---- lwip-2.1.3-org/src/include/lwip/tcp.h 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwip/tcp.h 2023-10-08 10:39:36.039167280 +0800 -@@ -476,8 +476,22 @@ +--- lwip-2.1.3-org/src/include/lwip/tcp.h 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwip/tcp.h 2023-10-24 09:54:35.735167280 +0800 +@@ -476,7 +476,26 @@ return c; } +-#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) +static inline unsigned int jhash_3words6(unsigned int *a, unsigned int *b, unsigned int c) +{ + for (int i = 0; i < 4; i++) { @@ -346,17 +286,21 @@ diff -Nur lwip-2.1.3-org/src/include/lwip/tcp.h lwip-2.1.3-ipv6/src/include/lwip + return c; +} + - #define TUPLE4_HASH_FN(laddr, lport, faddr, fport) jhash_3words(laddr, faddr,lport|(fport<<16)) ++#if LWIP_IPV4 && LWIP_IPV6 ++#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) \ ++ (IP_IS_V4(laddr) ? jhash_3words(ip_2_ip4(laddr)->addr, ip_2_ip4(faddr)->addr, lport|(fport<<16)) \ ++ : jhash_3words6(ip_2_ip6(laddr)->addr, ip_2_ip6(faddr)->addr, lport|(fport<<16))) ++#elif LWIP_IPV4 ++#define TUPLE4_HASH_FN(laddr, lport, faddr, fport) \ ++ jhash_3words(ip_2_ip4(laddr)->addr, ip_2_ip4(faddr)->addr, lport|(fport<<16)) ++#endif -+#define TUPLE4_HASH_FN6(laddr, lport, faddr, fport) jhash_3words6(laddr, faddr,lport|(fport<<16)) -+ #define tcppcb_hlist_for_each(tcppcb, node, list) \ hlist_for_each_entry(tcppcb, node, list, tcp_node) - diff -Nur lwip-2.1.3-org/src/include/lwipopts.h lwip-2.1.3-ipv6/src/include/lwipopts.h ---- lwip-2.1.3-org/src/include/lwipopts.h 2023-10-08 10:38:50.339167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-08 10:39:36.035167280 +0800 -@@ -62,6 +62,14 @@ +--- lwip-2.1.3-org/src/include/lwipopts.h 2023-10-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-24 10:12:59.751167280 +0800 +@@ -179,6 +179,14 @@ /* @@ -368,37 +312,36 @@ diff -Nur lwip-2.1.3-org/src/include/lwipopts.h lwip-2.1.3-ipv6/src/include/lwip + + +/* - ---------------------------------- - ---------- NIC offloads ---------- - ---------------------------------- + --------------------------------- + ---------- UDP options ---------- + --------------------------------- diff -Nur lwip-2.1.3-org/src/include/reg_sock.h lwip-2.1.3-ipv6/src/include/reg_sock.h ---- lwip-2.1.3-org/src/include/reg_sock.h 2023-10-08 10:38:50.343167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/reg_sock.h 2023-10-08 10:39:36.035167280 +0800 -@@ -50,6 +50,9 @@ +--- lwip-2.1.3-org/src/include/reg_sock.h 2023-10-23 11:23:55.595167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/reg_sock.h 2023-10-24 09:33:37.895167280 +0800 +@@ -34,6 +34,7 @@ + #define __REG_SOCK_H__ + + #include ++#include "lwip/ip_addr.h" + + enum reg_ring_type { + REG_RING_TCP_LISTEN = 0, +@@ -50,6 +51,10 @@ uint16_t dst_port; uint32_t src_ip; uint32_t dst_ip; -+ ++#if LWIP_IPV6 + uint32_t src_ip6[4]; + uint32_t dst_ip6[4]; ++#endif }; struct reg_ring_msg { -@@ -61,5 +64,7 @@ +@@ -60,6 +65,6 @@ + }; extern int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); - extern bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -+extern bool port_in_stack_queue6(uint32_t *src_ip, uint32_t *dst_ip, uint16_t src_port, uint16_t dst_port); -+ +-extern bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); ++extern bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port); #endif /* __REG_SOCK_H__ */ -diff -Nur lwip-2.1.3-org/.vscode/settings.json lwip-2.1.3-ipv6/.vscode/settings.json ---- lwip-2.1.3-org/.vscode/settings.json 1970-01-01 08:00:00.000000000 +0800 -+++ lwip-2.1.3-ipv6/.vscode/settings.json 2023-10-08 10:39:36.043167280 +0800 -@@ -0,0 +1,5 @@ -+{ -+ "files.associations": { -+ "type_traits": "c" -+ } -+} -\ No newline at end of file -- Gitee From 02016adceed6812f44048c2d4b8bc4a2495e7ed7 Mon Sep 17 00:00:00 2001 From: zhengjiebing Date: Thu, 26 Oct 2023 16:57:07 +0800 Subject: [PATCH 4/4] ipv6 --- 0074-enable-ipv6.patch | 74 +++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/0074-enable-ipv6.patch b/0074-enable-ipv6.patch index a412c19..cc45de4 100644 --- a/0074-enable-ipv6.patch +++ b/0074-enable-ipv6.patch @@ -1,6 +1,6 @@ diff -Nur lwip-2.1.3-org/src/api/sockets.c lwip-2.1.3-ipv6/src/api/sockets.c --- lwip-2.1.3-org/src/api/sockets.c 2023-10-23 11:23:55.587167280 +0800 -+++ lwip-2.1.3-ipv6/src/api/sockets.c 2023-10-24 10:12:24.763167280 +0800 ++++ lwip-2.1.3-ipv6/src/api/sockets.c 2023-10-25 17:56:00.707167280 +0800 @@ -113,6 +113,14 @@ #endif /* LWIP_IPV4 */ @@ -24,28 +24,25 @@ diff -Nur lwip-2.1.3-org/src/api/sockets.c lwip-2.1.3-ipv6/src/api/sockets.c #define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) { \ -@@ -556,7 +565,7 @@ +@@ -555,7 +564,8 @@ + LWIP_UNUSED_ARG(accepted); #if GAZELLE_ENABLE - int type, protocol = 0, domain = AF_INET; -- switch (NETCONNTYPE_GROUP(newconn->type)) { -+ switch (newconn->type) { +- int type, protocol = 0, domain = AF_INET; ++ int type, protocol = 0; ++ int domain = NETCONNTYPE_ISIPV6(newconn->type) ? AF_INET6 : AF_INET; + switch (NETCONNTYPE_GROUP(newconn->type)) { case NETCONN_RAW: type = SOCK_RAW; - break; -@@ -567,6 +576,12 @@ - case NETCONN_TCP: - type = SOCK_STREAM; - break; -+#if LWIP_IPV6 -+ case NETCONN_TCP_IPV6: -+ type = SOCK_STREAM; -+ domain = AF_INET6; -+ break; -+#endif - default: - type = -1; - break; +@@ -2952,7 +2962,7 @@ + *namelen = saddr.sa.sa_len; + } + #else +- *namelen = LWIP_MIN(*namelen, sizeof(saddr)); ++ *namelen = (IP_GET_TYPE(&naddr) == IPADDR_TYPE_V4 ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)); + #endif + MEMCPY(name, &saddr, *namelen); + diff -Nur lwip-2.1.3-org/src/core/dir.mk lwip-2.1.3-ipv6/src/core/dir.mk --- lwip-2.1.3-org/src/core/dir.mk 2023-10-23 11:23:55.591167280 +0800 +++ lwip-2.1.3-ipv6/src/core/dir.mk 2023-10-23 13:44:26.939167280 +0800 @@ -74,7 +71,7 @@ diff -Nur lwip-2.1.3-org/src/core/init.c lwip-2.1.3-ipv6/src/core/init.c #if LWIP_ARP diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6.c lwip-2.1.3-ipv6/src/core/ipv6/ip6.c --- lwip-2.1.3-org/src/core/ipv6/ip6.c 2023-10-23 11:23:55.591167280 +0800 -+++ lwip-2.1.3-ipv6/src/core/ipv6/ip6.c 2023-10-23 21:28:30.231167280 +0800 ++++ lwip-2.1.3-ipv6/src/core/ipv6/ip6.c 2023-10-26 10:39:20.775167280 +0800 @@ -60,6 +60,10 @@ #include "lwip/debug.h" #include "lwip/stats.h" @@ -86,7 +83,18 @@ diff -Nur lwip-2.1.3-org/src/core/ipv6/ip6.c lwip-2.1.3-ipv6/src/core/ipv6/ip6.c #ifdef LWIP_HOOK_FILENAME #include LWIP_HOOK_FILENAME #endif -@@ -1270,9 +1274,15 @@ +@@ -1232,6 +1236,10 @@ + /* 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 */ ++ + } else { + /* IP header already included in p */ + ip6hdr = (struct ip6_hdr *)p->payload; +@@ -1270,9 +1278,15 @@ #endif /* ENABLE_LOOPBACK */ #if LWIP_IPV6_FRAG /* don't fragment if interface has mtu set to 0 [loopif] */ @@ -186,7 +194,16 @@ diff -Nur lwip-2.1.3-org/src/core/udp.c lwip-2.1.3-ipv6/src/core/udp.c break; diff -Nur lwip-2.1.3-org/src/include/dpdk_cksum.h lwip-2.1.3-ipv6/src/include/dpdk_cksum.h --- lwip-2.1.3-org/src/include/dpdk_cksum.h 2023-10-23 11:23:55.595167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/dpdk_cksum.h 2023-10-24 10:08:28.203167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/dpdk_cksum.h 2023-10-26 10:33:10.627167280 +0800 +@@ -68,7 +68,7 @@ + + // replaces IPH_CHKSUM_SET + static inline void iph_cksum_set(struct pbuf *p, u16_t len, bool do_ipcksum) { +- p->ol_flags |= RTE_MBUF_F_TX_IPV4; ++ p->ol_flags |= ((len == IP_HLEN) ? RTE_MBUF_F_TX_IPV4 : RTE_MBUF_F_TX_IPV6); + if (do_ipcksum) { + p->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM; + } @@ -97,16 +97,16 @@ static inline u16_t ip_chksum_pseudo_offload(u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dst) @@ -209,6 +226,17 @@ diff -Nur lwip-2.1.3-org/src/include/dpdk_cksum.h lwip-2.1.3-ipv6/src/include/dp psd_hdr.proto = proto; psd_hdr.len = lwip_htons(proto_len); psd_hdr.zero = 0; +diff -Nur lwip-2.1.3-org/src/include/dpdk_version.h lwip-2.1.3-ipv6/src/include/dpdk_version.h +--- lwip-2.1.3-org/src/include/dpdk_version.h 2023-10-23 11:23:55.595167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/dpdk_version.h 2023-10-26 13:29:21.739167280 +0800 +@@ -43,6 +43,7 @@ + #define RTE_MBUF_F_RX_IP_CKSUM_BAD PKT_RX_IP_CKSUM_BAD + #define RTE_MBUF_F_RX_L4_CKSUM_BAD PKT_RX_L4_CKSUM_BAD + #define RTE_MBUF_F_TX_IPV4 PKT_TX_IPV4 ++#define RTE_MBUF_F_TX_IPV6 PKT_TX_IPV6 + #define RTE_MBUF_F_TX_IP_CKSUM PKT_TX_IP_CKSUM + #define RTE_MBUF_F_TX_TCP_CKSUM PKT_TX_TCP_CKSUM + #define RTE_MBUF_F_TX_TCP_SEG PKT_TX_TCP_SEG diff -Nur lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h --- lwip-2.1.3-org/src/include/lwip/priv/tcp_priv.h 2023-10-23 11:23:55.595167280 +0800 +++ lwip-2.1.3-ipv6/src/include/lwip/priv/tcp_priv.h 2023-10-24 09:30:26.355167280 +0800 @@ -299,7 +327,7 @@ diff -Nur lwip-2.1.3-org/src/include/lwip/tcp.h lwip-2.1.3-ipv6/src/include/lwip hlist_for_each_entry(tcppcb, node, list, tcp_node) diff -Nur lwip-2.1.3-org/src/include/lwipopts.h lwip-2.1.3-ipv6/src/include/lwipopts.h --- lwip-2.1.3-org/src/include/lwipopts.h 2023-10-23 11:23:55.591167280 +0800 -+++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-24 10:12:59.751167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-26 16:37:28.603167280 +0800 @@ -179,6 +179,14 @@ -- Gitee