[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/10] tap: add VNET_LE/VNET_BE operations
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 05/10] tap: add VNET_LE/VNET_BE operations |
Date: |
Wed, 17 Jun 2015 21:38:15 +0200 |
From: Greg Kurz <address@hidden>
The linux tap and macvtap backends can be told to parse vnet headers
according to little or big endian. This is done through the TUNSETVNETLE
and TUNSETVNETBE ioctls.
This patch brings all the plumbing for QEMU to use these APIs.
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/net/net.h | 6 ++++++
net/tap-linux.h | 2 ++
net/tap_int.h | 2 ++
net/net.c | 18 ++++++++++++++++++
net/tap-linux.c | 34 ++++++++++++++++++++++++++++++++++
net/tap.c | 16 ++++++++++++++++
6 files changed, 78 insertions(+)
diff --git a/include/net/net.h b/include/net/net.h
index e66ca03..4306252 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -55,6 +55,8 @@ typedef bool (HasVnetHdrLen)(NetClientState *, int);
typedef void (UsingVnetHdr)(NetClientState *, bool);
typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
typedef void (SetVnetHdrLen)(NetClientState *, int);
+typedef int (SetVnetLE)(NetClientState *, bool);
+typedef int (SetVnetBE)(NetClientState *, bool);
typedef struct NetClientInfo {
NetClientOptionsKind type;
@@ -73,6 +75,8 @@ typedef struct NetClientInfo {
UsingVnetHdr *using_vnet_hdr;
SetOffload *set_offload;
SetVnetHdrLen *set_vnet_hdr_len;
+ SetVnetLE *set_vnet_le;
+ SetVnetBE *set_vnet_be;
} NetClientInfo;
struct NetClientState {
@@ -139,6 +143,8 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
int ecn, int ufo);
void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
+int qemu_set_vnet_le(NetClientState *nc, bool is_le);
+int qemu_set_vnet_be(NetClientState *nc, bool is_be);
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
int qemu_show_nic_models(const char *arg, const char *const *models);
void qemu_check_nic_model(NICInfo *nd, const char *model);
diff --git a/net/tap-linux.h b/net/tap-linux.h
index 1cf35d4..01dc6f8 100644
--- a/net/tap-linux.h
+++ b/net/tap-linux.h
@@ -30,6 +30,8 @@
#define TUNGETVNETHDRSZ _IOR('T', 215, int)
#define TUNSETVNETHDRSZ _IOW('T', 216, int)
#define TUNSETQUEUE _IOW('T', 217, int)
+#define TUNSETVNETLE _IOW('T', 220, int)
+#define TUNSETVNETBE _IOW('T', 222, int)
#endif
diff --git a/net/tap_int.h b/net/tap_int.h
index d12a409..2378021 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -40,6 +40,8 @@ int tap_probe_vnet_hdr_len(int fd, int len);
int tap_probe_has_ufo(int fd);
void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int
ufo);
void tap_fd_set_vnet_hdr_len(int fd, int len);
+int tap_fd_set_vnet_le(int fd, int vnet_is_le);
+int tap_fd_set_vnet_be(int fd, int vnet_is_be);
int tap_fd_enable(int fd);
int tap_fd_disable(int fd);
int tap_fd_get_ifname(int fd, char *ifname);
diff --git a/net/net.c b/net/net.c
index db6be12..5148aac 100644
--- a/net/net.c
+++ b/net/net.c
@@ -510,6 +510,24 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)
nc->info->set_vnet_hdr_len(nc, len);
}
+int qemu_set_vnet_le(NetClientState *nc, bool is_le)
+{
+ if (!nc || !nc->info->set_vnet_le) {
+ return -ENOSYS;
+ }
+
+ return nc->info->set_vnet_le(nc, is_le);
+}
+
+int qemu_set_vnet_be(NetClientState *nc, bool is_be)
+{
+ if (!nc || !nc->info->set_vnet_be) {
+ return -ENOSYS;
+ }
+
+ return nc->info->set_vnet_be(nc, is_be);
+}
+
int qemu_can_send_packet(NetClientState *sender)
{
int vm_running = runstate_is_running();
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 6c3caef..394f2a6 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -198,6 +198,40 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
}
}
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+ int arg = is_le ? 1 : 0;
+
+ if (!ioctl(fd, TUNSETVNETLE, &arg)) {
+ return 0;
+ }
+
+ /* Check if our kernel supports TUNSETVNETLE */
+ if (errno == EINVAL) {
+ return -errno;
+ }
+
+ error_report("TUNSETVNETLE ioctl() failed: %s.\n", strerror(errno));
+ abort();
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+ int arg = is_be ? 1 : 0;
+
+ if (!ioctl(fd, TUNSETVNETBE, &arg)) {
+ return 0;
+ }
+
+ /* Check if our kernel supports TUNSETVNETBE */
+ if (errno == EINVAL) {
+ return -errno;
+ }
+
+ error_report("TUNSETVNETBE ioctl() failed: %s.\n", strerror(errno));
+ abort();
+}
+
void tap_fd_set_offload(int fd, int csum, int tso4,
int tso6, int ecn, int ufo)
{
diff --git a/net/tap.c b/net/tap.c
index d1ca314..ec12dfd 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -275,6 +275,20 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool
using_vnet_hdr)
s->using_vnet_hdr = using_vnet_hdr;
}
+static int tap_set_vnet_le(NetClientState *nc, bool is_le)
+{
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
+
+ return tap_fd_set_vnet_le(s->fd, is_le);
+}
+
+static int tap_set_vnet_be(NetClientState *nc, bool is_be)
+{
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
+
+ return tap_fd_set_vnet_be(s->fd, is_be);
+}
+
static void tap_set_offload(NetClientState *nc, int csum, int tso4,
int tso6, int ecn, int ufo)
{
@@ -341,6 +355,8 @@ static NetClientInfo net_tap_info = {
.using_vnet_hdr = tap_using_vnet_hdr,
.set_offload = tap_set_offload,
.set_vnet_hdr_len = tap_set_vnet_hdr_len,
+ .set_vnet_le = tap_set_vnet_le,
+ .set_vnet_be = tap_set_vnet_be,
};
static TAPState *net_tap_fd_init(NetClientState *peer,
--
MST
- [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 01/10] vhost-user: part of virtio, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 02/10] linux-headers: sync vhost.h, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 03/10] virtio: introduce virtio_legacy_is_cross_endian(), Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 04/10] vhost: set vring endianness for legacy virtio, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 05/10] tap: add VNET_LE/VNET_BE operations,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 07/10] vhost_net: re-enable when cross endian, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 08/10] hw/core: rebase sysbus_get_fw_dev_path() to g_strdup_printf(), Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 06/10] vhost-net: tell tap backend about the vnet endianness, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 09/10] pci: Don't register a specialized 'config_write' if default behavior is intended, Michael S. Tsirkin, 2015/06/17
- [Qemu-devel] [PULL 10/10] vhost: enable vhost without without MSI-X, Michael S. Tsirkin, 2015/06/17
- Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Peter Maydell, 2015/06/18
- Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Michael S. Tsirkin, 2015/06/18
- Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Peter Maydell, 2015/06/18
- Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Michael S. Tsirkin, 2015/06/19
- Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements, Peter Maydell, 2015/06/19