2 protocol types backward compatibility test
4 Copyright (C) Amitay Isaacs 2015
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/filesys.h"
25 #include "protocol/protocol_basic.c"
26 #include "protocol/protocol_types.c"
28 #include "tests/src/protocol_common.h"
30 #define COMPAT_TEST_FUNC(NAME) test_ ##NAME## _compat
31 #define OLD_LEN_FUNC(NAME) NAME## _len_old
32 #define OLD_PUSH_FUNC(NAME) NAME## _push_old
33 #define OLD_PULL_FUNC(NAME) NAME## _pull_old
35 #define COMPAT_TYPE1_TEST(TYPE, NAME) \
36 static void COMPAT_TEST_FUNC(NAME)(void) \
38 TALLOC_CTX *mem_ctx; \
39 uint8_t *buf1, *buf2; \
40 TYPE p = { 0 }, p1, p2; \
41 size_t buflen1, buflen2, np = 0; \
44 mem_ctx = talloc_new(NULL); \
45 assert(mem_ctx != NULL); \
46 FILL_FUNC(NAME)(&p); \
47 buflen1 = LEN_FUNC(NAME)(&p); \
48 buflen2 = OLD_LEN_FUNC(NAME)(&p); \
49 assert(buflen1 == buflen2); \
50 buf1 = talloc_zero_size(mem_ctx, buflen1); \
51 assert(buf1 != NULL); \
52 buf2 = talloc_zero_size(mem_ctx, buflen2); \
53 assert(buf2 != NULL); \
54 PUSH_FUNC(NAME)(&p, buf1, &np); \
55 OLD_PUSH_FUNC(NAME)(&p, buf2); \
56 assert(memcmp(buf1, buf2, buflen1) == 0); \
57 ret = PULL_FUNC(NAME)(buf1, buflen1, &p1, &np); \
59 ret = OLD_PULL_FUNC(NAME)(buf2, buflen2, &p2); \
61 VERIFY_FUNC(NAME)(&p1, &p2); \
62 talloc_free(mem_ctx); \
65 #define COMPAT_TYPE3_TEST(TYPE, NAME) \
66 static void COMPAT_TEST_FUNC(NAME)(void) \
68 TALLOC_CTX *mem_ctx; \
69 uint8_t *buf1, *buf2; \
71 size_t buflen1, buflen2, np = 0; \
74 mem_ctx = talloc_new(NULL); \
75 assert(mem_ctx != NULL); \
76 p = talloc_zero(mem_ctx, TYPE); \
78 FILL_FUNC(NAME)(p, p); \
79 buflen1 = LEN_FUNC(NAME)(p); \
80 buflen2 = OLD_LEN_FUNC(NAME)(p); \
81 assert(buflen1 == buflen2); \
82 buf1 = talloc_zero_size(mem_ctx, buflen1); \
83 assert(buf1 != NULL); \
84 buf2 = talloc_zero_size(mem_ctx, buflen2); \
85 assert(buf2 != NULL); \
86 PUSH_FUNC(NAME)(p, buf1, &np); \
87 OLD_PUSH_FUNC(NAME)(p, buf2); \
88 assert(memcmp(buf1, buf2, buflen1) == 0); \
89 ret = PULL_FUNC(NAME)(buf1, buflen1, mem_ctx, &p1, &np); \
91 ret = OLD_PULL_FUNC(NAME)(buf2, buflen2, mem_ctx, &p2); \
93 VERIFY_FUNC(NAME)(p1, p2); \
94 talloc_free(mem_ctx); \
98 static size_t ctdb_statistics_len_old(struct ctdb_statistics
*in
)
100 return sizeof(struct ctdb_statistics
);
103 static void ctdb_statistics_push_old(struct ctdb_statistics
*in
, uint8_t *buf
)
105 memcpy(buf
, in
, sizeof(struct ctdb_statistics
));
108 static int ctdb_statistics_pull_old(uint8_t *buf
, size_t buflen
,
110 struct ctdb_statistics
**out
)
112 struct ctdb_statistics
*val
;
114 if (buflen
< sizeof(struct ctdb_statistics
)) {
118 val
= talloc(mem_ctx
, struct ctdb_statistics
);
123 memcpy(val
, buf
, sizeof(struct ctdb_statistics
));
129 struct ctdb_vnn_map_wire
{
135 static size_t ctdb_vnn_map_len_old(struct ctdb_vnn_map
*in
)
137 return offsetof(struct ctdb_vnn_map
, map
) +
138 in
->size
* sizeof(uint32_t);
141 static void ctdb_vnn_map_push_old(struct ctdb_vnn_map
*in
, uint8_t *buf
)
143 struct ctdb_vnn_map_wire
*wire
= (struct ctdb_vnn_map_wire
*)buf
;
145 memcpy(wire
, in
, offsetof(struct ctdb_vnn_map
, map
));
146 memcpy(wire
->map
, in
->map
, in
->size
* sizeof(uint32_t));
149 static int ctdb_vnn_map_pull_old(uint8_t *buf
, size_t buflen
,
151 struct ctdb_vnn_map
**out
)
153 struct ctdb_vnn_map
*val
;
154 struct ctdb_vnn_map_wire
*wire
= (struct ctdb_vnn_map_wire
*)buf
;
156 if (buflen
< offsetof(struct ctdb_vnn_map_wire
, map
)) {
159 if (wire
->size
> buflen
/ sizeof(uint32_t)) {
162 if (offsetof(struct ctdb_vnn_map_wire
, map
) +
163 wire
->size
* sizeof(uint32_t) <
164 offsetof(struct ctdb_vnn_map_wire
, map
)) {
167 if (buflen
< offsetof(struct ctdb_vnn_map_wire
, map
) +
168 wire
->size
* sizeof(uint32_t)) {
172 val
= talloc(mem_ctx
, struct ctdb_vnn_map
);
177 memcpy(val
, wire
, offsetof(struct ctdb_vnn_map
, map
));
179 val
->map
= talloc_memdup(val
, wire
->map
,
180 wire
->size
* sizeof(uint32_t));
181 if (val
->map
== NULL
) {
190 struct ctdb_dbid_map_wire
{
192 struct ctdb_dbid dbs
[1];
195 static size_t ctdb_dbid_map_len_old(struct ctdb_dbid_map
*in
)
197 return sizeof(uint32_t) + in
->num
* sizeof(struct ctdb_dbid
);
200 static void ctdb_dbid_map_push_old(struct ctdb_dbid_map
*in
, uint8_t *buf
)
202 struct ctdb_dbid_map_wire
*wire
= (struct ctdb_dbid_map_wire
*)buf
;
205 memcpy(wire
->dbs
, in
->dbs
, in
->num
* sizeof(struct ctdb_dbid
));
208 static int ctdb_dbid_map_pull_old(uint8_t *buf
, size_t buflen
,
210 struct ctdb_dbid_map
**out
)
212 struct ctdb_dbid_map
*val
;
213 struct ctdb_dbid_map_wire
*wire
= (struct ctdb_dbid_map_wire
*)buf
;
215 if (buflen
< sizeof(uint32_t)) {
218 if (wire
->num
> buflen
/ sizeof(struct ctdb_dbid
)) {
221 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_dbid
) <
225 if (buflen
< sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_dbid
)) {
229 val
= talloc(mem_ctx
, struct ctdb_dbid_map
);
234 val
->num
= wire
->num
;
236 val
->dbs
= talloc_memdup(val
, wire
->dbs
,
237 wire
->num
* sizeof(struct ctdb_dbid
));
238 if (val
->dbs
== NULL
) {
247 static size_t ctdb_pulldb_len_old(struct ctdb_pulldb
*in
)
249 return sizeof(struct ctdb_pulldb
);
252 static void ctdb_pulldb_push_old(struct ctdb_pulldb
*in
, uint8_t *buf
)
254 memcpy(buf
, in
, sizeof(struct ctdb_pulldb
));
257 static int ctdb_pulldb_pull_old(uint8_t *buf
, size_t buflen
,
258 TALLOC_CTX
*mem_ctx
, struct ctdb_pulldb
**out
)
260 struct ctdb_pulldb
*val
;
262 if (buflen
< sizeof(struct ctdb_pulldb
)) {
266 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_pulldb
));
275 static size_t ctdb_pulldb_ext_len_old(struct ctdb_pulldb_ext
*in
)
277 return sizeof(struct ctdb_pulldb_ext
);
280 static void ctdb_pulldb_ext_push_old(struct ctdb_pulldb_ext
*in
, uint8_t *buf
)
282 memcpy(buf
, in
, sizeof(struct ctdb_pulldb_ext
));
285 static int ctdb_pulldb_ext_pull_old(uint8_t *buf
, size_t buflen
,
287 struct ctdb_pulldb_ext
**out
)
289 struct ctdb_pulldb_ext
*val
;
291 if (buflen
< sizeof(struct ctdb_pulldb_ext
)) {
295 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_pulldb_ext
));
304 static size_t ctdb_ltdb_header_len_old(struct ctdb_ltdb_header
*in
)
306 return sizeof(struct ctdb_ltdb_header
);
309 static void ctdb_ltdb_header_push_old(struct ctdb_ltdb_header
*in
,
312 memcpy(buf
, in
, sizeof(struct ctdb_ltdb_header
));
315 static int ctdb_ltdb_header_pull_old(uint8_t *buf
, size_t buflen
,
316 struct ctdb_ltdb_header
*out
)
318 if (buflen
< sizeof(struct ctdb_ltdb_header
)) {
322 memcpy(out
, buf
, sizeof(struct ctdb_ltdb_header
));
326 struct ctdb_rec_data_wire
{
334 static size_t ctdb_rec_data_len_old(struct ctdb_rec_data
*in
)
336 return offsetof(struct ctdb_rec_data_wire
, data
) +
337 in
->key
.dsize
+ in
->data
.dsize
+
338 (in
->header
== NULL
? 0 : sizeof(struct ctdb_ltdb_header
));
341 static void ctdb_rec_data_push_old(struct ctdb_rec_data
*in
, uint8_t *buf
)
343 struct ctdb_rec_data_wire
*wire
= (struct ctdb_rec_data_wire
*)buf
;
346 wire
->length
= ctdb_rec_data_len(in
);
347 wire
->reqid
= in
->reqid
;
348 wire
->keylen
= in
->key
.dsize
;
349 wire
->datalen
= in
->data
.dsize
;
350 if (in
->header
!= NULL
) {
351 wire
->datalen
+= sizeof(struct ctdb_ltdb_header
);
354 memcpy(wire
->data
, in
->key
.dptr
, in
->key
.dsize
);
355 offset
= in
->key
.dsize
;
356 if (in
->header
!= NULL
) {
357 memcpy(&wire
->data
[offset
], in
->header
,
358 sizeof(struct ctdb_ltdb_header
));
359 offset
+= sizeof(struct ctdb_ltdb_header
);
361 if (in
->data
.dsize
> 0) {
362 memcpy(&wire
->data
[offset
], in
->data
.dptr
, in
->data
.dsize
);
366 static int ctdb_rec_data_pull_data_old(uint8_t *buf
, size_t buflen
,
368 struct ctdb_ltdb_header
**header
,
369 TDB_DATA
*key
, TDB_DATA
*data
,
372 struct ctdb_rec_data_wire
*wire
= (struct ctdb_rec_data_wire
*)buf
;
375 if (buflen
< offsetof(struct ctdb_rec_data_wire
, data
)) {
378 if (wire
->keylen
> buflen
|| wire
->datalen
> buflen
) {
381 if (offsetof(struct ctdb_rec_data_wire
, data
) + wire
->keylen
<
382 offsetof(struct ctdb_rec_data_wire
, data
)) {
385 if (offsetof(struct ctdb_rec_data_wire
, data
) +
386 wire
->keylen
+ wire
->datalen
<
387 offsetof(struct ctdb_rec_data_wire
, data
)) {
390 if (buflen
< offsetof(struct ctdb_rec_data_wire
, data
) +
391 wire
->keylen
+ wire
->datalen
) {
395 *reqid
= wire
->reqid
;
397 key
->dsize
= wire
->keylen
;
398 key
->dptr
= wire
->data
;
399 offset
= wire
->keylen
;
401 /* Always set header to NULL. If it is required, exact it using
402 * ctdb_rec_data_extract_header()
406 data
->dsize
= wire
->datalen
;
407 data
->dptr
= &wire
->data
[offset
];
409 *reclen
= offsetof(struct ctdb_rec_data_wire
, data
) +
410 wire
->keylen
+ wire
->datalen
;
415 static int ctdb_rec_data_pull_elems_old(uint8_t *buf
, size_t buflen
,
417 struct ctdb_rec_data
*out
)
420 struct ctdb_ltdb_header
*header
;
425 ret
= ctdb_rec_data_pull_data_old(buf
, buflen
, &reqid
, &header
,
426 &key
, &data
, &reclen
);
434 out
->key
.dsize
= key
.dsize
;
436 out
->key
.dptr
= talloc_memdup(mem_ctx
, key
.dptr
, key
.dsize
);
437 if (out
->key
.dptr
== NULL
) {
442 out
->data
.dsize
= data
.dsize
;
443 if (data
.dsize
> 0) {
444 out
->data
.dptr
= talloc_memdup(mem_ctx
, data
.dptr
, data
.dsize
);
445 if (out
->data
.dptr
== NULL
) {
453 static int ctdb_rec_data_pull_old(uint8_t *buf
, size_t buflen
,
455 struct ctdb_rec_data
**out
)
457 struct ctdb_rec_data
*val
;
460 val
= talloc(mem_ctx
, struct ctdb_rec_data
);
465 ret
= ctdb_rec_data_pull_elems_old(buf
, buflen
, val
, val
);
475 struct ctdb_rec_buffer_wire
{
481 static size_t ctdb_rec_buffer_len_old(struct ctdb_rec_buffer
*in
)
483 return offsetof(struct ctdb_rec_buffer_wire
, data
) + in
->buflen
;
486 static void ctdb_rec_buffer_push_old(struct ctdb_rec_buffer
*in
, uint8_t *buf
)
488 struct ctdb_rec_buffer_wire
*wire
= (struct ctdb_rec_buffer_wire
*)buf
;
490 wire
->db_id
= in
->db_id
;
491 wire
->count
= in
->count
;
492 if (in
->buflen
> 0) {
493 memcpy(wire
->data
, in
->buf
, in
->buflen
);
497 static int ctdb_rec_buffer_pull_old(uint8_t *buf
, size_t buflen
,
499 struct ctdb_rec_buffer
**out
)
501 struct ctdb_rec_buffer
*val
;
502 struct ctdb_rec_buffer_wire
*wire
= (struct ctdb_rec_buffer_wire
*)buf
;
505 if (buflen
< offsetof(struct ctdb_rec_buffer_wire
, data
)) {
509 val
= talloc(mem_ctx
, struct ctdb_rec_buffer
);
514 val
->db_id
= wire
->db_id
;
515 val
->count
= wire
->count
;
517 offset
= offsetof(struct ctdb_rec_buffer_wire
, data
);
518 val
->buflen
= buflen
- offset
;
519 val
->buf
= talloc_memdup(val
, wire
->data
, val
->buflen
);
520 if (val
->buf
== NULL
) {
529 static size_t ctdb_traverse_start_len_old(struct ctdb_traverse_start
*in
)
531 return sizeof(struct ctdb_traverse_start
);
534 static void ctdb_traverse_start_push_old(struct ctdb_traverse_start
*in
,
537 memcpy(buf
, in
, sizeof(struct ctdb_traverse_start
));
540 static int ctdb_traverse_start_pull_old(uint8_t *buf
, size_t buflen
,
542 struct ctdb_traverse_start
**out
)
544 struct ctdb_traverse_start
*val
;
546 if (buflen
< sizeof(struct ctdb_traverse_start
)) {
550 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_traverse_start
));
559 static size_t ctdb_traverse_all_len_old(struct ctdb_traverse_all
*in
)
561 return sizeof(struct ctdb_traverse_all
);
564 static void ctdb_traverse_all_push_old(struct ctdb_traverse_all
*in
,
567 memcpy(buf
, in
, sizeof(struct ctdb_traverse_all
));
570 static int ctdb_traverse_all_pull_old(uint8_t *buf
, size_t buflen
,
572 struct ctdb_traverse_all
**out
)
574 struct ctdb_traverse_all
*val
;
576 if (buflen
< sizeof(struct ctdb_traverse_all
)) {
580 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_traverse_all
));
589 static size_t ctdb_traverse_start_ext_len_old(
590 struct ctdb_traverse_start_ext
*in
)
592 return sizeof(struct ctdb_traverse_start_ext
);
595 static void ctdb_traverse_start_ext_push_old(
596 struct ctdb_traverse_start_ext
*in
, uint8_t *buf
)
598 memcpy(buf
, in
, sizeof(struct ctdb_traverse_start_ext
));
601 static int ctdb_traverse_start_ext_pull_old(uint8_t *buf
, size_t buflen
,
603 struct ctdb_traverse_start_ext
**out
)
605 struct ctdb_traverse_start_ext
*val
;
607 if (buflen
< sizeof(struct ctdb_traverse_start_ext
)) {
611 val
= talloc_memdup(mem_ctx
, buf
,
612 sizeof(struct ctdb_traverse_start_ext
));
621 static size_t ctdb_traverse_all_ext_len_old(struct ctdb_traverse_all_ext
*in
)
623 return sizeof(struct ctdb_traverse_all_ext
);
626 static void ctdb_traverse_all_ext_push_old(struct ctdb_traverse_all_ext
*in
,
629 memcpy(buf
, in
, sizeof(struct ctdb_traverse_all_ext
));
632 static int ctdb_traverse_all_ext_pull_old(uint8_t *buf
, size_t buflen
,
634 struct ctdb_traverse_all_ext
**out
)
636 struct ctdb_traverse_all_ext
*val
;
638 if (buflen
< sizeof(struct ctdb_traverse_all_ext
)) {
642 val
= talloc_memdup(mem_ctx
, buf
,
643 sizeof(struct ctdb_traverse_all_ext
));
652 static size_t ctdb_sock_addr_len_old(ctdb_sock_addr
*in
)
654 return sizeof(ctdb_sock_addr
);
657 static void ctdb_sock_addr_push_old(ctdb_sock_addr
*in
, uint8_t *buf
)
659 memcpy(buf
, in
, sizeof(ctdb_sock_addr
));
662 static int ctdb_sock_addr_pull_elems_old(uint8_t *buf
, size_t buflen
,
666 if (buflen
< sizeof(ctdb_sock_addr
)) {
670 memcpy(out
, buf
, sizeof(ctdb_sock_addr
));
675 static int ctdb_sock_addr_pull_old(uint8_t *buf
, size_t buflen
,
676 TALLOC_CTX
*mem_ctx
, ctdb_sock_addr
**out
)
681 val
= talloc(mem_ctx
, ctdb_sock_addr
);
686 ret
= ctdb_sock_addr_pull_elems_old(buf
, buflen
, val
, val
);
696 static size_t ctdb_connection_len_old(struct ctdb_connection
*in
)
698 return sizeof(struct ctdb_connection
);
701 static void ctdb_connection_push_old(struct ctdb_connection
*in
, uint8_t *buf
)
703 memcpy(buf
, in
, sizeof(struct ctdb_connection
));
706 static int ctdb_connection_pull_elems_old(uint8_t *buf
, size_t buflen
,
708 struct ctdb_connection
*out
)
710 if (buflen
< sizeof(struct ctdb_connection
)) {
714 memcpy(out
, buf
, sizeof(struct ctdb_connection
));
719 static int ctdb_connection_pull_old(uint8_t *buf
, size_t buflen
,
721 struct ctdb_connection
**out
)
723 struct ctdb_connection
*val
;
726 val
= talloc(mem_ctx
, struct ctdb_connection
);
731 ret
= ctdb_connection_pull_elems_old(buf
, buflen
, val
, val
);
741 struct ctdb_tunable_wire
{
747 static size_t ctdb_tunable_len_old(struct ctdb_tunable
*in
)
749 return offsetof(struct ctdb_tunable_wire
, name
) +
750 strlen(in
->name
) + 1;
753 static void ctdb_tunable_push_old(struct ctdb_tunable
*in
, uint8_t *buf
)
755 struct ctdb_tunable_wire
*wire
= (struct ctdb_tunable_wire
*)buf
;
757 wire
->value
= in
->value
;
758 wire
->length
= strlen(in
->name
) + 1;
759 memcpy(wire
->name
, in
->name
, wire
->length
);
762 static int ctdb_tunable_pull_old(uint8_t *buf
, size_t buflen
,
764 struct ctdb_tunable
**out
)
766 struct ctdb_tunable
*val
;
767 struct ctdb_tunable_wire
*wire
= (struct ctdb_tunable_wire
*)buf
;
769 if (buflen
< offsetof(struct ctdb_tunable_wire
, name
)) {
772 if (wire
->length
> buflen
) {
775 if (offsetof(struct ctdb_tunable_wire
, name
) + wire
->length
<
776 offsetof(struct ctdb_tunable_wire
, name
)) {
779 if (buflen
< offsetof(struct ctdb_tunable_wire
, name
) + wire
->length
) {
783 val
= talloc(mem_ctx
, struct ctdb_tunable
);
788 val
->value
= wire
->value
;
789 val
->name
= talloc_memdup(val
, wire
->name
, wire
->length
);
790 if (val
->name
== NULL
) {
799 static size_t ctdb_node_flag_change_len_old(struct ctdb_node_flag_change
*in
)
801 return sizeof(struct ctdb_node_flag_change
);
804 static void ctdb_node_flag_change_push_old(struct ctdb_node_flag_change
*in
,
807 memcpy(buf
, in
, sizeof(struct ctdb_node_flag_change
));
810 static int ctdb_node_flag_change_pull_old(uint8_t *buf
, size_t buflen
,
812 struct ctdb_node_flag_change
**out
)
814 struct ctdb_node_flag_change
*val
;
816 if (buflen
< sizeof(struct ctdb_node_flag_change
)) {
820 val
= talloc_memdup(mem_ctx
, buf
,
821 sizeof(struct ctdb_node_flag_change
));
830 struct ctdb_var_list_wire
{
835 static size_t ctdb_var_list_len_old(struct ctdb_var_list
*in
)
838 size_t len
= sizeof(uint32_t);
840 for (i
=0; i
<in
->count
; i
++) {
841 len
+= strlen(in
->var
[i
]) + 1;
846 static void ctdb_var_list_push_old(struct ctdb_var_list
*in
, uint8_t *buf
)
848 struct ctdb_var_list_wire
*wire
= (struct ctdb_var_list_wire
*)buf
;
853 n
= sprintf(wire
->list_str
, "%s", in
->var
[0]);
856 for (i
=1; i
<in
->count
; i
++) {
857 n
= sprintf(&wire
->list_str
[offset
], ":%s", in
->var
[i
]);
860 wire
->length
= offset
+ 1;
863 static int ctdb_var_list_pull_old(uint8_t *buf
, size_t buflen
,
865 struct ctdb_var_list
**out
)
867 struct ctdb_var_list
*val
= NULL
;
868 struct ctdb_var_list_wire
*wire
= (struct ctdb_var_list_wire
*)buf
;
869 char *str
, *s
, *tok
, *ptr
;
872 if (buflen
< sizeof(uint32_t)) {
875 if (wire
->length
> buflen
) {
878 if (sizeof(uint32_t) + wire
->length
< sizeof(uint32_t)) {
881 if (buflen
< sizeof(uint32_t) + wire
->length
) {
885 str
= talloc_strndup(mem_ctx
, (char *)wire
->list_str
, wire
->length
);
890 val
= talloc_zero(mem_ctx
, struct ctdb_var_list
);
896 while ((tok
= strtok_r(s
, ":", &ptr
)) != NULL
) {
898 list
= talloc_realloc(val
, val
->var
, const char *,
905 val
->var
[val
->count
] = talloc_strdup(val
, tok
);
906 if (val
->var
[val
->count
] == NULL
) {
922 static size_t ctdb_tunable_list_len_old(struct ctdb_tunable_list
*in
)
924 return sizeof(struct ctdb_tunable_list
);
927 static void ctdb_tunable_list_push_old(struct ctdb_tunable_list
*in
,
930 memcpy(buf
, in
, sizeof(struct ctdb_tunable_list
));
933 static int ctdb_tunable_list_pull_old(uint8_t *buf
, size_t buflen
,
935 struct ctdb_tunable_list
**out
)
937 struct ctdb_tunable_list
*val
;
939 if (buflen
< sizeof(struct ctdb_tunable_list
)) {
943 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_tunable_list
));
952 struct ctdb_tickle_list_wire
{
955 struct ctdb_connection conn
[1];
958 static size_t ctdb_tickle_list_len_old(struct ctdb_tickle_list
*in
)
960 return offsetof(struct ctdb_tickle_list
, conn
) +
961 in
->num
* sizeof(struct ctdb_connection
);
964 static void ctdb_tickle_list_push_old(struct ctdb_tickle_list
*in
,
967 struct ctdb_tickle_list_wire
*wire
=
968 (struct ctdb_tickle_list_wire
*)buf
;
972 memcpy(&wire
->addr
, &in
->addr
, sizeof(ctdb_sock_addr
));
975 offset
= offsetof(struct ctdb_tickle_list_wire
, conn
);
976 for (i
=0; i
<in
->num
; i
++) {
977 ctdb_connection_push_old(&in
->conn
[i
], &buf
[offset
]);
978 offset
+= ctdb_connection_len_old(&in
->conn
[i
]);
982 static int ctdb_tickle_list_pull_old(uint8_t *buf
, size_t buflen
,
984 struct ctdb_tickle_list
**out
)
986 struct ctdb_tickle_list
*val
;
987 struct ctdb_tickle_list_wire
*wire
=
988 (struct ctdb_tickle_list_wire
*)buf
;
992 if (buflen
< offsetof(struct ctdb_tickle_list_wire
, conn
)) {
995 if (wire
->num
> buflen
/ sizeof(struct ctdb_connection
)) {
998 if (offsetof(struct ctdb_tickle_list_wire
, conn
) +
999 wire
->num
* sizeof(struct ctdb_connection
) <
1000 offsetof(struct ctdb_tickle_list_wire
, conn
)) {
1003 if (buflen
< offsetof(struct ctdb_tickle_list_wire
, conn
) +
1004 wire
->num
* sizeof(struct ctdb_connection
)) {
1008 val
= talloc(mem_ctx
, struct ctdb_tickle_list
);
1013 offset
= offsetof(struct ctdb_tickle_list
, conn
);
1014 memcpy(val
, wire
, offset
);
1016 val
->conn
= talloc_array(val
, struct ctdb_connection
, wire
->num
);
1017 if (val
->conn
== NULL
) {
1022 for (i
=0; i
<wire
->num
; i
++) {
1023 ret
= ctdb_connection_pull_elems_old(&buf
[offset
],
1031 offset
+= ctdb_connection_len_old(&val
->conn
[i
]);
1038 struct ctdb_addr_info_wire
{
1039 ctdb_sock_addr addr
;
1045 static size_t ctdb_addr_info_len_old(struct ctdb_addr_info
*in
)
1049 len
= offsetof(struct ctdb_addr_info_wire
, iface
);
1050 if (in
->iface
!= NULL
) {
1051 len
+= strlen(in
->iface
)+1;
1057 static void ctdb_addr_info_push_old(struct ctdb_addr_info
*in
, uint8_t *buf
)
1059 struct ctdb_addr_info_wire
*wire
= (struct ctdb_addr_info_wire
*)buf
;
1061 wire
->addr
= in
->addr
;
1062 wire
->mask
= in
->mask
;
1063 if (in
->iface
== NULL
) {
1066 wire
->len
= strlen(in
->iface
)+1;
1067 memcpy(wire
->iface
, in
->iface
, wire
->len
);
1071 static int ctdb_addr_info_pull_old(uint8_t *buf
, size_t buflen
,
1072 TALLOC_CTX
*mem_ctx
,
1073 struct ctdb_addr_info
**out
)
1075 struct ctdb_addr_info
*val
;
1076 struct ctdb_addr_info_wire
*wire
= (struct ctdb_addr_info_wire
*)buf
;
1078 if (buflen
< offsetof(struct ctdb_addr_info_wire
, iface
)) {
1081 if (wire
->len
> buflen
) {
1084 if (offsetof(struct ctdb_addr_info_wire
, iface
) + wire
->len
<
1085 offsetof(struct ctdb_addr_info_wire
, iface
)) {
1088 if (buflen
< offsetof(struct ctdb_addr_info_wire
, iface
) + wire
->len
) {
1092 val
= talloc(mem_ctx
, struct ctdb_addr_info
);
1097 val
->addr
= wire
->addr
;
1098 val
->mask
= wire
->mask
;
1100 if (wire
->len
== 0) {
1103 val
->iface
= talloc_strndup(val
, wire
->iface
, wire
->len
);
1104 if (val
->iface
== NULL
) {
1114 static size_t ctdb_transdb_len_old(struct ctdb_transdb
*in
)
1116 return sizeof(struct ctdb_transdb
);
1119 static void ctdb_transdb_push_old(struct ctdb_transdb
*in
, uint8_t *buf
)
1121 memcpy(buf
, in
, sizeof(struct ctdb_transdb
));
1124 static int ctdb_transdb_pull_old(uint8_t *buf
, size_t buflen
,
1125 TALLOC_CTX
*mem_ctx
,
1126 struct ctdb_transdb
**out
)
1128 struct ctdb_transdb
*val
;
1130 if (buflen
< sizeof(struct ctdb_transdb
)) {
1134 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_transdb
));
1143 static size_t ctdb_uptime_len_old(struct ctdb_uptime
*in
)
1145 return sizeof(struct ctdb_uptime
);
1148 static void ctdb_uptime_push_old(struct ctdb_uptime
*in
, uint8_t *buf
)
1150 memcpy(buf
, in
, sizeof(struct ctdb_uptime
));
1153 static int ctdb_uptime_pull_old(uint8_t *buf
, size_t buflen
,
1154 TALLOC_CTX
*mem_ctx
, struct ctdb_uptime
**out
)
1156 struct ctdb_uptime
*val
;
1158 if (buflen
< sizeof(struct ctdb_uptime
)) {
1162 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_uptime
));
1171 static size_t ctdb_public_ip_len_old(struct ctdb_public_ip
*in
)
1173 return sizeof(struct ctdb_public_ip
);
1176 static void ctdb_public_ip_push_old(struct ctdb_public_ip
*in
, uint8_t *buf
)
1178 memcpy(buf
, in
, sizeof(struct ctdb_public_ip
));
1181 static int ctdb_public_ip_pull_elems_old(uint8_t *buf
, size_t buflen
,
1182 TALLOC_CTX
*mem_ctx
,
1183 struct ctdb_public_ip
*out
)
1185 if (buflen
< sizeof(struct ctdb_public_ip
)) {
1189 memcpy(out
, buf
, sizeof(struct ctdb_public_ip
));
1194 static int ctdb_public_ip_pull_old(uint8_t *buf
, size_t buflen
,
1195 TALLOC_CTX
*mem_ctx
,
1196 struct ctdb_public_ip
**out
)
1198 struct ctdb_public_ip
*val
;
1201 val
= talloc(mem_ctx
, struct ctdb_public_ip
);
1206 ret
= ctdb_public_ip_pull_elems_old(buf
, buflen
, val
, val
);
1216 struct ctdb_public_ip_list_wire
{
1218 struct ctdb_public_ip ip
[1];
1221 static size_t ctdb_public_ip_list_len_old(struct ctdb_public_ip_list
*in
)
1226 len
= sizeof(uint32_t);
1227 for (i
=0; i
<in
->num
; i
++) {
1228 len
+= ctdb_public_ip_len_old(&in
->ip
[i
]);
1233 static void ctdb_public_ip_list_push_old(struct ctdb_public_ip_list
*in
,
1236 struct ctdb_public_ip_list_wire
*wire
=
1237 (struct ctdb_public_ip_list_wire
*)buf
;
1241 wire
->num
= in
->num
;
1243 offset
= offsetof(struct ctdb_public_ip_list_wire
, ip
);
1244 for (i
=0; i
<in
->num
; i
++) {
1245 ctdb_public_ip_push_old(&in
->ip
[i
], &buf
[offset
]);
1246 offset
+= ctdb_public_ip_len_old(&in
->ip
[i
]);
1250 static int ctdb_public_ip_list_pull_old(uint8_t *buf
, size_t buflen
,
1251 TALLOC_CTX
*mem_ctx
,
1252 struct ctdb_public_ip_list
**out
)
1254 struct ctdb_public_ip_list
*val
;
1255 struct ctdb_public_ip_list_wire
*wire
=
1256 (struct ctdb_public_ip_list_wire
*)buf
;
1261 if (buflen
< sizeof(uint32_t)) {
1264 if (wire
->num
> buflen
/ sizeof(struct ctdb_public_ip
)) {
1267 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_public_ip
) <
1271 if (buflen
< sizeof(uint32_t) +
1272 wire
->num
* sizeof(struct ctdb_public_ip
)) {
1276 val
= talloc(mem_ctx
, struct ctdb_public_ip_list
);
1281 val
->num
= wire
->num
;
1282 if (wire
->num
== 0) {
1287 val
->ip
= talloc_array(val
, struct ctdb_public_ip
, wire
->num
);
1288 if (val
->ip
== NULL
) {
1293 offset
= offsetof(struct ctdb_public_ip_list_wire
, ip
);
1294 for (i
=0; i
<wire
->num
; i
++) {
1295 ret
= ctdb_public_ip_pull_elems_old(&buf
[offset
],
1303 offset
+= ctdb_public_ip_len_old(&val
->ip
[i
]);
1310 static size_t ctdb_node_and_flags_len_old(struct ctdb_node_and_flags
*in
)
1312 return sizeof(struct ctdb_node_and_flags
);
1315 static void ctdb_node_and_flags_push_old(struct ctdb_node_and_flags
*in
,
1318 memcpy(buf
, in
, sizeof(struct ctdb_node_and_flags
));
1321 static int ctdb_node_and_flags_pull_elems_old(TALLOC_CTX
*mem_ctx
,
1322 uint8_t *buf
, size_t buflen
,
1323 struct ctdb_node_and_flags
*out
)
1325 if (buflen
< sizeof(struct ctdb_node_and_flags
)) {
1329 memcpy(out
, buf
, sizeof(struct ctdb_node_and_flags
));
1334 static int ctdb_node_and_flags_pull_old(uint8_t *buf
, size_t buflen
,
1335 TALLOC_CTX
*mem_ctx
,
1336 struct ctdb_node_and_flags
**out
)
1338 struct ctdb_node_and_flags
*val
;
1341 val
= talloc(mem_ctx
, struct ctdb_node_and_flags
);
1346 ret
= ctdb_node_and_flags_pull_elems_old(val
, buf
, buflen
, val
);
1356 struct ctdb_node_map_wire
{
1358 struct ctdb_node_and_flags node
[1];
1361 static size_t ctdb_node_map_len_old(struct ctdb_node_map
*in
)
1363 return sizeof(uint32_t) +
1364 in
->num
* sizeof(struct ctdb_node_and_flags
);
1367 static void ctdb_node_map_push_old(struct ctdb_node_map
*in
, uint8_t *buf
)
1369 struct ctdb_node_map_wire
*wire
= (struct ctdb_node_map_wire
*)buf
;
1373 wire
->num
= in
->num
;
1375 offset
= offsetof(struct ctdb_node_map_wire
, node
);
1376 for (i
=0; i
<in
->num
; i
++) {
1377 ctdb_node_and_flags_push_old(&in
->node
[i
], &buf
[offset
]);
1378 offset
+= ctdb_node_and_flags_len_old(&in
->node
[i
]);
1382 static int ctdb_node_map_pull_old(uint8_t *buf
, size_t buflen
,
1383 TALLOC_CTX
*mem_ctx
,
1384 struct ctdb_node_map
**out
)
1386 struct ctdb_node_map
*val
;
1387 struct ctdb_node_map_wire
*wire
= (struct ctdb_node_map_wire
*)buf
;
1392 if (buflen
< sizeof(uint32_t)) {
1395 if (wire
->num
> buflen
/ sizeof(struct ctdb_node_and_flags
)) {
1398 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_node_and_flags
) <
1402 if (buflen
< sizeof(uint32_t) +
1403 wire
->num
* sizeof(struct ctdb_node_and_flags
)) {
1407 val
= talloc(mem_ctx
, struct ctdb_node_map
);
1412 val
->num
= wire
->num
;
1413 val
->node
= talloc_array(val
, struct ctdb_node_and_flags
, wire
->num
);
1414 if (val
->node
== NULL
) {
1419 offset
= offsetof(struct ctdb_node_map_wire
, node
);
1420 for (i
=0; i
<wire
->num
; i
++) {
1421 ret
= ctdb_node_and_flags_pull_elems_old(val
->node
,
1429 offset
+= ctdb_node_and_flags_len_old(&val
->node
[i
]);
1436 static size_t ctdb_script_len_old(struct ctdb_script
*in
)
1438 return sizeof(struct ctdb_script
);
1441 static void ctdb_script_push_old(struct ctdb_script
*in
, uint8_t *buf
)
1443 memcpy(buf
, in
, sizeof(struct ctdb_script
));
1446 static int ctdb_script_pull_elems_old(uint8_t *buf
, size_t buflen
,
1447 TALLOC_CTX
*mem_ctx
,
1448 struct ctdb_script
*out
)
1450 if (buflen
< sizeof(struct ctdb_script
)) {
1454 memcpy(out
, buf
, sizeof(struct ctdb_script
));
1459 static int ctdb_script_pull_old(uint8_t *buf
, size_t buflen
,
1460 TALLOC_CTX
*mem_ctx
, struct ctdb_script
**out
)
1462 struct ctdb_script
*val
;
1465 val
= talloc(mem_ctx
, struct ctdb_script
);
1470 ret
= ctdb_script_pull_elems_old(buf
, buflen
, val
, val
);
1480 struct ctdb_script_list_wire
{
1481 uint32_t num_scripts
;
1482 struct ctdb_script script
[1];
1485 static size_t ctdb_script_list_len_old(struct ctdb_script_list
*in
)
1494 len
= offsetof(struct ctdb_script_list_wire
, script
);
1495 for (i
=0; i
<in
->num_scripts
; i
++) {
1496 len
+= ctdb_script_len_old(&in
->script
[i
]);
1501 static void ctdb_script_list_push_old(struct ctdb_script_list
*in
,
1504 struct ctdb_script_list_wire
*wire
=
1505 (struct ctdb_script_list_wire
*)buf
;
1513 wire
->num_scripts
= in
->num_scripts
;
1515 offset
= offsetof(struct ctdb_script_list_wire
, script
);
1516 for (i
=0; i
<in
->num_scripts
; i
++) {
1517 ctdb_script_push_old(&in
->script
[i
], &buf
[offset
]);
1518 offset
+= ctdb_script_len_old(&in
->script
[i
]);
1522 static int ctdb_script_list_pull_old(uint8_t *buf
, size_t buflen
,
1523 TALLOC_CTX
*mem_ctx
,
1524 struct ctdb_script_list
**out
)
1526 struct ctdb_script_list
*val
;
1527 struct ctdb_script_list_wire
*wire
=
1528 (struct ctdb_script_list_wire
*)buf
;
1533 /* If event scripts have never been run, the result will be NULL */
1539 offset
= offsetof(struct ctdb_script_list_wire
, script
);
1541 if (buflen
< offset
) {
1544 if (wire
->num_scripts
> buflen
/ sizeof(struct ctdb_script
)) {
1547 if (offset
+ wire
->num_scripts
* sizeof(struct ctdb_script
) < offset
) {
1550 if (buflen
< offset
+ wire
->num_scripts
* sizeof(struct ctdb_script
)) {
1554 val
= talloc(mem_ctx
, struct ctdb_script_list
);
1560 val
->num_scripts
= wire
->num_scripts
;
1561 val
->script
= talloc_array(val
, struct ctdb_script
, wire
->num_scripts
);
1562 if (val
->script
== NULL
) {
1567 for (i
=0; i
<wire
->num_scripts
; i
++) {
1568 ret
= ctdb_script_pull_elems_old(&buf
[offset
], buflen
-offset
,
1575 offset
+= ctdb_script_len_old(&val
->script
[i
]);
1582 static size_t ctdb_ban_state_len_old(struct ctdb_ban_state
*in
)
1584 return sizeof(struct ctdb_ban_state
);
1587 static void ctdb_ban_state_push_old(struct ctdb_ban_state
*in
, uint8_t *buf
)
1589 memcpy(buf
, in
, sizeof(struct ctdb_ban_state
));
1592 static int ctdb_ban_state_pull_old(uint8_t *buf
, size_t buflen
,
1593 TALLOC_CTX
*mem_ctx
,
1594 struct ctdb_ban_state
**out
)
1596 struct ctdb_ban_state
*val
;
1598 if (buflen
< sizeof(struct ctdb_ban_state
)) {
1602 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_ban_state
));
1611 struct ctdb_notify_data_wire
{
1617 static size_t ctdb_notify_data_len_old(struct ctdb_notify_data
*in
)
1619 return offsetof(struct ctdb_notify_data_wire
, data
) +
1623 static void ctdb_notify_data_push_old(struct ctdb_notify_data
*in
,
1626 struct ctdb_notify_data_wire
*wire
=
1627 (struct ctdb_notify_data_wire
*)buf
;
1629 wire
->srvid
= in
->srvid
;
1630 wire
->len
= in
->data
.dsize
;
1631 memcpy(wire
->data
, in
->data
.dptr
, in
->data
.dsize
);
1634 static int ctdb_notify_data_pull_old(uint8_t *buf
, size_t buflen
,
1635 TALLOC_CTX
*mem_ctx
,
1636 struct ctdb_notify_data
**out
)
1638 struct ctdb_notify_data
*val
;
1639 struct ctdb_notify_data_wire
*wire
=
1640 (struct ctdb_notify_data_wire
*)buf
;
1642 if (buflen
< offsetof(struct ctdb_notify_data_wire
, data
)) {
1645 if (wire
->len
> buflen
) {
1648 if (offsetof(struct ctdb_notify_data_wire
, data
) + wire
->len
<
1649 offsetof(struct ctdb_notify_data_wire
, data
)) {
1652 if (buflen
< offsetof(struct ctdb_notify_data_wire
, data
) + wire
->len
) {
1656 val
= talloc(mem_ctx
, struct ctdb_notify_data
);
1661 val
->srvid
= wire
->srvid
;
1662 val
->data
.dsize
= wire
->len
;
1663 val
->data
.dptr
= talloc_memdup(val
, wire
->data
, wire
->len
);
1664 if (val
->data
.dptr
== NULL
) {
1673 static size_t ctdb_iface_len_old(struct ctdb_iface
*in
)
1675 return sizeof(struct ctdb_iface
);
1678 static void ctdb_iface_push_old(struct ctdb_iface
*in
, uint8_t *buf
)
1680 memcpy(buf
, in
, sizeof(struct ctdb_iface
));
1683 static int ctdb_iface_pull_elems_old(uint8_t *buf
, size_t buflen
,
1684 TALLOC_CTX
*mem_ctx
,
1685 struct ctdb_iface
*out
)
1687 if (buflen
< sizeof(struct ctdb_iface
)) {
1691 memcpy(out
, buf
, sizeof(struct ctdb_iface
));
1696 static int ctdb_iface_pull_old(uint8_t *buf
, size_t buflen
,
1697 TALLOC_CTX
*mem_ctx
, struct ctdb_iface
**out
)
1699 struct ctdb_iface
*val
;
1702 val
= talloc(mem_ctx
, struct ctdb_iface
);
1707 ret
= ctdb_iface_pull_elems_old(buf
, buflen
, val
, val
);
1717 struct ctdb_iface_list_wire
{
1719 struct ctdb_iface iface
[1];
1722 static size_t ctdb_iface_list_len_old(struct ctdb_iface_list
*in
)
1724 return sizeof(uint32_t) +
1725 in
->num
* sizeof(struct ctdb_iface
);
1728 static void ctdb_iface_list_push_old(struct ctdb_iface_list
*in
, uint8_t *buf
)
1730 struct ctdb_iface_list_wire
*wire
=
1731 (struct ctdb_iface_list_wire
*)buf
;
1733 wire
->num
= in
->num
;
1734 memcpy(wire
->iface
, in
->iface
, in
->num
* sizeof(struct ctdb_iface
));
1737 static int ctdb_iface_list_pull_old(uint8_t *buf
, size_t buflen
,
1738 TALLOC_CTX
*mem_ctx
,
1739 struct ctdb_iface_list
**out
)
1741 struct ctdb_iface_list
*val
;
1742 struct ctdb_iface_list_wire
*wire
=
1743 (struct ctdb_iface_list_wire
*)buf
;
1745 if (buflen
< sizeof(uint32_t)) {
1748 if (wire
->num
> buflen
/ sizeof(struct ctdb_iface
)) {
1751 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_iface
) <
1755 if (buflen
< sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_iface
)) {
1759 val
= talloc(mem_ctx
, struct ctdb_iface_list
);
1764 val
->num
= wire
->num
;
1765 val
->iface
= talloc_array(val
, struct ctdb_iface
, wire
->num
);
1766 if (val
->iface
== NULL
) {
1771 memcpy(val
->iface
, wire
->iface
, wire
->num
* sizeof(struct ctdb_iface
));
1777 struct ctdb_public_ip_info_wire
{
1778 struct ctdb_public_ip ip
;
1779 uint32_t active_idx
;
1781 struct ctdb_iface ifaces
[1];
1784 static size_t ctdb_public_ip_info_len_old(struct ctdb_public_ip_info
*in
)
1786 return offsetof(struct ctdb_public_ip_info_wire
, num
) +
1787 ctdb_iface_list_len_old(in
->ifaces
);
1790 static void ctdb_public_ip_info_push_old(struct ctdb_public_ip_info
*in
,
1793 struct ctdb_public_ip_info_wire
*wire
=
1794 (struct ctdb_public_ip_info_wire
*)buf
;
1797 offset
= offsetof(struct ctdb_public_ip_info_wire
, num
);
1798 memcpy(wire
, in
, offset
);
1799 wire
->num
= in
->ifaces
->num
;
1800 memcpy(wire
->ifaces
, in
->ifaces
->iface
,
1801 in
->ifaces
->num
* sizeof(struct ctdb_iface
));
1804 static int ctdb_public_ip_info_pull_old(uint8_t *buf
, size_t buflen
,
1805 TALLOC_CTX
*mem_ctx
,
1806 struct ctdb_public_ip_info
**out
)
1808 struct ctdb_public_ip_info
*val
;
1809 struct ctdb_public_ip_info_wire
*wire
=
1810 (struct ctdb_public_ip_info_wire
*)buf
;
1812 if (buflen
< offsetof(struct ctdb_public_ip_info_wire
, ifaces
)) {
1815 if (wire
->num
> buflen
/ sizeof(struct ctdb_iface
)) {
1818 if (offsetof(struct ctdb_public_ip_info_wire
, ifaces
) +
1819 wire
->num
* sizeof(struct ctdb_iface
) <
1820 offsetof(struct ctdb_public_ip_info_wire
, ifaces
)) {
1823 if (buflen
< offsetof(struct ctdb_public_ip_info_wire
, ifaces
) +
1824 wire
->num
* sizeof(struct ctdb_iface
)) {
1828 val
= talloc(mem_ctx
, struct ctdb_public_ip_info
);
1833 memcpy(val
, wire
, offsetof(struct ctdb_public_ip_info_wire
, num
));
1835 val
->ifaces
= talloc(val
, struct ctdb_iface_list
);
1836 if (val
->ifaces
== NULL
) {
1841 val
->ifaces
->num
= wire
->num
;
1842 val
->ifaces
->iface
= talloc_array(val
->ifaces
, struct ctdb_iface
,
1844 if (val
->ifaces
->iface
== NULL
) {
1849 memcpy(val
->ifaces
->iface
, wire
->ifaces
,
1850 wire
->num
* sizeof(struct ctdb_iface
));
1856 struct ctdb_statistics_list_wire
{
1858 struct ctdb_statistics stats
[1];
1861 static size_t ctdb_statistics_list_len_old(struct ctdb_statistics_list
*in
)
1863 return offsetof(struct ctdb_statistics_list_wire
, stats
) +
1864 in
->num
* sizeof(struct ctdb_statistics
);
1867 static void ctdb_statistics_list_push_old(struct ctdb_statistics_list
*in
,
1870 struct ctdb_statistics_list_wire
*wire
=
1871 (struct ctdb_statistics_list_wire
*)buf
;
1873 wire
->num
= in
->num
;
1874 memcpy(wire
->stats
, in
->stats
,
1875 in
->num
* sizeof(struct ctdb_statistics
));
1878 static int ctdb_statistics_list_pull_old(uint8_t *buf
, size_t buflen
,
1879 TALLOC_CTX
*mem_ctx
,
1880 struct ctdb_statistics_list
**out
)
1882 struct ctdb_statistics_list
*val
;
1883 struct ctdb_statistics_list_wire
*wire
=
1884 (struct ctdb_statistics_list_wire
*)buf
;
1886 if (buflen
< offsetof(struct ctdb_statistics_list_wire
, stats
)) {
1889 if (wire
->num
> buflen
/ sizeof(struct ctdb_statistics
)) {
1892 if (offsetof(struct ctdb_statistics_list_wire
, stats
) +
1893 wire
->num
* sizeof(struct ctdb_statistics
) <
1894 offsetof(struct ctdb_statistics_list_wire
, stats
)) {
1897 if (buflen
< offsetof(struct ctdb_statistics_list_wire
, stats
) +
1898 wire
->num
* sizeof(struct ctdb_statistics
)) {
1902 val
= talloc(mem_ctx
, struct ctdb_statistics_list
);
1907 val
->num
= wire
->num
;
1909 val
->stats
= talloc_array(val
, struct ctdb_statistics
, wire
->num
);
1910 if (val
->stats
== NULL
) {
1915 memcpy(val
->stats
, wire
->stats
,
1916 wire
->num
* sizeof(struct ctdb_statistics
));
1922 struct ctdb_key_data_wire
{
1924 struct ctdb_ltdb_header header
;
1929 static size_t ctdb_key_data_len_old(struct ctdb_key_data
*in
)
1931 return offsetof(struct ctdb_key_data_wire
, key
) + in
->key
.dsize
;
1934 static void ctdb_key_data_push_old(struct ctdb_key_data
*in
, uint8_t *buf
)
1936 struct ctdb_key_data_wire
*wire
= (struct ctdb_key_data_wire
*)buf
;
1938 memcpy(wire
, in
, offsetof(struct ctdb_key_data
, key
));
1939 wire
->keylen
= in
->key
.dsize
;
1940 memcpy(wire
->key
, in
->key
.dptr
, in
->key
.dsize
);
1943 static int ctdb_key_data_pull_old(uint8_t *buf
, size_t buflen
,
1944 TALLOC_CTX
*mem_ctx
,
1945 struct ctdb_key_data
**out
)
1947 struct ctdb_key_data
*val
;
1948 struct ctdb_key_data_wire
*wire
= (struct ctdb_key_data_wire
*)buf
;
1950 if (buflen
< offsetof(struct ctdb_key_data_wire
, key
)) {
1953 if (wire
->keylen
> buflen
) {
1956 if (offsetof(struct ctdb_key_data_wire
, key
) + wire
->keylen
<
1957 offsetof(struct ctdb_key_data_wire
, key
)) {
1960 if (buflen
< offsetof(struct ctdb_key_data_wire
, key
) + wire
->keylen
) {
1964 val
= talloc(mem_ctx
, struct ctdb_key_data
);
1969 memcpy(val
, wire
, offsetof(struct ctdb_key_data
, key
));
1971 val
->key
.dsize
= wire
->keylen
;
1972 val
->key
.dptr
= talloc_memdup(val
, wire
->key
, wire
->keylen
);
1973 if (val
->key
.dptr
== NULL
) {
1982 struct ctdb_db_statistics_wire
{
1983 struct ctdb_db_statistics dbstats
;
1984 char hot_keys_wire
[1];
1987 static size_t ctdb_db_statistics_len_old(struct ctdb_db_statistics
*in
)
1992 len
= sizeof(struct ctdb_db_statistics
);
1993 for (i
=0; i
<MAX_HOT_KEYS
; i
++) {
1994 len
+= in
->hot_keys
[i
].key
.dsize
;
1999 static void ctdb_db_statistics_push_old(struct ctdb_db_statistics
*in
,
2002 struct ctdb_db_statistics_wire
*wire
=
2003 (struct ctdb_db_statistics_wire
*)buf
;
2007 in
->num_hot_keys
= MAX_HOT_KEYS
;
2008 memcpy(wire
, in
, sizeof(struct ctdb_db_statistics
));
2011 for (i
=0; i
<MAX_HOT_KEYS
; i
++) {
2012 memcpy(&wire
->hot_keys_wire
[offset
],
2013 in
->hot_keys
[i
].key
.dptr
,
2014 in
->hot_keys
[i
].key
.dsize
);
2015 offset
+= in
->hot_keys
[i
].key
.dsize
;
2019 static int ctdb_db_statistics_pull_old(uint8_t *buf
, size_t buflen
,
2020 TALLOC_CTX
*mem_ctx
,
2021 struct ctdb_db_statistics
**out
)
2023 struct ctdb_db_statistics
*val
;
2024 struct ctdb_db_statistics_wire
*wire
=
2025 (struct ctdb_db_statistics_wire
*)buf
;
2029 if (buflen
< sizeof(struct ctdb_db_statistics
)) {
2034 for (i
=0; i
<wire
->dbstats
.num_hot_keys
; i
++) {
2035 if (wire
->dbstats
.hot_keys
[i
].key
.dsize
> buflen
) {
2038 if (offset
+ wire
->dbstats
.hot_keys
[i
].key
.dsize
< offset
) {
2041 offset
+= wire
->dbstats
.hot_keys
[i
].key
.dsize
;
2042 if (offset
> buflen
) {
2046 if (sizeof(struct ctdb_db_statistics
) + offset
<
2047 sizeof(struct ctdb_db_statistics
)) {
2050 if (buflen
< sizeof(struct ctdb_db_statistics
) + offset
) {
2054 val
= talloc(mem_ctx
, struct ctdb_db_statistics
);
2059 memcpy(val
, wire
, sizeof(struct ctdb_db_statistics
));
2062 for (i
=0; i
<wire
->dbstats
.num_hot_keys
; i
++) {
2066 key_size
= val
->hot_keys
[i
].key
.dsize
;
2067 ptr
= talloc_memdup(mem_ctx
, &wire
->hot_keys_wire
[offset
],
2073 val
->hot_keys
[i
].key
.dptr
= ptr
;
2081 static size_t ctdb_election_message_len_old(struct ctdb_election_message
*in
)
2083 return sizeof(struct ctdb_election_message
);
2086 static void ctdb_election_message_push_old(struct ctdb_election_message
*in
,
2089 memcpy(buf
, in
, sizeof(struct ctdb_election_message
));
2092 static int ctdb_election_message_pull_old(uint8_t *buf
, size_t buflen
,
2093 TALLOC_CTX
*mem_ctx
,
2094 struct ctdb_election_message
**out
)
2096 struct ctdb_election_message
*val
;
2098 if (buflen
< sizeof(struct ctdb_election_message
)) {
2102 val
= talloc_memdup(mem_ctx
, buf
,
2103 sizeof(struct ctdb_election_message
));
2112 static size_t ctdb_srvid_message_len_old(struct ctdb_srvid_message
*in
)
2114 return sizeof(struct ctdb_srvid_message
);
2117 static void ctdb_srvid_message_push_old(struct ctdb_srvid_message
*in
,
2120 memcpy(buf
, in
, sizeof(struct ctdb_srvid_message
));
2123 static int ctdb_srvid_message_pull_old(uint8_t *buf
, size_t buflen
,
2124 TALLOC_CTX
*mem_ctx
,
2125 struct ctdb_srvid_message
**out
)
2127 struct ctdb_srvid_message
*val
;
2129 if (buflen
< sizeof(struct ctdb_srvid_message
)) {
2133 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_srvid_message
));
2142 static size_t ctdb_disable_message_len_old(struct ctdb_disable_message
*in
)
2144 return sizeof(struct ctdb_disable_message
);
2147 static void ctdb_disable_message_push_old(struct ctdb_disable_message
*in
,
2150 memcpy(buf
, in
, sizeof(struct ctdb_disable_message
));
2153 static int ctdb_disable_message_pull_old(uint8_t *buf
, size_t buflen
,
2154 TALLOC_CTX
*mem_ctx
,
2155 struct ctdb_disable_message
**out
)
2157 struct ctdb_disable_message
*val
;
2159 if (buflen
< sizeof(struct ctdb_disable_message
)) {
2163 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_disable_message
));
2172 static size_t ctdb_server_id_len_old(struct ctdb_server_id
*in
)
2174 return sizeof(struct ctdb_server_id
);
2177 static void ctdb_server_id_push_old(struct ctdb_server_id
*in
, uint8_t *buf
)
2179 memcpy(buf
, in
, sizeof(struct ctdb_server_id
));
2182 static int ctdb_server_id_pull_old(uint8_t *buf
, size_t buflen
,
2183 struct ctdb_server_id
*out
)
2185 if (buflen
< sizeof(struct ctdb_server_id
)) {
2189 memcpy(out
, buf
, sizeof(struct ctdb_server_id
));
2193 static size_t ctdb_g_lock_len_old(struct ctdb_g_lock
*in
)
2195 return sizeof(struct ctdb_g_lock
);
2198 static void ctdb_g_lock_push_old(struct ctdb_g_lock
*in
, uint8_t *buf
)
2200 memcpy(buf
, in
, sizeof(struct ctdb_g_lock
));
2203 static int ctdb_g_lock_pull_old(uint8_t *buf
, size_t buflen
,
2204 struct ctdb_g_lock
*out
)
2206 if (buflen
< sizeof(struct ctdb_g_lock
)) {
2210 memcpy(out
, buf
, sizeof(struct ctdb_g_lock
));
2214 static size_t ctdb_g_lock_list_len_old(struct ctdb_g_lock_list
*in
)
2216 return in
->num
* sizeof(struct ctdb_g_lock
);
2219 static void ctdb_g_lock_list_push_old(struct ctdb_g_lock_list
*in
,
2225 for (i
=0; i
<in
->num
; i
++) {
2226 ctdb_g_lock_push_old(&in
->lock
[i
], &buf
[offset
]);
2227 offset
+= sizeof(struct ctdb_g_lock
);
2231 static int ctdb_g_lock_list_pull_old(uint8_t *buf
, size_t buflen
,
2232 TALLOC_CTX
*mem_ctx
,
2233 struct ctdb_g_lock_list
**out
)
2235 struct ctdb_g_lock_list
*val
;
2240 val
= talloc_zero(mem_ctx
, struct ctdb_g_lock_list
);
2245 count
= buflen
/ sizeof(struct ctdb_g_lock
);
2246 val
->lock
= talloc_array(val
, struct ctdb_g_lock
, count
);
2247 if (val
->lock
== NULL
) {
2253 for (i
=0; i
<count
; i
++) {
2254 ret
= ctdb_g_lock_pull_old(&buf
[offset
], buflen
-offset
,
2260 offset
+= sizeof(struct ctdb_g_lock
);
2269 COMPAT_TYPE3_TEST(struct ctdb_statistics
, ctdb_statistics
);
2270 COMPAT_TYPE3_TEST(struct ctdb_vnn_map
, ctdb_vnn_map
);
2271 COMPAT_TYPE3_TEST(struct ctdb_dbid_map
, ctdb_dbid_map
);
2272 COMPAT_TYPE3_TEST(struct ctdb_pulldb
, ctdb_pulldb
);
2273 COMPAT_TYPE3_TEST(struct ctdb_pulldb_ext
, ctdb_pulldb_ext
);
2275 COMPAT_TYPE1_TEST(struct ctdb_ltdb_header
, ctdb_ltdb_header
);
2277 COMPAT_TYPE3_TEST(struct ctdb_rec_data
, ctdb_rec_data
);
2278 COMPAT_TYPE3_TEST(struct ctdb_rec_buffer
, ctdb_rec_buffer
);
2279 COMPAT_TYPE3_TEST(struct ctdb_traverse_start
, ctdb_traverse_start
);
2280 COMPAT_TYPE3_TEST(struct ctdb_traverse_all
, ctdb_traverse_all
);
2281 COMPAT_TYPE3_TEST(struct ctdb_traverse_start_ext
, ctdb_traverse_start_ext
);
2282 COMPAT_TYPE3_TEST(struct ctdb_traverse_all_ext
, ctdb_traverse_all_ext
);
2283 COMPAT_TYPE3_TEST(ctdb_sock_addr
, ctdb_sock_addr
);
2284 COMPAT_TYPE3_TEST(struct ctdb_connection
, ctdb_connection
);
2285 COMPAT_TYPE3_TEST(struct ctdb_tunable
, ctdb_tunable
);
2286 COMPAT_TYPE3_TEST(struct ctdb_node_flag_change
, ctdb_node_flag_change
);
2287 COMPAT_TYPE3_TEST(struct ctdb_var_list
, ctdb_var_list
);
2288 COMPAT_TYPE3_TEST(struct ctdb_tunable_list
, ctdb_tunable_list
);
2289 COMPAT_TYPE3_TEST(struct ctdb_tickle_list
, ctdb_tickle_list
);
2290 COMPAT_TYPE3_TEST(struct ctdb_addr_info
, ctdb_addr_info
);
2291 COMPAT_TYPE3_TEST(struct ctdb_transdb
, ctdb_transdb
);
2292 COMPAT_TYPE3_TEST(struct ctdb_uptime
, ctdb_uptime
);
2293 COMPAT_TYPE3_TEST(struct ctdb_public_ip
, ctdb_public_ip
);
2294 COMPAT_TYPE3_TEST(struct ctdb_public_ip_list
, ctdb_public_ip_list
);
2295 COMPAT_TYPE3_TEST(struct ctdb_node_and_flags
, ctdb_node_and_flags
);
2296 COMPAT_TYPE3_TEST(struct ctdb_node_map
, ctdb_node_map
);
2297 COMPAT_TYPE3_TEST(struct ctdb_script
, ctdb_script
);
2298 COMPAT_TYPE3_TEST(struct ctdb_script_list
, ctdb_script_list
);
2299 COMPAT_TYPE3_TEST(struct ctdb_ban_state
, ctdb_ban_state
);
2300 COMPAT_TYPE3_TEST(struct ctdb_notify_data
, ctdb_notify_data
);
2301 COMPAT_TYPE3_TEST(struct ctdb_iface
, ctdb_iface
);
2302 COMPAT_TYPE3_TEST(struct ctdb_iface_list
, ctdb_iface_list
);
2303 COMPAT_TYPE3_TEST(struct ctdb_public_ip_info
, ctdb_public_ip_info
);
2304 COMPAT_TYPE3_TEST(struct ctdb_statistics_list
, ctdb_statistics_list
);
2305 COMPAT_TYPE3_TEST(struct ctdb_key_data
, ctdb_key_data
);
2306 COMPAT_TYPE3_TEST(struct ctdb_db_statistics
, ctdb_db_statistics
);
2308 COMPAT_TYPE3_TEST(struct ctdb_election_message
, ctdb_election_message
);
2309 COMPAT_TYPE3_TEST(struct ctdb_srvid_message
, ctdb_srvid_message
);
2310 COMPAT_TYPE3_TEST(struct ctdb_disable_message
, ctdb_disable_message
);
2312 COMPAT_TYPE1_TEST(struct ctdb_server_id
, ctdb_server_id
);
2313 COMPAT_TYPE1_TEST(struct ctdb_g_lock
, ctdb_g_lock
);
2315 COMPAT_TYPE3_TEST(struct ctdb_g_lock_list
, ctdb_g_lock_list
);
2317 int main(int argc
, char *argv
[])
2320 int seed
= atoi(argv
[1]);
2324 COMPAT_TEST_FUNC(ctdb_statistics
)();
2325 COMPAT_TEST_FUNC(ctdb_vnn_map
)();
2326 COMPAT_TEST_FUNC(ctdb_dbid_map
)();
2327 COMPAT_TEST_FUNC(ctdb_pulldb
)();
2328 COMPAT_TEST_FUNC(ctdb_pulldb_ext
)();
2329 COMPAT_TEST_FUNC(ctdb_ltdb_header
)();
2330 COMPAT_TEST_FUNC(ctdb_rec_data
)();
2331 COMPAT_TEST_FUNC(ctdb_rec_buffer
)();
2332 COMPAT_TEST_FUNC(ctdb_traverse_start
)();
2333 COMPAT_TEST_FUNC(ctdb_traverse_all
)();
2334 COMPAT_TEST_FUNC(ctdb_traverse_start_ext
)();
2335 COMPAT_TEST_FUNC(ctdb_traverse_all_ext
)();
2336 COMPAT_TEST_FUNC(ctdb_sock_addr
)();
2337 COMPAT_TEST_FUNC(ctdb_connection
)();
2338 COMPAT_TEST_FUNC(ctdb_tunable
)();
2339 COMPAT_TEST_FUNC(ctdb_node_flag_change
)();
2340 COMPAT_TEST_FUNC(ctdb_var_list
)();
2341 COMPAT_TEST_FUNC(ctdb_tunable_list
)();
2342 COMPAT_TEST_FUNC(ctdb_tickle_list
)();
2343 COMPAT_TEST_FUNC(ctdb_addr_info
)();
2344 COMPAT_TEST_FUNC(ctdb_transdb
)();
2345 COMPAT_TEST_FUNC(ctdb_uptime
)();
2346 COMPAT_TEST_FUNC(ctdb_public_ip
)();
2347 COMPAT_TEST_FUNC(ctdb_public_ip_list
)();
2348 COMPAT_TEST_FUNC(ctdb_node_and_flags
)();
2349 COMPAT_TEST_FUNC(ctdb_node_map
)();
2350 COMPAT_TEST_FUNC(ctdb_script
)();
2351 COMPAT_TEST_FUNC(ctdb_script_list
)();
2352 COMPAT_TEST_FUNC(ctdb_ban_state
)();
2353 COMPAT_TEST_FUNC(ctdb_notify_data
)();
2354 COMPAT_TEST_FUNC(ctdb_iface
)();
2355 COMPAT_TEST_FUNC(ctdb_iface_list
)();
2356 COMPAT_TEST_FUNC(ctdb_public_ip_info
)();
2357 COMPAT_TEST_FUNC(ctdb_statistics_list
)();
2358 COMPAT_TEST_FUNC(ctdb_key_data
)();
2359 COMPAT_TEST_FUNC(ctdb_db_statistics
)();
2361 COMPAT_TEST_FUNC(ctdb_election_message
)();
2362 COMPAT_TEST_FUNC(ctdb_srvid_message
)();
2363 COMPAT_TEST_FUNC(ctdb_disable_message
)();
2364 COMPAT_TEST_FUNC(ctdb_server_id
)();
2365 COMPAT_TEST_FUNC(ctdb_g_lock
)();
2366 COMPAT_TEST_FUNC(ctdb_g_lock_list
)();