aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/net/net.c b/net/net.c
index 962904e..4651b3f 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1223,6 +1223,59 @@ DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
return dev;
}
+void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type,
+ const char *default_model,
+ const char *alias, const char *alias_target)
+{
+ GPtrArray *nic_models = qemu_get_nic_models(parent_type);
+ const char *model;
+ DeviceState *dev;
+ NICInfo *nd;
+ int i;
+
+ if (nic_model_help) {
+ if (alias_target) {
+ add_nic_model_help(alias_target, alias);
+ }
+ for (i = 0; i < nic_models->len - 1; i++) {
+ add_nic_model_help(nic_models->pdata[i], NULL);
+ }
+ }
+
+ /* Drop the NULL terminator which would make g_str_equal() unhappy */
+ nic_models->len--;
+
+ for (i = 0; i < nb_nics; i++) {
+ nd = &nd_table[i];
+
+ if (!nd->used || nd->instantiated) {
+ continue;
+ }
+
+ model = nd->model ? nd->model : default_model;
+ if (!model) {
+ continue;
+ }
+
+ /* Each bus type is allowed *one* substitution */
+ if (g_str_equal(model, alias)) {
+ model = alias_target;
+ }
+
+ if (!g_ptr_array_find_with_equal_func(nic_models, model,
+ g_str_equal, NULL)) {
+ /* This NIC does not live on this bus. */
+ continue;
+ }
+
+ dev = qdev_new(model);
+ qdev_set_nic_properties(dev, nd);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
+ }
+
+ g_ptr_array_free(nic_models, true);
+}
+
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
const Netdev *netdev,
const char *name,