Lines Matching defs: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);
115 ses->chans[chan_index].in_reconnect = false;
119 cifs_chan_in_reconnect(struct cifs_ses *ses,
122 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
127 return CIFS_CHAN_IN_RECONNECT(ses, chan_index);
131 cifs_chan_set_need_reconnect(struct cifs_ses *ses,
134 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
139 set_bit(chan_index, &ses->chans_need_reconnect);
141 chan_index, ses->chans_need_reconnect);
145 cifs_chan_clear_need_reconnect(struct cifs_ses *ses,
148 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
153 clear_bit(chan_index, &ses->chans_need_reconnect);
155 chan_index, ses->chans_need_reconnect);
159 cifs_chan_needs_reconnect(struct cifs_ses *ses,
162 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
167 return CIFS_CHAN_NEEDS_RECONNECT(ses, chan_index);
171 cifs_chan_is_iface_active(struct cifs_ses *ses,
174 unsigned int chan_index = cifs_ses_get_chan_index(ses, server);
179 return ses->chans[chan_index].iface &&
180 ses->chans[chan_index].iface->is_active;
184 int cifs_try_adding_channels(struct cifs_ses *ses)
186 struct TCP_Server_Info *server = ses->server;
195 spin_lock(&ses->chan_lock);
197 new_chan_count = old_chan_count = ses->chan_count;
198 left = ses->chan_max - ses->chan_count;
201 spin_unlock(&ses->chan_lock);
203 "ses already at max_channels (%zu), nothing to open\n",
204 ses->chan_max);
209 spin_unlock(&ses->chan_lock);
215 spin_unlock(&ses->chan_lock);
219 spin_unlock(&ses->chan_lock);
224 if (tries > 3*ses->chan_max) {
230 spin_lock(&ses->iface_lock);
231 if (!ses->iface_count) {
232 spin_unlock(&ses->iface_lock);
234 ses->server->hostname);
239 iface = list_first_entry(&ses->iface_list, struct cifs_server_iface,
241 last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface,
245 list_for_each_entry_safe_from(iface, niface, &ses->iface_list,
248 if (iface->rdma_capable != ses->server->rdma)
253 (is_ses_using_iface(ses, iface) &&
266 spin_unlock(&ses->iface_lock);
267 rc = cifs_ses_add_channel(ses, iface);
268 spin_lock(&ses->iface_lock);
288 if (list_entry_is_head(iface, &ses->iface_list, iface_head)) {
289 list_for_each_entry(iface, &ses->iface_list, iface_head)
291 spin_unlock(&ses->iface_lock);
295 spin_unlock(&ses->iface_lock);
310 cifs_disable_secondary_channels(struct cifs_ses *ses)
316 spin_lock(&ses->chan_lock);
317 chan_count = ses->chan_count;
321 ses->chan_count = 1;
324 ses->chans_need_reconnect &= 1;
327 iface = ses->chans[i].iface;
328 server = ses->chans[i].server;
334 ses->chans[i].iface = NULL;
335 ses->chans[i].server = NULL;
336 spin_unlock(&ses->chan_lock);
339 spin_lock(&ses->iface_lock);
344 spin_unlock(&ses->iface_lock);
355 spin_lock(&ses->chan_lock);
359 spin_unlock(&ses->chan_lock);
367 cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server)
376 spin_lock(&ses->chan_lock);
377 chan_index = cifs_ses_get_chan_index(ses, server);
379 spin_unlock(&ses->chan_lock);
383 if (ses->chans[chan_index].iface) {
384 old_iface = ses->chans[chan_index].iface;
386 spin_unlock(&ses->chan_lock);
390 spin_unlock(&ses->chan_lock);
396 spin_lock(&ses->iface_lock);
397 if (!ses->iface_count) {
398 spin_unlock(&ses->iface_lock);
399 cifs_dbg(ONCE, "server %s does not advertise interfaces\n", ses->server->hostname);
403 last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface,
408 list_for_each_entry(iface, &ses->iface_list, iface_head) {
424 (is_ses_using_iface(ses, iface) &&
439 if (list_entry_is_head(iface, &ses->iface_list, iface_head)) {
453 spin_unlock(&ses->iface_lock);
477 spin_unlock(&ses->iface_lock);
479 spin_lock(&ses->chan_lock);
480 chan_index = cifs_ses_get_chan_index(ses, server);
482 spin_unlock(&ses->chan_lock);
486 ses->chans[chan_index].iface = iface;
487 spin_unlock(&ses->chan_lock);
491 * If server is a channel of ses, return the corresponding enclosing
495 cifs_ses_find_chan(struct cifs_ses *ses, struct TCP_Server_Info *server)
499 spin_lock(&ses->chan_lock);
500 for (i = 0; i < ses->chan_count; i++) {
501 if (ses->chans[i].server == server) {
502 spin_unlock(&ses->chan_lock);
503 return &ses->chans[i];
506 spin_unlock(&ses->chan_lock);
511 cifs_ses_add_channel(struct cifs_ses *ses,
525 cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI4)\n",
526 ses, iface->speed, iface->rdma_capable ? "yes" : "no",
529 cifs_dbg(FYI, "adding channel to ses %p (speed:%zu bps rdma:%s ip:%pI6)\n",
530 ses, iface->speed, iface->rdma_capable ? "yes" : "no",
554 ctx->domainauto = ses->domainAuto;
555 ctx->domainname = ses->domainName;
560 ctx->username = ses->user_name;
561 ctx->password = ses->password;
562 ctx->sectype = ses->sectype;
563 ctx->sign = ses->sign;
566 /* XXX: Use ses->server->hostname? */
573 scnprintf(ctx->UNC, len, unc_fmt, ses->ip_addr);
577 ctx->vals = ses->server->vals;
578 ctx->ops = ses->server->ops;
580 ctx->noblocksnd = ses->server->noblocksnd;
581 ctx->noautotune = ses->server->noautotune;
582 ctx->sockopt_tcp_nodelay = ses->server->tcp_nodelay;
583 ctx->echo_interval = ses->server->echo_interval / HZ;
584 ctx->max_credits = ses->server->max_credits;
590 ctx->local_nls = ses->local_nls;
597 memcpy(&ctx->client_guid, ses->server->client_guid,
601 chan_server = cifs_get_tcp_session(ctx, ses->server);
603 spin_lock(&ses->chan_lock);
604 chan = &ses->chans[ses->chan_count];
609 spin_unlock(&ses->chan_lock);
613 ses->chan_count++;
614 atomic_set(&ses->chan_seq, 0);
617 cifs_chan_set_need_reconnect(ses, chan->server);
619 spin_unlock(&ses->chan_lock);
621 mutex_lock(&ses->session_mutex);
630 mutex_unlock(&ses->session_mutex);
634 rc = cifs_negotiate_protocol(xid, ses, chan->server);
636 rc = cifs_setup_session(xid, ses, chan->server, ses->local_nls);
638 mutex_unlock(&ses->session_mutex);
644 spin_lock(&ses->chan_lock);
647 cifs_chan_clear_need_reconnect(ses, chan->server);
648 ses->chan_count--;
653 WARN_ON(ses->chan_count < 1);
654 spin_unlock(&ses->chan_lock);
666 static __u32 cifs_ssetup_hdr(struct cifs_ses *ses,
694 if (ses->capabilities & CAP_UNICODE) {
698 if (ses->capabilities & CAP_STATUS32) {
702 if (ses->capabilities & CAP_DFS) {
706 if (ses->capabilities & CAP_UNIX)
735 static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
742 if (ses->domainName == NULL) {
751 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->domainName,
759 static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
768 if (ses->user_name == NULL) {
773 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->user_name,
779 unicode_domain_string(&bcc_ptr, ses, nls_cp);
785 static void ascii_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
794 if (ses->user_name != NULL) {
795 len = strscpy(bcc_ptr, ses->user_name, CIFS_MAX_USERNAME_LEN);
805 if (ses->domainName != NULL) {
806 len = strscpy(bcc_ptr, ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
828 decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifs_ses *ses,
836 kfree(ses->serverOS);
837 ses->serverOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
838 cifs_dbg(FYI, "serverOS=%s\n", ses->serverOS);
845 kfree(ses->serverNOS);
846 ses->serverNOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
847 cifs_dbg(FYI, "serverNOS=%s\n", ses->serverNOS);
854 kfree(ses->serverDomain);
855 ses->serverDomain = cifs_strndup_from_utf16(data, bleft, true, nls_cp);
856 cifs_dbg(FYI, "serverDomain=%s\n", ses->serverDomain);
862 struct cifs_ses *ses,
874 kfree(ses->serverOS);
876 ses->serverOS = kmalloc(len + 1, GFP_KERNEL);
877 if (ses->serverOS) {
878 memcpy(ses->serverOS, bcc_ptr, len);
879 ses->serverOS[len] = 0;
880 if (strncmp(ses->serverOS, "OS/2", 4) == 0)
891 kfree(ses->serverNOS);
893 ses->serverNOS = kmalloc(len + 1, GFP_KERNEL);
894 if (ses->serverNOS) {
895 memcpy(ses->serverNOS, bcc_ptr, len);
896 ses->serverNOS[len] = 0;
919 struct cifs_ses *ses)
944 ses->ntlmssp->client_flags, server_flags);
946 if ((ses->ntlmssp->client_flags & (NTLMSSP_NEGOTIATE_SEAL | NTLMSSP_NEGOTIATE_SIGN)) &&
956 if (ses->server->sign && !(server_flags & NTLMSSP_NEGOTIATE_SIGN)) {
961 if ((ses->ntlmssp->client_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
966 ses->ntlmssp->server_flags = server_flags;
968 memcpy(ses->ntlmssp->cryptkey, pblob->Challenge, CIFS_CRYPTO_KEY_SIZE);
984 kfree_sensitive(ses->auth_key.response);
985 ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
987 if (!ses->auth_key.response) {
991 ses->auth_key.len = tilen;
997 static int size_of_ntlmssp_blob(struct cifs_ses *ses, int base_size)
999 int sz = base_size + ses->auth_key.len
1002 if (ses->domainName)
1003 sz += sizeof(__le16) * strnlen(ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
1007 if (ses->user_name)
1008 sz += sizeof(__le16) * strnlen(ses->user_name, CIFS_MAX_USERNAME_LEN);
1012 if (ses->workstation_name[0])
1013 sz += sizeof(__le16) * strnlen(ses->workstation_name,
1014 ntlmssp_workstation_name_size(ses));
1059 struct cifs_ses *ses,
1069 len = size_of_ntlmssp_blob(ses, sizeof(NEGOTIATE_MESSAGE));
1089 if (!server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
1093 ses->ntlmssp->client_flags = flags;
1121 struct cifs_ses *ses,
1131 len = size_of_ntlmssp_blob(ses, sizeof(struct negotiate_message));
1151 if (!server->session_estab || ses->ntlmssp->sesskey_per_smbsess)
1160 ses->ntlmssp->client_flags = flags;
1185 struct cifs_ses *ses,
1195 rc = setup_ntlmv2_rsp(ses, nls_cp);
1202 len = size_of_ntlmssp_blob(ses, sizeof(AUTHENTICATE_MESSAGE));
1216 flags = ses->ntlmssp->server_flags | NTLMSSP_REQUEST_TARGET |
1235 if (ses->user_name != NULL) {
1236 memcpy(tmp, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
1237 ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1238 tmp += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
1241 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1243 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1253 ses->domainName,
1259 ses->user_name,
1265 ses->workstation_name,
1266 ntlmssp_workstation_name_size(ses),
1270 if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
1271 (!ses->server->session_estab || ses->ntlmssp->sesskey_per_smbsess) &&
1272 !calc_seckey(ses)) {
1273 memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
1329 struct cifs_ses *ses;
1351 struct cifs_ses *ses = sess_data->ses;
1354 rc = small_smb_init_no_tc(SMB_COM_SESSION_SETUP_ANDX, wct, ses,
1405 struct cifs_ses *ses = sess_data->ses;
1412 kmemdup(ses->auth_key.response,
1413 ses->auth_key.len, GFP_KERNEL);
1419 ses->auth_key.len;
1442 rc = SendReceive2(sess_data->xid, sess_data->ses,
1459 struct cifs_ses *ses = sess_data->ses;
1472 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1479 if (ses->user_name != NULL) {
1481 rc = setup_ntlmv2_rsp(ses, sess_data->nls_cp);
1487 memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
1488 ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1489 bcc_ptr += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
1495 cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
1500 if (ses->capabilities & CAP_UNICODE) {
1505 unicode_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1507 ascii_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1530 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1531 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1545 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1548 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1557 kfree_sensitive(ses->auth_key.response);
1558 ses->auth_key.response = NULL;
1569 struct cifs_ses *ses = sess_data->ses;
1585 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1587 spnego_key = cifs_get_spnego_key(ses, server);
1606 kfree_sensitive(ses->auth_key.response);
1607 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
1609 if (!ses->auth_key.response) {
1615 ses->auth_key.len = msg->sesskey_len;
1624 if (ses->capabilities & CAP_UNICODE) {
1631 unicode_domain_string(&bcc_ptr, ses, sess_data->nls_cp);
1634 ascii_ssetup_strings(&bcc_ptr, ses, sess_data->nls_cp);
1656 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1657 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1681 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1684 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1696 kfree_sensitive(ses->auth_key.response);
1697 ses->auth_key.response = NULL;
1710 struct cifs_ses *ses = sess_data->ses;
1717 capabilities = cifs_ssetup_hdr(ses, server, pSMB);
1750 struct cifs_ses *ses = sess_data->ses;
1763 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL);
1764 if (!ses->ntlmssp) {
1768 ses->ntlmssp->sesskey_per_smbsess = false;
1779 &blob_len, ses, server,
1814 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
1815 cifs_dbg(FYI, "UID = %llu\n", ses->Suid);
1828 rc = decode_ntlmssp_challenge(bcc_ptr, blob_len, ses);
1841 kfree_sensitive(ses->auth_key.response);
1842 ses->auth_key.response = NULL;
1843 kfree_sensitive(ses->ntlmssp);
1844 ses->ntlmssp = NULL;
1856 struct cifs_ses *ses = sess_data->ses;
1874 &blob_len, ses, server,
1886 smb_buf->Uid = ses->Suid;
1907 if (ses->Suid != smb_buf->Uid) {
1908 ses->Suid = smb_buf->Uid;
1909 cifs_dbg(FYI, "UID changed! new UID = %llu\n", ses->Suid);
1934 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses,
1937 decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,
1950 kfree_sensitive(ses->auth_key.response);
1951 ses->auth_key.response = NULL;
1952 kfree_sensitive(ses->ntlmssp);
1953 ses->ntlmssp = NULL;
1962 struct cifs_ses *ses = sess_data->ses;
1965 type = cifs_select_sectype(server, ses->sectype);
1995 int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
2002 if (ses == NULL) {
2003 WARN(1, "%s: ses == NULL!", __func__);
2012 sess_data->ses = ses;