[ovs-dev] [ovn-ipv6 17/26] packets: Introduce xor and is_zero functions on IPv6 addresses.

Justin Pettit jpettit at ovn.org
Tue Jul 12 06:56:47 UTC 2016


These will have callers later.

Signed-off-by: Justin Pettit <jpettit at ovn.org>
---
 lib/packets.c | 38 ++++++++++++++++++++++++++++++++++++++
 lib/packets.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/lib/packets.c b/lib/packets.c
index 9e4d0e7..9b34961 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -693,6 +693,44 @@ struct in6_addr ipv6_addr_bitand(const struct in6_addr *a,
     return dst;
 }
 
+struct in6_addr ipv6_addr_bitxor(const struct in6_addr *a,
+                                 const struct in6_addr *b)
+{
+    int i;
+    struct in6_addr dst;
+
+#ifdef s6_addr32
+    for (i=0; i<4; i++) {
+        dst.s6_addr32[i] = a->s6_addr32[i] ^ b->s6_addr32[i];
+    }
+#else
+    for (i=0; i<16; i++) {
+        dst.s6_addr[i] = a->s6_addr[i] ^ b->s6_addr[i];
+    }
+#endif
+
+    return dst;
+}
+
+bool ipv6_is_zero(const struct in6_addr *a)
+{
+#ifdef s6_addr32
+    for (int i = 0; i < 4; i++) {
+        if (a->s6_addr32[i]) {
+            return false;
+        }
+    }
+#else
+    for (int i = 0; i < 16; i++) {
+        if (a->s6_addr[i]) {
+            return false;
+        }
+    }
+#endif
+
+    return true;
+}
+
 /* Returns an in6_addr consisting of 'mask' high-order 1-bits and 128-N
  * low-order 0-bits. */
 struct in6_addr
diff --git a/lib/packets.h b/lib/packets.h
index 06166de..2043175 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -1027,6 +1027,9 @@ void ipv6_format_masked(const struct in6_addr *addr,
 const char * ipv6_string_mapped(char *addr_str, const struct in6_addr *addr);
 struct in6_addr ipv6_addr_bitand(const struct in6_addr *src,
                                  const struct in6_addr *mask);
+struct in6_addr ipv6_addr_bitxor(const struct in6_addr *a,
+                                 const struct in6_addr *b);
+bool ipv6_is_zero(const struct in6_addr *a);
 struct in6_addr ipv6_create_mask(int mask);
 int ipv6_count_cidr_bits(const struct in6_addr *netmask);
 bool ipv6_is_cidr(const struct in6_addr *netmask);
-- 
1.9.1




More information about the dev mailing list