From 417576a2c6ba1e4e2c437e78fe2d247827f2838a Mon Sep 17 00:00:00 2001 From: suchangzhi Date: Mon, 11 Nov 2024 16:37:22 +0800 Subject: [PATCH] virtio: support icmp reply --- src/lstack/netif/lstack_ethdev.c | 18 +++++++++++++++--- src/lstack/netif/lstack_vdev.c | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c index 315cced..e01d876 100644 --- a/src/lstack/netif/lstack_ethdev.c +++ b/src/lstack/netif/lstack_ethdev.c @@ -207,6 +207,10 @@ void kni_handle_tx(struct rte_mbuf *mbuf) ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) +#define IS_ICMP_PKT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ + ((ptype & RTE_PTYPE_L4_ICMP) == RTE_PTYPE_L4_ICMP) && \ + (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) + #define IS_ICMPV6_PKT(ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ ((ptype & RTE_PTYPE_L4_ICMP) == RTE_PTYPE_L4_ICMP) && \ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) @@ -257,9 +261,17 @@ int32_t eth_dev_poll(void) transfer_type = distribute_pakages(stack->pkts[i]); } if (get_global_cfg_params()->flow_bifurcation) { - uint16_t dst_port = eth_dev_get_dst_port(stack->pkts[i]); - if (virtio_distribute_pkg_to_kernel(dst_port)) { - transfer_type = TRANSFER_KERNEL; + if (unlikely(IS_ICMP_PKT(stack->pkts[i]->packet_type))) { + struct rte_icmp_hdr *icmph = rte_pktmbuf_mtod_offset(stack->pkts[i], struct rte_icmp_hdr *, + stack->pkts[i]->l2_len + stack->pkts[i]->l3_len); + if (icmph->icmp_type == RTE_IP_ICMP_ECHO_REPLY) { + transfer_type = TRANSFER_KERNEL; + } + } else { + uint16_t dst_port = eth_dev_get_dst_port(stack->pkts[i]); + if (virtio_distribute_pkg_to_kernel(dst_port)) { + transfer_type = TRANSFER_KERNEL; + } } } } diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c index b1d1a1b..9c02137 100644 --- a/src/lstack/netif/lstack_vdev.c +++ b/src/lstack/netif/lstack_vdev.c @@ -106,6 +106,8 @@ static inline void vdev_pkts_parse(struct rte_mbuf **pkts, int pkt_num) } else if (iph->next_proto_id == IPPROTO_UDP) { pkts[i]->l4_len = sizeof(struct rte_udp_hdr); pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; + } else if (iph->next_proto_id == IPPROTO_ICMP) { + pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_ICMP; } } else if (type == RTE_BE16(RTE_ETHER_TYPE_IPV6)) { -- Gitee