aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/sunrpc/svcsock.h12
-rw-r--r--net/sunrpc/svcsock.c26
2 files changed, 22 insertions, 16 deletions
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 92ad02f0dcc0..613cf42227aa 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -26,11 +26,21 @@ struct svc_sock {
26 void (*sk_owspace)(struct sock *); 26 void (*sk_owspace)(struct sock *);
27 27
28 /* private TCP part */ 28 /* private TCP part */
29 u32 sk_reclen; /* length of record */ 29 __be32 sk_reclen; /* length of record */
30 u32 sk_tcplen; /* current read length */ 30 u32 sk_tcplen; /* current read length */
31 struct page * sk_pages[RPCSVC_MAXPAGES]; /* received data */ 31 struct page * sk_pages[RPCSVC_MAXPAGES]; /* received data */
32}; 32};
33 33
34static inline u32 svc_sock_reclen(struct svc_sock *svsk)
35{
36 return ntohl(svsk->sk_reclen) & RPC_FRAGMENT_SIZE_MASK;
37}
38
39static inline u32 svc_sock_final_rec(struct svc_sock *svsk)
40{
41 return ntohl(svsk->sk_reclen) & RPC_LAST_STREAM_FRAGMENT;
42}
43
34/* 44/*
35 * Function prototypes. 45 * Function prototypes.
36 */ 46 */
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 03827cef1fa7..d50de2b95036 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -950,8 +950,7 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
950 return -EAGAIN; 950 return -EAGAIN;
951 } 951 }
952 952
953 svsk->sk_reclen = ntohl(svsk->sk_reclen); 953 if (!(svc_sock_final_rec(svsk))) {
954 if (!(svsk->sk_reclen & RPC_LAST_STREAM_FRAGMENT)) {
955 /* FIXME: technically, a record can be fragmented, 954 /* FIXME: technically, a record can be fragmented,
956 * and non-terminal fragments will not have the top 955 * and non-terminal fragments will not have the top
957 * bit set in the fragment length header. 956 * bit set in the fragment length header.
@@ -961,21 +960,18 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
961 goto err_delete; 960 goto err_delete;
962 } 961 }
963 962
964 svsk->sk_reclen &= RPC_FRAGMENT_SIZE_MASK; 963 dprintk("svc: TCP record, %d bytes\n", svc_sock_reclen(svsk));
965 dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen); 964 if (svc_sock_reclen(svsk) > serv->sv_max_mesg) {
966 if (svsk->sk_reclen > serv->sv_max_mesg) {
967 net_notice_ratelimited("RPC: fragment too large: 0x%08lx\n", 965 net_notice_ratelimited("RPC: fragment too large: 0x%08lx\n",
968 (unsigned long)svsk->sk_reclen); 966 (unsigned long)svc_sock_reclen(svsk));
969 goto err_delete; 967 goto err_delete;
970 } 968 }
971 } 969 }
972 970
973 if (svsk->sk_reclen < 8) 971 if (svc_sock_reclen(svsk) < 8)
974 goto err_delete; /* client is nuts. */ 972 goto err_delete; /* client is nuts. */
975 973
976 len = svsk->sk_reclen; 974 return svc_sock_reclen(svsk);
977
978 return len;
979error: 975error:
980 dprintk("RPC: TCP recv_record got %d\n", len); 976 dprintk("RPC: TCP recv_record got %d\n", len);
981 return len; 977 return len;
@@ -1019,7 +1015,7 @@ static int receive_cb_reply(struct svc_sock *svsk, struct svc_rqst *rqstp)
1019 if (dst->iov_len < src->iov_len) 1015 if (dst->iov_len < src->iov_len)
1020 return -EAGAIN; /* whatever; just giving up. */ 1016 return -EAGAIN; /* whatever; just giving up. */
1021 memcpy(dst->iov_base, src->iov_base, src->iov_len); 1017 memcpy(dst->iov_base, src->iov_base, src->iov_len);
1022 xprt_complete_rqst(req->rq_task, svsk->sk_reclen); 1018 xprt_complete_rqst(req->rq_task, rqstp->rq_arg.len);
1023 rqstp->rq_arg.len = 0; 1019 rqstp->rq_arg.len = 0;
1024 return 0; 1020 return 0;
1025} 1021}
@@ -1064,12 +1060,12 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
1064 goto error; 1060 goto error;
1065 1061
1066 base = svc_tcp_restore_pages(svsk, rqstp); 1062 base = svc_tcp_restore_pages(svsk, rqstp);
1067 want = svsk->sk_reclen - base; 1063 want = svc_sock_reclen(svsk) - base;
1068 1064
1069 vec = rqstp->rq_vec; 1065 vec = rqstp->rq_vec;
1070 1066
1071 pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0], 1067 pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0],
1072 svsk->sk_reclen); 1068 svc_sock_reclen(svsk));
1073 1069
1074 rqstp->rq_respages = &rqstp->rq_pages[pnum]; 1070 rqstp->rq_respages = &rqstp->rq_pages[pnum];
1075 1071
@@ -1082,11 +1078,11 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
1082 if (len < 0 && len != -EAGAIN) 1078 if (len < 0 && len != -EAGAIN)
1083 goto err_other; 1079 goto err_other;
1084 dprintk("svc: incomplete TCP record (%d of %d)\n", 1080 dprintk("svc: incomplete TCP record (%d of %d)\n",
1085 svsk->sk_tcplen, svsk->sk_reclen); 1081 svsk->sk_tcplen, svc_sock_reclen(svsk));
1086 goto err_noclose; 1082 goto err_noclose;
1087 } 1083 }
1088 1084
1089 rqstp->rq_arg.len = svsk->sk_reclen; 1085 rqstp->rq_arg.len = svc_sock_reclen(svsk);
1090 rqstp->rq_arg.page_base = 0; 1086 rqstp->rq_arg.page_base = 0;
1091 if (rqstp->rq_arg.len <= rqstp->rq_arg.head[0].iov_len) { 1087 if (rqstp->rq_arg.len <= rqstp->rq_arg.head[0].iov_len) {
1092 rqstp->rq_arg.head[0].iov_len = rqstp->rq_arg.len; 1088 rqstp->rq_arg.head[0].iov_len = rqstp->rq_arg.len;