aboutsummaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-22 17:43:39 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-27 12:29:00 -0500
commit24e323631a662320851c498695cb4d4d82caa629 (patch)
tree6bb12028c6aa2033812490eba7dc11a65e2d2a72 /net.c
parentbb6e636443d49f7444f49ab64dc7ec6aae1493a7 (diff)
net: add tap_has_vnet_hdr() and tap_using_vnet_hdr() APIs
These lamely named functions allow virtio-net to query whether IFF_VNET_HDR is enabled on a tap interface and inform the tap code that virtio-net will supply packets with a vnet header. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/net.c b/net.c
index 59f9a52998..431101eac4 100644
--- a/net.c
+++ b/net.c
@@ -1261,7 +1261,15 @@ void do_info_usernet(Monitor *mon)
#endif /* CONFIG_SLIRP */
-#if !defined(_WIN32)
+#if defined(_WIN32)
+int tap_has_vnet_hdr(VLANClientState *vc)
+{
+ return 0;
+}
+void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
+{
+}
+#else /* !defined(_WIN32) */
/* Maximum GSO packet size (64k) plus plenty of room for
* the ethernet and virtio_net headers
@@ -1277,6 +1285,7 @@ typedef struct TAPState {
unsigned int read_poll : 1;
unsigned int write_poll : 1;
unsigned int has_vnet_hdr : 1;
+ unsigned int using_vnet_hdr : 1;
} TAPState;
static int launch_script(const char *setup_script, const char *ifname, int fd);
@@ -1339,7 +1348,7 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
struct iovec iov_copy[iovcnt + 1];
struct virtio_net_hdr hdr = { 0, };
- if (s->has_vnet_hdr) {
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
iov_copy[0].iov_base = &hdr;
iov_copy[0].iov_len = sizeof(hdr);
memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov));
@@ -1357,7 +1366,7 @@ static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
int iovcnt = 0;
struct virtio_net_hdr hdr = { 0, };
- if (s->has_vnet_hdr) {
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
iov[iovcnt].iov_base = &hdr;
iov[iovcnt].iov_len = sizeof(hdr);
iovcnt++;
@@ -1414,7 +1423,7 @@ static void tap_send(void *opaque)
break;
}
- if (s->has_vnet_hdr) {
+ if (s->has_vnet_hdr && !s->using_vnet_hdr) {
buf += sizeof(struct virtio_net_hdr);
size -= sizeof(struct virtio_net_hdr);
}
@@ -1449,6 +1458,27 @@ static int tap_set_sndbuf(TAPState *s, QemuOpts *opts)
return 0;
}
+int tap_has_vnet_hdr(VLANClientState *vc)
+{
+ TAPState *s = vc->opaque;
+
+ assert(vc->type == NET_CLIENT_TYPE_TAP);
+
+ return s->has_vnet_hdr;
+}
+
+void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr)
+{
+ TAPState *s = vc->opaque;
+
+ using_vnet_hdr = using_vnet_hdr != 0;
+
+ assert(vc->type == NET_CLIENT_TYPE_TAP);
+ assert(s->has_vnet_hdr == using_vnet_hdr);
+
+ s->using_vnet_hdr = using_vnet_hdr;
+}
+
static int tap_probe_vnet_hdr(int fd)
{
struct ifreq ifr;
@@ -1489,6 +1519,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
s = qemu_mallocz(sizeof(TAPState));
s->fd = fd;
s->has_vnet_hdr = vnet_hdr != 0;
+ s->using_vnet_hdr = 0;
s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
vlan, NULL, model, name, NULL,
tap_receive, tap_receive_iov,