diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-04-05 16:25:42 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-10-10 11:45:19 +0200 |
commit | c700464d2330f3cede96349c0cdcc55bbb88a5a0 (patch) | |
tree | 79f5ce79b1a9cffc28f87967c902210458fb42c6 /ctdb/protocol | |
parent | 24e4197195a4a23d1b901ce1d5d9ab5fca22696a (diff) | |
download | samba-c700464d2330f3cede96349c0cdcc55bbb88a5a0.tar.gz |
ctdb-protocol: Add protocol marshalling for CTDB_REQ_TUNNEL
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.h | 14 | ||||
-rw-r--r-- | ctdb/protocol/protocol_debug.c | 47 | ||||
-rw-r--r-- | ctdb/protocol/protocol_tunnel.c | 114 |
3 files changed, 175 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_api.h b/ctdb/protocol/protocol_api.h index 0e5d57fdece..8b40d1d8c0e 100644 --- a/ctdb/protocol/protocol_api.h +++ b/ctdb/protocol/protocol_api.h @@ -653,6 +653,20 @@ int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, struct ctdb_req_keepalive *c); +/* From protocol/protocol_tunnel.c */ + +size_t ctdb_req_tunnel_len(struct ctdb_req_header *h, + struct ctdb_req_tunnel *c); + +int ctdb_req_tunnel_push(struct ctdb_req_header *h, + struct ctdb_req_tunnel *c, + uint8_t *buf, size_t *buflen); + +int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen, + struct ctdb_req_header *h, + TALLOC_CTX *mem_ctx, + struct ctdb_req_tunnel *c); + /* From protocol/protocol_event.c */ size_t ctdb_event_request_len(struct ctdb_event_request *in); diff --git a/ctdb/protocol/protocol_debug.c b/ctdb/protocol/protocol_debug.c index 1a87ade3419..3dd5c32ab11 100644 --- a/ctdb/protocol/protocol_debug.c +++ b/ctdb/protocol/protocol_debug.c @@ -354,6 +354,24 @@ static void ctdb_srvid_print(uint64_t srvid, FILE *fp) } } +static void ctdb_tunnel_id_print(uint64_t tunnel_id, FILE *fp) +{ + fprintf(fp, "0x%"PRIx64, tunnel_id); +} + +static void ctdb_tunnel_flags_print(uint32_t flags, FILE *fp) +{ + if (flags & CTDB_TUNNEL_FLAG_REQUEST) { + fprintf(fp, "REQUEST "); + } + if (flags & CTDB_TUNNEL_FLAG_REPLY) { + fprintf(fp, "REPLY "); + } + if (flags & CTDB_TUNNEL_FLAG_NOREPLY) { + fprintf(fp, "NOREPLY "); + } +} + /* * Print routines */ @@ -472,6 +490,16 @@ static void ctdb_req_keepalive_print(struct ctdb_req_keepalive *c, FILE *fp) fprintf(fp, "\n"); } +static void ctdb_req_tunnel_print(struct ctdb_req_tunnel *c, FILE *fp) +{ + fprintf(fp, "Data\n"); + fprintf(fp, " tunnel_id:"); + ctdb_tunnel_id_print(c->tunnel_id, fp); + ctdb_tunnel_flags_print(c->flags, fp); + tdb_data_print(c->data, fp); + fprintf(fp, "\n"); +} + /* * Parse routines */ @@ -611,6 +639,21 @@ static void ctdb_req_keepalive_parse(uint8_t *buf, size_t buflen, FILE *fp, ctdb_req_keepalive_print(&c, fp); } +static void ctdb_req_tunnel_parse(uint8_t *buf, size_t buflen, FILE *fp, + TALLOC_CTX *mem_ctx) +{ + struct ctdb_req_tunnel c; + int ret; + + ret = ctdb_req_tunnel_pull(buf, buflen, NULL, mem_ctx, &c); + if (ret != 0) { + fprintf(fp, "Failed to parse CTDB_REQ_TUNNEL\n"); + return; + } + + ctdb_req_tunnel_print(&c, fp); +} + /* * Packet print */ @@ -679,6 +722,10 @@ void ctdb_packet_print(uint8_t *buf, size_t buflen, FILE *fp) ctdb_req_keepalive_parse(buf, buflen, fp, mem_ctx); break; + case CTDB_REQ_TUNNEL: + ctdb_req_tunnel_parse(buf, buflen, fp, mem_ctx); + break; + default: fprintf(fp, "Invalid ctdb operation\n"); break; diff --git a/ctdb/protocol/protocol_tunnel.c b/ctdb/protocol/protocol_tunnel.c new file mode 100644 index 00000000000..d31d9d50f01 --- /dev/null +++ b/ctdb/protocol/protocol_tunnel.c @@ -0,0 +1,114 @@ +/* + 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_tunnel_len(struct ctdb_req_header *h, + struct ctdb_req_tunnel *c) +{ + return ctdb_req_header_len(h) + + ctdb_uint64_len(&c->tunnel_id) + + ctdb_uint32_len(&c->flags) + + ctdb_tdb_datan_len(&c->data); +} + +int ctdb_req_tunnel_push(struct ctdb_req_header *h, + struct ctdb_req_tunnel *c, + uint8_t *buf, size_t *buflen) +{ + size_t length, offset = 0, np; + + length = ctdb_req_tunnel_len(h, c); + if (*buflen < length) { + *buflen = length; + return EMSGSIZE; + } + + h->length = *buflen; + ctdb_req_header_push(h, buf, &np); + offset += np; + + ctdb_uint64_push(&c->tunnel_id, buf+offset, &np); + offset += np; + + ctdb_uint32_push(&c->flags, buf+offset, &np); + offset += np; + + ctdb_tdb_datan_push(&c->data, buf+offset, &np); + offset += np; + + if (offset > *buflen) { + return EMSGSIZE; + } + + return 0; +} + +int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen, + struct ctdb_req_header *h, + TALLOC_CTX *mem_ctx, + struct ctdb_req_tunnel *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_uint64_pull(buf+offset, buflen-offset, &c->tunnel_id, &np); + if (ret != 0) { + return ret; + } + offset += np; + + ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np); + if (ret != 0) { + return ret; + } + offset += np; + + ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, mem_ctx, + &c->data, &np); + if (ret != 0) { + return ret; + } + offset += np; + + if (offset > buflen) { + return EMSGSIZE; + } + + return 0; +} |