|
@@ -75,6 +75,11 @@ typedef QSIMPLEQ_HEAD(, NetdevQueueEntry) NetdevQueue;
|
|
|
|
|
|
static NetdevQueue nd_queue = QSIMPLEQ_HEAD_INITIALIZER(nd_queue);
|
|
static NetdevQueue nd_queue = QSIMPLEQ_HEAD_INITIALIZER(nd_queue);
|
|
|
|
|
|
|
|
+static GHashTable *nic_model_help;
|
|
|
|
+
|
|
|
|
+static int nb_nics;
|
|
|
|
+static NICInfo nd_table[MAX_NICS];
|
|
|
|
+
|
|
/***********************************************************/
|
|
/***********************************************************/
|
|
/* network device redirectors */
|
|
/* network device redirectors */
|
|
|
|
|
|
@@ -975,51 +980,6 @@ GPtrArray *qemu_get_nic_models(const char *device_type)
|
|
return nic_models;
|
|
return nic_models;
|
|
}
|
|
}
|
|
|
|
|
|
-int qemu_show_nic_models(const char *arg, const char *const *models)
|
|
|
|
-{
|
|
|
|
- int i;
|
|
|
|
-
|
|
|
|
- if (!arg || !is_help_option(arg)) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- printf("Available NIC models:\n");
|
|
|
|
- for (i = 0 ; models[i]; i++) {
|
|
|
|
- printf("%s\n", models[i]);
|
|
|
|
- }
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void qemu_check_nic_model(NICInfo *nd, const char *model)
|
|
|
|
-{
|
|
|
|
- const char *models[2];
|
|
|
|
-
|
|
|
|
- models[0] = model;
|
|
|
|
- models[1] = NULL;
|
|
|
|
-
|
|
|
|
- if (qemu_show_nic_models(nd->model, models))
|
|
|
|
- exit(0);
|
|
|
|
- if (qemu_find_nic_model(nd, models, model) < 0)
|
|
|
|
- exit(1);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int qemu_find_nic_model(NICInfo *nd, const char * const *models,
|
|
|
|
- const char *default_model)
|
|
|
|
-{
|
|
|
|
- int i;
|
|
|
|
-
|
|
|
|
- if (!nd->model)
|
|
|
|
- nd->model = g_strdup(default_model);
|
|
|
|
-
|
|
|
|
- for (i = 0 ; models[i]; i++) {
|
|
|
|
- if (strcmp(nd->model, models[i]) == 0)
|
|
|
|
- return i;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- error_report("Unsupported NIC model: %s", nd->model);
|
|
|
|
- return -1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static int net_init_nic(const Netdev *netdev, const char *name,
|
|
static int net_init_nic(const Netdev *netdev, const char *name,
|
|
NetClientState *peer, Error **errp)
|
|
NetClientState *peer, Error **errp)
|
|
{
|
|
{
|
|
@@ -1087,6 +1047,192 @@ static int net_init_nic(const Netdev *netdev, const char *name,
|
|
return idx;
|
|
return idx;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static gboolean add_nic_result(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
+{
|
|
|
|
+ GPtrArray *results = user_data;
|
|
|
|
+ GPtrArray *alias_list = value;
|
|
|
|
+ const char *model = key;
|
|
|
|
+ char *result;
|
|
|
|
+
|
|
|
|
+ if (!alias_list) {
|
|
|
|
+ result = g_strdup(model);
|
|
|
|
+ } else {
|
|
|
|
+ GString *result_str = g_string_new(model);
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ g_string_append(result_str, " (aka ");
|
|
|
|
+ for (i = 0; i < alias_list->len; i++) {
|
|
|
|
+ if (i) {
|
|
|
|
+ g_string_append(result_str, ", ");
|
|
|
|
+ }
|
|
|
|
+ g_string_append(result_str, alias_list->pdata[i]);
|
|
|
|
+ }
|
|
|
|
+ g_string_append(result_str, ")");
|
|
|
|
+ result = result_str->str;
|
|
|
|
+ g_string_free(result_str, false);
|
|
|
|
+ g_ptr_array_unref(alias_list);
|
|
|
|
+ }
|
|
|
|
+ g_ptr_array_add(results, result);
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int model_cmp(char **a, char **b)
|
|
|
|
+{
|
|
|
|
+ return strcmp(*a, *b);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void show_nic_models(void)
|
|
|
|
+{
|
|
|
|
+ GPtrArray *results = g_ptr_array_new();
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ g_hash_table_foreach_remove(nic_model_help, add_nic_result, results);
|
|
|
|
+ g_ptr_array_sort(results, (GCompareFunc)model_cmp);
|
|
|
|
+
|
|
|
|
+ printf("Available NIC models for this configuration:\n");
|
|
|
|
+ for (i = 0 ; i < results->len; i++) {
|
|
|
|
+ printf("%s\n", (char *)results->pdata[i]);
|
|
|
|
+ }
|
|
|
|
+ g_hash_table_unref(nic_model_help);
|
|
|
|
+ nic_model_help = NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void add_nic_model_help(const char *model, const char *alias)
|
|
|
|
+{
|
|
|
|
+ GPtrArray *alias_list = NULL;
|
|
|
|
+
|
|
|
|
+ if (g_hash_table_lookup_extended(nic_model_help, model, NULL,
|
|
|
|
+ (gpointer *)&alias_list)) {
|
|
|
|
+ /* Already exists, no alias to add: return */
|
|
|
|
+ if (!alias) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (alias_list) {
|
|
|
|
+ /* Check if this alias is already in the list. Add if not. */
|
|
|
|
+ if (!g_ptr_array_find_with_equal_func(alias_list, alias,
|
|
|
|
+ g_str_equal, NULL)) {
|
|
|
|
+ g_ptr_array_add(alias_list, g_strdup(alias));
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /* Either this model wasn't in the list already, or a first alias added */
|
|
|
|
+ if (alias) {
|
|
|
|
+ alias_list = g_ptr_array_new();
|
|
|
|
+ g_ptr_array_set_free_func(alias_list, g_free);
|
|
|
|
+ g_ptr_array_add(alias_list, g_strdup(alias));
|
|
|
|
+ }
|
|
|
|
+ g_hash_table_replace(nic_model_help, g_strdup(model), alias_list);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
|
|
|
|
+ const char *alias)
|
|
|
|
+{
|
|
|
|
+ NICInfo *nd;
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ if (nic_model_help) {
|
|
|
|
+ add_nic_model_help(typename, alias);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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])(
|
|
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
|
|
const Netdev *netdev,
|
|
const Netdev *netdev,
|
|
@@ -1555,6 +1701,10 @@ void net_check_clients(void)
|
|
NetClientState *nc;
|
|
NetClientState *nc;
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
+ if (nic_model_help) {
|
|
|
|
+ show_nic_models();
|
|
|
|
+ exit(0);
|
|
|
|
+ }
|
|
net_hub_check_clients();
|
|
net_hub_check_clients();
|
|
|
|
|
|
QTAILQ_FOREACH(nc, &net_clients, next) {
|
|
QTAILQ_FOREACH(nc, &net_clients, next) {
|
|
@@ -1612,9 +1762,14 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
|
|
}
|
|
}
|
|
if (is_help_option(type)) {
|
|
if (is_help_option(type)) {
|
|
GPtrArray *nic_models = qemu_get_nic_models(TYPE_DEVICE);
|
|
GPtrArray *nic_models = qemu_get_nic_models(TYPE_DEVICE);
|
|
|
|
+ int i;
|
|
show_netdevs();
|
|
show_netdevs();
|
|
printf("\n");
|
|
printf("\n");
|
|
- qemu_show_nic_models(type, (const char **)nic_models->pdata);
|
|
|
|
|
|
+ printf("Available NIC models "
|
|
|
|
+ "(use -nic model=help for a filtered list):\n");
|
|
|
|
+ for (i = 0 ; nic_models->pdata[i]; i++) {
|
|
|
|
+ printf("%s\n", (char *)nic_models->pdata[i]);
|
|
|
|
+ }
|
|
g_ptr_array_free(nic_models, true);
|
|
g_ptr_array_free(nic_models, true);
|
|
exit(0);
|
|
exit(0);
|
|
}
|
|
}
|
|
@@ -1634,6 +1789,12 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
|
|
memset(ni, 0, sizeof(*ni));
|
|
memset(ni, 0, sizeof(*ni));
|
|
ni->model = qemu_opt_get_del(opts, "model");
|
|
ni->model = qemu_opt_get_del(opts, "model");
|
|
|
|
|
|
|
|
+ if (!nic_model_help && !g_strcmp0(ni->model, "help")) {
|
|
|
|
+ nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
|
|
+ g_free, NULL);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* Create an ID if the user did not specify one */
|
|
/* Create an ID if the user did not specify one */
|
|
nd_id = g_strdup(qemu_opts_id(opts));
|
|
nd_id = g_strdup(qemu_opts_id(opts));
|
|
if (!nd_id) {
|
|
if (!nd_id) {
|