ctdb-daemon: Add code to process ctdb_req_tunnel packets
authorAmitay Isaacs <amitay@gmail.com>
Thu, 6 Apr 2017 09:09:58 +0000 (19:09 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 10 Oct 2017 09:45:19 +0000 (11:45 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_daemon.c
ctdb/server/ctdb_server.c
ctdb/server/ctdb_tunnel.c

index 3c46ef025c99b6034209fc6d26a7decb0cac6049..23cb7dcd53bae78c90967492cdc04487e6a21b15 100644 (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,
index dc2fd5d9695c3e50c4b70029514b8eef4f172fa7..aa2c92ed221062a279f822abdc8470a5c0e88043 100644 (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
 */
index 900674132ac08818f22c2df35648f2354b610480..8e31038cc9567d8ceb02799ff87adc58238b3098 100644 (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));
index 0f2e001005c48e72bc199bb1968649d9b78bdc93..2df94746ed485464b478d25707e3c1282e4676c7 100644 (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));
+       }
+}