aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--tcp_vu.c8
-rw-r--r--udp_vu.c7
-rw-r--r--vhost_user.c1
3 files changed, 12 insertions, 4 deletions
diff --git a/tcp_vu.c b/tcp_vu.c
index 3063376..7e2a7db 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -129,6 +129,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
struct vu_virtq_element flags_elem[2];
struct iov_tail payload, l2frame;
int elem_cnt, dup_elem_cnt = 0;
+ uint32_t csum_flags = IP4_CSUM;
struct iovec flags_iov[64];
struct tcp_syn_opts opts;
struct tcphdr th = { 0 };
@@ -138,6 +139,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
uint32_t seq;
int ret;
+ if (*c->pcap || !vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
+ csum_flags |= TCP_CSUM;
+
hdrlen = tcp_vu_hdrlen(CONN_V6(conn));
elem_cnt = vu_collect(vdev, vq, &flags_elem[0], 1,
@@ -174,7 +178,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
iov_from_buf(payload.iov, payload.cnt, payload.off, &opts, optlen);
tcp_fill_headers(c, conn, &eh, CONN_V4(conn) ? &ip4h : NULL,
CONN_V6(conn) ? &ip6h : NULL, &th, &payload,
- optlen, IP4_CSUM | (*c->pcap ? TCP_CSUM : 0), seq);
+ optlen, csum_flags, seq);
vu_pad(flags_elem[0].in_sg, iov_cnt, hdrlen + optlen);
@@ -520,7 +524,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
hdrlen = tcp_vu_hdrlen(v6);
check = IP4_CSUM;
- if (*c->pcap)
+ if (*c->pcap || !vu_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
check |= TCP_CSUM;
for (i = 0, previous_dlen = -1; i < frame_cnt; i++) {
struct iovec *iov = &iov_vu[frame[i].idx_iovec];
diff --git a/udp_vu.c b/udp_vu.c
index 4cfe573..e4fb105 100644
--- a/udp_vu.c
+++ b/udp_vu.c
@@ -103,6 +103,7 @@ static void udp_vu_prepare(const struct ctx *c, struct iov_tail *data,
bool ipv4 = inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr);
struct ethhdr eh;
struct udphdr uh;
+ bool no_csum;
/* ethernet header */
memcpy(eh.h_dest, c->guest_mac, sizeof(eh.h_dest));
@@ -114,17 +115,19 @@ static void udp_vu_prepare(const struct ctx *c, struct iov_tail *data,
eh.h_proto = htons(ETH_P_IPV6);
IOV_PUSH_HEADER(data, eh);
+ no_csum = vu_has_feature(c->vdev, VIRTIO_NET_F_GUEST_CSUM) && !*c->pcap;
+
/* initialize header */
if (ipv4) {
struct iphdr iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP);
- udp_update_hdr4(&iph, &uh, payload, toside, dlen, !*c->pcap);
+ udp_update_hdr4(&iph, &uh, payload, toside, dlen, no_csum);
IOV_PUSH_HEADER(data, iph);
} else {
struct ipv6hdr ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP);
- udp_update_hdr6(&ip6h, &uh, payload, toside, dlen, !*c->pcap);
+ udp_update_hdr6(&ip6h, &uh, payload, toside, dlen, no_csum);
IOV_PUSH_HEADER(data, ip6h);
}
diff --git a/vhost_user.c b/vhost_user.c
index f062bad..a1259c2 100644
--- a/vhost_user.c
+++ b/vhost_user.c
@@ -322,6 +322,7 @@ static bool vu_get_features_exec(struct vu_dev *vdev,
{
uint64_t features =
1ULL << VIRTIO_F_VERSION_1 |
+ 1ULL << VIRTIO_NET_F_GUEST_CSUM |
1ULL << VIRTIO_NET_F_MRG_RXBUF |
1ULL << VHOST_F_LOG_ALL |
1ULL << VHOST_USER_F_PROTOCOL_FEATURES;