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,
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)
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));
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
*/
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));
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));
+ }
+}