mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
net: Use hubs for the vlan feature
Stop using the special-case vlan code in net.c. Instead use the hub net client to implement the vlan feature. The next patch will remove vlan code from net.c completely. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
f6c874e300
commit
d33d93b2c4
14 changed files with 85 additions and 75 deletions
37
net.c
37
net.c
|
@ -157,23 +157,25 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)
|
|||
macaddr->a[5] = 0x56 + index++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a name for net client
|
||||
*
|
||||
* Only net clients created with the legacy -net option need this. Naming is
|
||||
* mandatory for net clients created with -netdev.
|
||||
*/
|
||||
static char *assign_name(VLANClientState *vc1, const char *model)
|
||||
{
|
||||
VLANState *vlan;
|
||||
VLANClientState *vc;
|
||||
char buf[256];
|
||||
int id = 0;
|
||||
|
||||
QTAILQ_FOREACH(vlan, &vlans, next) {
|
||||
QTAILQ_FOREACH(vc, &vlan->clients, next) {
|
||||
if (vc != vc1 && strcmp(vc->model, model) == 0) {
|
||||
id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
|
||||
if (vc != vc1 && strcmp(vc->model, model) == 0) {
|
||||
if (vc == vc1) {
|
||||
continue;
|
||||
}
|
||||
/* For compatibility only bump id for net clients on a vlan */
|
||||
if (strcmp(vc->model, model) == 0 &&
|
||||
net_hub_id_for_client(vc, NULL) == 0) {
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
@ -750,7 +752,7 @@ int net_handle_fd_param(Monitor *mon, const char *param)
|
|||
}
|
||||
|
||||
static int net_init_nic(const NetClientOptions *opts, const char *name,
|
||||
VLANState *vlan)
|
||||
VLANClientState *peer)
|
||||
{
|
||||
int idx;
|
||||
NICInfo *nd;
|
||||
|
@ -776,8 +778,8 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
assert(vlan);
|
||||
nd->vlan = vlan;
|
||||
assert(peer);
|
||||
nd->netdev = peer;
|
||||
}
|
||||
if (name) {
|
||||
nd->name = g_strdup(name);
|
||||
|
@ -816,7 +818,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
|
|||
static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
|
||||
const NetClientOptions *opts,
|
||||
const char *name,
|
||||
VLANState *vlan) = {
|
||||
VLANClientState *peer) = {
|
||||
[NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic,
|
||||
#ifdef CONFIG_SLIRP
|
||||
[NET_CLIENT_OPTIONS_KIND_USER] = net_init_slirp,
|
||||
|
@ -876,17 +878,17 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
|
|||
}
|
||||
|
||||
if (net_client_init_fun[opts->kind]) {
|
||||
VLANState *vlan = NULL;
|
||||
VLANClientState *peer = NULL;
|
||||
|
||||
/* Do not add to a vlan if it's a -netdev or a nic with a netdev=
|
||||
* parameter. */
|
||||
if (!is_netdev &&
|
||||
(opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
|
||||
!opts->nic->has_netdev)) {
|
||||
vlan = qemu_find_vlan(u.net->has_vlan ? u.net->vlan : 0, true);
|
||||
peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
|
||||
}
|
||||
|
||||
if (net_client_init_fun[opts->kind](opts, name, vlan) < 0) {
|
||||
if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {
|
||||
/* TODO push error reporting into init() methods */
|
||||
error_set(errp, QERR_DEVICE_INIT_FAILED,
|
||||
NetClientOptionsKind_lookup[opts->kind]);
|
||||
|
@ -1085,6 +1087,7 @@ void do_info_network(Monitor *mon)
|
|||
print_net_client(mon, peer);
|
||||
}
|
||||
}
|
||||
net_hub_info(mon);
|
||||
}
|
||||
|
||||
void qmp_set_link(const char *name, bool up, Error **errp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue