[ovs-dev,RFC,2/7] Provide functions to work with IPv4-mapped IPv6 addresses.
diff mbox

Message ID 1443564561-11804-3-git-send-email-cascardo@redhat.com
State Accepted
Headers show

Commit Message

Thadeu Lima de Souza Cascardo Sept. 29, 2015, 10:09 p.m. UTC
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>
---
 lib/mcast-snooping.c |  9 ---------
 lib/packets.h        | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)

Comments

Ben Pfaff Oct. 5, 2015, 6:06 p.m. UTC | #1
On Tue, Sep 29, 2015 at 07:09:16PM -0300, Thadeu Lima de Souza Cascardo wrote:
> 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>

Applied, thanks!

Patch
diff mbox

diff --git a/lib/mcast-snooping.c b/lib/mcast-snooping.c
index ba4141e..ff2382d 100644
--- a/lib/mcast-snooping.c
+++ b/lib/mcast-snooping.c
@@ -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)
diff --git a/lib/packets.h b/lib/packets.h
index 4fb1427..d55c718 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -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)