aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2008-07-14 16:03:27 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-07-15 18:08:44 -0400
commitcc5598b78fd320dd6d1f90c14491e08029f3c4f6 (patch)
treede62ba86decdc7bdb69ed717e3c42b4a7d6b774b /net/sunrpc
parent166b88d755f925139af7f7b75aa0a1b896ca0670 (diff)
SUNRPC: Introduce a specific rpcb_create for contacting localhost
Add rpcb_create_local() for use by rpcb_register() and upcoming IPv6 registration functions. Ensure any errors encountered by rpcb_create_local() are properly reported. We can also use a statically allocated constant loopback socket address instead of one allocated on the stack and initialized every time the function is called. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/rpcb_clnt.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 0021fad464e0..35c1ded1fc47 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -116,6 +116,29 @@ static void rpcb_map_release(void *data)
116 kfree(map); 116 kfree(map);
117} 117}
118 118
119static const struct sockaddr_in rpcb_inaddr_loopback = {
120 .sin_family = AF_INET,
121 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
122 .sin_port = htons(RPCBIND_PORT),
123};
124
125static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr,
126 size_t addrlen, u32 version)
127{
128 struct rpc_create_args args = {
129 .protocol = XPRT_TRANSPORT_UDP,
130 .address = addr,
131 .addrsize = addrlen,
132 .servername = "localhost",
133 .program = &rpcb_program,
134 .version = version,
135 .authflavor = RPC_AUTH_UNIX,
136 .flags = RPC_CLNT_CREATE_NOPING,
137 };
138
139 return rpc_create(&args);
140}
141
119static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, 142static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
120 size_t salen, int proto, u32 version, 143 size_t salen, int proto, u32 version,
121 int privileged) 144 int privileged)
@@ -161,10 +184,6 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
161 */ 184 */
162int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) 185int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
163{ 186{
164 struct sockaddr_in sin = {
165 .sin_family = AF_INET,
166 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
167 };
168 struct rpcbind_args map = { 187 struct rpcbind_args map = {
169 .r_prog = prog, 188 .r_prog = prog,
170 .r_vers = vers, 189 .r_vers = vers,
@@ -184,14 +203,15 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
184 "rpcbind\n", (port ? "" : "un"), 203 "rpcbind\n", (port ? "" : "un"),
185 prog, vers, prot, port); 204 prog, vers, prot, port);
186 205
187 rpcb_clnt = rpcb_create("localhost", (struct sockaddr *) &sin, 206 rpcb_clnt = rpcb_create_local((struct sockaddr *)&rpcb_inaddr_loopback,
188 sizeof(sin), XPRT_TRANSPORT_UDP, RPCBVERS_2, 1); 207 sizeof(rpcb_inaddr_loopback),
189 if (IS_ERR(rpcb_clnt)) 208 RPCBVERS_2);
190 return PTR_ERR(rpcb_clnt); 209 if (!IS_ERR(rpcb_clnt)) {
210 error = rpc_call_sync(rpcb_clnt, &msg, 0);
211 rpc_shutdown_client(rpcb_clnt);
212 } else
213 error = PTR_ERR(rpcb_clnt);
191 214
192 error = rpc_call_sync(rpcb_clnt, &msg, 0);
193
194 rpc_shutdown_client(rpcb_clnt);
195 if (error < 0) 215 if (error < 0)
196 printk(KERN_WARNING "RPC: failed to contact local rpcbind " 216 printk(KERN_WARNING "RPC: failed to contact local rpcbind "
197 "server (errno %d).\n", -error); 217 "server (errno %d).\n", -error);