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); \
60 VERIFY_FUNC(NAME)(&p1, &p2); \
61 talloc_free(mem_ctx); \
64 #define COMPAT_TYPE3_TEST(TYPE, NAME) \
65 static void COMPAT_TEST_FUNC(NAME)(void) \
67 TALLOC_CTX *mem_ctx; \
68 uint8_t *buf1, *buf2; \
70 size_t buflen1, buflen2, np = 0; \
73 mem_ctx = talloc_new(NULL); \
74 assert(mem_ctx != NULL); \
75 p = talloc_zero(mem_ctx, TYPE); \
77 FILL_FUNC(NAME)(p, p); \
78 buflen1 = LEN_FUNC(NAME)(p); \
79 buflen2 = OLD_LEN_FUNC(NAME)(p); \
80 assert(buflen1 == buflen2); \
81 buf1 = talloc_zero_size(mem_ctx, buflen1); \
82 assert(buf1 != NULL); \
83 buf2 = talloc_zero_size(mem_ctx, buflen2); \
84 assert(buf2 != NULL); \
85 PUSH_FUNC(NAME)(p, buf1, &np); \
86 OLD_PUSH_FUNC(NAME)(p, buf2); \
87 assert(memcmp(buf1, buf2, buflen1) == 0); \
88 ret = PULL_FUNC(NAME)(buf1, buflen1, mem_ctx, &p1, &np); \
90 ret = OLD_PULL_FUNC(NAME)(buf2, buflen2, mem_ctx, &p2); \
91 VERIFY_FUNC(NAME)(p1, p2); \
92 talloc_free(mem_ctx); \
96 static size_t ctdb_statistics_len_old(struct ctdb_statistics *in)
98 return sizeof(struct ctdb_statistics);
101 static void ctdb_statistics_push_old(struct ctdb_statistics *in, uint8_t *buf)
103 memcpy(buf, in, sizeof(struct ctdb_statistics));
106 static int ctdb_statistics_pull_old(uint8_t *buf, size_t buflen,
108 struct ctdb_statistics **out)
110 struct ctdb_statistics *val;
112 if (buflen < sizeof(struct ctdb_statistics)) {
116 val = talloc(mem_ctx, struct ctdb_statistics);
121 memcpy(val, buf, sizeof(struct ctdb_statistics));
127 struct ctdb_vnn_map_wire {
133 static size_t ctdb_vnn_map_len_old(struct ctdb_vnn_map *in)
135 return offsetof(struct ctdb_vnn_map, map) +
136 in->size * sizeof(uint32_t);
139 static void ctdb_vnn_map_push_old(struct ctdb_vnn_map *in, uint8_t *buf)
141 struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
143 memcpy(wire, in, offsetof(struct ctdb_vnn_map, map));
144 memcpy(wire->map, in->map, in->size * sizeof(uint32_t));
147 static int ctdb_vnn_map_pull_old(uint8_t *buf, size_t buflen,
149 struct ctdb_vnn_map **out)
151 struct ctdb_vnn_map *val;
152 struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
154 if (buflen < offsetof(struct ctdb_vnn_map_wire, map)) {
157 if (wire->size > buflen / sizeof(uint32_t)) {
160 if (offsetof(struct ctdb_vnn_map_wire, map) +
161 wire->size * sizeof(uint32_t) <
162 offsetof(struct ctdb_vnn_map_wire, map)) {
165 if (buflen < offsetof(struct ctdb_vnn_map_wire, map) +
166 wire->size * sizeof(uint32_t)) {
170 val = talloc(mem_ctx, struct ctdb_vnn_map);
175 memcpy(val, wire, offsetof(struct ctdb_vnn_map, map));
177 val->map = talloc_memdup(val, wire->map,
178 wire->size * sizeof(uint32_t));
179 if (val->map == NULL) {
188 struct ctdb_dbid_map_wire {
190 struct ctdb_dbid dbs[1];
193 static size_t ctdb_dbid_map_len_old(struct ctdb_dbid_map *in)
195 return sizeof(uint32_t) + in->num * sizeof(struct ctdb_dbid);
198 static void ctdb_dbid_map_push_old(struct ctdb_dbid_map *in, uint8_t *buf)
200 struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
203 memcpy(wire->dbs, in->dbs, in->num * sizeof(struct ctdb_dbid));
206 static int ctdb_dbid_map_pull_old(uint8_t *buf, size_t buflen,
208 struct ctdb_dbid_map **out)
210 struct ctdb_dbid_map *val;
211 struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
213 if (buflen < sizeof(uint32_t)) {
216 if (wire->num > buflen / sizeof(struct ctdb_dbid)) {
219 if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid) <
223 if (buflen < sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid)) {
227 val = talloc(mem_ctx, struct ctdb_dbid_map);
232 val->num = wire->num;
234 val->dbs = talloc_memdup(val, wire->dbs,
235 wire->num * sizeof(struct ctdb_dbid));
236 if (val->dbs == NULL) {
245 static size_t ctdb_pulldb_len_old(struct ctdb_pulldb *in)
247 return sizeof(struct ctdb_pulldb);
250 static void ctdb_pulldb_push_old(struct ctdb_pulldb *in, uint8_t *buf)
252 memcpy(buf, in, sizeof(struct ctdb_pulldb));
255 static int ctdb_pulldb_pull_old(uint8_t *buf, size_t buflen,
256 TALLOC_CTX *mem_ctx, struct ctdb_pulldb **out)
258 struct ctdb_pulldb *val;
260 if (buflen < sizeof(struct ctdb_pulldb)) {
264 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb));
273 static size_t ctdb_pulldb_ext_len_old(struct ctdb_pulldb_ext *in)
275 return sizeof(struct ctdb_pulldb_ext);
278 static void ctdb_pulldb_ext_push_old(struct ctdb_pulldb_ext *in, uint8_t *buf)
280 memcpy(buf, in, sizeof(struct ctdb_pulldb_ext));
283 static int ctdb_pulldb_ext_pull_old(uint8_t *buf, size_t buflen,
285 struct ctdb_pulldb_ext **out)
287 struct ctdb_pulldb_ext *val;
289 if (buflen < sizeof(struct ctdb_pulldb_ext)) {
293 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb_ext));
302 static size_t ctdb_ltdb_header_len_old(struct ctdb_ltdb_header *in)
304 return sizeof(struct ctdb_ltdb_header);
307 static void ctdb_ltdb_header_push_old(struct ctdb_ltdb_header *in,
310 memcpy(buf, in, sizeof(struct ctdb_ltdb_header));
313 static int ctdb_ltdb_header_pull_old(uint8_t *buf, size_t buflen,
314 struct ctdb_ltdb_header *out)
316 if (buflen < sizeof(struct ctdb_ltdb_header)) {
320 memcpy(out, buf, sizeof(struct ctdb_ltdb_header));
324 struct ctdb_rec_data_wire {
332 static size_t ctdb_rec_data_len_old(struct ctdb_rec_data *in)
334 return offsetof(struct ctdb_rec_data_wire, data) +
335 in->key.dsize + in->data.dsize +
336 (in->header == NULL ? 0 : sizeof(struct ctdb_ltdb_header));
339 static void ctdb_rec_data_push_old(struct ctdb_rec_data *in, uint8_t *buf)
341 struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
344 wire->length = ctdb_rec_data_len(in);
345 wire->reqid = in->reqid;
346 wire->keylen = in->key.dsize;
347 wire->datalen = in->data.dsize;
348 if (in->header != NULL) {
349 wire->datalen += sizeof(struct ctdb_ltdb_header);
352 memcpy(wire->data, in->key.dptr, in->key.dsize);
353 offset = in->key.dsize;
354 if (in->header != NULL) {
355 memcpy(&wire->data[offset], in->header,
356 sizeof(struct ctdb_ltdb_header));
357 offset += sizeof(struct ctdb_ltdb_header);
359 if (in->data.dsize > 0) {
360 memcpy(&wire->data[offset], in->data.dptr, in->data.dsize);
364 static int ctdb_rec_data_pull_data_old(uint8_t *buf, size_t buflen,
366 struct ctdb_ltdb_header **header,
367 TDB_DATA *key, TDB_DATA *data,
370 struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
373 if (buflen < offsetof(struct ctdb_rec_data_wire, data)) {
376 if (wire->keylen > buflen || wire->datalen > buflen) {
379 if (offsetof(struct ctdb_rec_data_wire, data) + wire->keylen <
380 offsetof(struct ctdb_rec_data_wire, data)) {
383 if (offsetof(struct ctdb_rec_data_wire, data) +
384 wire->keylen + wire->datalen <
385 offsetof(struct ctdb_rec_data_wire, data)) {
388 if (buflen < offsetof(struct ctdb_rec_data_wire, data) +
389 wire->keylen + wire->datalen) {
393 *reqid = wire->reqid;
395 key->dsize = wire->keylen;
396 key->dptr = wire->data;
397 offset = wire->keylen;
399 /* Always set header to NULL. If it is required, exact it using
400 * ctdb_rec_data_extract_header()
404 data->dsize = wire->datalen;
405 data->dptr = &wire->data[offset];
407 *reclen = offsetof(struct ctdb_rec_data_wire, data) +
408 wire->keylen + wire->datalen;
413 static int ctdb_rec_data_pull_elems_old(uint8_t *buf, size_t buflen,
415 struct ctdb_rec_data *out)
418 struct ctdb_ltdb_header *header;
423 ret = ctdb_rec_data_pull_data_old(buf, buflen, &reqid, &header,
424 &key, &data, &reclen);
432 out->key.dsize = key.dsize;
434 out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
435 if (out->key.dptr == NULL) {
440 out->data.dsize = data.dsize;
441 if (data.dsize > 0) {
442 out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
443 if (out->data.dptr == NULL) {
451 static int ctdb_rec_data_pull_old(uint8_t *buf, size_t buflen,
453 struct ctdb_rec_data **out)
455 struct ctdb_rec_data *val;
458 val = talloc(mem_ctx, struct ctdb_rec_data);
463 ret = ctdb_rec_data_pull_elems_old(buf, buflen, val, val);
473 struct ctdb_rec_buffer_wire {
479 static size_t ctdb_rec_buffer_len_old(struct ctdb_rec_buffer *in)
481 return offsetof(struct ctdb_rec_buffer_wire, data) + in->buflen;
484 static void ctdb_rec_buffer_push_old(struct ctdb_rec_buffer *in, uint8_t *buf)
486 struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
488 wire->db_id = in->db_id;
489 wire->count = in->count;
490 if (in->buflen > 0) {
491 memcpy(wire->data, in->buf, in->buflen);
495 static int ctdb_rec_buffer_pull_old(uint8_t *buf, size_t buflen,
497 struct ctdb_rec_buffer **out)
499 struct ctdb_rec_buffer *val;
500 struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
503 if (buflen < offsetof(struct ctdb_rec_buffer_wire, data)) {
507 val = talloc(mem_ctx, struct ctdb_rec_buffer);
512 val->db_id = wire->db_id;
513 val->count = wire->count;
515 offset = offsetof(struct ctdb_rec_buffer_wire, data);
516 val->buflen = buflen - offset;
517 val->buf = talloc_memdup(val, wire->data, val->buflen);
518 if (val->buf == NULL) {
527 static size_t ctdb_traverse_start_len_old(struct ctdb_traverse_start *in)
529 return sizeof(struct ctdb_traverse_start);
532 static void ctdb_traverse_start_push_old(struct ctdb_traverse_start *in,
535 memcpy(buf, in, sizeof(struct ctdb_traverse_start));
538 static int ctdb_traverse_start_pull_old(uint8_t *buf, size_t buflen,
540 struct ctdb_traverse_start **out)
542 struct ctdb_traverse_start *val;
544 if (buflen < sizeof(struct ctdb_traverse_start)) {
548 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_traverse_start));
557 static size_t ctdb_traverse_all_len_old(struct ctdb_traverse_all *in)
559 return sizeof(struct ctdb_traverse_all);
562 static void ctdb_traverse_all_push_old(struct ctdb_traverse_all *in,
565 memcpy(buf, in, sizeof(struct ctdb_traverse_all));
568 static int ctdb_traverse_all_pull_old(uint8_t *buf, size_t buflen,
570 struct ctdb_traverse_all **out)
572 struct ctdb_traverse_all *val;
574 if (buflen < sizeof(struct ctdb_traverse_all)) {
578 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_traverse_all));
587 static size_t ctdb_traverse_start_ext_len_old(
588 struct ctdb_traverse_start_ext *in)
590 return sizeof(struct ctdb_traverse_start_ext);
593 static void ctdb_traverse_start_ext_push_old(
594 struct ctdb_traverse_start_ext *in, uint8_t *buf)
596 memcpy(buf, in, sizeof(struct ctdb_traverse_start_ext));
599 static int ctdb_traverse_start_ext_pull_old(uint8_t *buf, size_t buflen,
601 struct ctdb_traverse_start_ext **out)
603 struct ctdb_traverse_start_ext *val;
605 if (buflen < sizeof(struct ctdb_traverse_start_ext)) {
609 val = talloc_memdup(mem_ctx, buf,
610 sizeof(struct ctdb_traverse_start_ext));
619 static size_t ctdb_traverse_all_ext_len_old(struct ctdb_traverse_all_ext *in)
621 return sizeof(struct ctdb_traverse_all_ext);
624 static void ctdb_traverse_all_ext_push_old(struct ctdb_traverse_all_ext *in,
627 memcpy(buf, in, sizeof(struct ctdb_traverse_all_ext));
630 static int ctdb_traverse_all_ext_pull_old(uint8_t *buf, size_t buflen,
632 struct ctdb_traverse_all_ext **out)
634 struct ctdb_traverse_all_ext *val;
636 if (buflen < sizeof(struct ctdb_traverse_all_ext)) {
640 val = talloc_memdup(mem_ctx, buf,
641 sizeof(struct ctdb_traverse_all_ext));
650 static size_t ctdb_sock_addr_len_old(ctdb_sock_addr *in)
652 return sizeof(ctdb_sock_addr);
655 static void ctdb_sock_addr_push_old(ctdb_sock_addr *in, uint8_t *buf)
657 memcpy(buf, in, sizeof(ctdb_sock_addr));
660 static int ctdb_sock_addr_pull_elems_old(uint8_t *buf, size_t buflen,
664 if (buflen < sizeof(ctdb_sock_addr)) {
668 memcpy(out, buf, sizeof(ctdb_sock_addr));
673 static int ctdb_sock_addr_pull_old(uint8_t *buf, size_t buflen,
674 TALLOC_CTX *mem_ctx, ctdb_sock_addr **out)
679 val = talloc(mem_ctx, ctdb_sock_addr);
684 ret = ctdb_sock_addr_pull_elems_old(buf, buflen, val, val);
694 static size_t ctdb_connection_len_old(struct ctdb_connection *in)
696 return sizeof(struct ctdb_connection);
699 static void ctdb_connection_push_old(struct ctdb_connection *in, uint8_t *buf)
701 memcpy(buf, in, sizeof(struct ctdb_connection));
704 static int ctdb_connection_pull_elems_old(uint8_t *buf, size_t buflen,
706 struct ctdb_connection *out)
708 if (buflen < sizeof(struct ctdb_connection)) {
712 memcpy(out, buf, sizeof(struct ctdb_connection));
717 static int ctdb_connection_pull_old(uint8_t *buf, size_t buflen,
719 struct ctdb_connection **out)
721 struct ctdb_connection *val;
724 val = talloc(mem_ctx, struct ctdb_connection);
729 ret = ctdb_connection_pull_elems_old(buf, buflen, val, val);
739 struct ctdb_tunable_wire {
745 static size_t ctdb_tunable_len_old(struct ctdb_tunable *in)
747 return offsetof(struct ctdb_tunable_wire, name) +
748 strlen(in->name) + 1;
751 static void ctdb_tunable_push_old(struct ctdb_tunable *in, uint8_t *buf)
753 struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
755 wire->value = in->value;
756 wire->length = strlen(in->name) + 1;
757 memcpy(wire->name, in->name, wire->length);
760 static int ctdb_tunable_pull_old(uint8_t *buf, size_t buflen,
762 struct ctdb_tunable **out)
764 struct ctdb_tunable *val;
765 struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
767 if (buflen < offsetof(struct ctdb_tunable_wire, name)) {
770 if (wire->length > buflen) {
773 if (offsetof(struct ctdb_tunable_wire, name) + wire->length <
774 offsetof(struct ctdb_tunable_wire, name)) {
777 if (buflen < offsetof(struct ctdb_tunable_wire, name) + wire->length) {
781 val = talloc(mem_ctx, struct ctdb_tunable);
786 val->value = wire->value;
787 val->name = talloc_memdup(val, wire->name, wire->length);
788 if (val->name == NULL) {
797 static size_t ctdb_node_flag_change_len_old(struct ctdb_node_flag_change *in)
799 return sizeof(struct ctdb_node_flag_change);
802 static void ctdb_node_flag_change_push_old(struct ctdb_node_flag_change *in,
805 memcpy(buf, in, sizeof(struct ctdb_node_flag_change));
808 static int ctdb_node_flag_change_pull_old(uint8_t *buf, size_t buflen,
810 struct ctdb_node_flag_change **out)
812 struct ctdb_node_flag_change *val;
814 if (buflen < sizeof(struct ctdb_node_flag_change)) {
818 val = talloc_memdup(mem_ctx, buf,
819 sizeof(struct ctdb_node_flag_change));
828 struct ctdb_var_list_wire {
833 static size_t ctdb_var_list_len_old(struct ctdb_var_list *in)
836 size_t len = sizeof(uint32_t);
838 for (i=0; i<in->count; i++) {
839 len += strlen(in->var[i]) + 1;
844 static void ctdb_var_list_push_old(struct ctdb_var_list *in, uint8_t *buf)
846 struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
851 n = sprintf(wire->list_str, "%s", in->var[0]);
854 for (i=1; i<in->count; i++) {
855 n = sprintf(&wire->list_str[offset], ":%s", in->var[i]);
858 wire->length = offset + 1;
861 static int ctdb_var_list_pull_old(uint8_t *buf, size_t buflen,
863 struct ctdb_var_list **out)
865 struct ctdb_var_list *val = NULL;
866 struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
867 char *str, *s, *tok, *ptr;
870 if (buflen < sizeof(uint32_t)) {
873 if (wire->length > buflen) {
876 if (sizeof(uint32_t) + wire->length < sizeof(uint32_t)) {
879 if (buflen < sizeof(uint32_t) + wire->length) {
883 str = talloc_strndup(mem_ctx, (char *)wire->list_str, wire->length);
888 val = talloc_zero(mem_ctx, struct ctdb_var_list);
894 while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
896 list = talloc_realloc(val, val->var, const char *,
903 val->var[val->count] = talloc_strdup(val, tok);
904 if (val->var[val->count] == NULL) {
920 static size_t ctdb_tunable_list_len_old(struct ctdb_tunable_list *in)
922 return sizeof(struct ctdb_tunable_list);
925 static void ctdb_tunable_list_push_old(struct ctdb_tunable_list *in,
928 memcpy(buf, in, sizeof(struct ctdb_tunable_list));
931 static int ctdb_tunable_list_pull_old(uint8_t *buf, size_t buflen,
933 struct ctdb_tunable_list **out)
935 struct ctdb_tunable_list *val;
937 if (buflen < sizeof(struct ctdb_tunable_list)) {
941 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_tunable_list));
950 struct ctdb_tickle_list_wire {
953 struct ctdb_connection conn[1];
956 static size_t ctdb_tickle_list_len_old(struct ctdb_tickle_list *in)
958 return offsetof(struct ctdb_tickle_list, conn) +
959 in->num * sizeof(struct ctdb_connection);
962 static void ctdb_tickle_list_push_old(struct ctdb_tickle_list *in,
965 struct ctdb_tickle_list_wire *wire =
966 (struct ctdb_tickle_list_wire *)buf;
970 memcpy(&wire->addr, &in->addr, sizeof(ctdb_sock_addr));
973 offset = offsetof(struct ctdb_tickle_list_wire, conn);
974 for (i=0; i<in->num; i++) {
975 ctdb_connection_push_old(&in->conn[i], &buf[offset]);
976 offset += ctdb_connection_len_old(&in->conn[i]);
980 static int ctdb_tickle_list_pull_old(uint8_t *buf, size_t buflen,
982 struct ctdb_tickle_list **out)
984 struct ctdb_tickle_list *val;
985 struct ctdb_tickle_list_wire *wire =
986 (struct ctdb_tickle_list_wire *)buf;
990 if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
993 if (wire->num > buflen / sizeof(struct ctdb_connection)) {
996 if (offsetof(struct ctdb_tickle_list_wire, conn) +
997 wire->num * sizeof(struct ctdb_connection) <
998 offsetof(struct ctdb_tickle_list_wire, conn)) {
1001 if (buflen < offsetof(struct ctdb_tickle_list_wire, conn) +
1002 wire->num * sizeof(struct ctdb_connection)) {
1006 val = talloc(mem_ctx, struct ctdb_tickle_list);
1011 offset = offsetof(struct ctdb_tickle_list, conn);
1012 memcpy(val, wire, offset);
1014 val->conn = talloc_array(val, struct ctdb_connection, wire->num);
1015 if (val->conn == NULL) {
1020 for (i=0; i<wire->num; i++) {
1021 ret = ctdb_connection_pull_elems_old(&buf[offset],
1029 offset += ctdb_connection_len_old(&val->conn[i]);
1036 struct ctdb_addr_info_wire {
1037 ctdb_sock_addr addr;
1043 static size_t ctdb_addr_info_len_old(struct ctdb_addr_info *in)
1047 len = offsetof(struct ctdb_addr_info_wire, iface);
1048 if (in->iface != NULL) {
1049 len += strlen(in->iface)+1;
1055 static void ctdb_addr_info_push_old(struct ctdb_addr_info *in, uint8_t *buf)
1057 struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
1059 wire->addr = in->addr;
1060 wire->mask = in->mask;
1061 if (in->iface == NULL) {
1064 wire->len = strlen(in->iface)+1;
1065 memcpy(wire->iface, in->iface, wire->len);
1069 static int ctdb_addr_info_pull_old(uint8_t *buf, size_t buflen,
1070 TALLOC_CTX *mem_ctx,
1071 struct ctdb_addr_info **out)
1073 struct ctdb_addr_info *val;
1074 struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
1076 if (buflen < offsetof(struct ctdb_addr_info_wire, iface)) {
1079 if (wire->len > buflen) {
1082 if (offsetof(struct ctdb_addr_info_wire, iface) + wire->len <
1083 offsetof(struct ctdb_addr_info_wire, iface)) {
1086 if (buflen < offsetof(struct ctdb_addr_info_wire, iface) + wire->len) {
1090 val = talloc(mem_ctx, struct ctdb_addr_info);
1095 val->addr = wire->addr;
1096 val->mask = wire->mask;
1098 if (wire->len == 0) {
1101 val->iface = talloc_strndup(val, wire->iface, wire->len);
1102 if (val->iface == NULL) {
1112 static size_t ctdb_transdb_len_old(struct ctdb_transdb *in)
1114 return sizeof(struct ctdb_transdb);
1117 static void ctdb_transdb_push_old(struct ctdb_transdb *in, uint8_t *buf)
1119 memcpy(buf, in, sizeof(struct ctdb_transdb));
1122 static int ctdb_transdb_pull_old(uint8_t *buf, size_t buflen,
1123 TALLOC_CTX *mem_ctx,
1124 struct ctdb_transdb **out)
1126 struct ctdb_transdb *val;
1128 if (buflen < sizeof(struct ctdb_transdb)) {
1132 val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_transdb));
1142 COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
1143 COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
1144 COMPAT_TYPE3_TEST(struct ctdb_dbid_map, ctdb_dbid_map);
1145 COMPAT_TYPE3_TEST(struct ctdb_pulldb, ctdb_pulldb);
1146 COMPAT_TYPE3_TEST(struct ctdb_pulldb_ext, ctdb_pulldb_ext);
1148 COMPAT_TYPE1_TEST(struct ctdb_ltdb_header, ctdb_ltdb_header);
1150 COMPAT_TYPE3_TEST(struct ctdb_rec_data, ctdb_rec_data);
1151 COMPAT_TYPE3_TEST(struct ctdb_rec_buffer, ctdb_rec_buffer);
1152 COMPAT_TYPE3_TEST(struct ctdb_traverse_start, ctdb_traverse_start);
1153 COMPAT_TYPE3_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
1154 COMPAT_TYPE3_TEST(struct ctdb_traverse_start_ext, ctdb_traverse_start_ext);
1155 COMPAT_TYPE3_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
1156 COMPAT_TYPE3_TEST(ctdb_sock_addr, ctdb_sock_addr);
1157 COMPAT_TYPE3_TEST(struct ctdb_connection, ctdb_connection);
1158 COMPAT_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
1159 COMPAT_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
1160 COMPAT_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
1161 COMPAT_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
1162 COMPAT_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
1163 COMPAT_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
1164 COMPAT_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
1166 int main(int argc, char *argv[])
1169 int seed = atoi(argv[1]);
1173 COMPAT_TEST_FUNC(ctdb_statistics)();
1174 COMPAT_TEST_FUNC(ctdb_vnn_map)();
1175 COMPAT_TEST_FUNC(ctdb_dbid_map)();
1176 COMPAT_TEST_FUNC(ctdb_pulldb)();
1177 COMPAT_TEST_FUNC(ctdb_pulldb_ext)();
1178 COMPAT_TEST_FUNC(ctdb_ltdb_header)();
1179 COMPAT_TEST_FUNC(ctdb_rec_data)();
1180 COMPAT_TEST_FUNC(ctdb_rec_buffer)();
1181 COMPAT_TEST_FUNC(ctdb_traverse_start)();
1182 COMPAT_TEST_FUNC(ctdb_traverse_all)();
1183 COMPAT_TEST_FUNC(ctdb_traverse_start_ext)();
1184 COMPAT_TEST_FUNC(ctdb_traverse_all_ext)();
1185 COMPAT_TEST_FUNC(ctdb_sock_addr)();
1186 COMPAT_TEST_FUNC(ctdb_connection)();
1187 COMPAT_TEST_FUNC(ctdb_tunable)();
1188 COMPAT_TEST_FUNC(ctdb_node_flag_change)();
1189 COMPAT_TEST_FUNC(ctdb_var_list)();
1190 COMPAT_TEST_FUNC(ctdb_tunable_list)();
1191 COMPAT_TEST_FUNC(ctdb_tickle_list)();
1192 COMPAT_TEST_FUNC(ctdb_addr_info)();
1193 COMPAT_TEST_FUNC(ctdb_transdb)();