WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2 of 2] libxl: fix libxl_mac_to_device_nic

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 2] libxl: fix libxl_mac_to_device_nic
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Wed, 5 Oct 2011 10:45:24 +0100
Cc: Roger Pau Monné <roger.pau@xxxxxxxxxxxxx>
Delivery-date: Wed, 05 Oct 2011 02:49:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1317807922@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1317807922@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317807819 -3600
# Node ID 88486538d739b5fb0aab51526e77315a696c6092
# Parent  b85fcaaf73a9cfb5e5f448015c56630aa8daba3d
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>

diff -r b85fcaaf73a9 -r 88486538d739 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Wed Oct 05 10:43:39 2011 +0100
+++ b/tools/libxl/libxl_internal.c      Wed Oct 05 10:43:39 2011 +0100
@@ -294,6 +294,18 @@ _hidden int libxl__parse_mac(const char 
     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 b85fcaaf73a9 -r 88486538d739 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Oct 05 10:43:39 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Wed Oct 05 10:43:39 2011 +0100
@@ -426,7 +426,10 @@ _hidden int libxl__fd_set_cloexec(int fd
 
 _hidden int libxl__e820_alloc(libxl__gc *gc, 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 b85fcaaf73a9 -r 88486538d739 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Wed Oct 05 10:43:39 2011 +0100
+++ b/tools/libxl/libxl_utils.c Wed Oct 05 10:43:39 2011 +0100
@@ -453,9 +453,7 @@ int libxl_mac_to_device_nic(libxl_ctx *c
 {
     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 @@ int libxl_mac_to_device_nic(libxl_ctx *c
         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 @@ int libxl_mac_to_device_nic(libxl_ctx *c
     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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>