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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 09 of 10] libxl: add LIBXL_MAC_{FMT, FMTLEN, BYTES}
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 23 Jun 2011 17:21:00 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 23 Jun 2011 09:33:07 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1308846051@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.1308846051@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1308845956 -3600
# Node ID 4e751a05df3c323aea8fb291961a21d13de4afda
# Parent  dea9208b98db2b1b301a17b13d21558fa0a0edc7
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 dea9208b98db -r 4e751a05df3c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Jun 23 17:19:09 2011 +0100
+++ b/tools/libxl/libxl.c       Thu Jun 23 17:19:16 2011 +0100
@@ -1284,9 +1284,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));
@@ -1304,9 +1303,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 dea9208b98db -r 4e751a05df3c tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Jun 23 17:19:09 2011 +0100
+++ b/tools/libxl/libxl.h       Thu Jun 23 17:19:16 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 dea9208b98db -r 4e751a05df3c tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Thu Jun 23 17:19:09 2011 +0100
+++ b/tools/libxl/libxl_dm.c    Thu Jun 23 17:19:16 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 dea9208b98db -r 4e751a05df3c tools/libxl/libxl_uuid.h
--- a/tools/libxl/libxl_uuid.h  Thu Jun 23 17:19:09 2011 +0100
+++ b/tools/libxl/libxl_uuid.h  Thu Jun 23 17:19:16 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 dea9208b98db -r 4e751a05df3c tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Jun 23 17:19:09 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu Jun 23 17:19:16 2011 +0100
@@ -4094,9 +4094,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