summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2020-06-25 15:14:04 +0200
committerStefan Metzmacher <metze@samba.org>2020-07-08 15:54:41 +0000
commit4d92452890539d894315db2255f99b24e4f2a348 (patch)
tree618804ae006104711e82375d9fb67aa24b58acaa /source3
parent57515a43fbd9ad7071838319aaa663a57fabf440 (diff)
downloadsamba-4d92452890539d894315db2255f99b24e4f2a348.tar.gz
s3:ctdbd_conn: add ctdbd_control_get_public_ips() and ctdbd_find_in_public_ips()
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>
Diffstat (limited to 'source3')
-rw-r--r--source3/include/ctdbd_conn.h8
-rw-r--r--source3/lib/ctdb_dummy.c15
-rw-r--r--source3/lib/ctdbd_conn.c69
3 files changed, 92 insertions, 0 deletions
diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 7aaab4e6bd2..b77dd06fd09 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -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,
diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 144c8507758..062fa999b06 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -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)
{
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 9c334764d36..a4a9f4e0cae 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -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
*/