2 ctdb_tunnel protocol code
4 Copyright (C) Amitay Isaacs 2017
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "system/network.h"
27 #include "lib/util/debug.h"
29 #include "common/logging.h"
30 #include "common/reqid.h"
31 #include "common/srvid.h"
33 #include "ctdb_private.h"
35 int32_t ctdb_control_tunnel_register(struct ctdb_context *ctdb,
36 uint32_t client_id, uint64_t tunnel_id)
38 struct ctdb_client *client;
41 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
43 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_register\n"));
47 ret = srvid_exists(ctdb->tunnels, tunnel_id, NULL);
50 ("Tunnel id 0x%"PRIx64" already registered\n",
55 ret = srvid_register(ctdb->tunnels, client, tunnel_id,
56 daemon_tunnel_handler, client);
59 ("Failed to register tunnel id 0x%"PRIx64"\n",
64 DEBUG(DEBUG_INFO, ("Registered tunnel for id 0x%"PRIx64"\n",
69 int32_t ctdb_control_tunnel_deregister(struct ctdb_context *ctdb,
70 uint32_t client_id, uint64_t tunnel_id)
72 struct ctdb_client *client;
75 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
77 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_deregister\n"));
81 ret = srvid_deregister(ctdb->tunnels, tunnel_id, client);
84 ("Failed to deregister tunnel id 0x%"PRIx64"\n",
92 int ctdb_daemon_send_tunnel(struct ctdb_context *ctdb, uint32_t destnode,
93 uint64_t tunnel_id, uint32_t flags, TDB_DATA data)
95 struct ctdb_req_tunnel_old *c;
98 if (ctdb->methods == NULL) {
100 ("Failed to send tunnel. Transport is DOWN\n"));
104 len = offsetof(struct ctdb_req_tunnel_old, data) + data.dsize;
105 c = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_TUNNEL, len,
106 struct ctdb_req_tunnel_old);
109 ("Memory error in ctdb_daemon_send_tunnel()\n"));
113 c->hdr.destnode = destnode;
114 c->tunnel_id = tunnel_id;
116 c->datalen = data.dsize;
117 memcpy(c->data, data.dptr, data.dsize);
119 ctdb_queue_packet(ctdb, &c->hdr);
125 void ctdb_request_tunnel(struct ctdb_context *ctdb,
126 struct ctdb_req_header *hdr)
128 struct ctdb_req_tunnel_old *c =
129 (struct ctdb_req_tunnel_old *)hdr;
133 data.dsize = hdr->length;
134 data.dptr = (uint8_t *)c;
136 ret = srvid_dispatch(ctdb->tunnels, c->tunnel_id, 0, data);
138 DEBUG(DEBUG_ERR, ("Tunnel id 0x%"PRIx64" not registered\n",