-
Notifications
You must be signed in to change notification settings - Fork 4
/
virnetprotocol.x
238 lines (213 loc) · 7.17 KB
/
virnetprotocol.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* -*- c -*-
* virnetprotocol.x: basic protocol for all RPC services.
*
* Copyright (C) 2006-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Richard Jones <[email protected]>
*/
%#include "internal.h"
%#include "virxdrdefs.h"
%#include <arpa/inet.h>
/*----- Data types. -----*/
/* Initial message size.
* When the message payload is larger this initial size will be
* quadrupled until the maximum total message size is reached.
*/
const VIR_NET_MESSAGE_INITIAL = 65536;
/*
* Until we enlarged the message buffers, this was the max
* payload size. We need to remember this for compat with
* old clients.
*/
const VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX = 262120;
/* Maximum total message size (serialised). */
const VIR_NET_MESSAGE_MAX = 16777216;
/* Size of struct virNetMessageHeader (serialised)*/
const VIR_NET_MESSAGE_HEADER_MAX = 24;
/* Size of message payload */
const VIR_NET_MESSAGE_PAYLOAD_MAX = 16777192;
/* Size of message length field. Not counted in VIR_NET_MESSAGE_MAX
* and VIR_NET_MESSAGE_INITIAL.
*/
const VIR_NET_MESSAGE_LEN_MAX = 4;
/* Length of long, but not unbounded, strings.
* This is an arbitrary limit designed to stop the decoder from trying
* to allocate unbounded amounts of memory when fed with a bad message.
*/
const VIR_NET_MESSAGE_STRING_MAX = 4194304;
/* Limit on number of File Descriptors allowed to be
* passed per message
*/
const VIR_NET_MESSAGE_NUM_FDS_MAX = 32;
/*
* RPC wire format
*
* Each message consists of:
*
* Name | Type | Description
* -----------+-----------------------+------------------
* Length | int | Total number of bytes in message _including_ length.
* Header | virNetMessageHeader | Control information about procedure call
* Payload | - | Variable payload data per procedure
*
* In header, the 'serial' field varies according to:
*
* - type == VIR_NET_CALL
* * serial is set by client, incrementing by 1 each time
*
* - type == VIR_NET_REPLY
* * serial matches that from the corresponding VIR_NET_CALL
*
* - type == VIR_NET_MESSAGE
* * serial is always zero
*
* - type == VIR_NET_STREAM
* * serial matches that from the corresponding VIR_NET_CALL
*
* and the 'status' field varies according to:
*
* - type == VIR_NET_CALL
* * VIR_NET_OK always
*
* - type == VIR_NET_REPLY
* * VIR_NET_OK if RPC finished successfully
* * VIR_NET_ERROR if something failed
*
* - type == VIR_NET_MESSAGE
* * VIR_NET_OK always
*
* - type == VIR_NET_STREAM
* * VIR_NET_CONTINUE if more data is following
* * VIR_NET_OK if stream is complete
* * VIR_NET_ERROR
* server message: stream had an error
* client message: client aborted the stream
*
* Payload varies according to type and status:
*
* - type == VIR_NET_CALL
* XXX_args for procedure
*
* - type == VIR_NET_REPLY
* * status == VIR_NET_OK
* XXX_ret for procedure
* * status == VIR_NET_ERROR
* remote_error Error information
*
* - type == VIR_NET_MESSAGE
* * status == VIR_NET_OK
* XXX_msg for event information
*
* - type == VIR_NET_STREAM
* * status == VIR_NET_CONTINUE
* byte[] raw stream data
* * status == VIR_NET_ERROR
* server message: remote_error error information
* client message: <empty>
* * status == VIR_NET_OK
* <empty>
*
* - type == VIR_NET_CALL_WITH_FDS
* int8 - number of FDs
* XXX_args for procedure
*
* - type == VIR_NET_REPLY_WITH_FDS
* int8 - number of FDs
* * status == VIR_NET_OK
* XXX_ret for procedure
* * status == VIR_NET_ERROR
* remote_error Error information
*
*/
enum virNetMessageType {
/* client -> server. args from a method call */
VIR_NET_CALL = 0,
/* server -> client. reply/error from a method call */
VIR_NET_REPLY = 1,
/* either direction. async notification */
VIR_NET_MESSAGE = 2,
/* either direction. stream data packet */
VIR_NET_STREAM = 3,
/* client -> server. args from a method call, with passed FDs */
VIR_NET_CALL_WITH_FDS = 4,
/* server -> client. reply/error from a method call, with passed FDs */
VIR_NET_REPLY_WITH_FDS = 5
};
enum virNetMessageStatus {
/* Status is always VIR_NET_OK for calls.
* For replies, indicates no error.
*/
VIR_NET_OK = 0,
/* For replies, indicates that an error happened, and a struct
* remote_error follows.
*/
VIR_NET_ERROR = 1,
/* For streams, indicates that more data is still expected
*/
VIR_NET_CONTINUE = 2
};
/* 4 byte length word per header */
const VIR_NET_MESSAGE_HEADER_XDR_LEN = 4;
struct virNetMessageHeader {
unsigned prog; /* Unique ID for the program */
unsigned vers; /* Program version number */
int proc; /* Unique ID for the procedure within the program */
virNetMessageType type; /* Type of message */
unsigned serial; /* Serial number of message. */
virNetMessageStatus status;
};
/* Error message. See <virterror.h> for explanation of fields. */
/* Most of these don't really belong here. There are sadly needed
* for wire ABI backwards compatibility with the rather crazy
* error struct we previously defined :-(
*/
typedef opaque virNetMessageUUID[VIR_UUID_BUFLEN];
typedef string virNetMessageNonnullString<VIR_NET_MESSAGE_STRING_MAX>;
/* A long string, which may be NULL. */
typedef virNetMessageNonnullString *virNetMessageString;
/* A domain which may not be NULL. */
struct virNetMessageNonnullDomain {
virNetMessageNonnullString name;
virNetMessageUUID uuid;
int id;
};
/* A network which may not be NULL. */
struct virNetMessageNonnullNetwork {
virNetMessageNonnullString name;
virNetMessageUUID uuid;
};
typedef virNetMessageNonnullDomain *virNetMessageDomain;
typedef virNetMessageNonnullNetwork *virNetMessageNetwork;
/* NB. Fields "code", "domain" and "level" are really enums. The
* numeric value should remain compatible between libvirt and
* libvirtd. This means, no changing or reordering the enums as
* defined in <virterror.h> (but we don't do that anyway, for separate
* ABI reasons).
*/
struct virNetMessageError {
int code;
int domain;
virNetMessageString message;
int level;
virNetMessageDomain dom; /* unused */
virNetMessageString str1;
virNetMessageString str2;
virNetMessageString str3;
int int1;
int int2;
virNetMessageNetwork net; /* unused */
};