/* * Copyright (c) 2014 Chelsio, Inc. All rights reserved. * Copyright (c) 2014 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.
*/
/** * iwpm_init - Allocate resources for the iwarp port mapper * @nl_client: The index of the netlink client * * Should be called when network interface goes up.
*/ int iwpm_init(u8 nl_client)
{
iwpm_hash_bucket = kcalloc(IWPM_MAPINFO_HASH_SIZE, sizeof(struct hlist_head), GFP_KERNEL); if (!iwpm_hash_bucket) return -ENOMEM;
/** * iwpm_exit - Deallocate resources for the iwarp port mapper * @nl_client: The index of the netlink client * * Should be called when network interface goes down.
*/ int iwpm_exit(u8 nl_client)
{
free_hash_bucket();
free_reminfo_bucket();
pr_debug("%s: Resources are destroyed\n", __func__);
iwpm_set_registration(nl_client, IWPM_REG_UNDEF); return 0;
}
/** * iwpm_create_mapinfo - Store local and mapped IPv4/IPv6 address * info in a hash table * @local_sockaddr: Local ip/tcp address * @mapped_sockaddr: Mapped local ip/tcp address * @nl_client: The index of the netlink client * @map_flags: IWPM mapping flags
*/ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr, struct sockaddr_storage *mapped_sockaddr,
u8 nl_client, u32 map_flags)
{ struct hlist_head *hash_bucket_head = NULL; struct iwpm_mapping_info *map_info; unsignedlong flags; int ret = -EINVAL;
map_info = kzalloc(sizeof(struct iwpm_mapping_info), GFP_KERNEL); if (!map_info) return -ENOMEM;
spin_lock_irqsave(&iwpm_mapinfo_lock, flags); if (iwpm_hash_bucket) {
hash_bucket_head = get_mapinfo_hash_bucket(
&map_info->local_sockaddr,
&map_info->mapped_sockaddr); if (hash_bucket_head) {
hlist_add_head(&map_info->hlist_node, hash_bucket_head);
ret = 0;
}
}
spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
if (!hash_bucket_head)
kfree(map_info); return ret;
}
/** * iwpm_remove_mapinfo - Remove local and mapped IPv4/IPv6 address * info from the hash table * @local_sockaddr: Local ip/tcp address * @mapped_local_addr: Mapped local ip/tcp address * * Returns err code if mapping info is not found in the hash table, * otherwise returns 0
*/ int iwpm_remove_mapinfo(struct sockaddr_storage *local_sockaddr, struct sockaddr_storage *mapped_local_addr)
{ struct hlist_node *tmp_hlist_node; struct hlist_head *hash_bucket_head; struct iwpm_mapping_info *map_info = NULL; unsignedlong flags; int ret = -EINVAL;
spin_lock_irqsave(&iwpm_mapinfo_lock, flags); if (iwpm_hash_bucket) {
hash_bucket_head = get_mapinfo_hash_bucket(
local_sockaddr,
mapped_local_addr); if (!hash_bucket_head) goto remove_mapinfo_exit;
/* remove all the mapinfo data from the list */
spin_lock_irqsave(&iwpm_mapinfo_lock, flags); for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) {
hlist_for_each_entry_safe(map_info, tmp_hlist_node,
&iwpm_hash_bucket[i], hlist_node) {
hlist_del_init(&map_info->hlist_node);
kfree(map_info);
}
} /* free the hash list */
kfree(iwpm_hash_bucket);
iwpm_hash_bucket = NULL;
spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
}
/* remove all the remote info from the list */
spin_lock_irqsave(&iwpm_reminfo_lock, flags); for (i = 0; i < IWPM_REMINFO_HASH_SIZE; i++) {
hlist_for_each_entry_safe(rem_info, tmp_hlist_node,
&iwpm_reminfo_bucket[i], hlist_node) {
hlist_del_init(&rem_info->hlist_node);
kfree(rem_info);
}
} /* free the hash list */
kfree(iwpm_reminfo_bucket);
iwpm_reminfo_bucket = NULL;
spin_unlock_irqrestore(&iwpm_reminfo_lock, flags);
}
spin_lock_irqsave(&iwpm_reminfo_lock, flags); if (iwpm_reminfo_bucket) {
hash_bucket_head = get_reminfo_hash_bucket(
&rem_info->mapped_loc_sockaddr,
&rem_info->mapped_rem_sockaddr); if (hash_bucket_head)
hlist_add_head(&rem_info->hlist_node, hash_bucket_head);
}
spin_unlock_irqrestore(&iwpm_reminfo_lock, flags);
}
/** * iwpm_get_remote_info - Get the remote connecting peer address info * * @mapped_loc_addr: Mapped local address of the listening peer * @mapped_rem_addr: Mapped remote address of the connecting peer * @remote_addr: To store the remote address of the connecting peer * @nl_client: The index of the netlink client * * The remote address info is retrieved and provided to the client in * the remote_addr. After that it is removed from the hash table
*/ int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr, struct sockaddr_storage *mapped_rem_addr, struct sockaddr_storage *remote_addr,
u8 nl_client)
{ struct hlist_node *tmp_hlist_node; struct hlist_head *hash_bucket_head; struct iwpm_remote_info *rem_info = NULL; unsignedlong flags; int ret = -EINVAL;
spin_lock_irqsave(&iwpm_reminfo_lock, flags); if (iwpm_reminfo_bucket) {
hash_bucket_head = get_reminfo_hash_bucket(
mapped_loc_addr,
mapped_rem_addr); if (!hash_bucket_head) goto get_remote_info_exit;
hlist_for_each_entry_safe(rem_info, tmp_hlist_node,
hash_bucket_head, hlist_node) {
if (!iwpm_compare_sockaddr(&rem_info->mapped_loc_sockaddr,
mapped_loc_addr) &&
!iwpm_compare_sockaddr(&rem_info->mapped_rem_sockaddr,
mapped_rem_addr)) {
ret = get_hash_bucket(mapped_loc_sockaddr, mapped_rem_sockaddr, &hash); if (ret) return NULL; return &iwpm_reminfo_bucket[hash & IWPM_REMINFO_HASH_MASK];
}
staticint send_mapinfo_num(u32 mapping_num, u8 nl_client, int iwpm_pid)
{ struct sk_buff *skb = NULL; struct nlmsghdr *nlh;
u32 msg_seq; constchar *err_str = ""; int ret = -EINVAL;
skb = iwpm_create_nlmsg(RDMA_NL_IWPM_MAPINFO_NUM, &nlh, nl_client); if (!skb) {
err_str = "Unable to create a nlmsg"; goto mapinfo_num_error;
}
nlh->nlmsg_seq = iwpm_get_nlmsg_seq();
msg_seq = 0;
err_str = "Unable to put attribute of mapinfo number nlmsg";
ret = ibnl_put_attr(skb, nlh, sizeof(u32), &msg_seq, IWPM_NLA_MAPINFO_SEQ); if (ret) goto mapinfo_num_error;
ret = ibnl_put_attr(skb, nlh, sizeof(u32),
&mapping_num, IWPM_NLA_MAPINFO_SEND_NUM); if (ret) goto mapinfo_num_error;
nlmsg_end(skb, nlh);
ret = rdma_nl_unicast(&init_net, skb, iwpm_pid); if (ret) {
skb = NULL;
err_str = "Unable to send a nlmsg"; goto mapinfo_num_error;
}
pr_debug("%s: Sent mapping number = %u\n", __func__, mapping_num); return 0;
mapinfo_num_error:
pr_info("%s: %s\n", __func__, err_str);
dev_kfree_skb(skb); return ret;
}
staticint send_nlmsg_done(struct sk_buff *skb, u8 nl_client, int iwpm_pid)
{ struct nlmsghdr *nlh = NULL; int ret = 0;
if (!skb) return ret; if (!(ibnl_put_msg(skb, &nlh, 0, 0, nl_client,
RDMA_NL_IWPM_MAPINFO, NLM_F_MULTI))) {
pr_warn("%s Unable to put NLMSG_DONE\n", __func__);
dev_kfree_skb(skb); return -ENOMEM;
}
nlh->nlmsg_type = NLMSG_DONE;
ret = rdma_nl_unicast(&init_net, skb, iwpm_pid); if (ret)
pr_warn("%s Unable to send a nlmsg\n", __func__); return ret;
}
int iwpm_send_mapinfo(u8 nl_client, int iwpm_pid)
{ struct iwpm_mapping_info *map_info; struct sk_buff *skb = NULL; struct nlmsghdr *nlh; int skb_num = 0, mapping_num = 0; int i = 0, nlmsg_bytes = 0; unsignedlong flags; constchar *err_str = ""; int ret;
skb = dev_alloc_skb(NLMSG_GOODSIZE); if (!skb) {
ret = -ENOMEM;
err_str = "Unable to allocate skb"; goto send_mapping_info_exit;
}
skb_num++;
spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
ret = -EINVAL; for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) {
hlist_for_each_entry(map_info, &iwpm_hash_bucket[i],
hlist_node) { if (map_info->nl_client != nl_client) continue;
nlh = NULL; if (!(ibnl_put_msg(skb, &nlh, 0, 0, nl_client,
RDMA_NL_IWPM_MAPINFO, NLM_F_MULTI))) {
ret = -ENOMEM;
err_str = "Unable to put the nlmsg header"; goto send_mapping_info_unlock;
}
err_str = "Unable to put attribute of the nlmsg";
ret = ibnl_put_attr(skb, nlh, sizeof(struct sockaddr_storage),
&map_info->local_sockaddr,
IWPM_NLA_MAPINFO_LOCAL_ADDR); if (ret) goto send_mapping_info_unlock;
ret = ibnl_put_attr(skb, nlh, sizeof(struct sockaddr_storage),
&map_info->mapped_sockaddr,
IWPM_NLA_MAPINFO_MAPPED_ADDR); if (ret) goto send_mapping_info_unlock;
if (iwpm_ulib_version > IWPM_UABI_VERSION_MIN) {
ret = ibnl_put_attr(skb, nlh, sizeof(u32),
&map_info->map_flags,
IWPM_NLA_MAPINFO_FLAGS); if (ret) goto send_mapping_info_unlock;
}
nlmsg_end(skb, nlh);
iwpm_print_sockaddr(&map_info->local_sockaddr, "send_mapping_info: Local sockaddr:");
iwpm_print_sockaddr(&map_info->mapped_sockaddr, "send_mapping_info: Mapped local sockaddr:");
mapping_num++;
nlmsg_bytes += nlh->nlmsg_len;
/* check if all mappings can fit in one skb */ if (NLMSG_GOODSIZE - nlmsg_bytes < nlh->nlmsg_len * 2) { /* and leave room for NLMSG_DONE */
nlmsg_bytes = 0;
skb_num++;
spin_unlock_irqrestore(&iwpm_mapinfo_lock,
flags); /* send the skb */
ret = send_nlmsg_done(skb, nl_client, iwpm_pid);
skb = NULL; if (ret) {
err_str = "Unable to send map info"; goto send_mapping_info_exit;
} if (skb_num == IWPM_MAPINFO_SKB_COUNT) {
ret = -ENOMEM;
err_str = "Insufficient skbs for map info"; goto send_mapping_info_exit;
}
skb = dev_alloc_skb(NLMSG_GOODSIZE); if (!skb) {
ret = -ENOMEM;
err_str = "Unable to allocate skb"; goto send_mapping_info_exit;
}
spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
}
}
}
send_mapping_info_unlock:
spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
send_mapping_info_exit: if (ret) {
pr_warn("%s: %s (ret = %d)\n", __func__, err_str, ret);
dev_kfree_skb(skb); return ret;
}
send_nlmsg_done(skb, nl_client, iwpm_pid); return send_mapinfo_num(mapping_num, nl_client, iwpm_pid);
}
int iwpm_mapinfo_available(void)
{ unsignedlong flags; int full_bucket = 0, i = 0;
spin_lock_irqsave(&iwpm_mapinfo_lock, flags); if (iwpm_hash_bucket) { for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) { if (!hlist_empty(&iwpm_hash_bucket[i])) {
full_bucket = 1; break;
}
}
}
spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags); return full_bucket;
}
int iwpm_send_hello(u8 nl_client, int iwpm_pid, u16 abi_version)
{ struct sk_buff *skb = NULL; struct nlmsghdr *nlh; constchar *err_str; int ret = -EINVAL;
skb = iwpm_create_nlmsg(RDMA_NL_IWPM_HELLO, &nlh, nl_client); if (!skb) {
err_str = "Unable to create a nlmsg"; goto hello_num_error;
}
nlh->nlmsg_seq = iwpm_get_nlmsg_seq();
err_str = "Unable to put attribute of abi_version into nlmsg";
ret = ibnl_put_attr(skb, nlh, sizeof(u16), &abi_version,
IWPM_NLA_HELLO_ABI_VERSION); if (ret) goto hello_num_error;
nlmsg_end(skb, nlh);
ret = rdma_nl_unicast(&init_net, skb, iwpm_pid); if (ret) {
skb = NULL;
err_str = "Unable to send a nlmsg"; goto hello_num_error;
}
pr_debug("%s: Sent hello abi_version = %u\n", __func__, abi_version); return 0;
hello_num_error:
pr_info("%s: %s\n", __func__, err_str);
dev_kfree_skb(skb); return ret;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.