[ofa-general] IPv6 RDMA CM PATCHv2 7/8

Hefty, Sean sean.hefty at intel.com
Mon Aug 11 12:34:20 PDT 2008


>+static inline struct net_device *cma_ipv6_dev_find(struct in6_addr *addr)

inline isn't needed

>+{
>+       struct net_device *dev = 0;

We don't need to initialize dev here.  (If we did, it should be set to NULL.)

>+       for_each_netdev(&init_net, dev)
>+               if (ipv6_chk_addr(&init_net,  addr, dev, 1))
>+                       return dev;
>+       return NULL;
>+}
>+
> int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
> {
>        struct net_device *dev;
>@@ -128,12 +137,13 @@ int rdma_translate_ip(struct sockaddr *addr, struct
>rdma_dev_addr *dev_addr)
>                dev_put(dev);
>                break;
>        case AF_INET6:
>-               for_each_netdev(&init_net, dev) {
>-                       if (ipv6_chk_addr(&init_net, &((struct sockaddr_in6 *)
>addr)->sin6_addr, dev, 1)) {
>-                               ret = rdma_copy_addr(dev_addr, dev, NULL);
>-                               break;
>-                       }
>-               }
>+               dev = cma_ipv6_dev_find(
>+                       &((struct sockaddr_in6 *)addr)->sin6_addr);
>+

extra blank line

>+               if (!dev)
>+                       return -EADDRNOTAVAIL;
>+
>+               ret = rdma_copy_addr(dev_addr, dev, NULL);
>                break;
>        default:
>                break;
>@@ -279,30 +289,60 @@ static int addr_resolve_local(struct sockaddr *src_in,
>                              struct rdma_dev_addr *addr)
> {
>        struct net_device *dev;
>-       __be32 src_ip = ((struct sockaddr_in *)src_in)->sin_addr.s_addr;
>-       __be32 dst_ip = ((struct sockaddr_in *)dst_in)->sin_addr.s_addr;
>-       int ret;
>+       int ret = -EADDRNOTAVAIL;

initialization isn't needed

>
>-       dev = ip_dev_find(&init_net, dst_ip);
>-       if (!dev)
>-               return -EADDRNOTAVAIL;
>+       if (dst_in->sa_family == AF_INET) {
>+               __be32 src_ip = ((struct sockaddr_in *)src_in)-
>>sin_addr.s_addr;
>+               __be32 dst_ip = ((struct sockaddr_in *)dst_in)-
>>sin_addr.s_addr;
>
>-       if (ipv4_is_zeronet(src_ip)) {
>-               src_in->sa_family = dst_in->sa_family;
>-               ((struct sockaddr_in *)src_in)->sin_addr.s_addr = dst_ip;
>-               ret = rdma_copy_addr(addr, dev, dev->dev_addr);
>-       } else if (ipv4_is_loopback(src_ip)) {
>-               ret = rdma_translate_ip(dst_in, addr);
>-               if (!ret)
>-                       memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>-       } else {
>-               ret = rdma_translate_ip(src_in, addr);
>-               if (!ret)
>-                       memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>-       }
>+               dev = ip_dev_find(&init_net, dst_ip);
>+               if (!dev)
>+                       return -EADDRNOTAVAIL;
>
>-       dev_put(dev);
>-       return ret;
>+               if (ipv4_is_zeronet(src_ip)) {
>+                       src_in->sa_family = dst_in->sa_family;
>+                       ((struct sockaddr_in *)src_in)->sin_addr.s_addr =
>dst_ip;
>+                       ret = rdma_copy_addr(addr, dev, dev->dev_addr);
>+               } else if (ipv4_is_loopback(src_ip)) {
>+                       ret = rdma_translate_ip(dst_in, addr);
>+                       if (!ret)
>+                               memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>+               } else {
>+                       ret = rdma_translate_ip(src_in, addr);
>+                       if (!ret)
>+                               memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>+               }
>+
>+               dev_put(dev);
>+               return ret;

use single return statement at end of function

>+       } else if (dst_in->sa_family == AF_INET6) {

should be safe to just make into an else

>+               struct in6_addr *a = &((struct sockaddr_in6 *)dst_in)-
>>sin6_addr;
>+
>+               dev = cma_ipv6_dev_find(a);
>+

extra blank line

>+               if (!dev)
>+                       return -EADDRNOTAVAIL;
>+
>+               a = &((struct sockaddr_in6 *)src_in)->sin6_addr;
>+
>+               if (ipv6_addr_any(a)) {
>+                       src_in->sa_family = dst_in->sa_family;
>+                       ((struct sockaddr_in6 *)src_in)->sin6_addr =
>+                               ((struct sockaddr_in6 *)dst_in)->sin6_addr;
>+                       ret = rdma_copy_addr(addr, dev, dev->dev_addr);
>+               } else if (ipv6_addr_loopback(a)) {
>+                       ret = rdma_translate_ip(dst_in, addr);
>+                       if (!ret)
>+                               memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>+               } else  {
>+                       ret = rdma_translate_ip(src_in, addr);
>+                       if (!ret)
>+                               memcpy(addr->dst_dev_addr, dev->dev_addr,
>MAX_ADDR_LEN);
>+               }
>+
>+               return ret;

use single return statement at end of function

>+       }
>+       return -EADDRNOTAVAIL;

use return ret;

> }




More information about the general mailing list