struct ctdb_client_context *client = talloc_get_type_abort(
private_data, struct ctdb_client_context);
struct ctdb_req_header hdr;
+ size_t np;
int ret;
- ret = ctdb_req_header_pull(buf, buflen, &hdr);
+ ret = ctdb_req_header_pull(buf, buflen, &hdr, &np);
if (ret != 0) {
DEBUG(DEBUG_WARNING, ("invalid header, ret=%d\n", ret));
return;
uint32_t operation, uint32_t destnode,
uint32_t srcnode, uint32_t reqid);
-size_t ctdb_req_header_len(struct ctdb_req_header *h);
-void ctdb_req_header_push(struct ctdb_req_header *h, uint8_t *buf);
+size_t ctdb_req_header_len(struct ctdb_req_header *in);
+void ctdb_req_header_push(struct ctdb_req_header *in, uint8_t *buf,
+ size_t *npush);
int ctdb_req_header_pull(uint8_t *buf, size_t buflen,
- struct ctdb_req_header *h);
+ struct ctdb_req_header *out, size_t *npull);
int ctdb_req_header_verify(struct ctdb_req_header *h, uint32_t operation);
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->flags = c->flags;
wire->db_id = c->db_id;
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->status = c->status;
wire->datalen = ctdb_tdb_data_len(&c->data);
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->status = c->status;
wire->msglen = ctdb_tdb_data_len(&c->msg);
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->db_id = c->db_id;
wire->rsn = c->rsn;
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->db_id = c->db_id;
wire->rsn = c->rsn;
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
{
struct ctdb_req_control_wire *wire =
(struct ctdb_req_control_wire *)buf;
- size_t length;
+ size_t length, np;
length = ctdb_req_control_len(h, request);
if (*buflen < length) {
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->opcode = request->opcode;
wire->pad = request->pad;
{
struct ctdb_req_control_wire *wire =
(struct ctdb_req_control_wire *)buf;
- size_t length;
+ size_t length, np;
int ret;
length = offsetof(struct ctdb_req_control_wire, data);
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->status = reply->status;
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct ctdb_req_header h;
+ size_t np;
int ret;
fprintf(fp, "Buffer len:%zu\n", buflen);
- ret = ctdb_req_header_pull(buf, buflen, &h);
+ ret = ctdb_req_header_pull(buf, buflen, &h, &np);
if (ret != 0) {
fprintf(fp, "Failed to parse ctdb packet header\n");
return;
#include "protocol.h"
#include "protocol_api.h"
+#include "protocol_private.h"
int ctdb_req_header_verify(struct ctdb_req_header *h, uint32_t operation)
{
h->reqid = reqid;
}
-size_t ctdb_req_header_len(struct ctdb_req_header *h)
+size_t ctdb_req_header_len(struct ctdb_req_header *in)
{
- return sizeof(struct ctdb_req_header);
+ return ctdb_uint32_len(&in->length) +
+ ctdb_uint32_len(&in->ctdb_magic) +
+ ctdb_uint32_len(&in->ctdb_version) +
+ ctdb_uint32_len(&in->generation) +
+ ctdb_uint32_len(&in->operation) +
+ ctdb_uint32_len(&in->destnode) +
+ ctdb_uint32_len(&in->srcnode) +
+ ctdb_uint32_len(&in->reqid);
}
-void ctdb_req_header_push(struct ctdb_req_header *h, uint8_t *buf)
+void ctdb_req_header_push(struct ctdb_req_header *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, h, sizeof(struct ctdb_req_header));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->length, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ctdb_magic, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ctdb_version, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->generation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->operation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->destnode, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->srcnode, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_req_header_pull(uint8_t *buf, size_t buflen,
- struct ctdb_req_header *h)
+ struct ctdb_req_header *out, size_t *npull)
{
- if (buflen < sizeof(struct ctdb_req_header)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->length, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->ctdb_magic,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->ctdb_version,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->generation,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->operation,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->destnode, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->srcnode, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reqid, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(h, buf, sizeof(struct ctdb_req_header));
+ *npull = offset;
return 0;
}
{
struct ctdb_req_message_wire *wire =
(struct ctdb_req_message_wire *)buf;
- size_t length;
+ size_t length, np;
length = ctdb_req_message_len(h, message);
if (*buflen < length) {
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->srvid = message->srvid;
wire->datalen = ctdb_message_data_len(&message->data, message->srvid);
{
struct ctdb_req_message_wire *wire =
(struct ctdb_req_message_wire *)buf;
- size_t length;
+ size_t length, np;
int ret;
length = offsetof(struct ctdb_req_message_wire, data);
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
}
h->length = *buflen;
- ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
+ ctdb_req_header_push(h, (uint8_t *)&wire->hdr, &np);
wire->srvid = message->srvid;
wire->datalen = ctdb_tdb_data_len(&message->data);
}
if (h != NULL) {
- ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
+ ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h,
+ &np);
if (ret != 0) {
return ret;
}
req, struct client_state);
struct ctdbd_context *ctdb = state->ctdb;
struct ctdb_req_header header;
+ size_t np;
int ret, i;
- ret = ctdb_req_header_pull(buf, buflen, &header);
+ ret = ctdb_req_header_pull(buf, buflen, &header, &np);
if (ret != 0) {
return;
}
for (i=0; i<ctdb->node_map->num_nodes; i++) {
header.destnode = i;
- ctdb_req_header_push(&header, buf);
+ ctdb_req_header_push(&header, buf, &np);
client_process_packet(req, buf, buflen);
}
return;
header.destnode = i;
- ctdb_req_header_push(&header, buf);
+ ctdb_req_header_push(&header, buf, &np);
client_process_packet(req, buf, buflen);
}
return;
return;
}
- ctdb_req_header_push(&header, buf);
+ ctdb_req_header_push(&header, buf, &np);
client_process_packet(req, buf, buflen);
}
uint8_t *buf, size_t buflen)
{
struct ctdb_req_header header;
+ size_t np;
int ret;
- ret = ctdb_req_header_pull(buf, buflen, &header);
+ ret = ctdb_req_header_pull(buf, buflen, &header, &np);
if (ret != 0) {
return;
}
* Functions to fill and verify protocol structures
*/
+void fill_ctdb_req_header(struct ctdb_req_header *h)
+{
+ h->length = rand32();
+ h->ctdb_magic = rand32();
+ h->ctdb_version = rand32();
+ h->generation = rand32();
+ h->operation = rand32();
+ h->destnode = rand32();
+ h->srcnode = rand32();
+ h->reqid = rand32();
+}
+
void verify_ctdb_req_header(struct ctdb_req_header *h,
struct ctdb_req_header *h2)
{
- verify_buffer(h, h2, sizeof(struct ctdb_req_header));
+ assert(h->length == h2->length);
+ assert(h->ctdb_magic == h2->ctdb_magic);
+ assert(h->ctdb_version == h2->ctdb_version);
+ assert(h->generation == h2->generation);
+ assert(h->operation == h2->operation);
+ assert(h->destnode == h2->destnode);
+ assert(h->srcnode == h2->srcnode);
+ assert(h->reqid == h2->reqid);
}
void fill_ctdb_req_call(TALLOC_CTX *mem_ctx, struct ctdb_req_call *c)
#include "protocol/protocol.h"
+void fill_ctdb_req_header(struct ctdb_req_header *h);
void verify_ctdb_req_header(struct ctdb_req_header *h,
struct ctdb_req_header *h2);
#include "protocol/protocol_basic.c"
#include "protocol/protocol_types.c"
+#include "protocol/protocol_header.c"
#include "tests/src/protocol_common.h"
+#include "tests/src/protocol_common_ctdb.h"
#define COMPAT_TEST_FUNC(NAME) test_ ##NAME## _compat
#define OLD_LEN_FUNC(NAME) NAME## _len_old
talloc_free(mem_ctx); \
}
+
+static size_t ctdb_req_header_len_old(struct ctdb_req_header *in)
+{
+ return sizeof(struct ctdb_req_header);
+}
+
+static void ctdb_req_header_push_old(struct ctdb_req_header *in, uint8_t *buf)
+{
+ memcpy(buf, in, sizeof(struct ctdb_req_header));
+}
+
+static int ctdb_req_header_pull_old(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *out)
+{
+ if (buflen < sizeof(struct ctdb_req_header)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(struct ctdb_req_header));
+ return 0;
+}
+
+
+COMPAT_CTDB1_TEST(struct ctdb_req_header, ctdb_req_header);
+
int main(int argc, char *argv[])
{
if (argc == 2) {
srandom(seed);
}
+ COMPAT_TEST_FUNC(ctdb_req_header)();
+
return 0;
}
talloc_free(mem_ctx); \
}
-static void test_ctdb_req_header(void)
-{
- TALLOC_CTX *mem_ctx;
- uint8_t *pkt;
- size_t pkt_len;
- struct ctdb_req_header h, h2;
- int ret;
-
- printf("ctdb_req_header\n");
- fflush(stdout);
-
- mem_ctx = talloc_new(NULL);
- assert(mem_ctx != NULL);
-
- ctdb_req_header_fill(&h, GENERATION, OPERATION, DESTNODE, SRCNODE,
- REQID);
-
- ret = ctdb_allocate_pkt(mem_ctx, ctdb_req_header_len(&h),
- &pkt, &pkt_len);
- assert(ret == 0);
- assert(pkt != NULL);
- assert(pkt_len >= ctdb_req_header_len(&h));
-
- ctdb_req_header_push(&h, pkt);
-
- ret = ctdb_req_header_pull(pkt, pkt_len, &h2);
- assert(ret == 0);
-
- verify_ctdb_req_header(&h, &h2);
-
- talloc_free(mem_ctx);
-}
+PROTOCOL_CTDB1_TEST(struct ctdb_req_header, ctdb_req_header);
static void test_ctdb_req_call(void)
{
srandom(seed);
}
- test_ctdb_req_header();
+ TEST_FUNC(ctdb_req_header)();
test_ctdb_req_call();
test_ctdb_reply_call();