[ovs-dev,02/15] tnl-arp-cache: fix log error when using tnl/arp/set with IPv6
diff mbox

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

Commit Message

Thadeu Lima de Souza Cascardo Oct. 22, 2015, 5:28 p.m. UTC
lookup_ip will emit an error when used with an IPv6 address, like below.

2015-10-20T18:48:22.357Z|00036|socket_util|ERR|"2001:cafe::92" is not a valid IP address

Verify if address looks like IPv6 before giving it to either lookup_ip or
lookup_ipv6.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
---
 lib/tnl-arp-cache.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Ben Pfaff Nov. 10, 2015, 6:01 p.m. UTC | #1
On Thu, Oct 22, 2015 at 03:28:55PM -0200, Thadeu Lima de Souza Cascardo wrote:
> lookup_ip will emit an error when used with an IPv6 address, like below.
> 
> 2015-10-20T18:48:22.357Z|00036|socket_util|ERR|"2001:cafe::92" is not a valid IP address
> 
> Verify if address looks like IPv6 before giving it to either lookup_ip or
> lookup_ipv6.
> 
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>

Applied, thanks!

Patch
diff mbox

diff --git a/lib/tnl-arp-cache.c b/lib/tnl-arp-cache.c
index d456d0c..85de312 100644
--- a/lib/tnl-arp-cache.c
+++ b/lib/tnl-arp-cache.c
@@ -236,18 +236,32 @@  tnl_arp_cache_flush(struct unixctl_conn *conn, int argc OVS_UNUSED,
     unixctl_command_reply(conn, "OK");
 }
 
+static int
+lookup_any(const char *host_name, struct in6_addr *address)
+{
+    if (addr_is_ipv6(host_name)) {
+        return lookup_ipv6(host_name, address);
+    } else {
+        int r;
+        struct in_addr ip;
+        r = lookup_ip(host_name, &ip);
+        if (r == 0) {
+            in6_addr_set_mapped_ipv4(address, ip.s_addr);
+        }
+        return r;
+    }
+    return ENOENT;
+}
+
 static void
 tnl_arp_cache_add(struct unixctl_conn *conn, int argc OVS_UNUSED,
                   const char *argv[], void *aux OVS_UNUSED)
 {
     const char *br_name = argv[1];
     struct eth_addr mac;
-    struct in_addr ip;
     struct in6_addr ip6;
 
-    if (lookup_ip(argv[2], &ip) == 0) {
-        in6_addr_set_mapped_ipv4(&ip6, ip.s_addr);
-    } else if (lookup_ipv6(argv[2], &ip6) != 0) {
+    if (lookup_any(argv[2], &ip6) != 0) {
         unixctl_command_reply_error(conn, "bad IP address");
         return;
     }