1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +03:00

ctdb-daemon: Add code to process ctdb_req_tunnel packets

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-04-06 19:09:58 +10:00 committed by Martin Schwenke
parent f4f5e7d2ad
commit 2cb5fdac42
4 changed files with 103 additions and 0 deletions

View File

@ -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,

View File

@ -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
*/

View File

@ -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));

View File

@ -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));
}
}