From patchwork Sun Nov 14 11:29:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 323212 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAEBTTru018976 for ; Sun, 14 Nov 2010 11:29:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755232Ab0KNL33 (ORCPT ); Sun, 14 Nov 2010 06:29:29 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:37650 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755248Ab0KNL32 (ORCPT ); Sun, 14 Nov 2010 06:29:28 -0500 Received: by ewy8 with SMTP id 8so352037ewy.19 for ; Sun, 14 Nov 2010 03:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=gSN1GlpAzYusPGJe/5oWXRNZmkk7b/3++AhVbzWHCtM=; b=ZYWh7ERevfopHLliGDiplrsEr0W1KjYUP372/Z2lg14PsGVfQrbndV7ROZp+cFXlIF B63swf4Nw6ZhBc1BglAy9cwTyfbhjAp346X8FblDo7/z8xCHr3Xdhep2ytQrFLZ3lV6z IGIb7BNnOcQmUHDbKz8rfH5nh0qb7t1NoxLAQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=sWEiUIUZqAKa3NJfedVnfhB5HctyZ1JOdRcLlGmnx4ekl1DMPTxbnro/r1pyLphbHU Bx4XWPtHWHkGDP6Rdduu3BFC6JGYR96mM6Ekrf0X5oNwtONOifvPlnvIpdDtl7OP+01z b67C+HBwfwiEPLLeaV68nEX68VH4K8tVrAjOU= Received: by 10.14.119.195 with SMTP id n43mr2887951eeh.0.1289734166824; Sun, 14 Nov 2010 03:29:26 -0800 (PST) Received: from localhost.localdomain (PPPoE-78-29-64-195.san.ru [78.29.64.195]) by mx.google.com with ESMTPS id b52sm5376328eei.7.2010.11.14.03.29.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 14 Nov 2010 03:29:26 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 2/2] CIFS: Add match_port check during looking for existing connection Date: Sun, 14 Nov 2010 14:29:15 +0300 Message-Id: <1289734155-3613-2-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1289734155-3613-1-git-send-email-piastryyy@gmail.com> References: <1289734155-3613-1-git-send-email-piastryyy@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 14 Nov 2010 11:29:29 +0000 (UTC) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index f0d0c1a..483ccb2 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1371,6 +1371,35 @@ cifs_parse_mount_options(char *options, const char *devname, } static bool +match_port(struct TCP_Server_Info *server, struct sockaddr *addr) +{ + struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; + unsigned short int port; + + /* search for a connection with the default port if user doesn't + specify the port manually */ + port = htons(CIFS_PORT); + + switch (addr->sa_family) { + case AF_INET: + if (addr4->sin_port) + port = addr4->sin_port; + if (port != server->addr.sockAddr.sin_port) + return false; + break; + case AF_INET6: + if (addr6->sin6_port) + port = addr6->sin6_port; + if (port != server->addr.sockAddr6.sin6_port) + return false; + break; + } + + return true; +} + +static bool match_address(struct TCP_Server_Info *server, struct sockaddr *addr) { struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; @@ -1381,9 +1410,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr) if (addr4->sin_addr.s_addr != server->addr.sockAddr.sin_addr.s_addr) return false; - if (addr4->sin_port && - addr4->sin_port != server->addr.sockAddr.sin_port) - return false; break; case AF_INET6: if (!ipv6_addr_equal(&addr6->sin6_addr, @@ -1392,9 +1418,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr) if (addr6->sin6_scope_id != server->addr.sockAddr6.sin6_scope_id) return false; - if (addr6->sin6_port && - addr6->sin6_port != server->addr.sockAddr6.sin6_port) - return false; break; } @@ -1468,6 +1491,9 @@ cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol) if (!match_address(server, addr)) continue; + if (!match_port(server, addr)) + continue; + if (!match_security(server, vol)) continue;