From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LB9JE-0005rM-Do for qemu-devel@nongnu.org; Fri, 12 Dec 2008 09:48:04 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LB9JB-0005pc-PF for qemu-devel@nongnu.org; Fri, 12 Dec 2008 09:48:02 -0500 Received: from [199.232.76.173] (port=32814 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LB9JA-0005pS-IO for qemu-devel@nongnu.org; Fri, 12 Dec 2008 09:48:00 -0500 Received: from mail06.svc.cra.dublin.eircom.net ([159.134.118.22]:40828) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LB9JA-0006fS-0r for qemu-devel@nongnu.org; Fri, 12 Dec 2008 09:48:00 -0500 From: Mark McLoughlin Date: Fri, 12 Dec 2008 14:46:28 +0000 Message-Id: <1229093191-20618-2-git-send-email-markmc@redhat.com> In-Reply-To: <1229093191-20618-1-git-send-email-markmc@redhat.com> References: <1229093136.4041.25.camel@blaa> <1229093191-20618-1-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Mark McLoughlin , qemu-devel@nongnu.org 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 --- net.c | 21 +++++++++++++++++++++ net.h | 1 + 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index d046b5e..fe7c648 100644 --- a/net.c +++ b/net.c @@ -304,6 +304,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, @@ -315,6 +334,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; @@ -335,6 +355,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; diff --git a/net.h b/net.h index fcae0e2..138cd23 100644 --- a/net.h +++ b/net.h @@ -14,6 +14,7 @@ struct VLANClientState { struct VLANClientState *next; struct VLANState *vlan; char *model; + char *name; char info_str[256]; }; -- 1.5.4.3