From patchwork Sun Jun 20 21:10:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 107091 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5KLAsc2020212 for ; Sun, 20 Jun 2010 21:12:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751975Ab0FTVMK (ORCPT ); Sun, 20 Jun 2010 17:12:10 -0400 Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.120]:59838 "EHLO cdptpa-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751953Ab0FTVMK (ORCPT ); Sun, 20 Jun 2010 17:12:10 -0400 Received: from cdptpa-omtalb.mail.rr.com ([10.127.143.54]) by cdptpa-qmta01.mail.rr.com with ESMTP id <20100620211209494.TFTV28241@cdptpa-qmta01.mail.rr.com> for ; Sun, 20 Jun 2010 21:12:09 +0000 X-Authority-Analysis: v=1.1 cv=g0MSbh+MYx8F7k+8LwuC+RmWZBEHob5zzeCYU6r5B3g= c=1 sm=0 a=FuBnvUsZmd4A:10 a=yQWWgrYGNuUA:10 a=ld/erqUjW76FpBUqCqkKeA==:17 a=20KFwNOVAAAA:8 a=EOkk5I58Ppj9KJiMA-IA:9 a=_cPODhcTMEGemz8n2WIA:7 a=2L5ftZFm4FgMwqMEmGLFg_KXJVEA:4 a=jEp0ucaQiEUA:10 a=Ljh8Meopild-3ufl:21 a=EuHtFl1CLFRBfaaS:21 a=ld/erqUjW76FpBUqCqkKeA==:117 X-Cloudmark-Score: 0 X-Originating-IP: 71.70.153.3 Received: from [71.70.153.3] ([71.70.153.3:51023] helo=mail.poochiereds.net) by cdptpa-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 73/10-27392-CD38E1C4; Sun, 20 Jun 2010 21:10:52 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id 2638D580E3; Sun, 20 Jun 2010 17:10:52 -0400 (EDT) From: Jeff Layton To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org Subject: [PATCH 2/6] cifs: move address comparison into separate function Date: Sun, 20 Jun 2010 17:10:47 -0400 Message-Id: <1277068251-16344-3-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1277068251-16344-1-git-send-email-jlayton@redhat.com> References: <1277068251-16344-1-git-send-email-jlayton@redhat.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 (demeter.kernel.org [140.211.167.41]); Sun, 20 Jun 2010 21:12:11 +0000 (UTC) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 640c7d5..665ee37 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1380,18 +1380,44 @@ cifs_parse_mount_options(char *options, const char *devname, return 0; } +static bool +match_address(struct TCP_Server_Info *server, struct sockaddr *addr) +{ + struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; + + switch (addr->sa_family) { + case AF_INET: + 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, + &server->addr.sockAddr6.sin6_addr)) + return false; + 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; + } + + return true; +} + static struct TCP_Server_Info * -cifs_find_tcp_session(struct sockaddr_storage *addr) +cifs_find_tcp_session(struct sockaddr *addr) { - struct list_head *tmp; struct TCP_Server_Info *server; - struct sockaddr_in *addr4 = (struct sockaddr_in *) addr; - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addr; write_lock(&cifs_tcp_ses_lock); - list_for_each(tmp, &cifs_tcp_ses_list) { - server = list_entry(tmp, struct TCP_Server_Info, - tcp_ses_list); + list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { /* * the demux thread can exit on its own while still in CifsNew * so don't accept any sockets in that state. Since the @@ -1401,35 +1427,8 @@ cifs_find_tcp_session(struct sockaddr_storage *addr) if (server->tcpStatus == CifsNew) continue; - switch (addr->ss_family) { - case AF_INET: - if (addr4->sin_addr.s_addr == - server->addr.sockAddr.sin_addr.s_addr) { - /* user overrode default port? */ - if (addr4->sin_port) { - if (addr4->sin_port != - server->addr.sockAddr.sin_port) - continue; - } - break; - } else - continue; - - case AF_INET6: - if (ipv6_addr_equal(&addr6->sin6_addr, - &server->addr.sockAddr6.sin6_addr) && - (addr6->sin6_scope_id == - server->addr.sockAddr6.sin6_scope_id)) { - /* user overrode default port? */ - if (addr6->sin6_port) { - if (addr6->sin6_port != - server->addr.sockAddr6.sin6_port) - continue; - } - break; - } else - continue; - } + if (!match_address(server, addr)) + continue; ++server->srv_count; write_unlock(&cifs_tcp_ses_lock); @@ -1499,7 +1498,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) } /* see if we already have a matching tcp_ses */ - tcp_ses = cifs_find_tcp_session(&addr); + tcp_ses = cifs_find_tcp_session((struct sockaddr *)&addr); if (tcp_ses) return tcp_ses;