packets: Provide functions to work with IPv4-mapped IPv6 addresses.
authorThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Tue, 29 Sep 2015 22:09:16 +0000 (19:09 -0300)
committerBen Pfaff <blp@nicira.com>
Mon, 5 Oct 2015 18:05:55 +0000 (11:05 -0700)
Move in6_addr_set_mapped_ipv4 out of mcast-snooping code to packets.h and
provide an in6_addr_get_mapped_ipv4 function that gets the corresponding IPv4
address or the ANY address if it's not IPv4 mapped.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/mcast-snooping.c
lib/packets.h

index ba4141e..ff2382d 100644 (file)
@@ -125,15 +125,6 @@ mcast_snooping_lookup(const struct mcast_snooping *ms,
     return NULL;
 }
 
-static inline void
-in6_addr_set_mapped_ipv4(struct in6_addr *addr, ovs_be32 ip4)
-{
-    union ovs_16aligned_in6_addr *taddr = (void *) addr;
-    memset(taddr->be16, 0, sizeof(taddr->be16));
-    taddr->be16[5] = OVS_BE16_MAX;
-    put_16aligned_be32(&taddr->be32[3], ip4);
-}
-
 struct mcast_group *
 mcast_snooping_lookup4(const struct mcast_snooping *ms, ovs_be32 ip4,
                       uint16_t vlan)
index 4fb1427..d55c718 100644 (file)
@@ -28,6 +28,7 @@
 #include "random.h"
 #include "hash.h"
 #include "tun-metadata.h"
+#include "unaligned.h"
 #include "util.h"
 
 struct dp_packet;
@@ -870,6 +871,26 @@ static inline bool ipv6_is_all_hosts(const struct in6_addr *addr) {
     return ipv6_addr_equals(addr, &in6addr_all_hosts);
 }
 
+static inline void
+in6_addr_set_mapped_ipv4(struct in6_addr *addr, ovs_be32 ip4)
+{
+    union ovs_16aligned_in6_addr *taddr = (void *) addr;
+    memset(taddr->be16, 0, sizeof(taddr->be16));
+    taddr->be16[5] = OVS_BE16_MAX;
+    put_16aligned_be32(&taddr->be32[3], ip4);
+}
+
+static inline ovs_be32
+in6_addr_get_mapped_ipv4(const struct in6_addr *addr)
+{
+    union ovs_16aligned_in6_addr *taddr = (void *) addr;
+    if (IN6_IS_ADDR_V4MAPPED(addr)) {
+        return get_16aligned_be32(&taddr->be32[3]);
+    } else {
+        return INADDR_ANY;
+    }
+}
+
 static inline bool dl_type_is_ip_any(ovs_be16 dl_type)
 {
     return dl_type == htons(ETH_TYPE_IP)