qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge


From: zwu . kernel
Subject: [Qemu-devel] [RFC 9/9] net: qomify -netdev tap & -netdev bridge
Date: Mon, 26 Mar 2012 13:40:23 +0800

From: Zhi Yong Wu <address@hidden>

Signed-off-by: Zhi Yong Wu <address@hidden>
---
 net/tap.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net/tap.h |    8 +++---
 2 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index 65f45b8..81d022b 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -512,12 +512,16 @@ static int net_bridge_run_helper(const char *helper, 
const char *bridge)
     return -1;
 }
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
-                    NetClientState *peer)
+int net_init_bridge(NETDevice *net_dev)
 {
     TAPState *s;
     int fd, vnet_hdr;
 
+    QemuOpts *opts = net_dev->opts;
+    //Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     if (!qemu_opt_get(opts, "br")) {
         qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE);
     }
@@ -583,13 +587,17 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
     return fd;
 }
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer)
+int net_init_tap(NETDevice *net_dev)
 {
     TAPState *s;
     int fd, vnet_hdr = 0;
     const char *model;
 
+    QemuOpts *opts = net_dev->opts;
+    Monitor *mon = net_dev->mon;
+    char *name = g_strdup(net_dev->name);
+    NetClientState *peer = net_dev->peer;
+
     if (qemu_opt_get(opts, "fd")) {
         if (qemu_opt_get(opts, "ifname") ||
             qemu_opt_get(opts, "script") ||
@@ -715,3 +723,51 @@ VHostNetState *tap_get_vhost_net(NetClientState *nc)
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     return s->vhost_net;
 }
+
+static hostdevProperty net_tap_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_tap_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_tap;
+    dc->props = net_tap_properties;
+}
+
+static TypeInfo net_tap_type = {
+    .name          = "tap",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_tap_class_init,
+};
+
+static hostdevProperty net_bridge_properties[] = {
+    DEFINE_HOSTDEV_PROP_END_OF_LIST(),
+};
+
+static void net_bridge_class_init(ObjectClass *klass, void *data)
+{
+    NETDeviceClass *k = NETDEV_CLASS(klass);
+    HOSTDeviceClass *dc = HOSTDEV_CLASS(klass);
+
+    k->init = net_init_bridge;
+    dc->props = net_bridge_properties;
+}
+
+static TypeInfo net_bridge_type = {
+    .name          = "bridge",
+    .parent        = TYPE_NETDEV,
+    .instance_size = sizeof(NetClientState),
+    .class_init    = net_bridge_class_init,
+};
+
+static void net_tap_register_types(void)
+{
+    type_register_static(&net_tap_type);
+    type_register_static(&net_bridge_type);
+}
+
+type_init(net_tap_register_types)
diff --git a/net/tap.h b/net/tap.h
index 0e35e81..5344d24 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -28,12 +28,13 @@
 
 #include "qemu-common.h"
 #include "qemu-option.h"
+#include "qemu/hostdev.h"
+#include "net.h"
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
 
-int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name,
-                 NetClientState *peer);
+int net_init_tap(NETDevice *net_dev);
 
 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int 
vnet_hdr_required);
 
@@ -58,7 +59,6 @@ int tap_get_fd(NetClientState *nc);
 struct vhost_net;
 struct vhost_net *tap_get_vhost_net(NetClientState *nc);
 
-int net_init_bridge(QemuOpts *opts, Monitor *mon, const char *name,
-                    NetClientState *peer);
+int net_init_bridge(NETDevice *net_dev);
 
 #endif /* QEMU_NET_TAP_H */
-- 
1.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]