Imported Upstream version 3.1.0
[debian/amanda] / ndmp-src / ndmprotocol.h
1 /*
2  * Copyright (c) 1998,1999,2000
3  *      Traakan, Inc., Los Altos, CA
4  *      All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *      This is the key #include file for the NDMP protocol
35  *      layer of NDMJOBLIB.
36  *
37  *      There are multiple version of NDMP. This gathers them together.
38  *      Under control of #ifdef NDMOS_OPTION_NO_NDMPx specific versions
39  *      may be omitted. At this time, NDMPv2 and NDMPv3 are deployed.
40  *      NDMPv1 was defined but not widely deployed, and deemed irrelavent.
41  *      NDMPv4 is under consideration.
42  *
43  *      NDMP is defined using RPC protocol specification
44  *      files (.x files). NDMP does not really use the RPC
45  *      layer, but it does use the RPC XDR (External Data
46  *      Representation) layer.
47  *
48  *      The original NDMP .x files are cosmetically transformed for
49  *      NDMJOBLIB. The original NDMPv2 and NDMPv3 .x files use names
50  *      like ndmp_name and ndmp_config_get_host_info_reply. These
51  *      changed between versions even though they have the same name.
52  *      Data structures which didn't change, like ndmp_pval, caused
53  *      compile-time agony. For example, xdr_ndmp_pval() would be
54  *      multiply defined at ld(1)-time. The first approach considered
55  *      and rejected to resolve this was to make a unified, all
56  *      versions .x file. It was rejected because it becomes difficult,
57  *      even impractical, to integrate new versions and to omit old ones.
58  *      The approach taken was to transform the names to reflect protocol
59  *      version. This same approach was adopted by NFS for NFSv3 and
60  *      NFSv4. Now there is an ndmp2_pval and an ndmp3_pval, and the
61  *      compiler is happy. When it's defined, there will be an ndmp4_pval.
62  *
63  *      There are two pseudo-versions of the protocol here: NDMPv0
64  *      and NDMPv9. These are used for internal convenience. These
65  *      are also defined using .x files because it's easy to
66  *      cut-n-paste from the official .x files. Neither NDMPv0
67  *      nor NDMPv9 may be omitted.
68  *
69  *      NDMPv0 is the NDMP protocol subset used before the protocol
70  *      version negotiation is complete. This subset of the protocol
71  *      must necessarily remain immutable and constant for all time.
72  *      NDMPv0 is the over-the-wire protocol until the version is
73  *      negotiated.
74  *
75  *      NDMPv9 is an internal representation of the protocol and
76  *      isolates higher layers of NDMJOB from most variations between
77  *      protocol version. NDMPv9 makes it a little easier to add
78  *      new versions and omit older ones. NDMPv9 is never used
79  *      over-the-wire, and therefor there are no XDR routines.
80  *
81  *      There are three primary elements of this layer:
82  *
83  *      1) Header files which define each version of the protocol.
84  *         These are generated from files (.x files) by rpcgen(1).
85  *
86  *      2) XDR routines which convert to/from the over-the-wire
87  *         protocol and internal data structures. These are
88  *         also generated by rpcgen(1). There are also
89  *         tables of XDR routines.
90  *
91  *      3) Support for pretty-printing the protocol data structures.
92  *         Maybe someday rpcgen(1) will generate these, too.
93  */
94
95
96 /*
97  * PROTOCOL VERSIONS
98  ****************************************************************
99  *
100  */
101
102 #include "ndmp0.h"
103
104 #ifndef NDMOS_OPTION_NO_NDMP2
105 #include "ndmp2.h"
106 #endif /* !NDMOS_OPTION_NO_NDMP2 */
107
108 #ifndef NDMOS_OPTION_NO_NDMP3
109 #include "ndmp3.h"
110 #endif /* !NDMOS_OPTION_NO_NDMP3 */
111
112 #ifndef NDMOS_OPTION_NO_NDMP4
113 #include "ndmp4.h"
114 #endif /* !NDMOS_OPTION_NO_NDMP4 */
115
116 #include "ndmp9.h"
117
118
119
120
121 /*
122  * Protocol ammendments. These are important constants
123  * omitted from the spec and .x files.
124  */
125 #include "ndmp_ammend.h"
126
127
128
129
130 /*
131  * XDR MESSAGE TABLES
132  ****************************************************************
133  *
134  * Table for binding a ndmp_message to appropriate XDR routines.
135  */
136
137 struct ndmp_xdr_message_table {
138         int     msg;
139         int     (*xdr_request)();
140         int     (*xdr_reply)();
141 };
142
143 extern struct ndmp_xdr_message_table    ndmp0_xdr_message_table[];
144
145 #ifndef NDMOS_OPTION_NO_NDMP2
146 extern struct ndmp_xdr_message_table    ndmp2_xdr_message_table[];
147 #endif /* !NDMOS_OPTION_NO_NDMP2 */
148
149 #ifndef NDMOS_OPTION_NO_NDMP3
150 extern struct ndmp_xdr_message_table    ndmp3_xdr_message_table[];
151 #endif /* !NDMOS_OPTION_NO_NDMP3 */
152
153 #ifndef NDMOS_OPTION_NO_NDMP4
154 extern struct ndmp_xdr_message_table    ndmp4_xdr_message_table[];
155 #endif /* !NDMOS_OPTION_NO_NDMP4 */
156
157 /* Note: no ndmp9 XDRs */
158
159 extern struct ndmp_xdr_message_table *
160                 ndmp_xmt_lookup (int protocol_version, int msg);
161
162
163
164
165 /*
166  * ENUM STRING TABLES
167  ****************************************************************
168  */
169
170 struct ndmp_enum_str_table {
171         char *          name;
172         int             value;
173 };
174
175 extern char *   ndmp_enum_to_str (int val, struct ndmp_enum_str_table *table);
176 extern int      ndmp_enum_from_str (int *valp, char *str,
177                                  struct ndmp_enum_str_table *table);
178
179
180 #include "ndmp0_enum_strs.h"
181
182 #ifndef NDMOS_OPTION_NO_NDMP2
183 #include "ndmp2_enum_strs.h"
184 #endif /* !NDMOS_OPTION_NO_NDMP2 */
185
186 #ifndef NDMOS_OPTION_NO_NDMP3
187 #include "ndmp3_enum_strs.h"
188 #endif /* !NDMOS_OPTION_NO_NDMP3 */
189
190 #ifndef NDMOS_OPTION_NO_NDMP4
191 #include "ndmp4_enum_strs.h"
192 #endif /* !NDMOS_OPTION_NO_NDMP4 */
193
194 #include "ndmp9_enum_strs.h"
195
196
197
198
199 /*
200  * MULTI-VERSION ENUM TO STRING CONVERTERS
201  ****************************************************************
202  */
203
204 extern char *   ndmp_message_to_str (int protocol_version, int msg);
205 extern char *   ndmp_error_to_str (int protocol_version, int msg);
206
207
208
209
210 /*
211  * PRETTY PRINTERS
212  ****************************************************************
213  *
214  * The ndmp[v]_pp_... (pretty printer) routines are debugging aids.
215  * They pretty much implement an NDMP snooping package.
216  *
217  * All routines return -1 for an error. Otherwise, they
218  * return the number of lines required to print the entire
219  * data structure.  A return of 0 indicates a void data
220  * structure. lineno parameter begins at 0.
221  *
222  * Line number 0 is usually usable as a summary.
223  * Three levels of increasing detail are easy:
224  *      1) Just ndmp_pp_header()
225  *      2) ndmp_pp_header() and ndmp_pp_{request|reply} w/ lineno=0
226  *      3) ndmp_pp_header() and ndmp_pp_{request|reply} all lines
227  */
228
229
230 extern int      ndmp_pp_header (int vers, void *data, char *buf);
231 extern int      ndmp_pp_request (int vers, int msg,
232                                 void *data, int lineno, char *buf);
233 extern int      ndmp_pp_reply (int vers, int msg,
234                                 void *data, int lineno, char *buf);
235
236 extern int      ndmp0_pp_header (void *data, char *buf);
237 extern int      ndmp0_pp_request (ndmp0_message msg,
238                                 void *data, int lineno, char *buf);
239 extern int      ndmp0_pp_reply (ndmp0_message msg,
240                                 void *data, int lineno, char *buf);
241
242 #ifndef NDMOS_OPTION_NO_NDMP2
243 extern int      ndmp2_pp_header (void *data, char *buf);
244 extern int      ndmp2_pp_request (ndmp2_message msg,
245                                 void *data, int lineno, char *buf);
246 extern int      ndmp2_pp_reply (ndmp2_message msg,
247                                 void *data, int lineno, char *buf);
248 #endif /* !NDMOS_OPTION_NO_NDMP2 */
249
250 #ifndef NDMOS_OPTION_NO_NDMP3
251 extern int      ndmp3_pp_header (void *data, char *buf);
252 extern int      ndmp3_pp_request (ndmp3_message msg,
253                                 void *data, int lineno, char *buf);
254 extern int      ndmp3_pp_reply (ndmp3_message msg,
255                                 void *data, int lineno, char *buf);
256 #endif /* !NDMOS_OPTION_NO_NDMP3 */
257
258 #ifndef NDMOS_OPTION_NO_NDMP4
259 extern int      ndmp4_pp_header (void *data, char *buf);
260 extern int      ndmp4_pp_request (ndmp4_message msg,
261                                 void *data, int lineno, char *buf);
262 extern int      ndmp4_pp_reply (ndmp4_message msg,
263                                 void *data, int lineno, char *buf);
264 #endif /* !NDMOS_OPTION_NO_NDMP4 */
265
266
267 #define NDMP_PP_AS(T) ((T *)data)
268
269 #define NDMP_PP_WITH(T) { T * p = ((T *)data);
270 #define NDMP_PP_ENDWITH }