1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-29 13:49:30 +03:00

ctdb-protocol: Fix marshalling for ctdb_node_and_flags

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs
2017-07-06 14:18:02 +10:00
committed by Martin Schwenke
parent 2a8dd02549
commit c060d01b3f
4 changed files with 113 additions and 29 deletions

View File

@ -243,10 +243,11 @@ void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_public_ip_list **out, size_t *npull);
size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *node);
void ctdb_node_and_flags_push(struct ctdb_node_and_flags *node, uint8_t *buf);
size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in);
void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
size_t *npush);
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);
size_t ctdb_node_map_len(struct ctdb_node_map *nodemap);
void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf);

View File

@ -3532,46 +3532,81 @@ fail:
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;
memcpy(out, buf, sizeof(struct ctdb_node_and_flags));
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
if (ret != 0) {
return ret;
}
offset += np;
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;
}
@ -3589,15 +3624,15 @@ size_t ctdb_node_map_len(struct ctdb_node_map *nodemap)
void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf)
{
struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
size_t offset;
size_t offset, np;
int i;
wire->num = nodemap->num;
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]);
ctdb_node_and_flags_push(&nodemap->node[i], &buf[offset], &np);
offset += np;
}
}
@ -3606,7 +3641,7 @@ int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
{
struct ctdb_node_map *nodemap;
struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
size_t offset;
size_t offset, np;
int i;
bool ret;
@ -3640,15 +3675,15 @@ int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
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],
ret = ctdb_node_and_flags_pull_elems(&buf[offset],
buflen-offset,
&nodemap->node[i]);
nodemap->node,
&nodemap->node[i], &np);
if (ret != 0) {
talloc_free(nodemap);
return ret;
}
offset += ctdb_node_and_flags_len(&nodemap->node[i]);
offset += np;
}
*out = nodemap;

View File

@ -1305,6 +1305,52 @@ static int ctdb_public_ip_list_pull_old(uint8_t *buf, size_t buflen,
return 0;
}
static size_t ctdb_node_and_flags_len_old(struct ctdb_node_and_flags *in)
{
return sizeof(struct ctdb_node_and_flags);
}
static void ctdb_node_and_flags_push_old(struct ctdb_node_and_flags *in,
uint8_t *buf)
{
memcpy(buf, in, sizeof(struct ctdb_node_and_flags));
}
static int ctdb_node_and_flags_pull_elems_old(TALLOC_CTX *mem_ctx,
uint8_t *buf, size_t buflen,
struct ctdb_node_and_flags *out)
{
if (buflen < sizeof(struct ctdb_node_and_flags)) {
return EMSGSIZE;
}
memcpy(out, buf, sizeof(struct ctdb_node_and_flags));
return 0;
}
static int ctdb_node_and_flags_pull_old(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_node_and_flags **out)
{
struct ctdb_node_and_flags *val;
int ret;
val = talloc(mem_ctx, struct ctdb_node_and_flags);
if (val == NULL) {
return ENOMEM;
}
ret = ctdb_node_and_flags_pull_elems_old(val, buf, buflen, val);
if (ret != 0) {
TALLOC_FREE(val);
return ret;
}
*out = val;
return ret;
}
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
@ -1332,6 +1378,7 @@ COMPAT_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
COMPAT_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
COMPAT_TYPE3_TEST(struct ctdb_public_ip, ctdb_public_ip);
COMPAT_TYPE3_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
COMPAT_TYPE3_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
int main(int argc, char *argv[])
{
@ -1364,6 +1411,7 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_uptime)();
COMPAT_TEST_FUNC(ctdb_public_ip)();
COMPAT_TEST_FUNC(ctdb_public_ip_list)();
COMPAT_TEST_FUNC(ctdb_node_and_flags)();
return 0;
}

View File

@ -72,7 +72,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
PROTOCOL_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
PROTOCOL_TYPE3_TEST(struct ctdb_public_ip, ctdb_public_ip);
PROTOCOL_TYPE3_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
DEFINE_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
PROTOCOL_TYPE3_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
DEFINE_TEST(struct ctdb_node_map, ctdb_node_map);
DEFINE_TEST(struct ctdb_script, ctdb_script);
DEFINE_TEST(struct ctdb_script_list, ctdb_script_list);