2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/nfs/rpc_clnt.c
|
|
|
|
*
|
2013-01-14 20:22:32 +01:00
|
|
|
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
|
2012-03-22 01:51:01 +01:00
|
|
|
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
|
|
|
|
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
|
2012-06-11 01:17:10 +02:00
|
|
|
* Gregory Nutt <gnutt@nuttx.org>
|
2012-03-17 01:25:34 +01:00
|
|
|
*
|
2012-03-22 01:51:01 +01:00
|
|
|
* Leveraged from OpenBSD:
|
2012-03-17 01:25:34 +01:00
|
|
|
*
|
2012-03-22 01:51:01 +01:00
|
|
|
* Copyright (c) 2004 The Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Weston Andros Adamson <muzzle@umich.edu>.
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@umich.edu>.
|
|
|
|
* All rights reserved.
|
2012-03-17 01:25:34 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-03-22 01:51:01 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 1989, 1991, 1993, 1995 The Regents of the University of
|
|
|
|
* California. All rights reserved.
|
2012-04-14 02:27:44 +02:00
|
|
|
*
|
2012-03-17 01:25:34 +01:00
|
|
|
* This code is derived from software contributed to Berkeley by Rick Macklem at
|
|
|
|
* The University of Guelph.
|
2012-04-14 02:27:44 +02:00
|
|
|
*
|
2012-03-17 01:25:34 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer. 2.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution. 3. All advertising
|
|
|
|
* materials mentioning features or use of this software must display the
|
|
|
|
* following acknowledgement: This product includes software developed by the
|
|
|
|
* University of California, Berkeley and its contributors. 4. Neither the
|
|
|
|
* name of the University nor the names of its contributors may be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
2012-04-14 02:27:44 +02:00
|
|
|
*
|
2012-03-17 01:25:34 +01:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2012-03-22 01:51:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2012-03-17 01:25:34 +01:00
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2015-02-15 22:18:35 +01:00
|
|
|
#include <sys/time.h>
|
2012-03-17 01:25:34 +01:00
|
|
|
#include <queue.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
2012-05-01 01:51:23 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2012-03-17 01:25:34 +01:00
|
|
|
|
|
|
|
#include "xdr_subs.h"
|
|
|
|
#include "nfs_proto.h"
|
|
|
|
#include "rpc.h"
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 20:35:42 +02:00
|
|
|
/* Increment RPC statistics */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NFS_STATISTICS
|
2015-02-25 15:58:30 +01:00
|
|
|
# define rpc_statistics(n) do { rpcstats.n++; } while (0)
|
2012-06-12 20:35:42 +02:00
|
|
|
#else
|
|
|
|
# define rpc_statistics(n)
|
|
|
|
#endif
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Static data, mostly RPC constants in XDR form */
|
|
|
|
|
2012-04-28 01:29:24 +02:00
|
|
|
static uint32_t rpc_reply;
|
|
|
|
static uint32_t rpc_call;
|
|
|
|
static uint32_t rpc_vers;
|
|
|
|
static uint32_t rpc_msgdenied;
|
|
|
|
static uint32_t rpc_mismatch;
|
|
|
|
static uint32_t rpc_auth_unix;
|
|
|
|
static uint32_t rpc_msgaccepted;
|
|
|
|
static uint32_t rpc_autherr;
|
|
|
|
static uint32_t rpc_auth_null;
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 20:35:42 +02:00
|
|
|
/* Global statics for all client instances. Cleared by NuttX on boot-up. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NFS_STATISTICS
|
|
|
|
static struct rpcstats rpcstats;
|
|
|
|
#endif
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
static int rpcclnt_send(FAR struct rpcclnt *rpc, int procid, int prog,
|
|
|
|
FAR void *call, int reqlen);
|
|
|
|
static int rpcclnt_receive(FAR struct rpcclnt *rpc, struct sockaddr *aname,
|
2012-06-10 02:13:59 +02:00
|
|
|
int proc, int program, void *reply, size_t resplen);
|
2012-06-12 23:59:00 +02:00
|
|
|
static int rpcclnt_reply(FAR struct rpcclnt *rpc, int procid, int prog,
|
2012-06-10 02:13:59 +02:00
|
|
|
void *reply, size_t resplen);
|
|
|
|
static uint32_t rpcclnt_newxid(void);
|
|
|
|
static void rpcclnt_fmtheader(FAR struct rpc_call_header *ch,
|
|
|
|
uint32_t xid, int procid, int prog, int vers);
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the nfs send routine.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2012-06-15 14:51:29 +02:00
|
|
|
* Returns zero on success or a (positive) errno value on failure.
|
2012-06-15 01:27:02 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
static int rpcclnt_send(FAR struct rpcclnt *rpc, int procid, int prog,
|
|
|
|
FAR void *call, int reqlen)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-09 17:55:10 +02:00
|
|
|
ssize_t nbytes;
|
2017-09-30 01:35:38 +02:00
|
|
|
int ret = OK;
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Send the call message
|
|
|
|
*
|
|
|
|
* On success, psock_sendto returns the number of bytes sent;
|
2017-09-30 01:35:38 +02:00
|
|
|
* On failure, it returns a negated errno value.
|
2012-06-10 02:13:59 +02:00
|
|
|
*/
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
nbytes = psock_sendto(rpc->rc_so, call, reqlen, 0,
|
|
|
|
rpc->rc_name, sizeof(struct sockaddr));
|
2012-06-10 02:13:59 +02:00
|
|
|
if (nbytes < 0)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-15 18:23:17 +02:00
|
|
|
/* psock_sendto failed */
|
2012-06-09 17:55:10 +02:00
|
|
|
|
2017-09-30 01:35:38 +02:00
|
|
|
ret = (int)-nbytes;
|
|
|
|
ferr("ERROR: psock_sendto failed: %d\n", ret);
|
2012-05-12 02:11:24 +02:00
|
|
|
}
|
2012-06-09 17:55:10 +02:00
|
|
|
|
2017-09-30 01:35:38 +02:00
|
|
|
return ret;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_receive
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all done
|
|
|
|
* by psock_recvfrom().
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
static int rpcclnt_receive(FAR struct rpcclnt *rpc, FAR struct sockaddr *aname,
|
|
|
|
int proc, int program, FAR void *reply,
|
|
|
|
size_t resplen)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-07 18:53:46 +02:00
|
|
|
ssize_t nbytes;
|
|
|
|
int error = 0;
|
2012-06-07 03:03:34 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
socklen_t fromlen = sizeof(struct sockaddr);
|
|
|
|
nbytes = psock_recvfrom(rpc->rc_so, reply, resplen, 0, aname, &fromlen);
|
|
|
|
if (nbytes < 0)
|
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
error = (int)-nbytes;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_recvfrom failed: %d\n", error);
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
2012-05-19 03:46:02 +02:00
|
|
|
|
2012-06-07 18:53:46 +02:00
|
|
|
return error;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_reply
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Received the RPC reply on the socket.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
static int rpcclnt_reply(FAR struct rpcclnt *rpc, int procid, int prog,
|
2012-06-15 01:27:02 +02:00
|
|
|
FAR void *reply, size_t resplen)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/* Get the next RPC reply from the socket */
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
error = rpcclnt_receive(rpc, rpc->rc_name, procid, prog, reply, resplen);
|
|
|
|
if (error != 0)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_receive returned: %d\n", error);
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2014-04-14 00:22:22 +02:00
|
|
|
/* If we failed because of a timeout, then try sending the CALL
|
2013-01-14 20:22:32 +01:00
|
|
|
* message again.
|
|
|
|
*/
|
2012-06-12 23:59:00 +02:00
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
if (error == EAGAIN || error == ETIMEDOUT)
|
|
|
|
{
|
|
|
|
rpc->rc_timeout = true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 01:32:53 +02:00
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/* Get the xid and check that it is an RPC replysvr */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-15 18:23:17 +02:00
|
|
|
else
|
2012-06-15 01:27:02 +02:00
|
|
|
{
|
2013-01-14 20:22:32 +01:00
|
|
|
FAR struct rpc_reply_header *replyheader =
|
|
|
|
(FAR struct rpc_reply_header *)reply;
|
2012-06-15 18:23:17 +02:00
|
|
|
|
|
|
|
if (replyheader->rp_direction != rpc_reply)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Different RPC REPLY returned\n");
|
2012-06-15 18:23:17 +02:00
|
|
|
rpc_statistics(rpcinvalid);
|
|
|
|
error = EPROTO;
|
|
|
|
}
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
return error;
|
2012-06-10 02:13:59 +02:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_newxid
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get a new (non-zero) xid
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-06-10 02:13:59 +02:00
|
|
|
|
|
|
|
static uint32_t rpcclnt_newxid(void)
|
|
|
|
{
|
|
|
|
static uint32_t rpcclnt_xid = 0;
|
|
|
|
static uint32_t rpcclnt_xid_touched = 0;
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
if ((rpcclnt_xid == 0) && (rpcclnt_xid_touched == 0))
|
|
|
|
{
|
|
|
|
rpcclnt_xid = rand();
|
|
|
|
rpcclnt_xid_touched = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-14 20:22:32 +01:00
|
|
|
int xidp = 0;
|
2012-06-10 02:13:59 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
xidp = rand();
|
|
|
|
}
|
|
|
|
while ((xidp % 256) == 0);
|
|
|
|
|
|
|
|
rpcclnt_xid += xidp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rpcclnt_xid;
|
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_fmtheader
|
|
|
|
*
|
|
|
|
* Description:
|
2014-04-14 00:22:22 +02:00
|
|
|
* Format the common part of the call header
|
2012-06-15 01:27:02 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-06-10 02:13:59 +02:00
|
|
|
|
|
|
|
static void rpcclnt_fmtheader(FAR struct rpc_call_header *ch,
|
|
|
|
uint32_t xid, int prog, int vers, int procid)
|
|
|
|
{
|
|
|
|
/* Format the call header */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-10 02:13:59 +02:00
|
|
|
ch->rp_xid = txdr_unsigned(xid);
|
|
|
|
ch->rp_direction = rpc_call;
|
|
|
|
ch->rp_rpcvers = rpc_vers;
|
|
|
|
ch->rp_prog = txdr_unsigned(prog);
|
|
|
|
ch->rp_vers = txdr_unsigned(vers);
|
|
|
|
ch->rp_proc = txdr_unsigned(procid);
|
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* rpc_auth part (auth_null) */
|
2012-06-10 02:13:59 +02:00
|
|
|
|
|
|
|
ch->rpc_auth.authtype = rpc_auth_null;
|
2012-06-13 17:00:34 +02:00
|
|
|
ch->rpc_auth.authlen = 0;
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2012-06-10 02:13:59 +02:00
|
|
|
/* rpc_verf part (auth_null) */
|
|
|
|
|
|
|
|
ch->rpc_verf.authtype = rpc_auth_null;
|
2012-06-13 17:00:34 +02:00
|
|
|
ch->rpc_verf.authlen = 0;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the RPC client
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
void rpcclnt_init(void)
|
|
|
|
{
|
|
|
|
/* RPC constants how about actually using more than one of these! */
|
|
|
|
|
|
|
|
rpc_reply = txdr_unsigned(RPC_REPLY);
|
|
|
|
rpc_vers = txdr_unsigned(RPC_VER2);
|
|
|
|
rpc_call = txdr_unsigned(RPC_CALL);
|
|
|
|
rpc_msgdenied = txdr_unsigned(RPC_MSGDENIED);
|
|
|
|
rpc_msgaccepted = txdr_unsigned(RPC_MSGACCEPTED);
|
|
|
|
rpc_mismatch = txdr_unsigned(RPC_MISMATCH);
|
|
|
|
rpc_autherr = txdr_unsigned(RPC_AUTHERR);
|
|
|
|
rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
|
|
|
|
rpc_auth_null = txdr_unsigned(RPCAUTH_NULL);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("RPC initialized\n");
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_connect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize sockets for a new RPC connection. We do not free the
|
|
|
|
* sockaddr if an error occurs.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
int rpcclnt_connect(struct rpcclnt *rpc)
|
|
|
|
{
|
|
|
|
struct socket *so;
|
|
|
|
int error;
|
|
|
|
struct sockaddr *saddr;
|
2012-04-26 01:22:09 +02:00
|
|
|
struct sockaddr_in sin;
|
2012-05-12 02:11:24 +02:00
|
|
|
struct sockaddr_in *sa;
|
2012-06-14 17:45:38 +02:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct rpc_call_pmap sdata;
|
|
|
|
struct rpc_call_mount mountd;
|
|
|
|
} request;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct rpc_reply_pmap rdata;
|
|
|
|
struct rpc_reply_mount mdata;
|
|
|
|
} response;
|
|
|
|
|
2012-04-26 01:22:09 +02:00
|
|
|
struct timeval tv;
|
2012-03-22 01:51:01 +01:00
|
|
|
uint16_t tport;
|
2012-06-07 03:03:34 +02:00
|
|
|
int errval;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Connecting\n");
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-04-14 02:27:44 +02:00
|
|
|
/* Create the socket */
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
saddr = rpc->rc_name;
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-05-01 01:51:23 +02:00
|
|
|
/* Create an instance of the socket state structure */
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2014-09-01 01:34:44 +02:00
|
|
|
so = (struct socket *)kmm_zalloc(sizeof(struct socket));
|
2012-05-01 01:51:23 +02:00
|
|
|
if (!so)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate socket structure\n");
|
2012-06-10 02:13:59 +02:00
|
|
|
return ENOMEM;
|
2012-05-01 01:51:23 +02:00
|
|
|
}
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
error = psock_socket(saddr->sa_family, rpc->rc_sotype, IPPROTO_UDP, so);
|
2012-06-07 03:03:34 +02:00
|
|
|
if (error < 0)
|
2012-03-22 01:51:01 +01:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_socket failed: %d", errval);
|
2017-09-30 16:18:08 +02:00
|
|
|
return errval;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-07 03:03:34 +02:00
|
|
|
so->s_crefs = 1;
|
|
|
|
rpc->rc_so = so;
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
/* Always set receive timeout to detect server crash and reconnect.
|
|
|
|
* Otherwise, we can get stuck in psock_receive forever.
|
|
|
|
*/
|
2012-05-18 03:11:57 +02:00
|
|
|
|
2012-06-07 03:03:34 +02:00
|
|
|
tv.tv_sec = 1;
|
2012-05-18 03:11:57 +02:00
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
error = psock_setsockopt(rpc->rc_so, SOL_SOCKET, SO_RCVTIMEO,
|
|
|
|
(const void *)&tv, sizeof(tv));
|
2012-06-07 03:03:34 +02:00
|
|
|
if (error < 0)
|
2012-05-18 03:11:57 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_setsockopt failed: %d\n", errval);
|
2012-05-18 03:11:57 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/* Some servers require that the client port be a reserved port
|
|
|
|
* number. We always allocate a reserved port, as this prevents
|
|
|
|
* filehandle disclosure through UDP port capture.
|
|
|
|
*/
|
|
|
|
|
2012-06-07 03:03:34 +02:00
|
|
|
sin.sin_family = AF_INET;
|
2012-04-26 01:22:09 +02:00
|
|
|
sin.sin_addr.s_addr = INADDR_ANY;
|
2012-06-07 03:03:34 +02:00
|
|
|
tport = 1024;
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-07 03:03:34 +02:00
|
|
|
errval = 0;
|
2012-03-22 01:51:01 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
tport--;
|
2012-04-26 01:22:09 +02:00
|
|
|
sin.sin_port = htons(tport);
|
2017-09-30 16:18:08 +02:00
|
|
|
|
2012-05-01 01:51:23 +02:00
|
|
|
error = psock_bind(rpc->rc_so, (struct sockaddr *)&sin, sizeof(sin));
|
2012-06-07 03:03:34 +02:00
|
|
|
if (error < 0)
|
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_bind failed: %d\n", errval);
|
2012-06-07 03:03:34 +02:00
|
|
|
}
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
2012-06-07 03:03:34 +02:00
|
|
|
while (errval == EADDRINUSE && tport > 1024 / 2);
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_bind failed: %d\n", errval);
|
2012-03-22 01:51:01 +01:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Protocols that do not require connections may be optionally left
|
|
|
|
* unconnected for servers that reply from a port other than
|
|
|
|
* NFS_PORT.
|
|
|
|
*/
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
|
|
|
if (error < 0)
|
2012-03-22 01:51:01 +01:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_connect to PMAP port failed: %d", errval);
|
2012-03-22 01:51:01 +01:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Do the RPC to get a dynamic bounding with the server using ppmap.
|
|
|
|
* Get port number for MOUNTD.
|
|
|
|
*/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
request.sdata.pmap.prog = txdr_unsigned(RPCPROG_MNT);
|
|
|
|
request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER1);
|
|
|
|
request.sdata.pmap.proc = txdr_unsigned(IPPROTO_UDP);
|
|
|
|
request.sdata.pmap.port = 0;
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = rpcclnt_request(rpc, PMAPPROC_GETPORT, PMAPPROG, PMAPVERS,
|
2012-06-14 17:45:38 +02:00
|
|
|
(FAR void *)&request.sdata, sizeof(struct call_args_pmap),
|
|
|
|
(FAR void *)&response.rdata, sizeof(struct rpc_reply_pmap));
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_request failed: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
sa = (FAR struct sockaddr_in *)saddr;
|
2012-06-14 17:45:38 +02:00
|
|
|
sa->sin_port = htons(fxdr_unsigned(uint32_t, response.rdata.pmap.port));
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
|
|
|
if (error < 0)
|
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_connect MOUNTD port failed: %d\n", errval);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Do RPC to mountd. */
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
strncpy(request.mountd.mount.rpath, rpc->rc_path, 90);
|
|
|
|
request.mountd.mount.len = txdr_unsigned(sizeof(request.mountd.mount.rpath));
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = rpcclnt_request(rpc, RPCMNT_MOUNT, RPCPROG_MNT, RPCMNT_VER1,
|
2012-06-14 17:45:38 +02:00
|
|
|
(FAR void *)&request.mountd, sizeof(struct call_args_mount),
|
|
|
|
(FAR void *)&response.mdata, sizeof(struct rpc_reply_mount));
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_request failed: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
error = fxdr_unsigned(uint32_t, response.mdata.mount.status);
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Bad mount status: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
memcpy(&rpc->rc_fh, &response.mdata.mount.fhandle, sizeof(nfsfh_t));
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Do the RPC to get a dynamic bounding with the server using PMAP.
|
|
|
|
* NFS port in the socket.
|
|
|
|
*/
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
sa->sin_port = htons(PMAPPORT);
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
|
|
|
if (error < 0)
|
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
errval = -error;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_connect PMAP port failed: %d\n", errval);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
request.sdata.pmap.prog = txdr_unsigned(NFS_PROG);
|
|
|
|
request.sdata.pmap.vers = txdr_unsigned(NFS_VER3);
|
|
|
|
request.sdata.pmap.proc = txdr_unsigned(IPPROTO_UDP);
|
|
|
|
request.sdata.pmap.port = 0;
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = rpcclnt_request(rpc, PMAPPROC_GETPORT, PMAPPROG, PMAPVERS,
|
2012-06-14 17:45:38 +02:00
|
|
|
(FAR void *)&request.sdata, sizeof(struct call_args_pmap),
|
|
|
|
(FAR void *)&response.rdata, sizeof(struct rpc_reply_pmap));
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_request failed: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
sa->sin_port = htons(fxdr_unsigned(uint32_t, response.rdata.pmap.port));
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
error = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
2017-09-30 16:18:08 +02:00
|
|
|
if (error < 0)
|
2012-06-12 23:59:00 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
error = -error;
|
2016-06-12 01:14:02 +02:00
|
|
|
ferr("ERROR: psock_connect NFS port returns %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
goto bad;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
return OK;
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
bad:
|
|
|
|
rpcclnt_disconnect(rpc);
|
2012-06-07 03:51:30 +02:00
|
|
|
return error;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_disconnect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disconnect from the NFS server.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
void rpcclnt_disconnect(struct rpcclnt *rpc)
|
|
|
|
{
|
|
|
|
if (rpc->rc_so != NULL)
|
|
|
|
{
|
2012-06-15 18:23:17 +02:00
|
|
|
(void)psock_close(rpc->rc_so);
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_umount
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Un-mount the NFS file system.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-12 02:11:24 +02:00
|
|
|
int rpcclnt_umount(struct rpcclnt *rpc)
|
|
|
|
{
|
|
|
|
struct sockaddr *saddr;
|
|
|
|
struct sockaddr_in *sa;
|
2012-06-14 17:45:38 +02:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct rpc_call_pmap sdata;
|
|
|
|
struct rpc_call_umount mountd;
|
|
|
|
} request;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct rpc_reply_pmap rdata;
|
|
|
|
struct rpc_reply_umount mdata;
|
|
|
|
} response;
|
|
|
|
|
2012-05-12 02:11:24 +02:00
|
|
|
int error;
|
2012-06-14 03:37:10 +02:00
|
|
|
int ret;
|
2012-05-12 02:11:24 +02:00
|
|
|
|
|
|
|
saddr = rpc->rc_name;
|
2012-05-23 02:15:53 +02:00
|
|
|
sa = (FAR struct sockaddr_in *)saddr;
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-05-19 03:46:02 +02:00
|
|
|
/* Do the RPC to get a dynamic bounding with the server using ppmap.
|
|
|
|
* Get port number for MOUNTD.
|
|
|
|
*/
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-05-23 02:15:53 +02:00
|
|
|
sa->sin_port = htons(PMAPPORT);
|
|
|
|
|
2012-06-14 03:37:10 +02:00
|
|
|
ret = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
|
|
|
if (ret < 0)
|
2012-05-23 02:15:53 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
error = -ret;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_connect failed [port=%d]: %d\n",
|
2012-06-14 03:37:10 +02:00
|
|
|
ntohs(sa->sin_port), error);
|
2012-05-23 02:15:53 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
request.sdata.pmap.prog = txdr_unsigned(RPCPROG_MNT);
|
|
|
|
request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER1);
|
|
|
|
request.sdata.pmap.proc = txdr_unsigned(IPPROTO_UDP);
|
|
|
|
request.sdata.pmap.port = 0;
|
2012-05-12 02:11:24 +02:00
|
|
|
|
|
|
|
error = rpcclnt_request(rpc, PMAPPROC_GETPORT, PMAPPROG, PMAPVERS,
|
2012-06-14 17:45:38 +02:00
|
|
|
(FAR void *)&request.sdata, sizeof(struct call_args_pmap),
|
|
|
|
(FAR void *)&response.rdata, sizeof(struct rpc_reply_pmap));
|
2012-05-12 02:11:24 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_request failed: %d\n", error);
|
2012-05-12 02:11:24 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
sa->sin_port = htons(fxdr_unsigned(uint32_t, response.rdata.pmap.port));
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2012-06-14 03:37:10 +02:00
|
|
|
ret = psock_connect(rpc->rc_so, saddr, sizeof(*saddr));
|
|
|
|
if (ret < 0)
|
2012-05-12 02:11:24 +02:00
|
|
|
{
|
2017-09-30 16:18:08 +02:00
|
|
|
error = -ret;
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: psock_connect failed [port=%d]: %d\n",
|
2012-06-14 03:37:10 +02:00
|
|
|
ntohs(sa->sin_port), error);
|
2012-05-12 02:11:24 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do RPC to umountd. */
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
strncpy(request.mountd.umount.rpath, rpc->rc_path, 92);
|
|
|
|
request.mountd.umount.len = txdr_unsigned(sizeof(request.mountd.umount.rpath));
|
2012-05-12 02:11:24 +02:00
|
|
|
|
|
|
|
error = rpcclnt_request(rpc, RPCMNT_UMOUNT, RPCPROG_MNT, RPCMNT_VER1,
|
2012-06-14 17:45:38 +02:00
|
|
|
(FAR void *)&request.mountd, sizeof(struct call_args_umount),
|
|
|
|
(FAR void *)&response.mdata, sizeof(struct rpc_reply_umount));
|
2012-05-12 02:11:24 +02:00
|
|
|
if (error != 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: rpcclnt_request failed: %d\n", error);
|
2012-05-23 02:15:53 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
return OK;
|
2012-05-12 02:11:24 +02:00
|
|
|
|
|
|
|
bad:
|
|
|
|
rpcclnt_disconnect(rpc);
|
2012-06-07 03:51:30 +02:00
|
|
|
return error;
|
2012-05-12 02:11:24 +02:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:27:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpcclnt_request
|
2012-04-14 02:27:44 +02:00
|
|
|
*
|
2012-06-15 01:27:02 +02:00
|
|
|
* Description:
|
2012-06-28 00:03:32 +02:00
|
|
|
* Perform the RPC request. Logic formats the RPC CALL message and calls
|
2012-06-15 01:27:02 +02:00
|
|
|
* rpcclnt_send to send the RPC CALL message. It then calls rpcclnt_reply()
|
|
|
|
* to get the response. It may attempt to re-send the CALL message on
|
|
|
|
* certain errors.
|
|
|
|
*
|
|
|
|
* On successful receipt, it verifies the RPC level of the returned values.
|
|
|
|
* (There may still be be NFS layer errors that will be deted by calling
|
|
|
|
* logic).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
int rpcclnt_request(FAR struct rpcclnt *rpc, int procnum, int prog,
|
2012-06-13 17:00:34 +02:00
|
|
|
int version, FAR void *request, size_t reqlen,
|
2012-06-12 23:59:00 +02:00
|
|
|
FAR void *response, size_t resplen)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-12 23:59:00 +02:00
|
|
|
struct rpc_reply_header *replymsg;
|
|
|
|
uint32_t tmp;
|
2012-06-13 17:00:34 +02:00
|
|
|
uint32_t xid;
|
2012-06-12 23:59:00 +02:00
|
|
|
int retries;
|
2012-03-17 01:25:34 +01:00
|
|
|
int error = 0;
|
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
/* Get a new (non-zero) xid */
|
2012-06-12 18:11:31 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
xid = rpcclnt_newxid();
|
2012-05-18 03:11:57 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
/* Initialize the RPC header fields */
|
2012-06-12 18:11:31 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
rpcclnt_fmtheader((FAR struct rpc_call_header *)request,
|
|
|
|
xid, prog, version, procnum);
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
/* Get the full size of the message (the size of variable data plus the size of
|
|
|
|
* the messages header).
|
|
|
|
*/
|
2012-05-06 01:17:25 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
reqlen += sizeof(struct rpc_call_header);
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Send the RPC call messsages and receive the RPC response. A limited
|
|
|
|
* number of re-tries will be attempted, but only for the case of response
|
|
|
|
* timeouts.
|
2012-03-17 01:25:34 +01:00
|
|
|
*/
|
2012-06-13 17:00:34 +02:00
|
|
|
|
2012-06-13 02:46:44 +02:00
|
|
|
retries = 0;
|
2012-06-12 23:59:00 +02:00
|
|
|
do
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Do the client side RPC. */
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
rpc_statistics(rpcrequests);
|
2012-06-15 18:23:17 +02:00
|
|
|
rpc->rc_timeout = false;
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Send the RPC CALL message */
|
2012-05-01 01:51:23 +02:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
error = rpcclnt_send(rpc, procnum, prog, request, reqlen);
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != OK)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("ERROR rpcclnt_send failed: %d\n", error);
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Wait for the reply from our send */
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
else
|
2012-06-10 20:16:01 +02:00
|
|
|
{
|
2012-06-12 23:59:00 +02:00
|
|
|
error = rpcclnt_reply(rpc, procnum, prog, response, resplen);
|
|
|
|
if (error != OK)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("ERROR rpcclnt_reply failed: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
}
|
2012-06-10 20:16:01 +02:00
|
|
|
}
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
retries++;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
2012-06-15 18:23:17 +02:00
|
|
|
while (rpc->rc_timeout && retries <= rpc->rc_retry);
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
if (error != OK)
|
2012-04-14 02:27:44 +02:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: RPC failed: %d\n", error);
|
2012-06-12 23:59:00 +02:00
|
|
|
return error;
|
2012-04-14 02:27:44 +02:00
|
|
|
}
|
2012-03-17 01:25:34 +01:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
/* Break down the RPC header and check if it is OK */
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-13 17:00:34 +02:00
|
|
|
replymsg = (FAR struct rpc_reply_header *)response;
|
2012-06-11 23:16:35 +02:00
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, replymsg->type);
|
|
|
|
if (tmp == RPC_MSGDENIED)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-12 23:59:00 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, replymsg->status);
|
|
|
|
switch (tmp)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
|
|
|
case RPC_MISMATCH:
|
2016-06-12 01:29:32 +02:00
|
|
|
ferr("ERROR: RPC_MSGDENIED: RPC_MISMATCH error\n");
|
2012-06-12 23:59:00 +02:00
|
|
|
return EOPNOTSUPP;
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2012-03-17 01:25:34 +01:00
|
|
|
case RPC_AUTHERR:
|
2016-06-12 01:14:02 +02:00
|
|
|
ferr("ERROR: RPC_MSGDENIED: RPC_AUTHERR error\n");
|
2012-06-12 23:59:00 +02:00
|
|
|
return EACCES;
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2012-03-17 01:25:34 +01:00
|
|
|
default:
|
2012-06-12 23:59:00 +02:00
|
|
|
return EOPNOTSUPP;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-12 23:59:00 +02:00
|
|
|
else if (tmp != RPC_MSGACCEPTED)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2012-06-12 23:59:00 +02:00
|
|
|
return EOPNOTSUPP;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, replymsg->status);
|
|
|
|
if (tmp == RPC_SUCCESS)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("RPC_SUCCESS\n");
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
2012-06-12 23:59:00 +02:00
|
|
|
else if (tmp == RPC_PROGMISMATCH)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2016-06-12 01:14:02 +02:00
|
|
|
ferr("ERROR: RPC_MSGACCEPTED: RPC_PROGMISMATCH error\n");
|
2012-06-12 23:59:00 +02:00
|
|
|
return EOPNOTSUPP;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
2012-06-12 23:59:00 +02:00
|
|
|
else if (tmp > 5)
|
2012-03-17 01:25:34 +01:00
|
|
|
{
|
2016-06-12 01:14:02 +02:00
|
|
|
ferr("ERROR: Unsupported RPC type: %d\n", tmp);
|
2012-06-12 23:59:00 +02:00
|
|
|
return EOPNOTSUPP;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-12 23:59:00 +02:00
|
|
|
return OK;
|
2012-03-17 01:25:34 +01:00
|
|
|
}
|