2 * Copyright (c) 2014 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2014 Intel Corporation. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include "iwpm_util.h"
36 #define IWPM_MAPINFO_HASH_SIZE 512
37 #define IWPM_MAPINFO_HASH_MASK (IWPM_MAPINFO_HASH_SIZE - 1)
38 #define IWPM_REMINFO_HASH_SIZE 64
39 #define IWPM_REMINFO_HASH_MASK (IWPM_REMINFO_HASH_SIZE - 1)
40 #define IWPM_MSG_SIZE 512
42 static LIST_HEAD(iwpm_nlmsg_req_list
);
43 static DEFINE_SPINLOCK(iwpm_nlmsg_req_lock
);
45 static struct hlist_head
*iwpm_hash_bucket
;
46 static DEFINE_SPINLOCK(iwpm_mapinfo_lock
);
48 static struct hlist_head
*iwpm_reminfo_bucket
;
49 static DEFINE_SPINLOCK(iwpm_reminfo_lock
);
51 static DEFINE_MUTEX(iwpm_admin_lock
);
52 static struct iwpm_admin_data iwpm_admin
;
54 int iwpm_init(u8 nl_client
)
57 if (iwpm_valid_client(nl_client
))
59 mutex_lock(&iwpm_admin_lock
);
60 if (atomic_read(&iwpm_admin
.refcount
) == 0) {
61 iwpm_hash_bucket
= kzalloc(IWPM_MAPINFO_HASH_SIZE
*
62 sizeof(struct hlist_head
), GFP_KERNEL
);
63 if (!iwpm_hash_bucket
) {
65 pr_err("%s Unable to create mapinfo hash table\n", __func__
);
68 iwpm_reminfo_bucket
= kzalloc(IWPM_REMINFO_HASH_SIZE
*
69 sizeof(struct hlist_head
), GFP_KERNEL
);
70 if (!iwpm_reminfo_bucket
) {
71 kfree(iwpm_hash_bucket
);
73 pr_err("%s Unable to create reminfo hash table\n", __func__
);
77 atomic_inc(&iwpm_admin
.refcount
);
79 mutex_unlock(&iwpm_admin_lock
);
81 iwpm_set_valid(nl_client
, 1);
82 iwpm_set_registration(nl_client
, IWPM_REG_UNDEF
);
83 pr_debug("%s: Mapinfo and reminfo tables are created\n",
88 EXPORT_SYMBOL(iwpm_init
);
90 static void free_hash_bucket(void);
91 static void free_reminfo_bucket(void);
93 int iwpm_exit(u8 nl_client
)
96 if (!iwpm_valid_client(nl_client
))
98 mutex_lock(&iwpm_admin_lock
);
99 if (atomic_read(&iwpm_admin
.refcount
) == 0) {
100 mutex_unlock(&iwpm_admin_lock
);
101 pr_err("%s Incorrect usage - negative refcount\n", __func__
);
104 if (atomic_dec_and_test(&iwpm_admin
.refcount
)) {
106 free_reminfo_bucket();
107 pr_debug("%s: Resources are destroyed\n", __func__
);
109 mutex_unlock(&iwpm_admin_lock
);
110 iwpm_set_valid(nl_client
, 0);
111 iwpm_set_registration(nl_client
, IWPM_REG_UNDEF
);
114 EXPORT_SYMBOL(iwpm_exit
);
116 static struct hlist_head
*get_mapinfo_hash_bucket(struct sockaddr_storage
*,
117 struct sockaddr_storage
*);
119 int iwpm_create_mapinfo(struct sockaddr_storage
*local_sockaddr
,
120 struct sockaddr_storage
*mapped_sockaddr
,
123 struct hlist_head
*hash_bucket_head
;
124 struct iwpm_mapping_info
*map_info
;
128 if (!iwpm_valid_client(nl_client
))
130 map_info
= kzalloc(sizeof(struct iwpm_mapping_info
), GFP_KERNEL
);
132 pr_err("%s: Unable to allocate a mapping info\n", __func__
);
135 memcpy(&map_info
->local_sockaddr
, local_sockaddr
,
136 sizeof(struct sockaddr_storage
));
137 memcpy(&map_info
->mapped_sockaddr
, mapped_sockaddr
,
138 sizeof(struct sockaddr_storage
));
139 map_info
->nl_client
= nl_client
;
141 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
142 if (iwpm_hash_bucket
) {
143 hash_bucket_head
= get_mapinfo_hash_bucket(
144 &map_info
->local_sockaddr
,
145 &map_info
->mapped_sockaddr
);
146 if (hash_bucket_head
) {
147 hlist_add_head(&map_info
->hlist_node
, hash_bucket_head
);
151 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
154 EXPORT_SYMBOL(iwpm_create_mapinfo
);
156 int iwpm_remove_mapinfo(struct sockaddr_storage
*local_sockaddr
,
157 struct sockaddr_storage
*mapped_local_addr
)
159 struct hlist_node
*tmp_hlist_node
;
160 struct hlist_head
*hash_bucket_head
;
161 struct iwpm_mapping_info
*map_info
= NULL
;
165 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
166 if (iwpm_hash_bucket
) {
167 hash_bucket_head
= get_mapinfo_hash_bucket(
170 if (!hash_bucket_head
)
171 goto remove_mapinfo_exit
;
173 hlist_for_each_entry_safe(map_info
, tmp_hlist_node
,
174 hash_bucket_head
, hlist_node
) {
176 if (!iwpm_compare_sockaddr(&map_info
->mapped_sockaddr
,
177 mapped_local_addr
)) {
179 hlist_del_init(&map_info
->hlist_node
);
187 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
190 EXPORT_SYMBOL(iwpm_remove_mapinfo
);
192 static void free_hash_bucket(void)
194 struct hlist_node
*tmp_hlist_node
;
195 struct iwpm_mapping_info
*map_info
;
199 /* remove all the mapinfo data from the list */
200 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
201 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
202 hlist_for_each_entry_safe(map_info
, tmp_hlist_node
,
203 &iwpm_hash_bucket
[i
], hlist_node
) {
205 hlist_del_init(&map_info
->hlist_node
);
209 /* free the hash list */
210 kfree(iwpm_hash_bucket
);
211 iwpm_hash_bucket
= NULL
;
212 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
215 static void free_reminfo_bucket(void)
217 struct hlist_node
*tmp_hlist_node
;
218 struct iwpm_remote_info
*rem_info
;
222 /* remove all the remote info from the list */
223 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
224 for (i
= 0; i
< IWPM_REMINFO_HASH_SIZE
; i
++) {
225 hlist_for_each_entry_safe(rem_info
, tmp_hlist_node
,
226 &iwpm_reminfo_bucket
[i
], hlist_node
) {
228 hlist_del_init(&rem_info
->hlist_node
);
232 /* free the hash list */
233 kfree(iwpm_reminfo_bucket
);
234 iwpm_reminfo_bucket
= NULL
;
235 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
238 static struct hlist_head
*get_reminfo_hash_bucket(struct sockaddr_storage
*,
239 struct sockaddr_storage
*);
241 void iwpm_add_remote_info(struct iwpm_remote_info
*rem_info
)
243 struct hlist_head
*hash_bucket_head
;
246 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
247 if (iwpm_reminfo_bucket
) {
248 hash_bucket_head
= get_reminfo_hash_bucket(
249 &rem_info
->mapped_loc_sockaddr
,
250 &rem_info
->mapped_rem_sockaddr
);
251 if (hash_bucket_head
)
252 hlist_add_head(&rem_info
->hlist_node
, hash_bucket_head
);
254 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
257 int iwpm_get_remote_info(struct sockaddr_storage
*mapped_loc_addr
,
258 struct sockaddr_storage
*mapped_rem_addr
,
259 struct sockaddr_storage
*remote_addr
,
262 struct hlist_node
*tmp_hlist_node
;
263 struct hlist_head
*hash_bucket_head
;
264 struct iwpm_remote_info
*rem_info
= NULL
;
268 if (!iwpm_valid_client(nl_client
)) {
269 pr_info("%s: Invalid client = %d\n", __func__
, nl_client
);
272 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
273 if (iwpm_reminfo_bucket
) {
274 hash_bucket_head
= get_reminfo_hash_bucket(
277 if (!hash_bucket_head
)
278 goto get_remote_info_exit
;
279 hlist_for_each_entry_safe(rem_info
, tmp_hlist_node
,
280 hash_bucket_head
, hlist_node
) {
282 if (!iwpm_compare_sockaddr(&rem_info
->mapped_loc_sockaddr
,
284 !iwpm_compare_sockaddr(&rem_info
->mapped_rem_sockaddr
,
287 memcpy(remote_addr
, &rem_info
->remote_sockaddr
,
288 sizeof(struct sockaddr_storage
));
289 iwpm_print_sockaddr(remote_addr
,
290 "get_remote_info: Remote sockaddr:");
292 hlist_del_init(&rem_info
->hlist_node
);
299 get_remote_info_exit
:
300 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
303 EXPORT_SYMBOL(iwpm_get_remote_info
);
305 struct iwpm_nlmsg_request
*iwpm_get_nlmsg_request(__u32 nlmsg_seq
,
306 u8 nl_client
, gfp_t gfp
)
308 struct iwpm_nlmsg_request
*nlmsg_request
= NULL
;
311 nlmsg_request
= kzalloc(sizeof(struct iwpm_nlmsg_request
), gfp
);
312 if (!nlmsg_request
) {
313 pr_err("%s Unable to allocate a nlmsg_request\n", __func__
);
316 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
317 list_add_tail(&nlmsg_request
->inprocess_list
, &iwpm_nlmsg_req_list
);
318 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
320 kref_init(&nlmsg_request
->kref
);
321 kref_get(&nlmsg_request
->kref
);
322 nlmsg_request
->nlmsg_seq
= nlmsg_seq
;
323 nlmsg_request
->nl_client
= nl_client
;
324 nlmsg_request
->request_done
= 0;
325 nlmsg_request
->err_code
= 0;
326 sema_init(&nlmsg_request
->sem
, 1);
327 down(&nlmsg_request
->sem
);
328 return nlmsg_request
;
331 void iwpm_free_nlmsg_request(struct kref
*kref
)
333 struct iwpm_nlmsg_request
*nlmsg_request
;
336 nlmsg_request
= container_of(kref
, struct iwpm_nlmsg_request
, kref
);
338 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
339 list_del_init(&nlmsg_request
->inprocess_list
);
340 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
342 if (!nlmsg_request
->request_done
)
343 pr_debug("%s Freeing incomplete nlmsg request (seq = %u).\n",
344 __func__
, nlmsg_request
->nlmsg_seq
);
345 kfree(nlmsg_request
);
348 struct iwpm_nlmsg_request
*iwpm_find_nlmsg_request(__u32 echo_seq
)
350 struct iwpm_nlmsg_request
*nlmsg_request
;
351 struct iwpm_nlmsg_request
*found_request
= NULL
;
354 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
355 list_for_each_entry(nlmsg_request
, &iwpm_nlmsg_req_list
,
357 if (nlmsg_request
->nlmsg_seq
== echo_seq
) {
358 found_request
= nlmsg_request
;
359 kref_get(&nlmsg_request
->kref
);
363 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
364 return found_request
;
367 int iwpm_wait_complete_req(struct iwpm_nlmsg_request
*nlmsg_request
)
371 ret
= down_timeout(&nlmsg_request
->sem
, IWPM_NL_TIMEOUT
);
374 pr_info("%s: Timeout %d sec for netlink request (seq = %u)\n",
375 __func__
, (IWPM_NL_TIMEOUT
/HZ
), nlmsg_request
->nlmsg_seq
);
377 ret
= nlmsg_request
->err_code
;
379 kref_put(&nlmsg_request
->kref
, iwpm_free_nlmsg_request
);
383 int iwpm_get_nlmsg_seq(void)
385 return atomic_inc_return(&iwpm_admin
.nlmsg_seq
);
388 int iwpm_valid_client(u8 nl_client
)
390 if (nl_client
>= RDMA_NL_NUM_CLIENTS
)
392 return iwpm_admin
.client_list
[nl_client
];
395 void iwpm_set_valid(u8 nl_client
, int valid
)
397 if (nl_client
>= RDMA_NL_NUM_CLIENTS
)
399 iwpm_admin
.client_list
[nl_client
] = valid
;
403 u32
iwpm_get_registration(u8 nl_client
)
405 return iwpm_admin
.reg_list
[nl_client
];
409 void iwpm_set_registration(u8 nl_client
, u32 reg
)
411 iwpm_admin
.reg_list
[nl_client
] = reg
;
415 u32
iwpm_check_registration(u8 nl_client
, u32 reg
)
417 return (iwpm_get_registration(nl_client
) & reg
);
420 int iwpm_compare_sockaddr(struct sockaddr_storage
*a_sockaddr
,
421 struct sockaddr_storage
*b_sockaddr
)
423 if (a_sockaddr
->ss_family
!= b_sockaddr
->ss_family
)
425 if (a_sockaddr
->ss_family
== AF_INET
) {
426 struct sockaddr_in
*a4_sockaddr
=
427 (struct sockaddr_in
*)a_sockaddr
;
428 struct sockaddr_in
*b4_sockaddr
=
429 (struct sockaddr_in
*)b_sockaddr
;
430 if (!memcmp(&a4_sockaddr
->sin_addr
,
431 &b4_sockaddr
->sin_addr
, sizeof(struct in_addr
))
432 && a4_sockaddr
->sin_port
== b4_sockaddr
->sin_port
)
435 } else if (a_sockaddr
->ss_family
== AF_INET6
) {
436 struct sockaddr_in6
*a6_sockaddr
=
437 (struct sockaddr_in6
*)a_sockaddr
;
438 struct sockaddr_in6
*b6_sockaddr
=
439 (struct sockaddr_in6
*)b_sockaddr
;
440 if (!memcmp(&a6_sockaddr
->sin6_addr
,
441 &b6_sockaddr
->sin6_addr
, sizeof(struct in6_addr
))
442 && a6_sockaddr
->sin6_port
== b6_sockaddr
->sin6_port
)
446 pr_err("%s: Invalid sockaddr family\n", __func__
);
451 struct sk_buff
*iwpm_create_nlmsg(u32 nl_op
, struct nlmsghdr
**nlh
,
454 struct sk_buff
*skb
= NULL
;
456 skb
= dev_alloc_skb(IWPM_MSG_SIZE
);
458 pr_err("%s Unable to allocate skb\n", __func__
);
459 goto create_nlmsg_exit
;
461 if (!(ibnl_put_msg(skb
, nlh
, 0, 0, nl_client
, nl_op
,
463 pr_warn("%s: Unable to put the nlmsg header\n", __func__
);
471 int iwpm_parse_nlmsg(struct netlink_callback
*cb
, int policy_max
,
472 const struct nla_policy
*nlmsg_policy
,
473 struct nlattr
*nltb
[], const char *msg_type
)
477 const char *err_str
= "";
479 ret
= nlmsg_validate(cb
->nlh
, nlh_len
, policy_max
-1, nlmsg_policy
);
481 err_str
= "Invalid attribute";
482 goto parse_nlmsg_error
;
484 ret
= nlmsg_parse(cb
->nlh
, nlh_len
, nltb
, policy_max
-1, nlmsg_policy
);
486 err_str
= "Unable to parse the nlmsg";
487 goto parse_nlmsg_error
;
489 ret
= iwpm_validate_nlmsg_attr(nltb
, policy_max
);
491 err_str
= "Invalid NULL attribute";
492 goto parse_nlmsg_error
;
496 pr_warn("%s: %s (msg type %s ret = %d)\n",
497 __func__
, err_str
, msg_type
, ret
);
501 void iwpm_print_sockaddr(struct sockaddr_storage
*sockaddr
, char *msg
)
503 struct sockaddr_in6
*sockaddr_v6
;
504 struct sockaddr_in
*sockaddr_v4
;
506 switch (sockaddr
->ss_family
) {
508 sockaddr_v4
= (struct sockaddr_in
*)sockaddr
;
509 pr_debug("%s IPV4 %pI4: %u(0x%04X)\n",
510 msg
, &sockaddr_v4
->sin_addr
,
511 ntohs(sockaddr_v4
->sin_port
),
512 ntohs(sockaddr_v4
->sin_port
));
515 sockaddr_v6
= (struct sockaddr_in6
*)sockaddr
;
516 pr_debug("%s IPV6 %pI6: %u(0x%04X)\n",
517 msg
, &sockaddr_v6
->sin6_addr
,
518 ntohs(sockaddr_v6
->sin6_port
),
519 ntohs(sockaddr_v6
->sin6_port
));
526 static u32
iwpm_ipv6_jhash(struct sockaddr_in6
*ipv6_sockaddr
)
528 u32 ipv6_hash
= jhash(&ipv6_sockaddr
->sin6_addr
, sizeof(struct in6_addr
), 0);
529 u32 hash
= jhash_2words(ipv6_hash
, (__force u32
) ipv6_sockaddr
->sin6_port
, 0);
533 static u32
iwpm_ipv4_jhash(struct sockaddr_in
*ipv4_sockaddr
)
535 u32 ipv4_hash
= jhash(&ipv4_sockaddr
->sin_addr
, sizeof(struct in_addr
), 0);
536 u32 hash
= jhash_2words(ipv4_hash
, (__force u32
) ipv4_sockaddr
->sin_port
, 0);
540 static int get_hash_bucket(struct sockaddr_storage
*a_sockaddr
,
541 struct sockaddr_storage
*b_sockaddr
, u32
*hash
)
545 if (a_sockaddr
->ss_family
== AF_INET
) {
546 a_hash
= iwpm_ipv4_jhash((struct sockaddr_in
*) a_sockaddr
);
547 b_hash
= iwpm_ipv4_jhash((struct sockaddr_in
*) b_sockaddr
);
549 } else if (a_sockaddr
->ss_family
== AF_INET6
) {
550 a_hash
= iwpm_ipv6_jhash((struct sockaddr_in6
*) a_sockaddr
);
551 b_hash
= iwpm_ipv6_jhash((struct sockaddr_in6
*) b_sockaddr
);
553 pr_err("%s: Invalid sockaddr family\n", __func__
);
557 if (a_hash
== b_hash
) /* if port mapper isn't available */
560 *hash
= jhash_2words(a_hash
, b_hash
, 0);
564 static struct hlist_head
*get_mapinfo_hash_bucket(struct sockaddr_storage
565 *local_sockaddr
, struct sockaddr_storage
571 ret
= get_hash_bucket(local_sockaddr
, mapped_sockaddr
, &hash
);
574 return &iwpm_hash_bucket
[hash
& IWPM_MAPINFO_HASH_MASK
];
577 static struct hlist_head
*get_reminfo_hash_bucket(struct sockaddr_storage
578 *mapped_loc_sockaddr
, struct sockaddr_storage
579 *mapped_rem_sockaddr
)
584 ret
= get_hash_bucket(mapped_loc_sockaddr
, mapped_rem_sockaddr
, &hash
);
587 return &iwpm_reminfo_bucket
[hash
& IWPM_REMINFO_HASH_MASK
];
590 static int send_mapinfo_num(u32 mapping_num
, u8 nl_client
, int iwpm_pid
)
592 struct sk_buff
*skb
= NULL
;
593 struct nlmsghdr
*nlh
;
595 const char *err_str
= "";
598 skb
= iwpm_create_nlmsg(RDMA_NL_IWPM_MAPINFO_NUM
, &nlh
, nl_client
);
600 err_str
= "Unable to create a nlmsg";
601 goto mapinfo_num_error
;
603 nlh
->nlmsg_seq
= iwpm_get_nlmsg_seq();
605 err_str
= "Unable to put attribute of mapinfo number nlmsg";
606 ret
= ibnl_put_attr(skb
, nlh
, sizeof(u32
), &msg_seq
, IWPM_NLA_MAPINFO_SEQ
);
608 goto mapinfo_num_error
;
609 ret
= ibnl_put_attr(skb
, nlh
, sizeof(u32
),
610 &mapping_num
, IWPM_NLA_MAPINFO_SEND_NUM
);
612 goto mapinfo_num_error
;
613 ret
= ibnl_unicast(skb
, nlh
, iwpm_pid
);
616 err_str
= "Unable to send a nlmsg";
617 goto mapinfo_num_error
;
619 pr_debug("%s: Sent mapping number = %d\n", __func__
, mapping_num
);
622 pr_info("%s: %s\n", __func__
, err_str
);
628 static int send_nlmsg_done(struct sk_buff
*skb
, u8 nl_client
, int iwpm_pid
)
630 struct nlmsghdr
*nlh
= NULL
;
635 if (!(ibnl_put_msg(skb
, &nlh
, 0, 0, nl_client
,
636 RDMA_NL_IWPM_MAPINFO
, NLM_F_MULTI
))) {
637 pr_warn("%s Unable to put NLMSG_DONE\n", __func__
);
641 nlh
->nlmsg_type
= NLMSG_DONE
;
642 ret
= ibnl_unicast(skb
, (struct nlmsghdr
*)skb
->data
, iwpm_pid
);
644 pr_warn("%s Unable to send a nlmsg\n", __func__
);
648 int iwpm_send_mapinfo(u8 nl_client
, int iwpm_pid
)
650 struct iwpm_mapping_info
*map_info
;
651 struct sk_buff
*skb
= NULL
;
652 struct nlmsghdr
*nlh
;
653 int skb_num
= 0, mapping_num
= 0;
654 int i
= 0, nlmsg_bytes
= 0;
656 const char *err_str
= "";
659 skb
= dev_alloc_skb(NLMSG_GOODSIZE
);
662 err_str
= "Unable to allocate skb";
663 goto send_mapping_info_exit
;
666 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
667 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
668 hlist_for_each_entry(map_info
, &iwpm_hash_bucket
[i
],
670 if (map_info
->nl_client
!= nl_client
)
673 if (!(ibnl_put_msg(skb
, &nlh
, 0, 0, nl_client
,
674 RDMA_NL_IWPM_MAPINFO
, NLM_F_MULTI
))) {
676 err_str
= "Unable to put the nlmsg header";
677 goto send_mapping_info_unlock
;
679 err_str
= "Unable to put attribute of the nlmsg";
680 ret
= ibnl_put_attr(skb
, nlh
,
681 sizeof(struct sockaddr_storage
),
682 &map_info
->local_sockaddr
,
683 IWPM_NLA_MAPINFO_LOCAL_ADDR
);
685 goto send_mapping_info_unlock
;
687 ret
= ibnl_put_attr(skb
, nlh
,
688 sizeof(struct sockaddr_storage
),
689 &map_info
->mapped_sockaddr
,
690 IWPM_NLA_MAPINFO_MAPPED_ADDR
);
692 goto send_mapping_info_unlock
;
694 iwpm_print_sockaddr(&map_info
->local_sockaddr
,
695 "send_mapping_info: Local sockaddr:");
696 iwpm_print_sockaddr(&map_info
->mapped_sockaddr
,
697 "send_mapping_info: Mapped local sockaddr:");
699 nlmsg_bytes
+= nlh
->nlmsg_len
;
701 /* check if all mappings can fit in one skb */
702 if (NLMSG_GOODSIZE
- nlmsg_bytes
< nlh
->nlmsg_len
* 2) {
703 /* and leave room for NLMSG_DONE */
706 spin_unlock_irqrestore(&iwpm_mapinfo_lock
,
709 ret
= send_nlmsg_done(skb
, nl_client
, iwpm_pid
);
712 err_str
= "Unable to send map info";
713 goto send_mapping_info_exit
;
715 if (skb_num
== IWPM_MAPINFO_SKB_COUNT
) {
717 err_str
= "Insufficient skbs for map info";
718 goto send_mapping_info_exit
;
720 skb
= dev_alloc_skb(NLMSG_GOODSIZE
);
723 err_str
= "Unable to allocate skb";
724 goto send_mapping_info_exit
;
726 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
730 send_mapping_info_unlock
:
731 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
732 send_mapping_info_exit
:
734 pr_warn("%s: %s (ret = %d)\n", __func__
, err_str
, ret
);
739 send_nlmsg_done(skb
, nl_client
, iwpm_pid
);
740 return send_mapinfo_num(mapping_num
, nl_client
, iwpm_pid
);
743 int iwpm_mapinfo_available(void)
746 int full_bucket
= 0, i
= 0;
748 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
749 if (iwpm_hash_bucket
) {
750 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
751 if (!hlist_empty(&iwpm_hash_bucket
[i
])) {
757 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);