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
This commit is contained in:

committed by
Beno�t Ganne

parent
c8cd079a00
commit
8636a32041
@ -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;
|
||||
|
@ -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],
|
||||
/* resolve packet in place */
|
||||
int resolve_packet (void *pck, uint32_t *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]);
|
||||
|
||||
/* 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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user