Skip to content

Commit 78c542f

Browse files
committed
SUNRPC: Add enum svc_auth_status
In addition to the benefits of using an enum rather than a set of macros, we now have a named type that can improve static type checking of function return values. As part of this change, I removed a stale comment from svcauth.h; the return values from current implementations of the auth_ops::release method are all zero/negative errno, not the SVC_OK enum values as the old comment suggested. Suggested-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent d75e490 commit 78c542f

File tree

9 files changed

+73
-49
lines changed

9 files changed

+73
-49
lines changed

fs/lockd/svc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static inline int is_callback(u32 proc)
506506
}
507507

508508

509-
static int lockd_authenticate(struct svc_rqst *rqstp)
509+
static enum svc_auth_status lockd_authenticate(struct svc_rqst *rqstp)
510510
{
511511
rqstp->rq_client = NULL;
512512
switch (rqstp->rq_authop->flavour) {

fs/nfs/callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
372372
* All other checking done after NFS decoding where the nfs_client can be
373373
* found in nfs4_callback_compound
374374
*/
375-
static int nfs_callback_authenticate(struct svc_rqst *rqstp)
375+
static enum svc_auth_status nfs_callback_authenticate(struct svc_rqst *rqstp)
376376
{
377377
rqstp->rq_auth_stat = rpc_autherr_badcred;
378378

include/linux/sunrpc/svc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct svc_program {
336336
char * pg_name; /* service name */
337337
char * pg_class; /* class name: services sharing authentication */
338338
struct svc_stat * pg_stats; /* rpc statistics */
339-
int (*pg_authenticate)(struct svc_rqst *);
339+
enum svc_auth_status (*pg_authenticate)(struct svc_rqst *rqstp);
340340
__be32 (*pg_init_request)(struct svc_rqst *,
341341
const struct svc_program *,
342342
struct svc_process_info *);

include/linux/sunrpc/svcauth.h

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ struct auth_domain {
8383
struct rcu_head rcu_head;
8484
};
8585

86+
enum svc_auth_status {
87+
SVC_GARBAGE = 1,
88+
SVC_SYSERR,
89+
SVC_VALID,
90+
SVC_NEGATIVE,
91+
SVC_OK,
92+
SVC_DROP,
93+
SVC_CLOSE,
94+
SVC_DENIED,
95+
SVC_PENDING,
96+
SVC_COMPLETE,
97+
};
98+
8699
/*
87100
* Each authentication flavour registers an auth_ops
88101
* structure.
@@ -98,6 +111,8 @@ struct auth_domain {
98111
* is (probably) already in place. Certainly space is
99112
* reserved for it.
100113
* DROP - simply drop the request. It may have been deferred
114+
* CLOSE - like SVC_DROP, but request is definitely lost.
115+
* If there is a tcp connection, it should be closed.
101116
* GARBAGE - rpc garbage_args error
102117
* SYSERR - rpc system_err error
103118
* DENIED - authp holds reason for denial.
@@ -111,14 +126,10 @@ struct auth_domain {
111126
*
112127
* release() is given a request after the procedure has been run.
113128
* It should sign/encrypt the results if needed
114-
* It should return:
115-
* OK - the resbuf is ready to be sent
116-
* DROP - the reply should be quitely dropped
117-
* DENIED - authp holds a reason for MSG_DENIED
118-
* SYSERR - rpc system_err
119129
*
120130
* domain_release()
121131
* This call releases a domain.
132+
*
122133
* set_client()
123134
* Givens a pending request (struct svc_rqst), finds and assigns
124135
* an appropriate 'auth_domain' as the client.
@@ -127,31 +138,18 @@ struct auth_ops {
127138
char * name;
128139
struct module *owner;
129140
int flavour;
130-
int (*accept)(struct svc_rqst *rq);
131-
int (*release)(struct svc_rqst *rq);
132-
void (*domain_release)(struct auth_domain *);
133-
int (*set_client)(struct svc_rqst *rq);
134-
};
135141

136-
#define SVC_GARBAGE 1
137-
#define SVC_SYSERR 2
138-
#define SVC_VALID 3
139-
#define SVC_NEGATIVE 4
140-
#define SVC_OK 5
141-
#define SVC_DROP 6
142-
#define SVC_CLOSE 7 /* Like SVC_DROP, but request is definitely
143-
* lost so if there is a tcp connection, it
144-
* should be closed
145-
*/
146-
#define SVC_DENIED 8
147-
#define SVC_PENDING 9
148-
#define SVC_COMPLETE 10
142+
enum svc_auth_status (*accept)(struct svc_rqst *rqstp);
143+
int (*release)(struct svc_rqst *rqstp);
144+
void (*domain_release)(struct auth_domain *dom);
145+
enum svc_auth_status (*set_client)(struct svc_rqst *rqstp);
146+
};
149147

150148
struct svc_xprt;
151149

152-
extern int svc_authenticate(struct svc_rqst *rqstp);
150+
extern enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
153151
extern int svc_authorise(struct svc_rqst *rqstp);
154-
extern int svc_set_client(struct svc_rqst *rqstp);
152+
extern enum svc_auth_status svc_set_client(struct svc_rqst *rqstp);
155153
extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
156154
extern void svc_auth_unregister(rpc_authflavor_t flavor);
157155

@@ -161,7 +159,7 @@ extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *ne
161159
extern struct auth_domain *auth_domain_find(char *name);
162160
extern void svcauth_unix_purge(struct net *net);
163161
extern void svcauth_unix_info_release(struct svc_xprt *xpt);
164-
extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
162+
extern enum svc_auth_status svcauth_unix_set_client(struct svc_rqst *rqstp);
165163

166164
extern int unix_gid_cache_create(struct net *net);
167165
extern void unix_gid_cache_destroy(struct net *net);

include/trace/events/sunrpc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ TRACE_DEFINE_ENUM(SVC_DENIED);
17061706
TRACE_DEFINE_ENUM(SVC_PENDING);
17071707
TRACE_DEFINE_ENUM(SVC_COMPLETE);
17081708

1709-
#define svc_show_status(status) \
1709+
#define show_svc_auth_status(status) \
17101710
__print_symbolic(status, \
17111711
{ SVC_GARBAGE, "SVC_GARBAGE" }, \
17121712
{ SVC_SYSERR, "SVC_SYSERR" }, \
@@ -1743,7 +1743,10 @@ TRACE_DEFINE_ENUM(SVC_COMPLETE);
17431743
__entry->xid, __get_sockaddr(server), __get_sockaddr(client)
17441744

17451745
TRACE_EVENT_CONDITION(svc_authenticate,
1746-
TP_PROTO(const struct svc_rqst *rqst, int auth_res),
1746+
TP_PROTO(
1747+
const struct svc_rqst *rqst,
1748+
enum svc_auth_status auth_res
1749+
),
17471750

17481751
TP_ARGS(rqst, auth_res),
17491752

@@ -1766,7 +1769,7 @@ TRACE_EVENT_CONDITION(svc_authenticate,
17661769
TP_printk(SVC_RQST_ENDPOINT_FORMAT
17671770
" auth_res=%s auth_stat=%s",
17681771
SVC_RQST_ENDPOINT_VARARGS,
1769-
svc_show_status(__entry->svc_status),
1772+
show_svc_auth_status(__entry->svc_status),
17701773
rpc_show_auth_stat(__entry->auth_stat))
17711774
);
17721775

net/sunrpc/auth_gss/svcauth_gss.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ svcauth_gss_unwrap_priv(struct svc_rqst *rqstp, u32 seq, struct gss_ctx *ctx)
986986
return -EINVAL;
987987
}
988988

989-
static int
989+
static enum svc_auth_status
990990
svcauth_gss_set_client(struct svc_rqst *rqstp)
991991
{
992992
struct gss_svc_data *svcdata = rqstp->rq_auth_data;
@@ -1634,7 +1634,7 @@ svcauth_gss_decode_credbody(struct xdr_stream *xdr,
16341634
*
16351635
* The rqstp->rq_auth_stat field is also set (see RFCs 2203 and 5531).
16361636
*/
1637-
static int
1637+
static enum svc_auth_status
16381638
svcauth_gss_accept(struct svc_rqst *rqstp)
16391639
{
16401640
struct gss_svc_data *svcdata = rqstp->rq_auth_data;
@@ -1945,9 +1945,6 @@ static int svcauth_gss_wrap_priv(struct svc_rqst *rqstp)
19451945
* %0: the Reply is ready to be sent
19461946
* %-ENOMEM: failed to allocate memory
19471947
* %-EINVAL: encoding error
1948-
*
1949-
* XXX: These return values do not match the return values documented
1950-
* for the auth_ops ->release method in linux/sunrpc/svcauth.h.
19511948
*/
19521949
static int
19531950
svcauth_gss_release(struct svc_rqst *rqstp)

net/sunrpc/svc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,9 @@ svc_process_common(struct svc_rqst *rqstp)
12751275
const struct svc_procedure *procp = NULL;
12761276
struct svc_serv *serv = rqstp->rq_server;
12771277
struct svc_process_info process;
1278-
int auth_res, rc;
1278+
enum svc_auth_status auth_res;
12791279
unsigned int aoffset;
1280+
int rc;
12801281
__be32 *p;
12811282

12821283
/* Will be turned off by GSS integrity and privacy services */
@@ -1331,6 +1332,9 @@ svc_process_common(struct svc_rqst *rqstp)
13311332
goto dropit;
13321333
case SVC_COMPLETE:
13331334
goto sendit;
1335+
default:
1336+
pr_warn_once("Unexpected svc_auth_status (%d)\n", auth_res);
1337+
goto err_system_err;
13341338
}
13351339

13361340
if (progp == NULL)

net/sunrpc/svcauth.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,19 @@ svc_put_auth_ops(struct auth_ops *aops)
6060
module_put(aops->owner);
6161
}
6262

63-
int
64-
svc_authenticate(struct svc_rqst *rqstp)
63+
/**
64+
* svc_authenticate - Initialize an outgoing credential
65+
* @rqstp: RPC execution context
66+
*
67+
* Return values:
68+
* %SVC_OK: XDR encoding of the result can begin
69+
* %SVC_DENIED: Credential or verifier is not valid
70+
* %SVC_GARBAGE: Failed to decode credential or verifier
71+
* %SVC_COMPLETE: GSS context lifetime event; no further action
72+
* %SVC_DROP: Drop this request; no further action
73+
* %SVC_CLOSE: Like drop, but also close transport connection
74+
*/
75+
enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp)
6576
{
6677
struct auth_ops *aops;
6778
u32 flavor;
@@ -89,16 +100,28 @@ svc_authenticate(struct svc_rqst *rqstp)
89100
}
90101
EXPORT_SYMBOL_GPL(svc_authenticate);
91102

92-
int svc_set_client(struct svc_rqst *rqstp)
103+
/**
104+
* svc_set_client - Assign an appropriate 'auth_domain' as the client
105+
* @rqstp: RPC execution context
106+
*
107+
* Return values:
108+
* %SVC_OK: Client was found and assigned
109+
* %SVC_DENY: Client was explicitly denied
110+
* %SVC_DROP: Ignore this request
111+
* %SVC_CLOSE: Ignore this request and close the connection
112+
*/
113+
enum svc_auth_status svc_set_client(struct svc_rqst *rqstp)
93114
{
94115
rqstp->rq_client = NULL;
95116
return rqstp->rq_authop->set_client(rqstp);
96117
}
97118
EXPORT_SYMBOL_GPL(svc_set_client);
98119

99-
/* A request, which was authenticated, has now executed.
100-
* Time to finalise the credentials and verifier
101-
* and release and resources
120+
/**
121+
* svc_authorise - Finalize credentials/verifier and release resources
122+
* @rqstp: RPC execution context
123+
*
124+
* Returns zero on success, or a negative errno.
102125
*/
103126
int svc_authorise(struct svc_rqst *rqstp)
104127
{

net/sunrpc/svcauth_unix.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static struct group_info *unix_gid_find(kuid_t uid, struct svc_rqst *rqstp)
665665
}
666666
}
667667

668-
int
668+
enum svc_auth_status
669669
svcauth_unix_set_client(struct svc_rqst *rqstp)
670670
{
671671
struct sockaddr_in *sin;
@@ -736,7 +736,6 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
736736
rqstp->rq_auth_stat = rpc_auth_ok;
737737
return SVC_OK;
738738
}
739-
740739
EXPORT_SYMBOL_GPL(svcauth_unix_set_client);
741740

742741
/**
@@ -751,7 +750,7 @@ EXPORT_SYMBOL_GPL(svcauth_unix_set_client);
751750
*
752751
* rqstp->rq_auth_stat is set as mandated by RFC 5531.
753752
*/
754-
static int
753+
static enum svc_auth_status
755754
svcauth_null_accept(struct svc_rqst *rqstp)
756755
{
757756
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
@@ -828,7 +827,7 @@ struct auth_ops svcauth_null = {
828827
*
829828
* rqstp->rq_auth_stat is set as mandated by RFC 5531.
830829
*/
831-
static int
830+
static enum svc_auth_status
832831
svcauth_tls_accept(struct svc_rqst *rqstp)
833832
{
834833
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
@@ -913,7 +912,7 @@ struct auth_ops svcauth_tls = {
913912
*
914913
* rqstp->rq_auth_stat is set as mandated by RFC 5531.
915914
*/
916-
static int
915+
static enum svc_auth_status
917916
svcauth_unix_accept(struct svc_rqst *rqstp)
918917
{
919918
struct xdr_stream *xdr = &rqstp->rq_arg_stream;

0 commit comments

Comments
 (0)