cifs: Fix connections over NetBIOS session
Subsystems (2)
cover cifs: Fix connections over NetBIOS session
This patch series fixes establishment of NetBIOS session for SMB2+ connections which is currently broken. Tested with SMB3 dialect against Windows Server 2022.
Also it improves autodetection whether NetBIOS session is needed on specified server port, and allows to initialize NetBIOS session also over other port than 139. This is needed when testing against virtual machines when port 139 is forwarded over some non-system port.
Pali Rohár (6):
cifs: Allow to disable or force initialization of NetBIOS session
cifs: Fix establishing NetBIOS session for SMB2+ connection
cifs: Improve establishing SMB connection with NetBIOS session
cifs: Improve handling of NetBIOS packets
cifs: Fix negotiate retry functionality
cifs: Set default Netbios RFC1001 server name to hostname in UNC
fs/smb/client/cifsglob.h | 4 + fs/smb/client/cifsproto.h | 3 + fs/smb/client/connect.c | 316 ++++++++++++++++++++++++++++++++++--- fs/smb/client/fs_context.c | 25 ++- fs/smb/client/fs_context.h | 2 + fs/smb/client/smb1ops.c | 7 - fs/smb/client/smb2ops.c | 3 - fs/smb/client/transport.c | 5 +- 8 files changed, 327 insertions(+), 38 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/6 cifs: Allow to disable or force initialization of NetBIOS session
Currently SMB client always tries to initialize NetBIOS session when the server port is 139. This is useful for default cases, but nowadays when using non-standard routing or testing between VMs, it is common that servers are listening on non-standard ports.
So add a new mount option -o nbsessinit and -o nonbsessinit which either forces initialization or disables initialization regardless of server port number.
This allows Linux SMB client to connect to older SMB1 server listening on non-standard port, which requires initialization of NetBIOS session, by using additional mount options -o port= and -o nbsessinit.
--- fs/smb/client/cifsglob.h | 1 + fs/smb/client/connect.c | 11 ++++++++++- fs/smb/client/fs_context.c | 14 +++++++++++++- fs/smb/client/fs_context.h | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-)
fs/smb/client/cifsglob.h +1 -0
@@ -716,6 +716,7 @@ struct TCP_Server_Info {spinlock_t srv_lock;/* protect anything here that is not protected */ __u64 conn_id;/* connection identifier (useful for debugging) */ int srv_count;/* reference counter */ +int rfc1001_sessinit;/* whether to estasblish netbios session */ /* 15 character server name + 0x20 16th byte indicating type = srv */ char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL ];struct smb_version_operations *ops;
fs/smb/client/connect.c +10 -1
@@ -1738,6 +1738,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx, ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);memcpy (tcp_ses->server_RFC1001_name, ctx->target_rfc1001_name,RFC1001_NAME_LEN_WITH_NULL ); + tcp_ses->rfc1001_sessinit = ctx->rfc1001_sessinit; tcp_ses->session_estab = false; tcp_ses->sequence_number =0 ; tcp_ses->channel_sequence_num =0 ;/* only tracked for primary channel */
@@ -3206,7 +3207,15 @@ generic_ip_connect(struct TCP_Server_Info *server)return rc; }trace_smb3_connect_done (server->hostname, server->conn_id, &server->dstaddr); -if (sport ==htons (RFC1001_PORT )) + +/* +* Establish RFC1001 NetBIOS session when it was explicitly requested +* by mount option -o nbsessinit, or when connecting to default RFC1001 +* server port (139) and it was not explicitly disabled by mount option +* -o nonbsessinit. +*/ +if (server->rfc1001_sessinit ==1 || + (server->rfc1001_sessinit ==-1 && sport ==htons (RFC1001_PORT ))) rc =ip_rfc1001_connect (server);return rc;
fs/smb/client/fs_context.c +13 -1
@@ -134,6 +134,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {fsparam_flag ("compress" , Opt_compress),fsparam_flag ("witness" , Opt_witness),fsparam_flag_no ("unicode" , Opt_unicode), +fsparam_flag_no ("nbsessinit" , Opt_nbsessinit),/* Mount options which take uid or gid */ fsparam_uid("backupuid", Opt_backupuid),
@@ -965,6 +966,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,cifs_errorf (fc,"can not change unicode during remount\n" );return -EINVAL ; } +if (new_ctx->rfc1001_sessinit != old_ctx->rfc1001_sessinit) { +cifs_errorf (fc,"can not change nbsessinit during remount\n" ); +return -EINVAL ; + }return 0 ; }
@@ -1585,6 +1590,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,if (i ==RFC1001_NAME_LEN && param->string[i] !=0 )pr_warn ("server netbiosname longer than 15 truncated\n" );break ; +case Opt_nbsessinit: + ctx->rfc1001_sessinit = !result.negated; +cifs_dbg (FYI ,"rfc1001_sessinit set to %d\n" , ctx->rfc1001_sessinit); +break ;case Opt_ver:/* version of mount userspace tools, not dialect */ /* If interface changes in mount.cifs bump to new ver */
@@ -1872,13 +1881,16 @@ int smb3_init_fs_context(struct fs_context *fc)memset (ctx->source_rfc1001_name,0x20 ,RFC1001_NAME_LEN );for (i =0 ; i <strnlen (nodename,RFC1001_NAME_LEN ); i++) ctx->source_rfc1001_name[i] =toupper (nodename[i]); - ctx->source_rfc1001_name[RFC1001_NAME_LEN ] =0 ; +/* * null target name indicates to use *SMBSERVR default called name * if we end up sending RFC1001 session initialize */ ctx->target_rfc1001_name[0 ] =0 ; + + ctx->rfc1001_sessinit =-1 ;/* autodetect based on port number */ + ctx->cred_uid =current_uid (); ctx->linux_uid =current_uid (); ctx->linux_gid =current_gid ();
fs/smb/client/fs_context.h +2 -0
@@ -174,6 +174,7 @@ enum cifs_param { Opt_iocharset, Opt_netbiosname, Opt_servern, + Opt_nbsessinit, Opt_ver, Opt_vers, Opt_sec,
@@ -216,6 +217,7 @@ struct smb3_fs_context {char *iocharset;/* local code page for mapping to and from Unicode */ char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL ];/* clnt nb name */ char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL ];/* srvr nb name */ +int rfc1001_sessinit;kuid_t cred_uid;kuid_t linux_uid;kgid_t linux_gid;
Signature · 1 line
2.20.1
PATCH 2/6 cifs: Fix establishing NetBIOS session for SMB2+ connection
In reply to Pali RohárFunction ip_rfc1001_connect() which establish NetBIOS session for SMB connections, currently uses smb_send() function for sending NetBIOS Session Request packet. This function expects that the passed buffer is SMB packet and for SMB2+ connections it mangles packet header, which breaks prepared NetBIOS Session Request packet. Result is that this function send garbage packet for SMB2+ connection, which SMB2+ server cannot parse. That function is not mangling packets for SMB1 connections, so it somehow works for SMB1.
Fix this problem and instead of smb_send(), use smb_send_kvec() function which does not mangle prepared packet, this function send them as is. Just API of this function takes struct msghdr (kvec) instead of packet buffer.
[MS-SMB2] specification allows SMB2 protocol to use NetBIOS as a transport protocol. NetBIOS can be used over TCP via port 139. So this is a valid configuration, just not so common. And even recent Windows versions (e.g. Windows Server 2022) still supports this configuration: SMB over TCP port 139, including for modern SMB2 and SMB3 dialects.
This change fixes SMB2 and SMB3 connections over TCP port 139 which requires establishing of NetBIOS session. Tested that this change fixes establishing of SMB2 and SMB3 connections with Windows Server 2022.
--- fs/smb/client/cifsproto.h | 3 +++ fs/smb/client/connect.c | 20 +++++++++++++++----- fs/smb/client/transport.c | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-)
fs/smb/client/cifsproto.h +3 -0
@@ -31,6 +31,9 @@ extern void cifs_small_buf_release(void *);extern void free_rsp_buf (int ,void *);extern int smb_send (struct TCP_Server_Info *,struct smb_hdr *,unsigned int /* length */ ); +extern int smb_send_kvec (struct TCP_Server_Info *server, +struct msghdr *msg, +size_t *sent);extern unsigned int _get_xid (void );extern void _free_xid (unsigned int );#define get_xid () \
fs/smb/client/connect.c +15 -5
@@ -3059,8 +3059,10 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)* sessinit is sent but no second negprot */ struct rfc1002_session_packet req = {}; -struct smb_hdr *smb_buf = (struct smb_hdr *)&req; +struct msghdr msg = {}; +struct kvec iov = {};unsigned int len; +size_t sent; req.trailer.session_req.called_len =sizeof (req.trailer.session_req.called_name);
@@ -3089,10 +3091,18 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)* As per rfc1002, @len must be the number of bytes that follows the * length field of a rfc1002 session request payload. */ - len = sizeof(req) - offsetof(struct rfc1002_session_packet, trailer.session_req); + len =sizeof (req.trailer.session_req); + req.type =RFC1002_SESSION_REQUEST ; + req.flags =0 ; + req.length =cpu_to_be16 (len); + len += offsetof(typeof(req), trailer.session_req); + iov.iov_base = &req; + iov.iov_len = len; +iov_iter_kvec (&msg.msg_iter,ITER_SOURCE , &iov,1 , len); + rc =smb_send_kvec (server, &msg, &sent); +if (rc <0 || len != sent) +return (rc == -EINTR || rc == -EAGAIN ) ? rc : -ECONNABORTED ; - smb_buf->smb_buf_length =cpu_to_be32 ((RFC1002_SESSION_REQUEST <<24 ) | len); - rc =smb_send (server, smb_buf, len);/* * RFC1001 layer in at least one server requires very short break before * negprot presumably because not expecting negprot to follow so fast.
@@ -3101,7 +3111,7 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)*/ usleep_range (1000 ,2000 ); -return rc; +return 0 ; } static int
fs/smb/client/transport.c +1 -1
@@ -179,7 +179,7 @@ delete_mid(struct mid_q_entry *mid)* Our basic "send data to server" function. Should be called with srv_mutex * held. The caller is responsible for handling the results. */ -static int +int smb_send_kvec (struct TCP_Server_Info *server,struct msghdr *smb_msg,size_t *sent) {
Signature · 1 line
2.20.1
PATCH 3/6 cifs: Improve establishing SMB connection with NetBIOS session
In reply to Pali RohárFunction ip_rfc1001_connect() send NetBIOS session request but currently does not read response. It even does not wait for the response. Instead it just calls usleep_range(1000, 2000) and explain in comment that some servers require short break before sending SMB negotiate packet. Response is later handled in generic is_smb_response() function called from cifs_demultiplex_thread().
That comment probably refers to the old DOS SMB server which cannot process incoming SMB negotiate packet if it has not sent NetBIOS session response packet. Note that current sleep timeout is too small when trying to establish connection to DOS SMB server running in qemu virtual machine connected over qemu user networking with guestfwd netcat options. So that usleep_range() call is not useful at all.
NetBIOS session response packet contains useful error information, like the server name specified NetBIOS session request packet is incorrect. Old Windows SMB servers and even the latest SMB server on the latest Windows Server 2022 version requires that the name is the correct server name, otherwise they return error RFC1002_NOT_PRESENT. This applies for all SMB dialects (old SMB1, and also modern SMB2 and SMB3).
Therefore read the reply of NetBIOS session request and implement parsing of the reply. Log received error to dmesg to help debugging reason why connection was refused. Also convert NetBIOS error to useful errno.
Note that ip_rfc1001_connect() function is used only when doing connection over port 139. So the common SMB scenario over port 445 is not affected by this change at all.
--- fs/smb/client/connect.c | 137 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 3 deletions(-)
fs/smb/client/connect.c +134 -3
@@ -3049,6 +3049,44 @@ bind_socket(struct TCP_Server_Info *server)return rc; } +static int +smb_recv_kvec (struct TCP_Server_Info *server,struct msghdr *msg,size_t *recv) +{ +int rc =0 ; +int retries =0 ; +int msg_flags = server->noblocksnd ?MSG_DONTWAIT :0 ; + + *recv =0 ; + +while (msg_data_left (msg)) { + rc =sock_recvmsg (server->ssocket, msg, msg_flags); +if (rc == -EAGAIN ) { + retries++; +if (retries >=14 || + (!server->noblocksnd && (retries >2 ))) { +cifs_server_dbg (VFS ,"sends on sock %p stuck for 15 seconds\n" , + server->ssocket); +return -EAGAIN ; + } +msleep (1 << retries); +continue ; + } + +if (rc <0 ) +return rc; + +if (rc ==0 ) { +cifs_dbg (FYI ,"Received no data (TCP RST)\n" ); +return -ECONNABORTED ; + } + +/* recv was at least partially successful */ + *recv += rc; + retries =0 ;/* in case we get ENOSPC on the next send */ + } +return 0 ; +} +static int ip_rfc1001_connect (struct TCP_Server_Info *server) {
@@ -3059,10 +3097,12 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)* sessinit is sent but no second negprot */ struct rfc1002_session_packet req = {}; +struct rfc1002_session_packet resp = {};struct msghdr msg = {};struct kvec iov = {};unsigned int len;size_t sent; +size_t recv; req.trailer.session_req.called_len =sizeof (req.trailer.session_req.called_name);
@@ -3106,10 +3146,101 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)/* * RFC1001 layer in at least one server requires very short break before * negprot presumably because not expecting negprot to follow so fast. -* This is a simple solution that works without complicating the code -* and causes no significant slowing down on mount for everyone else +* For example DOS SMB servers cannot process negprot if it was received +* before the server sent response for SESSION_REQUEST packet. So, wait +* for the response, read it and parse it as it can contain useful error +* information (e.g. specified server name was incorrect). For example +* even the latest Windows Server 2022 SMB1 server over port 139 send +* error if its server name was in SESSION_REQUEST packet incorrect. +* Nowadays usage of port 139 is not common, so waiting for reply here +* does not slowing down mounting of common case (over port 445). */ -usleep_range (1000 ,2000 ); + len = offsetof(typeof (resp ), trailer); + iov.iov_base = &resp; + iov.iov_len = len; +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , len); + rc =smb_recv_kvec (server, &msg, &recv); +if (rc <0 || recv != len) +return (rc == -EINTR || rc == -EAGAIN ) ? rc : -ECONNABORTED ; + +switch (resp.type) { +case RFC1002_POSITIVE_SESSION_RESPONSE : +if (be16_to_cpu (resp.length) !=0 ) { +cifs_dbg (VFS ,"RFC 1002 positive session response but with invalid non-zero length %u\n" , +be16_to_cpu (resp.length)); +return -EIO ; + } +cifs_dbg (FYI ,"RFC 1002 positive session response" ); +break ; +case RFC1002_NEGATIVE_SESSION_RESPONSE : +/* Read RFC1002 response error code and convert it to errno in rc */ + len =sizeof (resp.trailer.neg_ses_resp_error_code); + iov.iov_base = &resp.trailer.neg_ses_resp_error_code; + iov.iov_len = len; +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , len); +if (be16_to_cpu (resp.length) == len && +smb_recv_kvec (server, &msg, &recv) ==0 && + recv == len) { +cifs_dbg (VFS ,"RFC 1002 negative session response with error 0x%x\n" , + resp.trailer.neg_ses_resp_error_code); +switch (resp.trailer.neg_ses_resp_error_code) { +case RFC1002_NOT_LISTENING_CALLED : +/* server does not listen for specified server name */ + fallthrough; +case RFC1002_NOT_PRESENT : +/* server name is incorrect */ + rc = -ENOENT ; +cifs_dbg (VFS ,"Server rejected NetBIOS servername %.15s\n" , + server->server_RFC1001_name[0 ] ? + server->server_RFC1001_name : +DEFAULT_CIFS_CALLED_NAME ); +cifs_dbg (VFS ,"Specify correct NetBIOS servername in source path or with -o servern= option\n" ); +break ; +case RFC1002_NOT_LISTENING_CALLING : +/* client name was not accepted by server */ + rc = -EACCES ; +cifs_dbg (VFS ,"Server rejected NetBIOS clientname %.15s\n" , + server->workstation_RFC1001_name[0 ] ? + server->workstation_RFC1001_name : +"LINUX_CIFS_CLNT" ); +cifs_dbg (VFS ,"Specify correct NetBIOS clientname with -o netbiosname= option\n" ); +break ; +case RFC1002_INSUFFICIENT_RESOURCE : +/* remote server resource error */ + rc = -EREMOTEIO ; +break ; +case RFC1002_UNSPECIFIED_ERROR : +default : +/* other/unknown error */ + rc = -EIO ; +break ; + } + }else { +cifs_dbg (VFS ,"RFC 1002 negative session response\n" ); + rc = -EIO ; + } +return rc; +case RFC1002_RETARGET_SESSION_RESPONSE : +cifs_dbg (VFS ,"RFC 1002 retarget session response\n" ); +if (be16_to_cpu (resp.length) ==sizeof (resp.trailer.retarget_resp)) { + len =sizeof (resp.trailer.retarget_resp); + iov.iov_base = &resp.trailer.retarget_resp; + iov.iov_len = len; +iov_iter_kvec (&msg.msg_iter,ITER_DEST , &iov,1 , len); +if (smb_recv_kvec (server, &msg, &recv) ==0 && recv == len) { +cifs_dbg (VFS ,"Server wants to redirect connection\n" ); +cifs_dbg (VFS ,"Remount with options -o ip=%pI4,port=%u\n" , + &resp.trailer.retarget_resp.retarget_ip_addr, +be16_to_cpu (resp.trailer.retarget_resp.port)); + } + } +cifs_dbg (VFS ,"Closing connection\n" ); +/* FIXME: Should we automatically redirect to new retarget_resp server? */ +return -EMULTIHOP ; +default : +cifs_dbg (VFS ,"RFC 1002 unknown response type 0x%x\n" , resp.type); +return -EIO ; + }return 0 ; }
Signature · 1 line
2.20.1
PATCH 4/6 cifs: Improve handling of NetBIOS packets
In reply to Pali RohárNow all NetBIOS session logic is handled in ip_rfc1001_connect() function, so cleanup is_smb_response() function which contains generic handling of incoming SMB packets. Note that function is_smb_response() is not used directly or indirectly (e.g. over cifs_demultiplex_thread() by ip_rfc1001_connect() function.
Except the Negative Session Response and the Session Keep Alive packet, the cifs_demultiplex_thread() should not receive any NetBIOS session packets. And Session Keep Alive packet may be received only when the NetBIOS session was established by ip_rfc1001_connect() function. So treat any such packet as error and schedule reconnect.
Negative Session Response packet is returned from Windows SMB server (from Windows 98 and also from Windows Server 2022) if client sent over port 139 SMB negotiate request without previously establishing a NetBIOS session. The common scenario is that Negative Session Response packet is returned for the SMB negotiate packet, which is the first one which SMB client sends (if it is not establishing a NetBIOS session).
Note that server port 139 may be forwarded and mapped between virtual machines to different number. And Linux SMB client do not call function ip_rfc1001_connect() when prot is not 139. So nowadays when using port mapping or port forwarding between VMs, it is not so uncommon to see this error.
Currently the logic on Negative Session Response packet changes server port to 445 and force reconnection. But this logic does not work when using non-standard port numbers and also does not help if the server on specified port is requiring establishing a NetBIOS session.
Fix this Negative Session Response logic and instead of changing server port (on which server does not have to listen), force reconnection with establishing a NetBIOS session.
--- fs/smb/client/cifsglob.h | 3 + fs/smb/client/connect.c | 140 +++++++++++++++++++++++++++++++++----- fs/smb/client/transport.c | 3 + 3 files changed, 128 insertions(+), 18 deletions(-)
fs/smb/client/cifsglob.h +3 -0
@@ -717,6 +717,7 @@ struct TCP_Server_Info {__u64 conn_id;/* connection identifier (useful for debugging) */ int srv_count;/* reference counter */ int rfc1001_sessinit;/* whether to estasblish netbios session */ +bool with_rfc1001;/* if netbios session is used */ /* 15 character server name + 0x20 16th byte indicating type = srv */ char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL ];struct smb_version_operations *ops;
@@ -1728,6 +1729,7 @@ struct mid_q_entry {void *resp_buf;/* pointer to received SMB header */ unsigned int resp_buf_size;int mid_state;/* wish this were enum but can not pass to wait_event */ +int mid_rc;/* rc for MID_RC */ unsigned int mid_flags;__le16 command;/* smb command code */ unsigned int optype;/* operation type */
@@ -1890,6 +1892,7 @@ static inline bool is_replayable_error(int error)#define MID_RESPONSE_MALFORMED 0x10#define MID_SHUTDOWN 0x20#define MID_RESPONSE_READY 0x40/* ready for other process handle the rsp */ +#define MID_RC 0x80/* mid_rc contains custom rc */ /* Flags */ #define MID_WAIT_CANCELLED 1/* Cancelled while waiting for response */
fs/smb/client/connect.c +122 -18
204 lines not on this page · raw message
fs/smb/client/transport.c +3 -0
@@ -894,6 +894,9 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)case MID_SHUTDOWN : rc = -EHOSTDOWN ;break ; +case MID_RC : + rc = mid->mid_rc; +break ;default :if (!(mid->mid_flags &MID_DELETED )) {list_del_init (&mid->qhead);
Signature · 1 line
2.20.1
PATCH 5/6 cifs: Fix negotiate retry functionality
In reply to Pali RohárSMB negotiate retry functionality in cifs_negotiate() is currently broken and does not work when doing socket reconnect. Caller of this function, which is cifs_negotiate_protocol() requires that tcpStatus after successful execution of negotiate callback stay in CifsInNegotiate. But if the CIFSSMBNegotiate() called from cifs_negotiate() fails due to connection issues then tcpStatus is changed as so repeated CIFSSMBNegotiate() call does not help.
Fix this problem by moving retrying code from negotiate callback (which is either cifs_negotiate() or smb2_negotiate()) to cifs_negotiate_protocol() which is caller of those callbacks. This allows to properly handle and implement correct transistions between tcpStatus states as function cifs_negotiate_protocol() already handles it.
With this change, cifs_negotiate_protocol() now handles also -EAGAIN error set by the RFC1002_NEGATIVE_SESSION_RESPONSE processing after reconnecting with NetBIOS session.
--- fs/smb/client/connect.c | 10 ++++++++++ fs/smb/client/smb1ops.c | 7 ------- fs/smb/client/smb2ops.c | 3 --- 3 files changed, 10 insertions(+), 10 deletions(-)
fs/smb/client/connect.c +10 -0
@@ -4206,11 +4206,13 @@ int cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses, struct TCP_Server_Info *server) { + bool in_retry = false;int rc =0 ;if (!server->ops->need_neg || !server->ops->negotiate)return -ENOSYS ; +retry:/* only send once per connect */ spin_lock (&server->srv_lock); if (server->tcpStatus != CifsGood &&
@@ -4230,6 +4232,14 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses,spin_unlock (&server->srv_lock); rc = server->ops->negotiate (xid, ses, server); +if (rc == -EAGAIN ) { +/* Allow one retry attempt */ +if (!in_retry) { + in_retry = true; + goto retry; + } + rc = -EHOSTDOWN ; + }if (rc ==0 ) {spin_lock (&server->srv_lock);if (server->tcpStatus == CifsInNegotiate)
fs/smb/client/smb1ops.c +0 -7
@@ -426,13 +426,6 @@ cifs_negotiate(const unsigned int xid, {int rc; rc =CIFSSMBNegotiate (xid, ses, server); -if (rc == -EAGAIN ) { -/* retry only once on 1st time connection */ -set_credits (server,1 ); - rc =CIFSSMBNegotiate (xid, ses, server); -if (rc == -EAGAIN ) - rc = -EHOSTDOWN ; - }return rc; }
fs/smb/client/smb2ops.c +0 -3
@@ -464,9 +464,6 @@ smb2_negotiate(const unsigned int xid, server->CurrentMid =0 ;spin_unlock (&server->mid_lock); rc =SMB2_negotiate (xid, ses, server); -/* BB we probably don't need to retry with modern servers */ -if (rc == -EAGAIN ) - rc = -EHOSTDOWN ;return rc; }
Signature · 1 line
2.20.1
PATCH 6/6 cifs: Set default Netbios RFC1001 server name to hostname in UNC
In reply to Pali RohárWindows SMB servers (including SMB2+) which are working over RFC1001 require that Netbios server name specified in RFC1001 Session Request packet is same as the UNC host name. Netbios server name can be already specified manually via -o servern= option.
With this change the RFC1001 server name is set automatically by extracting the hostname from the mount source.
--- fs/smb/client/fs_context.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/client/fs_context.c +11 -0
@@ -1125,6 +1125,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,int i, opt;bool is_smb3 = !strcmp (fc->fs_type->name,"smb3" );bool skip_parsing = false; +char *hostname;cifs_dbg (FYI ,"CIFS: parsing cifs mount option '%s'\n" , param->key);
@@ -1447,6 +1448,16 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,cifs_errorf (fc,"OOM when copying UNC string\n" ); goto cifs_parse_mount_err; } + hostname =extract_hostname (ctx->UNC); +if (IS_ERR (hostname)) { +cifs_errorf (fc,"Cannot extract hostname from UNC string\n" ); + goto cifs_parse_mount_err; + } +/* last byte, type, is 0x20 for servr type */ +memset (ctx->target_rfc1001_name,0x20 ,RFC1001_NAME_LEN_WITH_NULL ); +for (i =0 ; i <RFC1001_NAME_LEN && hostname[i] !=0 ; i++) + ctx->target_rfc1001_name[i] =toupper (hostname[i]); +kfree (hostname);break ;case Opt_user:kfree (ctx->username);
Signature · 1 line
2.20.1