]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:ctdbd_conn: add ctdbd_control_get_public_ips() and ctdbd_find_in_public_ips()
authorStefan Metzmacher <metze@samba.org>
Thu, 25 Jun 2020 13:14:04 +0000 (15:14 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 8 Jul 2020 15:54:41 +0000 (15:54 +0000)
These will be used in the multi channel code in order to handle
public ip addresses, which can move arround ctdb nodes.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
source3/include/ctdbd_conn.h
source3/lib/ctdb_dummy.c
source3/lib/ctdbd_conn.c

index 7aaab4e6bd2772f7245e51865c012dd918cdd7ab..b77dd06fd09e2145ec447e076b1095e748e86c07 100644 (file)
@@ -85,6 +85,14 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
                                 void *private_data),
                       void *private_data);
 
+struct ctdb_public_ip_list_old;
+int ctdbd_control_get_public_ips(struct ctdbd_connection *conn,
+                                uint32_t flags,
+                                TALLOC_CTX *mem_ctx,
+                                struct ctdb_public_ip_list_old **_ips);
+bool ctdbd_find_in_public_ips(const struct ctdb_public_ip_list_old *ips,
+                             const struct sockaddr_storage *ip);
+
 int ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
                        uint64_t srvid, uint32_t flags, TDB_DATA data,
                        TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
index 144c85077582b57b024e0677de11becc38483586..062fa999b0635bb3d90025a6228720138793bb3d 100644 (file)
@@ -62,6 +62,21 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
        return ENOSYS;
 }
 
+int ctdbd_control_get_public_ips(struct ctdbd_connection *conn,
+                                uint32_t flags,
+                                TALLOC_CTX *mem_ctx,
+                                struct ctdb_public_ip_list_old **_ips)
+{
+       *_ips = NULL;
+       return ENOSYS;
+}
+
+bool ctdbd_find_in_public_ips(const struct ctdb_public_ip_list_old *ips,
+                             const struct sockaddr_storage *ip)
+{
+       return false;
+}
+
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
                          pid_t pid, uint64_t unique_id)
 {
index 9c334764d36ccfc5d2f7e028a19b72c3e97f434b..a4a9f4e0caea0990360d03eb6a82615b09c55296 100644 (file)
@@ -1179,6 +1179,75 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
        return 0;
 }
 
+int ctdbd_control_get_public_ips(struct ctdbd_connection *conn,
+                                uint32_t flags,
+                                TALLOC_CTX *mem_ctx,
+                                struct ctdb_public_ip_list_old **_ips)
+{
+       struct ctdb_public_ip_list_old *ips = NULL;
+       TDB_DATA outdata;
+       int32_t cstatus = -1;
+       size_t min_dsize;
+       size_t max_ips;
+       int ret;
+
+       *_ips = NULL;
+
+       ret = ctdbd_control_local(conn,
+                                 CTDB_CONTROL_GET_PUBLIC_IPS,
+                                 0, /* srvid */
+                                 flags,
+                                 tdb_null, /* indata */
+                                 mem_ctx,
+                                 &outdata,
+                                 &cstatus);
+       if (ret != 0 || cstatus != 0) {
+               DBG_ERR("ctdb_control for getpublicips failed ret:%d cstatus:%d\n",
+                       ret, (int)cstatus);
+               return -1;
+       }
+
+       min_dsize = offsetof(struct ctdb_public_ip_list_old, ips);
+       if (outdata.dsize < min_dsize) {
+               DBG_ERR("outdata.dsize=%zu < min_dsize=%zu\n",
+                       outdata.dsize, min_dsize);
+               return -1;
+       }
+       max_ips = (outdata.dsize - min_dsize)/sizeof(struct ctdb_public_ip);
+       ips = (struct ctdb_public_ip_list_old *)outdata.dptr;
+       if ((size_t)ips->num > max_ips) {
+               DBG_ERR("ips->num=%zu > max_ips=%zu\n",
+                       (size_t)ips->num, max_ips);
+               return -1;
+       }
+
+       *_ips = ips;
+       return 0;
+}
+
+bool ctdbd_find_in_public_ips(const struct ctdb_public_ip_list_old *ips,
+                             const struct sockaddr_storage *ip)
+{
+       uint32_t i;
+
+       for (i=0; i < ips->num; i++) {
+               struct samba_sockaddr tmp = {
+                       .u = {
+                               .ss = *ip,
+                       },
+               };
+               bool match;
+
+               match = sockaddr_equal(&ips->ips[i].addr.sa,
+                                      &tmp.u.sa);
+               if (match) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 /*
   call a control on the local node
  */