summaryrefslogtreecommitdiff
path: root/ctdb/protocol
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-06-28 16:50:53 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:26 +0200
commitf02a1a1149f614309d68e0e878a01d2467d3c8b3 (patch)
tree37a4344090d5589e60b4b4d39ecc5e97b5715f6d /ctdb/protocol
parent3f2495a4ebfac9de1e566dbe2263a79d97e229c5 (diff)
downloadsamba-f02a1a1149f614309d68e0e878a01d2467d3c8b3.tar.gz
ctdb-protocol: Add marshalling for ctdb_req_keepalive
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_api.h14
-rw-r--r--ctdb/protocol/protocol_debug.c24
-rw-r--r--ctdb/protocol/protocol_keepalive.c95
3 files changed, 133 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_api.h b/ctdb/protocol/protocol_api.h
index d6acefbcbcc..522b009b151 100644
--- a/ctdb/protocol/protocol_api.h
+++ b/ctdb/protocol/protocol_api.h
@@ -636,6 +636,20 @@ int ctdb_req_message_data_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_req_message_data *c);
+/* From protocol/protocol_keepalive.c */
+
+size_t ctdb_req_keepalive_len(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c);
+
+int ctdb_req_keepalive_push(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_keepalive *c);
+
/* From protocol/protocol_event.c */
void ctdb_event_header_fill(struct ctdb_event_header *h, uint32_t reqid);
diff --git a/ctdb/protocol/protocol_debug.c b/ctdb/protocol/protocol_debug.c
index a448fad9895..9cca76c5107 100644
--- a/ctdb/protocol/protocol_debug.c
+++ b/ctdb/protocol/protocol_debug.c
@@ -461,6 +461,14 @@ static void ctdb_reply_control_print(struct ctdb_reply_control *c, FILE *fp)
fprintf(fp, "\n");
}
+static void ctdb_req_keepalive_print(struct ctdb_req_keepalive *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " version:0x%"PRIx32, c->version);
+ fprintf(fp, " uptime:%"PRIu32, c->uptime);
+ fprintf(fp, "\n");
+}
+
/*
* Parse routines
*/
@@ -585,6 +593,21 @@ static void ctdb_reply_control_parse(uint8_t *buf, size_t buflen, FILE *fp,
ctdb_reply_control_print(&c, fp);
}
+static void ctdb_req_keepalive_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_keepalive c;
+ int ret;
+
+ ret = ctdb_req_keepalive_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_KEEPALIVE\n");
+ return;
+ }
+
+ ctdb_req_keepalive_print(&c, fp);
+}
+
/*
* Packet print
*/
@@ -650,6 +673,7 @@ void ctdb_packet_print(uint8_t *buf, size_t buflen, FILE *fp)
break;
case CTDB_REQ_KEEPALIVE:
+ ctdb_req_keepalive_parse(buf, buflen, fp, mem_ctx);
break;
default:
diff --git a/ctdb/protocol/protocol_keepalive.c b/ctdb/protocol/protocol_keepalive.c
new file mode 100644
index 00000000000..3a1fc0ec674
--- /dev/null
+++ b/ctdb/protocol/protocol_keepalive.c
@@ -0,0 +1,95 @@
+/*
+ CTDB protocol marshalling
+
+ Copyright (C) Amitay Isaacs 2017
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/network.h"
+
+#include <talloc.h>
+#include <tdb.h>
+
+#include "protocol.h"
+#include "protocol_api.h"
+#include "protocol_private.h"
+
+size_t ctdb_req_keepalive_len(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->version) +
+ ctdb_uint32_len(&c->uptime);
+}
+
+int ctdb_req_keepalive_push(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t length, offset = 0, np;
+
+ length = ctdb_req_keepalive_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->version, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->uptime, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_keepalive *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf, buflen, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->version, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->uptime, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}