mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
ctdb-protocol: Fix marshalling for ctdb_public_ip_info
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
a8569128f5
commit
b03f3b5663
@ -1527,7 +1527,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
|
||||
ctdb_public_ip_info_push(cd->data.ipinfo, buf);
|
||||
ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_GET_IFACES:
|
||||
@ -1709,7 +1709,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
|
||||
ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.ipinfo);
|
||||
&cd->data.ipinfo, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_GET_IFACES:
|
||||
|
@ -288,10 +288,11 @@ void ctdb_iface_list_push(struct ctdb_iface_list *in, uint8_t *buf,
|
||||
int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_iface_list **out, size_t *npull);
|
||||
|
||||
size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *ipinfo);
|
||||
void ctdb_public_ip_info_push(struct ctdb_public_ip_info *ipinfo, uint8_t *buf);
|
||||
size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in);
|
||||
void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
|
||||
size_t *npush);
|
||||
int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_public_ip_info **out);
|
||||
struct ctdb_public_ip_info **out, size_t *npull);
|
||||
|
||||
size_t ctdb_key_data_len(struct ctdb_key_data *key);
|
||||
void ctdb_key_data_push(struct ctdb_key_data *key, uint8_t *buf);
|
||||
|
@ -4163,81 +4163,70 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ctdb_public_ip_info_wire {
|
||||
struct ctdb_public_ip ip;
|
||||
uint32_t active_idx;
|
||||
uint32_t num;
|
||||
struct ctdb_iface ifaces[1];
|
||||
};
|
||||
|
||||
size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *ipinfo)
|
||||
size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in)
|
||||
{
|
||||
return offsetof(struct ctdb_public_ip_info_wire, num) +
|
||||
ctdb_iface_list_len(ipinfo->ifaces);
|
||||
return ctdb_public_ip_len(&in->ip) +
|
||||
ctdb_uint32_len(&in->active_idx) +
|
||||
ctdb_iface_list_len(in->ifaces);
|
||||
}
|
||||
|
||||
void ctdb_public_ip_info_push(struct ctdb_public_ip_info *ipinfo, uint8_t *buf)
|
||||
void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
|
||||
size_t *npush)
|
||||
{
|
||||
struct ctdb_public_ip_info_wire *wire =
|
||||
(struct ctdb_public_ip_info_wire *)buf;
|
||||
size_t offset;
|
||||
size_t offset = 0, np;
|
||||
|
||||
offset = offsetof(struct ctdb_public_ip_info_wire, num);
|
||||
memcpy(wire, ipinfo, offset);
|
||||
wire->num = ipinfo->ifaces->num;
|
||||
memcpy(wire->ifaces, ipinfo->ifaces->iface,
|
||||
ipinfo->ifaces->num * sizeof(struct ctdb_iface));
|
||||
ctdb_public_ip_push(&in->ip, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_uint32_push(&in->active_idx, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_iface_list_push(in->ifaces, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_public_ip_info **out)
|
||||
struct ctdb_public_ip_info **out, size_t *npull)
|
||||
{
|
||||
struct ctdb_public_ip_info *ipinfo;
|
||||
struct ctdb_public_ip_info_wire *wire =
|
||||
(struct ctdb_public_ip_info_wire *)buf;
|
||||
struct ctdb_public_ip_info *val;
|
||||
size_t offset = 0, np;
|
||||
int ret;
|
||||
|
||||
if (buflen < offsetof(struct ctdb_public_ip_info_wire, ifaces)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (wire->num > buflen / sizeof(struct ctdb_iface)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (offsetof(struct ctdb_public_ip_info_wire, ifaces) +
|
||||
wire->num * sizeof(struct ctdb_iface) <
|
||||
offsetof(struct ctdb_public_ip_info_wire, ifaces)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (buflen < offsetof(struct ctdb_public_ip_info_wire, ifaces) +
|
||||
wire->num * sizeof(struct ctdb_iface)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
ipinfo = talloc(mem_ctx, struct ctdb_public_ip_info);
|
||||
if (ipinfo == NULL) {
|
||||
val = talloc(mem_ctx, struct ctdb_public_ip_info);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(ipinfo, wire, offsetof(struct ctdb_public_ip_info_wire, num));
|
||||
|
||||
ipinfo->ifaces = talloc(ipinfo, struct ctdb_iface_list);
|
||||
if (ipinfo->ifaces == NULL) {
|
||||
talloc_free(ipinfo);
|
||||
return ENOMEM;
|
||||
ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset, val,
|
||||
&val->ip, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ipinfo->ifaces->num = wire->num;
|
||||
ipinfo->ifaces->iface = talloc_array(ipinfo->ifaces, struct ctdb_iface,
|
||||
wire->num);
|
||||
if (ipinfo->ifaces->iface == NULL) {
|
||||
talloc_free(ipinfo);
|
||||
return ENOMEM;
|
||||
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->active_idx,
|
||||
&np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
memcpy(ipinfo->ifaces->iface, wire->ifaces,
|
||||
wire->num * sizeof(struct ctdb_iface));
|
||||
ret = ctdb_iface_list_pull(buf+offset, buflen-offset, val,
|
||||
&val->ifaces, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
*out = ipinfo;
|
||||
*out = val;
|
||||
*npull = offset;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ctdb_key_data_wire {
|
||||
|
@ -1772,6 +1772,85 @@ static int ctdb_iface_list_pull_old(uint8_t *buf, size_t buflen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ctdb_public_ip_info_wire {
|
||||
struct ctdb_public_ip ip;
|
||||
uint32_t active_idx;
|
||||
uint32_t num;
|
||||
struct ctdb_iface ifaces[1];
|
||||
};
|
||||
|
||||
static size_t ctdb_public_ip_info_len_old(struct ctdb_public_ip_info *in)
|
||||
{
|
||||
return offsetof(struct ctdb_public_ip_info_wire, num) +
|
||||
ctdb_iface_list_len_old(in->ifaces);
|
||||
}
|
||||
|
||||
static void ctdb_public_ip_info_push_old(struct ctdb_public_ip_info *in,
|
||||
uint8_t *buf)
|
||||
{
|
||||
struct ctdb_public_ip_info_wire *wire =
|
||||
(struct ctdb_public_ip_info_wire *)buf;
|
||||
size_t offset;
|
||||
|
||||
offset = offsetof(struct ctdb_public_ip_info_wire, num);
|
||||
memcpy(wire, in, offset);
|
||||
wire->num = in->ifaces->num;
|
||||
memcpy(wire->ifaces, in->ifaces->iface,
|
||||
in->ifaces->num * sizeof(struct ctdb_iface));
|
||||
}
|
||||
|
||||
static int ctdb_public_ip_info_pull_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_public_ip_info **out)
|
||||
{
|
||||
struct ctdb_public_ip_info *val;
|
||||
struct ctdb_public_ip_info_wire *wire =
|
||||
(struct ctdb_public_ip_info_wire *)buf;
|
||||
|
||||
if (buflen < offsetof(struct ctdb_public_ip_info_wire, ifaces)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (wire->num > buflen / sizeof(struct ctdb_iface)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (offsetof(struct ctdb_public_ip_info_wire, ifaces) +
|
||||
wire->num * sizeof(struct ctdb_iface) <
|
||||
offsetof(struct ctdb_public_ip_info_wire, ifaces)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (buflen < offsetof(struct ctdb_public_ip_info_wire, ifaces) +
|
||||
wire->num * sizeof(struct ctdb_iface)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
val = talloc(mem_ctx, struct ctdb_public_ip_info);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(val, wire, offsetof(struct ctdb_public_ip_info_wire, num));
|
||||
|
||||
val->ifaces = talloc(val, struct ctdb_iface_list);
|
||||
if (val->ifaces == NULL) {
|
||||
talloc_free(val);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
val->ifaces->num = wire->num;
|
||||
val->ifaces->iface = talloc_array(val->ifaces, struct ctdb_iface,
|
||||
wire->num);
|
||||
if (val->ifaces->iface == NULL) {
|
||||
talloc_free(val);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(val->ifaces->iface, wire->ifaces,
|
||||
wire->num * sizeof(struct ctdb_iface));
|
||||
|
||||
*out = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
||||
@ -1807,6 +1886,7 @@ COMPAT_TYPE3_TEST(struct ctdb_ban_state, ctdb_ban_state);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_notify_data, ctdb_notify_data);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_iface, ctdb_iface);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_iface_list, ctdb_iface_list);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -1847,6 +1927,7 @@ int main(int argc, char *argv[])
|
||||
COMPAT_TEST_FUNC(ctdb_notify_data)();
|
||||
COMPAT_TEST_FUNC(ctdb_iface)();
|
||||
COMPAT_TEST_FUNC(ctdb_iface_list)();
|
||||
COMPAT_TEST_FUNC(ctdb_public_ip_info)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_ban_state, ctdb_ban_state);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_notify_data, ctdb_notify_data);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_iface, ctdb_iface);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_iface_list, ctdb_iface_list);
|
||||
DEFINE_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
|
||||
DEFINE_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
|
||||
DEFINE_TEST(struct ctdb_key_data, ctdb_key_data);
|
||||
DEFINE_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
|
||||
|
Loading…
x
Reference in New Issue
Block a user