Commit 676cff2940f3d34e2ef7735df0f83cce958b0d77
1 parent
bf38c1a0
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
Showing
2 changed files
with
22 additions
and
0 deletions
net.c
... | ... | @@ -296,6 +296,25 @@ static int parse_unix_path(struct sockaddr_un *uaddr, const char *str) |
296 | 296 | } |
297 | 297 | #endif |
298 | 298 | |
299 | +static char *assign_name(VLANClientState *vc1, const char *model) | |
300 | +{ | |
301 | + VLANState *vlan; | |
302 | + char buf[256]; | |
303 | + int id = 0; | |
304 | + | |
305 | + for (vlan = first_vlan; vlan; vlan = vlan->next) { | |
306 | + VLANClientState *vc; | |
307 | + | |
308 | + for (vc = vlan->first_client; vc; vc = vc->next) | |
309 | + if (vc != vc1 && strcmp(vc->model, model) == 0) | |
310 | + id++; | |
311 | + } | |
312 | + | |
313 | + snprintf(buf, sizeof(buf), "%s.%d", model, id); | |
314 | + | |
315 | + return strdup(buf); | |
316 | +} | |
317 | + | |
299 | 318 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
300 | 319 | const char *model, |
301 | 320 | IOReadHandler *fd_read, |
... | ... | @@ -307,6 +326,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
307 | 326 | if (!vc) |
308 | 327 | return NULL; |
309 | 328 | vc->model = strdup(model); |
329 | + vc->name = assign_name(vc, model); | |
310 | 330 | vc->fd_read = fd_read; |
311 | 331 | vc->fd_can_read = fd_can_read; |
312 | 332 | vc->opaque = opaque; |
... | ... | @@ -327,6 +347,7 @@ void qemu_del_vlan_client(VLANClientState *vc) |
327 | 347 | while (*pvc != NULL) |
328 | 348 | if (*pvc == vc) { |
329 | 349 | *pvc = vc->next; |
350 | + free(vc->name); | |
330 | 351 | free(vc->model); |
331 | 352 | free(vc); |
332 | 353 | break; | ... | ... |