]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfsrpc.h
d6d4a1cf881571935c015b66e97394bd631e9d13
[nfs-utils.git] / support / include / nfsrpc.h
1 /*
2  * nfsrpc.h -- RPC client APIs provided by support/nfs
3  *
4  * Copyright (C) 2008 Oracle Corporation.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA.
20  *
21  */
22
23 #ifndef __NFS_UTILS_NFSRPC_H
24 #define __NFS_UTILS_NFSRPC_H
25
26 #include <rpc/types.h>
27 #include <rpc/clnt.h>
28
29 /*
30  * Conventional RPC program numbers
31  */
32 #ifndef RPCBPROG
33 #define RPCBPROG        ((rpcprog_t)100000)
34 #endif
35 #ifndef PMAPPROG
36 #define PMAPPROG        ((rpcprog_t)100000)
37 #endif
38
39 #ifndef NFSPROG
40 #define NFSPROG         ((rpcprog_t)100003)
41 #endif
42 #ifndef MOUNTPROG
43 #define MOUNTPROG       ((rpcprog_t)100005)
44 #endif
45 #ifndef NLMPROG
46 #define NLMPROG         ((rpcprog_t)100021)
47 #endif
48 #ifndef NSMPROG
49 #define NSMPROG         ((rpcprog_t)100024)
50 #endif
51
52 /**
53  * nfs_clear_rpc_createerr - zap all error reporting fields
54  *
55  */
56 static inline void nfs_clear_rpc_createerr(void)
57 {
58         memset(&rpc_createerr, 0, sizeof(rpc_createerr));
59 }
60
61 /*
62  * Extract port value from a socket address
63  */
64 extern uint16_t         nfs_get_port(const struct sockaddr *);
65
66 /*
67  * Set port value in a socket address
68  */
69 extern void             nfs_set_port(struct sockaddr *, const uint16_t);
70
71 /*
72  * Look up an RPC program name in /etc/rpc
73  */
74 extern rpcprog_t        nfs_getrpcbyname(const rpcprog_t, const char *table[]);
75
76 /*
77  * Acquire an RPC CLIENT * with an ephemeral source port
78  */
79 extern CLIENT           *nfs_get_rpcclient(const struct sockaddr *,
80                                 const socklen_t, const unsigned short,
81                                 const rpcprog_t, const rpcvers_t,
82                                 struct timeval *);
83
84 /*
85  * Acquire an RPC CLIENT * with a privileged source port
86  */
87 extern CLIENT           *nfs_get_priv_rpcclient( const struct sockaddr *,
88                                 const socklen_t, const unsigned short,
89                                 const rpcprog_t, const rpcvers_t,
90                                 struct timeval *);
91
92 /*
93  * Convert a netid to a protocol number and protocol family
94  */
95 extern int              nfs_get_proto(const char *netid, sa_family_t *family,
96                                 unsigned long *protocol);
97
98 /*
99  * Convert a protocol family and protocol name to a netid
100  */
101 extern char             *nfs_get_netid(const sa_family_t family,
102                                 const unsigned long protocol);
103
104 /*
105  * Convert a socket address to a universal address
106  */
107 extern char             *nfs_sockaddr2universal(const struct sockaddr *);
108
109 /*
110  * Extract port number from a universal address
111  */
112 extern int              nfs_universal2port(const char *);
113
114 /*
115  * Generic function that maps an RPC service tuple to an IP port
116  * number of the service on a remote post, and sends a NULL
117  * request to determine if the service is responding to requests
118  */
119 extern int              nfs_getport_ping(struct sockaddr *sap,
120                                 const socklen_t salen,
121                                 const rpcprog_t program,
122                                 const rpcvers_t version,
123                                 const unsigned short protocol);
124
125 /*
126  * Generic function that maps an RPC service tuple to an IP port
127  * number of the service on a remote host
128  */
129 extern unsigned short   nfs_getport(const struct sockaddr *,
130                                 const socklen_t, const rpcprog_t,
131                                 const rpcvers_t, const unsigned short);
132
133 /*
134  * Generic function that maps an RPC service tuple to an IP port
135  * number of the service on the local host
136  */
137 extern unsigned short   nfs_getlocalport(const rpcprot_t,
138                                 const rpcvers_t, const unsigned short);
139
140 /*
141  * Function to invoke an rpcbind v3/v4 GETADDR request
142  */
143 extern unsigned short   nfs_rpcb_getaddr(const struct sockaddr *,
144                                 const socklen_t,
145                                 const unsigned short,
146                                 const struct sockaddr *,
147                                 const rpcprog_t,
148                                 const rpcvers_t,
149                                 const unsigned short,
150                                 const struct timeval *);
151
152 /*
153  * Function to invoke a portmap GETPORT request
154  */
155 extern unsigned long    nfs_pmap_getport(const struct sockaddr_in *,
156                                 const unsigned short,
157                                 const unsigned long,
158                                 const unsigned long,
159                                 const unsigned long,
160                                 const struct timeval *);
161
162 /*
163  * Contact a remote RPC service to discover whether it is responding
164  * to requests.
165  */
166 extern int              nfs_rpc_ping(const struct sockaddr *sap,
167                                 const socklen_t salen,
168                                 const rpcprog_t program,
169                                 const rpcvers_t version,
170                                 const unsigned short protocol,
171                                 const struct timeval *timeout);
172
173 #endif  /* __NFS_UTILS_NFSRPC_H */