ctdb-daemon: Add implementation of tunnel controls
[Samba.git] / ctdb / server / ctdb_tunnel.c
blob0f2e001005c48e72bc199bb1968649d9b78bdc93
1 /*
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/>.
20 #include "replace.h"
21 #include "system/network.h"
23 #include <talloc.h>
24 #include <tevent.h>
25 #include <tdb.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;
39 int ret;
41 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
42 if (client == NULL) {
43 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_register\n"));
44 return -1;
47 ret = srvid_exists(ctdb->tunnels, tunnel_id, NULL);
48 if (ret == 0) {
49 DEBUG(DEBUG_ERR,
50 ("Tunnel id 0x%"PRIx64" already registered\n",
51 tunnel_id));
52 return -1;
55 ret = srvid_register(ctdb->tunnels, client, tunnel_id,
56 daemon_tunnel_handler, client);
57 if (ret != 0) {
58 DEBUG(DEBUG_ERR,
59 ("Failed to register tunnel id 0x%"PRIx64"\n",
60 tunnel_id));
61 return -1;
64 DEBUG(DEBUG_INFO, ("Registered tunnel for id 0x%"PRIx64"\n",
65 tunnel_id));
66 return 0;
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;
73 int ret;
75 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
76 if (client == NULL) {
77 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_deregister\n"));
78 return -1;
81 ret = srvid_deregister(ctdb->tunnels, tunnel_id, client);
82 if (ret != 0) {
83 DEBUG(DEBUG_ERR,
84 ("Failed to deregister tunnel id 0x%"PRIx64"\n",
85 tunnel_id));
86 return -1;
89 return 0;