@@ -205,7 +205,12 @@ int qemu_show_nic_models(const char *arg, const char *const *models);
void qemu_check_nic_model(NICInfo *nd, const char *model);
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
const char *default_model);
-
+NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
+ const char *alias);
+bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
+ const char *alias);
+DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
+ const char *alias);
void print_net_client(Monitor *mon, NetClientState *nc);
void net_socket_rs_init(SocketReadState *rs,
SocketReadStateFinalize *finalize,
@@ -1072,6 +1072,57 @@ static int net_init_nic(const Netdev *netdev, const char *name,
return idx;
}
+NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd;
+ int i;
+
+ for (i = 0; i < nb_nics; i++) {
+ nd = &nd_table[i];
+
+ if (!nd->used || nd->instantiated) {
+ continue;
+ }
+
+ if ((match_default && !nd->model) || !g_strcmp0(nd->model, typename)
+ || (alias && !g_strcmp0(nd->model, alias))) {
+ return nd;
+ }
+ }
+ return NULL;
+}
+
+
+/* "I have created a device. Please configure it if you can" */
+bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd = qemu_find_nic_info(object_get_typename(OBJECT(dev)),
+ match_default, alias);
+
+ if (nd) {
+ qdev_set_nic_properties(dev, nd);
+ return true;
+ }
+ return false;
+}
+
+/* "Please create a device, if you have a configuration for it" */
+DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd = qemu_find_nic_info(typename, match_default, alias);
+ DeviceState *dev;
+
+ if (!nd) {
+ return NULL;
+ }
+
+ dev = qdev_new(typename);
+ qdev_set_nic_properties(dev, nd);
+ return dev;
+}
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
const Netdev *netdev,