1/**
2 * \file
3 * \brief RPC definitions
4 */
5
6/*
7 * Copyright (c) 2008, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef _RPC_H
16#define _RPC_H
17
18#include <nfs/xdr.h>
19#include <barrelfish/deferred.h>
20#include <net_sockets/net_sockets.h>
21
22/**
23 * A reply to a call message can take on two forms: The message was
24 * either accepted or rejected.
25 */
26enum rpc_reply_stat {
27    RPC_MSG_ACCEPTED = 0,
28    RPC_MSG_DENIED   = 1
29};
30
31/**
32 * Given that a call message was accepted, the following is the status
33 * of an attempt to call a remote procedure.
34 */
35enum rpc_accept_stat {
36    RPC_SUCCESS       = 0, ///< RPC executed successfully
37    RPC_PROG_UNAVAIL  = 1, ///< remote hasn't exported program
38    RPC_PROG_MISMATCH = 2, ///< remote can't support version #
39    RPC_PROC_UNAVAIL  = 3, ///< program can't support procedure
40    RPC_GARBAGE_ARGS  = 4  ///< procedure can't decode params
41};
42
43/// Reasons why a call message was rejected
44enum rpc_reject_stat {
45    RPC_RPC_MISMATCH    = 0, ///< RPC version number != 2
46    RPC_AUTH_ERROR      = 1  ///< remote can't authenticate caller
47};
48
49/// Why authentication failed
50enum rpc_auth_stat {
51    RPC_AUTH_BADCRED      = 1,  ///< bad credentials (seal broken)
52    RPC_AUTH_REJECTEDCRED = 2,  ///< client must begin new session
53    RPC_AUTH_BADVERF      = 3,  ///< bad verifier (seal broken)
54    RPC_AUTH_REJECTEDVERF = 4,  ///< verifier expired or replayed
55    RPC_AUTH_TOOWEAK      = 5   ///< rejected for security reasons
56};
57
58#define RPC_HTABLE_SIZE 128
59
60/// RPC client instance data
61struct rpc_client {
62    struct net_socket *socket;    ///< UDP socket
63    struct in_addr connected_address;
64    uint16_t connected_port;
65    struct in_addr server;  ///< Server IP
66    struct rpc_call *call_hash[RPC_HTABLE_SIZE];
67
68    uint32_t nextxid;       ///< Next transaction ID
69    struct periodic_event timer;    ///< Retransmit timer
70};
71
72/**
73 * \brief Callback function for RPC reply handlers
74 *
75 * \param rpc_client RPC client instance pointer
76 * \param arg1,arg2 Opaque argument values provided to rpc_call()
77 * \param replystat Reply status (RPC_MSG_ACCEPTED on success)
78 * \param acceptstat Accept status (RPC_SUCCESS on success)
79 * \param reply_xdr XDR pointer for deserialising any return values
80 *
81 * \note Two opaque argument values are provided to the callback, as this
82 * allows the NFS code to use them to store the callback pointer and argument
83 * for its own callbacks without further memory allocation.
84 */
85typedef void (*rpc_callback_t)(struct rpc_client *rpc_client, void *arg1,
86                               void *arg2, uint32_t replystat,
87                               uint32_t acceptstat, XDR *reply_xdr);
88
89errval_t rpc_init(struct rpc_client *client, struct in_addr server);
90void rpc_destroy(struct rpc_client *client);
91errval_t rpc_call(struct rpc_client *client, uint16_t port, uint32_t prog,
92               uint32_t vers, uint32_t proc, xdrproc_t args_xdrproc, void *args,
93               size_t args_size, rpc_callback_t callback, void *cbarg1,
94               void *cbarg2);
95
96#endif // _RPC_H
97