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)
41 static LIST_HEAD(iwpm_nlmsg_req_list
);
42 static DEFINE_SPINLOCK(iwpm_nlmsg_req_lock
);
44 static struct hlist_head
*iwpm_hash_bucket
;
45 static DEFINE_SPINLOCK(iwpm_mapinfo_lock
);
47 static struct hlist_head
*iwpm_reminfo_bucket
;
48 static DEFINE_SPINLOCK(iwpm_reminfo_lock
);
50 static DEFINE_MUTEX(iwpm_admin_lock
);
51 static struct iwpm_admin_data iwpm_admin
;
53 int iwpm_init(u8 nl_client
)
56 if (iwpm_valid_client(nl_client
))
58 mutex_lock(&iwpm_admin_lock
);
59 if (atomic_read(&iwpm_admin
.refcount
) == 0) {
60 iwpm_hash_bucket
= kzalloc(IWPM_MAPINFO_HASH_SIZE
*
61 sizeof(struct hlist_head
), GFP_KERNEL
);
62 if (!iwpm_hash_bucket
) {
64 pr_err("%s Unable to create mapinfo hash table\n", __func__
);
67 iwpm_reminfo_bucket
= kzalloc(IWPM_REMINFO_HASH_SIZE
*
68 sizeof(struct hlist_head
), GFP_KERNEL
);
69 if (!iwpm_reminfo_bucket
) {
70 kfree(iwpm_hash_bucket
);
72 pr_err("%s Unable to create reminfo hash table\n", __func__
);
76 atomic_inc(&iwpm_admin
.refcount
);
78 mutex_unlock(&iwpm_admin_lock
);
80 iwpm_set_valid(nl_client
, 1);
81 iwpm_set_registration(nl_client
, IWPM_REG_UNDEF
);
82 pr_debug("%s: Mapinfo and reminfo tables are created\n",
87 EXPORT_SYMBOL(iwpm_init
);
89 static void free_hash_bucket(void);
90 static void free_reminfo_bucket(void);
92 int iwpm_exit(u8 nl_client
)
95 if (!iwpm_valid_client(nl_client
))
97 mutex_lock(&iwpm_admin_lock
);
98 if (atomic_read(&iwpm_admin
.refcount
) == 0) {
99 mutex_unlock(&iwpm_admin_lock
);
100 pr_err("%s Incorrect usage - negative refcount\n", __func__
);
103 if (atomic_dec_and_test(&iwpm_admin
.refcount
)) {
105 free_reminfo_bucket();
106 pr_debug("%s: Resources are destroyed\n", __func__
);
108 mutex_unlock(&iwpm_admin_lock
);
109 iwpm_set_valid(nl_client
, 0);
110 iwpm_set_registration(nl_client
, IWPM_REG_UNDEF
);
113 EXPORT_SYMBOL(iwpm_exit
);
115 static struct hlist_head
*get_mapinfo_hash_bucket(struct sockaddr_storage
*,
116 struct sockaddr_storage
*);
118 int iwpm_create_mapinfo(struct sockaddr_storage
*local_sockaddr
,
119 struct sockaddr_storage
*mapped_sockaddr
,
122 struct hlist_head
*hash_bucket_head
;
123 struct iwpm_mapping_info
*map_info
;
127 if (!iwpm_valid_client(nl_client
))
129 map_info
= kzalloc(sizeof(struct iwpm_mapping_info
), GFP_KERNEL
);
131 pr_err("%s: Unable to allocate a mapping info\n", __func__
);
134 memcpy(&map_info
->local_sockaddr
, local_sockaddr
,
135 sizeof(struct sockaddr_storage
));
136 memcpy(&map_info
->mapped_sockaddr
, mapped_sockaddr
,
137 sizeof(struct sockaddr_storage
));
138 map_info
->nl_client
= nl_client
;
140 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
141 if (iwpm_hash_bucket
) {
142 hash_bucket_head
= get_mapinfo_hash_bucket(
143 &map_info
->local_sockaddr
,
144 &map_info
->mapped_sockaddr
);
145 if (hash_bucket_head
) {
146 hlist_add_head(&map_info
->hlist_node
, hash_bucket_head
);
150 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
153 EXPORT_SYMBOL(iwpm_create_mapinfo
);
155 int iwpm_remove_mapinfo(struct sockaddr_storage
*local_sockaddr
,
156 struct sockaddr_storage
*mapped_local_addr
)
158 struct hlist_node
*tmp_hlist_node
;
159 struct hlist_head
*hash_bucket_head
;
160 struct iwpm_mapping_info
*map_info
= NULL
;
164 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
165 if (iwpm_hash_bucket
) {
166 hash_bucket_head
= get_mapinfo_hash_bucket(
169 if (!hash_bucket_head
)
170 goto remove_mapinfo_exit
;
172 hlist_for_each_entry_safe(map_info
, tmp_hlist_node
,
173 hash_bucket_head
, hlist_node
) {
175 if (!iwpm_compare_sockaddr(&map_info
->mapped_sockaddr
,
176 mapped_local_addr
)) {
178 hlist_del_init(&map_info
->hlist_node
);
186 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
189 EXPORT_SYMBOL(iwpm_remove_mapinfo
);
191 static void free_hash_bucket(void)
193 struct hlist_node
*tmp_hlist_node
;
194 struct iwpm_mapping_info
*map_info
;
198 /* remove all the mapinfo data from the list */
199 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
200 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
201 hlist_for_each_entry_safe(map_info
, tmp_hlist_node
,
202 &iwpm_hash_bucket
[i
], hlist_node
) {
204 hlist_del_init(&map_info
->hlist_node
);
208 /* free the hash list */
209 kfree(iwpm_hash_bucket
);
210 iwpm_hash_bucket
= NULL
;
211 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
214 static void free_reminfo_bucket(void)
216 struct hlist_node
*tmp_hlist_node
;
217 struct iwpm_remote_info
*rem_info
;
221 /* remove all the remote info from the list */
222 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
223 for (i
= 0; i
< IWPM_REMINFO_HASH_SIZE
; i
++) {
224 hlist_for_each_entry_safe(rem_info
, tmp_hlist_node
,
225 &iwpm_reminfo_bucket
[i
], hlist_node
) {
227 hlist_del_init(&rem_info
->hlist_node
);
231 /* free the hash list */
232 kfree(iwpm_reminfo_bucket
);
233 iwpm_reminfo_bucket
= NULL
;
234 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
237 static struct hlist_head
*get_reminfo_hash_bucket(struct sockaddr_storage
*,
238 struct sockaddr_storage
*);
240 void iwpm_add_remote_info(struct iwpm_remote_info
*rem_info
)
242 struct hlist_head
*hash_bucket_head
;
245 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
246 if (iwpm_reminfo_bucket
) {
247 hash_bucket_head
= get_reminfo_hash_bucket(
248 &rem_info
->mapped_loc_sockaddr
,
249 &rem_info
->mapped_rem_sockaddr
);
250 if (hash_bucket_head
)
251 hlist_add_head(&rem_info
->hlist_node
, hash_bucket_head
);
253 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
256 int iwpm_get_remote_info(struct sockaddr_storage
*mapped_loc_addr
,
257 struct sockaddr_storage
*mapped_rem_addr
,
258 struct sockaddr_storage
*remote_addr
,
261 struct hlist_node
*tmp_hlist_node
;
262 struct hlist_head
*hash_bucket_head
;
263 struct iwpm_remote_info
*rem_info
= NULL
;
267 if (!iwpm_valid_client(nl_client
)) {
268 pr_info("%s: Invalid client = %d\n", __func__
, nl_client
);
271 spin_lock_irqsave(&iwpm_reminfo_lock
, flags
);
272 if (iwpm_reminfo_bucket
) {
273 hash_bucket_head
= get_reminfo_hash_bucket(
276 if (!hash_bucket_head
)
277 goto get_remote_info_exit
;
278 hlist_for_each_entry_safe(rem_info
, tmp_hlist_node
,
279 hash_bucket_head
, hlist_node
) {
281 if (!iwpm_compare_sockaddr(&rem_info
->mapped_loc_sockaddr
,
283 !iwpm_compare_sockaddr(&rem_info
->mapped_rem_sockaddr
,
286 memcpy(remote_addr
, &rem_info
->remote_sockaddr
,
287 sizeof(struct sockaddr_storage
));
288 iwpm_print_sockaddr(remote_addr
,
289 "get_remote_info: Remote sockaddr:");
291 hlist_del_init(&rem_info
->hlist_node
);
298 get_remote_info_exit
:
299 spin_unlock_irqrestore(&iwpm_reminfo_lock
, flags
);
302 EXPORT_SYMBOL(iwpm_get_remote_info
);
304 struct iwpm_nlmsg_request
*iwpm_get_nlmsg_request(__u32 nlmsg_seq
,
305 u8 nl_client
, gfp_t gfp
)
307 struct iwpm_nlmsg_request
*nlmsg_request
= NULL
;
310 nlmsg_request
= kzalloc(sizeof(struct iwpm_nlmsg_request
), gfp
);
311 if (!nlmsg_request
) {
312 pr_err("%s Unable to allocate a nlmsg_request\n", __func__
);
315 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
316 list_add_tail(&nlmsg_request
->inprocess_list
, &iwpm_nlmsg_req_list
);
317 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
319 kref_init(&nlmsg_request
->kref
);
320 kref_get(&nlmsg_request
->kref
);
321 nlmsg_request
->nlmsg_seq
= nlmsg_seq
;
322 nlmsg_request
->nl_client
= nl_client
;
323 nlmsg_request
->request_done
= 0;
324 nlmsg_request
->err_code
= 0;
325 sema_init(&nlmsg_request
->sem
, 1);
326 down(&nlmsg_request
->sem
);
327 return nlmsg_request
;
330 void iwpm_free_nlmsg_request(struct kref
*kref
)
332 struct iwpm_nlmsg_request
*nlmsg_request
;
335 nlmsg_request
= container_of(kref
, struct iwpm_nlmsg_request
, kref
);
337 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
338 list_del_init(&nlmsg_request
->inprocess_list
);
339 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
341 if (!nlmsg_request
->request_done
)
342 pr_debug("%s Freeing incomplete nlmsg request (seq = %u).\n",
343 __func__
, nlmsg_request
->nlmsg_seq
);
344 kfree(nlmsg_request
);
347 struct iwpm_nlmsg_request
*iwpm_find_nlmsg_request(__u32 echo_seq
)
349 struct iwpm_nlmsg_request
*nlmsg_request
;
350 struct iwpm_nlmsg_request
*found_request
= NULL
;
353 spin_lock_irqsave(&iwpm_nlmsg_req_lock
, flags
);
354 list_for_each_entry(nlmsg_request
, &iwpm_nlmsg_req_list
,
356 if (nlmsg_request
->nlmsg_seq
== echo_seq
) {
357 found_request
= nlmsg_request
;
358 kref_get(&nlmsg_request
->kref
);
362 spin_unlock_irqrestore(&iwpm_nlmsg_req_lock
, flags
);
363 return found_request
;
366 int iwpm_wait_complete_req(struct iwpm_nlmsg_request
*nlmsg_request
)
370 ret
= down_timeout(&nlmsg_request
->sem
, IWPM_NL_TIMEOUT
);
373 pr_info("%s: Timeout %d sec for netlink request (seq = %u)\n",
374 __func__
, (IWPM_NL_TIMEOUT
/HZ
), nlmsg_request
->nlmsg_seq
);
376 ret
= nlmsg_request
->err_code
;
378 kref_put(&nlmsg_request
->kref
, iwpm_free_nlmsg_request
);
382 int iwpm_get_nlmsg_seq(void)
384 return atomic_inc_return(&iwpm_admin
.nlmsg_seq
);
387 int iwpm_valid_client(u8 nl_client
)
389 if (nl_client
>= RDMA_NL_NUM_CLIENTS
)
391 return iwpm_admin
.client_list
[nl_client
];
394 void iwpm_set_valid(u8 nl_client
, int valid
)
396 if (nl_client
>= RDMA_NL_NUM_CLIENTS
)
398 iwpm_admin
.client_list
[nl_client
] = valid
;
402 u32
iwpm_get_registration(u8 nl_client
)
404 return iwpm_admin
.reg_list
[nl_client
];
408 void iwpm_set_registration(u8 nl_client
, u32 reg
)
410 iwpm_admin
.reg_list
[nl_client
] = reg
;
414 u32
iwpm_check_registration(u8 nl_client
, u32 reg
)
416 return (iwpm_get_registration(nl_client
) & reg
);
419 int iwpm_compare_sockaddr(struct sockaddr_storage
*a_sockaddr
,
420 struct sockaddr_storage
*b_sockaddr
)
422 if (a_sockaddr
->ss_family
!= b_sockaddr
->ss_family
)
424 if (a_sockaddr
->ss_family
== AF_INET
) {
425 struct sockaddr_in
*a4_sockaddr
=
426 (struct sockaddr_in
*)a_sockaddr
;
427 struct sockaddr_in
*b4_sockaddr
=
428 (struct sockaddr_in
*)b_sockaddr
;
429 if (!memcmp(&a4_sockaddr
->sin_addr
,
430 &b4_sockaddr
->sin_addr
, sizeof(struct in_addr
))
431 && a4_sockaddr
->sin_port
== b4_sockaddr
->sin_port
)
434 } else if (a_sockaddr
->ss_family
== AF_INET6
) {
435 struct sockaddr_in6
*a6_sockaddr
=
436 (struct sockaddr_in6
*)a_sockaddr
;
437 struct sockaddr_in6
*b6_sockaddr
=
438 (struct sockaddr_in6
*)b_sockaddr
;
439 if (!memcmp(&a6_sockaddr
->sin6_addr
,
440 &b6_sockaddr
->sin6_addr
, sizeof(struct in6_addr
))
441 && a6_sockaddr
->sin6_port
== b6_sockaddr
->sin6_port
)
445 pr_err("%s: Invalid sockaddr family\n", __func__
);
450 struct sk_buff
*iwpm_create_nlmsg(u32 nl_op
, struct nlmsghdr
**nlh
,
453 struct sk_buff
*skb
= NULL
;
455 skb
= dev_alloc_skb(NLMSG_GOODSIZE
);
457 pr_err("%s Unable to allocate skb\n", __func__
);
458 goto create_nlmsg_exit
;
460 if (!(ibnl_put_msg(skb
, nlh
, 0, 0, nl_client
, nl_op
,
462 pr_warn("%s: Unable to put the nlmsg header\n", __func__
);
470 int iwpm_parse_nlmsg(struct netlink_callback
*cb
, int policy_max
,
471 const struct nla_policy
*nlmsg_policy
,
472 struct nlattr
*nltb
[], const char *msg_type
)
476 const char *err_str
= "";
478 ret
= nlmsg_validate(cb
->nlh
, nlh_len
, policy_max
-1, nlmsg_policy
);
480 err_str
= "Invalid attribute";
481 goto parse_nlmsg_error
;
483 ret
= nlmsg_parse(cb
->nlh
, nlh_len
, nltb
, policy_max
-1, nlmsg_policy
);
485 err_str
= "Unable to parse the nlmsg";
486 goto parse_nlmsg_error
;
488 ret
= iwpm_validate_nlmsg_attr(nltb
, policy_max
);
490 err_str
= "Invalid NULL attribute";
491 goto parse_nlmsg_error
;
495 pr_warn("%s: %s (msg type %s ret = %d)\n",
496 __func__
, err_str
, msg_type
, ret
);
500 void iwpm_print_sockaddr(struct sockaddr_storage
*sockaddr
, char *msg
)
502 struct sockaddr_in6
*sockaddr_v6
;
503 struct sockaddr_in
*sockaddr_v4
;
505 switch (sockaddr
->ss_family
) {
507 sockaddr_v4
= (struct sockaddr_in
*)sockaddr
;
508 pr_debug("%s IPV4 %pI4: %u(0x%04X)\n",
509 msg
, &sockaddr_v4
->sin_addr
,
510 ntohs(sockaddr_v4
->sin_port
),
511 ntohs(sockaddr_v4
->sin_port
));
514 sockaddr_v6
= (struct sockaddr_in6
*)sockaddr
;
515 pr_debug("%s IPV6 %pI6: %u(0x%04X)\n",
516 msg
, &sockaddr_v6
->sin6_addr
,
517 ntohs(sockaddr_v6
->sin6_port
),
518 ntohs(sockaddr_v6
->sin6_port
));
525 static u32
iwpm_ipv6_jhash(struct sockaddr_in6
*ipv6_sockaddr
)
527 u32 ipv6_hash
= jhash(&ipv6_sockaddr
->sin6_addr
, sizeof(struct in6_addr
), 0);
528 u32 hash
= jhash_2words(ipv6_hash
, (__force u32
) ipv6_sockaddr
->sin6_port
, 0);
532 static u32
iwpm_ipv4_jhash(struct sockaddr_in
*ipv4_sockaddr
)
534 u32 ipv4_hash
= jhash(&ipv4_sockaddr
->sin_addr
, sizeof(struct in_addr
), 0);
535 u32 hash
= jhash_2words(ipv4_hash
, (__force u32
) ipv4_sockaddr
->sin_port
, 0);
539 static int get_hash_bucket(struct sockaddr_storage
*a_sockaddr
,
540 struct sockaddr_storage
*b_sockaddr
, u32
*hash
)
544 if (a_sockaddr
->ss_family
== AF_INET
) {
545 a_hash
= iwpm_ipv4_jhash((struct sockaddr_in
*) a_sockaddr
);
546 b_hash
= iwpm_ipv4_jhash((struct sockaddr_in
*) b_sockaddr
);
548 } else if (a_sockaddr
->ss_family
== AF_INET6
) {
549 a_hash
= iwpm_ipv6_jhash((struct sockaddr_in6
*) a_sockaddr
);
550 b_hash
= iwpm_ipv6_jhash((struct sockaddr_in6
*) b_sockaddr
);
552 pr_err("%s: Invalid sockaddr family\n", __func__
);
556 if (a_hash
== b_hash
) /* if port mapper isn't available */
559 *hash
= jhash_2words(a_hash
, b_hash
, 0);
563 static struct hlist_head
*get_mapinfo_hash_bucket(struct sockaddr_storage
564 *local_sockaddr
, struct sockaddr_storage
570 ret
= get_hash_bucket(local_sockaddr
, mapped_sockaddr
, &hash
);
573 return &iwpm_hash_bucket
[hash
& IWPM_MAPINFO_HASH_MASK
];
576 static struct hlist_head
*get_reminfo_hash_bucket(struct sockaddr_storage
577 *mapped_loc_sockaddr
, struct sockaddr_storage
578 *mapped_rem_sockaddr
)
583 ret
= get_hash_bucket(mapped_loc_sockaddr
, mapped_rem_sockaddr
, &hash
);
586 return &iwpm_reminfo_bucket
[hash
& IWPM_REMINFO_HASH_MASK
];
589 static int send_mapinfo_num(u32 mapping_num
, u8 nl_client
, int iwpm_pid
)
591 struct sk_buff
*skb
= NULL
;
592 struct nlmsghdr
*nlh
;
594 const char *err_str
= "";
597 skb
= iwpm_create_nlmsg(RDMA_NL_IWPM_MAPINFO_NUM
, &nlh
, nl_client
);
599 err_str
= "Unable to create a nlmsg";
600 goto mapinfo_num_error
;
602 nlh
->nlmsg_seq
= iwpm_get_nlmsg_seq();
604 err_str
= "Unable to put attribute of mapinfo number nlmsg";
605 ret
= ibnl_put_attr(skb
, nlh
, sizeof(u32
), &msg_seq
, IWPM_NLA_MAPINFO_SEQ
);
607 goto mapinfo_num_error
;
608 ret
= ibnl_put_attr(skb
, nlh
, sizeof(u32
),
609 &mapping_num
, IWPM_NLA_MAPINFO_SEND_NUM
);
611 goto mapinfo_num_error
;
612 ret
= ibnl_unicast(skb
, nlh
, iwpm_pid
);
615 err_str
= "Unable to send a nlmsg";
616 goto mapinfo_num_error
;
618 pr_debug("%s: Sent mapping number = %d\n", __func__
, mapping_num
);
621 pr_info("%s: %s\n", __func__
, err_str
);
627 static int send_nlmsg_done(struct sk_buff
*skb
, u8 nl_client
, int iwpm_pid
)
629 struct nlmsghdr
*nlh
= NULL
;
634 if (!(ibnl_put_msg(skb
, &nlh
, 0, 0, nl_client
,
635 RDMA_NL_IWPM_MAPINFO
, NLM_F_MULTI
))) {
636 pr_warn("%s Unable to put NLMSG_DONE\n", __func__
);
639 nlh
->nlmsg_type
= NLMSG_DONE
;
640 ret
= ibnl_unicast(skb
, (struct nlmsghdr
*)skb
->data
, iwpm_pid
);
642 pr_warn("%s Unable to send a nlmsg\n", __func__
);
646 int iwpm_send_mapinfo(u8 nl_client
, int iwpm_pid
)
648 struct iwpm_mapping_info
*map_info
;
649 struct sk_buff
*skb
= NULL
;
650 struct nlmsghdr
*nlh
;
651 int skb_num
= 0, mapping_num
= 0;
652 int i
= 0, nlmsg_bytes
= 0;
654 const char *err_str
= "";
657 skb
= dev_alloc_skb(NLMSG_GOODSIZE
);
660 err_str
= "Unable to allocate skb";
661 goto send_mapping_info_exit
;
664 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
665 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
666 hlist_for_each_entry(map_info
, &iwpm_hash_bucket
[i
],
668 if (map_info
->nl_client
!= nl_client
)
671 if (!(ibnl_put_msg(skb
, &nlh
, 0, 0, nl_client
,
672 RDMA_NL_IWPM_MAPINFO
, NLM_F_MULTI
))) {
674 err_str
= "Unable to put the nlmsg header";
675 goto send_mapping_info_unlock
;
677 err_str
= "Unable to put attribute of the nlmsg";
678 ret
= ibnl_put_attr(skb
, nlh
,
679 sizeof(struct sockaddr_storage
),
680 &map_info
->local_sockaddr
,
681 IWPM_NLA_MAPINFO_LOCAL_ADDR
);
683 goto send_mapping_info_unlock
;
685 ret
= ibnl_put_attr(skb
, nlh
,
686 sizeof(struct sockaddr_storage
),
687 &map_info
->mapped_sockaddr
,
688 IWPM_NLA_MAPINFO_MAPPED_ADDR
);
690 goto send_mapping_info_unlock
;
692 iwpm_print_sockaddr(&map_info
->local_sockaddr
,
693 "send_mapping_info: Local sockaddr:");
694 iwpm_print_sockaddr(&map_info
->mapped_sockaddr
,
695 "send_mapping_info: Mapped local sockaddr:");
697 nlmsg_bytes
+= nlh
->nlmsg_len
;
699 /* check if all mappings can fit in one skb */
700 if (NLMSG_GOODSIZE
- nlmsg_bytes
< nlh
->nlmsg_len
* 2) {
701 /* and leave room for NLMSG_DONE */
704 spin_unlock_irqrestore(&iwpm_mapinfo_lock
,
707 ret
= send_nlmsg_done(skb
, nl_client
, iwpm_pid
);
710 err_str
= "Unable to send map info";
711 goto send_mapping_info_exit
;
713 if (skb_num
== IWPM_MAPINFO_SKB_COUNT
) {
715 err_str
= "Insufficient skbs for map info";
716 goto send_mapping_info_exit
;
718 skb
= dev_alloc_skb(NLMSG_GOODSIZE
);
721 err_str
= "Unable to allocate skb";
722 goto send_mapping_info_exit
;
724 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
728 send_mapping_info_unlock
:
729 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);
730 send_mapping_info_exit
:
732 pr_warn("%s: %s (ret = %d)\n", __func__
, err_str
, ret
);
737 send_nlmsg_done(skb
, nl_client
, iwpm_pid
);
738 return send_mapinfo_num(mapping_num
, nl_client
, iwpm_pid
);
741 int iwpm_mapinfo_available(void)
744 int full_bucket
= 0, i
= 0;
746 spin_lock_irqsave(&iwpm_mapinfo_lock
, flags
);
747 if (iwpm_hash_bucket
) {
748 for (i
= 0; i
< IWPM_MAPINFO_HASH_SIZE
; i
++) {
749 if (!hlist_empty(&iwpm_hash_bucket
[i
])) {
755 spin_unlock_irqrestore(&iwpm_mapinfo_lock
, flags
);