ctdb-protocol: Fix marshalling for ctdb_iface_list
[vlendec/samba-autobuild/.git] / ctdb / protocol / protocol_control.c
1 /*
2    CTDB protocol marshalling
3
4    Copyright (C) Amitay Isaacs  2015
5
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.
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
14    GNU General Public License for more details.
15
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/>.
18 */
19
20 #include "replace.h"
21 #include "system/network.h"
22
23 #include <talloc.h>
24 #include <tdb.h>
25
26 #include "protocol.h"
27 #include "protocol_api.h"
28 #include "protocol_private.h"
29
30 struct ctdb_req_control_wire {
31         struct ctdb_req_header hdr;
32         uint32_t opcode;
33         uint32_t pad;
34         uint64_t srvid;
35         uint32_t client_id;
36         uint32_t flags;
37         uint32_t datalen;
38         uint8_t data[1];
39 };
40
41 struct ctdb_reply_control_wire {
42         struct ctdb_req_header hdr;
43         int32_t status;
44         uint32_t datalen;
45         uint32_t errorlen;
46         uint8_t data[1];
47 };
48
49 static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
50 {
51         size_t len = 0;
52         uint32_t u32;
53
54         if (cd == NULL) {
55                 return 0;
56         }
57
58         switch (cd->opcode) {
59         case CTDB_CONTROL_PROCESS_EXISTS:
60                 len = ctdb_pid_len(&cd->data.pid);
61                 break;
62
63         case CTDB_CONTROL_STATISTICS:
64                 break;
65
66         case CTDB_CONTROL_PING:
67                 break;
68
69         case CTDB_CONTROL_GETDBPATH:
70                 len = ctdb_uint32_len(&cd->data.db_id);
71                 break;
72
73         case CTDB_CONTROL_GETVNNMAP:
74                 break;
75
76         case CTDB_CONTROL_SETVNNMAP:
77                 len = ctdb_vnn_map_len(cd->data.vnnmap);
78                 break;
79
80         case CTDB_CONTROL_GET_DEBUG:
81                 break;
82
83         case CTDB_CONTROL_SET_DEBUG:
84                 len = ctdb_uint32_len(&cd->data.loglevel);
85                 break;
86
87         case CTDB_CONTROL_GET_DBMAP:
88                 break;
89
90         case CTDB_CONTROL_PULL_DB:
91                 len = ctdb_pulldb_len(cd->data.pulldb);
92                 break;
93
94         case CTDB_CONTROL_PUSH_DB:
95                 len = ctdb_rec_buffer_len(cd->data.recbuf);
96                 break;
97
98         case CTDB_CONTROL_GET_RECMODE:
99                 break;
100
101         case CTDB_CONTROL_SET_RECMODE:
102                 len = ctdb_uint32_len(&cd->data.recmode);
103                 break;
104
105         case CTDB_CONTROL_STATISTICS_RESET:
106                 break;
107
108         case CTDB_CONTROL_DB_ATTACH:
109                 len = ctdb_string_len(&cd->data.db_name);
110                 break;
111
112         case CTDB_CONTROL_SET_CALL:
113                 break;
114
115         case CTDB_CONTROL_TRAVERSE_START:
116                 len = ctdb_traverse_start_len(cd->data.traverse_start);
117                 break;
118
119         case CTDB_CONTROL_TRAVERSE_ALL:
120                 len = ctdb_traverse_all_len(cd->data.traverse_all);
121                 break;
122
123         case CTDB_CONTROL_TRAVERSE_DATA:
124                 len = ctdb_rec_data_len(cd->data.rec_data);
125                 break;
126
127         case CTDB_CONTROL_REGISTER_SRVID:
128                 break;
129
130         case CTDB_CONTROL_DEREGISTER_SRVID:
131                 break;
132
133         case CTDB_CONTROL_GET_DBNAME:
134                 len = ctdb_uint32_len(&cd->data.db_id);
135                 break;
136
137         case CTDB_CONTROL_ENABLE_SEQNUM:
138                 len = ctdb_uint32_len(&cd->data.db_id);
139                 break;
140
141         case CTDB_CONTROL_UPDATE_SEQNUM:
142                 len = ctdb_uint32_len(&cd->data.db_id);
143                 break;
144
145         case CTDB_CONTROL_DUMP_MEMORY:
146                 break;
147
148         case CTDB_CONTROL_GET_PID:
149                 break;
150
151         case CTDB_CONTROL_GET_RECMASTER:
152                 break;
153
154         case CTDB_CONTROL_SET_RECMASTER:
155                 len = ctdb_uint32_len(&cd->data.recmaster);
156                 break;
157
158         case CTDB_CONTROL_FREEZE:
159                 break;
160
161         case CTDB_CONTROL_GET_PNN:
162                 break;
163
164         case CTDB_CONTROL_SHUTDOWN:
165                 break;
166
167         case CTDB_CONTROL_GET_MONMODE:
168                 break;
169
170         case CTDB_CONTROL_TCP_CLIENT:
171                 len = ctdb_connection_len(cd->data.conn);
172                 break;
173
174         case CTDB_CONTROL_TCP_ADD:
175                 len = ctdb_connection_len(cd->data.conn);
176                 break;
177
178         case CTDB_CONTROL_TCP_REMOVE:
179                 len = ctdb_connection_len(cd->data.conn);
180                 break;
181
182         case CTDB_CONTROL_STARTUP:
183                 break;
184
185         case CTDB_CONTROL_SET_TUNABLE:
186                 len = ctdb_tunable_len(cd->data.tunable);
187                 break;
188
189         case CTDB_CONTROL_GET_TUNABLE:
190                 len = ctdb_stringn_len(&cd->data.tun_var);
191                 break;
192
193         case CTDB_CONTROL_LIST_TUNABLES:
194                 break;
195
196         case CTDB_CONTROL_MODIFY_FLAGS:
197                 len = ctdb_node_flag_change_len(cd->data.flag_change);
198                 break;
199
200         case CTDB_CONTROL_GET_ALL_TUNABLES:
201                 break;
202
203         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
204                 len = ctdb_sock_addr_len(cd->data.addr);
205                 break;
206
207         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
208                 len = ctdb_tickle_list_len(cd->data.tickles);
209                 break;
210
211         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
212                 len = ctdb_string_len(&cd->data.db_name);
213                 break;
214
215         case CTDB_CONTROL_UPDATE_RECORD:
216                 len = ctdb_rec_buffer_len(cd->data.recbuf);
217                 break;
218
219         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
220                 len = ctdb_addr_info_len(cd->data.addr_info);
221                 break;
222
223         case CTDB_CONTROL_WIPE_DATABASE:
224                 len = ctdb_transdb_len(cd->data.transdb);
225                 break;
226
227         case CTDB_CONTROL_UPTIME:
228                 break;
229
230         case CTDB_CONTROL_START_RECOVERY:
231                 break;
232
233         case CTDB_CONTROL_END_RECOVERY:
234                 break;
235
236         case CTDB_CONTROL_RELOAD_NODES_FILE:
237                 break;
238
239         case CTDB_CONTROL_TRY_DELETE_RECORDS:
240                 len = ctdb_rec_buffer_len(cd->data.recbuf);
241                 break;
242
243         case CTDB_CONTROL_ENABLE_MONITOR:
244                 break;
245
246         case CTDB_CONTROL_DISABLE_MONITOR:
247                 break;
248
249         case CTDB_CONTROL_ADD_PUBLIC_IP:
250                 len = ctdb_addr_info_len(cd->data.addr_info);
251                 break;
252
253         case CTDB_CONTROL_DEL_PUBLIC_IP:
254                 len = ctdb_addr_info_len(cd->data.addr_info);
255                 break;
256
257         case CTDB_CONTROL_GET_CAPABILITIES:
258                 break;
259
260         case CTDB_CONTROL_RECD_PING:
261                 break;
262
263         case CTDB_CONTROL_RELEASE_IP:
264                 len = ctdb_public_ip_len(cd->data.pubip);
265                 break;
266
267         case CTDB_CONTROL_TAKEOVER_IP:
268                 len = ctdb_public_ip_len(cd->data.pubip);
269                 break;
270
271         case CTDB_CONTROL_GET_PUBLIC_IPS:
272                 break;
273
274         case CTDB_CONTROL_GET_NODEMAP:
275                 break;
276
277         case CTDB_CONTROL_TRAVERSE_KILL:
278                 len = ctdb_traverse_start_len(cd->data.traverse_start);
279                 break;
280
281         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
282                 len = ctdb_double_len(&cd->data.reclock_latency);
283                 break;
284
285         case CTDB_CONTROL_GET_RECLOCK_FILE:
286                 break;
287
288         case CTDB_CONTROL_STOP_NODE:
289                 break;
290
291         case CTDB_CONTROL_CONTINUE_NODE:
292                 break;
293
294         case CTDB_CONTROL_SET_LMASTERROLE:
295                 len = ctdb_uint32_len(&cd->data.role);
296                 break;
297
298         case CTDB_CONTROL_SET_RECMASTERROLE:
299                 len = ctdb_uint32_len(&cd->data.role);
300                 break;
301
302         case CTDB_CONTROL_SET_BAN_STATE:
303                 len = ctdb_ban_state_len(cd->data.ban_state);
304                 break;
305
306         case CTDB_CONTROL_GET_BAN_STATE:
307                 break;
308
309         case CTDB_CONTROL_REGISTER_NOTIFY:
310                 len = ctdb_notify_data_len(cd->data.notify);
311                 break;
312
313         case CTDB_CONTROL_DEREGISTER_NOTIFY:
314                 len = ctdb_uint64_len(&cd->data.srvid);
315                 break;
316
317         case CTDB_CONTROL_TRANS3_COMMIT:
318                 len = ctdb_rec_buffer_len(cd->data.recbuf);
319                 break;
320
321         case CTDB_CONTROL_GET_DB_SEQNUM:
322                 u32 = 0;
323                 len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
324                 break;
325
326         case CTDB_CONTROL_DB_SET_HEALTHY:
327                 len = ctdb_uint32_len(&cd->data.db_id);
328                 break;
329
330         case CTDB_CONTROL_DB_GET_HEALTH:
331                 len = ctdb_uint32_len(&cd->data.db_id);
332                 break;
333
334         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
335                 len = ctdb_sock_addr_len(cd->data.addr);
336                 break;
337
338         case CTDB_CONTROL_GET_IFACES:
339                 break;
340
341         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
342                 len = ctdb_iface_len(cd->data.iface);
343                 break;
344
345         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
346                 len = ctdb_connection_len(cd->data.conn);
347                 break;
348
349         case CTDB_CONTROL_GET_STAT_HISTORY:
350                 break;
351
352         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
353                 len = ctdb_key_data_len(cd->data.key);
354                 break;
355
356         case CTDB_CONTROL_SET_DB_READONLY:
357                 len = ctdb_uint32_len(&cd->data.db_id);
358                 break;
359
360         case CTDB_CONTROL_CHECK_SRVIDS:
361                 break;
362
363         case CTDB_CONTROL_TRAVERSE_START_EXT:
364                 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
365                 break;
366
367         case CTDB_CONTROL_GET_DB_STATISTICS:
368                 len = ctdb_uint32_len(&cd->data.db_id);
369                 break;
370
371         case CTDB_CONTROL_SET_DB_STICKY:
372                 len = ctdb_uint32_len(&cd->data.db_id);
373                 break;
374
375         case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
376                 break;
377
378         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
379                 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
380                 break;
381
382         case CTDB_CONTROL_RECEIVE_RECORDS:
383                 len = ctdb_rec_buffer_len(cd->data.recbuf);
384                 break;
385
386         case CTDB_CONTROL_IPREALLOCATED:
387                 break;
388
389         case CTDB_CONTROL_GET_RUNSTATE:
390                 break;
391
392         case CTDB_CONTROL_DB_DETACH:
393                 len = ctdb_uint32_len(&cd->data.db_id);
394                 break;
395
396         case CTDB_CONTROL_GET_NODES_FILE:
397                 break;
398
399         case CTDB_CONTROL_DB_FREEZE:
400                 len = ctdb_uint32_len(&cd->data.db_id);
401                 break;
402
403         case CTDB_CONTROL_DB_THAW:
404                 len = ctdb_uint32_len(&cd->data.db_id);
405                 break;
406
407         case CTDB_CONTROL_DB_TRANSACTION_START:
408                 len = ctdb_transdb_len(cd->data.transdb);
409                 break;
410
411         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
412                 len = ctdb_transdb_len(cd->data.transdb);
413                 break;
414
415         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
416                 len = ctdb_uint32_len(&cd->data.db_id);
417                 break;
418
419         case CTDB_CONTROL_DB_PULL:
420                 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
421                 break;
422
423         case CTDB_CONTROL_DB_PUSH_START:
424                 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
425                 break;
426
427         case CTDB_CONTROL_DB_PUSH_CONFIRM:
428                 len = ctdb_uint32_len(&cd->data.db_id);
429                 break;
430
431         case CTDB_CONTROL_DB_OPEN_FLAGS:
432                 len = ctdb_uint32_len(&cd->data.db_id);
433                 break;
434
435         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
436                 len = ctdb_string_len(&cd->data.db_name);
437                 break;
438         }
439
440         return len;
441 }
442
443 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
444                                        uint8_t *buf)
445 {
446         size_t np, offset;
447         uint32_t u32;
448
449         switch (cd->opcode) {
450         case CTDB_CONTROL_PROCESS_EXISTS:
451                 ctdb_pid_push(&cd->data.pid, buf, &np);
452                 break;
453
454         case CTDB_CONTROL_GETDBPATH:
455                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
456                 break;
457
458         case CTDB_CONTROL_SETVNNMAP:
459                 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
460                 break;
461
462         case CTDB_CONTROL_SET_DEBUG:
463                 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
464                 break;
465
466         case CTDB_CONTROL_PULL_DB:
467                 ctdb_pulldb_push(cd->data.pulldb, buf, &np);
468                 break;
469
470         case CTDB_CONTROL_PUSH_DB:
471                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
472                 break;
473
474         case CTDB_CONTROL_SET_RECMODE:
475                 ctdb_uint32_push(&cd->data.recmode, buf, &np);
476                 break;
477
478         case CTDB_CONTROL_DB_ATTACH:
479                 ctdb_string_push(&cd->data.db_name, buf, &np);
480                 break;
481
482         case CTDB_CONTROL_SET_CALL:
483                 break;
484
485         case CTDB_CONTROL_TRAVERSE_START:
486                 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
487                 break;
488
489         case CTDB_CONTROL_TRAVERSE_ALL:
490                 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
491                 break;
492
493         case CTDB_CONTROL_TRAVERSE_DATA:
494                 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
495                 break;
496
497         case CTDB_CONTROL_GET_DBNAME:
498                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
499                 break;
500
501         case CTDB_CONTROL_ENABLE_SEQNUM:
502                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
503                 break;
504
505         case CTDB_CONTROL_UPDATE_SEQNUM:
506                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
507                 break;
508
509         case CTDB_CONTROL_SET_RECMASTER:
510                 ctdb_uint32_push(&cd->data.recmaster, buf, &np);
511                 break;
512
513         case CTDB_CONTROL_TCP_CLIENT:
514                 ctdb_connection_push(cd->data.conn, buf, &np);
515                 break;
516
517         case CTDB_CONTROL_TCP_ADD:
518                 ctdb_connection_push(cd->data.conn, buf, &np);
519                 break;
520
521         case CTDB_CONTROL_TCP_REMOVE:
522                 ctdb_connection_push(cd->data.conn, buf, &np);
523                 break;
524
525         case CTDB_CONTROL_SET_TUNABLE:
526                 ctdb_tunable_push(cd->data.tunable, buf, &np);
527                 break;
528
529         case CTDB_CONTROL_GET_TUNABLE:
530                 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
531                 break;
532
533         case CTDB_CONTROL_MODIFY_FLAGS:
534                 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
535                 break;
536
537         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
538                 ctdb_sock_addr_push(cd->data.addr, buf, &np);
539                 break;
540
541         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
542                 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
543                 break;
544
545         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
546                 ctdb_string_push(&cd->data.db_name, buf, &np);
547                 break;
548
549         case CTDB_CONTROL_UPDATE_RECORD:
550                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
551                 break;
552
553         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
554                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
555                 break;
556
557         case CTDB_CONTROL_WIPE_DATABASE:
558                 ctdb_transdb_push(cd->data.transdb, buf, &np);
559                 break;
560
561         case CTDB_CONTROL_TRY_DELETE_RECORDS:
562                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
563                 break;
564
565         case CTDB_CONTROL_ADD_PUBLIC_IP:
566                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
567                 break;
568
569         case CTDB_CONTROL_DEL_PUBLIC_IP:
570                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
571                 break;
572
573         case CTDB_CONTROL_RELEASE_IP:
574                 ctdb_public_ip_push(cd->data.pubip, buf, &np);
575                 break;
576
577         case CTDB_CONTROL_TAKEOVER_IP:
578                 ctdb_public_ip_push(cd->data.pubip, buf, &np);
579                 break;
580
581         case CTDB_CONTROL_TRAVERSE_KILL:
582                 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
583                 break;
584
585         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
586                 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
587                 break;
588
589         case CTDB_CONTROL_SET_LMASTERROLE:
590                 ctdb_uint32_push(&cd->data.role, buf, &np);
591                 break;
592
593         case CTDB_CONTROL_SET_RECMASTERROLE:
594                 ctdb_uint32_push(&cd->data.role, buf, &np);
595                 break;
596
597         case CTDB_CONTROL_SET_BAN_STATE:
598                 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
599                 break;
600
601         case CTDB_CONTROL_REGISTER_NOTIFY:
602                 ctdb_notify_data_push(cd->data.notify, buf, &np);
603                 break;
604
605         case CTDB_CONTROL_DEREGISTER_NOTIFY:
606                 ctdb_uint64_push(&cd->data.srvid, buf, &np);
607                 break;
608
609         case CTDB_CONTROL_TRANS3_COMMIT:
610                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
611                 break;
612
613         case CTDB_CONTROL_GET_DB_SEQNUM:
614                 u32 = 0;
615                 offset = 0;
616                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
617                 offset += np;
618                 ctdb_uint32_push(&u32, buf+offset, &np);
619                 offset += np;
620                 np = offset;
621                 break;
622
623         case CTDB_CONTROL_DB_SET_HEALTHY:
624                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
625                 break;
626
627         case CTDB_CONTROL_DB_GET_HEALTH:
628                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
629                 break;
630
631         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
632                 ctdb_sock_addr_push(cd->data.addr, buf, &np);
633                 break;
634
635         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
636                 ctdb_iface_push(cd->data.iface, buf, &np);
637                 break;
638
639         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
640                 ctdb_connection_push(cd->data.conn, buf, &np);
641                 break;
642
643         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
644                 ctdb_key_data_push(cd->data.key, buf);
645                 break;
646
647         case CTDB_CONTROL_SET_DB_READONLY:
648                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
649                 break;
650
651         case CTDB_CONTROL_CHECK_SRVIDS:
652                 break;
653
654         case CTDB_CONTROL_TRAVERSE_START_EXT:
655                 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
656                                              &np);
657                 break;
658
659         case CTDB_CONTROL_GET_DB_STATISTICS:
660                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
661                 break;
662
663         case CTDB_CONTROL_SET_DB_STICKY:
664                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
665                 break;
666
667         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
668                 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
669                                            &np);
670                 break;
671
672         case CTDB_CONTROL_RECEIVE_RECORDS:
673                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
674                 break;
675
676         case CTDB_CONTROL_DB_DETACH:
677                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
678                 break;
679
680         case CTDB_CONTROL_DB_FREEZE:
681                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
682                 break;
683
684         case CTDB_CONTROL_DB_THAW:
685                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
686                 break;
687
688         case CTDB_CONTROL_DB_TRANSACTION_START:
689                 ctdb_transdb_push(cd->data.transdb, buf, &np);
690                 break;
691
692         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
693                 ctdb_transdb_push(cd->data.transdb, buf, &np);
694                 break;
695
696         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
697                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
698                 break;
699
700         case CTDB_CONTROL_DB_PULL:
701                 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
702                 break;
703
704         case CTDB_CONTROL_DB_PUSH_START:
705                 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
706                 break;
707
708         case CTDB_CONTROL_DB_PUSH_CONFIRM:
709                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
710                 break;
711
712         case CTDB_CONTROL_DB_OPEN_FLAGS:
713                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
714                 break;
715
716         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
717                 ctdb_string_push(&cd->data.db_name, buf, &np);
718                 break;
719         }
720 }
721
722 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
723                                       uint32_t opcode,
724                                       TALLOC_CTX *mem_ctx,
725                                       struct ctdb_req_control_data *cd)
726 {
727         size_t np, offset;
728         uint32_t u32;
729         int ret = 0;
730
731         cd->opcode = opcode;
732
733         switch (opcode) {
734         case CTDB_CONTROL_PROCESS_EXISTS:
735                 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
736                 break;
737
738         case CTDB_CONTROL_GETDBPATH:
739                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
740                 break;
741
742         case CTDB_CONTROL_SETVNNMAP:
743                 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
744                                         &cd->data.vnnmap, &np);
745                 break;
746
747         case CTDB_CONTROL_SET_DEBUG:
748                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
749                 break;
750
751         case CTDB_CONTROL_PULL_DB:
752                 ret = ctdb_pulldb_pull(buf, buflen, mem_ctx,
753                                        &cd->data.pulldb, &np);
754                 break;
755
756         case CTDB_CONTROL_PUSH_DB:
757                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
758                                            &cd->data.recbuf, &np);
759                 break;
760
761         case CTDB_CONTROL_SET_RECMODE:
762                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
763                 break;
764
765         case CTDB_CONTROL_DB_ATTACH:
766                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
767                                        &cd->data.db_name, &np);
768                 break;
769
770         case CTDB_CONTROL_SET_CALL:
771                 break;
772
773         case CTDB_CONTROL_TRAVERSE_START:
774                 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
775                                                &cd->data.traverse_start, &np);
776                 break;
777
778         case CTDB_CONTROL_TRAVERSE_ALL:
779                 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
780                                              &cd->data.traverse_all, &np);
781                 break;
782
783         case CTDB_CONTROL_TRAVERSE_DATA:
784                 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
785                                          &cd->data.rec_data, &np);
786                 break;
787
788         case CTDB_CONTROL_GET_DBNAME:
789                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
790                 break;
791
792         case CTDB_CONTROL_ENABLE_SEQNUM:
793                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
794                 break;
795
796         case CTDB_CONTROL_UPDATE_SEQNUM:
797                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
798                 break;
799
800         case CTDB_CONTROL_SET_RECMASTER:
801                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmaster, &np);
802                 break;
803
804         case CTDB_CONTROL_TCP_CLIENT:
805                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
806                                            &cd->data.conn, &np);
807                 break;
808
809         case CTDB_CONTROL_TCP_ADD:
810                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
811                                            &cd->data.conn, &np);
812                 break;
813
814         case CTDB_CONTROL_TCP_REMOVE:
815                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
816                                            &cd->data.conn, &np);
817                 break;
818
819         case CTDB_CONTROL_SET_TUNABLE:
820                 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
821                                         &cd->data.tunable, &np);
822                 break;
823
824         case CTDB_CONTROL_GET_TUNABLE:
825                 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
826                                         &cd->data.tun_var, &np);
827                 break;
828
829         case CTDB_CONTROL_MODIFY_FLAGS:
830                 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
831                                                  &cd->data.flag_change, &np);
832                 break;
833
834         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
835                 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
836                                           &cd->data.addr, &np);
837                 break;
838
839         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
840                 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
841                                             &cd->data.tickles, &np);
842                 break;
843
844         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
845                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
846                                        &cd->data.db_name, &np);
847                 break;
848
849         case CTDB_CONTROL_UPDATE_RECORD:
850                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
851                                            &cd->data.recbuf, &np);
852                 break;
853
854         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
855                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
856                                           &cd->data.addr_info, &np);
857                 break;
858
859         case CTDB_CONTROL_WIPE_DATABASE:
860                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
861                                        &cd->data.transdb, &np);
862                 break;
863
864         case CTDB_CONTROL_TRY_DELETE_RECORDS:
865                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
866                                            &cd->data.recbuf, &np);
867                 break;
868
869         case CTDB_CONTROL_ADD_PUBLIC_IP:
870                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
871                                           &cd->data.addr_info, &np);
872                 break;
873
874         case CTDB_CONTROL_DEL_PUBLIC_IP:
875                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
876                                           &cd->data.addr_info, &np);
877                 break;
878
879         case CTDB_CONTROL_RELEASE_IP:
880                 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
881                                           &cd->data.pubip, &np);
882                 break;
883
884         case CTDB_CONTROL_TAKEOVER_IP:
885                 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
886                                           &cd->data.pubip, &np);
887                 break;
888
889         case CTDB_CONTROL_TRAVERSE_KILL:
890                 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
891                                                &cd->data.traverse_start, &np);
892                 break;
893
894         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
895                 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
896                                        &np);
897                 break;
898
899         case CTDB_CONTROL_SET_LMASTERROLE:
900                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
901                 break;
902
903         case CTDB_CONTROL_SET_RECMASTERROLE:
904                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
905                 break;
906
907         case CTDB_CONTROL_SET_BAN_STATE:
908                 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
909                                           &cd->data.ban_state, &np);
910                 break;
911
912         case CTDB_CONTROL_REGISTER_NOTIFY:
913                 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
914                                             &cd->data.notify, &np);
915                 break;
916
917         case CTDB_CONTROL_DEREGISTER_NOTIFY:
918                 ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
919                 break;
920
921         case CTDB_CONTROL_TRANS3_COMMIT:
922                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
923                                            &cd->data.recbuf, &np);
924                 break;
925
926         case CTDB_CONTROL_GET_DB_SEQNUM:
927                 offset = 0;
928                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
929                 if (ret != 0) {
930                         break;
931                 }
932                 offset += np;
933                 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
934                 offset += np;
935                 np = offset;
936                 break;
937
938         case CTDB_CONTROL_DB_SET_HEALTHY:
939                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
940                 break;
941
942         case CTDB_CONTROL_DB_GET_HEALTH:
943                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
944                 break;
945
946         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
947                 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
948                                           &cd->data.addr, &np);
949                 break;
950
951         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
952                 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
953                                       &cd->data.iface, &np);
954                 break;
955
956         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
957                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
958                                            &cd->data.conn, &np);
959                 break;
960
961         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
962                 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
963                                          &cd->data.key);
964                 break;
965
966         case CTDB_CONTROL_SET_DB_READONLY:
967                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
968                 break;
969
970         case CTDB_CONTROL_CHECK_SRVIDS:
971                 break;
972
973         case CTDB_CONTROL_TRAVERSE_START_EXT:
974                 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
975                                                    &cd->data.traverse_start_ext,
976                                                    &np);
977                 break;
978
979         case CTDB_CONTROL_GET_DB_STATISTICS:
980                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
981                 break;
982
983         case CTDB_CONTROL_SET_DB_STICKY:
984                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
985                 break;
986
987         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
988                 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
989                                                  &cd->data.traverse_all_ext,
990                                                  &np);
991                 break;
992
993         case CTDB_CONTROL_RECEIVE_RECORDS:
994                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
995                                            &cd->data.recbuf, &np);
996                 break;
997
998         case CTDB_CONTROL_DB_DETACH:
999                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1000                 break;
1001
1002         case CTDB_CONTROL_DB_FREEZE:
1003                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1004                 break;
1005
1006         case CTDB_CONTROL_DB_THAW:
1007                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1008                 break;
1009
1010         case CTDB_CONTROL_DB_TRANSACTION_START:
1011                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1012                                         &cd->data.transdb, &np);
1013                 break;
1014
1015         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1016                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1017                                         &cd->data.transdb, &np);
1018                 break;
1019
1020         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1021                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1022                 break;
1023
1024         case CTDB_CONTROL_DB_PULL:
1025                 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1026                                            &cd->data.pulldb_ext, &np);
1027                 break;
1028
1029         case CTDB_CONTROL_DB_PUSH_START:
1030                 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1031                                            &cd->data.pulldb_ext, &np);
1032                 break;
1033
1034         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1035                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1036                 break;
1037
1038         case CTDB_CONTROL_DB_OPEN_FLAGS:
1039                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1040                 break;
1041
1042         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1043                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1044                                        &cd->data.db_name, &np);
1045                 break;
1046         }
1047
1048         return ret;
1049 }
1050
1051 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1052 {
1053         size_t len = 0;
1054
1055         if (cd == NULL) {
1056                 return 0;
1057         }
1058
1059         switch (cd->opcode) {
1060         case CTDB_CONTROL_PROCESS_EXISTS:
1061                 break;
1062
1063         case CTDB_CONTROL_STATISTICS:
1064                 len = ctdb_statistics_len(cd->data.stats);
1065                 break;
1066
1067         case CTDB_CONTROL_PING:
1068                 break;
1069
1070         case CTDB_CONTROL_GETDBPATH:
1071                 len = ctdb_string_len(&cd->data.db_path);
1072                 break;
1073
1074         case CTDB_CONTROL_GETVNNMAP:
1075                 len = ctdb_vnn_map_len(cd->data.vnnmap);
1076                 break;
1077
1078         case CTDB_CONTROL_SETVNNMAP:
1079                 break;
1080
1081         case CTDB_CONTROL_GET_DEBUG:
1082                 len = ctdb_uint32_len(&cd->data.loglevel);
1083                 break;
1084
1085         case CTDB_CONTROL_SET_DEBUG:
1086                 break;
1087
1088         case CTDB_CONTROL_GET_DBMAP:
1089                 len = ctdb_dbid_map_len(cd->data.dbmap);
1090                 break;
1091
1092         case CTDB_CONTROL_PULL_DB:
1093                 len = ctdb_rec_buffer_len(cd->data.recbuf);
1094                 break;
1095
1096         case CTDB_CONTROL_PUSH_DB:
1097                 break;
1098
1099         case CTDB_CONTROL_GET_RECMODE:
1100                 break;
1101
1102         case CTDB_CONTROL_SET_RECMODE:
1103                 break;
1104
1105         case CTDB_CONTROL_STATISTICS_RESET:
1106                 break;
1107
1108         case CTDB_CONTROL_DB_ATTACH:
1109                 len = ctdb_uint32_len(&cd->data.db_id);
1110                 break;
1111
1112         case CTDB_CONTROL_SET_CALL:
1113                 break;
1114
1115         case CTDB_CONTROL_TRAVERSE_START:
1116                 break;
1117
1118         case CTDB_CONTROL_TRAVERSE_ALL:
1119                 break;
1120
1121         case CTDB_CONTROL_TRAVERSE_DATA:
1122                 break;
1123
1124         case CTDB_CONTROL_REGISTER_SRVID:
1125                 break;
1126
1127         case CTDB_CONTROL_DEREGISTER_SRVID:
1128                 break;
1129
1130         case CTDB_CONTROL_GET_DBNAME:
1131                 len = ctdb_string_len(&cd->data.db_name);
1132                 break;
1133
1134         case CTDB_CONTROL_ENABLE_SEQNUM:
1135                 break;
1136
1137         case CTDB_CONTROL_UPDATE_SEQNUM:
1138                 break;
1139
1140         case CTDB_CONTROL_DUMP_MEMORY:
1141                 len = ctdb_string_len(&cd->data.mem_str);
1142                 break;
1143
1144         case CTDB_CONTROL_GET_PID:
1145                 break;
1146
1147         case CTDB_CONTROL_GET_RECMASTER:
1148                 break;
1149
1150         case CTDB_CONTROL_SET_RECMASTER:
1151                 break;
1152
1153         case CTDB_CONTROL_FREEZE:
1154                 break;
1155
1156         case CTDB_CONTROL_GET_PNN:
1157                 break;
1158
1159         case CTDB_CONTROL_SHUTDOWN:
1160                 break;
1161
1162         case CTDB_CONTROL_GET_MONMODE:
1163                 break;
1164
1165         case CTDB_CONTROL_TCP_CLIENT:
1166                 break;
1167
1168         case CTDB_CONTROL_TCP_ADD:
1169                 break;
1170
1171         case CTDB_CONTROL_TCP_REMOVE:
1172                 break;
1173
1174         case CTDB_CONTROL_STARTUP:
1175                 break;
1176
1177         case CTDB_CONTROL_SET_TUNABLE:
1178                 break;
1179
1180         case CTDB_CONTROL_GET_TUNABLE:
1181                 len = ctdb_uint32_len(&cd->data.tun_value);
1182                 break;
1183
1184         case CTDB_CONTROL_LIST_TUNABLES:
1185                 len = ctdb_var_list_len(cd->data.tun_var_list);
1186                 break;
1187
1188         case CTDB_CONTROL_MODIFY_FLAGS:
1189                 break;
1190
1191         case CTDB_CONTROL_GET_ALL_TUNABLES:
1192                 len = ctdb_tunable_list_len(cd->data.tun_list);
1193                 break;
1194
1195         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1196                 len = ctdb_tickle_list_len(cd->data.tickles);
1197                 break;
1198
1199         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1200                 break;
1201
1202         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1203                 len = ctdb_uint32_len(&cd->data.db_id);
1204                 break;
1205
1206         case CTDB_CONTROL_UPDATE_RECORD:
1207                 break;
1208
1209         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1210                 break;
1211
1212         case CTDB_CONTROL_WIPE_DATABASE:
1213                 break;
1214
1215         case CTDB_CONTROL_UPTIME:
1216                 len = ctdb_uptime_len(cd->data.uptime);
1217                 break;
1218
1219         case CTDB_CONTROL_START_RECOVERY:
1220                 break;
1221
1222         case CTDB_CONTROL_END_RECOVERY:
1223                 break;
1224
1225         case CTDB_CONTROL_RELOAD_NODES_FILE:
1226                 break;
1227
1228         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1229                 len = ctdb_rec_buffer_len(cd->data.recbuf);
1230                 break;
1231
1232         case CTDB_CONTROL_ENABLE_MONITOR:
1233                 break;
1234
1235         case CTDB_CONTROL_DISABLE_MONITOR:
1236                 break;
1237
1238         case CTDB_CONTROL_ADD_PUBLIC_IP:
1239                 break;
1240
1241         case CTDB_CONTROL_DEL_PUBLIC_IP:
1242                 break;
1243
1244         case CTDB_CONTROL_GET_CAPABILITIES:
1245                 len = ctdb_uint32_len(&cd->data.caps);
1246                 break;
1247
1248         case CTDB_CONTROL_RECD_PING:
1249                 break;
1250
1251         case CTDB_CONTROL_RELEASE_IP:
1252                 break;
1253
1254         case CTDB_CONTROL_TAKEOVER_IP:
1255                 break;
1256
1257         case CTDB_CONTROL_GET_PUBLIC_IPS:
1258                 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1259                 break;
1260
1261         case CTDB_CONTROL_GET_NODEMAP:
1262                 len = ctdb_node_map_len(cd->data.nodemap);
1263                 break;
1264
1265         case CTDB_CONTROL_TRAVERSE_KILL:
1266                 break;
1267
1268         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1269                 break;
1270
1271         case CTDB_CONTROL_GET_RECLOCK_FILE:
1272                 len = ctdb_string_len(&cd->data.reclock_file);
1273                 break;
1274
1275         case CTDB_CONTROL_STOP_NODE:
1276                 break;
1277
1278         case CTDB_CONTROL_CONTINUE_NODE:
1279                 break;
1280
1281         case CTDB_CONTROL_SET_LMASTERROLE:
1282                 break;
1283
1284         case CTDB_CONTROL_SET_RECMASTERROLE:
1285                 break;
1286
1287         case CTDB_CONTROL_SET_BAN_STATE:
1288                 break;
1289
1290         case CTDB_CONTROL_GET_BAN_STATE:
1291                 len = ctdb_ban_state_len(cd->data.ban_state);
1292                 break;
1293
1294         case CTDB_CONTROL_SET_DB_PRIORITY:
1295                 break;
1296
1297         case CTDB_CONTROL_GET_DB_PRIORITY:
1298                 break;
1299
1300         case CTDB_CONTROL_REGISTER_NOTIFY:
1301                 break;
1302
1303         case CTDB_CONTROL_DEREGISTER_NOTIFY:
1304                 break;
1305
1306         case CTDB_CONTROL_TRANS3_COMMIT:
1307                 break;
1308
1309         case CTDB_CONTROL_GET_DB_SEQNUM:
1310                 len = ctdb_uint64_len(&cd->data.seqnum);
1311                 break;
1312
1313         case CTDB_CONTROL_DB_SET_HEALTHY:
1314                 break;
1315
1316         case CTDB_CONTROL_DB_GET_HEALTH:
1317                 len = ctdb_string_len(&cd->data.reason);
1318                 break;
1319
1320         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1321                 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1322                 break;
1323
1324         case CTDB_CONTROL_GET_IFACES:
1325                 len = ctdb_iface_list_len(cd->data.iface_list);
1326                 break;
1327
1328         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1329                 break;
1330
1331         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1332                 break;
1333
1334         case CTDB_CONTROL_GET_STAT_HISTORY:
1335                 len = ctdb_statistics_list_len(cd->data.stats_list);
1336                 break;
1337
1338         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1339                 break;
1340
1341         case CTDB_CONTROL_SET_DB_READONLY:
1342                 break;
1343
1344         case CTDB_CONTROL_CHECK_SRVIDS:
1345                 break;
1346
1347         case CTDB_CONTROL_TRAVERSE_START_EXT:
1348                 break;
1349
1350         case CTDB_CONTROL_GET_DB_STATISTICS:
1351                 len = ctdb_db_statistics_len(cd->data.dbstats);
1352                 break;
1353
1354         case CTDB_CONTROL_SET_DB_STICKY:
1355                 break;
1356
1357         case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1358                 break;
1359
1360         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1361                 break;
1362
1363         case CTDB_CONTROL_RECEIVE_RECORDS:
1364                 len = ctdb_rec_buffer_len(cd->data.recbuf);
1365                 break;
1366
1367         case CTDB_CONTROL_IPREALLOCATED:
1368                 break;
1369
1370         case CTDB_CONTROL_GET_RUNSTATE:
1371                 len = ctdb_uint32_len(&cd->data.runstate);
1372                 break;
1373
1374         case CTDB_CONTROL_DB_DETACH:
1375                 break;
1376
1377         case CTDB_CONTROL_GET_NODES_FILE:
1378                 len = ctdb_node_map_len(cd->data.nodemap);
1379                 break;
1380
1381         case CTDB_CONTROL_DB_FREEZE:
1382                 break;
1383
1384         case CTDB_CONTROL_DB_THAW:
1385                 break;
1386
1387         case CTDB_CONTROL_DB_TRANSACTION_START:
1388                 break;
1389
1390         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1391                 break;
1392
1393         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1394                 break;
1395
1396         case CTDB_CONTROL_DB_PULL:
1397                 len = ctdb_uint32_len(&cd->data.num_records);
1398                 break;
1399
1400         case CTDB_CONTROL_DB_PUSH_START:
1401                 break;
1402
1403         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1404                 len = ctdb_uint32_len(&cd->data.num_records);
1405                 break;
1406
1407         case CTDB_CONTROL_DB_OPEN_FLAGS:
1408                 len = ctdb_int32_len(&cd->data.tdb_flags);
1409                 break;
1410
1411         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1412                 len = ctdb_uint32_len(&cd->data.db_id);
1413                 break;
1414         }
1415
1416         return len;
1417 }
1418
1419 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1420                                          uint8_t *buf)
1421 {
1422         size_t np;
1423
1424         switch (cd->opcode) {
1425         case CTDB_CONTROL_STATISTICS:
1426                 ctdb_statistics_push(cd->data.stats, buf, &np);
1427                 break;
1428
1429         case CTDB_CONTROL_GETDBPATH:
1430                 ctdb_string_push(&cd->data.db_path, buf, &np);
1431                 break;
1432
1433         case CTDB_CONTROL_GETVNNMAP:
1434                 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1435                 break;
1436
1437         case CTDB_CONTROL_GET_DEBUG:
1438                 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1439                 break;
1440
1441         case CTDB_CONTROL_GET_DBMAP:
1442                 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1443                 break;
1444
1445         case CTDB_CONTROL_PULL_DB:
1446                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1447                 break;
1448
1449         case CTDB_CONTROL_PUSH_DB:
1450                 break;
1451
1452         case CTDB_CONTROL_DB_ATTACH:
1453                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1454                 break;
1455
1456         case CTDB_CONTROL_GET_DBNAME:
1457                 ctdb_string_push(&cd->data.db_name, buf, &np);
1458                 break;
1459
1460         case CTDB_CONTROL_DUMP_MEMORY:
1461                 ctdb_string_push(&cd->data.mem_str, buf, &np);
1462                 break;
1463
1464         case CTDB_CONTROL_GET_PID:
1465                 break;
1466
1467         case CTDB_CONTROL_GET_RECMASTER:
1468                 break;
1469
1470         case CTDB_CONTROL_GET_TUNABLE:
1471                 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1472                 break;
1473
1474         case CTDB_CONTROL_LIST_TUNABLES:
1475                 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1476                 break;
1477
1478         case CTDB_CONTROL_GET_ALL_TUNABLES:
1479                 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1480                 break;
1481
1482         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1483                 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1484                 break;
1485
1486         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1487                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1488                 break;
1489
1490         case CTDB_CONTROL_UPTIME:
1491                 ctdb_uptime_push(cd->data.uptime, buf, &np);
1492                 break;
1493
1494         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1495                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1496                 break;
1497
1498         case CTDB_CONTROL_GET_CAPABILITIES:
1499                 ctdb_uint32_push(&cd->data.caps, buf, &np);
1500                 break;
1501
1502         case CTDB_CONTROL_GET_PUBLIC_IPS:
1503                 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1504                 break;
1505
1506         case CTDB_CONTROL_GET_NODEMAP:
1507                 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1508                 break;
1509
1510         case CTDB_CONTROL_GET_RECLOCK_FILE:
1511                 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1512                 break;
1513
1514         case CTDB_CONTROL_GET_BAN_STATE:
1515                 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1516                 break;
1517
1518         case CTDB_CONTROL_GET_DB_PRIORITY:
1519                 break;
1520
1521         case CTDB_CONTROL_GET_DB_SEQNUM:
1522                 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1523                 break;
1524
1525         case CTDB_CONTROL_DB_GET_HEALTH:
1526                 ctdb_string_push(&cd->data.reason, buf, &np);
1527                 break;
1528
1529         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1530                 ctdb_public_ip_info_push(cd->data.ipinfo, buf);
1531                 break;
1532
1533         case CTDB_CONTROL_GET_IFACES:
1534                 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1535                 break;
1536
1537         case CTDB_CONTROL_GET_STAT_HISTORY:
1538                 ctdb_statistics_list_push(cd->data.stats_list, buf);
1539                 break;
1540
1541         case CTDB_CONTROL_CHECK_SRVIDS:
1542                 break;
1543
1544         case CTDB_CONTROL_GET_DB_STATISTICS:
1545                 ctdb_db_statistics_push(cd->data.dbstats, buf);
1546                 break;
1547
1548         case CTDB_CONTROL_RECEIVE_RECORDS:
1549                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1550                 break;
1551
1552         case CTDB_CONTROL_GET_RUNSTATE:
1553                 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1554                 break;
1555
1556         case CTDB_CONTROL_GET_NODES_FILE:
1557                 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1558                 break;
1559
1560         case CTDB_CONTROL_DB_PULL:
1561                 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1562                 break;
1563
1564         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1565                 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1566                 break;
1567
1568         case CTDB_CONTROL_DB_OPEN_FLAGS:
1569                 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1570                 break;
1571
1572         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1573                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1574                 break;
1575         }
1576 }
1577
1578 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1579                                         uint32_t opcode, TALLOC_CTX *mem_ctx,
1580                                         struct ctdb_reply_control_data *cd)
1581 {
1582         size_t np;
1583         int ret = 0;
1584
1585         cd->opcode = opcode;
1586
1587         switch (opcode) {
1588         case CTDB_CONTROL_STATISTICS:
1589                 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1590                                            &cd->data.stats, &np);
1591                 break;
1592
1593         case CTDB_CONTROL_GETDBPATH:
1594                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1595                                        &cd->data.db_path, &np);
1596                 break;
1597
1598         case CTDB_CONTROL_GETVNNMAP:
1599                 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1600                                         &cd->data.vnnmap, &np);
1601                 break;
1602
1603         case CTDB_CONTROL_GET_DEBUG:
1604                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1605                 break;
1606
1607         case CTDB_CONTROL_GET_DBMAP:
1608                 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1609                                          &cd->data.dbmap, &np);
1610                 break;
1611
1612         case CTDB_CONTROL_PULL_DB:
1613                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1614                                            &cd->data.recbuf, &np);
1615                 break;
1616
1617         case CTDB_CONTROL_PUSH_DB:
1618                 break;
1619
1620         case CTDB_CONTROL_DB_ATTACH:
1621                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1622                 break;
1623
1624         case CTDB_CONTROL_GET_DBNAME:
1625                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1626                                        &cd->data.db_name, &np);
1627                 break;
1628
1629         case CTDB_CONTROL_DUMP_MEMORY:
1630                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1631                                        &cd->data.mem_str, &np);
1632                 break;
1633
1634         case CTDB_CONTROL_GET_PID:
1635                 break;
1636
1637         case CTDB_CONTROL_GET_RECMASTER:
1638                 break;
1639
1640         case CTDB_CONTROL_GET_TUNABLE:
1641                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1642                                        &np);
1643                 break;
1644
1645         case CTDB_CONTROL_LIST_TUNABLES:
1646                 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1647                                          &cd->data.tun_var_list, &np);
1648                 break;
1649
1650         case CTDB_CONTROL_GET_ALL_TUNABLES:
1651                 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1652                                              &cd->data.tun_list, &np);
1653                 break;
1654
1655         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1656                 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1657                                             &cd->data.tickles, &np);
1658                 break;
1659
1660         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1661                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1662                 break;
1663
1664         case CTDB_CONTROL_UPTIME:
1665                 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1666                                        &cd->data.uptime, &np);
1667                 break;
1668
1669         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1670                 ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1671                                      &cd->data.recbuf, &np);
1672                 break;
1673
1674         case CTDB_CONTROL_GET_CAPABILITIES:
1675                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1676                 break;
1677
1678         case CTDB_CONTROL_GET_PUBLIC_IPS:
1679                 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1680                                                &cd->data.pubip_list, &np);
1681                 break;
1682
1683         case CTDB_CONTROL_GET_NODEMAP:
1684                 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1685                                          &cd->data.nodemap, &np);
1686                 break;
1687
1688         case CTDB_CONTROL_GET_RECLOCK_FILE:
1689                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1690                                        &cd->data.reclock_file, &np);
1691                 break;
1692
1693         case CTDB_CONTROL_GET_BAN_STATE:
1694                 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1695                                           &cd->data.ban_state, &np);
1696                 break;
1697
1698         case CTDB_CONTROL_GET_DB_PRIORITY:
1699                 break;
1700
1701         case CTDB_CONTROL_GET_DB_SEQNUM:
1702                 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1703                 break;
1704
1705         case CTDB_CONTROL_DB_GET_HEALTH:
1706                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1707                                        &cd->data.reason, &np);
1708                 break;
1709
1710         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1711                 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1712                                                &cd->data.ipinfo);
1713                 break;
1714
1715         case CTDB_CONTROL_GET_IFACES:
1716                 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1717                                            &cd->data.iface_list, &np);
1718                 break;
1719
1720         case CTDB_CONTROL_GET_STAT_HISTORY:
1721                 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1722                                                 &cd->data.stats_list);
1723                 break;
1724
1725         case CTDB_CONTROL_CHECK_SRVIDS:
1726                 break;
1727
1728         case CTDB_CONTROL_GET_DB_STATISTICS:
1729                 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1730                                               &cd->data.dbstats);
1731                 break;
1732
1733         case CTDB_CONTROL_RECEIVE_RECORDS:
1734                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1735                                            &cd->data.recbuf, &np);
1736                 break;
1737
1738         case CTDB_CONTROL_GET_RUNSTATE:
1739                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1740                 break;
1741
1742         case CTDB_CONTROL_GET_NODES_FILE:
1743                 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1744                                          &cd->data.nodemap, &np);
1745                 break;
1746
1747         case CTDB_CONTROL_DB_PULL:
1748                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1749                                        &np);
1750                 break;
1751
1752         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1753                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1754                                        &np);
1755                 break;
1756
1757         case CTDB_CONTROL_DB_OPEN_FLAGS:
1758                 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1759                 break;
1760
1761         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1762                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1763                 break;
1764         }
1765
1766         return ret;
1767 }
1768
1769 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1770                             struct ctdb_req_control *c)
1771 {
1772         return offsetof(struct ctdb_req_control_wire, data) +
1773                 ctdb_req_control_data_len(&c->rdata);
1774 }
1775
1776 int ctdb_req_control_push(struct ctdb_req_header *h,
1777                           struct ctdb_req_control *request,
1778                           uint8_t *buf, size_t *buflen)
1779 {
1780         struct ctdb_req_control_wire *wire =
1781                 (struct ctdb_req_control_wire *)buf;
1782         size_t length;
1783
1784         length = ctdb_req_control_len(h, request);
1785         if (*buflen < length) {
1786                 *buflen = length;
1787                 return EMSGSIZE;
1788         }
1789
1790         h->length = *buflen;
1791         ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
1792
1793         wire->opcode = request->opcode;
1794         wire->pad = request->pad;
1795         wire->srvid = request->srvid;
1796         wire->client_id = request->client_id;
1797         wire->flags = request->flags;
1798
1799         wire->datalen = ctdb_req_control_data_len(&request->rdata);
1800         ctdb_req_control_data_push(&request->rdata, wire->data);
1801
1802         return 0;
1803 }
1804
1805 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1806                           struct ctdb_req_header *h,
1807                           TALLOC_CTX *mem_ctx,
1808                           struct ctdb_req_control *c)
1809 {
1810         struct ctdb_req_control_wire *wire =
1811                 (struct ctdb_req_control_wire *)buf;
1812         size_t length;
1813         int ret;
1814
1815         length = offsetof(struct ctdb_req_control_wire, data);
1816         if (buflen < length) {
1817                 return EMSGSIZE;
1818         }
1819         if (wire->datalen > buflen) {
1820                 return EMSGSIZE;
1821         }
1822         if (length + wire->datalen < length) {
1823                 return EMSGSIZE;
1824         }
1825         if (buflen < length + wire->datalen) {
1826                 return EMSGSIZE;
1827         }
1828
1829         if (h != NULL) {
1830                 ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
1831                 if (ret != 0) {
1832                         return ret;
1833                 }
1834         }
1835
1836         c->opcode = wire->opcode;
1837         c->pad = wire->pad;
1838         c->srvid = wire->srvid;
1839         c->client_id = wire->client_id;
1840         c->flags = wire->flags;
1841
1842         ret = ctdb_req_control_data_pull(wire->data, wire->datalen,
1843                                          c->opcode, mem_ctx, &c->rdata);
1844         if (ret != 0) {
1845                 return ret;
1846         }
1847
1848         return 0;
1849 }
1850
1851 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1852                               struct ctdb_reply_control *c)
1853 {
1854         return offsetof(struct ctdb_reply_control_wire, data) +
1855                 (c->status == 0 ?
1856                         ctdb_reply_control_data_len(&c->rdata) :
1857                         ctdb_string_len(&c->errmsg));
1858 }
1859
1860 int ctdb_reply_control_push(struct ctdb_req_header *h,
1861                             struct ctdb_reply_control *reply,
1862                             uint8_t *buf, size_t *buflen)
1863 {
1864         struct ctdb_reply_control_wire *wire =
1865                 (struct ctdb_reply_control_wire *)buf;
1866         size_t length, np;
1867
1868         length = ctdb_reply_control_len(h, reply);
1869         if (*buflen < length) {
1870                 *buflen = length;
1871                 return EMSGSIZE;
1872         }
1873
1874         h->length = *buflen;
1875         ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
1876
1877         wire->status = reply->status;
1878
1879         if (reply->status == 0) {
1880                 wire->datalen = ctdb_reply_control_data_len(&reply->rdata);
1881                 wire->errorlen = 0;
1882                 ctdb_reply_control_data_push(&reply->rdata, wire->data);
1883         } else {
1884                 wire->datalen = 0;
1885                 wire->errorlen = ctdb_string_len(&reply->errmsg);
1886                 ctdb_string_push(&reply->errmsg, wire->data + wire->datalen,
1887                                  &np);
1888         }
1889
1890         return 0;
1891 }
1892
1893 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1894                             struct ctdb_req_header *h,
1895                             TALLOC_CTX *mem_ctx,
1896                             struct ctdb_reply_control *c)
1897 {
1898         struct ctdb_reply_control_wire *wire =
1899                 (struct ctdb_reply_control_wire *)buf;
1900         size_t length, np;
1901         int ret;
1902
1903         length = offsetof(struct ctdb_reply_control_wire, data);
1904         if (buflen < length) {
1905                 return EMSGSIZE;
1906         }
1907         if (wire->datalen > buflen || wire->errorlen > buflen) {
1908                 return EMSGSIZE;
1909         }
1910         if (length + wire->datalen < length) {
1911                 return EMSGSIZE;
1912         }
1913         if (length + wire->datalen + wire->errorlen < length) {
1914                 return EMSGSIZE;
1915         }
1916         if (buflen < length + wire->datalen + wire->errorlen) {
1917                 return EMSGSIZE;
1918         }
1919
1920         if (h != NULL) {
1921                 ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
1922                 if (ret != 0) {
1923                         return ret;
1924                 }
1925         }
1926
1927         c->status = wire->status;
1928
1929         if (c->status != -1) {
1930                 ret = ctdb_reply_control_data_pull(wire->data, wire->datalen,
1931                                                    opcode, mem_ctx,
1932                                                    &c->rdata);
1933                 if (ret != 0) {
1934                         return ret;
1935                 }
1936         }
1937
1938         ret = ctdb_string_pull(wire->data + wire->datalen, wire->errorlen,
1939                                mem_ctx, &c->errmsg, &np);
1940         if (ret != 0) {
1941                 return ret;
1942         }
1943
1944         return 0;
1945 }