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 <casca...@redhat.com> --- lib/mcast-snooping.c | 9 --------- lib/packets.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) 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) -- 2.4.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev