diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2007-02-12 03:53:37 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-12 12:48:36 -0500 |
commit | bcdb81ae29091f6a66369aabfd8324e4a53d05dc (patch) | |
tree | ce70eed085bd56c0b1eaffa838ca27bec94e1345 /net/sunrpc | |
parent | b92503b25c3f794cff5f96626ea3ecba8d10d254 (diff) |
[PATCH] knfsd: SUNRPC: add a "generic" function to see if the peer uses a secure port
The only reason svcsock.c looks at a sockaddr's port is to check whether the
remote peer is connecting from a privileged port. Refactor this check to hide
processing that is specific to address format.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Cc: Aurelien Charbon <aurelien.charbon@ext.bull.net>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/sunrpc')
-rw-r--r-- | net/sunrpc/svcsock.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index a89d04bd3855..01e77b8208ce 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c | |||
@@ -938,6 +938,22 @@ svc_tcp_data_ready(struct sock *sk, int count) | |||
938 | wake_up_interruptible(sk->sk_sleep); | 938 | wake_up_interruptible(sk->sk_sleep); |
939 | } | 939 | } |
940 | 940 | ||
941 | static inline int svc_port_is_privileged(struct sockaddr *sin) | ||
942 | { | ||
943 | switch (sin->sa_family) { | ||
944 | case AF_INET: | ||
945 | return ntohs(((struct sockaddr_in *)sin)->sin_port) | ||
946 | < PROT_SOCK; | ||
947 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
948 | case AF_INET6: | ||
949 | return ntohs(((struct sockaddr_in6 *)sin)->sin6_port) | ||
950 | < PROT_SOCK; | ||
951 | #endif | ||
952 | default: | ||
953 | return 0; | ||
954 | } | ||
955 | } | ||
956 | |||
941 | /* | 957 | /* |
942 | * Accept a TCP connection | 958 | * Accept a TCP connection |
943 | */ | 959 | */ |
@@ -984,7 +1000,7 @@ svc_tcp_accept(struct svc_sock *svsk) | |||
984 | * hosts here, but when we get encryption, the IP of the host won't | 1000 | * hosts here, but when we get encryption, the IP of the host won't |
985 | * tell us anything. For now just warn about unpriv connections. | 1001 | * tell us anything. For now just warn about unpriv connections. |
986 | */ | 1002 | */ |
987 | if (ntohs(sin.sin_port) >= 1024) { | 1003 | if (!svc_port_is_privileged((struct sockaddr *) &sin)) { |
988 | dprintk(KERN_WARNING | 1004 | dprintk(KERN_WARNING |
989 | "%s: connect from unprivileged port: %s\n", | 1005 | "%s: connect from unprivileged port: %s\n", |
990 | serv->sv_name, | 1006 | serv->sv_name, |
@@ -1334,7 +1350,6 @@ int | |||
1334 | svc_recv(struct svc_rqst *rqstp, long timeout) | 1350 | svc_recv(struct svc_rqst *rqstp, long timeout) |
1335 | { | 1351 | { |
1336 | struct svc_sock *svsk = NULL; | 1352 | struct svc_sock *svsk = NULL; |
1337 | struct sockaddr_in *sin = svc_addr_in(rqstp); | ||
1338 | struct svc_serv *serv = rqstp->rq_server; | 1353 | struct svc_serv *serv = rqstp->rq_server; |
1339 | struct svc_pool *pool = rqstp->rq_pool; | 1354 | struct svc_pool *pool = rqstp->rq_pool; |
1340 | int len, i; | 1355 | int len, i; |
@@ -1431,7 +1446,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout) | |||
1431 | svsk->sk_lastrecv = get_seconds(); | 1446 | svsk->sk_lastrecv = get_seconds(); |
1432 | clear_bit(SK_OLD, &svsk->sk_flags); | 1447 | clear_bit(SK_OLD, &svsk->sk_flags); |
1433 | 1448 | ||
1434 | rqstp->rq_secure = ntohs(sin->sin_port) < PROT_SOCK; | 1449 | rqstp->rq_secure = svc_port_is_privileged(svc_addr(rqstp)); |
1435 | rqstp->rq_chandle.defer = svc_defer; | 1450 | rqstp->rq_chandle.defer = svc_defer; |
1436 | 1451 | ||
1437 | if (serv->sv_stats) | 1452 | if (serv->sv_stats) |