Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp276461ybi; Wed, 29 May 2019 21:12:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFvv4iDmeqJBCo/MPsXHo5gxcWNZ0WDoA0gug6BytHpNEbaYc7djECtRza6fOsU5BUnwfa X-Received: by 2002:a17:902:24b:: with SMTP id 69mr1828678plc.255.1559189530084; Wed, 29 May 2019 21:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189530; cv=none; d=google.com; s=arc-20160816; b=VpkvXkyKSV76F/JfA3GZnpYvblxLG6zXB0vLVQYaO8Xy/LHkt+KphWisXPut1FsS17 Fms2ah6ULphpeYuOPHz5TWvIQQppgDGZcesdkj5TFrHdzv8+LDYh80fuu65Hs3chwCP/ 6cYRE4K/MHyjqPU2htgLhm+Rf3Cs0LOU45JParFXFiEWM2lOskwjGOn19DkmuR4qMRXp bpWoh+dhkdJOwdiZ0vRDxXu779hGQuFlcUxAZYgOSnyEV4r/zmNvrk+ubOoCAb+kLfuT FuaaKlUUur5B3Ngk90goKme8QaHGaMXxllkp9GoXDDvh/b0dkh5bTwZa/Gqp6RvTRKda eQrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F5RBv2nLVL53adC1Q2GU53WtRrf25LhXfKaWMKk/GF8=; b=g22/+XzCdyGc75g1zufItMEKD2nV8XUbT0pede41LQ+6CcX0jVhXSrVQGuBEAMRDtX bMzSbcuPh1POtsAWSGmfC7cg3lVQievTWVl4+APM4stL8+swXweu2WkFGLV4d4S6lz2A 7vbq1K/cJlyLvw49xWwsNOqiZw0C7L/XoghoTpfnm5XlAuHbVce6MHDI2To7i1UIBQyt J01Ot3deHfnV2PIrk2zEUFAk76FqE9Px/G5O32njxkeuSIE76FHCXRjqdI5r9DxDPJC0 yFi5CdTK2YNlaEoivddox6C3SPPiQ/iblC7e9QJJNn/I+9BCmPjTOSNStpQb06MKLT3Y /0kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ytsp3uqc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r185si2089261pgr.10.2019.05.29.21.11.53; Wed, 29 May 2019 21:12:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ytsp3uqc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbfE3EKo (ORCPT + 99 others); Thu, 30 May 2019 00:10:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:44490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730878AbfE3DQ7 (ORCPT ); Wed, 29 May 2019 23:16:59 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C1F724627; Thu, 30 May 2019 03:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186218; bh=4db5lcLgJ3ET8TrH4aWhQ7EKOifDOX0uLXxtvfOh7nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ytsp3uqcOBlnb6sRDhZxJfJOPuQtZq6QEbTu/DMyifb4SpLXXHfr+gX0t+muoUPr/ O7i1if/+8sALyUghzXfCbRhf99891mwSrhV7oPcNfT8NEMe0RIjMuU37OJO5imnb0d okjn1B+cMc0Hv2w0ekVHHrifNMkSnDWJ/wNZlOxo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Parav Pandit , Daniel Jurgens , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.19 107/276] RDMA/cma: Consider scope_id while binding to ipv6 ll address Date: Wed, 29 May 2019 20:04:25 -0700 Message-Id: <20190530030532.719815315@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 5d7ed2f27bbd482fd29e6b2e204b1a1ee8a0b268 ] When two netdev have same link local addresses (such as vlan and non vlan), two rdma cm listen id should be able to bind to following different addresses. listener-1: addr=lla, scope_id=A, port=X listener-2: addr=lla, scope_id=B, port=X However while comparing the addresses only addr and port are considered, due to which 2nd listener fails to listen. In below example of two listeners, 2nd listener is failing with address in use error. $ rping -sv -a fe80::268a:7ff:feb3:d113%ens2f1 -p 4545& $ rping -sv -a fe80::268a:7ff:feb3:d113%ens2f1.200 -p 4545 rdma_bind_addr: Address already in use To overcome this, consider the scope_ids as well which forms the accurate IPv6 link local address. Signed-off-by: Parav Pandit Reviewed-by: Daniel Jurgens Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 6f5be78024762..39dc7be56884a 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -1078,18 +1078,31 @@ static inline bool cma_any_addr(const struct sockaddr *addr) return cma_zero_addr(addr) || cma_loopback_addr(addr); } -static int cma_addr_cmp(struct sockaddr *src, struct sockaddr *dst) +static int cma_addr_cmp(const struct sockaddr *src, const struct sockaddr *dst) { if (src->sa_family != dst->sa_family) return -1; switch (src->sa_family) { case AF_INET: - return ((struct sockaddr_in *) src)->sin_addr.s_addr != - ((struct sockaddr_in *) dst)->sin_addr.s_addr; - case AF_INET6: - return ipv6_addr_cmp(&((struct sockaddr_in6 *) src)->sin6_addr, - &((struct sockaddr_in6 *) dst)->sin6_addr); + return ((struct sockaddr_in *)src)->sin_addr.s_addr != + ((struct sockaddr_in *)dst)->sin_addr.s_addr; + case AF_INET6: { + struct sockaddr_in6 *src_addr6 = (struct sockaddr_in6 *)src; + struct sockaddr_in6 *dst_addr6 = (struct sockaddr_in6 *)dst; + bool link_local; + + if (ipv6_addr_cmp(&src_addr6->sin6_addr, + &dst_addr6->sin6_addr)) + return 1; + link_local = ipv6_addr_type(&dst_addr6->sin6_addr) & + IPV6_ADDR_LINKLOCAL; + /* Link local must match their scope_ids */ + return link_local ? (src_addr6->sin6_scope_id != + dst_addr6->sin6_scope_id) : + 0; + } + default: return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, &((struct sockaddr_ib *) dst)->sib_addr); -- 2.20.1