diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-07 17:43:44 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-07 17:43:44 +0000 |
commit | 676cff2940f3d34e2ef7735df0f83cce958b0d77 (patch) | |
tree | 67333b5e19b42a5fe51386a0953059a643196e2a /net.c | |
parent | bf38c1a0e1d7ebbe0930d8926dbc499b88a2d7db (diff) | |
download | qemu-676cff2940f3d34e2ef7735df0f83cce958b0d77.zip qemu-676cff2940f3d34e2ef7735df0f83cce958b0d77.tar.gz qemu-676cff2940f3d34e2ef7735df0f83cce958b0d77.tar.bz2 |
Assign a name to each VLAN client (Mark McLoughlin)
Automatically assign a name to each vlan client based on its model,
e.g. e1000.0, tap.3 or vde.1.
This name is intended to be used by the forthcoming 'set_link'
monitor command.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6217 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -296,6 +296,25 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str) } #endif +static char *assign_name(VLANClientState *vc1, const char *model) +{ + VLANState *vlan; + char buf[256]; + int id = 0; + + for (vlan = first_vlan; vlan; vlan = vlan->next) { + VLANClientState *vc; + + for (vc = vlan->first_client; vc; vc = vc->next) + if (vc != vc1 && strcmp(vc->model, model) == 0) + id++; + } + + snprintf(buf, sizeof(buf), "%s.%d", model, id); + + return strdup(buf); +} + VLANClientState *qemu_new_vlan_client(VLANState *vlan, const char *model, IOReadHandler *fd_read, @@ -307,6 +326,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, if (!vc) return NULL; vc->model = strdup(model); + vc->name = assign_name(vc, model); vc->fd_read = fd_read; vc->fd_can_read = fd_can_read; vc->opaque = opaque; @@ -327,6 +347,7 @@ void qemu_del_vlan_client(VLANClientState *vc) while (*pvc != NULL) if (*pvc == vc) { *pvc = vc->next; + free(vc->name); free(vc->model); free(vc); break; |