@@ -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;