diff options
author | Mohsin Kazmi <sykazmi@cisco.com> | 2022-07-18 11:21:05 +0000 |
---|---|---|
committer | Beno�t Ganne <bganne@cisco.com> | 2022-07-25 14:03:48 +0000 |
commit | 8636a320413c12d1747c695ac594ca643ac539ba (patch) | |
tree | 9c0ba086b2f92827a0a32585f3b52a839e574796 | |
parent | c8cd079a0004b75892a08c7cac9a48b39e24e580 (diff) |
libmemif: fix chain buffer support
Type: fix
This patch fixes chain buffer support as transmit side
missing to set the flag to the descriptor in case of
chain buffers.
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I73ff11be69a388f14fea39a19272d8eb76148fba
-rw-r--r-- | extras/libmemif/examples/common/icmp_proto.c | 59 | ||||
-rw-r--r-- | extras/libmemif/examples/common/icmp_proto.h | 11 | ||||
-rw-r--r-- | extras/libmemif/examples/common/packet_handler.c | 32 | ||||
-rw-r--r-- | extras/libmemif/src/main.c | 2 |
4 files changed, 38 insertions, 66 deletions
diff --git a/extras/libmemif/examples/common/icmp_proto.c b/extras/libmemif/examples/common/icmp_proto.c index fafc8e425b9..70825eafdb2 100644 --- a/extras/libmemif/examples/common/icmp_proto.c +++ b/extras/libmemif/examples/common/icmp_proto.c @@ -198,54 +198,6 @@ resolve_icmp (struct icmphdr *icmp, void *icmp_resp) return sizeof (struct icmphdr); } -int -resolve_packet (void *in_pck, ssize_t in_size, void *out_pck, - uint32_t *out_size, uint8_t ip_addr[4], uint8_t hw_addr[6]) -{ - struct ether_header *eh; - struct ether_arp *eah; - struct iphdr *ip, *ip_out; - struct icmphdr *icmp; - *out_size = 0; - - if ((in_pck == NULL) || (out_pck == NULL)) - return -1; - - eh = (struct ether_header *) in_pck; - *out_size = resolve_eth (eh, out_pck, hw_addr); - - if (eh->ether_type == 0x0608) - { - eah = (struct ether_arp *) (in_pck + *out_size); - *out_size += resolve_eth_arp (eah, out_pck + *out_size, ip_addr); - } - else if (eh->ether_type == 0x0008) - { -#ifdef ICMP_DBG - print_packet (in_pck + *out_size); -#endif - ip = (struct iphdr *) (in_pck + *out_size); - ip_out = (struct iphdr *) (out_pck + *out_size); - *out_size += resolve_ip (ip, out_pck + *out_size, ip_addr); - if (ip->protocol == 1) - { - icmp = (struct icmphdr *) (in_pck + *out_size); - *out_size += resolve_icmp (icmp, out_pck + *out_size); - ((struct icmphdr *) (out_pck + *out_size - sizeof (struct icmphdr))) - ->checksum = cksum (out_pck + *out_size - sizeof (struct icmphdr), - sizeof (struct icmphdr)); - /* payload */ - memcpy (out_pck + *out_size, in_pck + *out_size, - in_size - *out_size); - *out_size = in_size; - ip_out->tot_len = - __bswap_16 (*out_size - sizeof (struct ether_header)); - ip_out->check = cksum (ip_out, sizeof (struct iphdr)); - } - } - return 0; -} - static ssize_t generate_eth (struct ether_header *eh, uint8_t hw_daddr[6]) { @@ -373,8 +325,8 @@ generate_packet2 (void *pck, uint32_t *size, uint8_t saddr[4], while (0) int -resolve_packet_zero_copy (void *pck, uint32_t *size, uint8_t ip_addr[4], - uint8_t hw_addr[6]) +resolve_packet (void *pck, uint32_t *size, uint8_t ip_addr[4], + uint8_t hw_addr[6]) { struct ether_header *eh; struct ether_arp *eah; @@ -385,6 +337,10 @@ resolve_packet_zero_copy (void *pck, uint32_t *size, uint8_t ip_addr[4], if (pck == NULL) return 0; +#ifdef ICMP_DBG + print_packet (pck); +#endif + GET_HEADER (eh, struct ether_header, pck, offset); memcpy (eh->ether_dhost, eh->ether_shost, 6); @@ -450,8 +406,7 @@ resolve_packet_zero_copy (void *pck, uint32_t *size, uint8_t ip_addr[4], } int -resolve_packet_zero_copy_add_encap (void **pck_, uint32_t *size, - uint8_t ip_addr[4]) +resolve_packet_with_encap (void **pck_, uint32_t *size, uint8_t ip_addr[4]) { struct ether_header *eh; struct iphdr *ip; diff --git a/extras/libmemif/examples/common/icmp_proto.h b/extras/libmemif/examples/common/icmp_proto.h index e346a3b13f7..1371146cd40 100644 --- a/extras/libmemif/examples/common/icmp_proto.h +++ b/extras/libmemif/examples/common/icmp_proto.h @@ -24,17 +24,12 @@ typedef enum ICMPR_FLOW_MODE_IP, } icmpr_flow_mode_t; -int resolve_packet (void *in_pck, ssize_t in_size, void *out_pck, - uint32_t *out_size, uint8_t ip_addr[4], - uint8_t hw_addr[6]); - /* resolve packet in place */ -int resolve_packet_zero_copy (void *pck, uint32_t *size, uint8_t ip_addr[4], - uint8_t hw_addr[6]); +int resolve_packet (void *pck, uint32_t *size, uint8_t ip_addr[4], + uint8_t hw_addr[6]); /* resolve packet in place and add eth encap */ -int resolve_packet_zero_copy_add_encap (void **pck, uint32_t *size, - uint8_t ip_addr[4]); +int resolve_packet_with_encap (void **pck, uint32_t *size, uint8_t ip_addr[4]); int generate_packet (void *pck, uint32_t *size, uint8_t saddr[4], uint8_t daddr[4], uint8_t hw_daddr[6], uint32_t seq); diff --git a/extras/libmemif/examples/common/packet_handler.c b/extras/libmemif/examples/common/packet_handler.c index 705cc728a36..9d3e4d703c1 100644 --- a/extras/libmemif/examples/common/packet_handler.c +++ b/extras/libmemif/examples/common/packet_handler.c @@ -47,19 +47,39 @@ icmp_packet_handler (memif_connection_t *c) { for (i = 0; i < c->tx_buf_num; i++) { - resolve_packet (c->rx_bufs[i].data, c->rx_bufs[i].len, - c->tx_bufs[i].data, &c->tx_bufs[i].len, c->ip_addr, - c->hw_addr); + uint32_t len; + void *packet = c->rx_bufs[i].data; + + memcpy (c->tx_bufs[i].data, c->rx_bufs[i].data, c->rx_bufs[i].len); + c->tx_bufs[i].flags = c->rx_bufs[i].flags; + len = c->tx_bufs[i].len = c->rx_bufs[i].len; + + while (c->rx_bufs[i].flags & MEMIF_BUFFER_FLAG_NEXT) + { + i++; + memcpy (c->tx_bufs[i].data, c->rx_bufs[i].data, + c->rx_bufs[i].len); + c->tx_bufs[i].flags = c->rx_bufs[i].flags; + len += c->tx_bufs[i].len = c->rx_bufs[i].len; + } + + resolve_packet (packet, &len, c->ip_addr, c->hw_addr); } } else { for (i = 0; i < c->rx_buf_num; i++) { - resolve_packet_zero_copy (c->rx_bufs[i].data, &c->rx_bufs[i].len, - c->ip_addr, c->hw_addr); + uint32_t len = c->rx_bufs[i].len; + void *packet = c->rx_bufs[i].data; + while (c->rx_bufs[i].flags & MEMIF_BUFFER_FLAG_NEXT) + { + i++; + len += c->rx_bufs[i].len; + } + resolve_packet (packet, &len, c->ip_addr, c->hw_addr); } } return 0; -}
\ No newline at end of file +} diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index 21b39947260..2a4cd817a65 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -1751,6 +1751,8 @@ memif_tx_burst (memif_conn_handle_t conn, uint16_t qid, } d = &ring->desc[b0->desc_index & mask]; d->length = b0->len; + d->flags = + ((b0->flags & MEMIF_BUFFER_FLAG_NEXT) == 1) ? MEMIF_DESC_FLAG_NEXT : 0; if (!c->args.is_master) { // reset headroom |