ctdb-protocol: Fix marshalling for ctdb_public_ip
authorAmitay Isaacs <amitay@gmail.com>
Thu, 6 Jul 2017 04:04:51 +0000 (14:04 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:24 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_control.c
ctdb/protocol/protocol_message.c
ctdb/protocol/protocol_private.h
ctdb/protocol/protocol_types.c
ctdb/tests/src/protocol_types_compat_test.c
ctdb/tests/src/protocol_types_test.c

index ddbc75fd48ac572efdaa8074153944f5ed5f4387..925cea1052fafdf2be2c13481efa3064f813e75f 100644 (file)
@@ -571,11 +571,11 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
                break;
 
        case CTDB_CONTROL_RELEASE_IP:
-               ctdb_public_ip_push(cd->data.pubip, buf);
+               ctdb_public_ip_push(cd->data.pubip, buf, &np);
                break;
 
        case CTDB_CONTROL_TAKEOVER_IP:
-               ctdb_public_ip_push(cd->data.pubip, buf);
+               ctdb_public_ip_push(cd->data.pubip, buf, &np);
                break;
 
        case CTDB_CONTROL_TRAVERSE_KILL:
@@ -878,12 +878,12 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
 
        case CTDB_CONTROL_RELEASE_IP:
                ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
-                                         &cd->data.pubip);
+                                         &cd->data.pubip, &np);
                break;
 
        case CTDB_CONTROL_TAKEOVER_IP:
                ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
-                                         &cd->data.pubip);
+                                         &cd->data.pubip, &np);
                break;
 
        case CTDB_CONTROL_TRAVERSE_KILL:
index 1fc7fcf70294fa5288c1835ece03213f82b58161..2ae7724233031c8a0601a6e9f32e68791a4484dc 100644 (file)
@@ -144,7 +144,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
                break;
 
        case CTDB_SRVID_RECD_UPDATE_IP:
-               ctdb_public_ip_push(mdata->pubip, buf);
+               ctdb_public_ip_push(mdata->pubip, buf, &np);
                break;
 
        case CTDB_SRVID_VACUUM_FETCH:
@@ -229,7 +229,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
 
        case CTDB_SRVID_RECD_UPDATE_IP:
                ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
-                                         &mdata->pubip);
+                                         &mdata->pubip, &np);
                break;
 
        case CTDB_SRVID_VACUUM_FETCH:
index 9496b54fbc26f0238fe414e6f0aca3adf62eb9c7..27cdeb3792478edc336cebb7216ab2dfa054bbfc 100644 (file)
@@ -231,10 +231,11 @@ void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush);
 int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
                     struct ctdb_uptime **out, size_t *npull);
 
-size_t ctdb_public_ip_len(struct ctdb_public_ip *public_ip);
-void ctdb_public_ip_push(struct ctdb_public_ip *public_ip, uint8_t *buf);
+size_t ctdb_public_ip_len(struct ctdb_public_ip *in);
+void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
+                        size_t *npush);
 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);
 
 size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *pubip_list);
 void ctdb_public_ip_list_push(struct ctdb_public_ip_list *pubip_list,
index 4e8b575496edfa7a4ed8078c8b1ba295d4e8f242..a28244aad44de935e7875c2b1e3e042a712bf33b 100644 (file)
@@ -3387,46 +3387,70 @@ fail:
        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;
 }
 
@@ -3452,15 +3476,15 @@ void ctdb_public_ip_list_push(struct ctdb_public_ip_list *pubip_list,
 {
        struct ctdb_public_ip_list_wire *wire =
                (struct ctdb_public_ip_list_wire *)buf;
-       size_t offset;
+       size_t offset, np;
        int i;
 
        wire->num = pubip_list->num;
 
        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]);
+               ctdb_public_ip_push(&pubip_list->ip[i], &buf[offset], &np);
+               offset += np;
        }
 }
 
@@ -3470,7 +3494,7 @@ int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        struct ctdb_public_ip_list *pubip_list;
        struct ctdb_public_ip_list_wire *wire =
                (struct ctdb_public_ip_list_wire *)buf;
-       size_t offset;
+       size_t offset, np;
        int i;
        bool ret;
 
@@ -3511,12 +3535,12 @@ int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        for (i=0; i<wire->num; i++) {
                ret = ctdb_public_ip_pull_elems(&buf[offset], buflen-offset,
                                                pubip_list->ip,
-                                               &pubip_list->ip[i]);
+                                               &pubip_list->ip[i], &np);
                if (ret != 0) {
                        talloc_free(pubip_list);
                        return ret;
                }
-               offset += ctdb_public_ip_len(&pubip_list->ip[i]);
+               offset += np;
        }
 
        *out = pubip_list;
index ad908d0b515ee3a077666776ff82403dad25892e..a69d8d891f67ac240b357553bfae064bd9eecdc8 100644 (file)
@@ -1166,6 +1166,51 @@ static int ctdb_uptime_pull_old(uint8_t *buf, size_t buflen,
        return 0;
 }
 
+static size_t ctdb_public_ip_len_old(struct ctdb_public_ip *in)
+{
+       return sizeof(struct ctdb_public_ip);
+}
+
+static void ctdb_public_ip_push_old(struct ctdb_public_ip *in, uint8_t *buf)
+{
+       memcpy(buf, in, sizeof(struct ctdb_public_ip));
+}
+
+static int ctdb_public_ip_pull_elems_old(uint8_t *buf, size_t buflen,
+                                        TALLOC_CTX *mem_ctx,
+                                        struct ctdb_public_ip *out)
+{
+       if (buflen < sizeof(struct ctdb_public_ip)) {
+               return EMSGSIZE;
+       }
+
+       memcpy(out, buf, sizeof(struct ctdb_public_ip));
+
+       return 0;
+}
+
+static int ctdb_public_ip_pull_old(uint8_t *buf, size_t buflen,
+                                  TALLOC_CTX *mem_ctx,
+                                  struct ctdb_public_ip **out)
+{
+       struct ctdb_public_ip *val;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_public_ip);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_public_ip_pull_elems_old(buf, buflen, val, 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);
@@ -1191,6 +1236,7 @@ COMPAT_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
 COMPAT_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
 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);
 
 int main(int argc, char *argv[])
 {
@@ -1221,6 +1267,7 @@ int main(int argc, char *argv[])
        COMPAT_TEST_FUNC(ctdb_addr_info)();
        COMPAT_TEST_FUNC(ctdb_transdb)();
        COMPAT_TEST_FUNC(ctdb_uptime)();
+       COMPAT_TEST_FUNC(ctdb_public_ip)();
 
        return 0;
 }
index d17beb47d1e2d4ea2177fbb923b04c516145deae..2360304ccd40ad1ce4d5b80301ade0326e836447 100644 (file)
@@ -70,7 +70,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
 PROTOCOL_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
 PROTOCOL_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
 PROTOCOL_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
-DEFINE_TEST(struct ctdb_public_ip, ctdb_public_ip);
+PROTOCOL_TYPE3_TEST(struct ctdb_public_ip, ctdb_public_ip);
 DEFINE_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
 DEFINE_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
 DEFINE_TEST(struct ctdb_node_map, ctdb_node_map);