From: Stefan Metzmacher Date: Thu, 16 Nov 2023 12:18:03 +0000 (+0100) Subject: ctdbd_conn: add ctdbd_unregister_ips() X-Git-Tag: samba-4.18.10~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18d34cea2a19232dc30cbe45545885a6406e2be0;p=thirdparty%2Fsamba.git ctdbd_conn: add ctdbd_unregister_ips() 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 Reviewed-by: Martin Schwenke (cherry picked from commit f3a03f3f774f0795fc1a163f12cccb9cedeebec1) --- diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h index 3fa94871029..a0801200794 100644 --- a/source3/include/ctdbd_conn.h +++ b/source3/include/ctdbd_conn.h @@ -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 diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c index f21037e0c30..99f27d843d2 100644 --- a/source3/lib/ctdb_dummy.c +++ b/source3/lib/ctdb_dummy.c @@ -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, diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 41239f702b9..408dd80e951 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -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,