aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2013-08-23 14:02:24 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2013-08-30 09:19:36 -0400
commitbd4a3eb15bb42296e61d0fd16f2c7f8cc171b681 (patch)
tree9cfc756e5d3de8524757c188ae3df526e5942fba
parent41b6b4d0b88f80d04729a5286e838e972733db1e (diff)
RPCSEC_GSS: Clean up upcall message allocation
Optimise away gss_encode_msg: we don't need to look up the pipe version a second time. Save the gss target name in struct gss_auth. It is a property of the auth cache itself, and doesn't really belong in the rpc_client. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index fc2f78d6a9b4..b62812a224a8 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -84,6 +84,7 @@ struct gss_auth {
84 * backwards-compatibility with older gssd's. 84 * backwards-compatibility with older gssd's.
85 */ 85 */
86 struct rpc_pipe *pipe[2]; 86 struct rpc_pipe *pipe[2];
87 const char *target_name;
87}; 88};
88 89
89/* pipe_version >= 0 if and only if someone has a pipe open. */ 90/* pipe_version >= 0 if and only if someone has a pipe open. */
@@ -406,8 +407,8 @@ static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg)
406} 407}
407 408
408static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg, 409static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
409 struct rpc_clnt *clnt, 410 const char *service_name,
410 const char *service_name) 411 const char *target_name)
411{ 412{
412 struct gss_api_mech *mech = gss_msg->auth->mech; 413 struct gss_api_mech *mech = gss_msg->auth->mech;
413 char *p = gss_msg->databuf; 414 char *p = gss_msg->databuf;
@@ -417,8 +418,8 @@ static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
417 mech->gm_name, 418 mech->gm_name,
418 from_kuid(&init_user_ns, gss_msg->uid)); 419 from_kuid(&init_user_ns, gss_msg->uid));
419 p += gss_msg->msg.len; 420 p += gss_msg->msg.len;
420 if (clnt->cl_principal) { 421 if (target_name) {
421 len = sprintf(p, "target=%s ", clnt->cl_principal); 422 len = sprintf(p, "target=%s ", target_name);
422 p += len; 423 p += len;
423 gss_msg->msg.len += len; 424 gss_msg->msg.len += len;
424 } 425 }
@@ -439,19 +440,6 @@ static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
439 BUG_ON(gss_msg->msg.len > UPCALL_BUF_LEN); 440 BUG_ON(gss_msg->msg.len > UPCALL_BUF_LEN);
440} 441}
441 442
442static void gss_encode_msg(struct gss_upcall_msg *gss_msg,
443 struct rpc_clnt *clnt,
444 const char *service_name)
445{
446 struct net *net = rpc_net_ns(clnt);
447 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
448
449 if (sn->pipe_version == 0)
450 gss_encode_v0_msg(gss_msg);
451 else /* pipe_version == 1 */
452 gss_encode_v1_msg(gss_msg, clnt, service_name);
453}
454
455static struct gss_upcall_msg * 443static struct gss_upcall_msg *
456gss_alloc_msg(struct gss_auth *gss_auth, struct rpc_clnt *clnt, 444gss_alloc_msg(struct gss_auth *gss_auth, struct rpc_clnt *clnt,
457 kuid_t uid, const char *service_name) 445 kuid_t uid, const char *service_name)
@@ -474,7 +462,12 @@ gss_alloc_msg(struct gss_auth *gss_auth, struct rpc_clnt *clnt,
474 atomic_set(&gss_msg->count, 1); 462 atomic_set(&gss_msg->count, 1);
475 gss_msg->uid = uid; 463 gss_msg->uid = uid;
476 gss_msg->auth = gss_auth; 464 gss_msg->auth = gss_auth;
477 gss_encode_msg(gss_msg, clnt, service_name); 465 switch (vers) {
466 case 0:
467 gss_encode_v0_msg(gss_msg);
468 default:
469 gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name);
470 };
478 return gss_msg; 471 return gss_msg;
479} 472}
480 473
@@ -883,6 +876,12 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
883 return ERR_PTR(err); 876 return ERR_PTR(err);
884 if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL))) 877 if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL)))
885 goto out_dec; 878 goto out_dec;
879 gss_auth->target_name = NULL;
880 if (clnt->cl_principal) {
881 gss_auth->target_name = kstrdup(clnt->cl_principal, GFP_KERNEL);
882 if (gss_auth->target_name == NULL)
883 goto err_free;
884 }
886 gss_auth->client = clnt; 885 gss_auth->client = clnt;
887 err = -EINVAL; 886 err = -EINVAL;
888 gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor); 887 gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor);
@@ -937,6 +936,7 @@ err_destroy_pipe_1:
937err_put_mech: 936err_put_mech:
938 gss_mech_put(gss_auth->mech); 937 gss_mech_put(gss_auth->mech);
939err_free: 938err_free:
939 kfree(gss_auth->target_name);
940 kfree(gss_auth); 940 kfree(gss_auth);
941out_dec: 941out_dec:
942 module_put(THIS_MODULE); 942 module_put(THIS_MODULE);
@@ -950,6 +950,7 @@ gss_free(struct gss_auth *gss_auth)
950 rpc_destroy_pipe_data(gss_auth->pipe[0]); 950 rpc_destroy_pipe_data(gss_auth->pipe[0]);
951 rpc_destroy_pipe_data(gss_auth->pipe[1]); 951 rpc_destroy_pipe_data(gss_auth->pipe[1]);
952 gss_mech_put(gss_auth->mech); 952 gss_mech_put(gss_auth->mech);
953 kfree(gss_auth->target_name);
953 954
954 kfree(gss_auth); 955 kfree(gss_auth);
955 module_put(THIS_MODULE); 956 module_put(THIS_MODULE);