]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Reimplement ctdb_sys_have_ip() using new infrastructure
authorMartin Schwenke <mschwenke@ddn.com>
Sun, 29 Sep 2024 02:05:31 +0000 (12:05 +1000)
committerAnoop C S <anoopcs@samba.org>
Mon, 7 Oct 2024 15:58:38 +0000 (15:58 +0000)
It can now be used when net.ipv4.ip_nonlocal_bind=1.

This makes the recovery daemon's local IP verification inefficient.
It can be optimised in a subsequent commit.

Fall back to bind() if unable to fetch IPs.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
ctdb/common/system_socket.c
ctdb/common/system_socket.h

index 6fe4c719f00296948c90f21a80f911767c206d60..b4275b1fc6460a71e3a9ad7ee2c634b5c02c922d 100644 (file)
@@ -160,10 +160,7 @@ bool ctdb_sys_local_ip_check(const struct ctdb_sys_local_ips_context *ips_ctx,
        return false;
 }
 
-/*
- * See if the given IP is currently on an interface
- */
-bool ctdb_sys_have_ip(const ctdb_sock_addr *_addr)
+bool ctdb_sys_bind_ip_check(const ctdb_sock_addr *_addr)
 {
        int s;
        int ret;
@@ -193,6 +190,28 @@ bool ctdb_sys_have_ip(const ctdb_sock_addr *_addr)
        return ret == 0;
 }
 
+/*
+ * See if the given IP is currently on an interface
+ */
+bool ctdb_sys_have_ip(const ctdb_sock_addr *addr)
+{
+       struct ctdb_sys_local_ips_context *ips_ctx = NULL;
+       bool have_ip;
+       int ret;
+
+       ret = ctdb_sys_local_ips_init(NULL, &ips_ctx);
+       if (ret != 0) {
+               DBG_DEBUG("Failed to get local addresses, depending on bind\n");
+               have_ip = ctdb_sys_bind_ip_check(addr);
+               return have_ip;
+       }
+
+       have_ip = ctdb_sys_local_ip_check(ips_ctx, addr);
+       talloc_free(ips_ctx);
+
+       return have_ip;
+}
+
 /*
  * simple TCP checksum - assumes data is multiple of 2 bytes long
  */
index 3edc9e146e47cbf04fee2e6948bbf415f91d7d23..f4d092cce0a52201a364df1c07997a664bbca48d 100644 (file)
@@ -30,6 +30,7 @@ int ctdb_sys_local_ips_init(TALLOC_CTX *ctx,
                            struct ctdb_sys_local_ips_context **ips_ctx);
 bool ctdb_sys_local_ip_check(const struct ctdb_sys_local_ips_context *ips_ctx,
                             const ctdb_sock_addr *addr);
+bool ctdb_sys_bind_ip_check(const ctdb_sock_addr *addr);
 bool ctdb_sys_have_ip(const ctdb_sock_addr *addr);
 
 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);