]> git.proxmox.com Git - qemu.git/commitdiff
net: add tap_set_offload()
authorMark McLoughlin <markmc@redhat.com>
Thu, 22 Oct 2009 16:43:46 +0000 (17:43 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 27 Oct 2009 17:29:02 +0000 (12:29 -0500)
This API allows virtio-net to enable various offload features on a
tap interface - e.g. to tell the host kernel it can pass up partial
checksums to userspace.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
net.c
net.h
tap-linux.h

diff --git a/net.c b/net.c
index 6f14e22d8159e3d6d05a54a92b6a0f5244501858..b061491b7faa489670f7732e21a58d1a13876e42 100644 (file)
--- a/net.c
+++ b/net.c
@@ -1302,6 +1302,9 @@ int tap_has_vnet_hdr(VLANClientState *vc)
 void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
 {
 }
+void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn)
+{
+}
 #else /* !defined(_WIN32) */
 
 /* Maximum GSO packet size (64k) plus plenty of room for
@@ -1539,6 +1542,27 @@ static int tap_probe_vnet_hdr(int fd)
     return ifr.ifr_flags & IFF_VNET_HDR;
 }
 
+void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn)
+{
+    TAPState *s = vc->opaque;
+    unsigned int offload = 0;
+
+    if (csum) {
+        offload |= TUN_F_CSUM;
+        if (tso4)
+            offload |= TUN_F_TSO4;
+        if (tso6)
+            offload |= TUN_F_TSO6;
+        if ((tso4 || tso6) && ecn)
+            offload |= TUN_F_TSO_ECN;
+    }
+
+    if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) {
+        fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
+                strerror(errno));
+    }
+}
+
 static void tap_cleanup(VLANClientState *vc)
 {
     TAPState *s = vc->opaque;
diff --git a/net.h b/net.h
index e0adc69660829aa0ada341d9827f1e9a8a07dae8..c1bfdbe7cd960d33be9b5a7372f02446e9e1cfca 100644 (file)
--- a/net.h
+++ b/net.h
@@ -182,5 +182,6 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
 
 int tap_has_vnet_hdr(VLANClientState *vc);
 void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
+void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn);
 
 #endif
index 8e7534829ef6cf546ce1b5bf157c97e10ed1b5e3..241cf836a46aba07cc5acc2cd353e2f8c43968e4 100644 (file)
@@ -22,6 +22,7 @@
 /* Ioctl defines */
 #define TUNSETIFF     _IOW('T', 202, int)
 #define TUNGETFEATURES _IOR('T', 207, unsigned int)
+#define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
 #define TUNGETIFF      _IOR('T', 210, unsigned int)
 #define TUNSETSNDBUF   _IOW('T', 212, int)
 
 #define IFF_NO_PI      0x1000
 #define IFF_VNET_HDR   0x4000
 
+/* Features for GSO (TUNSETOFFLOAD). */
+#define TUN_F_CSUM     0x01    /* You can hand me unchecksummed packets. */
+#define TUN_F_TSO4     0x02    /* I can handle TSO for IPv4 packets */
+#define TUN_F_TSO6     0x04    /* I can handle TSO for IPv6 packets */
+#define TUN_F_TSO_ECN  0x08    /* I can handle TSO with ECN bits. */
+
 struct virtio_net_hdr
 {
     uint8_t flags;