summaryrefslogtreecommitdiff
path: root/ctdb/protocol
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-07-13 14:56:50 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:25 +0200
commitd8309d9548276ff79b985f71ce686642d7377d6d (patch)
treec7ffafda7183fc0aa7fb075c24d94886f2bc003e /ctdb/protocol
parent2abf9c1bdb5420780617c0645aabfba740a4e75f (diff)
downloadsamba-d8309d9548276ff79b985f71ce686642d7377d6d.tar.gz
ctdb-protocol: Fix marshalling for ctdb_election_message
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/protocol')
-rw-r--r--ctdb/protocol/protocol_message.c4
-rw-r--r--ctdb/protocol/protocol_private.h9
-rw-r--r--ctdb/protocol/protocol_types.c88
3 files changed, 80 insertions, 21 deletions
diff --git a/ctdb/protocol/protocol_message.c b/ctdb/protocol/protocol_message.c
index 2ae77242330..b7eaa4fbe9f 100644
--- a/ctdb/protocol/protocol_message.c
+++ b/ctdb/protocol/protocol_message.c
@@ -125,7 +125,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
break;
case CTDB_SRVID_ELECTION:
- ctdb_election_message_push(mdata->election, buf);
+ ctdb_election_message_push(mdata->election, buf, &np);
break;
case CTDB_SRVID_RECONFIGURE:
@@ -206,7 +206,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
case CTDB_SRVID_ELECTION:
ret = ctdb_election_message_pull(buf, buflen, mem_ctx,
- &mdata->election);
+ &mdata->election, &np);
break;
case CTDB_SRVID_RECONFIGURE:
diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h
index 280fc9904d8..8e47d73c2dd 100644
--- a/ctdb/protocol/protocol_private.h
+++ b/ctdb/protocol/protocol_private.h
@@ -306,11 +306,12 @@ void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_db_statistics **out, size_t *npull);
-size_t ctdb_election_message_len(struct ctdb_election_message *election);
-void ctdb_election_message_push(struct ctdb_election_message *election,
- uint8_t *buf);
+size_t ctdb_election_message_len(struct ctdb_election_message *in);
+void ctdb_election_message_push(struct ctdb_election_message *in,
+ uint8_t *buf, size_t *npush);
int ctdb_election_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_election_message **out);
+ struct ctdb_election_message **out,
+ size_t *npull);
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *msg);
void ctdb_srvid_message_push(struct ctdb_srvid_message *msg, uint8_t *buf);
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
index f3d5d60b302..3ee9fb7f64f 100644
--- a/ctdb/protocol/protocol_types.c
+++ b/ctdb/protocol/protocol_types.c
@@ -4626,34 +4626,92 @@ int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
return 0;
}
-size_t ctdb_election_message_len(struct ctdb_election_message *election)
+size_t ctdb_election_message_len(struct ctdb_election_message *in)
{
- return sizeof(struct ctdb_election_message);
+ return ctdb_uint32_len(&in->num_connected) +
+ ctdb_padding_len(4) +
+ ctdb_timeval_len(&in->priority_time) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->node_flags);
}
-void ctdb_election_message_push(struct ctdb_election_message *election,
- uint8_t *buf)
+void ctdb_election_message_push(struct ctdb_election_message *in,
+ uint8_t *buf, size_t *npush)
{
- memcpy(buf, election, sizeof(struct ctdb_election_message));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->num_connected, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->priority_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_flags, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
-int ctdb_election_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_election_message **out)
+int ctdb_election_message_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_election_message **out,
+ size_t *npull)
{
- struct ctdb_election_message *election;
+ struct ctdb_election_message *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_election_message)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_election_message);
+ if (val == NULL) {
+ return ENOMEM;
}
- election = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_election_message));
- if (election == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_connected,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->priority_time, &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;
- *out = election;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->node_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *msg)