Re: [PATCH]Change MAC address to case insensitive

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

 



On Tue, Feb 26, 2008 at 12:54:15PM +0000, Daniel P. Berrange wrote:
> On Tue, Feb 26, 2008 at 12:13:43PM +0100, Jim Meyering wrote:
> > "Richard W.M. Jones" <rjones@xxxxxxxxxx> wrote:
> > > I'll apply this today (using our STRCASEEQ macros) if no one else
> > > objects.
> > 
> > Hi,
> > 
> > What do you think about using a MAC-address-specific comparison
> > function?  I.e., one that is not only case-independent, but that also
> > knows leading zeros are unnecessary?
> > 
> > i.e., it would admit that these two match:
> > 
> >   00:0A:FF:3A:00:09
> >   0:a:ff:3a:0:9
> > 
> > That would be a little more user friendly.
> 
> Yes, we should add a helper function for comparing mac addresses for
> equality.

OK, try this patch.

Jim, not sure I understood to full complexities of making static
linking work without duplicate symbols, so this patch may be wrong in
that regard.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
Index: src/internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/internal.h,v
retrieving revision 1.63
diff -u -r1.63 internal.h
--- src/internal.h	20 Feb 2008 15:06:53 -0000	1.63
+++ src/internal.h	26 Feb 2008 13:10:46 -0000
@@ -54,7 +54,6 @@
 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
 
-
 /* If configured with --enable-debug=yes then library calls
  * are printed to stderr for debugging.
  */
Index: src/libvirt_sym.version
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt_sym.version,v
retrieving revision 1.36
diff -u -r1.36 libvirt_sym.version
--- src/libvirt_sym.version	21 Feb 2008 03:53:03 -0000	1.36
+++ src/libvirt_sym.version	26 Feb 2008 13:10:46 -0000
@@ -185,5 +185,7 @@
         __virBufferAdd;
         __virBufferAddChar;
 
+	__virMacAddrCompare;
+
     local: *;
 };
Index: src/util.c
===================================================================
RCS file: /data/cvs/libvirt/src/util.c,v
retrieving revision 1.22
diff -u -r1.22 util.c
--- src/util.c	26 Feb 2008 07:05:18 -0000	1.22
+++ src/util.c	26 Feb 2008 13:10:46 -0000
@@ -602,6 +602,16 @@
     return 0;
 }
 
+/* Use this function when comparing two MAC addresses.  It deals with
+ * string case compare and will eventually be extended to understand
+ * that 01:02:03:04:05:06 is the same as 1:2:3:4:5:6.
+ */
+int
+__virMacAddrCompare (const char *mac1, const char *mac2)
+{
+    return strcasecmp (mac1, mac2);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
Index: src/util.h
===================================================================
RCS file: /data/cvs/libvirt/src/util.h,v
retrieving revision 1.11
diff -u -r1.11 util.h
--- src/util.h	26 Feb 2008 07:05:18 -0000	1.11
+++ src/util.h	26 Feb 2008 13:10:46 -0000
@@ -79,4 +79,7 @@
 		       unsigned long long *result);
 #define virStrToLong_ull(s,e,b,r) __virStrToLong_ull((s),(e),(b),(r))
 
+int __virMacAddrCompare (const char *mac1, const char *mac2);
+#define virMacAddrCompare(mac1,mac2) __virMacAddrCompare((mac1),(mac2))
+
 #endif /* __VIR_UTIL_H__ */
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.133
diff -u -r1.133 virsh.c
--- src/virsh.c	22 Feb 2008 15:55:04 -0000	1.133
+++ src/virsh.c	26 Feb 2008 13:10:50 -0000
@@ -4742,7 +4742,7 @@
         while (cur != NULL) {
             if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "mac")) {
                 tmp_mac = xmlGetProp(cur, BAD_CAST "address");
-                diff_mac = xmlStrcasecmp(tmp_mac, BAD_CAST mac);
+                diff_mac = virMacAddrCompare ((char *) tmp_mac, mac);
                 xmlFree(tmp_mac);
                 if (!diff_mac) {
                     goto hit;
Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.64
diff -u -r1.64 xm_internal.c
--- src/xm_internal.c	20 Feb 2008 15:29:13 -0000	1.64
+++ src/xm_internal.c	26 Feb 2008 13:10:52 -0000
@@ -53,6 +53,7 @@
 #include "xml.h"
 #include "buf.h"
 #include "uuid.h"
+#include "util.h"
 
 static int xenXMConfigSetString(virConfPtr conf, const char *setting,
                                 const char *str);
@@ -2812,7 +2813,7 @@
                 key = nextkey;
             }
 
-            if (!(strcmp(dommac, (const char *) mac))) {
+            if (virMacAddrCompare (dommac, (const char *) mac) == 0) {
                 if (autoassign) {
                     free(mac);
                     mac = NULL;
@@ -3087,7 +3088,7 @@
                     mac = nextmac;
                 }
 
-                if (!(strcmp(dommac, (const char *) key)))
+                if (virMacAddrCompare (dommac, (const char *) key) == 0)
                     break;
             }
         skip:
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]