2 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
4 * Copyright (c) 1999-2005, Mellanox Technologies, Inc. All rights reserved.
5 * Copyright (c) 2005 Intel Corporation. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/mutex.h>
37 #include <linux/inetdevice.h>
38 #include <linux/slab.h>
39 #include <linux/workqueue.h>
40 #include <linux/module.h>
42 #include <net/neighbour.h>
43 #include <net/route.h>
44 #include <net/netevent.h>
45 #include <net/ipv6_stubs.h>
46 #include <net/ip6_route.h>
47 #include <rdma/ib_addr.h>
48 #include <rdma/ib_cache.h>
49 #include <rdma/ib_sa.h>
51 #include <rdma/rdma_netlink.h>
52 #include <net/netlink.h>
54 #include "core_priv.h"
57 struct list_head list
;
58 struct sockaddr_storage src_addr
;
59 struct sockaddr_storage dst_addr
;
60 struct rdma_dev_addr
*addr
;
62 void (*callback
)(int status
, struct sockaddr
*src_addr
,
63 struct rdma_dev_addr
*addr
, void *context
);
64 unsigned long timeout
;
65 struct delayed_work work
;
66 bool resolve_by_gid_attr
; /* Consider gid attr in resolve phase */
71 static atomic_t ib_nl_addr_request_seq
= ATOMIC_INIT(0);
73 static DEFINE_SPINLOCK(lock
);
74 static LIST_HEAD(req_list
);
75 static struct workqueue_struct
*addr_wq
;
77 static const struct nla_policy ib_nl_addr_policy
[LS_NLA_TYPE_MAX
] = {
78 [LS_NLA_TYPE_DGID
] = {.type
= NLA_BINARY
,
79 .len
= sizeof(struct rdma_nla_ls_gid
)},
82 static inline bool ib_nl_is_good_ip_resp(const struct nlmsghdr
*nlh
)
84 struct nlattr
*tb
[LS_NLA_TYPE_MAX
] = {};
87 if (nlh
->nlmsg_flags
& RDMA_NL_LS_F_ERR
)
90 ret
= nla_parse_deprecated(tb
, LS_NLA_TYPE_MAX
- 1, nlmsg_data(nlh
),
91 nlmsg_len(nlh
), ib_nl_addr_policy
, NULL
);
98 static void ib_nl_process_good_ip_rsep(const struct nlmsghdr
*nlh
)
100 const struct nlattr
*head
, *curr
;
102 struct addr_req
*req
;
106 head
= (const struct nlattr
*)nlmsg_data(nlh
);
107 len
= nlmsg_len(nlh
);
109 nla_for_each_attr(curr
, head
, len
, rem
) {
110 if (curr
->nla_type
== LS_NLA_TYPE_DGID
)
111 memcpy(&gid
, nla_data(curr
), nla_len(curr
));
115 list_for_each_entry(req
, &req_list
, list
) {
116 if (nlh
->nlmsg_seq
!= req
->seq
)
118 /* We set the DGID part, the rest was set earlier */
119 rdma_addr_set_dgid(req
->addr
, &gid
);
124 spin_unlock_bh(&lock
);
127 pr_info("Couldn't find request waiting for DGID: %pI6\n",
131 int ib_nl_handle_ip_res_resp(struct sk_buff
*skb
,
132 struct nlmsghdr
*nlh
,
133 struct netlink_ext_ack
*extack
)
135 if ((nlh
->nlmsg_flags
& NLM_F_REQUEST
) ||
136 !(NETLINK_CB(skb
).sk
))
139 if (ib_nl_is_good_ip_resp(nlh
))
140 ib_nl_process_good_ip_rsep(nlh
);
145 static int ib_nl_ip_send_msg(struct rdma_dev_addr
*dev_addr
,
149 struct sk_buff
*skb
= NULL
;
150 struct nlmsghdr
*nlh
;
151 struct rdma_ls_ip_resolve_header
*header
;
157 if (family
== AF_INET
) {
158 size
= sizeof(struct in_addr
);
159 attrtype
= RDMA_NLA_F_MANDATORY
| LS_NLA_TYPE_IPV4
;
161 size
= sizeof(struct in6_addr
);
162 attrtype
= RDMA_NLA_F_MANDATORY
| LS_NLA_TYPE_IPV6
;
165 len
= nla_total_size(sizeof(size
));
166 len
+= NLMSG_ALIGN(sizeof(*header
));
168 skb
= nlmsg_new(len
, GFP_KERNEL
);
172 data
= ibnl_put_msg(skb
, &nlh
, seq
, 0, RDMA_NL_LS
,
173 RDMA_NL_LS_OP_IP_RESOLVE
, NLM_F_REQUEST
);
179 /* Construct the family header first */
180 header
= skb_put(skb
, NLMSG_ALIGN(sizeof(*header
)));
181 header
->ifindex
= dev_addr
->bound_dev_if
;
182 nla_put(skb
, attrtype
, size
, daddr
);
184 /* Repair the nlmsg header length */
186 rdma_nl_multicast(&init_net
, skb
, RDMA_NL_GROUP_LS
, GFP_KERNEL
);
188 /* Make the request retry, so when we get the response from userspace
189 * we will have something.
194 int rdma_addr_size(const struct sockaddr
*addr
)
196 switch (addr
->sa_family
) {
198 return sizeof(struct sockaddr_in
);
200 return sizeof(struct sockaddr_in6
);
202 return sizeof(struct sockaddr_ib
);
207 EXPORT_SYMBOL(rdma_addr_size
);
209 int rdma_addr_size_in6(struct sockaddr_in6
*addr
)
211 int ret
= rdma_addr_size((struct sockaddr
*) addr
);
213 return ret
<= sizeof(*addr
) ? ret
: 0;
215 EXPORT_SYMBOL(rdma_addr_size_in6
);
217 int rdma_addr_size_kss(struct __kernel_sockaddr_storage
*addr
)
219 int ret
= rdma_addr_size((struct sockaddr
*) addr
);
221 return ret
<= sizeof(*addr
) ? ret
: 0;
223 EXPORT_SYMBOL(rdma_addr_size_kss
);
226 * rdma_copy_src_l2_addr - Copy netdevice source addresses
227 * @dev_addr: Destination address pointer where to copy the addresses
228 * @dev: Netdevice whose source addresses to copy
230 * rdma_copy_src_l2_addr() copies source addresses from the specified netdevice.
231 * This includes unicast address, broadcast address, device type and
234 void rdma_copy_src_l2_addr(struct rdma_dev_addr
*dev_addr
,
235 const struct net_device
*dev
)
237 dev_addr
->dev_type
= dev
->type
;
238 memcpy(dev_addr
->src_dev_addr
, dev
->dev_addr
, MAX_ADDR_LEN
);
239 memcpy(dev_addr
->broadcast
, dev
->broadcast
, MAX_ADDR_LEN
);
240 dev_addr
->bound_dev_if
= dev
->ifindex
;
242 EXPORT_SYMBOL(rdma_copy_src_l2_addr
);
244 static struct net_device
*
245 rdma_find_ndev_for_src_ip_rcu(struct net
*net
, const struct sockaddr
*src_in
)
247 struct net_device
*dev
= NULL
;
248 int ret
= -EADDRNOTAVAIL
;
250 switch (src_in
->sa_family
) {
252 dev
= __ip_dev_find(net
,
253 ((const struct sockaddr_in
*)src_in
)->sin_addr
.s_addr
,
258 #if IS_ENABLED(CONFIG_IPV6)
260 for_each_netdev_rcu(net
, dev
) {
261 if (ipv6_chk_addr(net
,
262 &((const struct sockaddr_in6
*)src_in
)->sin6_addr
,
271 return ret
? ERR_PTR(ret
) : dev
;
274 int rdma_translate_ip(const struct sockaddr
*addr
,
275 struct rdma_dev_addr
*dev_addr
)
277 struct net_device
*dev
;
279 if (dev_addr
->bound_dev_if
) {
280 dev
= dev_get_by_index(dev_addr
->net
, dev_addr
->bound_dev_if
);
283 rdma_copy_src_l2_addr(dev_addr
, dev
);
289 dev
= rdma_find_ndev_for_src_ip_rcu(dev_addr
->net
, addr
);
291 rdma_copy_src_l2_addr(dev_addr
, dev
);
293 return PTR_ERR_OR_ZERO(dev
);
295 EXPORT_SYMBOL(rdma_translate_ip
);
297 static void set_timeout(struct addr_req
*req
, unsigned long time
)
301 delay
= time
- jiffies
;
305 mod_delayed_work(addr_wq
, &req
->work
, delay
);
308 static void queue_req(struct addr_req
*req
)
311 list_add_tail(&req
->list
, &req_list
);
312 set_timeout(req
, req
->timeout
);
313 spin_unlock_bh(&lock
);
316 static int ib_nl_fetch_ha(struct rdma_dev_addr
*dev_addr
,
317 const void *daddr
, u32 seq
, u16 family
)
319 if (!rdma_nl_chk_listeners(RDMA_NL_GROUP_LS
))
320 return -EADDRNOTAVAIL
;
322 return ib_nl_ip_send_msg(dev_addr
, daddr
, seq
, family
);
325 static int dst_fetch_ha(const struct dst_entry
*dst
,
326 struct rdma_dev_addr
*dev_addr
,
332 n
= dst_neigh_lookup(dst
, daddr
);
336 if (!(n
->nud_state
& NUD_VALID
)) {
337 neigh_event_send(n
, NULL
);
340 neigh_ha_snapshot(dev_addr
->dst_dev_addr
, n
, dst
->dev
);
348 static bool has_gateway(const struct dst_entry
*dst
, sa_family_t family
)
351 struct rt6_info
*rt6
;
353 if (family
== AF_INET
) {
354 rt
= container_of(dst
, struct rtable
, dst
);
355 return rt
->rt_uses_gateway
;
358 rt6
= container_of(dst
, struct rt6_info
, dst
);
359 return rt6
->rt6i_flags
& RTF_GATEWAY
;
362 static int fetch_ha(const struct dst_entry
*dst
, struct rdma_dev_addr
*dev_addr
,
363 const struct sockaddr
*dst_in
, u32 seq
)
365 const struct sockaddr_in
*dst_in4
=
366 (const struct sockaddr_in
*)dst_in
;
367 const struct sockaddr_in6
*dst_in6
=
368 (const struct sockaddr_in6
*)dst_in
;
369 const void *daddr
= (dst_in
->sa_family
== AF_INET
) ?
370 (const void *)&dst_in4
->sin_addr
.s_addr
:
371 (const void *)&dst_in6
->sin6_addr
;
372 sa_family_t family
= dst_in
->sa_family
;
376 /* If we have a gateway in IB mode then it must be an IB network */
377 if (has_gateway(dst
, family
) && dev_addr
->network
== RDMA_NETWORK_IB
)
378 return ib_nl_fetch_ha(dev_addr
, daddr
, seq
, family
);
380 return dst_fetch_ha(dst
, dev_addr
, daddr
);
383 static int addr4_resolve(struct sockaddr
*src_sock
,
384 const struct sockaddr
*dst_sock
,
385 struct rdma_dev_addr
*addr
,
388 struct sockaddr_in
*src_in
= (struct sockaddr_in
*)src_sock
;
389 const struct sockaddr_in
*dst_in
=
390 (const struct sockaddr_in
*)dst_sock
;
392 __be32 src_ip
= src_in
->sin_addr
.s_addr
;
393 __be32 dst_ip
= dst_in
->sin_addr
.s_addr
;
398 memset(&fl4
, 0, sizeof(fl4
));
401 fl4
.flowi4_oif
= addr
->bound_dev_if
;
402 rt
= ip_route_output_key(addr
->net
, &fl4
);
403 ret
= PTR_ERR_OR_ZERO(rt
);
407 src_in
->sin_addr
.s_addr
= fl4
.saddr
;
409 addr
->hoplimit
= ip4_dst_hoplimit(&rt
->dst
);
415 #if IS_ENABLED(CONFIG_IPV6)
416 static int addr6_resolve(struct sockaddr
*src_sock
,
417 const struct sockaddr
*dst_sock
,
418 struct rdma_dev_addr
*addr
,
419 struct dst_entry
**pdst
)
421 struct sockaddr_in6
*src_in
= (struct sockaddr_in6
*)src_sock
;
422 const struct sockaddr_in6
*dst_in
=
423 (const struct sockaddr_in6
*)dst_sock
;
425 struct dst_entry
*dst
;
427 memset(&fl6
, 0, sizeof fl6
);
428 fl6
.daddr
= dst_in
->sin6_addr
;
429 fl6
.saddr
= src_in
->sin6_addr
;
430 fl6
.flowi6_oif
= addr
->bound_dev_if
;
432 dst
= ipv6_stub
->ipv6_dst_lookup_flow(addr
->net
, NULL
, &fl6
, NULL
);
436 if (ipv6_addr_any(&src_in
->sin6_addr
))
437 src_in
->sin6_addr
= fl6
.saddr
;
439 addr
->hoplimit
= ip6_dst_hoplimit(dst
);
445 static int addr6_resolve(struct sockaddr
*src_sock
,
446 const struct sockaddr
*dst_sock
,
447 struct rdma_dev_addr
*addr
,
448 struct dst_entry
**pdst
)
450 return -EADDRNOTAVAIL
;
454 static int addr_resolve_neigh(const struct dst_entry
*dst
,
455 const struct sockaddr
*dst_in
,
456 struct rdma_dev_addr
*addr
,
457 unsigned int ndev_flags
,
462 if (ndev_flags
& IFF_LOOPBACK
) {
463 memcpy(addr
->dst_dev_addr
, addr
->src_dev_addr
, MAX_ADDR_LEN
);
465 if (!(ndev_flags
& IFF_NOARP
)) {
466 /* If the device doesn't do ARP internally */
467 ret
= fetch_ha(dst
, addr
, dst_in
, seq
);
473 static int copy_src_l2_addr(struct rdma_dev_addr
*dev_addr
,
474 const struct sockaddr
*dst_in
,
475 const struct dst_entry
*dst
,
476 const struct net_device
*ndev
)
480 if (dst
->dev
->flags
& IFF_LOOPBACK
)
481 ret
= rdma_translate_ip(dst_in
, dev_addr
);
483 rdma_copy_src_l2_addr(dev_addr
, dst
->dev
);
486 * If there's a gateway and type of device not ARPHRD_INFINIBAND,
487 * we're definitely in RoCE v2 (as RoCE v1 isn't routable) set the
488 * network type accordingly.
490 if (has_gateway(dst
, dst_in
->sa_family
) &&
491 ndev
->type
!= ARPHRD_INFINIBAND
)
492 dev_addr
->network
= dst_in
->sa_family
== AF_INET
?
496 dev_addr
->network
= RDMA_NETWORK_IB
;
501 static int rdma_set_src_addr_rcu(struct rdma_dev_addr
*dev_addr
,
502 unsigned int *ndev_flags
,
503 const struct sockaddr
*dst_in
,
504 const struct dst_entry
*dst
)
506 struct net_device
*ndev
= READ_ONCE(dst
->dev
);
508 *ndev_flags
= ndev
->flags
;
509 /* A physical device must be the RDMA device to use */
510 if (ndev
->flags
& IFF_LOOPBACK
) {
512 * RDMA (IB/RoCE, iWarp) doesn't run on lo interface or
513 * loopback IP address. So if route is resolved to loopback
514 * interface, translate that to a real ndev based on non
515 * loopback IP address.
517 ndev
= rdma_find_ndev_for_src_ip_rcu(dev_net(ndev
), dst_in
);
522 return copy_src_l2_addr(dev_addr
, dst_in
, dst
, ndev
);
525 static int set_addr_netns_by_gid_rcu(struct rdma_dev_addr
*addr
)
527 struct net_device
*ndev
;
529 ndev
= rdma_read_gid_attr_ndev_rcu(addr
->sgid_attr
);
531 return PTR_ERR(ndev
);
534 * Since we are holding the rcu, reading net and ifindex
535 * are safe without any additional reference; because
536 * change_net_namespace() in net/core/dev.c does rcu sync
537 * after it changes the state to IFF_DOWN and before
538 * updating netdev fields {net, ifindex}.
540 addr
->net
= dev_net(ndev
);
541 addr
->bound_dev_if
= ndev
->ifindex
;
545 static void rdma_addr_set_net_defaults(struct rdma_dev_addr
*addr
)
547 addr
->net
= &init_net
;
548 addr
->bound_dev_if
= 0;
551 static int addr_resolve(struct sockaddr
*src_in
,
552 const struct sockaddr
*dst_in
,
553 struct rdma_dev_addr
*addr
,
555 bool resolve_by_gid_attr
,
558 struct dst_entry
*dst
= NULL
;
559 unsigned int ndev_flags
= 0;
560 struct rtable
*rt
= NULL
;
564 pr_warn_ratelimited("%s: missing namespace\n", __func__
);
569 if (resolve_by_gid_attr
) {
570 if (!addr
->sgid_attr
) {
572 pr_warn_ratelimited("%s: missing gid_attr\n", __func__
);
576 * If the request is for a specific gid attribute of the
577 * rdma_dev_addr, derive net from the netdevice of the
580 ret
= set_addr_netns_by_gid_rcu(addr
);
586 if (src_in
->sa_family
== AF_INET
) {
587 ret
= addr4_resolve(src_in
, dst_in
, addr
, &rt
);
590 ret
= addr6_resolve(src_in
, dst_in
, addr
, &dst
);
596 ret
= rdma_set_src_addr_rcu(addr
, &ndev_flags
, dst_in
, dst
);
600 * Resolve neighbor destination address if requested and
601 * only if src addr translation didn't fail.
603 if (!ret
&& resolve_neigh
)
604 ret
= addr_resolve_neigh(dst
, dst_in
, addr
, ndev_flags
, seq
);
606 if (src_in
->sa_family
== AF_INET
)
612 * Clear the addr net to go back to its original state, only if it was
613 * derived from GID attribute in this context.
615 if (resolve_by_gid_attr
)
616 rdma_addr_set_net_defaults(addr
);
620 static void process_one_req(struct work_struct
*_work
)
622 struct addr_req
*req
;
623 struct sockaddr
*src_in
, *dst_in
;
625 req
= container_of(_work
, struct addr_req
, work
.work
);
627 if (req
->status
== -ENODATA
) {
628 src_in
= (struct sockaddr
*)&req
->src_addr
;
629 dst_in
= (struct sockaddr
*)&req
->dst_addr
;
630 req
->status
= addr_resolve(src_in
, dst_in
, req
->addr
,
631 true, req
->resolve_by_gid_attr
,
633 if (req
->status
&& time_after_eq(jiffies
, req
->timeout
)) {
634 req
->status
= -ETIMEDOUT
;
635 } else if (req
->status
== -ENODATA
) {
636 /* requeue the work for retrying again */
638 if (!list_empty(&req
->list
))
639 set_timeout(req
, req
->timeout
);
640 spin_unlock_bh(&lock
);
645 req
->callback(req
->status
, (struct sockaddr
*)&req
->src_addr
,
646 req
->addr
, req
->context
);
647 req
->callback
= NULL
;
651 * Although the work will normally have been canceled by the workqueue,
652 * it can still be requeued as long as it is on the req_list.
654 cancel_delayed_work(&req
->work
);
655 if (!list_empty(&req
->list
)) {
656 list_del_init(&req
->list
);
659 spin_unlock_bh(&lock
);
662 int rdma_resolve_ip(struct sockaddr
*src_addr
, const struct sockaddr
*dst_addr
,
663 struct rdma_dev_addr
*addr
, unsigned long timeout_ms
,
664 void (*callback
)(int status
, struct sockaddr
*src_addr
,
665 struct rdma_dev_addr
*addr
, void *context
),
666 bool resolve_by_gid_attr
, void *context
)
668 struct sockaddr
*src_in
, *dst_in
;
669 struct addr_req
*req
;
672 req
= kzalloc(sizeof *req
, GFP_KERNEL
);
676 src_in
= (struct sockaddr
*) &req
->src_addr
;
677 dst_in
= (struct sockaddr
*) &req
->dst_addr
;
680 if (src_addr
->sa_family
!= dst_addr
->sa_family
) {
685 memcpy(src_in
, src_addr
, rdma_addr_size(src_addr
));
687 src_in
->sa_family
= dst_addr
->sa_family
;
690 memcpy(dst_in
, dst_addr
, rdma_addr_size(dst_addr
));
692 req
->callback
= callback
;
693 req
->context
= context
;
694 req
->resolve_by_gid_attr
= resolve_by_gid_attr
;
695 INIT_DELAYED_WORK(&req
->work
, process_one_req
);
696 req
->seq
= (u32
)atomic_inc_return(&ib_nl_addr_request_seq
);
698 req
->status
= addr_resolve(src_in
, dst_in
, addr
, true,
699 req
->resolve_by_gid_attr
, req
->seq
);
700 switch (req
->status
) {
702 req
->timeout
= jiffies
;
706 req
->timeout
= msecs_to_jiffies(timeout_ms
) + jiffies
;
718 EXPORT_SYMBOL(rdma_resolve_ip
);
720 int roce_resolve_route_from_path(struct sa_path_rec
*rec
,
721 const struct ib_gid_attr
*attr
)
724 struct sockaddr _sockaddr
;
725 struct sockaddr_in _sockaddr_in
;
726 struct sockaddr_in6 _sockaddr_in6
;
728 struct rdma_dev_addr dev_addr
= {};
733 if (rec
->roce
.route_resolved
)
736 rdma_gid2ip((struct sockaddr
*)&sgid
, &rec
->sgid
);
737 rdma_gid2ip((struct sockaddr
*)&dgid
, &rec
->dgid
);
739 if (sgid
._sockaddr
.sa_family
!= dgid
._sockaddr
.sa_family
)
742 if (!attr
|| !attr
->ndev
)
745 dev_addr
.net
= &init_net
;
746 dev_addr
.sgid_attr
= attr
;
748 ret
= addr_resolve((struct sockaddr
*)&sgid
, (struct sockaddr
*)&dgid
,
749 &dev_addr
, false, true, 0);
753 if ((dev_addr
.network
== RDMA_NETWORK_IPV4
||
754 dev_addr
.network
== RDMA_NETWORK_IPV6
) &&
755 rec
->rec_type
!= SA_PATH_REC_TYPE_ROCE_V2
)
758 rec
->roce
.route_resolved
= true;
763 * rdma_addr_cancel - Cancel resolve ip request
764 * @addr: Pointer to address structure given previously
765 * during rdma_resolve_ip().
766 * rdma_addr_cancel() is synchronous function which cancels any pending
767 * request if there is any.
769 void rdma_addr_cancel(struct rdma_dev_addr
*addr
)
771 struct addr_req
*req
, *temp_req
;
772 struct addr_req
*found
= NULL
;
775 list_for_each_entry_safe(req
, temp_req
, &req_list
, list
) {
776 if (req
->addr
== addr
) {
778 * Removing from the list means we take ownership of
781 list_del_init(&req
->list
);
786 spin_unlock_bh(&lock
);
792 * sync canceling the work after removing it from the req_list
793 * guarentees no work is running and none will be started.
795 cancel_delayed_work_sync(&found
->work
);
798 EXPORT_SYMBOL(rdma_addr_cancel
);
800 struct resolve_cb_context
{
801 struct completion comp
;
805 static void resolve_cb(int status
, struct sockaddr
*src_addr
,
806 struct rdma_dev_addr
*addr
, void *context
)
808 ((struct resolve_cb_context
*)context
)->status
= status
;
809 complete(&((struct resolve_cb_context
*)context
)->comp
);
812 int rdma_addr_find_l2_eth_by_grh(const union ib_gid
*sgid
,
813 const union ib_gid
*dgid
,
814 u8
*dmac
, const struct ib_gid_attr
*sgid_attr
,
817 struct rdma_dev_addr dev_addr
;
818 struct resolve_cb_context ctx
;
820 struct sockaddr_in _sockaddr_in
;
821 struct sockaddr_in6 _sockaddr_in6
;
822 } sgid_addr
, dgid_addr
;
825 rdma_gid2ip((struct sockaddr
*)&sgid_addr
, sgid
);
826 rdma_gid2ip((struct sockaddr
*)&dgid_addr
, dgid
);
828 memset(&dev_addr
, 0, sizeof(dev_addr
));
829 dev_addr
.net
= &init_net
;
830 dev_addr
.sgid_attr
= sgid_attr
;
832 init_completion(&ctx
.comp
);
833 ret
= rdma_resolve_ip((struct sockaddr
*)&sgid_addr
,
834 (struct sockaddr
*)&dgid_addr
, &dev_addr
, 1000,
835 resolve_cb
, true, &ctx
);
839 wait_for_completion(&ctx
.comp
);
845 memcpy(dmac
, dev_addr
.dst_dev_addr
, ETH_ALEN
);
846 *hoplimit
= dev_addr
.hoplimit
;
850 static int netevent_callback(struct notifier_block
*self
, unsigned long event
,
853 struct addr_req
*req
;
855 if (event
== NETEVENT_NEIGH_UPDATE
) {
856 struct neighbour
*neigh
= ctx
;
858 if (neigh
->nud_state
& NUD_VALID
) {
860 list_for_each_entry(req
, &req_list
, list
)
861 set_timeout(req
, jiffies
);
862 spin_unlock_bh(&lock
);
868 static struct notifier_block nb
= {
869 .notifier_call
= netevent_callback
874 addr_wq
= alloc_ordered_workqueue("ib_addr", 0);
878 register_netevent_notifier(&nb
);
883 void addr_cleanup(void)
885 unregister_netevent_notifier(&nb
);
886 destroy_workqueue(addr_wq
);
887 WARN_ON(!list_empty(&req_list
));