libndr/compression: pass down compressed length in ndr_pull_compression_start
[Samba.git] / ctdb / protocol / protocol_debug.c
blob574f903b2c00d0ec0245aecbb87048b08c02a3d3
1 /*
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/>.
20 #include "replace.h"
21 #include "system/network.h"
22 #include "system/locale.h"
24 #include <talloc.h>
25 #include <tdb.h>
27 #include <protocol/protocol.h>
28 #include <protocol/protocol_api.h>
31 * Utility functions
33 struct uint32_map {
34 uint32_t key;
35 #define MAP_END 0xffffffff
36 const char *name;
40 static void uint32_map_print(struct uint32_map *map, uint32_t key, FILE *fp)
42 int i = 0;
44 while (map[i].key != MAP_END) {
45 if (key == map[i].key) {
46 fprintf(fp, "%s", map[i].name);
47 return;
49 i = i+1;
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;
58 int len = d.dsize;
59 while (len--) {
60 if (isprint(*p) && !strchr("\"\\", *p)) {
61 fputc(*p, fp);
62 } else {
63 fprintf(fp, "\\%02X", *p);
65 p++;
70 * Data types
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" },
85 { MAP_END, "" },
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" },
97 { MAP_END, "" },
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_PULL_DB, "PULL_DB" },
118 { CTDB_CONTROL_PUSH_DB, "PUSH_DB" },
119 { CTDB_CONTROL_GET_RECMODE, "GET_RECMODE" },
120 { CTDB_CONTROL_SET_RECMODE, "SET_RECMODE" },
121 { CTDB_CONTROL_STATISTICS_RESET, "STATISTICS_RESET" },
122 { CTDB_CONTROL_DB_ATTACH, "DB_ATTACH" },
123 { CTDB_CONTROL_SET_CALL, "SET_CALL" },
124 { CTDB_CONTROL_TRAVERSE_START, "TRAVERSE_START" },
125 { CTDB_CONTROL_TRAVERSE_ALL, "TRAVERSE_ALL" },
126 { CTDB_CONTROL_TRAVERSE_DATA, "TRAVERSE_DATA" },
127 { CTDB_CONTROL_REGISTER_SRVID, "REGISTER_SRVID" },
128 { CTDB_CONTROL_DEREGISTER_SRVID, "DEREGISTER_SRVID" },
129 { CTDB_CONTROL_GET_DBNAME, "GET_DBNAME" },
130 { CTDB_CONTROL_ENABLE_SEQNUM, "ENABLE_SEQNUM" },
131 { CTDB_CONTROL_UPDATE_SEQNUM, "UPDATE_SEQNUM" },
132 { CTDB_CONTROL_DUMP_MEMORY, "DUMP_MEMORY" },
133 { CTDB_CONTROL_GET_PID, "GET_PID" },
134 { CTDB_CONTROL_GET_RECMASTER, "GET_RECMASTER" },
135 { CTDB_CONTROL_SET_RECMASTER, "SET_RECMASTER" },
136 { CTDB_CONTROL_FREEZE, "FREEZE" },
137 { CTDB_CONTROL_THAW, "THAW" },
138 { CTDB_CONTROL_GET_PNN, "GET_PNN" },
139 { CTDB_CONTROL_SHUTDOWN, "SHUTDOWN" },
140 { CTDB_CONTROL_GET_MONMODE, "GET_MONMODE" },
141 { CTDB_CONTROL_TAKEOVER_IPv4, "TAKEOVER_IPv4" },
142 { CTDB_CONTROL_RELEASE_IPv4, "RELEASE_IPv4" },
143 { CTDB_CONTROL_TCP_CLIENT, "TCP_CLIENT" },
144 { CTDB_CONTROL_TCP_ADD, "TCP_ADD" },
145 { CTDB_CONTROL_TCP_REMOVE, "TCP_REMOVE" },
146 { CTDB_CONTROL_STARTUP, "STARTUP" },
147 { CTDB_CONTROL_SET_TUNABLE, "SET_TUNABLE" },
148 { CTDB_CONTROL_GET_TUNABLE, "GET_TUNABLE" },
149 { CTDB_CONTROL_LIST_TUNABLES, "LIST_TUNABLES" },
150 { CTDB_CONTROL_GET_PUBLIC_IPSv4, "GET_PUBLIC_IPSv4" },
151 { CTDB_CONTROL_MODIFY_FLAGS, "MODIFY_FLAGS" },
152 { CTDB_CONTROL_GET_ALL_TUNABLES, "GET_ALL_TUNABLES" },
153 { CTDB_CONTROL_KILL_TCP, "KILL_TCP" },
154 { CTDB_CONTROL_GET_TCP_TICKLE_LIST, "GET_TCP_TICKLE_LIST" },
155 { CTDB_CONTROL_SET_TCP_TICKLE_LIST, "SET_TCP_TICKLE_LIST" },
156 { CTDB_CONTROL_REGISTER_SERVER_ID, "REGISTER_SERVER_ID" },
157 { CTDB_CONTROL_UNREGISTER_SERVER_ID, "UNREGISTER_SERVER_ID" },
158 { CTDB_CONTROL_CHECK_SERVER_ID, "CHECK_SERVER_ID" },
159 { CTDB_CONTROL_GET_SERVER_ID_LIST, "GET_SERVER_ID_LIST" },
160 { CTDB_CONTROL_DB_ATTACH_PERSISTENT, "DB_ATTACH_PERSISTENT" },
161 { CTDB_CONTROL_PERSISTENT_STORE, "PERSISTENT_STORE" },
162 { CTDB_CONTROL_UPDATE_RECORD, "UPDATE_RECORD" },
163 { CTDB_CONTROL_SEND_GRATUITOUS_ARP, "SEND_GRATUITOUS_ARP" },
164 { CTDB_CONTROL_TRANSACTION_START, "TRANSACTION_START" },
165 { CTDB_CONTROL_TRANSACTION_COMMIT, "TRANSACTION_COMMIT" },
166 { CTDB_CONTROL_WIPE_DATABASE, "WIPE_DATABASE" },
167 { CTDB_CONTROL_UPTIME, "UPTIME" },
168 { CTDB_CONTROL_START_RECOVERY, "START_RECOVERY" },
169 { CTDB_CONTROL_END_RECOVERY, "END_RECOVERY" },
170 { CTDB_CONTROL_RELOAD_NODES_FILE, "RELOAD_NODES_FILE" },
171 { CTDB_CONTROL_TRY_DELETE_RECORDS, "TRY_DELETE_RECORDS" },
172 { CTDB_CONTROL_ENABLE_MONITOR, "ENABLE_MONITOR" },
173 { CTDB_CONTROL_DISABLE_MONITOR, "DISABLE_MONITOR" },
174 { CTDB_CONTROL_ADD_PUBLIC_IP, "ADD_PUBLIC_IP" },
175 { CTDB_CONTROL_DEL_PUBLIC_IP, "DEL_PUBLIC_IP" },
176 { CTDB_CONTROL_RUN_EVENTSCRIPTS, "RUN_EVENTSCRIPTS" },
177 { CTDB_CONTROL_GET_CAPABILITIES, "GET_CAPABILITIES" },
178 { CTDB_CONTROL_START_PERSISTENT_UPDATE, "START_PERSISTENT_UPDATE" },
179 { CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE, "CANCEL_PERSISTENT_UPDATE" },
180 { CTDB_CONTROL_TRANS2_COMMIT, "TRANS2_COMMIT" },
181 { CTDB_CONTROL_TRANS2_FINISHED, "TRANS2_FINISHED" },
182 { CTDB_CONTROL_TRANS2_ERROR, "TRANS2_ERROR" },
183 { CTDB_CONTROL_TRANS2_COMMIT_RETRY, "TRANS2_COMMIT_RETRY" },
184 { CTDB_CONTROL_RECD_PING, "RECD_PING" },
185 { CTDB_CONTROL_RELEASE_IP, "RELEASE_IP" },
186 { CTDB_CONTROL_TAKEOVER_IP, "TAKEOVER_IP" },
187 { CTDB_CONTROL_GET_PUBLIC_IPS, "GET_PUBLIC_IPS" },
188 { CTDB_CONTROL_GET_NODEMAP, "GET_NODEMAP" },
189 { CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, "GET_EVENT_SCRIPT_STATUS" },
190 { CTDB_CONTROL_TRAVERSE_KILL, "TRAVERSE_KILL" },
191 { CTDB_CONTROL_RECD_RECLOCK_LATENCY, "RECD_RECLOCK_LATENCY" },
192 { CTDB_CONTROL_GET_RECLOCK_FILE, "GET_RECLOCK_FILE" },
193 { CTDB_CONTROL_STOP_NODE, "STOP_NODE" },
194 { CTDB_CONTROL_CONTINUE_NODE, "CONTINUE_NODE" },
195 { CTDB_CONTROL_SET_NATGWSTATE, "SET_NATGWSTATE" },
196 { CTDB_CONTROL_SET_LMASTERROLE, "SET_LMASTERROLE" },
197 { CTDB_CONTROL_SET_RECMASTERROLE, "SET_RECMASTERROLE" },
198 { CTDB_CONTROL_ENABLE_SCRIPT, "ENABLE_SCRIPT" },
199 { CTDB_CONTROL_DISABLE_SCRIPT, "DISABLE_SCRIPT" },
200 { CTDB_CONTROL_SET_BAN_STATE, "SET_BAN_STATE" },
201 { CTDB_CONTROL_GET_BAN_STATE, "GET_BAN_STATE" },
202 { CTDB_CONTROL_SET_DB_PRIORITY, "SET_DB_PRIORITY" },
203 { CTDB_CONTROL_GET_DB_PRIORITY, "GET_DB_PRIORITY" },
204 { CTDB_CONTROL_TRANSACTION_CANCEL, "TRANSACTION_CANCEL" },
205 { CTDB_CONTROL_REGISTER_NOTIFY, "REGISTER_NOTIFY" },
206 { CTDB_CONTROL_DEREGISTER_NOTIFY, "DEREGISTER_NOTIFY" },
207 { CTDB_CONTROL_TRANS2_ACTIVE, "TRANS2_ACTIVE" },
208 { CTDB_CONTROL_GET_LOG, "GET_LOG" },
209 { CTDB_CONTROL_CLEAR_LOG, "CLEAR_LOG" },
210 { CTDB_CONTROL_TRANS3_COMMIT, "TRANS3_COMMIT" },
211 { CTDB_CONTROL_GET_DB_SEQNUM, "GET_DB_SEQNUM" },
212 { CTDB_CONTROL_DB_SET_HEALTHY, "DB_SET_HEALTHY" },
213 { CTDB_CONTROL_DB_GET_HEALTH, "DB_GET_HEALTH" },
214 { CTDB_CONTROL_GET_PUBLIC_IP_INFO, "GET_PUBLIC_IP_INFO" },
215 { CTDB_CONTROL_GET_IFACES, "GET_IFACES" },
216 { CTDB_CONTROL_SET_IFACE_LINK_STATE, "SET_IFACE_LINK_STATE" },
217 { CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE, "TCP_ADD_DELAYED_UPDATE" },
218 { CTDB_CONTROL_GET_STAT_HISTORY, "GET_STAT_HISTORY" },
219 { CTDB_CONTROL_SCHEDULE_FOR_DELETION, "SCHEDULE_FOR_DELETION" },
220 { CTDB_CONTROL_SET_DB_READONLY, "SET_DB_READONLY" },
221 { CTDB_CONTROL_CHECK_SRVIDS, "CHECK_SRVIDS" },
222 { CTDB_CONTROL_TRAVERSE_START_EXT, "TRAVERSE_START_EXT" },
223 { CTDB_CONTROL_GET_DB_STATISTICS, "GET_DB_STATISTICS" },
224 { CTDB_CONTROL_SET_DB_STICKY, "SET_DB_STICKY" },
225 { CTDB_CONTROL_RELOAD_PUBLIC_IPS, "RELOAD_PUBLIC_IPS" },
226 { CTDB_CONTROL_TRAVERSE_ALL_EXT, "TRAVERSE_ALL_EXT" },
227 { CTDB_CONTROL_RECEIVE_RECORDS, "RECEIVE_RECORDS" },
228 { CTDB_CONTROL_IPREALLOCATED, "IPREALLOCATED" },
229 { CTDB_CONTROL_GET_RUNSTATE, "GET_RUNSTATE" },
230 { CTDB_CONTROL_DB_DETACH, "DB_DETACH" },
231 { CTDB_CONTROL_GET_NODES_FILE, "GET_NODES_FILE" },
232 { CTDB_CONTROL_DB_FREEZE, "DB_FREEZE" },
233 { CTDB_CONTROL_DB_THAW, "DB_THAW" },
234 { CTDB_CONTROL_DB_TRANSACTION_START, "DB_TRANSACTION_START" },
235 { CTDB_CONTROL_DB_TRANSACTION_COMMIT, "DB_TRANSACTION_COMMIT" },
236 { CTDB_CONTROL_DB_TRANSACTION_CANCEL, "DB_TRANSACTION_CANCEL" },
237 { CTDB_CONTROL_DB_PULL, "DB_PULL" },
238 { CTDB_CONTROL_DB_PUSH_START, "DB_PUSH_START" },
239 { CTDB_CONTROL_DB_PUSH_CONFIRM, "DB_PUSH_CONFIRM" },
240 { CTDB_CONTROL_DB_OPEN_FLAGS, "DB_OPEN_FLAGS" },
241 { CTDB_CONTROL_DB_ATTACH_REPLICATED, "DB_ATTACH_REPLICATED" },
242 { MAP_END, "" },
245 uint32_map_print(map, opcode, fp);
248 static void ctdb_control_flags_print(uint32_t flags, FILE *fp)
250 if (flags & CTDB_CTRL_FLAG_NOREPLY) {
251 fprintf(fp, "NOREPLY ");
253 if (flags & CTDB_CTRL_FLAG_OPCODE_SPECIFIC) {
254 fprintf(fp, "OPCODE_SPECIFIC ");
258 static void ctdb_pnn_print(uint32_t pnn, FILE *fp)
260 if (pnn == CTDB_CURRENT_NODE) {
261 fprintf(fp, "CURRENT");
262 } else if (pnn == CTDB_BROADCAST_ALL) {
263 fprintf(fp, "ALL");
264 } else if (pnn == CTDB_BROADCAST_VNNMAP) {
265 fprintf(fp, "VNNMAP");
266 } else if (pnn == CTDB_BROADCAST_CONNECTED) {
267 fprintf(fp, "CONNECTED");
268 } else if (pnn == CTDB_MULTICAST) {
269 fprintf(fp, "MULTICAST");
270 } else if (pnn == CTDB_UNKNOWN_PNN) {
271 fprintf(fp, "UNKNOWN");
272 } else {
273 fprintf(fp, "%u", pnn);
277 static void ctdb_srvid_print(uint64_t srvid, FILE *fp)
279 uint64_t prefix = 0xFFFF000000000000LL;
281 if (srvid == CTDB_SRVID_ALL) {
282 fprintf(fp, "ALL");
283 } else if ((srvid & prefix) == CTDB_SRVID_RECOVERY) {
284 srvid = srvid & ~CTDB_SRVID_RECOVERY;
285 fprintf(fp, "RECOVERY-%"PRIx64"", srvid);
286 } else if (srvid == CTDB_SRVID_BANNING) {
287 fprintf(fp, "BANNING");
288 } else if (srvid == CTDB_SRVID_ELECTION) {
289 fprintf(fp, "ELECTION");
290 } else if (srvid == CTDB_SRVID_RECONFIGURE) {
291 fprintf(fp, "RECONFIGURE");
292 } else if (srvid == CTDB_SRVID_RELEASE_IP) {
293 fprintf(fp, "RELEASE_IP");
294 } else if (srvid == CTDB_SRVID_TAKE_IP) {
295 fprintf(fp, "TAKE_IP");
296 } else if (srvid == CTDB_SRVID_SET_NODE_FLAGS) {
297 fprintf(fp, "SET_NODE_FLAGS");
298 } else if (srvid == CTDB_SRVID_RECD_UPDATE_IP) {
299 fprintf(fp, "RECD_UPDATE_IP");
300 } else if (srvid == CTDB_SRVID_VACUUM_FETCH) {
301 fprintf(fp, "VACUUM_FETCH");
302 } else if (srvid == CTDB_SRVID_DETACH_DATABASE) {
303 fprintf(fp, "DETACH_DATABASE");
304 } else if (srvid == CTDB_SRVID_MEM_DUMP) {
305 fprintf(fp, "MEM_DUMP");
306 } else if (srvid == CTDB_SRVID_GETLOG) {
307 fprintf(fp, "GETLOG");
308 } else if (srvid == CTDB_SRVID_CLEARLOG) {
309 fprintf(fp, "CLEARLOG");
310 } else if (srvid == CTDB_SRVID_PUSH_NODE_FLAGS) {
311 fprintf(fp, "PUSH_NODE_FLAGS");
312 } else if (srvid == CTDB_SRVID_RELOAD_NODES) {
313 fprintf(fp, "RELOAD_NODES");
314 } else if (srvid == CTDB_SRVID_TAKEOVER_RUN) {
315 fprintf(fp, "TAKEOVER_RUN");
316 } else if (srvid == CTDB_SRVID_REBALANCE_NODE) {
317 fprintf(fp, "REBALANCE_NODE");
318 } else if (srvid == CTDB_SRVID_DISABLE_TAKEOVER_RUNS) {
319 fprintf(fp, "DISABLE_TAKEOVER_RUNS");
320 } else if (srvid == CTDB_SRVID_DISABLE_RECOVERIES) {
321 fprintf(fp, "DISABLE_RECOVERIES");
322 } else if (srvid == CTDB_SRVID_DISABLE_IP_CHECK) {
323 fprintf(fp, "DISABLE_IP_CHECK");
324 } else if ((srvid & prefix) == CTDB_SRVID_SAMBA_RANGE) {
325 if (srvid == CTDB_SRVID_SAMBA_NOTIFY) {
326 fprintf(fp, "SAMBA_NOTIFY");
327 } else {
328 srvid &= ~CTDB_SRVID_SAMBA_RANGE;
329 fprintf(fp, "samba-0x%"PRIx64"", srvid);
331 } else if ((srvid & prefix) == CTDB_SRVID_NFSD_RANGE) {
332 srvid &= ~CTDB_SRVID_NFSD_RANGE;
333 fprintf(fp, "nfsd-0x%"PRIx64"", srvid);
334 } else if ((srvid & prefix) == CTDB_SRVID_ISCSID_RANGE) {
335 srvid &= ~CTDB_SRVID_ISCSID_RANGE;
336 fprintf(fp, "iscsi-0x%"PRIx64"", srvid);
337 } else if ((srvid & prefix) == CTDB_SRVID_TOOL_RANGE) {
338 srvid &= ~CTDB_SRVID_TOOL_RANGE;
339 fprintf(fp, "tool-0x%"PRIx64"", srvid);
340 } else if ((srvid & prefix) == CTDB_SRVID_TEST_RANGE) {
341 srvid &= ~CTDB_SRVID_TEST_RANGE;
342 fprintf(fp, "test-0x%"PRIx64"", srvid);
343 } else if ((srvid & prefix) == CTDB_SRVID_PID_RANGE) {
344 if (srvid < UINT16_MAX) {
345 fprintf(fp, "pid-%"PRIu64, srvid);
346 } else {
347 fprintf(fp, "pid-0x%"PRIx64, srvid);
349 } else {
350 fprintf(fp, "0x%"PRIx64, srvid);
355 * Print routines
358 static void ctdb_req_header_print(struct ctdb_req_header *h, FILE *fp)
360 fprintf(fp, "Header\n");
361 fprintf(fp, " length:%u magic:0x%"PRIx32" version:%u generation:0x%"PRIx32"\n",
362 h->length, h->ctdb_magic, h->ctdb_version, h->generation);
363 fprintf(fp, " ");
364 ctdb_operation_print(h->operation, fp);
365 fprintf(fp, " dst:");
366 ctdb_pnn_print(h->destnode, fp);
367 fprintf(fp, " src:");
368 ctdb_pnn_print(h->srcnode, fp);
369 fprintf(fp, " reqid:0x%"PRIx32"\n", h->reqid);
372 static void ctdb_req_call_print(struct ctdb_req_call *c, FILE *fp)
374 fprintf(fp, "Data\n");
375 fprintf(fp, " db:0x%"PRIx32" ", c->db_id);
376 ctdb_callid_print(c->callid, fp);
377 fprintf(fp, "\n");
378 fprintf(fp, " key:");
379 tdb_data_print(c->key, fp);
380 fprintf(fp, "\n");
383 static void ctdb_reply_call_print(struct ctdb_reply_call *c, FILE *fp)
385 fprintf(fp, "Data\n");
386 fprintf(fp, " status:%d\n", c->status);
387 if (c->status == 0) {
388 fprintf(fp, " data:");
389 tdb_data_print(c->data, fp);
390 fprintf(fp, "\n");
394 static void ctdb_req_dmaster_print(struct ctdb_req_dmaster *c, FILE *fp)
396 fprintf(fp, "Data\n");
397 fprintf(fp, " db:0x%"PRIx32" rsn:0x%"PRIx64" dmaster:%u\n",
398 c->db_id, c->rsn, c->dmaster);
399 fprintf(fp, " key:");
400 tdb_data_print(c->key, fp);
401 fprintf(fp, "\n");
402 fprintf(fp, " data:");
403 tdb_data_print(c->data, fp);
404 fprintf(fp, "\n");
407 static void ctdb_reply_dmaster_print(struct ctdb_reply_dmaster *c, FILE *fp)
409 fprintf(fp, "Data\n");
410 fprintf(fp, " db:0x%"PRIx32" rsn:0x%"PRIx64"\n", c->db_id, c->rsn);
411 fprintf(fp, " key:");
412 tdb_data_print(c->key, fp);
413 fprintf(fp, "\n");
414 fprintf(fp, " data:");
415 tdb_data_print(c->data, fp);
416 fprintf(fp, "\n");
419 static void ctdb_reply_error_print(struct ctdb_reply_error *c, FILE *fp)
421 fprintf(fp, "Data\n");
422 fprintf(fp, " status:%d\n", c->status);
423 if (c->status != 0) {
424 fprintf(fp, " msg:");
425 tdb_data_print(c->msg, fp);
426 fprintf(fp, "\n");
430 static void ctdb_req_message_data_print(struct ctdb_req_message_data *c,
431 FILE *fp)
433 fprintf(fp, "Data\n");
434 fprintf(fp, " srvid:");
435 ctdb_srvid_print(c->srvid, fp);
436 fprintf(fp, "\n");
437 fprintf(fp, " data:");
438 tdb_data_print(c->data, fp);
439 fprintf(fp, "\n");
442 static void ctdb_req_control_print(struct ctdb_req_control *c, FILE *fp)
444 fprintf(fp, "Data\n");
445 fprintf(fp, " ");
446 ctdb_opcode_print(c->opcode, fp);
447 fprintf(fp, " srvid:");
448 ctdb_srvid_print(c->srvid, fp);
449 fprintf(fp, " client_id:0x%"PRIx32" ", c->client_id);
450 ctdb_control_flags_print(c->flags, fp);
451 fprintf(fp, "\n");
454 static void ctdb_reply_control_print(struct ctdb_reply_control *c, FILE *fp)
456 fprintf(fp, "Data\n");
457 fprintf(fp, " status:%d ", c->status);
458 if (c->errmsg != NULL) {
459 fprintf(fp, "errmsg: %s", c->errmsg);
461 fprintf(fp, "\n");
465 * Parse routines
468 static void ctdb_req_call_parse(uint8_t *buf, size_t buflen, FILE *fp,
469 TALLOC_CTX *mem_ctx)
471 struct ctdb_req_call c;
472 int ret;
474 ret = ctdb_req_call_pull(buf, buflen, NULL, mem_ctx, &c);
475 if (ret != 0) {
476 fprintf(fp, "Failed to parse CTDB_REQ_CALL\n");
477 return;
480 ctdb_req_call_print(&c, fp);
483 static void ctdb_reply_call_parse(uint8_t *buf, size_t buflen, FILE *fp,
484 TALLOC_CTX *mem_ctx)
486 struct ctdb_reply_call c;
487 int ret;
489 ret = ctdb_reply_call_pull(buf, buflen, NULL, mem_ctx, &c);
490 if (ret != 0) {
491 fprintf(fp, "Failed to parse CTDB_REPLY_CALL\n");
492 return;
495 ctdb_reply_call_print(&c, fp);
498 static void ctdb_req_dmaster_parse(uint8_t *buf, size_t buflen, FILE *fp,
499 TALLOC_CTX *mem_ctx)
501 struct ctdb_req_dmaster c;
502 int ret;
504 ret = ctdb_req_dmaster_pull(buf, buflen, NULL, mem_ctx, &c);
505 if (ret != 0) {
506 fprintf(fp, "Failed to parse CTDB_REQ_DMASTER\n");
507 return;
510 ctdb_req_dmaster_print(&c, fp);
513 static void ctdb_reply_dmaster_parse(uint8_t *buf, size_t buflen, FILE *fp,
514 TALLOC_CTX *mem_ctx)
516 struct ctdb_reply_dmaster c;
517 int ret;
519 ret = ctdb_reply_dmaster_pull(buf, buflen, NULL, mem_ctx, &c);
520 if (ret != 0) {
521 fprintf(fp, "Failed to parse CTDB_REPLY_DMASTER\n");
522 return;
525 ctdb_reply_dmaster_print(&c, fp);
528 static void ctdb_reply_error_parse(uint8_t *buf, size_t buflen, FILE *fp,
529 TALLOC_CTX *mem_ctx)
531 struct ctdb_reply_error c;
532 int ret;
534 ret = ctdb_reply_error_pull(buf, buflen, NULL, mem_ctx, &c);
535 if (ret != 0) {
536 fprintf(fp, "Failed to parse CTDB_REPLY_ERROR\n");
537 return;
540 ctdb_reply_error_print(&c, fp);
543 static void ctdb_req_message_parse(uint8_t *buf, size_t buflen, FILE *fp,
544 TALLOC_CTX *mem_ctx)
546 struct ctdb_req_message_data c;
547 int ret;
549 ret = ctdb_req_message_data_pull(buf, buflen, NULL, mem_ctx, &c);
550 if (ret != 0) {
551 fprintf(fp, "Failed to parse CTDB_REQ_MESSAGE\n");
552 return;
555 ctdb_req_message_data_print(&c, fp);
558 static void ctdb_req_control_parse(uint8_t *buf, size_t buflen, FILE *fp,
559 TALLOC_CTX *mem_ctx)
561 struct ctdb_req_control c;
562 int ret;
564 ret = ctdb_req_control_pull(buf, buflen, NULL, mem_ctx, &c);
565 if (ret != 0) {
566 fprintf(fp, "Failed to parse CTDB_REQ_CONTROL\n");
567 return;
570 ctdb_req_control_print(&c, fp);
573 static void ctdb_reply_control_parse(uint8_t *buf, size_t buflen, FILE *fp,
574 TALLOC_CTX *mem_ctx)
576 struct ctdb_reply_control c;
577 int ret;
579 ret = ctdb_reply_control_pull(buf, buflen, -1, NULL, mem_ctx, &c);
580 if (ret != 0) {
581 fprintf(fp, "Failed to parse CTDB_REPLY_CONTROL\n");
582 return;
585 ctdb_reply_control_print(&c, fp);
589 * Packet print
592 void ctdb_packet_print(uint8_t *buf, size_t buflen, FILE *fp)
594 TALLOC_CTX *mem_ctx = talloc_new(NULL);
595 struct ctdb_req_header h;
596 int ret;
598 fprintf(fp, "Buffer len:%zu\n", buflen);
600 ret = ctdb_req_header_pull(buf, buflen, &h);
601 if (ret != 0) {
602 fprintf(fp, "Failed to parse ctdb packet header\n");
603 return;
606 ctdb_req_header_print(&h, fp);
608 if (h.length > buflen) {
609 fprintf(fp, "Packet length mismatch\n");
612 ret = ctdb_req_header_verify(&h, 0);
613 if (ret != 0) {
614 fprintf(fp, "Invalid ctdb packet header\n");
615 return;
618 switch (h.operation) {
619 case CTDB_REQ_CALL:
620 ctdb_req_call_parse(buf, buflen, fp, mem_ctx);
621 break;
623 case CTDB_REPLY_CALL:
624 ctdb_reply_call_parse(buf, buflen, fp, mem_ctx);
625 break;
627 case CTDB_REQ_DMASTER:
628 ctdb_req_dmaster_parse(buf, buflen, fp, mem_ctx);
629 break;
631 case CTDB_REPLY_DMASTER:
632 ctdb_reply_dmaster_parse(buf, buflen, fp, mem_ctx);
633 break;
635 case CTDB_REPLY_ERROR:
636 ctdb_reply_error_parse(buf, buflen, fp, mem_ctx);
637 break;
639 case CTDB_REQ_MESSAGE:
640 ctdb_req_message_parse(buf, buflen, fp, mem_ctx);
641 break;
643 case CTDB_REQ_CONTROL:
644 ctdb_req_control_parse(buf, buflen, fp, mem_ctx);
645 break;
647 case CTDB_REPLY_CONTROL:
648 ctdb_reply_control_parse(buf, buflen, fp, mem_ctx);
649 break;
651 case CTDB_REQ_KEEPALIVE:
652 break;
654 default:
655 fprintf(fp, "Invalid ctdb operation\n");
656 break;
659 talloc_free(mem_ctx);