From: Amitay Isaacs Date: Thu, 6 Apr 2017 09:09:58 +0000 (+1000) Subject: ctdb-daemon: Add code to process ctdb_req_tunnel packets X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=2cb5fdac42104c68566c9766cabf7d167091f64d;p=metze%2Fsamba%2Fwip.git ctdb-daemon: Add code to process ctdb_req_tunnel packets Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 3c46ef025c99..23cb7dcd53ba 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -972,6 +972,13 @@ int32_t ctdb_control_tunnel_register(struct ctdb_context *ctdb, int32_t ctdb_control_tunnel_deregister(struct ctdb_context *ctdb, uint32_t client_id, uint64_t tunnel_id); +int ctdb_daemon_send_tunnel(struct ctdb_context *ctdb, uint32_t destnode, + uint64_t tunnel_id, uint32_t client_id, + TDB_DATA data); + +void ctdb_request_tunnel(struct ctdb_context *ctdb, + struct ctdb_req_header *hdr); + /* from ctdb_update_record.c */ int32_t ctdb_control_update_record(struct ctdb_context *ctdb, diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index dc2fd5d9695c..aa2c92ed2210 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -817,6 +817,8 @@ static void daemon_request_call_from_client(struct ctdb_client *client, static void daemon_request_control_from_client(struct ctdb_client *client, struct ctdb_req_control_old *c); +static void daemon_request_tunnel_from_client(struct ctdb_client *client, + struct ctdb_req_tunnel_old *c); /* data contains a packet from the client */ static void daemon_incoming_packet(void *p, struct ctdb_req_header *hdr) @@ -858,6 +860,11 @@ static void daemon_incoming_packet(void *p, struct ctdb_req_header *hdr) daemon_request_control_from_client(client, (struct ctdb_req_control_old *)hdr); break; + case CTDB_REQ_TUNNEL: + CTDB_INCREMENT_STAT(ctdb, client.req_tunnel); + daemon_request_tunnel_from_client(client, (struct ctdb_req_tunnel_old *)hdr); + break; + default: DEBUG(DEBUG_CRIT,(__location__ " daemon: unrecognized operation %u\n", hdr->operation)); @@ -1559,6 +1566,39 @@ static void daemon_request_control_from_client(struct ctdb_client *client, talloc_free(tmp_ctx); } +static void daemon_request_tunnel_from_client(struct ctdb_client *client, + struct ctdb_req_tunnel_old *c) +{ + TDB_DATA data; + int ret; + + if (! ctdb_validate_pnn(client->ctdb, c->hdr.destnode)) { + DEBUG(DEBUG_ERR, ("Invalid destination 0x%x\n", + c->hdr.destnode)); + return; + } + + ret = srvid_exists(client->ctdb->tunnels, c->tunnel_id, NULL); + if (ret != 0) { + DEBUG(DEBUG_ERR, + ("tunnel id 0x%"PRIx64" not registered, dropping pkt\n", + c->tunnel_id)); + return; + } + + data = (TDB_DATA) { + .dsize = c->datalen, + .dptr = &c->data[0], + }; + + ret = ctdb_daemon_send_tunnel(client->ctdb, c->hdr.destnode, + c->tunnel_id, c->flags, data); + if (ret != 0) { + DEBUG(DEBUG_ERR, ("Failed to set tunnel to remote note %u\n", + c->hdr.destnode)); + } +} + /* register a call function */ diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index 900674132ac0..8e31038cc956 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -268,6 +268,11 @@ void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) ctdb_request_keepalive(ctdb, hdr); break; + case CTDB_REQ_TUNNEL: + CTDB_INCREMENT_STAT(ctdb, node.req_tunnel); + ctdb_request_tunnel(ctdb, hdr); + break; + default: DEBUG(DEBUG_CRIT,("%s: Packet with unknown operation %u\n", __location__, hdr->operation)); diff --git a/ctdb/server/ctdb_tunnel.c b/ctdb/server/ctdb_tunnel.c index 0f2e001005c4..2df94746ed48 100644 --- a/ctdb/server/ctdb_tunnel.c +++ b/ctdb/server/ctdb_tunnel.c @@ -88,3 +88,54 @@ int32_t ctdb_control_tunnel_deregister(struct ctdb_context *ctdb, return 0; } + +int ctdb_daemon_send_tunnel(struct ctdb_context *ctdb, uint32_t destnode, + uint64_t tunnel_id, uint32_t flags, TDB_DATA data) +{ + struct ctdb_req_tunnel_old *c; + size_t len; + + if (ctdb->methods == NULL) { + DEBUG(DEBUG_INFO, + ("Failed to send tunnel. Transport is DOWN\n")); + return -1; + } + + len = offsetof(struct ctdb_req_tunnel_old, data) + data.dsize; + c = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_TUNNEL, len, + struct ctdb_req_tunnel_old); + if (c == NULL) { + DEBUG(DEBUG_ERR, + ("Memory error in ctdb_daemon_send_tunnel()\n")); + return -1; + } + + c->hdr.destnode = destnode; + c->tunnel_id = tunnel_id; + c->flags = flags; + c->datalen = data.dsize; + memcpy(c->data, data.dptr, data.dsize); + + ctdb_queue_packet(ctdb, &c->hdr); + + talloc_free(c); + return 0; +} + +void ctdb_request_tunnel(struct ctdb_context *ctdb, + struct ctdb_req_header *hdr) +{ + struct ctdb_req_tunnel_old *c = + (struct ctdb_req_tunnel_old *)hdr; + TDB_DATA data; + int ret; + + data.dsize = hdr->length; + data.dptr = (uint8_t *)c; + + ret = srvid_dispatch(ctdb->tunnels, c->tunnel_id, 0, data); + if (ret != 0) { + DEBUG(DEBUG_ERR, ("Tunnel id 0x%"PRIx64" not registered\n", + c->tunnel_id)); + } +}