]> git.proxmox.com Git - qemu.git/blobdiff - net/tap-win32.c
usb: create USBPortOps, move attach there.
[qemu.git] / net / tap-win32.c
index 7d92df2aa3e5896ecc890d1a69d96208113ce612..081904e8d74502684654a8c3463fb9d44816e886 100644 (file)
  *  along with this program (see the file COPYING included with this
  *  distribution); if not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "net/tap.h"
+
 #include "qemu-common.h"
 #include "net.h"
 #include "sysemu.h"
+#include "qemu-error.h"
 #include <stdio.h>
 #include <windows.h>
 #include <winioctl.h>
@@ -575,7 +579,6 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
     } version;
     DWORD version_len;
     DWORD idThread;
-    HANDLE hThread;
 
     if (prefered_name != NULL)
         snprintf(name_buffer, sizeof(name_buffer), "%s", prefered_name);
@@ -619,33 +622,32 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,
 
     *phandle = &tap_overlapped;
 
-    hThread = CreateThread(NULL, 0, tap_win32_thread_entry,
-                           (LPVOID)&tap_overlapped, 0, &idThread);
+    CreateThread(NULL, 0, tap_win32_thread_entry,
+                 (LPVOID)&tap_overlapped, 0, &idThread);
     return 0;
 }
 
 /********************************************/
 
  typedef struct TAPState {
-     VLANClientState *vc;
+     VLANClientState nc;
      tap_win32_overlapped_t *handle;
  } TAPState;
 
-static void tap_cleanup(VLANClientState *vc)
+static void tap_cleanup(VLANClientState *nc)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
 
     /* FIXME: need to kill thread and close file handle:
        tap_win32_close(s);
     */
-    qemu_free(s);
 }
 
-static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
 {
-    TAPState *s = vc->opaque;
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
 
     return tap_win32_write(s->handle, buf, size);
 }
@@ -659,32 +661,91 @@ static void tap_win32_send(void *opaque)
 
     size = tap_win32_read(s->handle, &buf, max_size);
     if (size > 0) {
-        qemu_send_packet(s->vc, buf, size);
+        qemu_send_packet(&s->nc, buf, size);
         tap_win32_free_buffer(s->handle, buf);
     }
 }
 
-int tap_win32_init(VLANState *vlan, const char *model,
-                   const char *name, const char *ifname)
+static NetClientInfo net_tap_win32_info = {
+    .type = NET_CLIENT_TYPE_TAP,
+    .size = sizeof(TAPState),
+    .receive = tap_receive,
+    .cleanup = tap_cleanup,
+};
+
+static int tap_win32_init(VLANState *vlan, const char *model,
+                          const char *name, const char *ifname)
 {
+    VLANClientState *nc;
     TAPState *s;
+    tap_win32_overlapped_t *handle;
 
-    s = qemu_mallocz(sizeof(TAPState));
-    if (!s)
-        return -1;
-    if (tap_win32_open(&s->handle, ifname) < 0) {
+    if (tap_win32_open(&handle, ifname) < 0) {
         printf("tap: Could not open '%s'\n", ifname);
         return -1;
     }
 
-    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP,
-                                 vlan, NULL, model, name,
-                                 NULL, tap_receive,
-                                 NULL, NULL, tap_cleanup, s);
+    nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name);
+
+    s = DO_UPCAST(TAPState, nc, nc);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
+    snprintf(s->nc.info_str, sizeof(s->nc.info_str),
              "tap: ifname=%s", ifname);
 
+    s->handle = handle;
+
     qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
+
+    return 0;
+}
+
+int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
+{
+    const char *ifname;
+
+    ifname = qemu_opt_get(opts, "ifname");
+
+    if (!ifname) {
+        error_report("tap: no interface name");
+        return -1;
+    }
+
+    if (tap_win32_init(vlan, "tap", name, ifname) == -1) {
+        return -1;
+    }
+
     return 0;
 }
+
+int tap_has_ufo(VLANClientState *vc)
+{
+    return 0;
+}
+
+int tap_has_vnet_hdr(VLANClientState *vc)
+{
+    return 0;
+}
+
+int tap_probe_vnet_hdr_len(int fd, int len)
+{
+    return 0;
+}
+
+void tap_fd_set_vnet_hdr_len(int fd, int len)
+{
+}
+
+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, int ufo)
+{
+}
+
+struct vhost_net *tap_get_vhost_net(VLANClientState *nc)
+{
+    return NULL;
+}