ctdbd_conn: add ctdbd_unregister_ips()
authorStefan Metzmacher <metze@samba.org>
Thu, 16 Nov 2023 12:18:03 +0000 (13:18 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 15 Dec 2023 11:06:34 +0000 (11:06 +0000)
This reverts the effect of ctdbd_register_ips().
We'll use this in order to disconnect individual
multichannel connections.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15523

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
source3/include/ctdbd_conn.h
source3/lib/ctdb_dummy.c
source3/lib/ctdbd_conn.c

index 3fa948710298460ca0c8f79bcea082a1f060263e..a0801200794685d826b91e154e463760b9014a73 100644 (file)
@@ -84,6 +84,17 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
                                 const uint8_t *msg, size_t msglen,
                                 void *private_data),
                       void *private_data);
+void ctdbd_unregister_ips(struct ctdbd_connection *conn,
+                         const struct sockaddr_storage *_server,
+                         const struct sockaddr_storage *_client,
+                         int (*cb)(struct tevent_context *ev,
+                                   uint32_t src_vnn,
+                                   uint32_t dst_vnn,
+                                   uint64_t dst_srvid,
+                                   const uint8_t *msg,
+                                   size_t msglen,
+                                   void *private_data),
+                         void *private_data);
 
 /*
  * call @cb for each public IP. If @cb returns non-zero, then break the loop
index f21037e0c3093ef6a93000ed637151ec0ba1b14f..99f27d843d28679fec5286471074ad9393b7c92d 100644 (file)
@@ -75,6 +75,21 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
        return ENOSYS;
 }
 
+void ctdbd_unregister_ips(struct ctdbd_connection *conn,
+                         const struct sockaddr_storage *_server,
+                         const struct sockaddr_storage *_client,
+                         int (*cb)(struct tevent_context *ev,
+                                   uint32_t src_vnn,
+                                   uint32_t dst_vnn,
+                                   uint64_t dst_srvid,
+                                   const uint8_t *msg,
+                                   size_t msglen,
+                                   void *private_data),
+                         void *private_data)
+{
+       return;
+}
+
 int ctdbd_public_ip_foreach(struct ctdbd_connection *conn,
                            int (*cb)(uint32_t total_ip_count,
                                      const struct sockaddr_storage *ip,
index 41239f702b9daf11778dba3a6a3e504de637334e..408dd80e951fc2de7cb6f25d4ab41b216d519277 100644 (file)
@@ -1263,6 +1263,70 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
        return 0;
 }
 
+void ctdbd_unregister_ips(struct ctdbd_connection *conn,
+                         const struct sockaddr_storage *_server,
+                         const struct sockaddr_storage *_client,
+                         int (*cb)(struct tevent_context *ev,
+                                   uint32_t src_vnn,
+                                   uint32_t dst_vnn,
+                                   uint64_t dst_srvid,
+                                   const uint8_t *msg,
+                                   size_t msglen,
+                                   void *private_data),
+                         void *private_data)
+{
+       struct ctdb_connection p;
+       TDB_DATA data = { .dptr = (uint8_t *)&p, .dsize = sizeof(p) };
+       int ret;
+       struct sockaddr_storage client;
+       struct sockaddr_storage server;
+
+       /*
+        * Only one connection so far
+        */
+
+       smbd_ctdb_canonicalize_ip(_client, &client);
+       smbd_ctdb_canonicalize_ip(_server, &server);
+
+       ZERO_STRUCT(p);
+       switch (client.ss_family) {
+       case AF_INET:
+               memcpy(&p.dst.ip, &server, sizeof(p.dst.ip));
+               memcpy(&p.src.ip, &client, sizeof(p.src.ip));
+               break;
+       case AF_INET6:
+               memcpy(&p.dst.ip6, &server, sizeof(p.dst.ip6));
+               memcpy(&p.src.ip6, &client, sizeof(p.src.ip6));
+               break;
+       default:
+               return;
+       }
+
+       /*
+        * We no longer want to be told about IP releases
+        * for the given callback/private_data combination
+        */
+       deregister_from_ctdbd(conn, CTDB_SRVID_RELEASE_IP,
+                             cb, private_data);
+
+       /*
+        * inform ctdb of our tcp connection is no longer active
+        */
+       ret = ctdbd_control_local(conn,
+                                 CTDB_CONTROL_TCP_CLIENT_DISCONNECTED, 0,
+                                 CTDB_CTRL_FLAG_NOREPLY, data, NULL, NULL,
+                                 NULL);
+       if (ret != 0) {
+               /*
+                * We ignore errors here, as we'll just
+                * no longer have a callback handler
+                * registered and messages may just be ignored
+                */
+       }
+
+       return;
+}
+
 static int ctdbd_control_get_public_ips(struct ctdbd_connection *conn,
                                        uint32_t flags,
                                        TALLOC_CTX *mem_ctx,