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 assert(in
->var
[i
] != NULL
);
842 len
+= strlen(in
->var
[i
]) + 1;
847 static void ctdb_var_list_push_old(struct ctdb_var_list
*in
, uint8_t *buf
)
849 struct ctdb_var_list_wire
*wire
= (struct ctdb_var_list_wire
*)buf
;
854 n
= sprintf(wire
->list_str
, "%s", in
->var
[0]);
857 for (i
=1; i
<in
->count
; i
++) {
858 n
= sprintf(&wire
->list_str
[offset
], ":%s", in
->var
[i
]);
861 wire
->length
= offset
+ 1;
864 static int ctdb_var_list_pull_old(uint8_t *buf
, size_t buflen
,
866 struct ctdb_var_list
**out
)
868 struct ctdb_var_list
*val
= NULL
;
869 struct ctdb_var_list_wire
*wire
= (struct ctdb_var_list_wire
*)buf
;
870 char *str
, *s
, *tok
, *ptr
;
873 if (buflen
< sizeof(uint32_t)) {
876 if (wire
->length
> buflen
) {
879 if (sizeof(uint32_t) + wire
->length
< sizeof(uint32_t)) {
882 if (buflen
< sizeof(uint32_t) + wire
->length
) {
886 str
= talloc_strndup(mem_ctx
, (char *)wire
->list_str
, wire
->length
);
891 val
= talloc_zero(mem_ctx
, struct ctdb_var_list
);
897 while ((tok
= strtok_r(s
, ":", &ptr
)) != NULL
) {
899 list
= talloc_realloc(val
, val
->var
, const char *,
906 val
->var
[val
->count
] = talloc_strdup(val
, tok
);
907 if (val
->var
[val
->count
] == NULL
) {
923 static size_t ctdb_tunable_list_len_old(struct ctdb_tunable_list
*in
)
925 return sizeof(struct ctdb_tunable_list
);
928 static void ctdb_tunable_list_push_old(struct ctdb_tunable_list
*in
,
931 memcpy(buf
, in
, sizeof(struct ctdb_tunable_list
));
934 static int ctdb_tunable_list_pull_old(uint8_t *buf
, size_t buflen
,
936 struct ctdb_tunable_list
**out
)
938 struct ctdb_tunable_list
*val
;
940 if (buflen
< sizeof(struct ctdb_tunable_list
)) {
944 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_tunable_list
));
953 struct ctdb_tickle_list_wire
{
956 struct ctdb_connection conn
[1];
959 static size_t ctdb_tickle_list_len_old(struct ctdb_tickle_list
*in
)
961 return offsetof(struct ctdb_tickle_list
, conn
) +
962 in
->num
* sizeof(struct ctdb_connection
);
965 static void ctdb_tickle_list_push_old(struct ctdb_tickle_list
*in
,
968 struct ctdb_tickle_list_wire
*wire
=
969 (struct ctdb_tickle_list_wire
*)buf
;
973 memcpy(&wire
->addr
, &in
->addr
, sizeof(ctdb_sock_addr
));
976 offset
= offsetof(struct ctdb_tickle_list_wire
, conn
);
977 for (i
=0; i
<in
->num
; i
++) {
978 ctdb_connection_push_old(&in
->conn
[i
], &buf
[offset
]);
979 offset
+= ctdb_connection_len_old(&in
->conn
[i
]);
983 static int ctdb_tickle_list_pull_old(uint8_t *buf
, size_t buflen
,
985 struct ctdb_tickle_list
**out
)
987 struct ctdb_tickle_list
*val
;
988 struct ctdb_tickle_list_wire
*wire
=
989 (struct ctdb_tickle_list_wire
*)buf
;
994 if (buflen
< offsetof(struct ctdb_tickle_list_wire
, conn
)) {
997 if (wire
->num
> buflen
/ sizeof(struct ctdb_connection
)) {
1000 if (offsetof(struct ctdb_tickle_list_wire
, conn
) +
1001 wire
->num
* sizeof(struct ctdb_connection
) <
1002 offsetof(struct ctdb_tickle_list_wire
, conn
)) {
1005 if (buflen
< offsetof(struct ctdb_tickle_list_wire
, conn
) +
1006 wire
->num
* sizeof(struct ctdb_connection
)) {
1010 val
= talloc(mem_ctx
, struct ctdb_tickle_list
);
1015 offset
= offsetof(struct ctdb_tickle_list
, conn
);
1016 memcpy(val
, wire
, offset
);
1018 val
->conn
= talloc_array(val
, struct ctdb_connection
, wire
->num
);
1019 if (val
->conn
== NULL
) {
1024 for (i
=0; i
<wire
->num
; i
++) {
1025 ret
= ctdb_connection_pull_elems_old(&buf
[offset
],
1033 offset
+= ctdb_connection_len_old(&val
->conn
[i
]);
1040 struct ctdb_addr_info_wire
{
1041 ctdb_sock_addr addr
;
1047 static size_t ctdb_addr_info_len_old(struct ctdb_addr_info
*in
)
1051 len
= offsetof(struct ctdb_addr_info_wire
, iface
);
1052 if (in
->iface
!= NULL
) {
1053 len
+= strlen(in
->iface
)+1;
1059 static void ctdb_addr_info_push_old(struct ctdb_addr_info
*in
, uint8_t *buf
)
1061 struct ctdb_addr_info_wire
*wire
= (struct ctdb_addr_info_wire
*)buf
;
1063 wire
->addr
= in
->addr
;
1064 wire
->mask
= in
->mask
;
1065 if (in
->iface
== NULL
) {
1068 wire
->len
= strlen(in
->iface
)+1;
1069 memcpy(wire
->iface
, in
->iface
, wire
->len
);
1073 static int ctdb_addr_info_pull_old(uint8_t *buf
, size_t buflen
,
1074 TALLOC_CTX
*mem_ctx
,
1075 struct ctdb_addr_info
**out
)
1077 struct ctdb_addr_info
*val
;
1078 struct ctdb_addr_info_wire
*wire
= (struct ctdb_addr_info_wire
*)buf
;
1080 if (buflen
< offsetof(struct ctdb_addr_info_wire
, iface
)) {
1083 if (wire
->len
> buflen
) {
1086 if (offsetof(struct ctdb_addr_info_wire
, iface
) + wire
->len
<
1087 offsetof(struct ctdb_addr_info_wire
, iface
)) {
1090 if (buflen
< offsetof(struct ctdb_addr_info_wire
, iface
) + wire
->len
) {
1094 val
= talloc(mem_ctx
, struct ctdb_addr_info
);
1099 val
->addr
= wire
->addr
;
1100 val
->mask
= wire
->mask
;
1102 if (wire
->len
== 0) {
1105 val
->iface
= talloc_strndup(val
, wire
->iface
, wire
->len
);
1106 if (val
->iface
== NULL
) {
1116 static size_t ctdb_transdb_len_old(struct ctdb_transdb
*in
)
1118 return sizeof(struct ctdb_transdb
);
1121 static void ctdb_transdb_push_old(struct ctdb_transdb
*in
, uint8_t *buf
)
1123 memcpy(buf
, in
, sizeof(struct ctdb_transdb
));
1126 static int ctdb_transdb_pull_old(uint8_t *buf
, size_t buflen
,
1127 TALLOC_CTX
*mem_ctx
,
1128 struct ctdb_transdb
**out
)
1130 struct ctdb_transdb
*val
;
1132 if (buflen
< sizeof(struct ctdb_transdb
)) {
1136 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_transdb
));
1145 static size_t ctdb_uptime_len_old(struct ctdb_uptime
*in
)
1147 return sizeof(struct ctdb_uptime
);
1150 static void ctdb_uptime_push_old(struct ctdb_uptime
*in
, uint8_t *buf
)
1152 memcpy(buf
, in
, sizeof(struct ctdb_uptime
));
1155 static int ctdb_uptime_pull_old(uint8_t *buf
, size_t buflen
,
1156 TALLOC_CTX
*mem_ctx
, struct ctdb_uptime
**out
)
1158 struct ctdb_uptime
*val
;
1160 if (buflen
< sizeof(struct ctdb_uptime
)) {
1164 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_uptime
));
1173 static size_t ctdb_public_ip_len_old(struct ctdb_public_ip
*in
)
1175 return sizeof(struct ctdb_public_ip
);
1178 static void ctdb_public_ip_push_old(struct ctdb_public_ip
*in
, uint8_t *buf
)
1180 memcpy(buf
, in
, sizeof(struct ctdb_public_ip
));
1183 static int ctdb_public_ip_pull_elems_old(uint8_t *buf
, size_t buflen
,
1184 TALLOC_CTX
*mem_ctx
,
1185 struct ctdb_public_ip
*out
)
1187 if (buflen
< sizeof(struct ctdb_public_ip
)) {
1191 memcpy(out
, buf
, sizeof(struct ctdb_public_ip
));
1196 static int ctdb_public_ip_pull_old(uint8_t *buf
, size_t buflen
,
1197 TALLOC_CTX
*mem_ctx
,
1198 struct ctdb_public_ip
**out
)
1200 struct ctdb_public_ip
*val
;
1203 val
= talloc(mem_ctx
, struct ctdb_public_ip
);
1208 ret
= ctdb_public_ip_pull_elems_old(buf
, buflen
, val
, val
);
1218 struct ctdb_public_ip_list_wire
{
1220 struct ctdb_public_ip ip
[1];
1223 static size_t ctdb_public_ip_list_len_old(struct ctdb_public_ip_list
*in
)
1228 len
= sizeof(uint32_t);
1229 for (i
=0; i
<in
->num
; i
++) {
1230 len
+= ctdb_public_ip_len_old(&in
->ip
[i
]);
1235 static void ctdb_public_ip_list_push_old(struct ctdb_public_ip_list
*in
,
1238 struct ctdb_public_ip_list_wire
*wire
=
1239 (struct ctdb_public_ip_list_wire
*)buf
;
1243 wire
->num
= in
->num
;
1245 offset
= offsetof(struct ctdb_public_ip_list_wire
, ip
);
1246 for (i
=0; i
<in
->num
; i
++) {
1247 ctdb_public_ip_push_old(&in
->ip
[i
], &buf
[offset
]);
1248 offset
+= ctdb_public_ip_len_old(&in
->ip
[i
]);
1252 static int ctdb_public_ip_list_pull_old(uint8_t *buf
, size_t buflen
,
1253 TALLOC_CTX
*mem_ctx
,
1254 struct ctdb_public_ip_list
**out
)
1256 struct ctdb_public_ip_list
*val
;
1257 struct ctdb_public_ip_list_wire
*wire
=
1258 (struct ctdb_public_ip_list_wire
*)buf
;
1263 if (buflen
< sizeof(uint32_t)) {
1266 if (wire
->num
> buflen
/ sizeof(struct ctdb_public_ip
)) {
1269 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_public_ip
) <
1273 if (buflen
< sizeof(uint32_t) +
1274 wire
->num
* sizeof(struct ctdb_public_ip
)) {
1278 val
= talloc(mem_ctx
, struct ctdb_public_ip_list
);
1283 val
->num
= wire
->num
;
1284 if (wire
->num
== 0) {
1289 val
->ip
= talloc_array(val
, struct ctdb_public_ip
, wire
->num
);
1290 if (val
->ip
== NULL
) {
1295 offset
= offsetof(struct ctdb_public_ip_list_wire
, ip
);
1296 for (i
=0; i
<wire
->num
; i
++) {
1297 ret
= ctdb_public_ip_pull_elems_old(&buf
[offset
],
1305 offset
+= ctdb_public_ip_len_old(&val
->ip
[i
]);
1312 static size_t ctdb_node_and_flags_len_old(struct ctdb_node_and_flags
*in
)
1314 return sizeof(struct ctdb_node_and_flags
);
1317 static void ctdb_node_and_flags_push_old(struct ctdb_node_and_flags
*in
,
1320 memcpy(buf
, in
, sizeof(struct ctdb_node_and_flags
));
1323 static int ctdb_node_and_flags_pull_elems_old(TALLOC_CTX
*mem_ctx
,
1324 uint8_t *buf
, size_t buflen
,
1325 struct ctdb_node_and_flags
*out
)
1327 if (buflen
< sizeof(struct ctdb_node_and_flags
)) {
1331 memcpy(out
, buf
, sizeof(struct ctdb_node_and_flags
));
1336 static int ctdb_node_and_flags_pull_old(uint8_t *buf
, size_t buflen
,
1337 TALLOC_CTX
*mem_ctx
,
1338 struct ctdb_node_and_flags
**out
)
1340 struct ctdb_node_and_flags
*val
;
1343 val
= talloc(mem_ctx
, struct ctdb_node_and_flags
);
1348 ret
= ctdb_node_and_flags_pull_elems_old(val
, buf
, buflen
, val
);
1358 struct ctdb_node_map_wire
{
1360 struct ctdb_node_and_flags node
[1];
1363 static size_t ctdb_node_map_len_old(struct ctdb_node_map
*in
)
1365 return sizeof(uint32_t) +
1366 in
->num
* sizeof(struct ctdb_node_and_flags
);
1369 static void ctdb_node_map_push_old(struct ctdb_node_map
*in
, uint8_t *buf
)
1371 struct ctdb_node_map_wire
*wire
= (struct ctdb_node_map_wire
*)buf
;
1375 wire
->num
= in
->num
;
1377 offset
= offsetof(struct ctdb_node_map_wire
, node
);
1378 for (i
=0; i
<in
->num
; i
++) {
1379 ctdb_node_and_flags_push_old(&in
->node
[i
], &buf
[offset
]);
1380 offset
+= ctdb_node_and_flags_len_old(&in
->node
[i
]);
1384 static int ctdb_node_map_pull_old(uint8_t *buf
, size_t buflen
,
1385 TALLOC_CTX
*mem_ctx
,
1386 struct ctdb_node_map
**out
)
1388 struct ctdb_node_map
*val
;
1389 struct ctdb_node_map_wire
*wire
= (struct ctdb_node_map_wire
*)buf
;
1394 if (buflen
< sizeof(uint32_t)) {
1397 if (wire
->num
> buflen
/ sizeof(struct ctdb_node_and_flags
)) {
1400 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_node_and_flags
) <
1404 if (buflen
< sizeof(uint32_t) +
1405 wire
->num
* sizeof(struct ctdb_node_and_flags
)) {
1409 val
= talloc(mem_ctx
, struct ctdb_node_map
);
1414 val
->num
= wire
->num
;
1415 val
->node
= talloc_array(val
, struct ctdb_node_and_flags
, wire
->num
);
1416 if (val
->node
== NULL
) {
1421 offset
= offsetof(struct ctdb_node_map_wire
, node
);
1422 for (i
=0; i
<wire
->num
; i
++) {
1423 ret
= ctdb_node_and_flags_pull_elems_old(val
->node
,
1431 offset
+= ctdb_node_and_flags_len_old(&val
->node
[i
]);
1438 static size_t ctdb_script_len_old(struct ctdb_script
*in
)
1440 return sizeof(struct ctdb_script
);
1443 static void ctdb_script_push_old(struct ctdb_script
*in
, uint8_t *buf
)
1445 memcpy(buf
, in
, sizeof(struct ctdb_script
));
1448 static int ctdb_script_pull_elems_old(uint8_t *buf
, size_t buflen
,
1449 TALLOC_CTX
*mem_ctx
,
1450 struct ctdb_script
*out
)
1452 if (buflen
< sizeof(struct ctdb_script
)) {
1456 memcpy(out
, buf
, sizeof(struct ctdb_script
));
1461 static int ctdb_script_pull_old(uint8_t *buf
, size_t buflen
,
1462 TALLOC_CTX
*mem_ctx
, struct ctdb_script
**out
)
1464 struct ctdb_script
*val
;
1467 val
= talloc(mem_ctx
, struct ctdb_script
);
1472 ret
= ctdb_script_pull_elems_old(buf
, buflen
, val
, val
);
1482 struct ctdb_script_list_wire
{
1483 uint32_t num_scripts
;
1484 struct ctdb_script script
[1];
1487 static size_t ctdb_script_list_len_old(struct ctdb_script_list
*in
)
1496 len
= offsetof(struct ctdb_script_list_wire
, script
);
1497 for (i
=0; i
<in
->num_scripts
; i
++) {
1498 len
+= ctdb_script_len_old(&in
->script
[i
]);
1503 static void ctdb_script_list_push_old(struct ctdb_script_list
*in
,
1506 struct ctdb_script_list_wire
*wire
=
1507 (struct ctdb_script_list_wire
*)buf
;
1515 wire
->num_scripts
= in
->num_scripts
;
1517 offset
= offsetof(struct ctdb_script_list_wire
, script
);
1518 for (i
=0; i
<in
->num_scripts
; i
++) {
1519 ctdb_script_push_old(&in
->script
[i
], &buf
[offset
]);
1520 offset
+= ctdb_script_len_old(&in
->script
[i
]);
1524 static int ctdb_script_list_pull_old(uint8_t *buf
, size_t buflen
,
1525 TALLOC_CTX
*mem_ctx
,
1526 struct ctdb_script_list
**out
)
1528 struct ctdb_script_list
*val
;
1529 struct ctdb_script_list_wire
*wire
=
1530 (struct ctdb_script_list_wire
*)buf
;
1535 /* If event scripts have never been run, the result will be NULL */
1541 offset
= offsetof(struct ctdb_script_list_wire
, script
);
1543 if (buflen
< offset
) {
1546 if (wire
->num_scripts
> buflen
/ sizeof(struct ctdb_script
)) {
1549 if (offset
+ wire
->num_scripts
* sizeof(struct ctdb_script
) < offset
) {
1552 if (buflen
< offset
+ wire
->num_scripts
* sizeof(struct ctdb_script
)) {
1556 val
= talloc(mem_ctx
, struct ctdb_script_list
);
1562 val
->num_scripts
= wire
->num_scripts
;
1563 val
->script
= talloc_array(val
, struct ctdb_script
, wire
->num_scripts
);
1564 if (val
->script
== NULL
) {
1569 for (i
=0; i
<wire
->num_scripts
; i
++) {
1570 ret
= ctdb_script_pull_elems_old(&buf
[offset
], buflen
-offset
,
1577 offset
+= ctdb_script_len_old(&val
->script
[i
]);
1584 static size_t ctdb_ban_state_len_old(struct ctdb_ban_state
*in
)
1586 return sizeof(struct ctdb_ban_state
);
1589 static void ctdb_ban_state_push_old(struct ctdb_ban_state
*in
, uint8_t *buf
)
1591 memcpy(buf
, in
, sizeof(struct ctdb_ban_state
));
1594 static int ctdb_ban_state_pull_old(uint8_t *buf
, size_t buflen
,
1595 TALLOC_CTX
*mem_ctx
,
1596 struct ctdb_ban_state
**out
)
1598 struct ctdb_ban_state
*val
;
1600 if (buflen
< sizeof(struct ctdb_ban_state
)) {
1604 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_ban_state
));
1613 struct ctdb_notify_data_wire
{
1619 static size_t ctdb_notify_data_len_old(struct ctdb_notify_data
*in
)
1621 return offsetof(struct ctdb_notify_data_wire
, data
) +
1625 static void ctdb_notify_data_push_old(struct ctdb_notify_data
*in
,
1628 struct ctdb_notify_data_wire
*wire
=
1629 (struct ctdb_notify_data_wire
*)buf
;
1631 wire
->srvid
= in
->srvid
;
1632 wire
->len
= in
->data
.dsize
;
1633 memcpy(wire
->data
, in
->data
.dptr
, in
->data
.dsize
);
1636 static int ctdb_notify_data_pull_old(uint8_t *buf
, size_t buflen
,
1637 TALLOC_CTX
*mem_ctx
,
1638 struct ctdb_notify_data
**out
)
1640 struct ctdb_notify_data
*val
;
1641 struct ctdb_notify_data_wire
*wire
=
1642 (struct ctdb_notify_data_wire
*)buf
;
1644 if (buflen
< offsetof(struct ctdb_notify_data_wire
, data
)) {
1647 if (wire
->len
> buflen
) {
1650 if (offsetof(struct ctdb_notify_data_wire
, data
) + wire
->len
<
1651 offsetof(struct ctdb_notify_data_wire
, data
)) {
1654 if (buflen
< offsetof(struct ctdb_notify_data_wire
, data
) + wire
->len
) {
1658 val
= talloc(mem_ctx
, struct ctdb_notify_data
);
1663 val
->srvid
= wire
->srvid
;
1664 val
->data
.dsize
= wire
->len
;
1665 val
->data
.dptr
= talloc_memdup(val
, wire
->data
, wire
->len
);
1666 if (val
->data
.dptr
== NULL
) {
1675 static size_t ctdb_iface_len_old(struct ctdb_iface
*in
)
1677 return sizeof(struct ctdb_iface
);
1680 static void ctdb_iface_push_old(struct ctdb_iface
*in
, uint8_t *buf
)
1682 memcpy(buf
, in
, sizeof(struct ctdb_iface
));
1685 static int ctdb_iface_pull_elems_old(uint8_t *buf
, size_t buflen
,
1686 TALLOC_CTX
*mem_ctx
,
1687 struct ctdb_iface
*out
)
1689 if (buflen
< sizeof(struct ctdb_iface
)) {
1693 memcpy(out
, buf
, sizeof(struct ctdb_iface
));
1698 static int ctdb_iface_pull_old(uint8_t *buf
, size_t buflen
,
1699 TALLOC_CTX
*mem_ctx
, struct ctdb_iface
**out
)
1701 struct ctdb_iface
*val
;
1704 val
= talloc(mem_ctx
, struct ctdb_iface
);
1709 ret
= ctdb_iface_pull_elems_old(buf
, buflen
, val
, val
);
1719 struct ctdb_iface_list_wire
{
1721 struct ctdb_iface iface
[1];
1724 static size_t ctdb_iface_list_len_old(struct ctdb_iface_list
*in
)
1726 return sizeof(uint32_t) +
1727 in
->num
* sizeof(struct ctdb_iface
);
1730 static void ctdb_iface_list_push_old(struct ctdb_iface_list
*in
, uint8_t *buf
)
1732 struct ctdb_iface_list_wire
*wire
=
1733 (struct ctdb_iface_list_wire
*)buf
;
1735 wire
->num
= in
->num
;
1736 memcpy(wire
->iface
, in
->iface
, in
->num
* sizeof(struct ctdb_iface
));
1739 static int ctdb_iface_list_pull_old(uint8_t *buf
, size_t buflen
,
1740 TALLOC_CTX
*mem_ctx
,
1741 struct ctdb_iface_list
**out
)
1743 struct ctdb_iface_list
*val
;
1744 struct ctdb_iface_list_wire
*wire
=
1745 (struct ctdb_iface_list_wire
*)buf
;
1747 if (buflen
< sizeof(uint32_t)) {
1750 if (wire
->num
> buflen
/ sizeof(struct ctdb_iface
)) {
1753 if (sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_iface
) <
1757 if (buflen
< sizeof(uint32_t) + wire
->num
* sizeof(struct ctdb_iface
)) {
1761 val
= talloc(mem_ctx
, struct ctdb_iface_list
);
1766 val
->num
= wire
->num
;
1767 val
->iface
= talloc_array(val
, struct ctdb_iface
, wire
->num
);
1768 if (val
->iface
== NULL
) {
1773 memcpy(val
->iface
, wire
->iface
, wire
->num
* sizeof(struct ctdb_iface
));
1779 struct ctdb_public_ip_info_wire
{
1780 struct ctdb_public_ip ip
;
1781 uint32_t active_idx
;
1783 struct ctdb_iface ifaces
[1];
1786 static size_t ctdb_public_ip_info_len_old(struct ctdb_public_ip_info
*in
)
1788 return offsetof(struct ctdb_public_ip_info_wire
, num
) +
1789 ctdb_iface_list_len_old(in
->ifaces
);
1792 static void ctdb_public_ip_info_push_old(struct ctdb_public_ip_info
*in
,
1795 struct ctdb_public_ip_info_wire
*wire
=
1796 (struct ctdb_public_ip_info_wire
*)buf
;
1799 offset
= offsetof(struct ctdb_public_ip_info_wire
, num
);
1800 memcpy(wire
, in
, offset
);
1801 wire
->num
= in
->ifaces
->num
;
1802 memcpy(wire
->ifaces
, in
->ifaces
->iface
,
1803 in
->ifaces
->num
* sizeof(struct ctdb_iface
));
1806 static int ctdb_public_ip_info_pull_old(uint8_t *buf
, size_t buflen
,
1807 TALLOC_CTX
*mem_ctx
,
1808 struct ctdb_public_ip_info
**out
)
1810 struct ctdb_public_ip_info
*val
;
1811 struct ctdb_public_ip_info_wire
*wire
=
1812 (struct ctdb_public_ip_info_wire
*)buf
;
1814 if (buflen
< offsetof(struct ctdb_public_ip_info_wire
, ifaces
)) {
1817 if (wire
->num
> buflen
/ sizeof(struct ctdb_iface
)) {
1820 if (offsetof(struct ctdb_public_ip_info_wire
, ifaces
) +
1821 wire
->num
* sizeof(struct ctdb_iface
) <
1822 offsetof(struct ctdb_public_ip_info_wire
, ifaces
)) {
1825 if (buflen
< offsetof(struct ctdb_public_ip_info_wire
, ifaces
) +
1826 wire
->num
* sizeof(struct ctdb_iface
)) {
1830 val
= talloc(mem_ctx
, struct ctdb_public_ip_info
);
1835 memcpy(val
, wire
, offsetof(struct ctdb_public_ip_info_wire
, num
));
1837 val
->ifaces
= talloc(val
, struct ctdb_iface_list
);
1838 if (val
->ifaces
== NULL
) {
1843 val
->ifaces
->num
= wire
->num
;
1844 val
->ifaces
->iface
= talloc_array(val
->ifaces
, struct ctdb_iface
,
1846 if (val
->ifaces
->iface
== NULL
) {
1851 memcpy(val
->ifaces
->iface
, wire
->ifaces
,
1852 wire
->num
* sizeof(struct ctdb_iface
));
1858 struct ctdb_statistics_list_wire
{
1860 struct ctdb_statistics stats
[1];
1863 static size_t ctdb_statistics_list_len_old(struct ctdb_statistics_list
*in
)
1865 return offsetof(struct ctdb_statistics_list_wire
, stats
) +
1866 in
->num
* sizeof(struct ctdb_statistics
);
1869 static void ctdb_statistics_list_push_old(struct ctdb_statistics_list
*in
,
1872 struct ctdb_statistics_list_wire
*wire
=
1873 (struct ctdb_statistics_list_wire
*)buf
;
1875 wire
->num
= in
->num
;
1876 memcpy(wire
->stats
, in
->stats
,
1877 in
->num
* sizeof(struct ctdb_statistics
));
1880 static int ctdb_statistics_list_pull_old(uint8_t *buf
, size_t buflen
,
1881 TALLOC_CTX
*mem_ctx
,
1882 struct ctdb_statistics_list
**out
)
1884 struct ctdb_statistics_list
*val
;
1885 struct ctdb_statistics_list_wire
*wire
=
1886 (struct ctdb_statistics_list_wire
*)buf
;
1888 if (buflen
< offsetof(struct ctdb_statistics_list_wire
, stats
)) {
1891 if (wire
->num
> buflen
/ sizeof(struct ctdb_statistics
)) {
1894 if (offsetof(struct ctdb_statistics_list_wire
, stats
) +
1895 wire
->num
* sizeof(struct ctdb_statistics
) <
1896 offsetof(struct ctdb_statistics_list_wire
, stats
)) {
1899 if (buflen
< offsetof(struct ctdb_statistics_list_wire
, stats
) +
1900 wire
->num
* sizeof(struct ctdb_statistics
)) {
1904 val
= talloc(mem_ctx
, struct ctdb_statistics_list
);
1909 val
->num
= wire
->num
;
1911 val
->stats
= talloc_array(val
, struct ctdb_statistics
, wire
->num
);
1912 if (val
->stats
== NULL
) {
1917 memcpy(val
->stats
, wire
->stats
,
1918 wire
->num
* sizeof(struct ctdb_statistics
));
1924 struct ctdb_key_data_wire
{
1926 struct ctdb_ltdb_header header
;
1931 static size_t ctdb_key_data_len_old(struct ctdb_key_data
*in
)
1933 return offsetof(struct ctdb_key_data_wire
, key
) + in
->key
.dsize
;
1936 static void ctdb_key_data_push_old(struct ctdb_key_data
*in
, uint8_t *buf
)
1938 struct ctdb_key_data_wire
*wire
= (struct ctdb_key_data_wire
*)buf
;
1940 memcpy(wire
, in
, offsetof(struct ctdb_key_data
, key
));
1941 wire
->keylen
= in
->key
.dsize
;
1942 memcpy(wire
->key
, in
->key
.dptr
, in
->key
.dsize
);
1945 static int ctdb_key_data_pull_old(uint8_t *buf
, size_t buflen
,
1946 TALLOC_CTX
*mem_ctx
,
1947 struct ctdb_key_data
**out
)
1949 struct ctdb_key_data
*val
;
1950 struct ctdb_key_data_wire
*wire
= (struct ctdb_key_data_wire
*)buf
;
1952 if (buflen
< offsetof(struct ctdb_key_data_wire
, key
)) {
1955 if (wire
->keylen
> buflen
) {
1958 if (offsetof(struct ctdb_key_data_wire
, key
) + wire
->keylen
<
1959 offsetof(struct ctdb_key_data_wire
, key
)) {
1962 if (buflen
< offsetof(struct ctdb_key_data_wire
, key
) + wire
->keylen
) {
1966 val
= talloc(mem_ctx
, struct ctdb_key_data
);
1971 memcpy(val
, wire
, offsetof(struct ctdb_key_data
, key
));
1973 val
->key
.dsize
= wire
->keylen
;
1974 val
->key
.dptr
= talloc_memdup(val
, wire
->key
, wire
->keylen
);
1975 if (val
->key
.dptr
== NULL
) {
1984 struct ctdb_db_statistics_wire
{
1985 struct ctdb_db_statistics dbstats
;
1986 char hot_keys_wire
[1];
1989 static size_t ctdb_db_statistics_len_old(struct ctdb_db_statistics
*in
)
1994 len
= sizeof(struct ctdb_db_statistics
);
1995 for (i
=0; i
<MAX_HOT_KEYS
; i
++) {
1996 len
+= in
->hot_keys
[i
].key
.dsize
;
2001 static void ctdb_db_statistics_push_old(struct ctdb_db_statistics
*in
,
2004 struct ctdb_db_statistics_wire
*wire
=
2005 (struct ctdb_db_statistics_wire
*)buf
;
2009 in
->num_hot_keys
= MAX_HOT_KEYS
;
2010 memcpy(wire
, in
, sizeof(struct ctdb_db_statistics
));
2013 for (i
=0; i
<MAX_HOT_KEYS
; i
++) {
2014 memcpy(&wire
->hot_keys_wire
[offset
],
2015 in
->hot_keys
[i
].key
.dptr
,
2016 in
->hot_keys
[i
].key
.dsize
);
2017 offset
+= in
->hot_keys
[i
].key
.dsize
;
2021 static int ctdb_db_statistics_pull_old(uint8_t *buf
, size_t buflen
,
2022 TALLOC_CTX
*mem_ctx
,
2023 struct ctdb_db_statistics
**out
)
2025 struct ctdb_db_statistics
*val
;
2026 struct ctdb_db_statistics_wire
*wire
=
2027 (struct ctdb_db_statistics_wire
*)buf
;
2031 if (buflen
< sizeof(struct ctdb_db_statistics
)) {
2036 for (i
=0; i
<wire
->dbstats
.num_hot_keys
; i
++) {
2037 if (wire
->dbstats
.hot_keys
[i
].key
.dsize
> buflen
) {
2040 if (offset
+ wire
->dbstats
.hot_keys
[i
].key
.dsize
< offset
) {
2043 offset
+= wire
->dbstats
.hot_keys
[i
].key
.dsize
;
2044 if (offset
> buflen
) {
2048 if (sizeof(struct ctdb_db_statistics
) + offset
<
2049 sizeof(struct ctdb_db_statistics
)) {
2052 if (buflen
< sizeof(struct ctdb_db_statistics
) + offset
) {
2056 val
= talloc(mem_ctx
, struct ctdb_db_statistics
);
2061 memcpy(val
, wire
, sizeof(struct ctdb_db_statistics
));
2064 for (i
=0; i
<wire
->dbstats
.num_hot_keys
; i
++) {
2068 key_size
= val
->hot_keys
[i
].key
.dsize
;
2069 ptr
= talloc_memdup(mem_ctx
, &wire
->hot_keys_wire
[offset
],
2075 val
->hot_keys
[i
].key
.dptr
= ptr
;
2083 static size_t ctdb_election_message_len_old(struct ctdb_election_message
*in
)
2085 return sizeof(struct ctdb_election_message
);
2088 static void ctdb_election_message_push_old(struct ctdb_election_message
*in
,
2091 memcpy(buf
, in
, sizeof(struct ctdb_election_message
));
2094 static int ctdb_election_message_pull_old(uint8_t *buf
, size_t buflen
,
2095 TALLOC_CTX
*mem_ctx
,
2096 struct ctdb_election_message
**out
)
2098 struct ctdb_election_message
*val
;
2100 if (buflen
< sizeof(struct ctdb_election_message
)) {
2104 val
= talloc_memdup(mem_ctx
, buf
,
2105 sizeof(struct ctdb_election_message
));
2114 static size_t ctdb_srvid_message_len_old(struct ctdb_srvid_message
*in
)
2116 return sizeof(struct ctdb_srvid_message
);
2119 static void ctdb_srvid_message_push_old(struct ctdb_srvid_message
*in
,
2122 memcpy(buf
, in
, sizeof(struct ctdb_srvid_message
));
2125 static int ctdb_srvid_message_pull_old(uint8_t *buf
, size_t buflen
,
2126 TALLOC_CTX
*mem_ctx
,
2127 struct ctdb_srvid_message
**out
)
2129 struct ctdb_srvid_message
*val
;
2131 if (buflen
< sizeof(struct ctdb_srvid_message
)) {
2135 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_srvid_message
));
2144 static size_t ctdb_disable_message_len_old(struct ctdb_disable_message
*in
)
2146 return sizeof(struct ctdb_disable_message
);
2149 static void ctdb_disable_message_push_old(struct ctdb_disable_message
*in
,
2152 memcpy(buf
, in
, sizeof(struct ctdb_disable_message
));
2155 static int ctdb_disable_message_pull_old(uint8_t *buf
, size_t buflen
,
2156 TALLOC_CTX
*mem_ctx
,
2157 struct ctdb_disable_message
**out
)
2159 struct ctdb_disable_message
*val
;
2161 if (buflen
< sizeof(struct ctdb_disable_message
)) {
2165 val
= talloc_memdup(mem_ctx
, buf
, sizeof(struct ctdb_disable_message
));
2174 static size_t ctdb_server_id_len_old(struct ctdb_server_id
*in
)
2176 return sizeof(struct ctdb_server_id
);
2179 static void ctdb_server_id_push_old(struct ctdb_server_id
*in
, uint8_t *buf
)
2181 memcpy(buf
, in
, sizeof(struct ctdb_server_id
));
2184 static int ctdb_server_id_pull_old(uint8_t *buf
, size_t buflen
,
2185 struct ctdb_server_id
*out
)
2187 if (buflen
< sizeof(struct ctdb_server_id
)) {
2191 memcpy(out
, buf
, sizeof(struct ctdb_server_id
));
2195 static size_t ctdb_g_lock_len_old(struct ctdb_g_lock
*in
)
2197 return sizeof(struct ctdb_g_lock
);
2200 static void ctdb_g_lock_push_old(struct ctdb_g_lock
*in
, uint8_t *buf
)
2202 memcpy(buf
, in
, sizeof(struct ctdb_g_lock
));
2205 static int ctdb_g_lock_pull_old(uint8_t *buf
, size_t buflen
,
2206 struct ctdb_g_lock
*out
)
2208 if (buflen
< sizeof(struct ctdb_g_lock
)) {
2212 memcpy(out
, buf
, sizeof(struct ctdb_g_lock
));
2216 static size_t ctdb_g_lock_list_len_old(struct ctdb_g_lock_list
*in
)
2218 return in
->num
* sizeof(struct ctdb_g_lock
);
2221 static void ctdb_g_lock_list_push_old(struct ctdb_g_lock_list
*in
,
2227 for (i
=0; i
<in
->num
; i
++) {
2228 ctdb_g_lock_push_old(&in
->lock
[i
], &buf
[offset
]);
2229 offset
+= sizeof(struct ctdb_g_lock
);
2233 static int ctdb_g_lock_list_pull_old(uint8_t *buf
, size_t buflen
,
2234 TALLOC_CTX
*mem_ctx
,
2235 struct ctdb_g_lock_list
**out
)
2237 struct ctdb_g_lock_list
*val
;
2243 val
= talloc_zero(mem_ctx
, struct ctdb_g_lock_list
);
2248 count
= buflen
/ sizeof(struct ctdb_g_lock
);
2249 val
->lock
= talloc_array(val
, struct ctdb_g_lock
, count
);
2250 if (val
->lock
== NULL
) {
2256 for (i
=0; i
<count
; i
++) {
2257 ret
= ctdb_g_lock_pull_old(&buf
[offset
], buflen
-offset
,
2263 offset
+= sizeof(struct ctdb_g_lock
);
2272 COMPAT_TYPE3_TEST(struct ctdb_statistics
, ctdb_statistics
);
2273 COMPAT_TYPE3_TEST(struct ctdb_vnn_map
, ctdb_vnn_map
);
2274 COMPAT_TYPE3_TEST(struct ctdb_dbid_map
, ctdb_dbid_map
);
2275 COMPAT_TYPE3_TEST(struct ctdb_pulldb
, ctdb_pulldb
);
2276 COMPAT_TYPE3_TEST(struct ctdb_pulldb_ext
, ctdb_pulldb_ext
);
2278 COMPAT_TYPE1_TEST(struct ctdb_ltdb_header
, ctdb_ltdb_header
);
2280 COMPAT_TYPE3_TEST(struct ctdb_rec_data
, ctdb_rec_data
);
2281 COMPAT_TYPE3_TEST(struct ctdb_rec_buffer
, ctdb_rec_buffer
);
2282 COMPAT_TYPE3_TEST(struct ctdb_traverse_start
, ctdb_traverse_start
);
2283 COMPAT_TYPE3_TEST(struct ctdb_traverse_all
, ctdb_traverse_all
);
2284 COMPAT_TYPE3_TEST(struct ctdb_traverse_start_ext
, ctdb_traverse_start_ext
);
2285 COMPAT_TYPE3_TEST(struct ctdb_traverse_all_ext
, ctdb_traverse_all_ext
);
2286 COMPAT_TYPE3_TEST(ctdb_sock_addr
, ctdb_sock_addr
);
2287 COMPAT_TYPE3_TEST(struct ctdb_connection
, ctdb_connection
);
2288 COMPAT_TYPE3_TEST(struct ctdb_tunable
, ctdb_tunable
);
2289 COMPAT_TYPE3_TEST(struct ctdb_node_flag_change
, ctdb_node_flag_change
);
2290 COMPAT_TYPE3_TEST(struct ctdb_var_list
, ctdb_var_list
);
2291 COMPAT_TYPE3_TEST(struct ctdb_tunable_list
, ctdb_tunable_list
);
2292 COMPAT_TYPE3_TEST(struct ctdb_tickle_list
, ctdb_tickle_list
);
2293 COMPAT_TYPE3_TEST(struct ctdb_addr_info
, ctdb_addr_info
);
2294 COMPAT_TYPE3_TEST(struct ctdb_transdb
, ctdb_transdb
);
2295 COMPAT_TYPE3_TEST(struct ctdb_uptime
, ctdb_uptime
);
2296 COMPAT_TYPE3_TEST(struct ctdb_public_ip
, ctdb_public_ip
);
2297 COMPAT_TYPE3_TEST(struct ctdb_public_ip_list
, ctdb_public_ip_list
);
2298 COMPAT_TYPE3_TEST(struct ctdb_node_and_flags
, ctdb_node_and_flags
);
2299 COMPAT_TYPE3_TEST(struct ctdb_node_map
, ctdb_node_map
);
2300 COMPAT_TYPE3_TEST(struct ctdb_script
, ctdb_script
);
2301 COMPAT_TYPE3_TEST(struct ctdb_script_list
, ctdb_script_list
);
2302 COMPAT_TYPE3_TEST(struct ctdb_ban_state
, ctdb_ban_state
);
2303 COMPAT_TYPE3_TEST(struct ctdb_notify_data
, ctdb_notify_data
);
2304 COMPAT_TYPE3_TEST(struct ctdb_iface
, ctdb_iface
);
2305 COMPAT_TYPE3_TEST(struct ctdb_iface_list
, ctdb_iface_list
);
2306 COMPAT_TYPE3_TEST(struct ctdb_public_ip_info
, ctdb_public_ip_info
);
2307 COMPAT_TYPE3_TEST(struct ctdb_statistics_list
, ctdb_statistics_list
);
2308 COMPAT_TYPE3_TEST(struct ctdb_key_data
, ctdb_key_data
);
2309 COMPAT_TYPE3_TEST(struct ctdb_db_statistics
, ctdb_db_statistics
);
2311 COMPAT_TYPE3_TEST(struct ctdb_election_message
, ctdb_election_message
);
2312 COMPAT_TYPE3_TEST(struct ctdb_srvid_message
, ctdb_srvid_message
);
2313 COMPAT_TYPE3_TEST(struct ctdb_disable_message
, ctdb_disable_message
);
2315 COMPAT_TYPE1_TEST(struct ctdb_server_id
, ctdb_server_id
);
2316 COMPAT_TYPE1_TEST(struct ctdb_g_lock
, ctdb_g_lock
);
2318 COMPAT_TYPE3_TEST(struct ctdb_g_lock_list
, ctdb_g_lock_list
);
2320 static void protocol_types_compat_test(void)
2322 COMPAT_TEST_FUNC(ctdb_statistics
)();
2323 COMPAT_TEST_FUNC(ctdb_vnn_map
)();
2324 COMPAT_TEST_FUNC(ctdb_dbid_map
)();
2325 COMPAT_TEST_FUNC(ctdb_pulldb
)();
2326 COMPAT_TEST_FUNC(ctdb_pulldb_ext
)();
2327 COMPAT_TEST_FUNC(ctdb_ltdb_header
)();
2328 COMPAT_TEST_FUNC(ctdb_rec_data
)();
2329 COMPAT_TEST_FUNC(ctdb_rec_buffer
)();
2330 COMPAT_TEST_FUNC(ctdb_traverse_start
)();
2331 COMPAT_TEST_FUNC(ctdb_traverse_all
)();
2332 COMPAT_TEST_FUNC(ctdb_traverse_start_ext
)();
2333 COMPAT_TEST_FUNC(ctdb_traverse_all_ext
)();
2334 COMPAT_TEST_FUNC(ctdb_sock_addr
)();
2335 COMPAT_TEST_FUNC(ctdb_connection
)();
2336 COMPAT_TEST_FUNC(ctdb_tunable
)();
2337 COMPAT_TEST_FUNC(ctdb_node_flag_change
)();
2338 COMPAT_TEST_FUNC(ctdb_var_list
)();
2339 COMPAT_TEST_FUNC(ctdb_tunable_list
)();
2340 COMPAT_TEST_FUNC(ctdb_tickle_list
)();
2341 COMPAT_TEST_FUNC(ctdb_addr_info
)();
2342 COMPAT_TEST_FUNC(ctdb_transdb
)();
2343 COMPAT_TEST_FUNC(ctdb_uptime
)();
2344 COMPAT_TEST_FUNC(ctdb_public_ip
)();
2345 COMPAT_TEST_FUNC(ctdb_public_ip_list
)();
2346 COMPAT_TEST_FUNC(ctdb_node_and_flags
)();
2347 COMPAT_TEST_FUNC(ctdb_node_map
)();
2348 COMPAT_TEST_FUNC(ctdb_script
)();
2349 COMPAT_TEST_FUNC(ctdb_script_list
)();
2350 COMPAT_TEST_FUNC(ctdb_ban_state
)();
2351 COMPAT_TEST_FUNC(ctdb_notify_data
)();
2352 COMPAT_TEST_FUNC(ctdb_iface
)();
2353 COMPAT_TEST_FUNC(ctdb_iface_list
)();
2354 COMPAT_TEST_FUNC(ctdb_public_ip_info
)();
2355 COMPAT_TEST_FUNC(ctdb_statistics_list
)();
2356 COMPAT_TEST_FUNC(ctdb_key_data
)();
2357 COMPAT_TEST_FUNC(ctdb_db_statistics
)();
2359 COMPAT_TEST_FUNC(ctdb_election_message
)();
2360 COMPAT_TEST_FUNC(ctdb_srvid_message
)();
2361 COMPAT_TEST_FUNC(ctdb_disable_message
)();
2362 COMPAT_TEST_FUNC(ctdb_server_id
)();
2363 COMPAT_TEST_FUNC(ctdb_g_lock
)();
2364 COMPAT_TEST_FUNC(ctdb_g_lock_list
)();
2367 int main(int argc
, const char *argv
[])
2369 protocol_test_iterate(argc
, argv
, protocol_types_compat_test
);