Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhost: fix offloading #347

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,44 @@ static int vhost_poll(struct pg_brick *brick, uint16_t *pkts_cnt,
/* count rx bytes: burst is packed so we can directly iterate */
for (int i = 0; i < count; i++) {
in[i]->l2_len = sizeof(struct ether_hdr);
struct eth_ip_l4 *hdr =
rte_pktmbuf_mtod(in[i],
struct eth_ip_l4 *);
struct eth_ip_l4 *hdr = rte_pktmbuf_mtod(in[i],
struct eth_ip_l4 *);
uint16_t eth_type = rte_cpu_to_be_16(hdr->ethernet.ether_type);
uint8_t proto;

if (eth_type == ETHER_TYPE_IPv4) {
proto = hdr->ipv4.next_proto_id;
in[i]->ol_flags |= PKT_TX_IP_CKSUM | PKT_TX_IPV4;
in[i]->l3_len = sizeof(struct ipv4_hdr);

if (proto == TCP_PROTOCOL_NUMBER)
if (proto == TCP_PROTOCOL_NUMBER) {
in[i]->l4_len = (hdr->v4tcp.data_off >> 4) * 4;
else if (proto == UDP_PROTOCOL_NUMBER)
if (in[i]->ol_flags & PKT_TX_TCP_SEG) {
in[i]->ol_flags |= PKT_TX_TCP_CKSUM;
hdr->v4tcp.cksum = 0;
hdr->v4tcp.cksum = rte_ipv4_phdr_cksum(
&hdr->ipv4, in[i]->ol_flags);
}
} else if (proto == UDP_PROTOCOL_NUMBER) {
in[i]->l4_len = sizeof(struct udp_hdr);

}
} else if (eth_type == ETHER_TYPE_IPv6) {
proto = hdr->ipv6.proto;
in[i]->l3_len = sizeof(struct ipv6_hdr);

if (proto == TCP_PROTOCOL_NUMBER)
if (proto == TCP_PROTOCOL_NUMBER) {
in[i]->l4_len = (hdr->v6tcp.data_off >> 4) * 4;
else if (proto == UDP_PROTOCOL_NUMBER)
if (in[i]->ol_flags & PKT_TX_TCP_SEG) {
hdr->v6tcp.cksum = 0;
hdr->v6tcp.cksum = rte_ipv6_phdr_cksum(
&hdr->ipv6, in[i]->ol_flags);
}
} else if (proto == UDP_PROTOCOL_NUMBER) {
in[i]->l4_len = sizeof(struct udp_hdr);
}
}

rx_bytes += rte_pktmbuf_pkt_len(in[i]);

}
rte_atomic64_add(&state->rx_bytes, rx_bytes);

Expand Down