ctdb-protocol: Fix marshalling for ctdb_script_list
[vlendec/samba-autobuild/.git] / ctdb / protocol / protocol_types.c
index 04a9d5c4a9bb4c180804cae29a473a7d4b5a80e3..b0409e42070375c501201043470f73837db67548 100644 (file)
@@ -1,7 +1,7 @@
 /*
    CTDB protocol marshalling
 
-   Copyright (C) Amitay Isaacs  2015
+   Copyright (C) Amitay Isaacs  2015-2017
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "protocol_private.h"
 #include "protocol_api.h"
 
-size_t ctdb_uint32_len(uint32_t val)
+size_t ctdb_tdb_data_len(TDB_DATA *in)
 {
-       return sizeof(uint32_t);
+       return in->dsize > UINT32_MAX ? UINT32_MAX : in->dsize;
 }
 
-void ctdb_uint32_push(uint32_t val, uint8_t *buf)
+void ctdb_tdb_data_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
 {
-       memcpy(buf, &val, sizeof(uint32_t));
-}
+       size_t len = ctdb_tdb_data_len(in);
 
-int ctdb_uint32_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    uint32_t *out)
-{
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
+       if (len > 0) {
+               memcpy(buf, in->dptr, len);
        }
 
-       *out = *(uint32_t *)buf;
-       return 0;
-}
-
-size_t ctdb_uint64_len(uint64_t val)
-{
-       return sizeof(uint64_t);
+       *npush = len;
 }
 
-void ctdb_uint64_push(uint64_t val, uint8_t *buf)
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      TDB_DATA *out, size_t *npull)
 {
-       memcpy(buf, &val, sizeof(uint64_t));
-}
+       TDB_DATA val;
 
-int ctdb_uint64_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    uint64_t *out)
-{
-       if (buflen < sizeof(uint64_t)) {
+       if (buflen > UINT32_MAX) {
                return EMSGSIZE;
        }
 
-       *out = *(uint64_t *)buf;
+       val.dsize = buflen;
+       if (val.dsize > 0) {
+               val.dptr = talloc_memdup(mem_ctx, buf, buflen);
+               if (val.dptr == NULL) {
+                       return ENOMEM;
+               }
+       } else {
+               val.dptr = NULL;
+       }
+
+       *out = val;
+       *npull = buflen;
        return 0;
 }
 
-size_t ctdb_double_len(double val)
+size_t ctdb_tdb_datan_len(TDB_DATA *in)
 {
-       return sizeof(double);
-}
+       uint32_t u32 = ctdb_tdb_data_len(in);
 
-void ctdb_double_push(double val, uint8_t *buf)
-{
-       memcpy(buf, &val, sizeof(double));
+       return ctdb_uint32_len(&u32) + u32;
 }
 
-int ctdb_double_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    double *out)
+void ctdb_tdb_datan_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
 {
-       if (buflen < sizeof(double)) {
-               return EMSGSIZE;
-       }
+       size_t offset = 0, np;
+       uint32_t u32 = ctdb_tdb_data_len(in);
 
-       *out = *(double *)buf;
-       return 0;
-}
+       ctdb_uint32_push(&u32, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_uint8_array_len(struct ctdb_uint8_array *array)
-{
-       return array->num * sizeof(uint8_t);
-}
+       ctdb_tdb_data_push(in, buf+offset, &np);
+       offset += np;
 
-void ctdb_uint8_array_push(struct ctdb_uint8_array *array, uint8_t *buf)
-{
-       if (array->num > 0) {
-               memcpy(buf, array->val, array->num * sizeof(uint8_t));
-       }
+       *npush = offset;
 }
 
-int ctdb_uint8_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                         struct ctdb_uint8_array **out)
+int ctdb_tdb_datan_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       TDB_DATA *out, size_t *npull)
 {
-       struct ctdb_uint8_array *array;
+       size_t offset = 0, np;
+       uint32_t u32;
+       int ret;
 
-       array = talloc(mem_ctx, struct ctdb_uint8_array);
-       if (array == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       array->num = buflen / sizeof(uint8_t);
+       if (buflen-offset < u32) {
+               return EMSGSIZE;
+       }
 
-       if (array->num > 0) {
-               array->val = talloc_array(array, uint8_t, array->num);
-               if (array->val == NULL) {
-                       talloc_free(array);
-                       return ENOMEM;
-               }
-               memcpy(array->val, buf, buflen);
-       } else {
-               array->val = NULL;
+       ret = ctdb_tdb_data_pull(buf+offset, u32, mem_ctx, out, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = array;
+       *npull = offset;
        return 0;
 }
 
-size_t ctdb_uint64_array_len(struct ctdb_uint64_array *array)
+size_t ctdb_latency_counter_len(struct ctdb_latency_counter *in)
 {
-       return array->num * sizeof(uint64_t);
+       return ctdb_int32_len(&in->num) +
+               ctdb_padding_len(4) +
+               ctdb_double_len(&in->min) +
+               ctdb_double_len(&in->max) +
+               ctdb_double_len(&in->total);
 }
 
-void ctdb_uint64_array_push(struct ctdb_uint64_array *array, uint8_t *buf)
+void ctdb_latency_counter_push(struct ctdb_latency_counter *in, uint8_t *buf,
+                              size_t *npush)
 {
-       if (array->num > 0) {
-               memcpy(buf, array->val, array->num * sizeof(uint64_t));
-       }
-}
+       size_t offset = 0, np;
 
-int ctdb_uint64_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                          struct ctdb_uint64_array **out)
-{
-       struct ctdb_uint64_array *array;
+       ctdb_int32_push(&in->num, buf+offset, &np);
+       offset += np;
 
-       array = talloc(mem_ctx, struct ctdb_uint64_array);
-       if (array == NULL) {
-               return ENOMEM;
-       }
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
 
-       array->num = buflen / sizeof(uint64_t);
+       ctdb_double_push(&in->min, buf+offset, &np);
+       offset += np;
 
-       if (array->num > 0) {
-               array->val = talloc_array(array, uint64_t, array->num);
-               if (array->val == NULL) {
-                       talloc_free(array);
-                       return ENOMEM;
-               }
-               memcpy(array->val, buf, buflen);
-       } else {
-               array->val = NULL;
-       }
+       ctdb_double_push(&in->max, buf+offset, &np);
+       offset += np;
 
-       *out = array;
-       return 0;
-}
+       ctdb_double_push(&in->total, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_pid_len(pid_t pid)
-{
-       return sizeof(pid_t);
+       *npush = offset;
 }
 
-void ctdb_pid_push(pid_t pid, uint8_t *buf)
+int ctdb_latency_counter_pull(uint8_t *buf, size_t buflen,
+                             struct ctdb_latency_counter *out, size_t *npull)
 {
-       memcpy(buf, &pid, sizeof(pid_t));
-}
+       size_t offset = 0, np;
+       int ret;
 
-int ctdb_pid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                 pid_t *out)
-{
-       if (buflen < sizeof(pid_t)) {
-               return EMSGSIZE;
+       ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->num, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = *(pid_t *)buf;
-       return 0;
-}
-
-size_t ctdb_string_len(const char *str)
-{
-       if (str == NULL) {
-               return 0;
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
        }
-       return strlen(str) + 1;
-}
+       offset += np;
 
-void ctdb_string_push(const char *str, uint8_t *buf)
-{
-       if (str == NULL) {
-               return;
+       ret = ctdb_double_pull(buf+offset, buflen-offset, &out->min, &np);
+       if (ret != 0) {
+               return ret;
        }
-       memcpy(buf, str, strlen(str)+1);
-}
+       offset += np;
 
-int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    const char **out)
-{
-       char *str;
-
-       if (buflen == 0) {
-               *out = NULL;
-               return 0;
+       ret = ctdb_double_pull(buf+offset, buflen-offset, &out->max, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       str = talloc_strndup(mem_ctx, (char *)buf, buflen);
-       if (str == NULL) {
-               return ENOMEM;
+       ret = ctdb_double_pull(buf+offset, buflen-offset, &out->total, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = str;
+       *npull = offset;
        return 0;
 }
 
-struct stringn_wire {
-       uint32_t length;
-       uint8_t str[1];
-};
-
-size_t ctdb_stringn_len(const char *str)
-{
-       return sizeof(uint32_t) + strlen(str) + 1;
-}
+size_t ctdb_statistics_len(struct ctdb_statistics *in)
+{
+       return ctdb_uint32_len(&in->num_clients) +
+               ctdb_uint32_len(&in->frozen) +
+               ctdb_uint32_len(&in->recovering) +
+               ctdb_uint32_len(&in->client_packets_sent) +
+               ctdb_uint32_len(&in->client_packets_recv) +
+               ctdb_uint32_len(&in->node_packets_sent) +
+               ctdb_uint32_len(&in->node_packets_recv) +
+               ctdb_uint32_len(&in->keepalive_packets_sent) +
+               ctdb_uint32_len(&in->keepalive_packets_recv) +
+               ctdb_uint32_len(&in->node.req_call) +
+               ctdb_uint32_len(&in->node.reply_call) +
+               ctdb_uint32_len(&in->node.req_dmaster) +
+               ctdb_uint32_len(&in->node.reply_dmaster) +
+               ctdb_uint32_len(&in->node.reply_error) +
+               ctdb_uint32_len(&in->node.req_message) +
+               ctdb_uint32_len(&in->node.req_control) +
+               ctdb_uint32_len(&in->node.reply_control) +
+               ctdb_uint32_len(&in->client.req_call) +
+               ctdb_uint32_len(&in->client.req_message) +
+               ctdb_uint32_len(&in->client.req_control) +
+               ctdb_uint32_len(&in->timeouts.call) +
+               ctdb_uint32_len(&in->timeouts.control) +
+               ctdb_uint32_len(&in->timeouts.traverse) +
+               ctdb_padding_len(4) +
+               ctdb_latency_counter_len(&in->reclock.ctdbd) +
+               ctdb_latency_counter_len(&in->reclock.recd) +
+               ctdb_uint32_len(&in->locks.num_calls) +
+               ctdb_uint32_len(&in->locks.num_current) +
+               ctdb_uint32_len(&in->locks.num_pending) +
+               ctdb_uint32_len(&in->locks.num_failed) +
+               ctdb_latency_counter_len(&in->locks.latency) +
+               MAX_COUNT_BUCKETS * ctdb_uint32_len(&in->locks.buckets[0]) +
+               ctdb_uint32_len(&in->total_calls) +
+               ctdb_uint32_len(&in->pending_calls) +
+               ctdb_uint32_len(&in->childwrite_calls) +
+               ctdb_uint32_len(&in->pending_childwrite_calls) +
+               ctdb_uint32_len(&in->memory_used) +
+               ctdb_uint32_len(&in->__last_counter) +
+               ctdb_uint32_len(&in->max_hop_count) +
+               MAX_COUNT_BUCKETS *
+                       ctdb_uint32_len(&in->hop_count_bucket[0]) +
+               ctdb_padding_len(4) +
+               ctdb_latency_counter_len(&in->call_latency) +
+               ctdb_latency_counter_len(&in->childwrite_latency) +
+               ctdb_uint32_len(&in->num_recoveries) +
+               ctdb_padding_len(4) +
+               ctdb_timeval_len(&in->statistics_start_time) +
+               ctdb_timeval_len(&in->statistics_current_time) +
+               ctdb_uint32_len(&in->total_ro_delegations) +
+               ctdb_uint32_len(&in->total_ro_revokes);
+}
+
+void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
+                         size_t *npush)
+{
+       size_t offset = 0, np;
+       int i;
 
-void ctdb_stringn_push(const char *str, uint8_t *buf)
-{
-       struct stringn_wire *wire = (struct stringn_wire *)buf;
+       ctdb_uint32_push(&in->num_clients, buf+offset, &np);
+       offset += np;
 
-       if (str == NULL) {
-               wire->length = 0;
-       } else {
-               wire->length = strlen(str) + 1;
-               memcpy(wire->str, str, wire->length);
-       }
-}
+       ctdb_uint32_push(&in->frozen, buf+offset, &np);
+       offset += np;
 
-int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                     const char **out)
-{
-       char *str;
-       struct stringn_wire *wire = (struct stringn_wire *)buf;
+       ctdb_uint32_push(&in->recovering, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (wire->length > buflen) {
-               return EMSGSIZE;
-       }
-       if (sizeof(uint32_t) + wire->length < sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (buflen < sizeof(uint32_t) + wire->length) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->client_packets_sent, buf+offset, &np);
+       offset += np;
 
-       str = talloc_strndup(mem_ctx, (char *)wire->str, wire->length);
-       if (str == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->client_packets_recv, buf+offset, &np);
+       offset += np;
 
-       *out = str;
-       return 0;
-}
+       ctdb_uint32_push(&in->node_packets_sent, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_statistics_len(struct ctdb_statistics *stats)
-{
-       return sizeof(struct ctdb_statistics);
-}
+       ctdb_uint32_push(&in->node_packets_recv, buf+offset, &np);
+       offset += np;
 
-void ctdb_statistics_push(struct ctdb_statistics *stats, uint8_t *buf)
-{
-       memcpy(buf, stats, sizeof(struct ctdb_statistics));
-}
+       ctdb_uint32_push(&in->keepalive_packets_sent, buf+offset, &np);
+       offset += np;
 
-int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                        struct ctdb_statistics **out)
-{
-       struct ctdb_statistics *stats;
-       struct ctdb_statistics *wire = (struct ctdb_statistics *)buf;
+       ctdb_uint32_push(&in->keepalive_packets_recv, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_statistics)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->node.req_call, buf+offset, &np);
+       offset += np;
 
-       stats = talloc(mem_ctx, struct ctdb_statistics);
-       if (stats == NULL) {
-               return ENOMEM;
-       }
-       memcpy(stats, wire, sizeof(struct ctdb_statistics));
+       ctdb_uint32_push(&in->node.reply_call, buf+offset, &np);
+       offset += np;
 
-       *out = stats;
-       return 0;
-}
+       ctdb_uint32_push(&in->node.req_dmaster, buf+offset, &np);
+       offset += np;
 
-struct ctdb_statistics_list_wire {
-       uint32_t num;
-       struct ctdb_statistics stats[1];
-};
+       ctdb_uint32_push(&in->node.reply_dmaster, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_statistics_list_len(struct ctdb_statistics_list *stats_list)
-{
-       return offsetof(struct ctdb_statistics_list_wire, stats) +
-              stats_list->num * sizeof(struct ctdb_statistics);
-}
+       ctdb_uint32_push(&in->node.reply_error, buf+offset, &np);
+       offset += np;
 
-void ctdb_statistics_list_push(struct ctdb_statistics_list *stats_list,
-                              uint8_t *buf)
-{
-       struct ctdb_statistics_list_wire *wire =
-               (struct ctdb_statistics_list_wire *)buf;
+       ctdb_uint32_push(&in->node.req_message, buf+offset, &np);
+       offset += np;
 
-       wire->num = stats_list->num;
-       memcpy(wire->stats, stats_list->stats,
-              stats_list->num * sizeof(struct ctdb_statistics));
-}
+       ctdb_uint32_push(&in->node.req_control, buf+offset, &np);
+       offset += np;
 
-int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                             struct ctdb_statistics_list **out)
-{
-       struct ctdb_statistics_list *stats_list;
-       struct ctdb_statistics_list_wire *wire =
-               (struct ctdb_statistics_list_wire *)buf;
+       ctdb_uint32_push(&in->node.reply_control, buf+offset, &np);
+       offset += np;
 
-       if (buflen < offsetof(struct ctdb_statistics_list_wire, stats)) {
-               return EMSGSIZE;
-       }
-       if (wire->num > buflen / sizeof(struct ctdb_statistics)) {
-               return EMSGSIZE;
-       }
-       if (offsetof(struct ctdb_statistics_list_wire, stats) +
-           wire->num * sizeof(struct ctdb_statistics) <
-           offsetof(struct ctdb_statistics_list_wire, stats)) {
-               return EMSGSIZE;
-       }
-       if (buflen < offsetof(struct ctdb_statistics_list_wire, stats) +
-                    wire->num * sizeof(struct ctdb_statistics)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->client.req_call, buf+offset, &np);
+       offset += np;
 
-       stats_list = talloc(mem_ctx, struct ctdb_statistics_list);
-       if (stats_list == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->client.req_message, buf+offset, &np);
+       offset += np;
 
-       stats_list->num = wire->num;
+       ctdb_uint32_push(&in->client.req_control, buf+offset, &np);
+       offset += np;
 
-       stats_list->stats = talloc_array(stats_list, struct ctdb_statistics,
-                                        wire->num);
-       if (stats_list->stats == NULL) {
-               talloc_free(stats_list);
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->timeouts.call, buf+offset, &np);
+       offset += np;
 
-       memcpy(stats_list->stats, wire->stats,
-              wire->num * sizeof(struct ctdb_statistics));
+       ctdb_uint32_push(&in->timeouts.control, buf+offset, &np);
+       offset += np;
 
-       *out = stats_list;
-       return 0;
-}
+       ctdb_uint32_push(&in->timeouts.traverse, buf+offset, &np);
+       offset += np;
 
-struct ctdb_vnn_map_wire {
-       uint32_t generation;
-       uint32_t size;
-       uint32_t map[1];
-};
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_vnn_map_len(struct ctdb_vnn_map *vnnmap)
-{
-       return offsetof(struct ctdb_vnn_map, map) +
-              vnnmap->size * sizeof(uint32_t);
-}
+       ctdb_latency_counter_push(&in->reclock.ctdbd, buf+offset, &np);
+       offset += np;
 
-void ctdb_vnn_map_push(struct ctdb_vnn_map *vnnmap, uint8_t *buf)
-{
-       struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
+       ctdb_latency_counter_push(&in->reclock.recd, buf+offset, &np);
+       offset += np;
 
-       memcpy(wire, vnnmap, offsetof(struct ctdb_vnn_map, map));
-       memcpy(wire->map, vnnmap->map, vnnmap->size * sizeof(uint32_t));
-}
+       ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
+       offset += np;
 
-int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                     struct ctdb_vnn_map **out)
-{
-       struct ctdb_vnn_map *vnnmap;
-       struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
+       ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
+       offset += np;
 
-       if (buflen < offsetof(struct ctdb_vnn_map_wire, map)) {
-               return EMSGSIZE;
-       }
-       if (wire->size > buflen / sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (offsetof(struct ctdb_vnn_map_wire, map) +
-           wire->size * sizeof(uint32_t) <
-           offsetof(struct ctdb_vnn_map_wire, map)) {
-                   return EMSGSIZE;
-       }
-       if (buflen < offsetof(struct ctdb_vnn_map_wire, map) +
-                    wire->size * sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
+       offset += np;
 
-       vnnmap = talloc(mem_ctx, struct ctdb_vnn_map);
-       if (vnnmap == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
+       offset += np;
 
-       memcpy(vnnmap, wire, offsetof(struct ctdb_vnn_map, map));
+       ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
+       offset += np;
 
-       vnnmap->map = talloc_memdup(vnnmap, wire->map,
-                                   wire->size * sizeof(uint32_t));
-       if (vnnmap->map == NULL) {
-               talloc_free(vnnmap);
-               return ENOMEM;
+       for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+               ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
+               offset += np;
        }
 
-       *out = vnnmap;
-       return 0;
-}
+       ctdb_uint32_push(&in->total_calls, buf+offset, &np);
+       offset += np;
 
-struct ctdb_dbid_map_wire {
-       uint32_t num;
-       struct ctdb_dbid dbs[1];
-};
+       ctdb_uint32_push(&in->pending_calls, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_dbid_map_len(struct ctdb_dbid_map *dbmap)
-{
-       return sizeof(uint32_t) + dbmap->num * sizeof(struct ctdb_dbid);
-}
+       ctdb_uint32_push(&in->childwrite_calls, buf+offset, &np);
+       offset += np;
 
-void ctdb_dbid_map_push(struct ctdb_dbid_map *dbmap, uint8_t *buf)
-{
-       struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+       ctdb_uint32_push(&in->pending_childwrite_calls, buf+offset, &np);
+       offset += np;
 
-       wire->num = dbmap->num;
-       memcpy(wire->dbs, dbmap->dbs, dbmap->num * sizeof(struct ctdb_dbid));
-}
+       ctdb_uint32_push(&in->memory_used, buf+offset, &np);
+       offset += np;
 
-int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                      struct ctdb_dbid_map **out)
-{
-       struct ctdb_dbid_map *dbmap;
-       struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+       ctdb_uint32_push(&in->__last_counter, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (wire->num > buflen / sizeof(struct ctdb_dbid)) {
-               return EMSGSIZE;
-       }
-       if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid) <
-           sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (buflen < sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->max_hop_count, buf+offset, &np);
+       offset += np;
 
-       dbmap = talloc(mem_ctx, struct ctdb_dbid_map);
-       if (dbmap == NULL) {
-               return ENOMEM;
+       for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+               ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
+               offset += np;
        }
 
-       dbmap->num = wire->num;
-
-       dbmap->dbs = talloc_memdup(dbmap, wire->dbs,
-                                  wire->num * sizeof(struct ctdb_dbid));
-       if (dbmap->dbs == NULL) {
-               talloc_free(dbmap);
-               return ENOMEM;
-       }
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
 
-       *out = dbmap;
-       return 0;
-}
+       ctdb_latency_counter_push(&in->call_latency, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb)
-{
-       return sizeof(struct ctdb_pulldb);
-}
+       ctdb_latency_counter_push(&in->childwrite_latency, buf+offset, &np);
+       offset += np;
 
-void ctdb_pulldb_push(struct ctdb_pulldb *pulldb, uint8_t *buf)
-{
-       memcpy(buf, pulldb, sizeof(struct ctdb_pulldb));
-}
+       ctdb_uint32_push(&in->num_recoveries, buf+offset, &np);
+       offset += np;
 
-int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    struct ctdb_pulldb **out)
-{
-       struct ctdb_pulldb *pulldb;
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_pulldb)) {
-               return EMSGSIZE;
-       }
+       ctdb_timeval_push(&in->statistics_start_time, buf+offset, &np);
+       offset += np;
 
-       pulldb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb));
-       if (pulldb == NULL) {
-               return ENOMEM;
-       }
+       ctdb_timeval_push(&in->statistics_current_time, buf+offset, &np);
+       offset += np;
 
-       *out = pulldb;
-       return 0;
-}
+       ctdb_uint32_push(&in->total_ro_delegations, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *pulldb)
-{
-       return sizeof(struct ctdb_pulldb_ext);
-}
+       ctdb_uint32_push(&in->total_ro_revokes, buf+offset, &np);
+       offset += np;
 
-void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *pulldb, uint8_t *buf)
-{
-       memcpy(buf, pulldb, sizeof(struct ctdb_pulldb_ext));
+       *npush = offset;
 }
 
-int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                        struct ctdb_pulldb_ext **out)
+static int ctdb_statistics_pull_elems(uint8_t *buf, size_t buflen,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct ctdb_statistics *out,
+                                     size_t *npull)
 {
-       struct ctdb_pulldb_ext *pulldb;
+       size_t offset = 0, np;
+       int ret, i;
 
-       if (buflen < sizeof(struct ctdb_pulldb_ext)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->num_clients,
+                              &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       pulldb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb_ext));
-       if (pulldb == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->frozen, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = pulldb;
-       return 0;
-}
-
-size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *header)
-{
-       return sizeof(struct ctdb_ltdb_header);
-}
-
-void ctdb_ltdb_header_push(struct ctdb_ltdb_header *header, uint8_t *buf)
-{
-       memcpy(buf, header, sizeof(struct ctdb_ltdb_header));
-}
-
-int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
-                         struct ctdb_ltdb_header *header)
-{
-       if (buflen < sizeof(struct ctdb_ltdb_header)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->recovering,
+                              &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(header, buf, sizeof(struct ctdb_ltdb_header));
-       return 0;
-}
-
-int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
-{
-       int ret;
-
-       ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header);
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->client_packets_sent, &np);
        if (ret != 0) {
                return ret;
        }
+       offset += np;
 
-       data->dptr += sizeof(struct ctdb_ltdb_header);
-       data->dsize -= sizeof(struct ctdb_ltdb_header);
-
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->client_packets_recv, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node_packets_sent, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node_packets_recv, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->keepalive_packets_sent, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->keepalive_packets_recv, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.req_call, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.reply_call, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.req_dmaster, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.reply_dmaster, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.reply_error, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.req_message, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.req_control, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->node.reply_control, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->client.req_call, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->client.req_message, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->client.req_control, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->timeouts.call, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->timeouts.control, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->timeouts.traverse, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+                                       &out->reclock.ctdbd, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+                                       &out->reclock.recd, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->locks.num_calls, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->locks.num_current, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->locks.num_pending, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->locks.num_failed, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+                                       &out->locks.latency, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       for (i=0;  i<MAX_COUNT_BUCKETS; i++) {
+               ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                                      &out->locks.buckets[i], &np);
+               if (ret != 0) {
+                       return ret;
+               }
+               offset += np;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->total_calls, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->pending_calls, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->childwrite_calls, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->pending_childwrite_calls, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->memory_used,
+                              &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->__last_counter, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->max_hop_count, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       for (i=0;  i<MAX_COUNT_BUCKETS; i++) {
+               ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                                      &out->hop_count_bucket[i], &np);
+               if (ret != 0) {
+                       return ret;
+               }
+               offset += np;
+       }
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+                                       &out->call_latency, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+                                       &out->childwrite_latency, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->num_recoveries, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+                               &out->statistics_start_time, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+                               &out->statistics_current_time, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->total_ro_delegations, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->total_ro_revokes, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       *npull = offset;
+       return 0;
+}
+
+int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                        struct ctdb_statistics **out, size_t *npull)
+{
+       struct ctdb_statistics *val;
+       size_t np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_statistics);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_statistics_pull_elems(buf, buflen, val, val, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
+       }
+
+       *out = val;
+       *npull = np;
+       return 0;
+}
+
+struct ctdb_statistics_list_wire {
+       uint32_t num;
+       struct ctdb_statistics stats[1];
+};
+
+size_t ctdb_statistics_list_len(struct ctdb_statistics_list *stats_list)
+{
+       return offsetof(struct ctdb_statistics_list_wire, stats) +
+              stats_list->num * sizeof(struct ctdb_statistics);
+}
+
+void ctdb_statistics_list_push(struct ctdb_statistics_list *stats_list,
+                              uint8_t *buf)
+{
+       struct ctdb_statistics_list_wire *wire =
+               (struct ctdb_statistics_list_wire *)buf;
+
+       wire->num = stats_list->num;
+       memcpy(wire->stats, stats_list->stats,
+              stats_list->num * sizeof(struct ctdb_statistics));
+}
+
+int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                             struct ctdb_statistics_list **out)
+{
+       struct ctdb_statistics_list *stats_list;
+       struct ctdb_statistics_list_wire *wire =
+               (struct ctdb_statistics_list_wire *)buf;
+
+       if (buflen < offsetof(struct ctdb_statistics_list_wire, stats)) {
+               return EMSGSIZE;
+       }
+       if (wire->num > buflen / sizeof(struct ctdb_statistics)) {
+               return EMSGSIZE;
+       }
+       if (offsetof(struct ctdb_statistics_list_wire, stats) +
+           wire->num * sizeof(struct ctdb_statistics) <
+           offsetof(struct ctdb_statistics_list_wire, stats)) {
+               return EMSGSIZE;
+       }
+       if (buflen < offsetof(struct ctdb_statistics_list_wire, stats) +
+                    wire->num * sizeof(struct ctdb_statistics)) {
+               return EMSGSIZE;
+       }
+
+       stats_list = talloc(mem_ctx, struct ctdb_statistics_list);
+       if (stats_list == NULL) {
+               return ENOMEM;
+       }
+
+       stats_list->num = wire->num;
+
+       stats_list->stats = talloc_array(stats_list, struct ctdb_statistics,
+                                        wire->num);
+       if (stats_list->stats == NULL) {
+               talloc_free(stats_list);
+               return ENOMEM;
+       }
+
+       memcpy(stats_list->stats, wire->stats,
+              wire->num * sizeof(struct ctdb_statistics));
+
+       *out = stats_list;
+       return 0;
+}
+
+size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
+{
+       size_t len;
+
+       len = ctdb_uint32_len(&in->generation) + ctdb_uint32_len(&in->size);
+       if (in->size > 0) {
+               len += in->size * ctdb_uint32_len(&in->map[0]);
+       }
+
+       return len;
+}
+
+void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+       uint32_t i;
+
+       ctdb_uint32_push(&in->generation, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->size, buf+offset, &np);
+       offset += np;
+
+       for (i=0; i<in->size; i++) {
+               ctdb_uint32_push(&in->map[i], buf+offset, &np);
+               offset += np;
+       }
+
+       *npush = offset;
+}
+
+int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                     struct ctdb_vnn_map **out, size_t *npull)
+{
+       struct ctdb_vnn_map *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_vnn_map);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->generation,
+                              &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->size, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       if (val->size == 0) {
+               val->map = NULL;
+               goto done;
+       }
+
+       val->map = talloc_array(val, uint32_t, val->size);
+       if (val->map == NULL) {
+               ret = ENOMEM;
+               goto fail;
+       }
+
+       for (i=0; i<val->size; i++) {
+               ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                                      &val->map[i], &np);
+               if (ret != 0) {
+                       goto fail;
+               }
+               offset += np;
+       }
+
+done:
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_dbid_len(struct ctdb_dbid *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint8_len(&in->flags) +
+               ctdb_padding_len(3);
+}
+
+void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint8_push(&in->flags, buf+offset, &np);
+       offset += np;
+
+       ctdb_padding_push(3, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
+                               TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
+                               size_t *npull)
+{
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       *npull = offset;
+       return 0;
+}
+
+int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                  struct ctdb_dbid **out, size_t *npull)
+{
+       struct ctdb_dbid *val;
+       size_t np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_dbid);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
+       }
+
+       *out = val;
+       *npull = np;
+       return 0;
+}
+
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
+{
+       size_t len;
+
+       len = ctdb_uint32_len(&in->num);
+       if (in->num > 0) {
+               len += in->num * ctdb_dbid_len(&in->dbs[0]);
+       }
+
+       return len;
+}
+
+void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+       uint32_t i;
+
+       ctdb_uint32_push(&in->num, buf+offset, &np);
+       offset += np;
+
+       for (i=0; i<in->num; i++) {
+               ctdb_dbid_push(&in->dbs[i], buf+offset, &np);
+               offset += np;
+       }
+
+       *npush = offset;
+}
+
+int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      struct ctdb_dbid_map **out, size_t *npull)
+{
+       struct ctdb_dbid_map *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_dbid_map);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       if (val->num == 0) {
+               val->dbs = NULL;
+               goto done;
+       }
+
+       val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
+       if (val->dbs == NULL) {
+               ret = ENOMEM;
+               goto fail;
+       }
+
+       for (i=0; i<val->num; i++) {
+               ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
+                                          &val->dbs[i], &np);
+               if (ret != 0) {
+                       goto fail;
+               }
+               offset += np;
+       }
+
+done:
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->lmaster);
+}
+
+void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                    struct ctdb_pulldb **out, size_t *npull)
+{
+       struct ctdb_pulldb *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_pulldb);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+}
+
+size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->lmaster) +
+               ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
+                         size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                        struct ctdb_pulldb_ext **out, size_t *npull)
+{
+       struct ctdb_pulldb_ext *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_pulldb_ext);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in)
+{
+       return ctdb_uint64_len(&in->rsn) +
+               ctdb_uint32_len(&in->dmaster) +
+               ctdb_uint32_len(&in->reserved1) +
+               ctdb_uint32_len(&in->flags) +
+               ctdb_padding_len(4);
+}
+
+void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
+                          size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint64_push(&in->rsn, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->dmaster, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reserved1, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->flags, buf+offset, &np);
+       offset += np;
+
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
+                         struct ctdb_ltdb_header *out, size_t *npull)
+{
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->rsn, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->dmaster, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reserved1,
+                              &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       *npull = offset;
+       return 0;
+}
+
+int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
+{
+       size_t np;
+       int ret;
+
+       ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header, &np);
+       if (ret != 0) {
+               return ret;
+       }
+
+       data->dptr += np;
+       data->dsize -= np;
+
+       return 0;
+}
+
+size_t ctdb_rec_data_len(struct ctdb_rec_data *in)
+{
+       uint32_t u32;
+
+       u32 = ctdb_uint32_len(&in->reqid) +
+               ctdb_tdb_datan_len(&in->key) +
+               ctdb_tdb_datan_len(&in->data);
+
+       if (in->header != NULL) {
+               u32 += ctdb_ltdb_header_len(in->header);
+       }
+
+       return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+       uint32_t u32;
+
+       u32 = ctdb_rec_data_len(in);
+       ctdb_uint32_push(&u32, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reqid, buf+offset, &np);
+       offset += np;
+
+       u32 = ctdb_tdb_data_len(&in->key);
+       ctdb_uint32_push(&u32, buf+offset, &np);
+       offset += np;
+
+       u32 = ctdb_tdb_data_len(&in->data);
+       if (in->header != NULL) {
+               u32 += ctdb_ltdb_header_len(in->header);
+       }
+
+       ctdb_uint32_push(&u32, buf+offset, &np);
+       offset += np;
+
+       ctdb_tdb_data_push(&in->key, buf+offset, &np);
+       offset += np;
+
+       /* If ltdb header is not NULL, then it is pushed as part of the data */
+       if (in->header != NULL) {
+               ctdb_ltdb_header_push(in->header, buf+offset, &np);
+               offset += np;
+       }
+       ctdb_tdb_data_push(&in->data, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
+                                  uint32_t *reqid,
+                                  TDB_DATA *key, TDB_DATA *data,
+                                  size_t *npull)
+{
+       size_t offset = 0, np;
+       size_t len;
+       uint32_t u32;
+       int ret;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       if (buflen < u32) {
+               return EMSGSIZE;
+       }
+       len = u32;
+
+       ret = ctdb_uint32_pull(buf+offset, len-offset, reqid, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+       key->dsize = u32;
+
+       ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+       data->dsize = u32;
+
+       if (len-offset < key->dsize) {
+               return EMSGSIZE;
+       }
+
+       key->dptr = buf+offset;
+       offset += key->dsize;
+
+       if (len-offset < data->dsize) {
+               return EMSGSIZE;
+       }
+
+       data->dptr = buf+offset;
+       offset += data->dsize;
+
+       *npull = offset;
+       return 0;
+}
+
+static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
+                                   TALLOC_CTX *mem_ctx,
+                                   struct ctdb_rec_data *out,
+                                   size_t *npull)
+{
+       uint32_t reqid;
+       TDB_DATA key, data;
+       size_t np;
+       int ret;
+
+       ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &key, &data, &np);
+       if (ret != 0) {
+               return ret;
+       }
+
+       out->reqid = reqid;
+
+       /* Always set header to NULL.  If it is required, extract it using
+        * ctdb_rec_data_extract_header()
+        */
+       out->header = NULL;
+
+       out->key.dsize = key.dsize;
+       if (key.dsize > 0) {
+               out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
+               if (out->key.dptr == NULL) {
+                       return ENOMEM;
+               }
+       }
+
+       out->data.dsize = data.dsize;
+       if (data.dsize > 0) {
+               out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
+               if (out->data.dptr == NULL) {
+                       return ENOMEM;
+               }
+       }
+
+       *npull = np;
+       return 0;
+}
+
+int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      struct ctdb_rec_data **out, size_t *npull)
+{
+       struct ctdb_rec_data *val;
+       size_t np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_rec_data);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_rec_data_pull_elems(buf, buflen, val, val, &np);
+       if (ret != 0) {
+               TALLOC_FREE(val);
+               return ret;
+       }
+
+       *out = val;
+       *npull = np;
+       return ret;
+}
+
+size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->count) +
+               in->buflen;
+}
+
+void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
+                         size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->count, buf+offset, &np);
+       offset += np;
+
+       memcpy(buf+offset, in->buf, in->buflen);
+       offset += in->buflen;
+
+       *npush = offset;
+}
+
+int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                        struct ctdb_rec_buffer **out, size_t *npull)
+{
+       struct ctdb_rec_buffer *val;
+       size_t offset = 0, np;
+       size_t length;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_rec_buffer);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->count, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       /* Since there is no buflen provided, walk the records to
+        * validate the length of the buffer.
+        */
+       val->buf = buf+offset;
+       val->buflen = buflen-offset;
+
+       length = 0;
+       ret = ctdb_rec_buffer_traverse(val, NULL, &length);
+       if (ret != 0) {
+               goto fail;
+       }
+
+       if (length > buflen-offset) {
+               ret = EMSGSIZE;
+               goto fail;
+       }
+
+       val->buf = talloc_memdup(val, buf+offset, length);
+       if (val->buf == NULL) {
+               ret = ENOMEM;
+               goto fail;
+       }
+       val->buflen = length;
+       offset += length;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
+                                            uint32_t db_id)
+{
+       struct ctdb_rec_buffer *recbuf;
+
+       recbuf = talloc_zero(mem_ctx, struct ctdb_rec_buffer);
+       if (recbuf == NULL) {
+               return recbuf;
+       }
+
+       recbuf->db_id = db_id;
+
+       return recbuf;
+}
+
+int ctdb_rec_buffer_add(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *recbuf,
+                       uint32_t reqid, struct ctdb_ltdb_header *header,
+                       TDB_DATA key, TDB_DATA data)
+{
+       struct ctdb_rec_data recdata;
+       size_t len, np;
+       uint8_t *ptr;
+
+       recdata.reqid = reqid;
+       recdata.header = header;
+       recdata.key = key;
+       recdata.data = data;
+
+       len = ctdb_rec_data_len(&recdata);
+
+       ptr = talloc_realloc(mem_ctx, recbuf->buf, uint8_t,
+                            recbuf->buflen + len);
+       if (ptr == NULL) {
+               return ENOMEM;
+       }
+
+       ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen], &np);
+
+       recbuf->count++;
+       recbuf->buf = ptr;
+       recbuf->buflen += np;
+       return 0;
+}
+
+int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
+                            ctdb_rec_parser_func_t func,
+                            void *private_data)
+{
+       TDB_DATA key, data;
+       uint32_t reqid;
+       size_t offset, reclen;
+       int ret = 0, i;
+
+       offset = 0;
+       for (i=0; i<recbuf->count; i++) {
+               ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
+                                             recbuf->buflen - offset,
+                                             &reqid, &key, &data, &reclen);
+               if (ret != 0) {
+                       return ret;
+               }
+
+               if (func != NULL) {
+                       ret = func(reqid, NULL, key, data, private_data);
+                       if (ret != 0) {
+                               break;
+                       }
+               }
+
+               offset += reclen;
+       }
+
+       if (ret != 0) {
+               return ret;
+       }
+
+       if (func == NULL) {
+               size_t *length = (size_t *)private_data;
+
+               *length = offset;
+       }
+
+       return 0;
+}
+
+int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
+{
+       ssize_t n;
+
+       n = write(fd, &recbuf->db_id, sizeof(uint32_t));
+       if (n == -1 || n != sizeof(uint32_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+       n = write(fd, &recbuf->count, sizeof(uint32_t));
+       if (n == -1 || n != sizeof(uint32_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+       n = write(fd, &recbuf->buflen, sizeof(size_t));
+       if (n == -1 || n != sizeof(size_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+       n = write(fd, recbuf->buf, recbuf->buflen);
+       if (n == -1 || n != recbuf->buflen) {
+               return (errno != 0 ? errno : EIO);
+       }
+
+       return 0;
+}
+
+int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
+                        struct ctdb_rec_buffer **out)
+{
+       struct ctdb_rec_buffer *recbuf;
+       ssize_t n;
+
+       recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
+       if (recbuf == NULL) {
+               return ENOMEM;
+       }
+
+       n = read(fd, &recbuf->db_id, sizeof(uint32_t));
+       if (n == -1 || n != sizeof(uint32_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+       n = read(fd, &recbuf->count, sizeof(uint32_t));
+       if (n == -1 || n != sizeof(uint32_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+       n = read(fd, &recbuf->buflen, sizeof(size_t));
+       if (n == -1 || n != sizeof(size_t)) {
+               return (errno != 0 ? errno : EIO);
+       }
+
+       recbuf->buf = talloc_size(recbuf, recbuf->buflen);
+       if (recbuf->buf == NULL) {
+               return ENOMEM;
+       }
+
+       n = read(fd, recbuf->buf, recbuf->buflen);
+       if (n == -1 || n != recbuf->buflen) {
+               return (errno != 0 ? errno : EIO);
+       }
+
+       *out = recbuf;
+       return 0;
+}
+
+size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->reqid) +
+               ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
+                             size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                            struct ctdb_traverse_start **out, size_t *npull)
+{
+       struct ctdb_traverse_start *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_traverse_start);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->reqid) +
+               ctdb_uint32_len(&in->pnn) +
+               ctdb_uint32_len(&in->client_reqid) +
+               ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
+                           size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->pnn, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                          struct ctdb_traverse_all **out, size_t *npull)
+{
+       struct ctdb_traverse_all *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_traverse_all);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+                              &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-struct ctdb_rec_data_wire {
-       uint32_t length;
-       uint32_t reqid;
-       uint32_t keylen;
-       uint32_t datalen;
-       uint8_t data[1];
-};
+size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in)
+{
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->reqid) +
+               ctdb_uint64_len(&in->srvid) +
+               ctdb_bool_len(&in->withemptyrecords) +
+               ctdb_padding_len(7);
+}
 
-size_t ctdb_rec_data_len(struct ctdb_rec_data *rec)
+void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
+                                 uint8_t *buf, size_t *npush)
 {
-       return offsetof(struct ctdb_rec_data_wire, data) +
-              rec->key.dsize + rec->data.dsize +
-              (rec->header == NULL ? 0 : sizeof(struct ctdb_ltdb_header));
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+       offset += np;
+
+       ctdb_padding_push(7, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
-void ctdb_rec_data_push(struct ctdb_rec_data *rec, uint8_t *buf)
+int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
+                                TALLOC_CTX *mem_ctx,
+                                struct ctdb_traverse_start_ext **out,
+                                size_t *npull)
 {
-       struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
-       size_t offset;
+       struct ctdb_traverse_start_ext *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_traverse_start_ext);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
 
-       wire->length = ctdb_rec_data_len(rec);
-       wire->reqid = rec->reqid;
-       wire->keylen = rec->key.dsize;
-       wire->datalen = rec->data.dsize;
-       if (rec->header != NULL) {
-               wire->datalen += sizeof(struct ctdb_ltdb_header);
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       memcpy(wire->data, rec->key.dptr, rec->key.dsize);
-       offset = rec->key.dsize;
-       if (rec->header != NULL) {
-               memcpy(&wire->data[offset], rec->header,
-                      sizeof(struct ctdb_ltdb_header));
-               offset += sizeof(struct ctdb_ltdb_header);
+       ret = ctdb_bool_pull(buf+offset, buflen-offset,
+                            &val->withemptyrecords, &np);
+       if (ret != 0) {
+               goto fail;
        }
-       if (rec->data.dsize > 0) {
-               memcpy(&wire->data[offset], rec->data.dptr, rec->data.dsize);
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
-                                  uint32_t *reqid,
-                                  struct ctdb_ltdb_header **header,
-                                  TDB_DATA *key, TDB_DATA *data,
-                                  size_t *reclen)
+size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in)
 {
-       struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
-       size_t offset;
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->reqid) +
+               ctdb_uint32_len(&in->pnn) +
+               ctdb_uint32_len(&in->client_reqid) +
+               ctdb_uint64_len(&in->srvid) +
+               ctdb_bool_len(&in->withemptyrecords) +
+               ctdb_padding_len(7);
+}
 
-       if (buflen < offsetof(struct ctdb_rec_data_wire, data)) {
-               return EMSGSIZE;
+void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
+                               uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->pnn, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+       offset += np;
+
+       ctdb_padding_push(7, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
+                              TALLOC_CTX *mem_ctx,
+                              struct ctdb_traverse_all_ext **out,
+                              size_t *npull)
+{
+       struct ctdb_traverse_all_ext *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_traverse_all_ext);
+       if (val == NULL) {
+               return ENOMEM;
        }
-       if (wire->keylen > buflen || wire->datalen > buflen) {
-               return EMSGSIZE;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
        }
-       if (offsetof(struct ctdb_rec_data_wire, data) + wire->keylen <
-           offsetof(struct ctdb_rec_data_wire, data)) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+       if (ret != 0) {
+               goto fail;
        }
-       if (offsetof(struct ctdb_rec_data_wire, data) +
-               wire->keylen + wire->datalen <
-           offsetof(struct ctdb_rec_data_wire, data)) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+                              &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_bool_pull(buf+offset, buflen-offset,
+                            &val->withemptyrecords, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+       if (ret != 0) {
+               goto fail;
        }
-       if (buflen < offsetof(struct ctdb_rec_data_wire, data) +
-                       wire->keylen + wire->datalen) {
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_sock_addr_len(ctdb_sock_addr *in)
+{
+       return sizeof(ctdb_sock_addr);
+}
+
+void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush)
+{
+       memcpy(buf, in, sizeof(ctdb_sock_addr));
+       *npush = sizeof(ctdb_sock_addr);
+}
+
+int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
+                             TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
+                             size_t *npull)
+{
+       if (buflen < sizeof(ctdb_sock_addr)) {
                return EMSGSIZE;
        }
 
-       *reqid = wire->reqid;
+       memcpy(out, buf, sizeof(ctdb_sock_addr));
+       *npull = sizeof(ctdb_sock_addr);
+
+       return 0;
+}
+
+int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       ctdb_sock_addr **out, size_t *npull)
+{
+       ctdb_sock_addr *val;
+       size_t np;
+       int ret;
+
+       val = talloc(mem_ctx, ctdb_sock_addr);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_sock_addr_pull_elems(buf, buflen, val, val, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
+       }
+
+       *out = val;
+       *npull = np;
+       return ret;
+}
+
+size_t ctdb_connection_len(struct ctdb_connection *in)
+{
+       return ctdb_sock_addr_len(&in->src) +
+               ctdb_sock_addr_len(&in->dst);
+}
+
+void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
+                         size_t *npush)
+{
+       size_t offset = 0, np;
 
-       key->dsize = wire->keylen;
-       key->dptr = wire->data;
-       offset = wire->keylen;
+       ctdb_sock_addr_push(&in->src, buf+offset, &np);
+       offset += np;
 
-       /* Always set header to NULL.  If it is required, exact it using
-        * ctdb_rec_data_extract_header()
-        */
-       *header = NULL;
+       ctdb_sock_addr_push(&in->dst, buf+offset, &np);
+       offset += np;
 
-       data->dsize = wire->datalen;
-       data->dptr = &wire->data[offset];
+       *npush = offset;
+}
+
+static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct ctdb_connection *out,
+                                     size_t *npull)
+{
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+                                       mem_ctx, &out->src, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       *reclen = offsetof(struct ctdb_rec_data_wire, data) +
-                       wire->keylen + wire->datalen;
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+                                       mem_ctx, &out->dst, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
+       *npull = offset;
        return 0;
 }
 
-static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
-                                   TALLOC_CTX *mem_ctx,
-                                   struct ctdb_rec_data *out)
+int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                        struct ctdb_connection **out, size_t *npull)
 {
-       uint32_t reqid;
-       struct ctdb_ltdb_header *header;
-       TDB_DATA key, data;
-       size_t reclen;
+       struct ctdb_connection *val;
+       size_t np;
        int ret;
 
-       ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &header,
-                                     &key, &data, &reclen);
+       val = talloc(mem_ctx, struct ctdb_connection);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
        if (ret != 0) {
+               talloc_free(val);
                return ret;
        }
 
-       out->reqid = reqid;
-       out->header = NULL;
+       *out = val;
+       *npull = np;
+       return ret;
+}
 
-       out->key.dsize = key.dsize;
-       if (key.dsize > 0) {
-               out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
-               if (out->key.dptr == NULL) {
-                       return ENOMEM;
-               }
+size_t ctdb_tunable_len(struct ctdb_tunable *in)
+{
+       return ctdb_uint32_len(&in->value) +
+               ctdb_stringn_len(&in->name);
+}
+
+void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->value, buf+offset, &np);
+       offset += np;
+
+       ctdb_stringn_push(&in->name, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                     struct ctdb_tunable **out, size_t *npull)
+{
+       struct ctdb_tunable *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_tunable);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->value, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_stringn_pull(buf+offset, buflen-offset, mem_ctx,
+                               &val->name, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
+{
+       return ctdb_uint32_len(&in->pnn) +
+               ctdb_uint32_len(&in->new_flags) +
+               ctdb_uint32_len(&in->old_flags);
+}
+
+void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
+                               uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->pnn, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->new_flags, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->old_flags, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
+                              TALLOC_CTX *mem_ctx,
+                              struct ctdb_node_flag_change **out,
+                              size_t *npull)
+{
+       struct ctdb_node_flag_change *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_node_flag_change);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->new_flags,
+                              &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
+                              &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
+size_t ctdb_var_list_len(struct ctdb_var_list *in)
+{
+       uint32_t u32 = 0;
+       int i;
+
+       for (i=0; i<in->count; i++) {
+               u32 += ctdb_string_len(&in->var[i]);
+       }
+
+       return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush)
+{
+       size_t offset = 0, np;
+       uint32_t u32;
+       int i;
+       uint8_t sep = ':';
 
-       out->data.dsize = data.dsize;
-       if (data.dsize > 0) {
-               out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
-               if (out->data.dptr == NULL) {
-                       return ENOMEM;
+       /* The length only corresponds to the payload size */
+       u32 = ctdb_var_list_len(in);
+       u32 -= ctdb_uint32_len(&u32);
+
+       ctdb_uint32_push(&u32, buf+offset, &np);
+       offset += np;
+
+       /* The variables are separated by ':' and the complete string is null
+        * terminated.
+        */
+       for (i=0; i<in->count; i++) {
+               ctdb_string_push(&in->var[i], buf+offset, &np);
+               offset += np;
+
+               if (i < in->count - 1) {
+                       /* Replace '\0' with ':' */
+                       ctdb_uint8_push(&sep, buf+offset-1, &np);
                }
        }
 
-       return 0;
+       *npush = offset;
 }
 
-int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                      struct ctdb_rec_data **out)
+int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      struct ctdb_var_list **out, size_t *npull)
 {
-       struct ctdb_rec_data *rec;
+       struct ctdb_var_list *val;
+       const char *str, **list;
+       char *s, *tok, *ptr = NULL;
+       size_t offset = 0, np;
+       uint32_t u32;
        int ret;
 
-       rec = talloc(mem_ctx, struct ctdb_rec_data);
-       if (rec == NULL) {
+       val = talloc_zero(mem_ctx, struct ctdb_var_list);
+       if (val == NULL) {
                return ENOMEM;
        }
 
-       ret = ctdb_rec_data_pull_elems(buf, buflen, rec, rec);
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
        if (ret != 0) {
-               TALLOC_FREE(rec);
+               goto fail;
        }
+       offset += np;
 
-       *out = rec;
-       return ret;
-}
+       if (buflen-offset < u32) {
+               ret = EMSGSIZE;
+               goto fail;
+       }
 
-struct ctdb_rec_buffer_wire {
-       uint32_t db_id;
-       uint32_t count;
-       uint8_t data[1];
-};
+       ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
 
-size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *recbuf)
-{
-       return offsetof(struct ctdb_rec_buffer_wire, data) + recbuf->buflen;
-}
+       s = discard_const(str);
+       while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
+               list = talloc_realloc(val, val->var, const char *,
+                                     val->count+1);
+               if (list == NULL) {
+                       ret = ENOMEM;
+                       goto fail;
+               }
 
-void ctdb_rec_buffer_push(struct ctdb_rec_buffer *recbuf, uint8_t *buf)
-{
-       struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
+               val->var = list;
+
+               s = talloc_strdup(val, tok);
+               if (s == NULL) {
+                       ret = ENOMEM;
+                       goto fail;
+               }
 
-       wire->db_id = recbuf->db_id;
-       wire->count = recbuf->count;
-       if (recbuf->buflen > 0) {
-               memcpy(wire->data, recbuf->buf, recbuf->buflen);
+               val->var[val->count] = s;
+               val->count += 1;
+               s = NULL;
        }
+
+       talloc_free(discard_const(str));
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                        struct ctdb_rec_buffer **out)
-{
-       struct ctdb_rec_buffer *recbuf;
-       struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
-       size_t offset;
+size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in)
+{
+       return ctdb_uint32_len(&in->max_redirect_count) +
+               ctdb_uint32_len(&in->seqnum_interval) +
+               ctdb_uint32_len(&in->control_timeout) +
+               ctdb_uint32_len(&in->traverse_timeout) +
+               ctdb_uint32_len(&in->keepalive_interval) +
+               ctdb_uint32_len(&in->keepalive_limit) +
+               ctdb_uint32_len(&in->recover_timeout) +
+               ctdb_uint32_len(&in->recover_interval) +
+               ctdb_uint32_len(&in->election_timeout) +
+               ctdb_uint32_len(&in->takeover_timeout) +
+               ctdb_uint32_len(&in->monitor_interval) +
+               ctdb_uint32_len(&in->tickle_update_interval) +
+               ctdb_uint32_len(&in->script_timeout) +
+               ctdb_uint32_len(&in->monitor_timeout_count) +
+               ctdb_uint32_len(&in->script_unhealthy_on_timeout) +
+               ctdb_uint32_len(&in->recovery_grace_period) +
+               ctdb_uint32_len(&in->recovery_ban_period) +
+               ctdb_uint32_len(&in->database_hash_size) +
+               ctdb_uint32_len(&in->database_max_dead) +
+               ctdb_uint32_len(&in->rerecovery_timeout) +
+               ctdb_uint32_len(&in->enable_bans) +
+               ctdb_uint32_len(&in->deterministic_public_ips) +
+               ctdb_uint32_len(&in->reclock_ping_period) +
+               ctdb_uint32_len(&in->no_ip_failback) +
+               ctdb_uint32_len(&in->disable_ip_failover) +
+               ctdb_uint32_len(&in->verbose_memory_names) +
+               ctdb_uint32_len(&in->recd_ping_timeout) +
+               ctdb_uint32_len(&in->recd_ping_failcount) +
+               ctdb_uint32_len(&in->log_latency_ms) +
+               ctdb_uint32_len(&in->reclock_latency_ms) +
+               ctdb_uint32_len(&in->recovery_drop_all_ips) +
+               ctdb_uint32_len(&in->verify_recovery_lock) +
+               ctdb_uint32_len(&in->vacuum_interval) +
+               ctdb_uint32_len(&in->vacuum_max_run_time) +
+               ctdb_uint32_len(&in->repack_limit) +
+               ctdb_uint32_len(&in->vacuum_limit) +
+               ctdb_uint32_len(&in->max_queue_depth_drop_msg) +
+               ctdb_uint32_len(&in->allow_unhealthy_db_read) +
+               ctdb_uint32_len(&in->stat_history_interval) +
+               ctdb_uint32_len(&in->deferred_attach_timeout) +
+               ctdb_uint32_len(&in->vacuum_fast_path_count) +
+               ctdb_uint32_len(&in->lcp2_public_ip_assignment) +
+               ctdb_uint32_len(&in->allow_client_db_attach) +
+               ctdb_uint32_len(&in->recover_pdb_by_seqnum) +
+               ctdb_uint32_len(&in->deferred_rebalance_on_node_add) +
+               ctdb_uint32_len(&in->fetch_collapse) +
+               ctdb_uint32_len(&in->hopcount_make_sticky) +
+               ctdb_uint32_len(&in->sticky_duration) +
+               ctdb_uint32_len(&in->sticky_pindown) +
+               ctdb_uint32_len(&in->no_ip_takeover) +
+               ctdb_uint32_len(&in->db_record_count_warn) +
+               ctdb_uint32_len(&in->db_record_size_warn) +
+               ctdb_uint32_len(&in->db_size_warn) +
+               ctdb_uint32_len(&in->pulldb_preallocation_size) +
+               ctdb_uint32_len(&in->no_ip_host_on_all_disabled) +
+               ctdb_uint32_len(&in->samba3_hack) +
+               ctdb_uint32_len(&in->mutex_enabled) +
+               ctdb_uint32_len(&in->lock_processes_per_db) +
+               ctdb_uint32_len(&in->rec_buffer_size_limit) +
+               ctdb_uint32_len(&in->queue_buffer_size) +
+               ctdb_uint32_len(&in->ip_alloc_algorithm) +
+               ctdb_uint32_len(&in->allow_mixed_versions);
+}
+
+void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
+                           size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->max_redirect_count, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->seqnum_interval, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->control_timeout, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->traverse_timeout, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->keepalive_interval, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->keepalive_limit, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->recover_timeout, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->recover_interval, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->election_timeout, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->takeover_timeout, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->monitor_interval, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->tickle_update_interval, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->script_timeout, buf+offset, &np);
+       offset += np;
 
-       if (buflen < offsetof(struct ctdb_rec_buffer_wire, data)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->monitor_timeout_count, buf+offset, &np);
+       offset += np;
 
-       recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
-       if (recbuf == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->script_unhealthy_on_timeout, buf+offset, &np);
+       offset += np;
 
-       recbuf->db_id = wire->db_id;
-       recbuf->count = wire->count;
+       ctdb_uint32_push(&in->recovery_grace_period, buf+offset, &np);
+       offset += np;
 
-       offset = offsetof(struct ctdb_rec_buffer_wire, data);
-       recbuf->buflen = buflen - offset;
-       recbuf->buf = talloc_memdup(recbuf, wire->data, recbuf->buflen);
-       if (recbuf->buf == NULL) {
-               talloc_free(recbuf);
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->recovery_ban_period, buf+offset, &np);
+       offset += np;
 
-       *out = recbuf;
-       return 0;
-}
+       ctdb_uint32_push(&in->database_hash_size, buf+offset, &np);
+       offset += np;
 
-struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
-                                            uint32_t db_id)
-{
-       struct ctdb_rec_buffer *recbuf;
+       ctdb_uint32_push(&in->database_max_dead, buf+offset, &np);
+       offset += np;
 
-       recbuf = talloc_zero(mem_ctx, struct ctdb_rec_buffer);
-       if (recbuf == NULL) {
-               return recbuf;
-       }
+       ctdb_uint32_push(&in->rerecovery_timeout, buf+offset, &np);
+       offset += np;
 
-       recbuf->db_id = db_id;
+       ctdb_uint32_push(&in->enable_bans, buf+offset, &np);
+       offset += np;
 
-       return recbuf;
-}
+       ctdb_uint32_push(&in->deterministic_public_ips, buf+offset, &np);
+       offset += np;
 
-int ctdb_rec_buffer_add(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *recbuf,
-                       uint32_t reqid, struct ctdb_ltdb_header *header,
-                       TDB_DATA key, TDB_DATA data)
-{
-       struct ctdb_rec_data recdata;
-       size_t len;
-       uint8_t *ptr;
+       ctdb_uint32_push(&in->reclock_ping_period, buf+offset, &np);
+       offset += np;
 
-       recdata.reqid = reqid;
-       recdata.header = header;
-       recdata.key = key;
-       recdata.data = data;
+       ctdb_uint32_push(&in->no_ip_failback, buf+offset, &np);
+       offset += np;
 
-       len = ctdb_rec_data_len(&recdata);
+       ctdb_uint32_push(&in->disable_ip_failover, buf+offset, &np);
+       offset += np;
 
-       ptr = talloc_realloc(mem_ctx, recbuf->buf, uint8_t,
-                            recbuf->buflen + len);
-       if (ptr == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->verbose_memory_names, buf+offset, &np);
+       offset += np;
 
-       ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen]);
+       ctdb_uint32_push(&in->recd_ping_timeout, buf+offset, &np);
+       offset += np;
 
-       recbuf->count++;
-       recbuf->buf = ptr;
-       recbuf->buflen += len;
-       return 0;
-}
+       ctdb_uint32_push(&in->recd_ping_failcount, buf+offset, &np);
+       offset += np;
 
-int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
-                            ctdb_rec_parser_func_t func,
-                            void *private_data)
-{
-       struct ctdb_ltdb_header *header;
-       TDB_DATA key, data;
-       uint32_t reqid;
-       size_t offset, reclen;
-       int ret = 0, i;
+       ctdb_uint32_push(&in->log_latency_ms, buf+offset, &np);
+       offset += np;
 
-       offset = 0;
-       for (i=0; i<recbuf->count; i++) {
-               ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
-                                             recbuf->buflen - offset,
-                                             &reqid, &header,
-                                             &key, &data, &reclen);
-               if (ret != 0) {
-                       return ret;
-               }
+       ctdb_uint32_push(&in->reclock_latency_ms, buf+offset, &np);
+       offset += np;
 
-               ret = func(reqid, header, key, data, private_data);
-               if (ret != 0) {
-                       break;
-               }
+       ctdb_uint32_push(&in->recovery_drop_all_ips, buf+offset, &np);
+       offset += np;
 
-               offset += reclen;
-       }
+       ctdb_uint32_push(&in->verify_recovery_lock, buf+offset, &np);
+       offset += np;
 
-       return ret;
-}
+       ctdb_uint32_push(&in->vacuum_interval, buf+offset, &np);
+       offset += np;
 
-int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
-{
-       ssize_t n;
+       ctdb_uint32_push(&in->vacuum_max_run_time, buf+offset, &np);
+       offset += np;
 
-       n = write(fd, &recbuf->db_id, sizeof(uint32_t));
-       if (n == -1 || n != sizeof(uint32_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
-       n = write(fd, &recbuf->count, sizeof(uint32_t));
-       if (n == -1 || n != sizeof(uint32_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
-       n = write(fd, &recbuf->buflen, sizeof(size_t));
-       if (n == -1 || n != sizeof(size_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
-       n = write(fd, recbuf->buf, recbuf->buflen);
-       if (n == -1 || n != recbuf->buflen) {
-               return (errno != 0 ? errno : EIO);
-       }
+       ctdb_uint32_push(&in->repack_limit, buf+offset, &np);
+       offset += np;
 
-       return 0;
-}
+       ctdb_uint32_push(&in->vacuum_limit, buf+offset, &np);
+       offset += np;
 
-int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
-                        struct ctdb_rec_buffer **out)
-{
-       struct ctdb_rec_buffer *recbuf;
-       ssize_t n;
+       ctdb_uint32_push(&in->max_queue_depth_drop_msg, buf+offset, &np);
+       offset += np;
 
-       recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
-       if (recbuf == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->allow_unhealthy_db_read, buf+offset, &np);
+       offset += np;
 
-       n = read(fd, &recbuf->db_id, sizeof(uint32_t));
-       if (n == -1 || n != sizeof(uint32_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
-       n = read(fd, &recbuf->count, sizeof(uint32_t));
-       if (n == -1 || n != sizeof(uint32_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
-       n = read(fd, &recbuf->buflen, sizeof(size_t));
-       if (n == -1 || n != sizeof(size_t)) {
-               return (errno != 0 ? errno : EIO);
-       }
+       ctdb_uint32_push(&in->stat_history_interval, buf+offset, &np);
+       offset += np;
 
-       recbuf->buf = talloc_size(recbuf, recbuf->buflen);
-       if (recbuf->buf == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->deferred_attach_timeout, buf+offset, &np);
+       offset += np;
 
-       n = read(fd, recbuf->buf, recbuf->buflen);
-       if (n == -1 || n != recbuf->buflen) {
-               return (errno != 0 ? errno : EIO);
-       }
+       ctdb_uint32_push(&in->vacuum_fast_path_count, buf+offset, &np);
+       offset += np;
 
-       *out = recbuf;
-       return 0;
-}
+       ctdb_uint32_push(&in->lcp2_public_ip_assignment, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_traverse_start_len(struct ctdb_traverse_start *traverse)
-{
-       return sizeof(struct ctdb_traverse_start);
-}
+       ctdb_uint32_push(&in->allow_client_db_attach, buf+offset, &np);
+       offset += np;
 
-void ctdb_traverse_start_push(struct ctdb_traverse_start *traverse,
-                             uint8_t *buf)
-{
-       memcpy(buf, traverse, sizeof(struct ctdb_traverse_start));
-}
+       ctdb_uint32_push(&in->recover_pdb_by_seqnum, buf+offset, &np);
+       offset += np;
 
-int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                            struct ctdb_traverse_start **out)
-{
-       struct ctdb_traverse_start *traverse;
+       ctdb_uint32_push(&in->deferred_rebalance_on_node_add, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_traverse_start)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->fetch_collapse, buf+offset, &np);
+       offset += np;
 
-       traverse = talloc_memdup(mem_ctx, buf,
-                                sizeof(struct ctdb_traverse_start));
-       if (traverse == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->hopcount_make_sticky, buf+offset, &np);
+       offset += np;
 
-       *out = traverse;
-       return 0;
-}
+       ctdb_uint32_push(&in->sticky_duration, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_traverse_all_len(struct ctdb_traverse_all *traverse)
-{
-       return sizeof(struct ctdb_traverse_all);
-}
+       ctdb_uint32_push(&in->sticky_pindown, buf+offset, &np);
+       offset += np;
 
-void ctdb_traverse_all_push(struct ctdb_traverse_all *traverse, uint8_t *buf)
-{
-       memcpy(buf, traverse, sizeof(struct ctdb_traverse_all));
-}
+       ctdb_uint32_push(&in->no_ip_takeover, buf+offset, &np);
+       offset += np;
 
-int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                          struct ctdb_traverse_all **out)
-{
-       struct ctdb_traverse_all *traverse;
+       ctdb_uint32_push(&in->db_record_count_warn, buf+offset, &np);
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_traverse_all)) {
-               return EMSGSIZE;
-       }
+       ctdb_uint32_push(&in->db_record_size_warn, buf+offset, &np);
+       offset += np;
 
-       traverse = talloc_memdup(mem_ctx, buf,
-                                sizeof(struct ctdb_traverse_all));
-       if (traverse == NULL) {
-               return ENOMEM;
-       }
+       ctdb_uint32_push(&in->db_size_warn, buf+offset, &np);
+       offset += np;
 
-       *out = traverse;
-       return 0;
-}
+       ctdb_uint32_push(&in->pulldb_preallocation_size, buf+offset, &np);
+       offset += np;
 
-size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *traverse)
-{
-       return sizeof(struct ctdb_traverse_start_ext);
-}
+       ctdb_uint32_push(&in->no_ip_host_on_all_disabled, buf+offset, &np);
+       offset += np;
 
-void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *traverse,
-                                 uint8_t *buf)
-{
-       memcpy(buf, traverse, sizeof(struct ctdb_traverse_start_ext));
+       ctdb_uint32_push(&in->samba3_hack, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->mutex_enabled, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->lock_processes_per_db, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->rec_buffer_size_limit, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->queue_buffer_size, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->ip_alloc_algorithm, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->allow_mixed_versions, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
-int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
-                                TALLOC_CTX *mem_ctx,
-                                struct ctdb_traverse_start_ext **out)
+static int ctdb_tunable_list_pull_elems(uint8_t *buf, size_t buflen,
+                                       TALLOC_CTX *mem_ctx,
+                                       struct ctdb_tunable_list *out,
+                                       size_t *npull)
 {
-       struct ctdb_traverse_start_ext *traverse;
+       size_t offset = 0, np;
+       int ret;
 
-       if (buflen < sizeof(struct ctdb_traverse_start_ext)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->max_redirect_count, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       traverse = talloc_memdup(mem_ctx, buf,
-                                sizeof(struct ctdb_traverse_start_ext));
-       if (traverse == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->seqnum_interval, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = traverse;
-       return 0;
-}
-
-size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *traverse)
-{
-       return sizeof(struct ctdb_traverse_all_ext);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->control_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *traverse,
-                               uint8_t *buf)
-{
-       memcpy(buf, traverse, sizeof(struct ctdb_traverse_all_ext));
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->traverse_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
-                              TALLOC_CTX *mem_ctx,
-                              struct ctdb_traverse_all_ext **out)
-{
-       struct ctdb_traverse_all_ext *traverse;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->keepalive_interval, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_traverse_all_ext)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->keepalive_limit, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       traverse = talloc_memdup(mem_ctx, buf,
-                                sizeof(struct ctdb_traverse_all_ext));
-       if (traverse == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recover_timeout, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = traverse;
-       return 0;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recover_interval, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_sock_addr_len(ctdb_sock_addr *addr)
-{
-       return sizeof(ctdb_sock_addr);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->election_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_sock_addr_push(ctdb_sock_addr *addr, uint8_t *buf)
-{
-       memcpy(buf, addr, sizeof(ctdb_sock_addr));
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->takeover_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-static int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
-                                    TALLOC_CTX *mem_ctx, ctdb_sock_addr *out)
-{
-       if (buflen < sizeof(ctdb_sock_addr)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->monitor_interval, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(out, buf, sizeof(ctdb_sock_addr));
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->tickle_update_interval, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       return 0;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->script_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                       ctdb_sock_addr **out)
-{
-       ctdb_sock_addr *addr;
-       int ret;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->monitor_timeout_count, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       addr = talloc(mem_ctx, ctdb_sock_addr);
-       if (addr == NULL) {
-               return false;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->script_unhealthy_on_timeout, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       ret = ctdb_sock_addr_pull_elems(buf, buflen, addr, addr);
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recovery_grace_period, &np);
        if (ret != 0) {
-               TALLOC_FREE(addr);
+               return ret;
        }
+       offset += np;
 
-       *out = addr;
-       return ret;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recovery_ban_period, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_connection_len(struct ctdb_connection *conn)
-{
-       return sizeof(struct ctdb_connection);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->database_hash_size, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_connection_push(struct ctdb_connection *conn, uint8_t *buf)
-{
-       memcpy(buf, conn, sizeof(struct ctdb_connection));
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->database_max_dead, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
-                                     TALLOC_CTX *mem_ctx,
-                                     struct ctdb_connection *out)
-{
-       if (buflen < sizeof(struct ctdb_connection)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->rerecovery_timeout, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(out, buf, sizeof(struct ctdb_connection));
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->enable_bans, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       return 0;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->deterministic_public_ips, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                        struct ctdb_connection **out)
-{
-       struct ctdb_connection *conn;
-       int ret;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->reclock_ping_period, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       conn = talloc(mem_ctx, struct ctdb_connection);
-       if (conn == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->no_ip_failback, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       ret = ctdb_connection_pull_elems(buf, buflen, conn, conn);
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->disable_ip_failover, &np);
        if (ret != 0) {
-               TALLOC_FREE(conn);
+               return ret;
        }
+       offset += np;
 
-       *out = conn;
-       return ret;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->verbose_memory_names, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-struct ctdb_tunable_wire {
-       uint32_t value;
-       uint32_t length;
-       uint8_t name[1];
-};
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recd_ping_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_tunable_len(struct ctdb_tunable *tunable)
-{
-       return offsetof(struct ctdb_tunable_wire, name) +
-              strlen(tunable->name) + 1;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recd_ping_failcount, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_tunable_push(struct ctdb_tunable *tunable, uint8_t *buf)
-{
-       struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->log_latency_ms, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       wire->value = tunable->value;
-       wire->length = strlen(tunable->name) + 1;
-       memcpy(wire->name, tunable->name, wire->length);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->reclock_latency_ms, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                     struct ctdb_tunable **out)
-{
-       struct ctdb_tunable *tunable;
-       struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recovery_drop_all_ips, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       if (buflen < offsetof(struct ctdb_tunable_wire, name)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->verify_recovery_lock, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (wire->length > buflen) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->vacuum_interval, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (offsetof(struct ctdb_tunable_wire, name) + wire->length <
-           offsetof(struct ctdb_tunable_wire, name)) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->vacuum_max_run_time, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (buflen < offsetof(struct ctdb_tunable_wire, name) + wire->length) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->repack_limit, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       tunable = talloc(mem_ctx, struct ctdb_tunable);
-       if (tunable == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->vacuum_limit, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       tunable->value = wire->value;
-       tunable->name = talloc_memdup(tunable, wire->name, wire->length);
-       if (tunable->name == NULL) {
-               talloc_free(tunable);
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->max_queue_depth_drop_msg, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = tunable;
-       return 0;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->allow_unhealthy_db_read, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *flag_change)
-{
-       return sizeof(struct ctdb_node_flag_change);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->stat_history_interval, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_node_flag_change_push(struct ctdb_node_flag_change *flag_change,
-                               uint8_t *buf)
-{
-       memcpy(buf, flag_change, sizeof(struct ctdb_node_flag_change));
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->deferred_attach_timeout, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                              struct ctdb_node_flag_change **out)
-{
-       struct ctdb_node_flag_change *flag_change;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->vacuum_fast_path_count, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       if (buflen < sizeof(struct ctdb_node_flag_change)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->lcp2_public_ip_assignment, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       flag_change = talloc_memdup(mem_ctx, buf,
-                                   sizeof(struct ctdb_node_flag_change));
-       if (flag_change == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->allow_client_db_attach, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       *out = flag_change;
-       return 0;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->recover_pdb_by_seqnum, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-struct ctdb_var_list_wire {
-       uint32_t length;
-       char list_str[1];
-};
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->deferred_rebalance_on_node_add, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_var_list_len(struct ctdb_var_list *var_list)
-{
-       int i;
-       size_t len = sizeof(uint32_t);
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->fetch_collapse, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       for (i=0; i<var_list->count; i++) {
-               len += strlen(var_list->var[i]) + 1;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->hopcount_make_sticky, &np);
+       if (ret != 0) {
+               return ret;
        }
-       return len;
-}
+       offset += np;
 
-void ctdb_var_list_push(struct ctdb_var_list *var_list, uint8_t *buf)
-{
-       struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
-       int i, n;
-       size_t offset = 0;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->sticky_duration, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       if (var_list->count > 0) {
-               n = sprintf(wire->list_str, "%s", var_list->var[0]);
-               offset += n;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->sticky_pindown, &np);
+       if (ret != 0) {
+               return ret;
        }
-       for (i=1; i<var_list->count; i++) {
-               n = sprintf(&wire->list_str[offset], ":%s", var_list->var[i]);
-               offset += n;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->no_ip_takeover, &np);
+       if (ret != 0) {
+               return ret;
        }
-       wire->length = offset + 1;
-}
+       offset += np;
 
-int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                      struct ctdb_var_list **out)
-{
-       struct ctdb_var_list *var_list = NULL;
-       struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
-       char *str, *s, *tok, *ptr;
-       const char **list;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->db_record_count_warn, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->db_record_size_warn, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (wire->length > buflen) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->db_size_warn, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (sizeof(uint32_t) + wire->length < sizeof(uint32_t)) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->pulldb_preallocation_size, &np);
+       if (ret != 0) {
+               return ret;
        }
-       if (buflen < sizeof(uint32_t) + wire->length) {
-               return EMSGSIZE;
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->no_ip_host_on_all_disabled, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       str = talloc_strndup(mem_ctx, (char *)wire->list_str, wire->length);
-       if (str == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->samba3_hack, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       var_list = talloc_zero(mem_ctx, struct ctdb_var_list);
-       if (var_list == NULL) {
-               goto fail;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->mutex_enabled, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       s = str;
-       while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
-               s = NULL;
-               list = talloc_realloc(var_list, var_list->var, const char *,
-                                     var_list->count+1);
-               if (list == NULL) {
-                       goto fail;
-               }
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->lock_processes_per_db, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-               var_list->var = list;
-               var_list->var[var_list->count] = talloc_strdup(var_list, tok);
-               if (var_list->var[var_list->count] == NULL) {
-                       goto fail;
-               }
-               var_list->count++;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->rec_buffer_size_limit, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       talloc_free(str);
-       *out = var_list;
-       return 0;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->queue_buffer_size, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-fail:
-       talloc_free(str);
-       talloc_free(var_list);
-       return ENOMEM;
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->ip_alloc_algorithm, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-size_t ctdb_tunable_list_len(struct ctdb_tunable_list *tun_list)
-{
-       return sizeof(struct ctdb_tunable_list);
-}
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+                              &out->allow_mixed_versions, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
-void ctdb_tunable_list_push(struct ctdb_tunable_list *tun_list, uint8_t *buf)
-{
-       memcpy(buf, tun_list, sizeof(struct ctdb_tunable_list));
+       *npull = offset;
+       return 0;
 }
 
 int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                          struct ctdb_tunable_list **out)
+                          struct ctdb_tunable_list **out, size_t *npull)
 {
-       struct ctdb_tunable_list *tun_list;
+       struct ctdb_tunable_list *val;
+       size_t np;
+       int ret;
 
-       if (buflen < sizeof(struct ctdb_tunable_list)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_tunable_list);
+       if (val == NULL) {
+               return ENOMEM;
        }
 
-       tun_list = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_tunable_list));
-       if (tun_list == NULL) {
-               return ENOMEM;
+       ret = ctdb_tunable_list_pull_elems(buf, buflen, val, val, &np);
+       if (ret != 0) {
+               talloc_free(val);
+               return ret;
        }
 
-       *out = tun_list;
+       *out = val;
+       *npull = np;
        return 0;
 }
 
-struct ctdb_tickle_list_wire {
-       ctdb_sock_addr addr;
-       uint32_t num;
-       struct ctdb_connection conn[1];
-};
-
-size_t ctdb_tickle_list_len(struct ctdb_tickle_list *tickles)
+size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
 {
-       return offsetof(struct ctdb_tickle_list, conn) +
-              tickles->num * sizeof(struct ctdb_connection);
+       size_t len;
+
+       len = ctdb_sock_addr_len(&in->addr) +
+               ctdb_uint32_len(&in->num);
+       if (in->num > 0) {
+               len += in->num * ctdb_connection_len(&in->conn[0]);
+       }
+
+       return len;
 }
 
-void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf)
+void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
+                          size_t *npush)
 {
-       struct ctdb_tickle_list_wire *wire =
-               (struct ctdb_tickle_list_wire *)buf;
-       size_t offset;
-       int i;
+       size_t offset = 0, np;
+       uint32_t i;
+
+       ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+       offset += np;
 
-       memcpy(&wire->addr, &tickles->addr, sizeof(ctdb_sock_addr));
-       wire->num = tickles->num;
+       ctdb_uint32_push(&in->num, buf+offset, &np);
+       offset += np;
 
-       offset = offsetof(struct ctdb_tickle_list_wire, conn);
-       for (i=0; i<tickles->num; i++) {
-               ctdb_connection_push(&tickles->conn[i], &buf[offset]);
-               offset += ctdb_connection_len(&tickles->conn[i]);
+       for (i=0; i<in->num; i++) {
+               ctdb_connection_push(&in->conn[i], buf+offset, &np);
+               offset += np;
        }
+
+       *npush = offset;
 }
 
 int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                          struct ctdb_tickle_list **out)
+                          struct ctdb_tickle_list **out, size_t *npull)
 {
-       struct ctdb_tickle_list *tickles;
-       struct ctdb_tickle_list_wire *wire =
-               (struct ctdb_tickle_list_wire *)buf;
-       size_t offset;
-       int i, ret;
+       struct ctdb_tickle_list *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
 
-       if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
-               return EMSGSIZE;
-       }
-       if (wire->num > buflen / sizeof(struct ctdb_connection)) {
-               return EMSGSIZE;
-       }
-       if (offsetof(struct ctdb_tickle_list_wire, conn) +
-           wire->num * sizeof(struct ctdb_connection) <
-           offsetof(struct ctdb_tickle_list_wire, conn)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_tickle_list);
+       if (val == NULL) {
+               return ENOMEM;
        }
-       if (buflen < offsetof(struct ctdb_tickle_list_wire, conn) +
-                    wire->num * sizeof(struct ctdb_connection)) {
-               return EMSGSIZE;
+
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+                                       &val->addr, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       tickles = talloc(mem_ctx, struct ctdb_tickle_list);
-       if (tickles == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       offset = offsetof(struct ctdb_tickle_list, conn);
-       memcpy(tickles, wire, offset);
+       if (val->num == 0) {
+               val->conn = NULL;
+               goto done;
+       }
 
-       tickles->conn = talloc_array(tickles, struct ctdb_connection,
-                                    wire->num);
-       if (tickles->conn == NULL) {
-               talloc_free(tickles);
-               return ENOMEM;
+       val->conn = talloc_array(val, struct ctdb_connection, val->num);
+       if (val->conn == NULL) {
+               ret = ENOMEM;
+               goto fail;
        }
 
-       for (i=0; i<wire->num; i++) {
-               ret = ctdb_connection_pull_elems(&buf[offset], buflen-offset,
-                                                tickles->conn,
-                                                &tickles->conn[i]);
+       for (i=0; i<val->num; i++) {
+               ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
+                                                val, &val->conn[i], &np);
                if (ret != 0) {
-                       talloc_free(tickles);
-                       return ret;
+                       goto fail;
                }
-               offset += ctdb_connection_len(&tickles->conn[i]);
+               offset += np;
        }
 
-       *out = tickles;
+done:
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-struct ctdb_addr_info_wire {
-       ctdb_sock_addr addr;
-       uint32_t mask;
-       uint32_t len;
-       char iface[1];
-};
+size_t ctdb_addr_info_len(struct ctdb_addr_info *in)
+{
+       return ctdb_sock_addr_len(&in->addr) +
+               ctdb_uint32_len(&in->mask) +
+               ctdb_stringn_len(&in->iface);
+}
 
-size_t ctdb_addr_info_len(struct ctdb_addr_info *arp)
+void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
+                        size_t *npush)
 {
-       uint32_t len;
+       size_t offset = 0, np;
 
-       len = offsetof(struct ctdb_addr_info_wire, iface);
-       if (arp->iface != NULL) {
-              len += strlen(arp->iface)+1;
-       }
+       ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+       offset += np;
 
-       return len;
-}
+       ctdb_uint32_push(&in->mask, buf+offset, &np);
+       offset += np;
 
-void ctdb_addr_info_push(struct ctdb_addr_info *addr_info, uint8_t *buf)
-{
-       struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
+       ctdb_stringn_push(&in->iface, buf+offset, &np);
+       offset += np;
 
-       wire->addr = addr_info->addr;
-       wire->mask = addr_info->mask;
-       if (addr_info->iface == NULL) {
-               wire->len = 0;
-       } else {
-               wire->len = strlen(addr_info->iface)+1;
-               memcpy(wire->iface, addr_info->iface, wire->len);
-       }
+       *npush = offset;
 }
 
 int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                       struct ctdb_addr_info **out)
+                       struct ctdb_addr_info **out, size_t *npull)
 {
-       struct ctdb_addr_info *addr_info;
-       struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
+       struct ctdb_addr_info *val;
+       size_t offset = 0, np;
+       int ret;
 
-       if (buflen < offsetof(struct ctdb_addr_info_wire, iface)) {
-               return EMSGSIZE;
-       }
-       if (wire->len > buflen) {
-               return EMSGSIZE;
-       }
-       if (offsetof(struct ctdb_addr_info_wire, iface) + wire->len <
-           offsetof(struct ctdb_addr_info_wire, iface)) {
-               return EMSGSIZE;
-       }
-       if (buflen < offsetof(struct ctdb_addr_info_wire, iface) + wire->len) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_addr_info);
+       if (val == NULL) {
+               return ENOMEM;
        }
 
-       addr_info = talloc(mem_ctx, struct ctdb_addr_info);
-       if (addr_info == NULL) {
-               return ENOMEM;
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+                                       &val->addr, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       addr_info->addr = wire->addr;
-       addr_info->mask = wire->mask;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->mask, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
 
-       if (wire->len == 0) {
-               addr_info->iface = NULL;
-       } else {
-               addr_info->iface = talloc_strndup(addr_info, wire->iface,
-                                                 wire->len);
-               if (addr_info->iface == NULL) {
-                       talloc_free(addr_info);
-                       return ENOMEM;
-               }
+       ret = ctdb_stringn_pull(buf+offset, buflen-offset, val, &val->iface,
+                               &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       *out = addr_info;
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-size_t ctdb_transdb_len(struct ctdb_transdb *transdb)
+size_t ctdb_transdb_len(struct ctdb_transdb *in)
 {
-       return sizeof(struct ctdb_transdb);
+       return ctdb_uint32_len(&in->db_id) +
+               ctdb_uint32_len(&in->tid);
 }
 
-void ctdb_transdb_push(struct ctdb_transdb *transdb, uint8_t *buf)
+void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush)
 {
-       memcpy(buf, transdb, sizeof(struct ctdb_transdb));
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->db_id, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->tid, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
 int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    struct ctdb_transdb **out)
+                    struct ctdb_transdb **out, size_t *npull)
 {
-       struct ctdb_transdb *transdb;
+       struct ctdb_transdb *val;
+       size_t offset = 0, np;
+       int ret;
 
-       if (buflen < sizeof(struct ctdb_transdb)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_transdb);
+       if (val == NULL) {
+               return ENOMEM;
        }
 
-       transdb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_transdb));
-       if (transdb == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       *out = transdb;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-size_t ctdb_uptime_len(struct ctdb_uptime *uptime)
+size_t ctdb_uptime_len(struct ctdb_uptime *in)
 {
-       return sizeof(struct ctdb_uptime);
+       return ctdb_timeval_len(&in->current_time) +
+               ctdb_timeval_len(&in->ctdbd_start_time) +
+               ctdb_timeval_len(&in->last_recovery_started) +
+               ctdb_timeval_len(&in->last_recovery_finished);
 }
 
-void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf)
+void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
 {
-       memcpy(buf, uptime, sizeof(struct ctdb_uptime));
+       size_t offset = 0, np;
+
+       ctdb_timeval_push(&in->current_time, buf+offset, &np);
+       offset += np;
+
+       ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
+       offset += np;
+
+       ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
+       offset += np;
+
+       ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
 int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    struct ctdb_uptime **out)
+                    struct ctdb_uptime **out, size_t *npull)
 {
-       struct ctdb_uptime *uptime;
+       struct ctdb_uptime *val;
+       size_t offset = 0, np;
+       int ret;
 
-       if (buflen < sizeof(struct ctdb_uptime)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_uptime);
+       if (val == NULL) {
+               return ENOMEM;
        }
 
-       uptime = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_uptime));
-       if (uptime == NULL) {
-               return ENOMEM;
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
+                               &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+                               &val->ctdbd_start_time, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+                               &val->last_recovery_started, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+                               &val->last_recovery_finished, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       *out = uptime;
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-size_t ctdb_public_ip_len(struct ctdb_public_ip *pubip)
+size_t ctdb_public_ip_len(struct ctdb_public_ip *in)
 {
-       return sizeof(struct ctdb_public_ip);
+       return ctdb_uint32_len(&in->pnn) +
+               ctdb_sock_addr_len(&in->addr);
 }
 
-void ctdb_public_ip_push(struct ctdb_public_ip *pubip, uint8_t *buf)
+void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
+                        size_t *npush)
 {
-       memcpy(buf, pubip, sizeof(struct ctdb_public_ip));
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->pnn, buf+offset, &np);
+       offset += np;
+
+       ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
 static int ctdb_public_ip_pull_elems(uint8_t *buf, size_t buflen,
                                     TALLOC_CTX *mem_ctx,
-                                    struct ctdb_public_ip *out)
+                                    struct ctdb_public_ip *out, size_t *npull)
 {
-       if (buflen < sizeof(struct ctdb_public_ip)) {
-               return EMSGSIZE;
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(out, buf, sizeof(struct ctdb_public_ip));
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+                                       &out->addr, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
+       *npull = offset;
        return 0;
 }
 
 int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                       struct ctdb_public_ip **out)
+                       struct ctdb_public_ip **out, size_t *npull)
 {
-       struct ctdb_public_ip *pubip;
+       struct ctdb_public_ip *val;
+       size_t np;
        int ret;
 
-       pubip = talloc(mem_ctx, struct ctdb_public_ip);
-       if (pubip == NULL) {
+       val = talloc(mem_ctx, struct ctdb_public_ip);
+       if (val == NULL) {
                return ENOMEM;
        }
 
-       ret = ctdb_public_ip_pull_elems(buf, buflen, pubip, pubip);
+       ret = ctdb_public_ip_pull_elems(buf, buflen, val, val, &np);
        if (ret != 0) {
-               TALLOC_FREE(pubip);
+               TALLOC_FREE(val);
+               return ret;
        }
 
-       *out = pubip;
+       *out = val;
+       *npull = np;
        return ret;
 }
 
-struct ctdb_public_ip_list_wire {
-       uint32_t num;
-       struct ctdb_public_ip ip[1];
-};
-
-size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *pubip_list)
+size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in)
 {
-       int i;
        size_t len;
 
-       len = sizeof(uint32_t);
-       for (i=0; i<pubip_list->num; i++) {
-               len += ctdb_public_ip_len(&pubip_list->ip[i]);
+       len = ctdb_uint32_len(&in->num);
+       if (in->num > 0) {
+               len += in->num * ctdb_public_ip_len(&in->ip[0]);
        }
+
        return len;
 }
 
-void ctdb_public_ip_list_push(struct ctdb_public_ip_list *pubip_list,
-                             uint8_t *buf)
+void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
+                             size_t *npush)
 {
-       struct ctdb_public_ip_list_wire *wire =
-               (struct ctdb_public_ip_list_wire *)buf;
-       size_t offset;
-       int i;
+       size_t offset = 0, np;
+       uint32_t i;
 
-       wire->num = pubip_list->num;
+       ctdb_uint32_push(&in->num, buf+offset, &np);
+       offset += np;
 
-       offset = offsetof(struct ctdb_public_ip_list_wire, ip);
-       for (i=0; i<pubip_list->num; i++) {
-               ctdb_public_ip_push(&pubip_list->ip[i], &buf[offset]);
-               offset += ctdb_public_ip_len(&pubip_list->ip[i]);
+       for (i=0; i<in->num; i++) {
+               ctdb_public_ip_push(&in->ip[i], buf+offset, &np);
+               offset += np;
        }
+
+       *npush = offset;
 }
 
 int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                            struct ctdb_public_ip_list **out)
+                            struct ctdb_public_ip_list **out, size_t *npull)
 {
-       struct ctdb_public_ip_list *pubip_list;
-       struct ctdb_public_ip_list_wire *wire =
-               (struct ctdb_public_ip_list_wire *)buf;
-       size_t offset;
-       int i;
-       bool ret;
+       struct ctdb_public_ip_list *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
 
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (wire->num > buflen / sizeof(struct ctdb_public_ip)) {
-               return EMSGSIZE;
-       }
-       if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_public_ip) <
-           sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (buflen < sizeof(uint32_t) +
-                    wire->num * sizeof(struct ctdb_public_ip)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_public_ip_list);
+       if (val == NULL) {
+               return ENOMEM;
        }
 
-       pubip_list = talloc(mem_ctx, struct ctdb_public_ip_list);
-       if (pubip_list == NULL) {
-               return ENOMEM;
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       pubip_list->num = wire->num;
-       if (wire->num == 0) {
-               pubip_list->ip = NULL;
-               *out = pubip_list;
-               return 0;
+       if (val->num == 0) {
+               val->ip = NULL;
+               goto done;
        }
-       pubip_list->ip = talloc_array(pubip_list, struct ctdb_public_ip,
-                                     wire->num);
-       if (pubip_list->ip == NULL) {
-               talloc_free(pubip_list);
-               return ENOMEM;
+
+       val->ip = talloc_array(val, struct ctdb_public_ip, val->num);
+       if (val->ip == NULL) {
+               ret = ENOMEM;
+               goto fail;
        }
 
-       offset = offsetof(struct ctdb_public_ip_list_wire, ip);
-       for (i=0; i<wire->num; i++) {
-               ret = ctdb_public_ip_pull_elems(&buf[offset], buflen-offset,
-                                               pubip_list->ip,
-                                               &pubip_list->ip[i]);
+       for (i=0; i<val->num; i++) {
+               ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset,
+                                               val->ip, &val->ip[i], &np);
                if (ret != 0) {
-                       talloc_free(pubip_list);
-                       return ret;
+                       goto fail;
                }
-               offset += ctdb_public_ip_len(&pubip_list->ip[i]);
+               offset += np;
        }
 
-       *out = pubip_list;
+done:
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *node)
+size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in)
 {
-       return sizeof(struct ctdb_node_and_flags);
+       return ctdb_uint32_len(&in->pnn) +
+               ctdb_uint32_len(&in->flags) +
+               ctdb_sock_addr_len(&in->addr);
 }
 
-void ctdb_node_and_flags_push(struct ctdb_node_and_flags *node, uint8_t *buf)
+void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
+                             size_t *npush)
 {
-       memcpy(buf, node, sizeof(struct ctdb_node_and_flags));
+       size_t offset = 0, np;
+
+       ctdb_uint32_push(&in->pnn, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint32_push(&in->flags, buf+offset, &np);
+       offset += np;
+
+       ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
-static int ctdb_node_and_flags_pull_elems(TALLOC_CTX *mem_ctx,
-                                         uint8_t *buf, size_t buflen,
-                                         struct ctdb_node_and_flags *out)
+static int ctdb_node_and_flags_pull_elems(uint8_t *buf, size_t buflen,
+                                         TALLOC_CTX *mem_ctx,
+                                         struct ctdb_node_and_flags *out,
+                                         size_t *npull)
 {
-       if (buflen < sizeof(struct ctdb_node_and_flags)) {
-               return EMSGSIZE;
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(out, buf, sizeof(struct ctdb_node_and_flags));
+       ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+                                       &out->addr, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
+       *npull = offset;
        return 0;
 }
 
 int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                             struct ctdb_node_and_flags **out)
+                             struct ctdb_node_and_flags **out, size_t *npull)
 {
-       struct ctdb_node_and_flags *node;
+       struct ctdb_node_and_flags *val;
+       size_t np;
        int ret;
 
-       node = talloc(mem_ctx, struct ctdb_node_and_flags);
-       if (node == NULL) {
+       val = talloc(mem_ctx, struct ctdb_node_and_flags);
+       if (val == NULL) {
                return ENOMEM;
        }
 
-       ret = ctdb_node_and_flags_pull_elems(node, buf, buflen, node);
+       ret = ctdb_node_and_flags_pull_elems(buf, buflen, val, val, &np);
        if (ret != 0) {
-               TALLOC_FREE(node);
+               TALLOC_FREE(val);
+               return ret;
        }
 
-       *out = node;
+       *out = val;
+       *npull = np;
        return ret;
 }
 
-struct ctdb_node_map_wire {
-       uint32_t num;
-       struct ctdb_node_and_flags node[1];
-};
-
-size_t ctdb_node_map_len(struct ctdb_node_map *nodemap)
+size_t ctdb_node_map_len(struct ctdb_node_map *in)
 {
-       return sizeof(uint32_t) +
-              nodemap->num * sizeof(struct ctdb_node_and_flags);
+       size_t len;
+
+       len = ctdb_uint32_len(&in->num);
+       if (in->num > 0) {
+               len += in->num * ctdb_node_and_flags_len(&in->node[0]);
+       }
+
+       return len;
 }
 
-void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf)
+void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
 {
-       struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
-       size_t offset;
-       int i;
+       size_t offset = 0, np;
+       uint32_t i;
 
-       wire->num = nodemap->num;
+       ctdb_uint32_push(&in->num, buf+offset, &np);
+       offset += np;
 
-       offset = offsetof(struct ctdb_node_map_wire, node);
-       for (i=0; i<nodemap->num; i++) {
-               ctdb_node_and_flags_push(&nodemap->node[i], &buf[offset]);
-               offset += ctdb_node_and_flags_len(&nodemap->node[i]);
+       for (i=0; i<in->num; i++) {
+               ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
+               offset += np;
        }
+
+       *npush = offset;
 }
 
 int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                      struct ctdb_node_map **out)
+                      struct ctdb_node_map **out, size_t *npull)
 {
-       struct ctdb_node_map *nodemap;
-       struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
-       size_t offset;
-       int i;
-       bool ret;
+       struct ctdb_node_map *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
 
-       if (buflen < sizeof(uint32_t)) {
-               return EMSGSIZE;
-       }
-       if (wire->num > buflen / sizeof(struct ctdb_node_and_flags)) {
-               return EMSGSIZE;
-       }
-       if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_node_and_flags) <
-           sizeof(uint32_t)) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_node_map);
+       if (val == NULL) {
+               return ENOMEM;
        }
-       if (buflen < sizeof(uint32_t) +
-                    wire->num * sizeof(struct ctdb_node_and_flags)) {
-               return EMSGSIZE;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       nodemap = talloc(mem_ctx, struct ctdb_node_map);
-       if (nodemap == NULL) {
-               return ENOMEM;
+       if (val->num == 0) {
+               val->node = NULL;
+               goto done;
        }
 
-       nodemap->num = wire->num;
-       nodemap->node = talloc_array(nodemap, struct ctdb_node_and_flags,
-                                    wire->num);
-       if (nodemap->node == NULL) {
-               talloc_free(nodemap);
-               return ENOMEM;
+       val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
+       if (val->node == NULL) {
+               ret = ENOMEM;
+               goto fail;
        }
 
-       offset = offsetof(struct ctdb_node_map_wire, node);
-       for (i=0; i<wire->num; i++) {
-               ret = ctdb_node_and_flags_pull_elems(nodemap->node,
-                                                    &buf[offset],
+       for (i=0; i<val->num; i++) {
+               ret = ctdb_node_and_flags_pull_elems(buf+offset,
                                                     buflen-offset,
-                                                    &nodemap->node[i]);
+                                                    val->node, &val->node[i],
+                                                    &np);
                if (ret != 0) {
-                       talloc_free(nodemap);
-                       return ret;
+                       goto fail;
                }
-               offset += ctdb_node_and_flags_len(&nodemap->node[i]);
+               offset += np;
        }
 
-       *out = nodemap;
+done:
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
-size_t ctdb_script_len(struct ctdb_script *script)
+size_t ctdb_script_len(struct ctdb_script *in)
 {
-       return sizeof(struct ctdb_script);
+       return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
+               ctdb_timeval_len(&in->start) +
+               ctdb_timeval_len(&in->finished) +
+               ctdb_int32_len(&in->status) +
+               ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
+               ctdb_padding_len(4);
 }
 
-void ctdb_script_push(struct ctdb_script *script, uint8_t *buf)
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
 {
-       memcpy(buf, script, sizeof(struct ctdb_script));
+       size_t offset = 0, np;
+
+       ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
+       offset += np;
+
+       ctdb_timeval_push(&in->start, buf+offset, &np);
+       offset += np;
+
+       ctdb_timeval_push(&in->finished, buf+offset, &np);
+       offset += np;
+
+       ctdb_int32_push(&in->status, buf+offset, &np);
+       offset += np;
+
+       ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
+       offset += np;
+
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
 }
 
 static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
                                  TALLOC_CTX *mem_ctx,
-                                 struct ctdb_script *out)
+                                 struct ctdb_script *out, size_t *npull)
 {
-       if (buflen < sizeof(struct ctdb_script)) {
-               return EMSGSIZE;
+       size_t offset = 0, np;
+       int ret;
+
+       ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+                                 out->name, MAX_SCRIPT_NAME+1, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
+                               &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
+
+       ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+                                 out->output, MAX_SCRIPT_OUTPUT+1, &np);
+       if (ret != 0) {
+               return ret;
        }
+       offset += np;
 
-       memcpy(out, buf, sizeof(struct ctdb_script));
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               return ret;
+       }
+       offset += np;
 
+       *npull = offset;
        return 0;
 }
 
 int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    struct ctdb_script **out)
+                    struct ctdb_script **out, size_t *npull)
 {
-       struct ctdb_script *script;
+       struct ctdb_script *val;
+       size_t np;
        int ret;
 
-       script = talloc(mem_ctx, struct ctdb_script);
-       if (script == NULL) {
+       val = talloc(mem_ctx, struct ctdb_script);
+       if (val == NULL) {
                return ENOMEM;
        }
 
-       ret = ctdb_script_pull_elems(buf, buflen, script, script);
+       ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
        if (ret != 0) {
-               TALLOC_FREE(script);
+               TALLOC_FREE(val);
+               return ret;
        }
 
-       *out = script;
+       *out = val;
+       *npull = np;
        return ret;
 }
 
-struct ctdb_script_list_wire {
-       uint32_t num_scripts;
-       struct ctdb_script script[1];
-};
-
-size_t ctdb_script_list_len(struct ctdb_script_list *script_list)
+size_t ctdb_script_list_len(struct ctdb_script_list *in)
 {
-       int i;
        size_t len;
 
-       if (script_list == NULL) {
+       if (in == NULL) {
                return 0;
        }
 
-       len = offsetof(struct ctdb_script_list_wire, script);
-       for (i=0; i<script_list->num_scripts; i++) {
-               len += ctdb_script_len(&script_list->script[i]);
+       len = ctdb_uint32_len(&in->num_scripts) + ctdb_padding_len(4);
+       if (in->num_scripts > 0) {
+               len += in->num_scripts * ctdb_script_len(&in->script[0]);
        }
+
        return len;
 }
 
-void ctdb_script_list_push(struct ctdb_script_list *script_list, uint8_t *buf)
+void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
+                          size_t *npush)
 {
-       struct ctdb_script_list_wire *wire =
-               (struct ctdb_script_list_wire *)buf;
-       size_t offset;
-       int i;
+       size_t offset = 0, np;
+       uint32_t i;
 
-       if (script_list == NULL) {
+       if (in == NULL) {
+               *npush = 0;
                return;
        }
 
-       wire->num_scripts = script_list->num_scripts;
+       ctdb_uint32_push(&in->num_scripts, buf+offset, &np);
+       offset += np;
 
-       offset = offsetof(struct ctdb_script_list_wire, script);
-       for (i=0; i<script_list->num_scripts; i++) {
-               ctdb_script_push(&script_list->script[i], &buf[offset]);
-               offset += ctdb_script_len(&script_list->script[i]);
+       ctdb_padding_push(4, buf+offset, &np);
+       offset += np;
+
+       for (i=0; i<in->num_scripts; i++) {
+               ctdb_script_push(&in->script[i], buf+offset, &np);
+               offset += np;
        }
+
+       *npush = offset;
 }
 
 int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                         struct ctdb_script_list **out)
+                         struct ctdb_script_list **out, size_t *npull)
 {
-       struct ctdb_script_list *script_list;
-       struct ctdb_script_list_wire *wire =
-               (struct ctdb_script_list_wire *)buf;
-       size_t offset;
-       int i;
-       bool ret;
+       struct ctdb_script_list *val;
+       size_t offset = 0, np;
+       uint32_t i;
+       int ret;
 
        /* If event scripts have never been run, the result will be NULL */
        if (buflen == 0) {
-               *out = NULL;
-               return 0;
+               val = NULL;
+               goto done;
        }
 
-       offset = offsetof(struct ctdb_script_list_wire, script);
-
-       if (buflen < offset) {
-               return EMSGSIZE;
-       }
-       if (wire->num_scripts > buflen / sizeof(struct ctdb_script)) {
-               return EMSGSIZE;
-       }
-       if (offset + wire->num_scripts * sizeof(struct ctdb_script) < offset) {
-               return EMSGSIZE;
+       val = talloc(mem_ctx, struct ctdb_script_list);
+       if (val == NULL) {
+               return ENOMEM;
        }
-       if (buflen < offset + wire->num_scripts * sizeof(struct ctdb_script)) {
-               return EMSGSIZE;
+
+       ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_scripts,
+                              &np);
+       if (ret != 0) {
+               goto fail;
        }
+       offset += np;
 
-       script_list = talloc(mem_ctx, struct ctdb_script_list);
-       if (script_list == NULL) {
-               return ENOMEM;
+       ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
 
+       if (val->num_scripts == 0) {
+               goto done;
+               val->script = NULL;
        }
 
-       script_list->num_scripts = wire->num_scripts;
-       script_list->script = talloc_array(script_list, struct ctdb_script,
-                                          wire->num_scripts);
-       if (script_list->script == NULL) {
-               talloc_free(script_list);
-               return ENOMEM;
+       val->script = talloc_array(val, struct ctdb_script, val->num_scripts);
+       if (val->script == NULL) {
+               ret = ENOMEM;
+               goto fail;
        }
 
-       for (i=0; i<wire->num_scripts; i++) {
-               ret = ctdb_script_pull_elems(&buf[offset], buflen-offset,
-                                            script_list->script,
-                                            &script_list->script[i]);
+       for (i=0; i<val->num_scripts; i++) {
+               ret = ctdb_script_pull_elems(buf+offset, buflen-offset,
+                                            val, &val->script[i], &np);
                if (ret != 0) {
-                       talloc_free(script_list);
-                       return ret;
+                       goto fail;
                }
-               offset += ctdb_script_len(&script_list->script[i]);
+               offset += np;
        }
 
-       *out = script_list;
+done:
+       *out = val;
+       *npull = offset;
        return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
 }
 
 size_t ctdb_ban_state_len(struct ctdb_ban_state *ban_state)
@@ -2460,37 +4414,6 @@ int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        return 0;
 }
 
-size_t ctdb_tdb_data_len(TDB_DATA data)
-{
-       return data.dsize;
-}
-
-void ctdb_tdb_data_push(TDB_DATA data, uint8_t *buf)
-{
-       if (data.dsize > 0) {
-               memcpy(buf, data.dptr, data.dsize);
-       }
-}
-
-int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                      TDB_DATA *out)
-{
-       TDB_DATA data;
-
-       data.dsize = buflen;
-       if (data.dsize > 0) {
-               data.dptr = talloc_memdup(mem_ctx, buf, buflen);
-               if (data.dptr == NULL) {
-                       return ENOMEM;
-               }
-       } else {
-               data.dptr = NULL;
-       }
-
-       *out = data;
-       return 0;
-}
-
 size_t ctdb_server_id_len(struct ctdb_server_id *sid)
 {
        return sizeof(struct ctdb_server_id);