From patchwork Fri Jul 30 21:10:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sindhu Devale X-Patchwork-Id: 12411945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA742C4320A for ; Fri, 30 Jul 2021 21:10:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B561860F6B for ; Fri, 30 Jul 2021 21:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231584AbhG3VKm (ORCPT ); Fri, 30 Jul 2021 17:10:42 -0400 Received: from mga03.intel.com ([134.134.136.65]:12207 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbhG3VKm (ORCPT ); Fri, 30 Jul 2021 17:10:42 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10061"; a="213203322" X-IronPort-AV: E=Sophos;i="5.84,282,1620716400"; d="scan'208";a="213203322" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 14:10:37 -0700 X-IronPort-AV: E=Sophos;i="5.84,282,1620716400"; d="scan'208";a="499752255" Received: from sindhude-mobl.amr.corp.intel.com ([10.212.74.5]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 14:10:36 -0700 From: Sindhu Devale To: jgg@nvidia.com, dledford@redhat.com, leon@kernel.org, tatyana.e.nikolova@intel.com Cc: linux-rdma@vger.kernel.org, shiraz.saleem@intel.com, mustafa.ismail@intel.com, Earl Ruby , Sindhu Devale Subject: [PATCH rdma-core 1/2] iwpmd: Start the service if IPv4 or IPv6 is available Date: Fri, 30 Jul 2021 16:10:03 -0500 Message-Id: <20210730211004.1946-2-sindhu.devale@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210730211004.1946-1-sindhu.devale@intel.com> References: <20210730211004.1946-1-sindhu.devale@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Tatyana Nikolova Currently the iwpmd fails to start if IPv6 isn't enabled. systemd: Starting iWarp Port Mapper... iwpmd[118194]: create_iwpm_socket_v6: Unable to create socket. Address family not supported by protocol. iwpmd[118194]: main: Couldn't start iWarp Port Mapper systemd: iwpmd.service: main process exited, code=exited, status=1/FAILURE This isn't necessary because iwpmd can use IPv4 for all its functions. This fix allows iwpmd to start if either IPv6 or IPv4 is available. Change-Id: I158e7cfad06c9efdb01b4a38465d015b2a302bb2 Reported-by: Earl Ruby Signed-off-by: Tatyana Nikolova Signed-off-by: Sindhu Devale --- iwpmd/iwarp_pm_common.c | 2 +- iwpmd/iwarp_pm_server.c | 82 +++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/iwpmd/iwarp_pm_common.c b/iwpmd/iwarp_pm_common.c index 67309cbe..da8a70e3 100644 --- a/iwpmd/iwarp_pm_common.c +++ b/iwpmd/iwarp_pm_common.c @@ -264,7 +264,7 @@ create_nl_socket_exit: */ void destroy_iwpm_socket(int pm_sock) { - if (pm_sock > 0) + if (pm_sock >= 0) close(pm_sock); pm_sock = -1; } diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c index b3f23b7a..366fb33f 100644 --- a/iwpmd/iwarp_pm_server.c +++ b/iwpmd/iwarp_pm_server.c @@ -1416,10 +1416,14 @@ static int iwarp_port_mapper(void) /* initialize the file sets for select */ FD_ZERO(&select_fdset); /* add the UDP and Netlink sockets to the file set */ - FD_SET(pmv4_sock, &select_fdset); - FD_SET(pmv4_client_sock, &select_fdset); - FD_SET(pmv6_sock, &select_fdset); - FD_SET(pmv6_client_sock, &select_fdset); + if (pmv4_sock >= 0) { + FD_SET(pmv4_sock, &select_fdset); + FD_SET(pmv4_client_sock, &select_fdset); + } + if (pmv6_sock >= 0) { + FD_SET(pmv6_sock, &select_fdset); + FD_SET(pmv6_client_sock, &select_fdset); + } FD_SET(netlink_sock, &select_fdset); /* set the timeout for select */ @@ -1438,25 +1442,25 @@ static int iwarp_port_mapper(void) goto iwarp_port_mapper_exit; } - if (FD_ISSET(pmv4_sock, &select_fdset)) { - ret = process_iwpm_msg(pmv4_sock); - } + if (pmv4_sock >= 0) { + if (FD_ISSET(pmv4_sock, &select_fdset)) + ret = process_iwpm_msg(pmv4_sock); - if (FD_ISSET(pmv6_sock, &select_fdset)) { - ret = process_iwpm_msg(pmv6_sock); + if (FD_ISSET(pmv4_client_sock, &select_fdset)) + ret = process_iwpm_msg(pmv4_client_sock); } - if (FD_ISSET(pmv4_client_sock, &select_fdset)) { - ret = process_iwpm_msg(pmv4_client_sock); - } + if (pmv6_sock >= 0) { + if (FD_ISSET(pmv6_sock, &select_fdset)) + ret = process_iwpm_msg(pmv6_sock); - if (FD_ISSET(pmv6_client_sock, &select_fdset)) { - ret = process_iwpm_msg(pmv6_client_sock); + if (FD_ISSET(pmv6_client_sock, &select_fdset)) + ret = process_iwpm_msg(pmv6_client_sock); } - if (FD_ISSET(netlink_sock, &select_fdset)) { + if (FD_ISSET(netlink_sock, &select_fdset)) ret = process_iwpm_netlink_msg(netlink_sock); - } + } while (1); iwarp_port_mapper_exit: @@ -1516,26 +1520,38 @@ int main(int argc, char *argv[]) fclose(fp); } memset(client_list, 0, sizeof(client_list)); + pmv4_client_sock = -1; + pmv6_sock = -1; + pmv6_client_sock = pmv6_sock; pmv4_sock = create_iwpm_socket_v4(IWARP_PM_PORT); - if (pmv4_sock < 0) - goto error_exit_v4; - - pmv4_client_sock = create_iwpm_socket_v4(0); - if (pmv4_client_sock < 0) - goto error_exit_v4_client; + if (pmv4_sock < 0 && pmv4_sock != -EAFNOSUPPORT) + goto error_exit_sock; pmv6_sock = create_iwpm_socket_v6(IWARP_PM_PORT); - if (pmv6_sock < 0) - goto error_exit_v6; + if (pmv6_sock < 0 && pmv6_sock != -EAFNOSUPPORT) + goto error_exit_sock; + + /* If neither IPv4 nor IPv6 is supported, exit */ + if (pmv4_sock < 0 && pmv6_sock < 0) + goto error_exit_sock; - pmv6_client_sock = create_iwpm_socket_v6(0); - if (pmv6_client_sock < 0) - goto error_exit_v6_client; + if (pmv4_sock >= 0) { + pmv4_client_sock = create_iwpm_socket_v4(0); + + if (pmv4_client_sock < 0) + goto error_exit_sock; + } + if (pmv6_sock >= 0) { + pmv6_client_sock = create_iwpm_socket_v6(0); + + if (pmv6_client_sock < 0) + goto error_exit_sock; + } netlink_sock = create_netlink_socket(); if (netlink_sock < 0) - goto error_exit_nl; + goto error_exit_sock; signal(SIGHUP, iwpm_signal_handler); signal(SIGTERM, iwpm_signal_handler); @@ -1566,15 +1582,11 @@ int main(int argc, char *argv[]) error_exit: destroy_iwpm_socket(netlink_sock); -error_exit_nl: - destroy_iwpm_socket(pmv6_client_sock); -error_exit_v6_client: - destroy_iwpm_socket(pmv6_sock); -error_exit_v6: +error_exit_sock: destroy_iwpm_socket(pmv4_client_sock); -error_exit_v4_client: + destroy_iwpm_socket(pmv6_client_sock); destroy_iwpm_socket(pmv4_sock); -error_exit_v4: + destroy_iwpm_socket(pmv6_sock); syslog(LOG_WARNING, "main: Couldn't start iWarp Port Mapper.\n"); return ret; } From patchwork Fri Jul 30 21:10:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sindhu Devale X-Patchwork-Id: 12411947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1795C432BE for ; Fri, 30 Jul 2021 21:10:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90A5560EFD for ; Fri, 30 Jul 2021 21:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231980AbhG3VKn (ORCPT ); Fri, 30 Jul 2021 17:10:43 -0400 Received: from mga03.intel.com ([134.134.136.65]:12207 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbhG3VKn (ORCPT ); Fri, 30 Jul 2021 17:10:43 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10061"; a="213203323" X-IronPort-AV: E=Sophos;i="5.84,282,1620716400"; d="scan'208";a="213203323" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 14:10:38 -0700 X-IronPort-AV: E=Sophos;i="5.84,282,1620716400"; d="scan'208";a="499752259" Received: from sindhude-mobl.amr.corp.intel.com ([10.212.74.5]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 14:10:37 -0700 From: Sindhu Devale To: jgg@nvidia.com, dledford@redhat.com, leon@kernel.org, tatyana.e.nikolova@intel.com Cc: linux-rdma@vger.kernel.org, shiraz.saleem@intel.com, mustafa.ismail@intel.com, Sindhu Devale Subject: [PATCH rdma-core 2/2] iwpmd: Remove IP address checking per mapping Date: Fri, 30 Jul 2021 16:10:04 -0500 Message-Id: <20210730211004.1946-3-sindhu.devale@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210730211004.1946-1-sindhu.devale@intel.com> References: <20210730211004.1946-1-sindhu.devale@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Tatyana Nikolova IP address checking per mapping is redundant, because the IP address has already been checked in the rdma_bind_addr() in kernel before the IP address is passed to the iwpmd. Without removing this logic, the system call getifaddrs() could take long time and cause mapping requests to timeout. Signed-off-by: Tatyana Nikolova Signed-off-by: Sindhu Devale --- iwpmd/iwarp_pm_helper.c | 89 +---------------------------------------- 1 file changed, 2 insertions(+), 87 deletions(-) diff --git a/iwpmd/iwarp_pm_helper.c b/iwpmd/iwarp_pm_helper.c index b82de5c8..5d75eb32 100644 --- a/iwpmd/iwarp_pm_helper.c +++ b/iwpmd/iwarp_pm_helper.c @@ -172,83 +172,6 @@ int send_iwpm_msg(void (*form_msg_type)(iwpm_wire_msg *, iwpm_msg_parms *), return add_iwpm_pending_msg(&send_msg); } -/** - * check_iwpm_ip_addr - Check if the local IP address is valid - * @local_addr: local IP address to verify - * - * Check if the local IP address is used by the host ethernet interfaces - */ -static int check_iwpm_ip_addr(struct sockaddr_storage *local_addr) -{ - struct ifaddrs ifa; - struct ifaddrs *ifap = &ifa; - struct ifaddrs **ifa_list = &ifap; - struct ifaddrs *ifa_current; - int found_addr = 0; - int ret = -EINVAL; - - /* get a list of host ethernet interfaces */ - if ((ret = getifaddrs(ifa_list)) < 0) { - syslog(LOG_WARNING, "check_iwpm_ip_addr: Unable to get the list of interfaces (%s).\n", - strerror(errno)); - return ret; - } - /* go through the list to make sure local IP address is valid */ - ifa_current = *ifa_list; - while (ifa_current != NULL && !found_addr) { - if (local_addr->ss_family == ifa_current->ifa_addr->sa_family) { - switch (ifa_current->ifa_addr->sa_family) { - case AF_INET: { - if (!memcmp(&((struct sockaddr_in *) - ifa_current->ifa_addr)->sin_addr.s_addr, - &((struct sockaddr_in *)local_addr)->sin_addr.s_addr, - IWARP_PM_IPV4_ADDR)) { - - found_addr = 1; - } - break; - } - case AF_INET6: { - if (!memcmp(&((struct sockaddr_in6 *) - ifa_current->ifa_addr)->sin6_addr.s6_addr, - &((struct sockaddr_in6 *)local_addr)->sin6_addr.s6_addr, - INET6_ADDRSTRLEN)) - - found_addr = 1; - break; - } - default: - break; - } - } - ifa_current = ifa_current->ifa_next; - } - if (found_addr) - ret = 0; - - freeifaddrs(*ifa_list); - return ret; -} - -/** - * get_iwpm_ip_addr - Get a mapped IP address - * @local_addr: local IP address to map - * @mapped_addr: to store the mapped local IP address - * - * Currently, don't map the local IP address - */ -static int get_iwpm_ip_addr(struct sockaddr_storage *local_addr, - struct sockaddr_storage *mapped_addr) -{ - int ret = check_iwpm_ip_addr(local_addr); - if (!ret) - memcpy(mapped_addr, local_addr, sizeof(struct sockaddr_storage)); - else - iwpm_debug(IWARP_PM_ALL_DBG, "get_iwpm_ip_addr: Invalid local IP address.\n"); - - return ret; -} - /** * get_iwpm_tcp_port - Get a new TCP port from the host stack * @addr_family: should be valid AF_INET or AF_INET6 @@ -358,18 +281,14 @@ iwpm_mapped_port *create_iwpm_mapped_port(struct sockaddr_storage *local_addr, i struct sockaddr_storage mapped_addr; int new_sd; - /* check the local IP address */ - if (get_iwpm_ip_addr(local_addr, &mapped_addr)) - goto create_mapped_port_error; + memcpy(&mapped_addr, local_addr, sizeof(mapped_addr)); /* get a tcp port from the host net stack */ if (flags & IWPM_FLAGS_NO_PORT_MAP) { - mapped_addr = *local_addr; new_sd = -1; } else { if (get_iwpm_tcp_port(local_addr->ss_family, 0, &mapped_addr, &new_sd)) goto create_mapped_port_error; } - iwpm_port = get_iwpm_port(client_idx, local_addr, &mapped_addr, new_sd); return iwpm_port; @@ -391,11 +310,7 @@ iwpm_mapped_port *reopen_iwpm_mapped_port(struct sockaddr_storage *local_addr, iwpm_mapped_port *iwpm_port; int new_sd = -1; const char *str_err = ""; - int ret = check_iwpm_ip_addr(local_addr); - if (ret) { - str_err = "Invalid local IP address"; - goto reopen_mapped_port_error; - } + if (local_addr->ss_family != mapped_addr->ss_family) { str_err = "Different local and mapped sockaddr families"; goto reopen_mapped_port_error;