Skip to content

Commit 5000531

Browse files
chuckleverTrond Myklebust
authored andcommitted
SUNRPC: Plumb an API for setting transport layer security
Add an initial set of policies along with fields for upper layers to pass the requested policy down to the transport layer. Signed-off-by: Chuck Lever <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 9e8ab85 commit 5000531

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/linux/sunrpc/clnt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct rpc_clnt {
5858
cl_noretranstimeo: 1,/* No retransmit timeouts */
5959
cl_autobind : 1,/* use getport() */
6060
cl_chatty : 1;/* be verbose */
61+
struct xprtsec_parms cl_xprtsec; /* transport security policy */
6162

6263
struct rpc_rtt * cl_rtt; /* RTO estimator data */
6364
const struct rpc_timeout *cl_timeout; /* Timeout strategy */
@@ -139,6 +140,7 @@ struct rpc_create_args {
139140
struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
140141
const struct cred *cred;
141142
unsigned int max_connect;
143+
struct xprtsec_parms xprtsec;
142144
};
143145

144146
struct rpc_add_xprt_test {

include/linux/sunrpc/xprt.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ struct rpc_rqst {
129129
#define rq_svec rq_snd_buf.head
130130
#define rq_slen rq_snd_buf.len
131131

132+
/* RPC transport layer security policies */
133+
enum xprtsec_policies {
134+
RPC_XPRTSEC_NONE = 0,
135+
RPC_XPRTSEC_TLS_ANON,
136+
RPC_XPRTSEC_TLS_X509,
137+
};
138+
139+
struct xprtsec_parms {
140+
enum xprtsec_policies policy;
141+
142+
/* authentication material */
143+
key_serial_t cert_serial;
144+
key_serial_t privkey_serial;
145+
};
146+
132147
struct rpc_xprt_ops {
133148
void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize);
134149
int (*reserve_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
@@ -229,6 +244,7 @@ struct rpc_xprt {
229244
*/
230245
unsigned long bind_timeout,
231246
reestablish_timeout;
247+
struct xprtsec_parms xprtsec;
232248
unsigned int connect_cookie; /* A cookie that gets bumped
233249
every time the transport
234250
is reconnected */
@@ -333,6 +349,7 @@ struct xprt_create {
333349
struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
334350
struct rpc_xprt_switch *bc_xps;
335351
unsigned int flags;
352+
struct xprtsec_parms xprtsec;
336353
};
337354

338355
struct xprt_class {

net/sunrpc/clnt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args,
385385
if (!clnt)
386386
goto out_err;
387387
clnt->cl_parent = parent ? : clnt;
388+
clnt->cl_xprtsec = args->xprtsec;
388389

389390
err = rpc_alloc_clid(clnt);
390391
if (err)
@@ -532,6 +533,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
532533
.addrlen = args->addrsize,
533534
.servername = args->servername,
534535
.bc_xprt = args->bc_xprt,
536+
.xprtsec = args->xprtsec,
535537
};
536538
char servername[48];
537539
struct rpc_clnt *clnt;
@@ -731,6 +733,7 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
731733
struct rpc_clnt *parent;
732734
int err;
733735

736+
args->xprtsec = clnt->cl_xprtsec;
734737
xprt = xprt_create_transport(args);
735738
if (IS_ERR(xprt))
736739
return PTR_ERR(xprt);
@@ -3050,6 +3053,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
30503053

30513054
if (!xprtargs->ident)
30523055
xprtargs->ident = ident;
3056+
xprtargs->xprtsec = clnt->cl_xprtsec;
30533057
xprt = xprt_create_transport(xprtargs);
30543058
if (IS_ERR(xprt)) {
30553059
ret = PTR_ERR(xprt);

0 commit comments

Comments
 (0)