diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2009-08-09 15:09:34 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2009-08-09 15:09:34 -0400 |
commit | a02d692611348f11ee1bc37431a883c3ff2de23e (patch) | |
tree | 5a2ad4862784b4337846b44ddd816e495484086f /include/linux/sunrpc | |
parent | 0b10bf5e14d856d1d27a2117d07af2bebee81b75 (diff) |
SUNRPC: Provide functions for managing universal addresses
Introduce a set of functions in the kernel's RPC implementation for
converting between a socket address and either a standard
presentation address string or an RPC universal address.
The universal address functions will be used to encode and decode
RPCB_FOO and NFSv4 SETCLIENTID arguments. The other functions are
part of a previous promise to deliver shared functions that can be
used by upper-layer protocols to display and manipulate IP
addresses.
The kernel's current address printf formatters were designed
specifically for kernel to user-space APIs that require a particular
string format for socket addresses, thus are somewhat limited for the
purposes of sunrpc.ko. The formatter for IPv6 addresses, %pI6, does
not support short-handing or scope IDs. Also, these printf formatters
are unique per address family, so a separate formatter string is
required for printing AF_INET and AF_INET6 addresses.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'include/linux/sunrpc')
-rw-r--r-- | include/linux/sunrpc/clnt.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 37881f1a0bd7..2636e8ad551c 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h | |||
@@ -9,6 +9,10 @@ | |||
9 | #ifndef _LINUX_SUNRPC_CLNT_H | 9 | #ifndef _LINUX_SUNRPC_CLNT_H |
10 | #define _LINUX_SUNRPC_CLNT_H | 10 | #define _LINUX_SUNRPC_CLNT_H |
11 | 11 | ||
12 | #include <linux/socket.h> | ||
13 | #include <linux/in.h> | ||
14 | #include <linux/in6.h> | ||
15 | |||
12 | #include <linux/sunrpc/msg_prot.h> | 16 | #include <linux/sunrpc/msg_prot.h> |
13 | #include <linux/sunrpc/sched.h> | 17 | #include <linux/sunrpc/sched.h> |
14 | #include <linux/sunrpc/xprt.h> | 18 | #include <linux/sunrpc/xprt.h> |
@@ -151,5 +155,39 @@ void rpc_force_rebind(struct rpc_clnt *); | |||
151 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); | 155 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); |
152 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); | 156 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); |
153 | 157 | ||
158 | size_t rpc_ntop(const struct sockaddr *, char *, const size_t); | ||
159 | size_t rpc_pton(const char *, const size_t, | ||
160 | struct sockaddr *, const size_t); | ||
161 | char * rpc_sockaddr2uaddr(const struct sockaddr *); | ||
162 | size_t rpc_uaddr2sockaddr(const char *, const size_t, | ||
163 | struct sockaddr *, const size_t); | ||
164 | |||
165 | static inline unsigned short rpc_get_port(const struct sockaddr *sap) | ||
166 | { | ||
167 | switch (sap->sa_family) { | ||
168 | case AF_INET: | ||
169 | return ntohs(((struct sockaddr_in *)sap)->sin_port); | ||
170 | case AF_INET6: | ||
171 | return ntohs(((struct sockaddr_in6 *)sap)->sin6_port); | ||
172 | } | ||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | static inline void rpc_set_port(struct sockaddr *sap, | ||
177 | const unsigned short port) | ||
178 | { | ||
179 | switch (sap->sa_family) { | ||
180 | case AF_INET: | ||
181 | ((struct sockaddr_in *)sap)->sin_port = htons(port); | ||
182 | break; | ||
183 | case AF_INET6: | ||
184 | ((struct sockaddr_in6 *)sap)->sin6_port = htons(port); | ||
185 | break; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | #define IPV6_SCOPE_DELIMITER '%' | ||
190 | #define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") | ||
191 | |||
154 | #endif /* __KERNEL__ */ | 192 | #endif /* __KERNEL__ */ |
155 | #endif /* _LINUX_SUNRPC_CLNT_H */ | 193 | #endif /* _LINUX_SUNRPC_CLNT_H */ |