2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2016
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "system/network.h"
22 #include "system/locale.h"
27 #include <protocol/protocol.h>
28 #include <protocol/protocol_api.h>
35 #define MAP_END 0xffffffff
40 static void uint32_map_print(struct uint32_map
*map
, uint32_t key
, FILE *fp
)
44 while (map
[i
].key
!= MAP_END
) {
45 if (key
== map
[i
].key
) {
46 fprintf(fp
, "%s", map
[i
].name
);
52 fprintf(fp
, "UNKNOWN(%u)", key
);
55 static void tdb_data_print(TDB_DATA d
, FILE *fp
)
57 unsigned char *p
= (unsigned char *)d
.dptr
;
60 if (isprint(*p
) && !strchr("\"\\", *p
)) {
63 fprintf(fp
, "\\%02X", *p
);
73 static void ctdb_operation_print(uint32_t operation
, FILE *fp
)
75 struct uint32_map map
[] = {
76 { CTDB_REQ_CALL
, "REQ_CALL" },
77 { CTDB_REPLY_CALL
, "REPLY_CALL" },
78 { CTDB_REQ_DMASTER
, "REQ_DMASTER" },
79 { CTDB_REPLY_DMASTER
, "REPLY_DMASTER" },
80 { CTDB_REPLY_ERROR
, "REPLY_ERROR" },
81 { CTDB_REQ_MESSAGE
, "REQ_MESSAGE" },
82 { CTDB_REQ_CONTROL
, "REQ_CONTROL", },
83 { CTDB_REPLY_CONTROL
, "REPLY_CONTROL" },
84 { CTDB_REQ_KEEPALIVE
, "REQ_KEEPALIVE" },
88 uint32_map_print(map
, operation
, fp
);
91 static void ctdb_callid_print(uint32_t callid
, FILE *fp
)
93 struct uint32_map map
[] = {
94 { CTDB_NULL_FUNC
, "NULL" },
95 { CTDB_FETCH_FUNC
, "FETCH" },
96 { CTDB_FETCH_WITH_HEADER_FUNC
, "FETCH_WITH_HEADER" },
100 uint32_map_print(map
, callid
, fp
);
103 static void ctdb_opcode_print(uint32_t opcode
, FILE *fp
)
105 struct uint32_map map
[] = {
106 { CTDB_CONTROL_PROCESS_EXISTS
, "PROCESS_EXISTS" },
107 { CTDB_CONTROL_STATISTICS
, "STATISTICS" },
108 { CTDB_CONTROL_PING
, "PING" },
109 { CTDB_CONTROL_GETDBPATH
, "GETDBPATH" },
110 { CTDB_CONTROL_GETVNNMAP
, "GETVNNMAP" },
111 { CTDB_CONTROL_SETVNNMAP
, "SETVNNMAP" },
112 { CTDB_CONTROL_GET_DEBUG
, "GET_DEBUG" },
113 { CTDB_CONTROL_SET_DEBUG
, "SET_DEBUG" },
114 { CTDB_CONTROL_GET_DBMAP
, "GET_DBMAP" },
115 { CTDB_CONTROL_GET_NODEMAPv4
, "GET_NODEMAPv4" },
116 { CTDB_CONTROL_SET_DMASTER
, "SET_DMASTER" },
117 { CTDB_CONTROL_GET_RECMODE
, "GET_RECMODE" },
118 { CTDB_CONTROL_SET_RECMODE
, "SET_RECMODE" },
119 { CTDB_CONTROL_STATISTICS_RESET
, "STATISTICS_RESET" },
120 { CTDB_CONTROL_DB_ATTACH
, "DB_ATTACH" },
121 { CTDB_CONTROL_SET_CALL
, "SET_CALL" },
122 { CTDB_CONTROL_TRAVERSE_START
, "TRAVERSE_START" },
123 { CTDB_CONTROL_TRAVERSE_ALL
, "TRAVERSE_ALL" },
124 { CTDB_CONTROL_TRAVERSE_DATA
, "TRAVERSE_DATA" },
125 { CTDB_CONTROL_REGISTER_SRVID
, "REGISTER_SRVID" },
126 { CTDB_CONTROL_DEREGISTER_SRVID
, "DEREGISTER_SRVID" },
127 { CTDB_CONTROL_GET_DBNAME
, "GET_DBNAME" },
128 { CTDB_CONTROL_ENABLE_SEQNUM
, "ENABLE_SEQNUM" },
129 { CTDB_CONTROL_UPDATE_SEQNUM
, "UPDATE_SEQNUM" },
130 { CTDB_CONTROL_DUMP_MEMORY
, "DUMP_MEMORY" },
131 { CTDB_CONTROL_GET_PID
, "GET_PID" },
132 { CTDB_CONTROL_GET_RECMASTER
, "GET_RECMASTER" },
133 { CTDB_CONTROL_SET_RECMASTER
, "SET_RECMASTER" },
134 { CTDB_CONTROL_FREEZE
, "FREEZE" },
135 { CTDB_CONTROL_THAW
, "THAW" },
136 { CTDB_CONTROL_GET_PNN
, "GET_PNN" },
137 { CTDB_CONTROL_SHUTDOWN
, "SHUTDOWN" },
138 { CTDB_CONTROL_GET_MONMODE
, "GET_MONMODE" },
139 { CTDB_CONTROL_TAKEOVER_IPv4
, "TAKEOVER_IPv4" },
140 { CTDB_CONTROL_RELEASE_IPv4
, "RELEASE_IPv4" },
141 { CTDB_CONTROL_TCP_CLIENT
, "TCP_CLIENT" },
142 { CTDB_CONTROL_TCP_ADD
, "TCP_ADD" },
143 { CTDB_CONTROL_TCP_REMOVE
, "TCP_REMOVE" },
144 { CTDB_CONTROL_STARTUP
, "STARTUP" },
145 { CTDB_CONTROL_SET_TUNABLE
, "SET_TUNABLE" },
146 { CTDB_CONTROL_GET_TUNABLE
, "GET_TUNABLE" },
147 { CTDB_CONTROL_LIST_TUNABLES
, "LIST_TUNABLES" },
148 { CTDB_CONTROL_GET_PUBLIC_IPSv4
, "GET_PUBLIC_IPSv4" },
149 { CTDB_CONTROL_MODIFY_FLAGS
, "MODIFY_FLAGS" },
150 { CTDB_CONTROL_GET_ALL_TUNABLES
, "GET_ALL_TUNABLES" },
151 { CTDB_CONTROL_KILL_TCP
, "KILL_TCP" },
152 { CTDB_CONTROL_GET_TCP_TICKLE_LIST
, "GET_TCP_TICKLE_LIST" },
153 { CTDB_CONTROL_SET_TCP_TICKLE_LIST
, "SET_TCP_TICKLE_LIST" },
154 { CTDB_CONTROL_REGISTER_SERVER_ID
, "REGISTER_SERVER_ID" },
155 { CTDB_CONTROL_UNREGISTER_SERVER_ID
, "UNREGISTER_SERVER_ID" },
156 { CTDB_CONTROL_CHECK_SERVER_ID
, "CHECK_SERVER_ID" },
157 { CTDB_CONTROL_GET_SERVER_ID_LIST
, "GET_SERVER_ID_LIST" },
158 { CTDB_CONTROL_DB_ATTACH_PERSISTENT
, "DB_ATTACH_PERSISTENT" },
159 { CTDB_CONTROL_PERSISTENT_STORE
, "PERSISTENT_STORE" },
160 { CTDB_CONTROL_UPDATE_RECORD
, "UPDATE_RECORD" },
161 { CTDB_CONTROL_SEND_GRATUITOUS_ARP
, "SEND_GRATUITOUS_ARP" },
162 { CTDB_CONTROL_TRANSACTION_START
, "TRANSACTION_START" },
163 { CTDB_CONTROL_TRANSACTION_COMMIT
, "TRANSACTION_COMMIT" },
164 { CTDB_CONTROL_WIPE_DATABASE
, "WIPE_DATABASE" },
165 { CTDB_CONTROL_UPTIME
, "UPTIME" },
166 { CTDB_CONTROL_START_RECOVERY
, "START_RECOVERY" },
167 { CTDB_CONTROL_END_RECOVERY
, "END_RECOVERY" },
168 { CTDB_CONTROL_RELOAD_NODES_FILE
, "RELOAD_NODES_FILE" },
169 { CTDB_CONTROL_TRY_DELETE_RECORDS
, "TRY_DELETE_RECORDS" },
170 { CTDB_CONTROL_ENABLE_MONITOR
, "ENABLE_MONITOR" },
171 { CTDB_CONTROL_DISABLE_MONITOR
, "DISABLE_MONITOR" },
172 { CTDB_CONTROL_ADD_PUBLIC_IP
, "ADD_PUBLIC_IP" },
173 { CTDB_CONTROL_DEL_PUBLIC_IP
, "DEL_PUBLIC_IP" },
174 { CTDB_CONTROL_RUN_EVENTSCRIPTS
, "RUN_EVENTSCRIPTS" },
175 { CTDB_CONTROL_GET_CAPABILITIES
, "GET_CAPABILITIES" },
176 { CTDB_CONTROL_START_PERSISTENT_UPDATE
, "START_PERSISTENT_UPDATE" },
177 { CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE
, "CANCEL_PERSISTENT_UPDATE" },
178 { CTDB_CONTROL_TRANS2_COMMIT
, "TRANS2_COMMIT" },
179 { CTDB_CONTROL_TRANS2_FINISHED
, "TRANS2_FINISHED" },
180 { CTDB_CONTROL_TRANS2_ERROR
, "TRANS2_ERROR" },
181 { CTDB_CONTROL_TRANS2_COMMIT_RETRY
, "TRANS2_COMMIT_RETRY" },
182 { CTDB_CONTROL_RECD_PING
, "RECD_PING" },
183 { CTDB_CONTROL_RELEASE_IP
, "RELEASE_IP" },
184 { CTDB_CONTROL_TAKEOVER_IP
, "TAKEOVER_IP" },
185 { CTDB_CONTROL_GET_PUBLIC_IPS
, "GET_PUBLIC_IPS" },
186 { CTDB_CONTROL_GET_NODEMAP
, "GET_NODEMAP" },
187 { CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS
, "GET_EVENT_SCRIPT_STATUS" },
188 { CTDB_CONTROL_TRAVERSE_KILL
, "TRAVERSE_KILL" },
189 { CTDB_CONTROL_RECD_RECLOCK_LATENCY
, "RECD_RECLOCK_LATENCY" },
190 { CTDB_CONTROL_GET_RECLOCK_FILE
, "GET_RECLOCK_FILE" },
191 { CTDB_CONTROL_STOP_NODE
, "STOP_NODE" },
192 { CTDB_CONTROL_CONTINUE_NODE
, "CONTINUE_NODE" },
193 { CTDB_CONTROL_SET_NATGWSTATE
, "SET_NATGWSTATE" },
194 { CTDB_CONTROL_SET_LMASTERROLE
, "SET_LMASTERROLE" },
195 { CTDB_CONTROL_SET_RECMASTERROLE
, "SET_RECMASTERROLE" },
196 { CTDB_CONTROL_ENABLE_SCRIPT
, "ENABLE_SCRIPT" },
197 { CTDB_CONTROL_DISABLE_SCRIPT
, "DISABLE_SCRIPT" },
198 { CTDB_CONTROL_SET_BAN_STATE
, "SET_BAN_STATE" },
199 { CTDB_CONTROL_GET_BAN_STATE
, "GET_BAN_STATE" },
200 { CTDB_CONTROL_SET_DB_PRIORITY
, "SET_DB_PRIORITY" },
201 { CTDB_CONTROL_GET_DB_PRIORITY
, "GET_DB_PRIORITY" },
202 { CTDB_CONTROL_TRANSACTION_CANCEL
, "TRANSACTION_CANCEL" },
203 { CTDB_CONTROL_REGISTER_NOTIFY
, "REGISTER_NOTIFY" },
204 { CTDB_CONTROL_DEREGISTER_NOTIFY
, "DEREGISTER_NOTIFY" },
205 { CTDB_CONTROL_TRANS2_ACTIVE
, "TRANS2_ACTIVE" },
206 { CTDB_CONTROL_GET_LOG
, "GET_LOG" },
207 { CTDB_CONTROL_CLEAR_LOG
, "CLEAR_LOG" },
208 { CTDB_CONTROL_TRANS3_COMMIT
, "TRANS3_COMMIT" },
209 { CTDB_CONTROL_GET_DB_SEQNUM
, "GET_DB_SEQNUM" },
210 { CTDB_CONTROL_DB_SET_HEALTHY
, "DB_SET_HEALTHY" },
211 { CTDB_CONTROL_DB_GET_HEALTH
, "DB_GET_HEALTH" },
212 { CTDB_CONTROL_GET_PUBLIC_IP_INFO
, "GET_PUBLIC_IP_INFO" },
213 { CTDB_CONTROL_GET_IFACES
, "GET_IFACES" },
214 { CTDB_CONTROL_SET_IFACE_LINK_STATE
, "SET_IFACE_LINK_STATE" },
215 { CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE
, "TCP_ADD_DELAYED_UPDATE" },
216 { CTDB_CONTROL_GET_STAT_HISTORY
, "GET_STAT_HISTORY" },
217 { CTDB_CONTROL_SCHEDULE_FOR_DELETION
, "SCHEDULE_FOR_DELETION" },
218 { CTDB_CONTROL_SET_DB_READONLY
, "SET_DB_READONLY" },
219 { CTDB_CONTROL_CHECK_SRVIDS
, "CHECK_SRVIDS" },
220 { CTDB_CONTROL_TRAVERSE_START_EXT
, "TRAVERSE_START_EXT" },
221 { CTDB_CONTROL_GET_DB_STATISTICS
, "GET_DB_STATISTICS" },
222 { CTDB_CONTROL_SET_DB_STICKY
, "SET_DB_STICKY" },
223 { CTDB_CONTROL_RELOAD_PUBLIC_IPS
, "RELOAD_PUBLIC_IPS" },
224 { CTDB_CONTROL_TRAVERSE_ALL_EXT
, "TRAVERSE_ALL_EXT" },
225 { CTDB_CONTROL_RECEIVE_RECORDS
, "RECEIVE_RECORDS" },
226 { CTDB_CONTROL_IPREALLOCATED
, "IPREALLOCATED" },
227 { CTDB_CONTROL_GET_RUNSTATE
, "GET_RUNSTATE" },
228 { CTDB_CONTROL_DB_DETACH
, "DB_DETACH" },
229 { CTDB_CONTROL_GET_NODES_FILE
, "GET_NODES_FILE" },
230 { CTDB_CONTROL_DB_FREEZE
, "DB_FREEZE" },
231 { CTDB_CONTROL_DB_THAW
, "DB_THAW" },
232 { CTDB_CONTROL_DB_TRANSACTION_START
, "DB_TRANSACTION_START" },
233 { CTDB_CONTROL_DB_TRANSACTION_COMMIT
, "DB_TRANSACTION_COMMIT" },
234 { CTDB_CONTROL_DB_TRANSACTION_CANCEL
, "DB_TRANSACTION_CANCEL" },
235 { CTDB_CONTROL_DB_PULL
, "DB_PULL" },
236 { CTDB_CONTROL_DB_PUSH_START
, "DB_PUSH_START" },
237 { CTDB_CONTROL_DB_PUSH_CONFIRM
, "DB_PUSH_CONFIRM" },
238 { CTDB_CONTROL_DB_OPEN_FLAGS
, "DB_OPEN_FLAGS" },
239 { CTDB_CONTROL_DB_ATTACH_REPLICATED
, "DB_ATTACH_REPLICATED" },
240 { CTDB_CONTROL_CHECK_PID_SRVID
, "CHECK_PID_SRVID" },
241 { CTDB_CONTROL_TUNNEL_REGISTER
, "TUNNEL_REGISTER" },
242 { CTDB_CONTROL_TUNNEL_DEREGISTER
, "TUNNEL_DEREGISTER" },
243 { CTDB_CONTROL_VACUUM_FETCH
, "VACUUM_FETCH" },
244 { CTDB_CONTROL_DB_VACUUM
, "DB_VACUUM" },
245 { CTDB_CONTROL_ECHO_DATA
, "ECHO_DATA" },
249 uint32_map_print(map
, opcode
, fp
);
252 static void ctdb_control_flags_print(uint32_t flags
, FILE *fp
)
254 if (flags
& CTDB_CTRL_FLAG_NOREPLY
) {
255 fprintf(fp
, "NOREPLY ");
257 if (flags
& CTDB_CTRL_FLAG_OPCODE_SPECIFIC
) {
258 fprintf(fp
, "OPCODE_SPECIFIC ");
262 static void ctdb_pnn_print(uint32_t pnn
, FILE *fp
)
264 if (pnn
== CTDB_CURRENT_NODE
) {
265 fprintf(fp
, "CURRENT");
266 } else if (pnn
== CTDB_BROADCAST_ALL
) {
268 } else if (pnn
== CTDB_BROADCAST_ACTIVE
) {
269 fprintf(fp
, "ACTIVE");
270 } else if (pnn
== CTDB_BROADCAST_CONNECTED
) {
271 fprintf(fp
, "CONNECTED");
272 } else if (pnn
== CTDB_MULTICAST
) {
273 fprintf(fp
, "MULTICAST");
274 } else if (pnn
== CTDB_UNKNOWN_PNN
) {
275 fprintf(fp
, "UNKNOWN");
277 fprintf(fp
, "%u", pnn
);
281 static void ctdb_srvid_print(uint64_t srvid
, FILE *fp
)
283 uint64_t prefix
= 0xFFFF000000000000LL
;
285 if (srvid
== CTDB_SRVID_ALL
) {
287 } else if ((srvid
& prefix
) == CTDB_SRVID_RECOVERY
) {
288 srvid
= srvid
& ~CTDB_SRVID_RECOVERY
;
289 fprintf(fp
, "RECOVERY-%"PRIx64
"", srvid
);
290 } else if (srvid
== CTDB_SRVID_BANNING
) {
291 fprintf(fp
, "BANNING");
292 } else if (srvid
== CTDB_SRVID_ELECTION
) {
293 fprintf(fp
, "ELECTION");
294 } else if (srvid
== CTDB_SRVID_RECONFIGURE
) {
295 fprintf(fp
, "RECONFIGURE");
296 } else if (srvid
== CTDB_SRVID_RELEASE_IP
) {
297 fprintf(fp
, "RELEASE_IP");
298 } else if (srvid
== CTDB_SRVID_TAKE_IP
) {
299 fprintf(fp
, "TAKE_IP");
300 } else if (srvid
== CTDB_SRVID_SET_NODE_FLAGS
) {
301 fprintf(fp
, "SET_NODE_FLAGS");
302 } else if (srvid
== CTDB_SRVID_RECD_UPDATE_IP
) {
303 fprintf(fp
, "RECD_UPDATE_IP");
304 } else if (srvid
== CTDB_SRVID_VACUUM_FETCH
) {
305 fprintf(fp
, "VACUUM_FETCH");
306 } else if (srvid
== CTDB_SRVID_DETACH_DATABASE
) {
307 fprintf(fp
, "DETACH_DATABASE");
308 } else if (srvid
== CTDB_SRVID_MEM_DUMP
) {
309 fprintf(fp
, "MEM_DUMP");
310 } else if (srvid
== CTDB_SRVID_GETLOG
) {
311 fprintf(fp
, "GETLOG");
312 } else if (srvid
== CTDB_SRVID_CLEARLOG
) {
313 fprintf(fp
, "CLEARLOG");
314 } else if (srvid
== CTDB_SRVID_PUSH_NODE_FLAGS
) {
315 fprintf(fp
, "PUSH_NODE_FLAGS");
316 } else if (srvid
== CTDB_SRVID_RELOAD_NODES
) {
317 fprintf(fp
, "RELOAD_NODES");
318 } else if (srvid
== CTDB_SRVID_TAKEOVER_RUN
) {
319 fprintf(fp
, "TAKEOVER_RUN");
320 } else if (srvid
== CTDB_SRVID_REBALANCE_NODE
) {
321 fprintf(fp
, "REBALANCE_NODE");
322 } else if (srvid
== CTDB_SRVID_DISABLE_TAKEOVER_RUNS
) {
323 fprintf(fp
, "DISABLE_TAKEOVER_RUNS");
324 } else if (srvid
== CTDB_SRVID_DISABLE_RECOVERIES
) {
325 fprintf(fp
, "DISABLE_RECOVERIES");
326 } else if (srvid
== CTDB_SRVID_DISABLE_IP_CHECK
) {
327 fprintf(fp
, "DISABLE_IP_CHECK");
328 } else if ((srvid
& prefix
) == CTDB_SRVID_SAMBA_RANGE
) {
329 if (srvid
== CTDB_SRVID_SAMBA_NOTIFY
) {
330 fprintf(fp
, "SAMBA_NOTIFY");
332 srvid
&= ~CTDB_SRVID_SAMBA_RANGE
;
333 fprintf(fp
, "samba-0x%"PRIx64
"", srvid
);
335 } else if ((srvid
& prefix
) == CTDB_SRVID_NFSD_RANGE
) {
336 srvid
&= ~CTDB_SRVID_NFSD_RANGE
;
337 fprintf(fp
, "nfsd-0x%"PRIx64
"", srvid
);
338 } else if ((srvid
& prefix
) == CTDB_SRVID_ISCSID_RANGE
) {
339 srvid
&= ~CTDB_SRVID_ISCSID_RANGE
;
340 fprintf(fp
, "iscsi-0x%"PRIx64
"", srvid
);
341 } else if ((srvid
& prefix
) == CTDB_SRVID_TOOL_RANGE
) {
342 srvid
&= ~CTDB_SRVID_TOOL_RANGE
;
343 fprintf(fp
, "tool-0x%"PRIx64
"", srvid
);
344 } else if ((srvid
& prefix
) == CTDB_SRVID_TEST_RANGE
) {
345 srvid
&= ~CTDB_SRVID_TEST_RANGE
;
346 fprintf(fp
, "test-0x%"PRIx64
"", srvid
);
347 } else if ((srvid
& prefix
) == CTDB_SRVID_PID_RANGE
) {
348 if (srvid
< UINT16_MAX
) {
349 fprintf(fp
, "pid-%"PRIu64
, srvid
);
351 fprintf(fp
, "pid-0x%"PRIx64
, srvid
);
354 fprintf(fp
, "0x%"PRIx64
, srvid
);
358 static void ctdb_tunnel_id_print(uint64_t tunnel_id
, FILE *fp
)
360 if ((tunnel_id
& CTDB_TUNNEL_TEST
) == CTDB_TUNNEL_TEST
) {
361 fprintf(fp
, "TEST-%"PRIx64
, tunnel_id
);
363 fprintf(fp
, "0x%"PRIx64
, tunnel_id
);
367 static void ctdb_tunnel_flags_print(uint32_t flags
, FILE *fp
)
369 if (flags
& CTDB_TUNNEL_FLAG_REQUEST
) {
370 fprintf(fp
, "REQUEST ");
372 if (flags
& CTDB_TUNNEL_FLAG_REPLY
) {
373 fprintf(fp
, "REPLY ");
375 if (flags
& CTDB_TUNNEL_FLAG_NOREPLY
) {
376 fprintf(fp
, "NOREPLY ");
384 static void ctdb_req_header_print(struct ctdb_req_header
*h
, FILE *fp
)
386 fprintf(fp
, "Header\n");
387 fprintf(fp
, " length:%u magic:0x%"PRIx32
" version:%u generation:0x%"PRIx32
"\n",
388 h
->length
, h
->ctdb_magic
, h
->ctdb_version
, h
->generation
);
390 ctdb_operation_print(h
->operation
, fp
);
391 fprintf(fp
, " dst:");
392 ctdb_pnn_print(h
->destnode
, fp
);
393 fprintf(fp
, " src:");
394 ctdb_pnn_print(h
->srcnode
, fp
);
395 fprintf(fp
, " reqid:0x%"PRIx32
"\n", h
->reqid
);
398 static void ctdb_req_call_print(struct ctdb_req_call
*c
, FILE *fp
)
400 fprintf(fp
, "Data\n");
401 fprintf(fp
, " db:0x%"PRIx32
" ", c
->db_id
);
402 ctdb_callid_print(c
->callid
, fp
);
404 fprintf(fp
, " key:");
405 tdb_data_print(c
->key
, fp
);
409 static void ctdb_reply_call_print(struct ctdb_reply_call
*c
, FILE *fp
)
411 fprintf(fp
, "Data\n");
412 fprintf(fp
, " status:%d\n", c
->status
);
413 if (c
->status
== 0) {
414 fprintf(fp
, " data:");
415 tdb_data_print(c
->data
, fp
);
420 static void ctdb_req_dmaster_print(struct ctdb_req_dmaster
*c
, FILE *fp
)
422 fprintf(fp
, "Data\n");
423 fprintf(fp
, " db:0x%"PRIx32
" rsn:0x%"PRIx64
" dmaster:%u\n",
424 c
->db_id
, c
->rsn
, c
->dmaster
);
425 fprintf(fp
, " key:");
426 tdb_data_print(c
->key
, fp
);
428 fprintf(fp
, " data:");
429 tdb_data_print(c
->data
, fp
);
433 static void ctdb_reply_dmaster_print(struct ctdb_reply_dmaster
*c
, FILE *fp
)
435 fprintf(fp
, "Data\n");
436 fprintf(fp
, " db:0x%"PRIx32
" rsn:0x%"PRIx64
"\n", c
->db_id
, c
->rsn
);
437 fprintf(fp
, " key:");
438 tdb_data_print(c
->key
, fp
);
440 fprintf(fp
, " data:");
441 tdb_data_print(c
->data
, fp
);
445 static void ctdb_reply_error_print(struct ctdb_reply_error
*c
, FILE *fp
)
447 fprintf(fp
, "Data\n");
448 fprintf(fp
, " status:%d\n", c
->status
);
449 if (c
->status
!= 0) {
450 fprintf(fp
, " msg:");
451 tdb_data_print(c
->msg
, fp
);
456 static void ctdb_req_message_data_print(struct ctdb_req_message_data
*c
,
459 fprintf(fp
, "Data\n");
460 fprintf(fp
, " srvid:");
461 ctdb_srvid_print(c
->srvid
, fp
);
463 fprintf(fp
, " data:");
464 tdb_data_print(c
->data
, fp
);
468 static void ctdb_req_control_print(struct ctdb_req_control
*c
, FILE *fp
)
470 fprintf(fp
, "Data\n");
472 ctdb_opcode_print(c
->opcode
, fp
);
473 fprintf(fp
, " srvid:");
474 ctdb_srvid_print(c
->srvid
, fp
);
475 fprintf(fp
, " client_id:0x%"PRIx32
" ", c
->client_id
);
476 ctdb_control_flags_print(c
->flags
, fp
);
480 static void ctdb_reply_control_print(struct ctdb_reply_control
*c
, FILE *fp
)
482 fprintf(fp
, "Data\n");
483 fprintf(fp
, " status:%d ", c
->status
);
484 if (c
->errmsg
!= NULL
) {
485 fprintf(fp
, "errmsg: %s", c
->errmsg
);
490 static void ctdb_req_keepalive_print(struct ctdb_req_keepalive
*c
, FILE *fp
)
492 fprintf(fp
, "Data\n");
493 fprintf(fp
, " version:0x%"PRIx32
, c
->version
);
494 fprintf(fp
, " uptime:%"PRIu32
, c
->uptime
);
498 static void ctdb_req_tunnel_print(struct ctdb_req_tunnel
*c
, FILE *fp
)
500 fprintf(fp
, "Data\n");
501 fprintf(fp
, " tunnel_id:");
502 ctdb_tunnel_id_print(c
->tunnel_id
, fp
);
503 ctdb_tunnel_flags_print(c
->flags
, fp
);
504 tdb_data_print(c
->data
, fp
);
512 static void ctdb_req_call_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
515 struct ctdb_req_call c
;
518 ret
= ctdb_req_call_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
520 fprintf(fp
, "Failed to parse CTDB_REQ_CALL\n");
524 ctdb_req_call_print(&c
, fp
);
527 static void ctdb_reply_call_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
530 struct ctdb_reply_call c
;
533 ret
= ctdb_reply_call_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
535 fprintf(fp
, "Failed to parse CTDB_REPLY_CALL\n");
539 ctdb_reply_call_print(&c
, fp
);
542 static void ctdb_req_dmaster_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
545 struct ctdb_req_dmaster c
;
548 ret
= ctdb_req_dmaster_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
550 fprintf(fp
, "Failed to parse CTDB_REQ_DMASTER\n");
554 ctdb_req_dmaster_print(&c
, fp
);
557 static void ctdb_reply_dmaster_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
560 struct ctdb_reply_dmaster c
;
563 ret
= ctdb_reply_dmaster_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
565 fprintf(fp
, "Failed to parse CTDB_REPLY_DMASTER\n");
569 ctdb_reply_dmaster_print(&c
, fp
);
572 static void ctdb_reply_error_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
575 struct ctdb_reply_error c
;
578 ret
= ctdb_reply_error_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
580 fprintf(fp
, "Failed to parse CTDB_REPLY_ERROR\n");
584 ctdb_reply_error_print(&c
, fp
);
587 static void ctdb_req_message_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
590 struct ctdb_req_message_data c
;
593 ret
= ctdb_req_message_data_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
595 fprintf(fp
, "Failed to parse CTDB_REQ_MESSAGE\n");
599 ctdb_req_message_data_print(&c
, fp
);
602 static void ctdb_req_control_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
605 struct ctdb_req_control c
;
608 ret
= ctdb_req_control_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
610 fprintf(fp
, "Failed to parse CTDB_REQ_CONTROL\n");
614 ctdb_req_control_print(&c
, fp
);
617 static void ctdb_reply_control_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
620 struct ctdb_reply_control c
;
623 ret
= ctdb_reply_control_pull(buf
, buflen
, -1, NULL
, mem_ctx
, &c
);
625 fprintf(fp
, "Failed to parse CTDB_REPLY_CONTROL\n");
629 ctdb_reply_control_print(&c
, fp
);
632 static void ctdb_req_keepalive_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
635 struct ctdb_req_keepalive c
;
638 ret
= ctdb_req_keepalive_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
640 fprintf(fp
, "Failed to parse CTDB_REQ_KEEPALIVE\n");
644 ctdb_req_keepalive_print(&c
, fp
);
647 static void ctdb_req_tunnel_parse(uint8_t *buf
, size_t buflen
, FILE *fp
,
650 struct ctdb_req_tunnel c
;
653 ret
= ctdb_req_tunnel_pull(buf
, buflen
, NULL
, mem_ctx
, &c
);
655 fprintf(fp
, "Failed to parse CTDB_REQ_TUNNEL\n");
659 ctdb_req_tunnel_print(&c
, fp
);
666 void ctdb_packet_print(uint8_t *buf
, size_t buflen
, FILE *fp
)
668 TALLOC_CTX
*mem_ctx
= talloc_new(NULL
);
669 struct ctdb_req_header h
;
673 fprintf(fp
, "Buffer len:%zu\n", buflen
);
675 ret
= ctdb_req_header_pull(buf
, buflen
, &h
, &np
);
677 fprintf(fp
, "Failed to parse ctdb packet header\n");
681 ctdb_req_header_print(&h
, fp
);
683 if (h
.length
> buflen
) {
684 fprintf(fp
, "Packet length mismatch\n");
687 ret
= ctdb_req_header_verify(&h
, 0);
689 fprintf(fp
, "Invalid ctdb packet header\n");
693 switch (h
.operation
) {
695 ctdb_req_call_parse(buf
, buflen
, fp
, mem_ctx
);
698 case CTDB_REPLY_CALL
:
699 ctdb_reply_call_parse(buf
, buflen
, fp
, mem_ctx
);
702 case CTDB_REQ_DMASTER
:
703 ctdb_req_dmaster_parse(buf
, buflen
, fp
, mem_ctx
);
706 case CTDB_REPLY_DMASTER
:
707 ctdb_reply_dmaster_parse(buf
, buflen
, fp
, mem_ctx
);
710 case CTDB_REPLY_ERROR
:
711 ctdb_reply_error_parse(buf
, buflen
, fp
, mem_ctx
);
714 case CTDB_REQ_MESSAGE
:
715 ctdb_req_message_parse(buf
, buflen
, fp
, mem_ctx
);
718 case CTDB_REQ_CONTROL
:
719 ctdb_req_control_parse(buf
, buflen
, fp
, mem_ctx
);
722 case CTDB_REPLY_CONTROL
:
723 ctdb_reply_control_parse(buf
, buflen
, fp
, mem_ctx
);
726 case CTDB_REQ_KEEPALIVE
:
727 ctdb_req_keepalive_parse(buf
, buflen
, fp
, mem_ctx
);
730 case CTDB_REQ_TUNNEL
:
731 ctdb_req_tunnel_parse(buf
, buflen
, fp
, mem_ctx
);
735 fprintf(fp
, "Invalid ctdb operation\n");
739 talloc_free(mem_ctx
);