These functions will be used by the next patch. Signed-off-by: Jiri Benc <jb...@redhat.com> --- lib/packets.h | 9 +++++++++ lib/smap.c | 11 +++++++++++ lib/smap.h | 1 + lib/socket-util.c | 9 +++++++++ lib/socket-util.h | 1 + 5 files changed, 31 insertions(+)
diff --git a/lib/packets.h b/lib/packets.h index b146a5069e25..385971903ce3 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -708,6 +708,15 @@ static inline bool ipv6_mask_is_exact(const struct in6_addr *mask) { return ipv6_addr_equals(mask, &in6addr_exact); } +static inline bool ipv6_addr_is_set(const struct in6_addr *ip) { + return (ip->s6_addr32[0] | ip->s6_addr32[1] | ip->s6_addr32[2] + | ip->s6_addr32[3]) != 0; +} + +static inline bool ipv6_addr_is_multicast(const struct in6_addr *ip) { + return ip->s6_addr[0] == 0xff; +} + static inline bool dl_type_is_ip_any(ovs_be16 dl_type) { return dl_type == htons(ETH_TYPE_IP) diff --git a/lib/smap.c b/lib/smap.c index 7fe3ce41cd75..cee0863469bc 100644 --- a/lib/smap.c +++ b/lib/smap.c @@ -94,6 +94,17 @@ smap_add_format(struct smap *smap, const char *key, const char *format, ...) hash_bytes(key, key_len, 0)); } +/* Adds 'key' paired with a string representation of 'addr'. It is the + * caller's responsibility to avoid duplicate keys if desirable. */ +void +smap_add_ipv6(struct smap *smap, const char *key, struct in6_addr *addr) +{ + char buf[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET6, addr, buf, sizeof buf); + smap_add(smap, key, buf); +} + /* Searches for 'key' in 'smap'. If it does not already exists, adds it. * Otherwise, changes its value to 'value'. */ void diff --git a/lib/smap.h b/lib/smap.h index caf3efcac365..913cbbccaabb 100644 --- a/lib/smap.h +++ b/lib/smap.h @@ -46,6 +46,7 @@ struct smap_node *smap_add_nocopy(struct smap *, char *, char *); bool smap_add_once(struct smap *, const char *, const char *); void smap_add_format(struct smap *, const char *key, const char *, ...) OVS_PRINTF_FORMAT(3, 4); +void smap_add_ipv6(struct smap *, const char *, struct in6_addr *); void smap_replace(struct smap *, const char *, const char *); void smap_remove(struct smap *, const char *); diff --git a/lib/socket-util.c b/lib/socket-util.c index 206e17bd23b3..97ee01bd881d 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -136,6 +136,15 @@ set_dscp(int fd, int family, uint8_t dscp) return retval ? sock_errno() : 0; } +/* Checks whether 'host_name' is an IPv4 or IPv6 address. It is assumed + * that 'host_name' is valid. Returns false if it is IPv4 address, true if + * it is IPv6 address. */ +bool +addr_is_ipv6(const char *host_name) +{ + return strchr(host_name, ':') != NULL; +} + /* Translates 'host_name', which must be a string representation of an IP * address, into a numeric IP address in '*addr'. Returns 0 if successful, * otherwise a positive errno value. */ diff --git a/lib/socket-util.h b/lib/socket-util.h index 1178fb8ce783..f1dad11d6f47 100644 --- a/lib/socket-util.h +++ b/lib/socket-util.h @@ -32,6 +32,7 @@ void xset_nonblocking(int fd); void setsockopt_tcp_nodelay(int fd); int set_dscp(int fd, int family, uint8_t dscp); +bool addr_is_ipv6(const char *host_name); int lookup_ip(const char *host_name, struct in_addr *address); int lookup_ipv6(const char *host_name, struct in6_addr *address); -- 1.8.3.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev