]>
Commit | Line | Data |
---|---|---|
ef1eac0a | 1 | /* |
647e18e3 | 2 | * Copyright (c) 2016 Oracle. All rights reserved. |
ef1eac0a TT |
3 | * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved. |
4 | * | |
5 | * This software is available to you under a choice of one of two | |
6 | * licenses. You may choose to be licensed under the terms of the GNU | |
7 | * General Public License (GPL) Version 2, available from the file | |
8 | * COPYING in the main directory of this source tree, or the BSD-type | |
9 | * license below: | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * | |
15 | * Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions and the following disclaimer. | |
17 | * | |
18 | * Redistributions in binary form must reproduce the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer in the documentation and/or other materials provided | |
21 | * with the distribution. | |
22 | * | |
23 | * Neither the name of the Network Appliance, Inc. nor the names of | |
24 | * its contributors may be used to endorse or promote products | |
25 | * derived from this software without specific prior written | |
26 | * permission. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
39 | * | |
40 | * Author: Tom Tucker <tom@opengridcomputing.com> | |
41 | */ | |
42 | ||
43 | #include <linux/sunrpc/xdr.h> | |
44 | #include <linux/sunrpc/debug.h> | |
45 | #include <asm/unaligned.h> | |
46 | #include <linux/sunrpc/rpc_rdma.h> | |
47 | #include <linux/sunrpc/svc_rdma.h> | |
48 | ||
49 | #define RPCDBG_FACILITY RPCDBG_SVCXPRT | |
50 | ||
647e18e3 | 51 | static __be32 *xdr_check_read_list(__be32 *p, __be32 *end) |
ef1eac0a | 52 | { |
647e18e3 | 53 | __be32 *next; |
ef1eac0a | 54 | |
647e18e3 CL |
55 | while (*p++ != xdr_zero) { |
56 | next = p + rpcrdma_readchunk_maxsz - 1; | |
57 | if (next > end) | |
ef1eac0a | 58 | return NULL; |
647e18e3 | 59 | p = next; |
ef1eac0a | 60 | } |
647e18e3 | 61 | return p; |
ef1eac0a TT |
62 | } |
63 | ||
647e18e3 | 64 | static __be32 *xdr_check_write_list(__be32 *p, __be32 *end) |
ef1eac0a | 65 | { |
647e18e3 | 66 | __be32 *next; |
ef1eac0a | 67 | |
647e18e3 CL |
68 | while (*p++ != xdr_zero) { |
69 | next = p + 1 + be32_to_cpup(p) * rpcrdma_segment_maxsz; | |
70 | if (next > end) | |
71 | return NULL; | |
72 | p = next; | |
ef1eac0a | 73 | } |
647e18e3 | 74 | return p; |
ef1eac0a TT |
75 | } |
76 | ||
647e18e3 | 77 | static __be32 *xdr_check_reply_chunk(__be32 *p, __be32 *end) |
ef1eac0a | 78 | { |
647e18e3 CL |
79 | __be32 *next; |
80 | ||
81 | if (*p++ != xdr_zero) { | |
82 | next = p + 1 + be32_to_cpup(p) * rpcrdma_segment_maxsz; | |
83 | if (next > end) | |
84 | return NULL; | |
85 | p = next; | |
ef1eac0a | 86 | } |
647e18e3 | 87 | return p; |
ef1eac0a TT |
88 | } |
89 | ||
d9e4084f CL |
90 | /** |
91 | * svc_rdma_xdr_decode_req - Parse incoming RPC-over-RDMA header | |
92 | * @rq_arg: Receive buffer | |
93 | * | |
94 | * On entry, xdr->head[0].iov_base points to first byte in the | |
95 | * RPC-over-RDMA header. | |
96 | * | |
97 | * On successful exit, head[0] points to first byte past the | |
98 | * RPC-over-RDMA header. For RDMA_MSG, this is the RPC message. | |
99 | * The length of the RPC-over-RDMA header is returned. | |
100 | */ | |
101 | int svc_rdma_xdr_decode_req(struct xdr_buf *rq_arg) | |
ef1eac0a | 102 | { |
647e18e3 CL |
103 | __be32 *p, *end, *rdma_argp; |
104 | unsigned int hdr_len; | |
ef1eac0a | 105 | |
ef1eac0a | 106 | /* Verify that there's enough bytes for header + something */ |
647e18e3 CL |
107 | if (rq_arg->len <= RPCRDMA_HDRLEN_ERR) |
108 | goto out_short; | |
ef1eac0a | 109 | |
647e18e3 CL |
110 | rdma_argp = rq_arg->head[0].iov_base; |
111 | if (*(rdma_argp + 1) != rpcrdma_version) | |
112 | goto out_version; | |
a0544c94 | 113 | |
647e18e3 CL |
114 | switch (*(rdma_argp + 3)) { |
115 | case rdma_msg: | |
116 | case rdma_nomsg: | |
a0544c94 | 117 | break; |
ef1eac0a | 118 | |
647e18e3 CL |
119 | case rdma_done: |
120 | goto out_drop; | |
ef1eac0a | 121 | |
647e18e3 CL |
122 | case rdma_error: |
123 | goto out_drop; | |
124 | ||
125 | default: | |
126 | goto out_proc; | |
a0544c94 | 127 | } |
ef1eac0a | 128 | |
647e18e3 CL |
129 | end = (__be32 *)((unsigned long)rdma_argp + rq_arg->len); |
130 | p = xdr_check_read_list(rdma_argp + 4, end); | |
131 | if (!p) | |
132 | goto out_inval; | |
133 | p = xdr_check_write_list(p, end); | |
134 | if (!p) | |
135 | goto out_inval; | |
136 | p = xdr_check_reply_chunk(p, end); | |
137 | if (!p) | |
138 | goto out_inval; | |
139 | if (p > end) | |
140 | goto out_inval; | |
141 | ||
142 | rq_arg->head[0].iov_base = p; | |
143 | hdr_len = (unsigned long)p - (unsigned long)rdma_argp; | |
d9e4084f | 144 | rq_arg->head[0].iov_len -= hdr_len; |
ef1eac0a | 145 | return hdr_len; |
647e18e3 CL |
146 | |
147 | out_short: | |
148 | dprintk("svcrdma: header too short = %d\n", rq_arg->len); | |
149 | return -EINVAL; | |
150 | ||
151 | out_version: | |
152 | dprintk("svcrdma: bad xprt version: %u\n", | |
153 | be32_to_cpup(rdma_argp + 1)); | |
154 | return -EPROTONOSUPPORT; | |
155 | ||
156 | out_drop: | |
157 | dprintk("svcrdma: dropping RDMA_DONE/ERROR message\n"); | |
158 | return 0; | |
159 | ||
160 | out_proc: | |
161 | dprintk("svcrdma: bad rdma procedure (%u)\n", | |
162 | be32_to_cpup(rdma_argp + 3)); | |
163 | return -EINVAL; | |
164 | ||
165 | out_inval: | |
166 | dprintk("svcrdma: failed to parse transport header\n"); | |
167 | return -EINVAL; | |
ef1eac0a | 168 | } |