lib: add ipv6 helper functions for tnl_config
authorJiri Benc <jbenc@redhat.com>
Thu, 22 Oct 2015 17:28:54 +0000 (15:28 -0200)
committerBen Pfaff <blp@ovn.org>
Tue, 10 Nov 2015 18:00:04 +0000 (10:00 -0800)
These functions will be used by the next patches.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
AUTHORS
lib/smap.c
lib/smap.h
lib/socket-util.c
lib/socket-util.h

diff --git a/AUTHORS b/AUTHORS
index df185f2..c10b19f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -92,6 +92,7 @@ Jeremy Stribling        strib@nicira.com
 Jeroen van Bemmel       jvb127@gmail.com
 Jesse Gross             jesse@nicira.com
 Jing Ai                 jinga@google.com
+Jiri Benc               jbenc@redhat.com
 Joe Perches             joe@perches.com
 Joe Stringer            joestringer@nicira.com
 Jonathan Vestin         jonavest@kau.se
index 1d59f56..2c41013 100644 (file)
@@ -95,6 +95,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
index 3bfbb71..489497a 100644 (file)
@@ -66,6 +66,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 *);
index 206e17b..d053d37 100644 (file)
@@ -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. */
index 8015c7f..c3c1224 100644 (file)
@@ -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);