]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-server: Optimise local IP verification
authorMartin Schwenke <mschwenke@ddn.com>
Sun, 29 Sep 2024 04:10:22 +0000 (14:10 +1000)
committerAnoop C S <anoopcs@samba.org>
Mon, 7 Oct 2024 15:58:38 +0000 (15:58 +0000)
It is more efficient calling ctdb_sys_local_ip_check() inside a loop
compared to calling ctdb_sys_have_ip().  There is a chance that this
is premature optimisation... but it sure is easy.  Fall back to
checking with bind().

I think these checks really exist because of the weirdness fixed by
commit 4b4e4d8870475d994fe42a7b2c57dc69842d91f6.  However, we might as
well do what we can.

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

index f31ff43ee0b47f3d966bef42fbf56d874007e1f9..11644868e461e4baab2031e2c13574f2d679171d 100644 (file)
@@ -2285,6 +2285,7 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec)
        int ret;
        bool need_takeover_run = false;
        struct ctdb_public_ip_list_old *ips = NULL;
+       struct ctdb_sys_local_ips_context *ips_ctx = NULL;
 
        /* If we are not the leader then do some housekeeping */
        if (!this_node_is_leader(rec)) {
@@ -2355,9 +2356,30 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec)
                return -1;
        }
 
+       ret = ctdb_sys_local_ips_init(mem_ctx, &ips_ctx);
+       if (ret != 0) {
+               /*
+                * What to do?  The point here is to allow public
+                * addresses to be checked when
+                * net.ipv4.ip_nonlocal_bind = 1, which is probably
+                * just Linux... though other platforms may have a
+                * similar setting.  For non-Linux platforms without a
+                * usable getifaddrs(3) function/replacement, fall
+                * back to bind() below...
+                */
+               DBG_DEBUG("Failed to get local addresses, depending on bind\n");
+               ips_ctx = NULL; /* Just in case */
+       }
+
        for (j=0; j<ips->num; j++) {
                ctdb_sock_addr *addr = &ips->ips[j].addr;
-               bool have_ip = ctdb_sys_have_ip(addr);
+               bool have_ip;
+
+               if (ips_ctx != NULL) {
+                       have_ip = ctdb_sys_local_ip_check(ips_ctx, addr);
+               } else {
+                       have_ip = ctdb_sys_bind_ip_check(addr);
+               }
 
                if (ips->ips[j].pnn == rec->pnn) {
                        if (!have_ip) {
@@ -2374,6 +2396,8 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec)
                }
        }
 
+       TALLOC_FREE(ips_ctx);
+
 done:
        if (need_takeover_run) {
                struct ctdb_srvid_message rd;