Lines Matching refs:ses

27 cifs_ses_add_channel(struct cifs_ses *ses,
55 bool is_ses_using_iface(struct cifs_ses *ses, struct cifs_server_iface *iface)
59 spin_lock(&ses->chan_lock);
60 for (i = 0; i < ses->chan_count; i++) {
61 if (ses->chans[i].iface == iface) {
62 spin_unlock(&ses->chan_lock);
66 spin_unlock(&ses->chan_lock);
73 cifs_ses_get_chan_index(struct cifs_ses *ses,
82 for (i = 0; i < ses->chan_count; i++) {
83 if (ses->chans[i].server == server)
95 cifs_chan_set_in_reconnect(struct cifs_ses *ses,
98 int chan_index = cifs_ses_get_chan_index(ses, server);
103 ses->chans[chan_index].in_reconnect = true;
107 cifs_chan_clear_in_reconnect(struct cifs_ses *ses,
110 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
114 ses->chans[chan_index].in_reconnect = false;
118 cifs_chan_in_reconnect(struct cifs_ses *ses,
121 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
125 return CIFS_CHAN_IN_RECONNECT(ses, chan_index);
129 cifs_chan_set_need_reconnect(struct cifs_ses *ses,
132 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
136 set_bit(chan_index, &ses->chans_need_reconnect);
138 chan_index, ses->chans_need_reconnect);
142 cifs_chan_clear_need_reconnect(struct cifs_ses *ses,
145 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
149 clear_bit(chan_index, &ses->chans_need_reconnect);
151 chan_index, ses->chans_need_reconnect);
155 cifs_chan_needs_reconnect(struct cifs_ses *ses,
158 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
162 return CIFS_CHAN_NEEDS_RECONNECT(ses, chan_index);
166 cifs_chan_is_iface_active(struct cifs_ses *ses,
169 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
173 return ses->chans[chan_index].iface &&
174 ses->chans[chan_index].iface->is_active;
178 int cifs_try_adding_channels(struct cifs_ses *ses)
180 struct TCP_Server_Info *server = ses->server;
189 spin_lock(&ses->chan_lock);
191 new_chan_count = old_chan_count = ses->chan_count;
192 left = ses->chan_max - ses->chan_count;
195 spin_unlock(&ses->chan_lock);
197 "ses already at max_channels (%zu), nothing to open\n",
198 ses->chan_max);
203 spin_unlock(&ses->chan_lock);
209 spin_unlock(&ses->chan_lock);
213 spin_unlock(&ses->chan_lock);
218 if (tries > 3*ses->chan_max) {
224 spin_lock(&ses->iface_lock);
225 if (!ses->iface_count) {
226 spin_unlock(&ses->iface_lock);
228 ses->server->hostname);
233 iface = list_first_entry(&ses->iface_list, struct cifs_server_iface,
235 last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface,
239 list_for_each_entry_safe_from(iface, niface, &ses->iface_list,
242 if (iface->rdma_capable != ses->server->rdma)
247 (is_ses_using_iface(ses, iface) &&
260 spin_unlock(&ses->iface_lock);
261 rc = cifs_ses_add_channel(ses, iface);
262 spin_lock(&ses->iface_lock);
282 if (list_entry_is_head(iface, &ses->iface_list, iface_head)) {
283 list_for_each_entry(iface, &ses->iface_list, iface_head)
285 spin_unlock(&ses->iface_lock);
289 spin_unlock(&ses->iface_lock);
304 cifs_disable_secondary_channels(struct cifs_ses *ses)
310 spin_lock(&ses->chan_lock);
311 chan_count = ses->chan_count;
315 ses->chan_count = 1;
318 ses->chans_need_reconnect &= 1;
321 iface = ses->chans[i].iface;
322 server = ses->chans[i].server;
328 ses->chans[i].iface = NULL;
329 ses->chans[i].server = NULL;
330 spin_unlock(&ses->chan_lock);
333 spin_lock(&ses->iface_lock);
338 spin_unlock(&ses->iface_lock);
349 spin_lock(&ses->chan_lock);
353 spin_unlock(&ses->chan_lock);
362 cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server)
372 spin_lock(&ses->chan_lock);
373 chan_index = cifs_ses_get_chan_index(ses, server);
375 spin_unlock(&ses->chan_lock);
379 if (ses->chans[chan_index].iface) {
380 old_iface = ses->chans[chan_index].iface;
382 spin_unlock(&ses->chan_lock);
386 spin_unlock(&ses->chan_lock);
392 spin_lock(&ses->iface_lock);
393 if (!ses->iface_count) {
394 spin_unlock(&ses->iface_lock);
395 cifs_dbg(VFS, "server %s does not advertise interfaces\n", ses->server->hostname);
399 last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface,
404 list_for_each_entry(iface, &ses->iface_list, iface_head) {
420 (is_ses_using_iface(ses, iface) &&
435 if (list_entry_is_head(iface, &ses->iface_list, iface_head)) {
444 spin_unlock(&ses->iface_lock);
480 spin_unlock(&ses->iface_lock);
482 spin_lock(&ses->chan_lock);
483 chan_index = cifs_ses_get_chan_index(ses, server);
485 spin_unlock(&ses->chan_lock);
489 ses->chans[chan_index].iface = iface;
493 ses->chans[chan_index].server = NULL;
495 spin_unlock(&ses->chan_lock);
504 * If server is a channel of ses, return the corresponding enclosing
508 cifs_ses_find_chan(struct cifs_ses *ses, struct TCP_Server_Info *server)
512 spin_lock(&ses->chan_lock);
513 for (i = 0; i < ses->chan_count; i++) {
514 if (ses->chans[i].server == server) {
515 spin_unlock(&ses->chan_lock);
516 return &ses->chans[i];
519 spin_unlock(&ses->chan_lock);
524 cifs_ses_add_channel(struct cifs_ses *ses,
538 cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI4)\n",
539 ses, iface->speed, iface->rdma_capable ? "yes" : "no",
542 cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI6)\n",
543 ses, iface->speed, iface->rdma_capable ? "yes" : "no",
567 ctx->domainauto = ses->domainAuto;
568 ctx->domainname = ses->domainName;
573 ctx->username = ses->user_name;
574 ctx->password = ses->password;
575 ctx->sectype = ses->sectype;
576 ctx->sign = ses->sign;
579 /* XXX: Use ses->server->hostname? */
586 scnprintf(ctx->UNC, len, unc_fmt, ses->ip_addr);
590 ctx->vals = ses->server->vals;
591 ctx->ops = ses->server->ops;
593 ctx->noblocksnd = ses->server->noblocksnd;
594 ctx->noautotune = ses->server->noautotune;
595 ctx->sockopt_tcp_nodelay = ses->server->tcp_nodelay;
596 ctx->echo_interval = ses->server->echo_interval / HZ;
597 ctx->max_credits = ses->server->max_credits;
603 ctx->local_nls = ses->local_nls;
610 memcpy(&ctx->client_guid, ses->server->client_guid,
614 chan_server = cifs_get_tcp_session(ctx, ses->server);
616 spin_lock(&ses->chan_lock);
617 chan = &ses->chans[ses->chan_count];
622 spin_unlock(&ses->chan_lock);
626 ses->chan_count++;
627 atomic_set(&ses->chan_seq, 0);
630 cifs_chan_set_need_reconnect(ses, chan->server);
632 spin_unlock(&ses->chan_lock);
634 mutex_lock(&ses->session_mutex);
643 mutex_unlock(&ses->session_mutex);
647 rc = cifs_negotiate_protocol(xid, ses, chan->server);
649 rc = cifs_setup_session(xid, ses, chan->server, ses->local_nls);
651 mutex_unlock(&ses->session_mutex);
657 spin_lock(&ses->chan_lock);
660 cifs_chan_clear_need_reconnect(ses, chan->server);
661 ses->chan_count--;
666 WARN_ON(ses->chan_count < 1);
667 spin_unlock(&ses->chan_lock);
679 static __u32 cifs_ssetup_hdr(struct cifs_ses *ses,
708 if (ses->capabilities & CAP_UNICODE) {
712 if (ses->capabilities & CAP_STATUS32) {
716 if (ses->capabilities & CAP_DFS) {
720 if (ses->capabilities & CAP_UNIX)
749 static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
756 if (ses->domainName == NULL) {
763 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->domainName,
771 static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
781 if (ses->user_name == NULL) {
786 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->user_name,
792 unicode_domain_string(&bcc_ptr, ses, nls_cp);
798 static void ascii_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
807 if (ses->user_name != NULL) {
808 len = strscpy(bcc_ptr, ses->user_name, CIFS_MAX_USERNAME_LEN);
818 if (ses->domainName != NULL) {
819 len = strscpy(bcc_ptr, ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
842 decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifs_ses *ses,
850 kfree(ses->serverOS);
851 ses->serverOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
852 cifs_dbg(FYI, "serverOS=%s\n", ses->serverOS);
859 kfree(ses->serverNOS);
860 ses->serverNOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
861 cifs_dbg(FYI, "serverNOS=%s\n", ses->serverNOS);
868 kfree(ses->serverDomain);
869 ses->serverDomain = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
870 cifs_dbg(FYI, "serverDomain=%s\n", ses->serverDomain);
876 struct cifs_ses *ses,
888 kfree(ses->serverOS);
890 ses->serverOS = kmalloc(len + 1, GFP_KERNEL);
891 if (ses->serverOS) {
892 memcpy(ses->serverOS, bcc_ptr, len);
893 ses->serverOS[len] = 0;
894 if (strncmp(ses->serverOS, "OS/2", 4) == 0)
905 kfree(ses->serverNOS);
907 ses->serverNOS = kmalloc(len + 1, GFP_KERNEL);
908 if (ses->serverNOS) {
909 memcpy(ses->serverNOS, bcc_ptr, len);
910 ses->serverNOS[len] = 0;
930 struct cifs_ses *ses)
955 ses->ntlmssp->client_flags, server_flags);
957 if ((ses->ntlmssp->client_flags & (NTLMSSP_NEGOTIATE_SEAL | NTLMSSP_NEGOTIATE_SIGN)) &&
967 if (ses->server->sign && !(server_flags & NTLMSSP_NEGOTIATE_SIGN)) {
972 if ((ses->ntlmssp->client_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
977 ses->ntlmssp->server_flags = server_flags;
979 memcpy(ses->ntlmssp->cryptkey, pblob->Challenge, CIFS_CRYPTO_KEY_SIZE);
992 kfree_sensitive(ses->auth_key.response);
993 ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
995 if (!ses->auth_key.response) {
999 ses->auth_key.len = tilen;
1005 static int size_of_ntlmssp_blob(struct cifs_ses *ses, int base_size)
1007 int sz = base_size + ses->auth_key.len
1010 if (ses->domainName)
1011 sz += sizeof(__le16) * strnlen(ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
1015 if (ses->user_name)
1016 sz += sizeof(__le16) * strnlen(ses->user_name, CIFS_MAX_USERNAME_LEN);
1020 if (ses->workstation_name[0])
1021 sz += sizeof(__le16) * strnlen(ses->workstation_name,
1022 ntlmssp_workstation_name_size(ses));
1067 struct cifs_ses *ses,
1077 len = size_of_ntlmssp_blob(ses, sizeof(NEGOTIATE_MESSAGE));
1097 if (!server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
1101 ses->ntlmssp->client_flags = flags;
1129 struct cifs_ses *ses,
1139 len = size_of_ntlmssp_blob(ses, sizeof(struct negotiate_message));
1159 if (!server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
1168 ses->ntlmssp->client_flags = flags;
1193 struct cifs_ses *ses,
1203 rc = setup_ntlmv2_rsp(ses, nls_cp);
1210 len = size_of_ntlmssp_blob(ses, sizeof(AUTHENTICATE_MESSAGE));
1223 flags = ses->ntlmssp->server_flags | NTLMSSP_REQUEST_TARGET |
1237 if (ses->user_name != NULL) {
1238 memcpy(tmp, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
1239 ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1240 tmp += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
1243 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1245 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1255 ses->domainName,
1261 ses->user_name,
1267 ses->workstation_name,
1268 ntlmssp_workstation_name_size(ses),
1272 if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
1273 (!ses->server->session_estab || ses->ntlmssp->sesskey_per_smbsess) &&
1274 !calc_seckey(ses)) {
1275 memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
1331 struct cifs_ses *ses;
1353 struct cifs_ses *ses = sess_data->ses;
1356 rc = small_smb_init_no_tc(SMB_COM_SESSION_SETUP_ANDX, wct, ses,
1407 struct cifs_ses *ses = sess_data->ses;
1414 kmemdup(ses->auth_key.response,
1415 ses->auth_key.len, GFP_KERNEL);
1421 ses->auth_key.len;
1444 rc = SendReceive2(sess_data->xid, sess_data->ses,
1461 struct cifs_ses *ses = sess_data->ses;
1474 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1481 if (ses->user_name != NULL) {
1483 rc = setup_ntlmv2_rsp(ses, sess_data->nls_cp);
1489 memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
1490 ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1491 bcc_ptr += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
1497 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1502 if (ses->capabilities & CAP_UNICODE) {
1507 unicode_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1509 ascii_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1532 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1533 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1547 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1550 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1559 kfree_sensitive(ses->auth_key.response);
1560 ses->auth_key.response = NULL;
1571 struct cifs_ses *ses = sess_data->ses;
1587 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1589 spnego_key = cifs_get_spnego_key(ses, server);
1608 kfree_sensitive(ses->auth_key.response);
1609 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
1611 if (!ses->auth_key.response) {
1617 ses->auth_key.len = msg->sesskey_len;
1626 if (ses->capabilities & CAP_UNICODE) {
1633 unicode_domain_string(&bcc_ptr, ses, sess_data->nls_cp);
1636 ascii_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1658 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1659 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1683 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1686 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1698 kfree_sensitive(ses->auth_key.response);
1699 ses->auth_key.response = NULL;
1712 struct cifs_ses *ses = sess_data->ses;
1719 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1752 struct cifs_ses *ses = sess_data->ses;
1765 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL);
1766 if (!ses->ntlmssp) {
1770 ses->ntlmssp->sesskey_per_smbsess = false;
1781 &blob_len, ses, server,
1816 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1817 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1830 rc = decode_ntlmssp_challenge(bcc_ptr, blob_len, ses);
1843 kfree_sensitive(ses->auth_key.response);
1844 ses->auth_key.response = NULL;
1845 kfree_sensitive(ses->ntlmssp);
1846 ses->ntlmssp = NULL;
1858 struct cifs_ses *ses = sess_data->ses;
1876 &blob_len, ses, server,
1888 smb_buf->Uid = ses->Suid;
1909 if (ses->Suid != smb_buf->Uid) {
1910 ses->Suid = smb_buf->Uid;
1911 cifs_dbg(FYI, "UID changed! new UID = %llu\n", ses->Suid);
1936 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1939 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1952 kfree_sensitive(ses->auth_key.response);
1953 ses->auth_key.response = NULL;
1954 kfree_sensitive(ses->ntlmssp);
1955 ses->ntlmssp = NULL;
1964 struct cifs_ses *ses = sess_data->ses;
1967 type = cifs_select_sectype(server, ses->sectype);
1997 int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
2004 if (ses == NULL) {
2005 WARN(1, "%s: ses == NULL!", __func__);
2014 sess_data->ses = ses;