RDMA/core: Use common code flow for IPv4/6 for addr resolve
authorParav Pandit <parav@mellanox.com>
Wed, 5 Sep 2018 09:54:21 +0000 (12:54 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 12 Sep 2018 21:48:08 +0000 (15:48 -0600)
Use common code flow for resolving neighbour and for finding source
addresses.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Daniel Jurgens <danielj@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/addr.c

index c9d14d6996b2bf99f537eb9b57bd8f5e18c14433..cbc64de2d7914f54153025b30ef48bd3dbbffd03 100644 (file)
@@ -500,8 +500,8 @@ static int addr_resolve(struct sockaddr *src_in,
                        bool resolve_neigh,
                        u32 seq)
 {
+       struct dst_entry *dst = NULL;
        struct rtable *rt = NULL;
-       struct dst_entry *dst;
        int ret;
 
        if (!addr->net) {
@@ -510,28 +510,26 @@ static int addr_resolve(struct sockaddr *src_in,
        }
 
        if (src_in->sa_family == AF_INET) {
-
                ret = addr4_resolve(src_in, dst_in, addr, &rt);
-               if (ret)
-                       return ret;
-
-               ret = rdma_set_src_addr(&rt->dst, dst_in, addr);
-               if (!ret && resolve_neigh)
-                       ret = addr_resolve_neigh(&rt->dst, dst_in, addr, seq);
-
-               ip_rt_put(rt);
+               dst = &rt->dst;
        } else {
                ret = addr6_resolve(src_in, dst_in, addr, &dst);
-               if (ret)
-                       return ret;
+       }
+       if (ret)
+               return ret;
 
-               ret = rdma_set_src_addr(dst, dst_in, addr);
-               if (!ret && resolve_neigh)
-                       ret = addr_resolve_neigh(dst, dst_in, addr, seq);
+       ret = rdma_set_src_addr(dst, dst_in, addr);
+       /*
+        * Resolve neighbor destination address if requested and
+        * only if src addr translation didn't fail.
+        */
+       if (!ret && resolve_neigh)
+               ret = addr_resolve_neigh(dst, dst_in, addr, seq);
 
+       if (src_in->sa_family == AF_INET)
+               ip_rt_put(rt);
+       else
                dst_release(dst);
-       }
-
        return ret;
 }