diff options
author | Pavel Shilovsky <piastry@etersoft.ru> | 2012-03-23 14:28:02 -0400 |
---|---|---|
committer | Jeff Layton <jlayton@redhat.com> | 2012-03-23 14:28:02 -0400 |
commit | d4e4854fd1c85ac8ba4d6de39703e07704754b85 (patch) | |
tree | 96cbc43691d2bbef4a03087a3d1ac8c26ffff827 /fs/cifs/connect.c | |
parent | 792af7b05b8a78def080ec757a4d4420b9fd0cc2 (diff) |
CIFS: Separate protocol-specific code from demultiplex code
Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
Diffstat (limited to 'fs/cifs/connect.c')
-rw-r--r-- | fs/cifs/connect.c | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 5560e1d5e54b..cb6e757feb52 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -183,8 +183,9 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
183 | -EINVAL = invalid transact2 | 183 | -EINVAL = invalid transact2 |
184 | 184 | ||
185 | */ | 185 | */ |
186 | static int check2ndT2(struct smb_hdr *pSMB) | 186 | static int check2ndT2(char *buf) |
187 | { | 187 | { |
188 | struct smb_hdr *pSMB = (struct smb_hdr *)buf; | ||
188 | struct smb_t2_rsp *pSMBt; | 189 | struct smb_t2_rsp *pSMBt; |
189 | int remaining; | 190 | int remaining; |
190 | __u16 total_data_size, data_in_this_rsp; | 191 | __u16 total_data_size, data_in_this_rsp; |
@@ -224,10 +225,10 @@ static int check2ndT2(struct smb_hdr *pSMB) | |||
224 | return remaining; | 225 | return remaining; |
225 | } | 226 | } |
226 | 227 | ||
227 | static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) | 228 | static int coalesce_t2(char *second_buf, struct smb_hdr *target_hdr) |
228 | { | 229 | { |
229 | struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)psecond; | 230 | struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)second_buf; |
230 | struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB; | 231 | struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)target_hdr; |
231 | char *data_area_of_tgt; | 232 | char *data_area_of_tgt; |
232 | char *data_area_of_src; | 233 | char *data_area_of_src; |
233 | int remaining; | 234 | int remaining; |
@@ -280,23 +281,23 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) | |||
280 | put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount); | 281 | put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount); |
281 | 282 | ||
282 | /* fix up the BCC */ | 283 | /* fix up the BCC */ |
283 | byte_count = get_bcc(pTargetSMB); | 284 | byte_count = get_bcc(target_hdr); |
284 | byte_count += total_in_src; | 285 | byte_count += total_in_src; |
285 | /* is the result too big for the field? */ | 286 | /* is the result too big for the field? */ |
286 | if (byte_count > USHRT_MAX) { | 287 | if (byte_count > USHRT_MAX) { |
287 | cFYI(1, "coalesced BCC too large (%u)", byte_count); | 288 | cFYI(1, "coalesced BCC too large (%u)", byte_count); |
288 | return -EPROTO; | 289 | return -EPROTO; |
289 | } | 290 | } |
290 | put_bcc(byte_count, pTargetSMB); | 291 | put_bcc(byte_count, target_hdr); |
291 | 292 | ||
292 | byte_count = be32_to_cpu(pTargetSMB->smb_buf_length); | 293 | byte_count = be32_to_cpu(target_hdr->smb_buf_length); |
293 | byte_count += total_in_src; | 294 | byte_count += total_in_src; |
294 | /* don't allow buffer to overflow */ | 295 | /* don't allow buffer to overflow */ |
295 | if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { | 296 | if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
296 | cFYI(1, "coalesced BCC exceeds buffer size (%u)", byte_count); | 297 | cFYI(1, "coalesced BCC exceeds buffer size (%u)", byte_count); |
297 | return -ENOBUFS; | 298 | return -ENOBUFS; |
298 | } | 299 | } |
299 | pTargetSMB->smb_buf_length = cpu_to_be32(byte_count); | 300 | target_hdr->smb_buf_length = cpu_to_be32(byte_count); |
300 | 301 | ||
301 | /* copy second buffer into end of first buffer */ | 302 | /* copy second buffer into end of first buffer */ |
302 | memcpy(data_area_of_tgt, data_area_of_src, total_in_src); | 303 | memcpy(data_area_of_tgt, data_area_of_src, total_in_src); |
@@ -337,6 +338,18 @@ requeue_echo: | |||
337 | queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL); | 338 | queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL); |
338 | } | 339 | } |
339 | 340 | ||
341 | static inline size_t | ||
342 | header_size(void) | ||
343 | { | ||
344 | return sizeof(struct smb_hdr); | ||
345 | } | ||
346 | |||
347 | static inline size_t | ||
348 | max_header_size(void) | ||
349 | { | ||
350 | return MAX_CIFS_HDR_SIZE; | ||
351 | } | ||
352 | |||
340 | static bool | 353 | static bool |
341 | allocate_buffers(struct TCP_Server_Info *server) | 354 | allocate_buffers(struct TCP_Server_Info *server) |
342 | { | 355 | { |
@@ -350,7 +363,7 @@ allocate_buffers(struct TCP_Server_Info *server) | |||
350 | } | 363 | } |
351 | } else if (server->large_buf) { | 364 | } else if (server->large_buf) { |
352 | /* we are reusing a dirty large buf, clear its start */ | 365 | /* we are reusing a dirty large buf, clear its start */ |
353 | memset(server->bigbuf, 0, sizeof(struct smb_hdr)); | 366 | memset(server->bigbuf, 0, header_size()); |
354 | } | 367 | } |
355 | 368 | ||
356 | if (!server->smallbuf) { | 369 | if (!server->smallbuf) { |
@@ -364,7 +377,7 @@ allocate_buffers(struct TCP_Server_Info *server) | |||
364 | /* beginning of smb buffer is cleared in our buf_get */ | 377 | /* beginning of smb buffer is cleared in our buf_get */ |
365 | } else { | 378 | } else { |
366 | /* if existing small buf clear beginning */ | 379 | /* if existing small buf clear beginning */ |
367 | memset(server->smallbuf, 0, sizeof(struct smb_hdr)); | 380 | memset(server->smallbuf, 0, header_size()); |
368 | } | 381 | } |
369 | 382 | ||
370 | return true; | 383 | return true; |
@@ -566,8 +579,9 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) | |||
566 | } | 579 | } |
567 | 580 | ||
568 | static struct mid_q_entry * | 581 | static struct mid_q_entry * |
569 | find_mid(struct TCP_Server_Info *server, struct smb_hdr *buf) | 582 | find_mid(struct TCP_Server_Info *server, char *buffer) |
570 | { | 583 | { |
584 | struct smb_hdr *buf = (struct smb_hdr *)buffer; | ||
571 | struct mid_q_entry *mid; | 585 | struct mid_q_entry *mid; |
572 | 586 | ||
573 | spin_lock(&GlobalMid_Lock); | 587 | spin_lock(&GlobalMid_Lock); |
@@ -600,7 +614,7 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed) | |||
600 | 614 | ||
601 | static void | 615 | static void |
602 | handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, | 616 | handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
603 | struct smb_hdr *buf, int malformed) | 617 | char *buf, int malformed) |
604 | { | 618 | { |
605 | if (malformed == 0 && check2ndT2(buf) > 0) { | 619 | if (malformed == 0 && check2ndT2(buf) > 0) { |
606 | mid->multiRsp = true; | 620 | mid->multiRsp = true; |
@@ -731,11 +745,10 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
731 | { | 745 | { |
732 | int length; | 746 | int length; |
733 | char *buf = server->smallbuf; | 747 | char *buf = server->smallbuf; |
734 | struct smb_hdr *smb_buffer = (struct smb_hdr *)buf; | 748 | unsigned int pdu_length = get_rfc1002_length(buf); |
735 | unsigned int pdu_length = be32_to_cpu(smb_buffer->smb_buf_length); | ||
736 | 749 | ||
737 | /* make sure this will fit in a large buffer */ | 750 | /* make sure this will fit in a large buffer */ |
738 | if (pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { | 751 | if (pdu_length > CIFSMaxBufSize + max_header_size() - 4) { |
739 | cERROR(1, "SMB response too long (%u bytes)", | 752 | cERROR(1, "SMB response too long (%u bytes)", |
740 | pdu_length); | 753 | pdu_length); |
741 | cifs_reconnect(server); | 754 | cifs_reconnect(server); |
@@ -746,20 +759,18 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
746 | /* switch to large buffer if too big for a small one */ | 759 | /* switch to large buffer if too big for a small one */ |
747 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { | 760 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { |
748 | server->large_buf = true; | 761 | server->large_buf = true; |
749 | memcpy(server->bigbuf, server->smallbuf, server->total_read); | 762 | memcpy(server->bigbuf, buf, server->total_read); |
750 | buf = server->bigbuf; | 763 | buf = server->bigbuf; |
751 | smb_buffer = (struct smb_hdr *)buf; | ||
752 | } | 764 | } |
753 | 765 | ||
754 | /* now read the rest */ | 766 | /* now read the rest */ |
755 | length = cifs_read_from_socket(server, | 767 | length = cifs_read_from_socket(server, buf + header_size() - 1, |
756 | buf + sizeof(struct smb_hdr) - 1, | 768 | pdu_length - header_size() + 1 + 4); |
757 | pdu_length - sizeof(struct smb_hdr) + 1 + 4); | ||
758 | if (length < 0) | 769 | if (length < 0) |
759 | return length; | 770 | return length; |
760 | server->total_read += length; | 771 | server->total_read += length; |
761 | 772 | ||
762 | dump_smb(smb_buffer, server->total_read); | 773 | dump_smb(buf, server->total_read); |
763 | 774 | ||
764 | /* | 775 | /* |
765 | * We know that we received enough to get to the MID as we | 776 | * We know that we received enough to get to the MID as we |
@@ -770,7 +781,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
770 | * 48 bytes is enough to display the header and a little bit | 781 | * 48 bytes is enough to display the header and a little bit |
771 | * into the payload for debugging purposes. | 782 | * into the payload for debugging purposes. |
772 | */ | 783 | */ |
773 | length = checkSMB(smb_buffer, smb_buffer->Mid, server->total_read); | 784 | length = checkSMB(buf, server->total_read); |
774 | if (length != 0) | 785 | if (length != 0) |
775 | cifs_dump_mem("Bad SMB: ", buf, | 786 | cifs_dump_mem("Bad SMB: ", buf, |
776 | min_t(unsigned int, server->total_read, 48)); | 787 | min_t(unsigned int, server->total_read, 48)); |
@@ -778,7 +789,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
778 | if (!mid) | 789 | if (!mid) |
779 | return length; | 790 | return length; |
780 | 791 | ||
781 | handle_mid(mid, server, smb_buffer, length); | 792 | handle_mid(mid, server, buf, length); |
782 | return 0; | 793 | return 0; |
783 | } | 794 | } |
784 | 795 | ||
@@ -789,7 +800,6 @@ cifs_demultiplex_thread(void *p) | |||
789 | struct TCP_Server_Info *server = p; | 800 | struct TCP_Server_Info *server = p; |
790 | unsigned int pdu_length; | 801 | unsigned int pdu_length; |
791 | char *buf = NULL; | 802 | char *buf = NULL; |
792 | struct smb_hdr *smb_buffer = NULL; | ||
793 | struct task_struct *task_to_wake = NULL; | 803 | struct task_struct *task_to_wake = NULL; |
794 | struct mid_q_entry *mid_entry; | 804 | struct mid_q_entry *mid_entry; |
795 | 805 | ||
@@ -810,7 +820,6 @@ cifs_demultiplex_thread(void *p) | |||
810 | continue; | 820 | continue; |
811 | 821 | ||
812 | server->large_buf = false; | 822 | server->large_buf = false; |
813 | smb_buffer = (struct smb_hdr *)server->smallbuf; | ||
814 | buf = server->smallbuf; | 823 | buf = server->smallbuf; |
815 | pdu_length = 4; /* enough to get RFC1001 header */ | 824 | pdu_length = 4; /* enough to get RFC1001 header */ |
816 | 825 | ||
@@ -823,14 +832,14 @@ cifs_demultiplex_thread(void *p) | |||
823 | * The right amount was read from socket - 4 bytes, | 832 | * The right amount was read from socket - 4 bytes, |
824 | * so we can now interpret the length field. | 833 | * so we can now interpret the length field. |
825 | */ | 834 | */ |
826 | pdu_length = be32_to_cpu(smb_buffer->smb_buf_length); | 835 | pdu_length = get_rfc1002_length(buf); |
827 | 836 | ||
828 | cFYI(1, "RFC1002 header 0x%x", pdu_length); | 837 | cFYI(1, "RFC1002 header 0x%x", pdu_length); |
829 | if (!is_smb_response(server, buf[0])) | 838 | if (!is_smb_response(server, buf[0])) |
830 | continue; | 839 | continue; |
831 | 840 | ||
832 | /* make sure we have enough to get to the MID */ | 841 | /* make sure we have enough to get to the MID */ |
833 | if (pdu_length < sizeof(struct smb_hdr) - 1 - 4) { | 842 | if (pdu_length < header_size() - 1 - 4) { |
834 | cERROR(1, "SMB response too short (%u bytes)", | 843 | cERROR(1, "SMB response too short (%u bytes)", |
835 | pdu_length); | 844 | pdu_length); |
836 | cifs_reconnect(server); | 845 | cifs_reconnect(server); |
@@ -840,12 +849,12 @@ cifs_demultiplex_thread(void *p) | |||
840 | 849 | ||
841 | /* read down to the MID */ | 850 | /* read down to the MID */ |
842 | length = cifs_read_from_socket(server, buf + 4, | 851 | length = cifs_read_from_socket(server, buf + 4, |
843 | sizeof(struct smb_hdr) - 1 - 4); | 852 | header_size() - 1 - 4); |
844 | if (length < 0) | 853 | if (length < 0) |
845 | continue; | 854 | continue; |
846 | server->total_read += length; | 855 | server->total_read += length; |
847 | 856 | ||
848 | mid_entry = find_mid(server, smb_buffer); | 857 | mid_entry = find_mid(server, buf); |
849 | 858 | ||
850 | if (!mid_entry || !mid_entry->receive) | 859 | if (!mid_entry || !mid_entry->receive) |
851 | length = standard_receive3(server, mid_entry); | 860 | length = standard_receive3(server, mid_entry); |
@@ -855,22 +864,19 @@ cifs_demultiplex_thread(void *p) | |||
855 | if (length < 0) | 864 | if (length < 0) |
856 | continue; | 865 | continue; |
857 | 866 | ||
858 | if (server->large_buf) { | 867 | if (server->large_buf) |
859 | buf = server->bigbuf; | 868 | buf = server->bigbuf; |
860 | smb_buffer = (struct smb_hdr *)buf; | ||
861 | } | ||
862 | 869 | ||
863 | server->lstrp = jiffies; | 870 | server->lstrp = jiffies; |
864 | if (mid_entry != NULL) { | 871 | if (mid_entry != NULL) { |
865 | if (!mid_entry->multiRsp || mid_entry->multiEnd) | 872 | if (!mid_entry->multiRsp || mid_entry->multiEnd) |
866 | mid_entry->callback(mid_entry); | 873 | mid_entry->callback(mid_entry); |
867 | } else if (!is_valid_oplock_break(smb_buffer, server)) { | 874 | } else if (!is_valid_oplock_break(buf, server)) { |
868 | cERROR(1, "No task to wake, unknown frame received! " | 875 | cERROR(1, "No task to wake, unknown frame received! " |
869 | "NumMids %d", atomic_read(&midCount)); | 876 | "NumMids %d", atomic_read(&midCount)); |
870 | cifs_dump_mem("Received Data is: ", buf, | 877 | cifs_dump_mem("Received Data is: ", buf, header_size()); |
871 | sizeof(struct smb_hdr)); | ||
872 | #ifdef CONFIG_CIFS_DEBUG2 | 878 | #ifdef CONFIG_CIFS_DEBUG2 |
873 | cifs_dump_detail(smb_buffer); | 879 | cifs_dump_detail(buf); |
874 | cifs_dump_mids(server); | 880 | cifs_dump_mids(server); |
875 | #endif /* CIFS_DEBUG2 */ | 881 | #endif /* CIFS_DEBUG2 */ |
876 | 882 | ||