}
}
-static int net_init_nic(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_nic(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
int idx;
NICInfo *nd;
memset(nd, 0, sizeof(*nd));
- nd->vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
+ assert(vlan);
+ nd->vlan = vlan;
if (name) {
nd->name = qemu_strdup(name);
return 0;
}
-static int net_init_slirp(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_slirp(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
struct slirp_config_str *config;
const char *vhost;
const char *vhostname;
int restricted = 0;
int ret;
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
-
vhost = qemu_opt_get(opts, "host");
vhostname = qemu_opt_get(opts, "hostname");
vdhcp_start = qemu_opt_get(opts, "dhcpstart");
qemu_free(config);
}
- if (ret != -1) {
+ if (ret != -1 && vlan) {
vlan->nb_host_devs++;
}
#endif /* CONFIG_SLIRP */
#ifdef _WIN32
-static int net_init_tap_win32(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_tap_win32(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
const char *ifname;
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
-
ifname = qemu_opt_get(opts, "ifname");
if (!ifname) {
return -1;
}
- vlan->nb_host_devs++;
+ if (vlan) {
+ vlan->nb_host_devs++;
+ }
return 0;
}
#elif !defined(_AIX)
-static int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_tap(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
TAPState *s;
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
-
if (qemu_opt_get(opts, "fd")) {
int fd;
return -1;
}
- vlan->nb_host_devs++;
+ if (vlan) {
+ vlan->nb_host_devs++;
+ }
return 0;
}
#endif
-static int net_init_socket(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_socket(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
-
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
-
if (qemu_opt_get(opts, "fd")) {
int fd;
return -1;
}
- vlan->nb_host_devs++;
+ if (vlan) {
+ vlan->nb_host_devs++;
+ }
return 0;
}
#ifdef CONFIG_VDE
-static int net_init_vde(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_vde(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
const char *sock;
const char *group;
int port, mode;
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
-
sock = qemu_opt_get(opts, "sock");
group = qemu_opt_get(opts, "group");
return -1;
}
- vlan->nb_host_devs++;
+ if (vlan) {
+ vlan->nb_host_devs++;
+ }
return 0;
}
#endif
-static int net_init_dump(QemuOpts *opts, Monitor *mon, const char *name)
+static int net_init_dump(QemuOpts *opts,
+ Monitor *mon,
+ const char *name,
+ VLANState *vlan)
{
- VLANState *vlan;
int len;
const char *file;
char def_file[128];
- vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
+ assert(vlan);
file = qemu_opt_get(opts, "file");
if (!file) {
typedef int (*net_client_init_func)(QemuOpts *opts,
Monitor *mon,
- const char *name);
+ const char *name,
+ VLANState *vlan);
/* magic number, but compiler will warn if too small */
#define NET_MAX_DESC 20
{ /* end of list */ }
};
-int net_client_init(Monitor *mon, QemuOpts *opts)
+int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
{
const char *name;
const char *type;
return -1;
}
+ if (is_netdev) {
+ if (strcmp(type, "tap") != 0 &&
+#ifdef CONFIG_SLIRP
+ strcmp(type, "user") != 0 &&
+#endif
+#ifdef CONFIG_VDE
+ strcmp(type, "vde") != 0 &&
+#endif
+ strcmp(type, "socket") != 0) {
+ qemu_error("The '%s' network backend type is not valid with -netdev\n",
+ type);
+ return -1;
+ }
+
+ if (qemu_opt_get(opts, "vlan")) {
+ qemu_error("The 'vlan' parameter is not valid with -netdev\n");
+ return -1;
+ }
+ if (qemu_opt_get(opts, "name")) {
+ qemu_error("The 'name' parameter is not valid with -netdev\n");
+ return -1;
+ }
+ if (!qemu_opts_id(opts)) {
+ qemu_error("The id= parameter is required with -netdev\n");
+ return -1;
+ }
+ }
+
name = qemu_opts_id(opts);
if (!name) {
name = qemu_opt_get(opts, "name");
for (i = 0; net_client_types[i].type != NULL; i++) {
if (!strcmp(net_client_types[i].type, type)) {
+ VLANState *vlan = NULL;
+
if (qemu_opts_validate(opts, &net_client_types[i].desc[0]) == -1) {
return -1;
}
+ if (!is_netdev) {
+ vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
+ }
+
if (net_client_types[i].init) {
- return net_client_types[i].init(opts, mon, name);
+ return net_client_types[i].init(opts, mon, name, vlan);
} else {
return 0;
}
qemu_opt_set(opts, "type", device);
- if (net_client_init(mon, opts) < 0) {
+ if (net_client_init(mon, opts, 0) < 0) {
monitor_printf(mon, "adding host network device %s failed\n", device);
}
}
static int net_init_client(QemuOpts *opts, void *dummy)
{
- return net_client_init(NULL, opts);
+ return net_client_init(NULL, opts, 0);
+}
+
+static int net_init_netdev(QemuOpts *opts, void *dummy)
+{
+ return net_client_init(NULL, opts, 1);
}
int net_init_clients(void)
QTAILQ_INIT(&vlans);
+ if (qemu_opts_foreach(&qemu_netdev_opts, net_init_netdev, NULL, 1) == -1)
+ return -1;
+
if (qemu_opts_foreach(&qemu_net_opts, net_init_client, NULL, 1) == -1) {
return -1;
}