net/sunrpc/auth.c
Source file repositories/reference/linux-study-clean/net/sunrpc/auth.c
File Facts
- System
- Linux kernel
- Corpus path
net/sunrpc/auth.c- Extension
.c- Size
- 21438 bytes
- Lines
- 898
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/sched.hlinux/cred.hlinux/module.hlinux/slab.hlinux/errno.hlinux/hash.hlinux/sunrpc/clnt.hlinux/sunrpc/gss_api.hlinux/spinlock.htrace/events/sunrpc.h
Detected Declarations
struct rpc_cred_cachefunction param_set_hashtbl_szfunction param_get_hashtbl_szfunction pseudoflavor_to_flavorfunction rpcauth_registerfunction rpcauth_unregisterfunction rpcauth_get_authopsfunction rpcauth_put_authopsfunction rpcauth_get_pseudoflavorfunction rpcauth_get_gssinfofunction rpcauth_createfunction rpcauth_releasefunction rpcauth_unhash_cred_lockedfunction rpcauth_unhash_credfunction rpcauth_init_credcachefunction rpcauth_stringify_acceptorfunction rpcauth_destroy_credlistfunction rpcauth_lru_add_lockedfunction rpcauth_lru_addfunction rpcauth_lru_remove_lockedfunction rpcauth_lru_removefunction rpcauth_clear_credcachefunction rpcauth_destroy_credcachefunction rpcauth_prune_expiredfunction list_for_each_entry_safefunction rpcauth_cache_do_shrinkfunction rpcauth_cache_shrink_scanfunction rpcauth_cache_shrink_countfunction rpcauth_cache_enforce_limitfunction rpcauth_lookup_credcachefunction rpcauth_lookupcredfunction rpcauth_init_credfunction rpcauth_bind_root_credfunction rpcauth_bind_machine_credfunction rpcauth_bind_new_credfunction rpcauth_bindcredfunction put_rpccredfunction rpcauth_marshcredfunction rpcauth_wrap_req_encodefunction rpcauth_wrap_reqfunction rpcauth_checkverffunction rpcauth_unwrap_resp_decodefunction rpcauth_unwrap_respfunction rpcauth_xmit_need_reencodefunction rpcauth_refreshcredfunction rpcauth_invalcredfunction rpcauth_uptodatecredfunction rpcauth_init_module
Annotated Snippet
struct rpc_cred_cache {
struct hlist_head *hashtable;
unsigned int hashbits;
spinlock_t lock;
};
static unsigned int auth_hashbits = RPC_CREDCACHE_DEFAULT_HASHBITS;
static const struct rpc_authops __rcu *auth_flavors[RPC_AUTH_MAXFLAVOR] = {
[RPC_AUTH_NULL] = (const struct rpc_authops __force __rcu *)&authnull_ops,
[RPC_AUTH_UNIX] = (const struct rpc_authops __force __rcu *)&authunix_ops,
[RPC_AUTH_TLS] = (const struct rpc_authops __force __rcu *)&authtls_ops,
};
static LIST_HEAD(cred_unused);
static unsigned long number_cred_unused;
static struct cred machine_cred = {
.usage = ATOMIC_INIT(1),
};
/*
* Return the machine_cred pointer to be used whenever
* the a generic machine credential is needed.
*/
const struct cred *rpc_machine_cred(void)
{
return &machine_cred;
}
EXPORT_SYMBOL_GPL(rpc_machine_cred);
#define MAX_HASHTABLE_BITS (14)
static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)
{
unsigned long num;
unsigned int nbits;
int ret;
if (!val)
goto out_inval;
ret = kstrtoul(val, 0, &num);
if (ret)
goto out_inval;
nbits = fls(num - 1);
if (nbits > MAX_HASHTABLE_BITS || nbits < 2)
goto out_inval;
*(unsigned int *)kp->arg = nbits;
return 0;
out_inval:
return -EINVAL;
}
static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)
{
unsigned int nbits;
nbits = *(unsigned int *)kp->arg;
return sprintf(buffer, "%u\n", 1U << nbits);
}
#define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int);
static const struct kernel_param_ops param_ops_hashtbl_sz = {
.set = param_set_hashtbl_sz,
.get = param_get_hashtbl_sz,
};
module_param_named(auth_hashtable_size, auth_hashbits, hashtbl_sz, 0644);
MODULE_PARM_DESC(auth_hashtable_size, "RPC credential cache hashtable size");
static unsigned long auth_max_cred_cachesize = ULONG_MAX;
module_param(auth_max_cred_cachesize, ulong, 0644);
MODULE_PARM_DESC(auth_max_cred_cachesize, "RPC credential maximum total cache size");
static u32
pseudoflavor_to_flavor(u32 flavor) {
if (flavor > RPC_AUTH_MAXFLAVOR)
return RPC_AUTH_GSS;
return flavor;
}
int
rpcauth_register(const struct rpc_authops *ops)
{
const struct rpc_authops *old;
rpc_authflavor_t flavor;
if ((flavor = ops->au_flavor) >= RPC_AUTH_MAXFLAVOR)
return -EINVAL;
old = cmpxchg((const struct rpc_authops ** __force)&auth_flavors[flavor], NULL, ops);
Annotation
- Immediate include surface: `linux/types.h`, `linux/sched.h`, `linux/cred.h`, `linux/module.h`, `linux/slab.h`, `linux/errno.h`, `linux/hash.h`, `linux/sunrpc/clnt.h`.
- Detected declarations: `struct rpc_cred_cache`, `function param_set_hashtbl_sz`, `function param_get_hashtbl_sz`, `function pseudoflavor_to_flavor`, `function rpcauth_register`, `function rpcauth_unregister`, `function rpcauth_get_authops`, `function rpcauth_put_authops`, `function rpcauth_get_pseudoflavor`, `function rpcauth_get_gssinfo`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.