diff --git a/0074-enable-ipv6.patch b/0074-enable-ipv6.patch new file mode 100644 index 0000000000000000000000000000000000000000..cc45de4e3a3a3bb827b78b56fe450f1692f8cf23 --- /dev/null +++ b/0074-enable-ipv6.patch @@ -0,0 +1,375 @@ +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-25 17:56:00.707167280 +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,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,7 +564,8 @@ + LWIP_UNUSED_ARG(accepted); + + #if GAZELLE_ENABLE +- 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; +@@ -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 +@@ -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-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(); + 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.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-26 10:39:20.775167280 +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 +@@ -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] */ +- 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-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); + } + ++#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 /* !GAZELLE_ENABLE */ + #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 /* !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-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)) { ++ 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-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) & ++ idx = TUPLE4_HASH_FN( ip_current_dest_addr(), tcphdr->dest, ++ ip_current_src_addr(), tcphdr->src) & + (tcp_active_htable->size - 1); + head = &tcp_active_htable->array[idx].chain; + tcppcb_hlist_for_each(pcb, node, head) { +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-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) + { ++#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-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)) { ++ 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-23 11:23:55.595167280 +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) + { +- struct ipv4_psd_header { +- uint32_t src_addr; /* IP address of source host. */ +- uint32_t dst_addr; /* IP address of destination host. */ ++ 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); ++ 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/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 +@@ -347,11 +347,24 @@ + 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 = ip_2_ip4(&pcb->local_ip)->addr; ++ qtuple.src_port = lwip_htons(pcb->local_port); ++ 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); ++ ++ 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]; ++ } ++#endif ++ } + + #if GAZELLE_TCP_REUSE_IPPORT + if (reg_type == REG_RING_TCP_CONNECT_CLOSE) { +@@ -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) & \ ++ 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); \ +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-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 + u8_t sin6_len; /* length of this structure */ ++#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-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++) { ++ 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; ++} ++ ++#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 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-23 11:23:55.591167280 +0800 ++++ lwip-2.1.3-ipv6/src/include/lwipopts.h 2023-10-26 16:37:28.603167280 +0800 +@@ -179,6 +179,14 @@ + + + /* ++ ------------------------------------- ++ ----------- IPv6 options ----------- ++ ------------------------------------- ++*/ ++#define LWIP_IPV6 1 ++ ++ ++/* + --------------------------------- + ---------- 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-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 { +@@ -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_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port); + + #endif /* __REG_SOCK_H__ */ diff --git a/lwip.spec b/lwip.spec index 20ee3a43ce0bd59a167a39426037b7d0a36ed182..9243e04839c0246abfd27178ac2ffe31d0eefeba 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