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 9 of 9] libxl: add LIBXL_MAC_{FMT,FMTLEN,BYTES}

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 9 of 9] libxl: add LIBXL_MAC_{FMT,FMTLEN,BYTES}
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 14 Jul 2011 17:02:29 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 14 Jul 2011 09:17:32 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1310659340@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.1310659340@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310646259 -3600
# Node ID 57e96d4f36b244faff9370d42c50355d9abd0494
# Parent  f3d8695e7b03a5a90d05380f7ed4aa5d9ad56dd4
libxl: add LIBXL_MAC_{FMT,FMTLEN,BYTES}

Modelled after LIBXL_UUID_... (where I also add FMTLEN).

signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r f3d8695e7b03 -r 57e96d4f36b2 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Jul 14 13:24:11 2011 +0100
+++ b/tools/libxl/libxl.c       Thu Jul 14 13:24:19 2011 +0100
@@ -1215,9 +1215,8 @@ int libxl_device_nic_add(libxl_ctx *ctx,
                                           nic->script));
     }
     flexarray_append(back, "mac");
-    flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
-                                                 nic->mac[0], nic->mac[1], 
nic->mac[2],
-                                                 nic->mac[3], nic->mac[4], 
nic->mac[5]));
+    flexarray_append(back,libxl__sprintf(&gc,
+                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
     if (nic->ip) {
         flexarray_append(back, "ip");
         flexarray_append(back, libxl__strdup(&gc, nic->ip));
@@ -1235,9 +1234,8 @@ int libxl_device_nic_add(libxl_ctx *ctx,
     flexarray_append(front, "handle");
     flexarray_append(front, libxl__sprintf(&gc, "%d", nic->devid));
     flexarray_append(front, "mac");
-    flexarray_append(front, libxl__sprintf(&gc, 
"%02x:%02x:%02x:%02x:%02x:%02x",
-                                                  nic->mac[0], nic->mac[1], 
nic->mac[2],
-                                                  nic->mac[3], nic->mac[4], 
nic->mac[5]));
+    flexarray_append(front, libxl__sprintf(&gc,
+                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
     libxl__device_generic_add(&gc, &device,
                              libxl__xs_kvs_of_flexarray(&gc, back, 
back->count),
                              libxl__xs_kvs_of_flexarray(&gc, front, 
front->count));
diff -r f3d8695e7b03 -r 57e96d4f36b2 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Jul 14 13:24:11 2011 +0100
+++ b/tools/libxl/libxl.h       Thu Jul 14 13:24:19 2011 +0100
@@ -139,6 +139,9 @@
 #include <libxl_uuid.h>
 
 typedef uint8_t libxl_mac[6];
+#define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
+#define LIBXL_MAC_FMTLEN ((2*6)+5) /* 6 hex bytes plus 5 colons */
+#define LIBXL_MAC_BYTES(mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
 
 typedef char **libxl_string_list;
 void libxl_string_list_destroy(libxl_string_list *sl);
diff -r f3d8695e7b03 -r 57e96d4f36b2 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Thu Jul 14 13:24:11 2011 +0100
+++ b/tools/libxl/libxl_dm.c    Thu Jul 14 13:24:19 2011 +0100
@@ -177,9 +177,8 @@ static char ** libxl__build_device_model
         }
         for (i = 0; i < num_vifs; i++) {
             if (vifs[i].nictype == LIBXL_NIC_TYPE_IOEMU) {
-                char *smac = libxl__sprintf(gc, 
"%02x:%02x:%02x:%02x:%02x:%02x",
-                                           vifs[i].mac[0], vifs[i].mac[1], 
vifs[i].mac[2],
-                                           vifs[i].mac[3], vifs[i].mac[4], 
vifs[i].mac[5]);
+                char *smac = libxl__sprintf(gc,
+                                   LIBXL_MAC_FMT, 
LIBXL_MAC_BYTES(vifs[i].mac));
                 char *ifname;
                 if (!vifs[i].ifname)
                     ifname = libxl__sprintf(gc, "tap%d.%d", info->domid, 
vifs[i].devid);
@@ -368,9 +367,8 @@ static char ** libxl__build_device_model
         }
         for (i = 0; i < num_vifs; i++) {
             if (vifs[i].nictype == LIBXL_NIC_TYPE_IOEMU) {
-                char *smac = libxl__sprintf(gc, 
"%02x:%02x:%02x:%02x:%02x:%02x",
-                                           vifs[i].mac[0], vifs[i].mac[1], 
vifs[i].mac[2],
-                                           vifs[i].mac[3], vifs[i].mac[4], 
vifs[i].mac[5]);
+                char *smac = libxl__sprintf(gc,
+                                LIBXL_MAC_FMT, LIBXL_MAC_BYTES(vifs[i].mac));
                 char *ifname;
                 if (!vifs[i].ifname) {
                     ifname = libxl__sprintf(gc, "tap%d.%d", info->domid, 
vifs[i].devid);
diff -r f3d8695e7b03 -r 57e96d4f36b2 tools/libxl/libxl_uuid.h
--- a/tools/libxl/libxl_uuid.h  Thu Jul 14 13:24:11 2011 +0100
+++ b/tools/libxl/libxl_uuid.h  Thu Jul 14 13:24:19 2011 +0100
@@ -16,6 +16,7 @@
 #define __LIBXL_UUID_H__
 
 #define LIBXL_UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+#define LIBXL_UUID_FMTLEN ((2*16)+4) /* 16 hex bytes plus 4 hypens */
 #define LIBXL__UUID_BYTES(uuid) uuid[0], uuid[1], uuid[2], uuid[3], \
                                 uuid[4], uuid[5], uuid[6], uuid[7], \
                                 uuid[8], uuid[9], uuid[10], uuid[11], \
diff -r f3d8695e7b03 -r 57e96d4f36b2 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Jul 14 13:24:11 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu Jul 14 13:24:19 2011 +0100
@@ -3989,9 +3989,7 @@ int main_networklist(int argc, char **ar
             /* Idx BE */
             printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id);
             /* MAC */
-            printf("%02x:%02x:%02x:%02x:%02x:%02x ",
-                   nics[i].mac[0], nics[i].mac[1], nics[i].mac[2],
-                   nics[i].mac[3], nics[i].mac[4], nics[i].mac[5]);
+            printf(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nics[i].mac));
             /* Hdl  Sta  evch txr/rxr  BE-path */
             printf("%6d %5d %6d %5d/%-11d %-30s\n",
                    nics[i].devid, nics[i].state, nics[i].evtch,

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