[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: fix libxl_mac_to_device_nic



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317923422 -3600
# Node ID 61e6a43e5abcaadb22685155ea9d4afd5c66d37e
# Parent  98e8b894927b59f5ad4046f591d63f77f556b692
libxl: fix libxl_mac_to_device_nic

I think I broke this back in 22041:4c9ef5ec9146, using i as both the inner and
outer loop iterator.

I've added libxl__compare_macs which helps keep things clean.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 98e8b894927b -r 61e6a43e5abc tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Thu Oct 06 18:49:41 2011 +0100
+++ b/tools/libxl/libxl_internal.c      Thu Oct 06 18:50:22 2011 +0100
@@ -294,6 +294,18 @@
     return 0;
 }
 
+_hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b)
+{
+    int i;
+
+    for (i = 0; i<6; i++) {
+        if ((*a)[i] != (*b)[i])
+            return (*a)[i] - (*b)[i];
+    }
+
+    return 0;
+}
+
 int libxl__fd_set_cloexec(int fd)
 {
     int flags = 0;
diff -r 98e8b894927b -r 61e6a43e5abc tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Oct 06 18:49:41 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Thu Oct 06 18:50:22 2011 +0100
@@ -416,7 +416,10 @@
 
 _hidden int libxl__e820_alloc(libxl_ctx *ctx, uint32_t domid, 
libxl_domain_config *d_config);
 
+/* parse the string @s as a sequence of 6 colon separated bytes in to @mac */
 _hidden int libxl__parse_mac(const char *s, libxl_mac mac);
+/* compare mac address @a and @b. 0 if the same, -ve if a<b and +ve if a>b */
+_hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b);
 
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
diff -r 98e8b894927b -r 61e6a43e5abc tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Thu Oct 06 18:49:41 2011 +0100
+++ b/tools/libxl/libxl_utils.c Thu Oct 06 18:50:22 2011 +0100
@@ -453,9 +453,7 @@
 {
     libxl_nicinfo *nics;
     unsigned int nb, rc, i;
-    int found;
     libxl_mac mac_n;
-    uint8_t *a, *b;
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
@@ -466,17 +464,15 @@
         return ERROR_FAIL;
 
     memset(nic, 0, sizeof (libxl_device_nic));
-    found = 0;
+
+    rc = ERROR_INVAL;
     for (i = 0; i < nb; ++i) {
-        for (i = 0, a = nics[i].mac, b = mac_n;
-             (b < mac_n + 6) && (*a == *b); ++a, ++b)
-            ;
-        if ((b >= mac_n + 6) && (*a == *b)) {
+        if (!libxl__compare_macs(&mac_n, &nics[i].mac)) {
             nic->backend_domid = nics[i].backend_id;
             nic->devid = nics[i].devid;
             memcpy(nic->mac, nics[i].mac, sizeof (nic->mac));
             nic->script = strdup(nics[i].script);
-            found = 1;
+            rc = 0;
             break;
         }
     }
@@ -484,7 +480,7 @@
     for (i=0; i<nb; i++)
         libxl_nicinfo_destroy(&nics[i]);
     free(nics);
-    return found;
+    return rc;
 }
 
 int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.