Correct problem with cleanup of security handshake

Signed-off-by: Marcel Jordense <marcel.jordense@adlinktech.com>
This commit is contained in:
Marcel Jordense 2020-03-04 18:34:30 +01:00 committed by eboasson
parent b8537c0d09
commit 8ca1780538
6 changed files with 74 additions and 42 deletions

View file

@ -131,10 +131,9 @@ void ddsi_handshake_register(struct participant *pp, struct proxy_participant *p
*
* @param[in] pp The local participant.
* @param[in] proxypp The remote participant.
* @param[in] handshake The handshake.
*
*/
void ddsi_handshake_remove(struct participant *pp, struct proxy_participant *proxypp, struct ddsi_handshake *handshake);
void ddsi_handshake_remove(struct participant *pp, struct proxy_participant *proxypp);
/**
* @brief Searches for the handshake associated with the specified participants

View file

@ -21,6 +21,7 @@
#include "dds/ddsi/ddsi_entity_index.h"
#include "dds/ddsi/ddsi_plist.h"
#include "dds/ddsi/q_entity.h"
#include "dds/ddsi/q_gc.h"
#include "dds/security/dds_security_api_types.h"
#include "dds/security/dds_security_api.h"
#include "dds/ddsi/ddsi_security_omg.h"
@ -991,6 +992,7 @@ void ddsi_handshake_release(struct ddsi_handshake *handshake)
DDS_Security_DataHolder_free(handshake->handshake_message_out);
DDS_Security_DataHolder_free(handshake->remote_auth_request_token);
DDS_Security_OctetSeq_deinit(&handshake->pdata);
dds_security_fsm_free(handshake->fsm);
ddsrt_mutex_destroy(&handshake->lock);
ddsrt_free(handshake);
}
@ -1146,22 +1148,31 @@ static struct ddsi_handshake * ddsi_handshake_find_locked(
return ddsrt_avl_lookup(&handshake_treedef, &hsadmin->handshakes, &handles);
}
void ddsi_handshake_remove(struct participant *pp, struct proxy_participant *proxypp, struct ddsi_handshake *handshake)
static void gc_delete_handshale (struct gcreq *gcreq)
{
struct ddsi_handshake *handshake = gcreq->arg;
ddsi_handshake_release(handshake);
gcreq_free(gcreq);
}
void ddsi_handshake_remove(struct participant *pp, struct proxy_participant *proxypp)
{
struct ddsi_hsadmin *hsadmin = pp->e.gv->hsadmin;
struct ddsi_handshake *handshake = NULL;
ddsrt_mutex_lock(&hsadmin->lock);
if (!handshake)
handshake = ddsi_handshake_find_locked(hsadmin, pp, proxypp);
handshake = ddsi_handshake_find_locked(hsadmin, pp, proxypp);
if (handshake)
{
struct gcreq *gcreq = gcreq_new (pp->e.gv->gcreq_queue, gc_delete_handshale);
ddsrt_avl_delete(&handshake_treedef, &hsadmin->handshakes, handshake);
ddsrt_atomic_st32(&handshake->deleting, 1);
dds_security_fsm_stop(handshake->fsm);
gcreq->arg = handshake;
gcreq_enqueue (gcreq);
}
ddsrt_mutex_unlock(&hsadmin->lock);
if (handshake && handshake->fsm)
dds_security_fsm_free(handshake->fsm);
ddsi_handshake_release(handshake);
}
struct ddsi_handshake * ddsi_handshake_find(struct participant *pp, struct proxy_participant *proxypp)

View file

@ -668,7 +668,7 @@ static void disconnect_participant_secure(struct participant *pp)
entidx_enum_proxy_participant_init (&it, gv->entity_index);
while ((proxypp = entidx_enum_proxy_participant_next (&it)) != NULL)
{
ddsi_handshake_remove(pp, proxypp, NULL);
ddsi_handshake_remove(pp, proxypp);
}
entidx_enum_proxy_participant_fini (&it);
}
@ -3102,19 +3102,21 @@ static void match_volatile_secure_endpoints (struct participant *pp, struct prox
guid = pp->e.guid;
guid.entityid.u = NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_READER;
rd = entidx_lookup_reader_guid (pp->e.gv->entity_index, &guid);
assert(rd);
if ((rd = entidx_lookup_reader_guid (pp->e.gv->entity_index, &guid)) == NULL)
return;
guid.entityid.u = NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_WRITER;
wr = entidx_lookup_writer_guid (pp->e.gv->entity_index, &guid);
assert(wr);
if ((wr = entidx_lookup_writer_guid (pp->e.gv->entity_index, &guid)) == NULL)
return;
guid = proxypp->e.guid;
guid.entityid.u = NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_READER;
prd = entidx_lookup_proxy_reader_guid (pp->e.gv->entity_index, &guid);
assert(rd);
if ((prd = entidx_lookup_proxy_reader_guid (pp->e.gv->entity_index, &guid)) == NULL)
return;
guid.entityid.u = NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_WRITER;
pwr = entidx_lookup_proxy_writer_guid (pp->e.gv->entity_index, &guid);
assert(wr);
if ((pwr = entidx_lookup_proxy_writer_guid (pp->e.gv->entity_index, &guid)) == NULL)
return;
connect_proxy_writer_with_reader_wrapper(&pwr->e, &rd->e, tnow);
connect_writer_with_proxy_reader_wrapper(&wr->e, &prd->e, tnow);
@ -4771,7 +4773,7 @@ void handshake_end_cb(struct ddsi_handshake *handshake, struct participant *pp,
case STATE_HANDSHAKE_OK:
DDS_CLOG (DDS_LC_DISCOVERY, &gv->logconfig, "handshake (lguid="PGUIDFMT" rguid="PGUIDFMT") succeeded\n", PGUID (pp->e.guid), PGUID (proxypp->e.guid));
update_proxy_participant_endpoint_matching(proxypp, pp);
ddsi_handshake_remove(pp, proxypp, handshake);
ddsi_handshake_remove(pp, proxypp);
break;
case STATE_HANDSHAKE_TIMED_OUT:
@ -4780,7 +4782,7 @@ void handshake_end_cb(struct ddsi_handshake *handshake, struct participant *pp,
downgrade_to_nonsecure(proxypp);
update_proxy_participant_endpoint_matching(proxypp, pp);
}
ddsi_handshake_remove(pp, proxypp, handshake);
ddsi_handshake_remove(pp, proxypp);
break;
case STATE_HANDSHAKE_FAILED:
DDS_CERROR (&gv->logconfig, "handshake (lguid="PGUIDFMT" rguid="PGUIDFMT") failed: (%d) Failed\n", PGUID (pp->e.guid), PGUID (proxypp->e.guid), (int)result);
@ -4788,11 +4790,11 @@ void handshake_end_cb(struct ddsi_handshake *handshake, struct participant *pp,
downgrade_to_nonsecure(proxypp);
update_proxy_participant_endpoint_matching(proxypp, pp);
}
ddsi_handshake_remove(pp, proxypp, handshake);
ddsi_handshake_remove(pp, proxypp);
break;
default:
DDS_CERROR (&gv->logconfig, "handshake (lguid="PGUIDFMT" rguid="PGUIDFMT") failed: (%d) Unknown failure\n", PGUID (pp->e.guid), PGUID (proxypp->e.guid), (int)result);
ddsi_handshake_remove(pp, proxypp, handshake);
ddsi_handshake_remove(pp, proxypp);
break;
}
}
@ -4840,7 +4842,7 @@ static void disconnect_proxy_participant_secure(struct proxy_participant *proxyp
entidx_enum_participant_init (&it, gv->entity_index);
while ((pp = entidx_enum_participant_next (&it)) != NULL)
{
ddsi_handshake_remove(pp, proxypp, NULL);
ddsi_handshake_remove(pp, proxypp);
}
entidx_enum_participant_fini (&it);
}

View file

@ -1159,7 +1159,7 @@ static int maybe_grow_whc (struct writer *wr)
int write_sample_p2p_wrlock_held(struct writer *wr, seqno_t seq, struct ddsi_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk, struct proxy_reader *prd)
{
struct ddsi_domaingv * const gv = wr->e.gv;
int r;
int r = 0;
nn_mtime_t tnow;
int rexmit = 1;
struct wr_prd_match *wprd = NULL;
@ -1170,10 +1170,14 @@ int write_sample_p2p_wrlock_held(struct writer *wr, seqno_t seq, struct ddsi_pli
serdata->twrite = tnow;
serdata->timestamp = now();
if (prd->filter)
{
if ((wprd = ddsrt_avl_lookup (&wr_readers_treedef, &wr->readers, &prd->e.guid)) != NULL)
{
if (wprd->seq == MAX_SEQ_NUMBER)
goto prd_is_deleting;
rexmit = prd->filter(wr, prd, serdata);
/* determine if gap has to added */
if (rexmit)
@ -1212,6 +1216,7 @@ int write_sample_p2p_wrlock_held(struct writer *wr, seqno_t seq, struct ddsi_pli
writer_hbcontrol_note_asyncwrite(wr, tnow);
}
prd_is_deleting:
return r;
}