ib/addr: fix ipv6 routing lookup
PATCH 9/9 ib/addr: fix ipv6 routing lookup
Include link scope as part of address resolution. Combine local and remote address resolution into a single, simpler code path. Fix error checking in the IPv6 routing lookups.
Based on work from:
David Wilder <dwilder-r/[email protected]> Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
drivers/infiniband/core/addr.c | 144 +++++++++++----------------------------- drivers/infiniband/core/cma.c | 45 +++++++++---- 2 files changed, 72 insertions(+), 117 deletions(-)
drivers/infiniband/core/addr.c +41 -103
@@ -176,34 +176,6 @@ static void queue_req(struct addr_req *req)mutex_unlock (&lock); } -static void addr_send_arp (struct sockaddr *dst_in) -{ -struct rtable *rt; -struct flowi fl; - -memset (&fl,0 ,sizeof fl); - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct dst_entry *dst; - - fl.nl_u.ip6_u.daddr = - ((struct sockaddr_in6 *) dst_in)->sin6_addr; - - dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ; - -neigh_event_send (dst->neighbour,NULL ); -dst_release (dst); -break ; - } -#endif - } -} -static int addr4_resolve (struct sockaddr_in *src_in,struct sockaddr_in *dst_in,struct rdma_dev_addr *addr)
@@ -259,39 +231,63 @@ out: }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {struct flowi fl;struct neighbour *neigh;struct dst_entry *dst; -int ret = -ENODATA ; +int ret;memset (&fl,0 ,sizeof fl); - fl.nl_u.ip6_u.daddr = dst_in->sin6_addr; - fl.nl_u.ip6_u.saddr = src_in->sin6_addr; +ipv6_addr_copy (&fl.fl6_dst, &dst_in->sin6_addr); +ipv6_addr_copy (&fl.fl6_src, &src_in->sin6_addr); fl.oif = addr->bound_dev_if; dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ret; +if ((ret = dst->error)) + goto put; +if (ipv6_addr_any (&fl.fl6_src)) { + ret =ipv6_dev_get_saddr (&init_net,ip6_dst_idev (dst)->dev, + &fl.fl6_dst,0 , &fl.fl6_src); +if (ret) + goto put; + + src_in->sin6_family =AF_INET6 ; +ipv6_addr_copy (&src_in->sin6_addr, &fl.fl6_src); + } + +if (dst->dev->flags &IFF_LOOPBACK ) { + ret =rdma_translate_ip ((struct sockaddr *) dst_in, addr); +if (!ret) +memcpy (addr->dst_dev_addr, addr->src_dev_addr,MAX_ADDR_LEN ); + goto put; + } + +/* If the device does ARP internally, return 'done' */ if (dst->dev->flags &IFF_NOARP ) { ret =rdma_copy_addr (addr, dst->dev,NULL ); - }else { - neigh = dst->neighbour; -if (neigh && (neigh->nud_state &NUD_VALID )) - ret =rdma_copy_addr (addr, neigh->dev, neigh->ha); + goto put; + } + + neigh = dst->neighbour; +if (!neigh || !(neigh->nud_state &NUD_VALID )) { +neigh_event_send (dst->neighbour,NULL ); + ret = -ENODATA ; + goto put; } + ret =rdma_copy_addr (addr, dst->dev, neigh->ha); +put:dst_release (dst);return ret; }#else -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {return -EADDRNOTAVAIL ; }
@@ -305,7 +301,7 @@ static int addr_resolve(struct sockaddr *src_in,return addr4_resolve ((struct sockaddr_in *) src_in, (struct sockaddr_in *) dst_in, addr); }else -return addr6_resolve_remote ((struct sockaddr_in6 *) src_in, +return addr6_resolve ((struct sockaddr_in6 *) src_in, (struct sockaddr_in6 *) dst_in, addr); }
@@ -346,60 +342,6 @@ static void process_req(struct work_struct *work) } } -static int addr_resolve_local (struct sockaddr *src_in, -struct sockaddr *dst_in, -struct rdma_dev_addr *addr) -{ -struct net_device *dev; -int ret; - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct in6_addr *a; - -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) -if (ipv6_chk_addr (&init_net, - &((struct sockaddr_in6 *) addr)->sin6_addr, - dev,1 )) -break ; - -if (!dev) { -read_unlock (&dev_base_lock); -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 ); - } -read_unlock (&dev_base_lock); -break ; - } -#endif - -default : - ret = -EADDRNOTAVAIL ; -break ; - } - -return ret; -} - int rdma_resolve_ip(struct rdma_addr_client *client, struct sockaddr *src_addr, struct sockaddr *dst_addr, struct rdma_dev_addr *addr, int timeout_ms,
@@ -429,10 +371,7 @@ int rdma_resolve_ip(struct rdma_addr_client *client, src_in = (struct sockaddr *) &req->src_addr; dst_in = (struct sockaddr *) &req->dst_addr; - req->status =addr_resolve_local (src_in, dst_in, addr); -if (req->status == -EADDRNOTAVAIL ) - req->status =addr_resolve (src_in, dst_in, addr); - + req->status =addr_resolve (src_in, dst_in, addr);switch (req->status) {case 0 : req->timeout = jiffies;
@@ -441,7 +380,6 @@ int rdma_resolve_ip(struct rdma_addr_client *client,case -ENODATA : req->timeout =msecs_to_jiffies (timeout_ms) + jiffies;queue_req (req); -addr_send_arp (dst_in);break ;default : ret = req->status;
drivers/infiniband/core/cma.c +31 -14
75 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 9/9 ib/addr: fix ipv6 routing lookup
In reply to a message not in the archiveib/addr: fix ipv6 routing lookup
From: Sean Hefty <[email protected]>
Include link scope as part of address resolution. Combine local and remote address resolution into a single, simpler code path. Fix error checking in the IPv6 routing lookups.
Based on work from:
David Wilder <dwilder-r/[email protected]> Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
change from v1:
update from 2.6.31 to 2.6.32-rc7
remove end of line white space
drivers/infiniband/core/addr.c | 144 +++++++++++----------------------------- drivers/infiniband/core/cma.c | 45 +++++++++---- 2 files changed, 72 insertions(+), 117 deletions(-)
drivers/infiniband/core/addr.c +41 -103
@@ -176,34 +176,6 @@ static void queue_req(struct addr_req *req)mutex_unlock (&lock); } -static void addr_send_arp (struct sockaddr *dst_in) -{ -struct rtable *rt; -struct flowi fl; - -memset (&fl,0 ,sizeof fl); - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct dst_entry *dst; - - fl.nl_u.ip6_u.daddr = - ((struct sockaddr_in6 *) dst_in)->sin6_addr; - - dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ; - -neigh_event_send (dst->neighbour,NULL ); -dst_release (dst); -break ; - } -#endif - } -} -static int addr4_resolve (struct sockaddr_in *src_in,struct sockaddr_in *dst_in,struct rdma_dev_addr *addr)
@@ -259,39 +231,63 @@ out: }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {struct flowi fl;struct neighbour *neigh;struct dst_entry *dst; -int ret = -ENODATA ; +int ret;memset (&fl,0 ,sizeof fl); - fl.nl_u.ip6_u.daddr = dst_in->sin6_addr; - fl.nl_u.ip6_u.saddr = src_in->sin6_addr; +ipv6_addr_copy (&fl.fl6_dst, &dst_in->sin6_addr); +ipv6_addr_copy (&fl.fl6_src, &src_in->sin6_addr); fl.oif = addr->bound_dev_if; dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ret; +if ((ret = dst->error)) + goto put; +if (ipv6_addr_any (&fl.fl6_src)) { + ret =ipv6_dev_get_saddr (&init_net,ip6_dst_idev (dst)->dev, + &fl.fl6_dst,0 , &fl.fl6_src); +if (ret) + goto put; + + src_in->sin6_family =AF_INET6 ; +ipv6_addr_copy (&src_in->sin6_addr, &fl.fl6_src); + } + +if (dst->dev->flags &IFF_LOOPBACK ) { + ret =rdma_translate_ip ((struct sockaddr *) dst_in, addr); +if (!ret) +memcpy (addr->dst_dev_addr, addr->src_dev_addr,MAX_ADDR_LEN ); + goto put; + } + +/* If the device does ARP internally, return 'done' */ if (dst->dev->flags &IFF_NOARP ) { ret =rdma_copy_addr (addr, dst->dev,NULL ); - }else { - neigh = dst->neighbour; -if (neigh && (neigh->nud_state &NUD_VALID )) - ret =rdma_copy_addr (addr, neigh->dev, neigh->ha); + goto put; + } + + neigh = dst->neighbour; +if (!neigh || !(neigh->nud_state &NUD_VALID )) { +neigh_event_send (dst->neighbour,NULL ); + ret = -ENODATA ; + goto put; } + ret =rdma_copy_addr (addr, dst->dev, neigh->ha); +put:dst_release (dst);return ret; }#else -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {return -EADDRNOTAVAIL ; }
@@ -305,7 +301,7 @@ static int addr_resolve(struct sockaddr *src_in,return addr4_resolve ((struct sockaddr_in *) src_in, (struct sockaddr_in *) dst_in, addr); }else -return addr6_resolve_remote ((struct sockaddr_in6 *) src_in, +return addr6_resolve ((struct sockaddr_in6 *) src_in, (struct sockaddr_in6 *) dst_in, addr); }
@@ -346,60 +342,6 @@ static void process_req(struct work_struct *work) } } -static int addr_resolve_local (struct sockaddr *src_in, -struct sockaddr *dst_in, -struct rdma_dev_addr *addr) -{ -struct net_device *dev; -int ret; - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct in6_addr *a; - -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) -if (ipv6_chk_addr (&init_net, - &((struct sockaddr_in6 *) dst_in)->sin6_addr, - dev,1 )) -break ; - -if (!dev) { -read_unlock (&dev_base_lock); -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 ); - } -read_unlock (&dev_base_lock); -break ; - } -#endif - -default : - ret = -EADDRNOTAVAIL ; -break ; - } - -return ret; -} - int rdma_resolve_ip(struct rdma_addr_client *client, struct sockaddr *src_addr, struct sockaddr *dst_addr, struct rdma_dev_addr *addr, int timeout_ms,
@@ -429,10 +371,7 @@ int rdma_resolve_ip(struct rdma_addr_client *client, src_in = (struct sockaddr *) &req->src_addr; dst_in = (struct sockaddr *) &req->dst_addr; - req->status =addr_resolve_local (src_in, dst_in, addr); -if (req->status == -EADDRNOTAVAIL ) - req->status =addr_resolve (src_in, dst_in, addr); - + req->status =addr_resolve (src_in, dst_in, addr);switch (req->status) {case 0 : req->timeout = jiffies;
@@ -441,7 +380,6 @@ int rdma_resolve_ip(struct rdma_addr_client *client,case -ENODATA : req->timeout =msecs_to_jiffies (timeout_ms) + jiffies;queue_req (req); -addr_send_arp (dst_in);break ;default : ret = req->status;
drivers/infiniband/core/cma.c +31 -14
75 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 9/9 ib/addr: fix ipv6 routing lookup
In reply to a message not in the archiveInclude link scope as part of address resolution. Combine local and remote address resolution into a single, simpler code path. Fix error checking in the IPv6 routing lookups.
Based on work from:
David Wilder <dwilder-r/[email protected]> Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
change from v2:
modified lines are the same, only updated because of changes to patch 5 in series
change from v1:
update from 2.6.31 to 2.6.32-rc7
remove end of line white space
drivers/infiniband/core/addr.c | 144 +++++++++++----------------------------- drivers/infiniband/core/cma.c | 45 +++++++++---- 2 files changed, 72 insertions(+), 117 deletions(-)
drivers/infiniband/core/addr.c +41 -103
@@ -176,34 +176,6 @@ static void queue_req(struct addr_req *req)mutex_unlock (&lock); } -static void addr_send_arp (struct sockaddr *dst_in) -{ -struct rtable *rt; -struct flowi fl; - -memset (&fl,0 ,sizeof fl); - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct dst_entry *dst; - - fl.nl_u.ip6_u.daddr = - ((struct sockaddr_in6 *) dst_in)->sin6_addr; - - dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ; - -neigh_event_send (dst->neighbour,NULL ); -dst_release (dst); -break ; - } -#endif - } -} -static int addr4_resolve (struct sockaddr_in *src_in,struct sockaddr_in *dst_in,struct rdma_dev_addr *addr)
@@ -259,39 +231,63 @@ out: }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {struct flowi fl;struct neighbour *neigh;struct dst_entry *dst; -int ret = -ENODATA ; +int ret;memset (&fl,0 ,sizeof fl); - fl.nl_u.ip6_u.daddr = dst_in->sin6_addr; - fl.nl_u.ip6_u.saddr = src_in->sin6_addr; +ipv6_addr_copy (&fl.fl6_dst, &dst_in->sin6_addr); +ipv6_addr_copy (&fl.fl6_src, &src_in->sin6_addr); fl.oif = addr->bound_dev_if; dst =ip6_route_output (&init_net,NULL , &fl); -if (!dst) -return ret; +if ((ret = dst->error)) + goto put; + +if (ipv6_addr_any (&fl.fl6_src)) { + ret =ipv6_dev_get_saddr (&init_net,ip6_dst_idev (dst)->dev, + &fl.fl6_dst,0 , &fl.fl6_src); +if (ret) + goto put; + src_in->sin6_family =AF_INET6 ; +ipv6_addr_copy (&src_in->sin6_addr, &fl.fl6_src); + } + +if (dst->dev->flags &IFF_LOOPBACK ) { + ret =rdma_translate_ip ((struct sockaddr *) dst_in, addr); +if (!ret) +memcpy (addr->dst_dev_addr, addr->src_dev_addr,MAX_ADDR_LEN ); + goto put; + } + +/* If the device does ARP internally, return 'done' */ if (dst->dev->flags &IFF_NOARP ) { ret =rdma_copy_addr (addr, dst->dev,NULL ); - }else { - neigh = dst->neighbour; -if (neigh && (neigh->nud_state &NUD_VALID )) - ret =rdma_copy_addr (addr, neigh->dev, neigh->ha); + goto put; } + neigh = dst->neighbour; +if (!neigh || !(neigh->nud_state &NUD_VALID )) { +neigh_event_send (dst->neighbour,NULL ); + ret = -ENODATA ; + goto put; + } + + ret =rdma_copy_addr (addr, dst->dev, neigh->ha); +put:dst_release (dst);return ret; }#else -static int addr6_resolve_remote (struct sockaddr_in6 *src_in, -struct sockaddr_in6 *dst_in, -struct rdma_dev_addr *addr) +static int addr6_resolve (struct sockaddr_in6 *src_in, +struct sockaddr_in6 *dst_in, +struct rdma_dev_addr *addr) {return -EADDRNOTAVAIL ; }
@@ -305,7 +301,7 @@ static int addr_resolve(struct sockaddr *src_in,return addr4_resolve ((struct sockaddr_in *) src_in, (struct sockaddr_in *) dst_in, addr); }else -return addr6_resolve_remote ((struct sockaddr_in6 *) src_in, +return addr6_resolve ((struct sockaddr_in6 *) src_in, (struct sockaddr_in6 *) dst_in, addr); }
@@ -346,60 +342,6 @@ static void process_req(struct work_struct *work) } } -static int addr_resolve_local (struct sockaddr *src_in, -struct sockaddr *dst_in, -struct rdma_dev_addr *addr) -{ -struct net_device *dev; -int ret; - -switch (dst_in->sa_family) { -#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -case AF_INET6 : - { -struct in6_addr *a; - -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) -if (ipv6_chk_addr (&init_net, - &((struct sockaddr_in6 *) dst_in)->sin6_addr, - dev,1 )) -break ; - -if (!dev) { -read_unlock (&dev_base_lock); -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 ); - } -read_unlock (&dev_base_lock); -break ; - } -#endif - -default : - ret = -EADDRNOTAVAIL ; -break ; - } - -return ret; -} - int rdma_resolve_ip(struct rdma_addr_client *client, struct sockaddr *src_addr, struct sockaddr *dst_addr, struct rdma_dev_addr *addr, int timeout_ms,
@@ -436,10 +378,7 @@ int rdma_resolve_ip(struct rdma_addr_client *client, req->client = client;atomic_inc (&client->refcount); - req->status =addr_resolve_local (src_in, dst_in, addr); -if (req->status == -EADDRNOTAVAIL ) - req->status =addr_resolve (src_in, dst_in, addr); - + req->status =addr_resolve (src_in, dst_in, addr);switch (req->status) {case 0 : req->timeout = jiffies;
@@ -448,7 +387,6 @@ int rdma_resolve_ip(struct rdma_addr_client *client,case -ENODATA : req->timeout =msecs_to_jiffies (timeout_ms) + jiffies;queue_req (req); -addr_send_arp (dst_in);break ;default : ret = req->status;
drivers/infiniband/core/cma.c +31 -14
75 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Sean Hefty
drivers/infiniband/core/cma.c +6
-0+static int cma_check_linklocal (struct rdma_dev_addr *dev_addr, +struct sockaddr *addr) +{ +struct sockaddr_in6 *sin6; + +if (addr->sa_family !=AF_INET6 )
drivers/infiniband/core/cma.c static int cma_get_port(struct rdma_id_private *id_priv) · line 2098
Quoted 10 lines
drivers/infiniband/core/cma.c +10
-0+return 0 ; + + sin6 = (struct sockaddr_in6 *) addr; +if ((ipv6_addr_type (&sin6->sin6_addr) &IPV6_ADDR_LINKLOCAL ) && + !sin6->sin6_scope_id) +return -EINVAL ; + + dev_addr->bound_dev_if = sin6->sin6_scope_id; +return 0 ; +}
There is something missing here to match the TCP sin6_scope_id semantics..
I think what you have is OK for the non-error cases, but the rdma_resolve_addr path does need to check that an input sin6_scope_id is either 0 or matches bound_dev_if and return EINVAL.
My approach was to use this:
static int check_ip6_ll(struct rdma_dev_addr *dev_addr,
const struct sockaddr *addr)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
if (addr->sa_family != AF_INET6)
return 0;
if (ipv6_addr_type(&addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL) {
if (dev_addr->bound_dev_if &&
dev_addr->bound_dev_if != addr6->sin6_scope_id)
return -EINVAL;
dev_addr->bound_dev_if = addr6->sin6_scope_id;
if (!dev_addr->bound_dev_if)
return -EINVAL;
}
return 0;
}On all 3 addresess, I copied the algorithm from the TCP stack.
The main missing test from the new version is:
if (dev_addr->bound_dev_if &&
dev_addr->bound_dev_if != addr6->sin6_scope_id)
return -EINVAL;Done on the 2nd src and dest address.
Any thoughts on how to fit that in?
Were you able to check the dst/neighbour stuff at all?
Otherwise it looks great to me, thanks for doing this.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 20 lines
Quoted 6 lines
drivers/infiniband/core/cma.c +6
-0+static int cma_check_linklocal (struct rdma_dev_addr *dev_addr, +struct sockaddr *addr) +{ +struct sockaddr_in6 *sin6; + +if (addr->sa_family !=AF_INET6 )drivers/infiniband/core/cma.c static int cma_get_port(struct rdma_id_private *id_priv) · line 2098
Quoted 10 lines
drivers/infiniband/core/cma.c +10
-0+return 0 ; + + sin6 = (struct sockaddr_in6 *) addr; +if ((ipv6_addr_type (&sin6->sin6_addr) &IPV6_ADDR_LINKLOCAL ) && + !sin6->sin6_scope_id) +return -EINVAL ; + + dev_addr->bound_dev_if = sin6->sin6_scope_id; +return 0 ; +}There is something missing here to match the TCP
sin6_scope_idsemantics..
Quoted 3 lines
I think what you have is OK for the non-error cases, but the
rdma_resolve_addrpath does need to check that an inputsin6_scope_idis either 0 or matchesbound_dev_ifand return EINVAL.
cma_check_linklocal() is only called from rdma_bind_addr(), and is the only place where bound_dev_if is set in cma.c. So this if statement:
Quoted 3 lines
if (dev_addr->bound_dev_if &&
dev_addr->bound_dev_if != addr6->sin6_scope_id)
return -EINVAL;would always be false. bound_dev_if should be 0.
Quoted 8 lines
The main missing test from the new version is:
if (dev_addr->bound_dev_if && dev_addr->bound_dev_if != addr6->sin6_scope_id) return -EINVAL;Done on the 2nd src and dest address.
Any thoughts on how to fit that in?
A separate check can be added to rdma_resolve_addr if it's really needed, but I'm not sure that we need to require that the source and destination use the same device or RDMA port.
- Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Sean Hefty
Quoted 5 lines
The main missing test from the new version is:
if (dev_addr->bound_dev_if && dev_addr->bound_dev_if != addr6->sin6_scope_id) return -EINVAL;
Quoted 7 lines
Quoted 3 lines
Done on the 2nd src and dest address.
Any thoughts on how to fit that in?
A separate check can be added to
rdma_resolve_addrif it's really needed, but I'm not sure that we need to require that the source and destination use the same device or RDMA port.
We do need to check this only for IPv6 link local addresses, that is what TCP does. The reason is that the LL addresses are not unique, so it is impossible to reach a LL on a different interface than the socket is bound to.
All other cases can use any IP/IPv6 address assigned to any interface with any bound device (the Linux IP is associated with the host, not the NIC, model).
Actually, upon looking closer, there is another little thing:
2083 static int cma_check_linklocal(struct rdma_dev_addr *dev_addr,
2084 struct sockaddr *addr)
2085 {
2086 #if defined(CONFIG_IPv6) || defined(CONFIG_IPV6_MODULE)
2087 struct sockaddr_in6 *sin6;
2088
2089 if (addr->sa_family != AF_INET6)
2090 return 0;
2091
2092 sin6 = (struct sockaddr_in6 *) addr;
2093 if ((ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
2094 !sin6->sin6_scope_id)
2095 return -EINVAL;
2096
2097 dev_addr->bound_dev_if = sin6->sin6_scope_id;
The sin6_scope_id must be ignored in all cases except LL addresses. Fixing this will break the path that sets the bound_dev_if starting from rdma_resolve_addr. This is why my version was setting bound_dev_if directly in rdma_resolve_addr.
Did you change it to be like this because you found something wrong with the way things were in my big patch?
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines
The
sin6_scope_idmust be ignored in all cases except LL addresses. Fixing this will break the path that sets thebound_dev_ifstarting fromrdma_resolve_addr. This is why my version was settingbound_dev_ifdirectly inrdma_resolve_addr.Did you change it to be like this because you found something wrong with the way things were in my big patch?
I was wanting to have all of the code paths go through rdma_bind_addr(), with source address checks there to things as easy to follow as possible.
- Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Sean Hefty
Quoted 7 lines
The
sin6_scope_idmust be ignored in all cases except LL addresses. Fixing this will break the path that sets thebound_dev_ifstarting fromrdma_resolve_addr. This is why my version was settingbound_dev_ifdirectly inrdma_resolve_addr.Did you change it to be like this because you found something wrong with the way things were in my big patch?
I was wanting to have all of the code paths go through
rdma_bind_addr(), with source address checks there to things as easy to follow as possible.
OK. Then I'll send a patch to do it the other way, processing sin6_scope_id for the non-link-local case is worth fixing.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html