osaf/libs/core/include/mds_papi.h | 4 +-
osaf/libs/core/mds/include/mds_core.h | 15 +++
osaf/libs/core/mds/include/mds_dt2c.h | 3 +
osaf/libs/core/mds/mds_c_api.c | 23 +++++
osaf/libs/core/mds/mds_c_db.c | 28 +++++++
osaf/libs/core/mds/mds_c_sndrcv.c | 4 +-
osaf/libs/core/mds/mds_dt_common.c | 11 ++
osaf/libs/core/mds/mds_main.c | 134 ++++++++++++++++++++++++++++++++++
8 files changed, 220 insertions(+), 2 deletions(-)
Three new environment variables are now supported:
MDS_SOCK_SERVER_CREATE - When this variable is defined in the environment,
a server socket will be created. Used on the server side.
MDS_SOCK_SERVER_NAME - Name of the server socket (used to bind the name)
MDS_SOCK_SERVER_CONNECT - When this variable is defined in the environment,
a client will try to connect to a server and securely exchange its MDS address.
Other changes:
- The MDS_CALLBACK_RECEIVE_INFO structure has added pid, uid & gid members.
They will have valid values on the server side when the above mentioned has been
configured properly. This is an MDS backwards compatible interface change, data
has been added.
- A new MDS database maintained on the server side, MDS_DEST is the key. Each
entry represents a node local MDS core (process).
diff --git a/osaf/libs/core/include/mds_papi.h
b/osaf/libs/core/include/mds_papi.h
--- a/osaf/libs/core/include/mds_papi.h
+++ b/osaf/libs/core/include/mds_papi.h
@@ -731,7 +731,9 @@ unpack individual structure members. */
*/
MDS_HDL sender_pwe_hdl;
MDS_CLIENT_MSG_FORMAT_VER i_msg_fmt_ver;
-
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
} MDS_CALLBACK_RECEIVE_INFO;
typedef struct {
diff --git a/osaf/libs/core/mds/include/mds_core.h
b/osaf/libs/core/mds/include/mds_core.h
--- a/osaf/libs/core/mds/include/mds_core.h
+++ b/osaf/libs/core/mds/include/mds_core.h
@@ -284,6 +284,7 @@ typedef struct mds_mcm_cb {
NCS_PATRICIA_TREE subtn_results;
NCS_PATRICIA_TREE svc_list; /* Tree of MDS_SVC_INFO information */
NCS_PATRICIA_TREE vdest_list; /* Tree of MDS_VDEST_INFO information */
+ NCS_PATRICIA_TREE process_info_db; /* all known local MDS dests */
} MDS_MCM_CB;
/* Global MDSCB */
@@ -297,6 +298,20 @@ extern uint32_t MDS_SUBSCRIPTION_TMR_VAL
/* Global gl_mds_checksum */
extern uint32_t gl_mds_checksum;
+typedef struct mds_process_info {
+ NCS_PATRICIA_NODE patnode; // mds_dest is key
+ MDS_DEST mds_dest;
+ uid_t uid;
+ gid_t gid;
+ pid_t pid;
+ int count;
+} MDS_PROCESS_INFO;
+
+MDS_PROCESS_INFO *mds_process_info_get(MDS_DEST mds_dest);
+int mds_process_info_add(MDS_PROCESS_INFO *info);
+int mds_process_info_del(MDS_PROCESS_INFO *info);
+int mds_process_info_cnt(void);
+
/* ******************************************** */
/* ******************************************** */
/* MCM Private */
diff --git a/osaf/libs/core/mds/include/mds_dt2c.h
b/osaf/libs/core/mds/include/mds_dt2c.h
--- a/osaf/libs/core/mds/include/mds_dt2c.h
+++ b/osaf/libs/core/mds/include/mds_dt2c.h
@@ -106,6 +106,9 @@ typedef struct mds_data_recv {
MDS_SVC_PVT_SUB_PART_VER src_svc_sub_part_ver;
MDS_SVC_ARCHWORD_TYPE msg_arch_word;
uint32_t src_seq_num;
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
} MDS_DATA_RECV;
diff --git a/osaf/libs/core/mds/mds_c_api.c b/osaf/libs/core/mds/mds_c_api.c
--- a/osaf/libs/core/mds/mds_c_api.c
+++ b/osaf/libs/core/mds/mds_c_api.c
@@ -1598,6 +1598,12 @@ else (entry exists)
}
*/
+ MDS_PROCESS_INFO *info = mds_process_info_get(adest);
+ if (info != NULL) {
+ info->count++;
+ TRACE("svc %d up cnt:%d, db cnt:%d", svc_id, info->count,
mds_process_info_cnt());
+ }
+
status =
mds_svc_tbl_query(m_MDS_GET_PWE_HDL_FROM_SVC_HDL(local_svc_hdl),
m_MDS_GET_SVC_ID_FROM_SVC_HDL(local_svc_hdl));
@@ -2647,6 +2653,16 @@ else (entry exists)
}
*/
+ MDS_PROCESS_INFO *info = mds_process_info_get(adest);
+ if (info != NULL) {
+ info->count--;
+ TRACE("svc %d down cnt:%d, db cnt:%d", svc_id, info->count,
mds_process_info_cnt());
+ if (info->count == 0) {
+ mds_process_info_del(info);
+ free(info);
+ }
+ }
+
status =
mds_svc_tbl_query(m_MDS_GET_PWE_HDL_FROM_SVC_HDL(local_svc_hdl),
m_MDS_GET_SVC_ID_FROM_SVC_HDL(local_svc_hdl));
@@ -3794,6 +3810,13 @@ uint32_t mds_mcm_init(void)
ncs_patricia_tree_add(&gl_mds_mcm_cb->vdest_list, (NCS_PATRICIA_NODE
*)vdest_for_adest_node);
+ memset(&pat_tree_params, 0, sizeof(pat_tree_params));
+ pat_tree_params.key_size = sizeof(MDS_DEST);
+ if (NCSCC_RC_SUCCESS !=
ncs_patricia_tree_init(&gl_mds_mcm_cb->process_info_db, &pat_tree_params)) {
+ m_MDS_LOG_ERR("MCM_API : patricia_tree_init:proc_info :failure,
L mds_mcm_init");
+ return NCSCC_RC_FAILURE;
+ }
+
return NCSCC_RC_SUCCESS;
}
diff --git a/osaf/libs/core/mds/mds_c_db.c b/osaf/libs/core/mds/mds_c_db.c
--- a/osaf/libs/core/mds/mds_c_db.c
+++ b/osaf/libs/core/mds/mds_c_db.c
@@ -2331,6 +2331,34 @@ uint32_t mds_subtn_res_tbl_cleanup(void)
return NCSCC_RC_SUCCESS;
}
+MDS_PROCESS_INFO *mds_process_info_get(MDS_DEST mds_dest)
+{
+ return (MDS_PROCESS_INFO *)
ncs_patricia_tree_get(&gl_mds_mcm_cb->process_info_db,
+ (uint8_t *)&mds_dest);
+}
+
+int mds_process_info_add(MDS_PROCESS_INFO *info)
+{
+ TRACE_ENTER2("dest:%lx, pid:%d", info->mds_dest, info->pid);
+ info->patnode.key_info = (uint8_t *)&info->mds_dest;
+ int rc = ncs_patricia_tree_add(&gl_mds_mcm_cb->process_info_db,
+ (NCS_PATRICIA_NODE *)&info->patnode);
+ return rc;
+}
+
+int mds_process_info_del(MDS_PROCESS_INFO *info)
+{
+ TRACE_ENTER2("dest:%lx, pid:%d", info->mds_dest, info->pid);
+ int rc = ncs_patricia_tree_del(&gl_mds_mcm_cb->process_info_db,
+ (NCS_PATRICIA_NODE *)&info->patnode);
+ return rc;
+}
+
+int mds_process_info_cnt(void)
+{
+ return gl_mds_mcm_cb->process_info_db.n_nodes;
+}
+
/*********************************************************
Function NAME: mds_mcm_cleanup
*********************************************************/
diff --git a/osaf/libs/core/mds/mds_c_sndrcv.c
b/osaf/libs/core/mds/mds_c_sndrcv.c
--- a/osaf/libs/core/mds/mds_c_sndrcv.c
+++ b/osaf/libs/core/mds/mds_c_sndrcv.c
@@ -4342,7 +4342,9 @@ static uint32_t mds_mcm_process_recv_snd
mds_mcm_free_msg_memory(recv->msg);
return NCSCC_RC_FAILURE;
}
-
+ cbinfo.info.receive.pid = recv->pid;
+ cbinfo.info.receive.uid = recv->uid;
+ cbinfo.info.receive.gid = recv->gid;
rc = svccb->cback_ptr(&cbinfo);
if (rc != NCSCC_RC_SUCCESS) {
mds_mcm_free_msg_memory(recv->msg);
diff --git a/osaf/libs/core/mds/mds_dt_common.c
b/osaf/libs/core/mds/mds_dt_common.c
--- a/osaf/libs/core/mds/mds_dt_common.c
+++ b/osaf/libs/core/mds/mds_dt_common.c
@@ -14,12 +14,16 @@
* Author(s): GoAhead Software
*
*/
+#define _GNU_SOURCE
#include "mds_dt.h"
+#include "mds_core.h"
#include "mds_log.h"
#include "ncssysf_def.h"
#include "ncssysf_tsk.h"
#include "ncssysf_mem.h"
+#include "osaf_utility.h"
+#include <osaf_secutil.h>
static SYSF_MBX mdtm_mbx_common;
static MDTM_TX_TYPE mdtm_transport;
@@ -266,6 +270,8 @@ uint32_t mdtm_process_recv_message_commo
abort();
}
+ MDS_PROCESS_INFO *info = mds_process_info_get(adest);
+
if (MDTM_DIRECT == flag) {
uint32_t xch_id = 0;
uint8_t prot_ver = 0;
@@ -423,6 +429,11 @@ uint32_t mdtm_process_recv_message_commo
reassem_queue->recv.pri = (prot_ver & MDTM_PRI_MASK) + 1;
reassem_queue->recv.snd_type = msg_snd_type;
reassem_queue->recv.src_seq_num = svc_seq_num;
+ if (info != NULL) {
+ reassem_queue->recv.pid = info->pid;
+ reassem_queue->recv.uid = info->uid;
+ reassem_queue->recv.gid = info->gid;
+ }
m_MDS_LOG_DBG("MDTM: Recd Unfragmented message with SVC Seq num
=%d, from src_Tipc_id=<%llx>",
svc_seq_num, transport_adest);
diff --git a/osaf/libs/core/mds/mds_main.c b/osaf/libs/core/mds/mds_main.c
--- a/osaf/libs/core/mds/mds_main.c
+++ b/osaf/libs/core/mds/mds_main.c
@@ -45,6 +45,7 @@
#include <config.h>
#include "osaf_utility.h"
#include "osaf_poll.h"
+#include <osaf_secutil.h>
#ifdef ENABLE_TIPC_TRANSPORT
#include "mds_dt_tipc.h"
#include <configmake.h>
@@ -108,6 +109,125 @@ uint32_t MDS_SUBSCRIPTION_TMR_VAL = 500;
uint32_t MDTM_REASSEMBLE_TMR_VAL = 500;
uint32_t MDTM_CACHED_EVENTS_TMR_VAL = 24000;
+enum {
+ MDS_REGISTER_REQ = 77,
+ MDS_REGISTER_RESP = 78
+};
+
+/**
+ * Handler for mds register requests
+ * Note: executed by and in context of the auth thread!
+ * Communicates with the main thread (where the
+ * real work is done) to get outcome of initialization request which is then
+ * sent back to the client.
+ * @param fd
+ * @param creds credentials for client
+ */
+static void mds_register_callback(int fd, const struct ucred *creds)
+{
+ uint8_t buf[32];
+ uint8_t *p = buf;
+
+ TRACE_ENTER2("fd:%d, pid:%u", fd, creds->pid);
+
+ int n = recv(fd, buf, sizeof(buf), 0);
+ if (n == -1) {
+ syslog(LOG_ERR, "%s: recv failed - %s", __FUNCTION__,
strerror(errno));
+ goto done;
+ }
+
+ if (n != 12) {
+ syslog(LOG_ERR, "%s: recv failed - %d bytes", __FUNCTION__, n);
+ goto done;
+ }
+
+ int type = ncs_decode_32bit(&p);
+ if (type != MDS_REGISTER_REQ) {
+ syslog(LOG_ERR, "%s: recv failed - wrong type %d",
__FUNCTION__, type);
+ goto done;
+ }
+
+ MDS_DEST mds_dest = ncs_decode_64bit(&p);
+ TRACE("mds: received %d from %lx, pid %d", type, mds_dest, creds->pid);
+
+ if (mds_process_info_get(mds_dest) == NULL) {
+ MDS_PROCESS_INFO *info = malloc(sizeof(MDS_PROCESS_INFO));
+ osafassert(info);
+ info->mds_dest = mds_dest;
+ info->uid = creds->uid;
+ info->pid = creds->pid;
+ info->gid = creds->gid;
+ int rc = mds_process_info_add(info);
+ osafassert(rc == NCSCC_RC_SUCCESS);
+ } else {
+ // can this ever happen?
+ syslog(LOG_WARNING, "%s: dest %lx already exist", __FUNCTION__,
mds_dest);
+ }
+
+ p = buf;
+ uint32_t sz = ncs_encode_32bit(&p, MDS_REGISTER_RESP);
+ sz += ncs_encode_32bit(&p, 0); // result OK
+
+ if ((n = send(fd, buf, sz, 0)) == -1)
+ syslog(LOG_ERR, "%s: send to pid %d failed - %s",
+ __FUNCTION__, creds->pid, strerror(errno));
+
+ done:
+ TRACE_LEAVE();
+}
+
+/**
++ * Sends and receives an initialize message using osaf_secutil
++ * @param evt_type
++ * @param mds_dest
++ * @param version
++ * @param out_evt
++ * @param timeout max time to wait for a response in ms unit
++ * @return NCSCC_RC_SUCCESS - response stored in out_evt, NCSCC_RC_FAILURE or
++ * NCSCC_RC_REQ_TIMOUT
++ */
+static uint32_t mds_dest_register(const char *name, MDS_DEST mds_dest, int
timeout)
+{
+ uint32_t rc;
+ uint8_t msg[32];
+ uint8_t *p = msg;
+ uint32_t sz;
+ int n;
+
+ sz = ncs_encode_32bit(&p, MDS_REGISTER_REQ);
+ sz += ncs_encode_64bit(&p, mds_dest);
+
+ n = osaf_auth_server_connect(name, msg, sz, msg,
+ sizeof(msg), timeout);
+
+ if (n < 0) {
+ TRACE_3("err n:%d", n);
+ rc = NCSCC_RC_FAILURE;
+ goto fail;
+ } else if (n == 0) {
+ TRACE_3("tmo");
+ rc = NCSCC_RC_REQ_TIMOUT;
+ goto fail;
+ } else if (n == 8) {
+ p = msg;
+ int type = ncs_decode_32bit(&p);
+ if (type != MDS_REGISTER_RESP) {
+ TRACE_3("wrong type %d", type);
+ rc = NCSCC_RC_FAILURE;
+ }
+ int status = ncs_decode_32bit(&p);
+ TRACE("received type:%d, status:%d", type, status);
+ status == 0 ? (rc = NCSCC_RC_SUCCESS) : (rc = NCSCC_RC_FAILURE);
+ } else {
+ TRACE_3("err n:%d", n);
+ rc = NCSCC_RC_FAILURE;
+ goto fail;
+ }
+
+ fail:
+ return rc;
+ }
+
/* ******************************************** */
/* ******************************************** */
/* ******************************************** */
@@ -292,6 +412,20 @@ uint32_t mds_lib_req(NCS_LIB_REQ_INFO *r
mds_log_init(buff, pref);
}
+ if (getenv("MDS_SOCK_SERVER_CREATE")) {
+ const char *name = getenv("MDS_SOCK_SERVER_NAME");
+ if (name) {
+ osaf_auth_server_create(name,
mds_register_callback);
+ }
+ }
+
+ if (getenv("MDS_SOCK_SERVER_CONNECT")) {
+ const char *name = getenv("MDS_SOCK_SERVER_NAME");
+ if (name) {
+ mds_dest_register(name, gl_mds_mcm_cb->adest,
10000);
+ }
+ }
+
osaf_mutex_unlock_ordie(&gl_mds_library_mutex);
break;
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel