aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-21 15:25:25 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-27 12:28:37 -0500
commit851bec091d70b839f07a5e0615c2e17c8cd12b58 (patch)
tree08f54085126f66d8e855d0e1346db5c73646d09c /hw/qdev-properties.c
parent2ef924b416edb55f9d87b0f53d78c9fb78f0ec52 (diff)
qdev: add vlan property
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 992631895c..2d4eeecbe7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -310,6 +310,40 @@ PropertyInfo qdev_prop_netdev = {
.print = print_netdev,
};
+/* --- vlan --- */
+
+static int parse_vlan(DeviceState *dev, Property *prop, const char *str)
+{
+ VLANState **ptr = qdev_get_prop_ptr(dev, prop);
+ int id;
+
+ if (sscanf(str, "%d", &id) != 1)
+ return -1;
+ *ptr = qemu_find_vlan(id, 1);
+ if (*ptr == NULL)
+ return -1;
+ return 0;
+}
+
+static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ VLANState **ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (*ptr) {
+ return snprintf(dest, len, "%d", (*ptr)->id);
+ } else {
+ return snprintf(dest, len, "<null>");
+ }
+}
+
+PropertyInfo qdev_prop_vlan = {
+ .name = "vlan",
+ .type = PROP_TYPE_VLAN,
+ .size = sizeof(VLANClientState*),
+ .parse = parse_vlan,
+ .print = print_vlan,
+};
+
/* --- pointer --- */
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -524,6 +558,11 @@ void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *v
qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
}
+void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
+{
+ qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
+}
+
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
{
qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);