diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-07-13 15:09:31 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-08-30 14:59:25 +0200 |
commit | 4d8359ada01dc5835b976e305e505e463fdebb38 (patch) | |
tree | 0ada0abaa84cfd8d4c45dd421d6e4883732263ca /ctdb/protocol | |
parent | 95ae006d5cd9591242b739bb18b08dd286cc7132 (diff) | |
download | samba-4d8359ada01dc5835b976e305e505e463fdebb38.tar.gz |
ctdb-protocol: Fix marshalling for ctdb_disable_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.c | 8 | ||||
-rw-r--r-- | ctdb/protocol/protocol_private.h | 12 | ||||
-rw-r--r-- | ctdb/protocol/protocol_types.c | 82 |
3 files changed, 79 insertions, 23 deletions
diff --git a/ctdb/protocol/protocol_message.c b/ctdb/protocol/protocol_message.c index 3760c471b73..54a8c5a2470 100644 --- a/ctdb/protocol/protocol_message.c +++ b/ctdb/protocol/protocol_message.c @@ -175,11 +175,11 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata, break; case CTDB_SRVID_DISABLE_TAKEOVER_RUNS: - ctdb_disable_message_push(mdata->disable, buf); + ctdb_disable_message_push(mdata->disable, buf, &np); break; case CTDB_SRVID_DISABLE_RECOVERIES: - ctdb_disable_message_push(mdata->disable, buf); + ctdb_disable_message_push(mdata->disable, buf, &np); break; case CTDB_SRVID_DISABLE_IP_CHECK: @@ -265,12 +265,12 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen, case CTDB_SRVID_DISABLE_TAKEOVER_RUNS: ret = ctdb_disable_message_pull(buf, buflen, mem_ctx, - &mdata->disable); + &mdata->disable, &np); break; case CTDB_SRVID_DISABLE_RECOVERIES: ret = ctdb_disable_message_pull(buf, buflen, mem_ctx, - &mdata->disable); + &mdata->disable, &np); break; case CTDB_SRVID_DISABLE_IP_CHECK: diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index bfdac59b17f..a609930aae6 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -309,7 +309,8 @@ int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, 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, +int ctdb_election_message_pull(uint8_t *buf, size_t buflen, + TALLOC_CTX *mem_ctx, struct ctdb_election_message **out, size_t *npull); @@ -319,10 +320,11 @@ void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf, int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, struct ctdb_srvid_message **out, size_t *npull); -size_t ctdb_disable_message_len(struct ctdb_disable_message *disable); -void ctdb_disable_message_push(struct ctdb_disable_message *disable, - uint8_t *buf); +size_t ctdb_disable_message_len(struct ctdb_disable_message *in); +void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf, + size_t *npush); int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, - struct ctdb_disable_message **out); + struct ctdb_disable_message **out, + size_t *npull); #endif /* __PROTOCOL_PRIVATE_H__ */ diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c index 5c08b664074..e375b44184a 100644 --- a/ctdb/protocol/protocol_types.c +++ b/ctdb/protocol/protocol_types.c @@ -4777,34 +4777,88 @@ fail: return ret; } -size_t ctdb_disable_message_len(struct ctdb_disable_message *disable) +size_t ctdb_disable_message_len(struct ctdb_disable_message *in) { - return sizeof(struct ctdb_disable_message); + return ctdb_uint32_len(&in->pnn) + + ctdb_padding_len(4) + + ctdb_uint64_len(&in->srvid) + + ctdb_uint32_len(&in->timeout) + + ctdb_padding_len(4); } -void ctdb_disable_message_push(struct ctdb_disable_message *disable, - uint8_t *buf) +void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf, + size_t *npush) { - memcpy(buf, disable, sizeof(struct ctdb_disable_message)); + size_t offset = 0, np; + + ctdb_uint32_push(&in->pnn, buf+offset, &np); + offset += np; + + ctdb_padding_push(4, buf+offset, &np); + offset += np; + + ctdb_uint64_push(&in->srvid, buf+offset, &np); + offset += np; + + ctdb_uint32_push(&in->timeout, buf+offset, &np); + offset += np; + + ctdb_padding_push(4, buf+offset, &np); + offset += np; + + *npush = offset; } int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, - struct ctdb_disable_message **out) + struct ctdb_disable_message **out, + size_t *npull) { - struct ctdb_disable_message *disable; + struct ctdb_disable_message *val; + size_t offset = 0, np; + int ret; - if (buflen < sizeof(struct ctdb_disable_message)) { - return EMSGSIZE; + val = talloc(mem_ctx, struct ctdb_disable_message); + if (val == NULL) { + return ENOMEM; } - disable = talloc_memdup(mem_ctx, buf, - sizeof(struct ctdb_disable_message)); - if (disable == NULL) { - return ENOMEM; + ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &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_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np); + if (ret != 0) { + goto fail; } + offset += np; - *out = disable; + ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->timeout, &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; + + *out = val; + *npull = offset; return 0; + +fail: + talloc_free(val); + return ret; } size_t ctdb_server_id_len(struct ctdb_server_id *sid) |