SUNRPC: Add a server-side API for retrieving an RPC's pseudoflavor
authorChuck Lever <chuck.lever@oracle.com>
Fri, 17 Nov 2023 22:14:27 +0000 (17:14 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Sun, 7 Jan 2024 22:54:25 +0000 (17:54 -0500)
NFSD will use this new API to determine whether nfsd_splice_read is
safe to use. This avoids the need to add a dependency to NFSD for
CONFIG_SUNRPC_GSS.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
include/linux/sunrpc/svcauth.h
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/svcauth.c

index 6f90203edbf8d9d82376136deb4409d8128a24b7..61c455f1e1f50feff85368c08d2acc5d054018f8 100644 (file)
@@ -131,8 +131,11 @@ enum svc_auth_status {
  *   This call releases a domain.
  *
  * set_client()
- *   Givens a pending request (struct svc_rqst), finds and assigns
+ *   Given a pending request (struct svc_rqst), finds and assigns
  *   an appropriate 'auth_domain' as the client.
+ *
+ * pseudoflavor()
+ *   Returns RPC_AUTH pseudoflavor in use by @rqstp.
  */
 struct auth_ops {
        char *  name;
@@ -143,11 +146,13 @@ struct auth_ops {
        int                     (*release)(struct svc_rqst *rqstp);
        void                    (*domain_release)(struct auth_domain *dom);
        enum svc_auth_status    (*set_client)(struct svc_rqst *rqstp);
+       rpc_authflavor_t        (*pseudoflavor)(struct svc_rqst *rqstp);
 };
 
 struct svc_xprt;
 
 extern enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
+extern rpc_authflavor_t svc_auth_flavor(struct svc_rqst *rqstp);
 extern int     svc_authorise(struct svc_rqst *rqstp);
 extern enum svc_auth_status svc_set_client(struct svc_rqst *rqstp);
 extern int     svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
index 18734e70c5ddb19d75809cc252499404b0a37f69..104d9a32014263c045a7d9d06efa1e20cb4d3f71 100644 (file)
@@ -2014,6 +2014,11 @@ svcauth_gss_domain_release(struct auth_domain *dom)
        call_rcu(&dom->rcu_head, svcauth_gss_domain_release_rcu);
 }
 
+static rpc_authflavor_t svcauth_gss_pseudoflavor(struct svc_rqst *rqstp)
+{
+       return svcauth_gss_flavor(rqstp->rq_gssclient);
+}
+
 static struct auth_ops svcauthops_gss = {
        .name           = "rpcsec_gss",
        .owner          = THIS_MODULE,
@@ -2022,6 +2027,7 @@ static struct auth_ops svcauthops_gss = {
        .release        = svcauth_gss_release,
        .domain_release = svcauth_gss_domain_release,
        .set_client     = svcauth_gss_set_client,
+       .pseudoflavor   = svcauth_gss_pseudoflavor,
 };
 
 static int rsi_cache_create_net(struct net *net)
index aa4429d0b8106ab53479ebf6aa9419f429b2613a..1619211f0960afbfdac1a22617a3e74f437672e1 100644 (file)
@@ -160,6 +160,22 @@ svc_auth_unregister(rpc_authflavor_t flavor)
 }
 EXPORT_SYMBOL_GPL(svc_auth_unregister);
 
+/**
+ * svc_auth_flavor - return RPC transaction's RPC_AUTH flavor
+ * @rqstp: RPC transaction context
+ *
+ * Returns an RPC flavor or GSS pseudoflavor.
+ */
+rpc_authflavor_t svc_auth_flavor(struct svc_rqst *rqstp)
+{
+       struct auth_ops *aops = rqstp->rq_authop;
+
+       if (!aops->pseudoflavor)
+               return aops->flavour;
+       return aops->pseudoflavor(rqstp);
+}
+EXPORT_SYMBOL_GPL(svc_auth_flavor);
+
 /**************************************************
  * 'auth_domains' are stored in a hash table indexed by name.
  * When the last reference to an 'auth_domain' is dropped,