[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client
From: |
Mark McLoughlin |
Subject: |
[Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client |
Date: |
Fri, 12 Dec 2008 14:46:28 +0000 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000, Mark McLoughlin, 2008/12/09
- [Qemu-devel] [PATCH 1/4] Add 'set_link' monitor command, Mark McLoughlin, 2008/12/09
- [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command, Anthony Liguori, 2008/12/09
- [Qemu-devel] Re: [PATCH 1/4] Add 'set_link' monitor command, Mark McLoughlin, 2008/12/12
- [Qemu-devel] [PATCH 1/5] Add a model string to VLANClientState, Mark McLoughlin, 2008/12/12
- [Qemu-devel] [PATCH 2/5] Assign a name to each VLAN client,
Mark McLoughlin <=
- [Qemu-devel] [PATCH 3/5] Fixup info_str formatting, Mark McLoughlin, 2008/12/12
- [Qemu-devel] [PATCH 4/5] Add qemu_format_nic_info_str(), Mark McLoughlin, 2008/12/12
- [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter, Mark McLoughlin, 2008/12/12
- Re: [Qemu-devel] [PATCH 5/5] Add a -net name=foo parameter, Aurelien Jarno, 2008/12/14
Re: [Qemu-devel] [PATCH 0/4] Add nic link up/down emulation to e1000, Daniel P. Berrange, 2008/12/09
[Qemu-devel] Re: [PATCH 0/4] Add nic link up/down emulation to e1000, Anthony Liguori, 2008/12/09