# HG changeset patch # User Sebastien Decugis # Date 1381414126 -7200 # Node ID 8f9684264fe05e25a073f1cb939a18af2e78fe14 # Parent a0d9fb49694ea7ffaee3746a7636da998906f653 Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages. diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/fdcore-internal.h --- a/libfdcore/fdcore-internal.h Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/fdcore-internal.h Thu Oct 10 16:08:46 2013 +0200 @@ -296,7 +296,7 @@ void fd_psm_cleanup(struct fd_peer * peer, int terminate); /* Peer out */ -int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer); +int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, int update_reqin_cnt); int fd_out_start(struct fd_peer * peer); int fd_out_stop(struct fd_peer * peer); diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_ce.c --- a/libfdcore/p_ce.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_ce.c Thu Oct 10 16:08:46 2013 +0200 @@ -634,7 +634,7 @@ /* Create and send the CEA with appropriate error code */ CHECK_FCT_DO( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ), goto destroy ); CHECK_FCT_DO( fd_msg_rescode_set(*cer, error->pei_errcode, error->pei_message, error->pei_avp, 1 ), goto destroy ); - CHECK_FCT_DO( fd_out_send(cer, *recv_cnx, NULL), goto destroy ); + CHECK_FCT_DO( fd_out_send(cer, *recv_cnx, NULL, 0), goto destroy ); if (error->pei_avp_free) { fd_msg_free(error->pei_avp); @@ -658,7 +658,7 @@ /* Send CER on the new connection */ CHECK_FCT( create_CER(peer, initiator, &cer) ); - CHECK_FCT( fd_out_send(&cer, initiator, peer) ); + CHECK_FCT( fd_out_send(&cer, initiator, peer, 0) ); /* Are we doing an election ? */ if (fd_peer_getstate(peer) == STATE_WAITCNXACK_ELEC) { @@ -713,7 +713,7 @@ CHECK_FCT( fd_msg_rescode_set(*msg, "DIAMETER_UNABLE_TO_COMPLY", "No CER allowed in current state", NULL, 1 ) ); /* msg now contains an answer message to send back */ - CHECK_FCT_DO( fd_out_send(msg, NULL, peer), /* In case of error the message has already been dumped */ ); + CHECK_FCT_DO( fd_out_send(msg, NULL, peer, 0), /* In case of error the message has already been dumped */ ); } /* If the state is not WAITCEA, just discard the message */ @@ -942,11 +942,6 @@ isi = 0; } - /* Update the counter to match with the answer being sent */ - CHECK_POSIX( pthread_mutex_lock(&peer->p_state_mtx) ); - peer->p_reqin_count++; - CHECK_POSIX( pthread_mutex_unlock(&peer->p_state_mtx) ); - /* Reply a CEA */ CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msg, 0 ) ); CHECK_FCT( fd_msg_rescode_set(msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) ); @@ -955,7 +950,7 @@ /* The connection is complete, but we may still need TLS handshake */ fd_hook_call(HOOK_PEER_CONNECT_SUCCESS, msg, peer, NULL, NULL); - CHECK_FCT( fd_out_send(&msg, peer->p_cnxctx, peer ) ); + CHECK_FCT( fd_out_send(&msg, peer->p_cnxctx, peer, 0 ) ); /* Handshake if needed */ if (isi & PI_SEC_TLS_OLD) { diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_dp.c --- a/libfdcore/p_dp.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_dp.c Thu Oct 10 16:08:46 2013 +0200 @@ -112,12 +112,12 @@ /* Do we have pending exchanges with this peer? */ CHECK_FCT( fd_peer_get_load_pending(&peer->p_hdr, &to_receive, &to_send) ); - if ((to_receive == 0) && (to_send == 1 /* only the DPA */)) { + if ((to_receive == 0) && (to_send == 0)) { /* No pending exchange, move to CLOSING directly */ CHECK_FCT( fd_psm_change_state(peer, STATE_CLOSING) ); /* Now send the DPA */ - CHECK_FCT( fd_out_send( msg, NULL, peer) ); + CHECK_FCT( fd_out_send( msg, NULL, peer, 0) ); /* and move to CLOSED */ fd_psm_cleanup(peer, 0); @@ -131,7 +131,7 @@ fd_psm_next_timeout(peer, 0, GRACE_TIMEOUT); /* Now send the DPA */ - CHECK_FCT( fd_out_send( msg, NULL, peer) ); + CHECK_FCT( fd_out_send( msg, NULL, peer, 0) ); } } else { /* We received a DPA */ @@ -201,7 +201,7 @@ fd_psm_next_timeout(peer, 0, DPR_TIMEOUT); /* Now send the DPR message */ - CHECK_FCT_DO( fd_out_send(&msg, NULL, peer), /* ignore since we are on timeout anyway */ ); + CHECK_FCT_DO( fd_out_send(&msg, NULL, peer, 0), /* ignore since we are on timeout anyway */ ); return 0; } diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_dw.c --- a/libfdcore/p_dw.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_dw.c Thu Oct 10 16:08:46 2013 +0200 @@ -82,7 +82,7 @@ CHECK_FCT( fd_msg_add_origin ( msg, 1 ) ); /* Now send this message */ - CHECK_FCT( fd_out_send(&msg, NULL, peer) ); + CHECK_FCT( fd_out_send(&msg, NULL, peer, 0) ); /* And mark the pending DW */ peer->p_flags.pf_dw_pending = 1; @@ -105,7 +105,7 @@ CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); CHECK_FCT( fd_msg_rescode_set( *msg, "DIAMETER_SUCCESS", NULL, NULL, 0 ) ); CHECK_FCT( fd_msg_add_origin ( *msg, 1 ) ); - CHECK_FCT( fd_out_send( msg, peer->p_cnxctx, peer) ); + CHECK_FCT( fd_out_send( msg, peer->p_cnxctx, peer, 0) ); } else { /* Discard the DWA */ diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_out.c --- a/libfdcore/p_out.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_out.c Thu Oct 10 16:08:46 2013 +0200 @@ -159,14 +159,14 @@ } /* Wrapper to sending a message either by out thread (peer in OPEN state) or directly; cnx or peer must be provided. Flags are valid only for direct sending, not through thread (unused) */ -int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer) +int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, int update_reqin_cnt) { struct msg_hdr * hdr; TRACE_ENTRY("%p %p %p", msg, cnx, peer); CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); - if (peer) { + if (update_reqin_cnt && peer) { CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); if (!(hdr->msg_flags & CMD_FLAG_REQUEST)) { /* Update the count of pending answers to send */ diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_psm.c --- a/libfdcore/p_psm.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_psm.c Thu Oct 10 16:08:46 2013 +0200 @@ -526,11 +526,6 @@ /* Associate */ CHECK_FCT_DO( fd_msg_answ_associate( msg, req ), goto psm_end ); - } else { - /* Mark the incoming request so that we know we have pending answers for this peer */ - CHECK_POSIX_DO( pthread_mutex_lock(&peer->p_state_mtx), goto psm_end ); - peer->p_reqin_count++; - CHECK_POSIX_DO( pthread_mutex_unlock(&peer->p_state_mtx), goto psm_end ); } /* Log incoming message */ @@ -559,6 +554,13 @@ /* Set the message source and add the Route-Record */ CHECK_FCT_DO( fd_msg_source_setrr( msg, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, fd_g_config->cnf_dict ), goto psm_end); + if ((hdr->msg_flags & CMD_FLAG_REQUEST)) { + /* Mark the incoming request so that we know we have pending answers for this peer */ + CHECK_POSIX_DO( pthread_mutex_lock(&peer->p_state_mtx), goto psm_end ); + peer->p_reqin_count++; + CHECK_POSIX_DO( pthread_mutex_unlock(&peer->p_state_mtx), goto psm_end ); + } + /* Requeue to the global incoming queue */ CHECK_FCT_DO(fd_fifo_post(fd_g_incoming, &msg), goto psm_end ); @@ -600,7 +602,7 @@ } else { if (msg == NULL) { /* Send the error back to the peer */ - CHECK_FCT_DO( ret = fd_out_send(&error, NULL, peer), ); + CHECK_FCT_DO( ret = fd_out_send(&error, NULL, peer, 0), ); if (error) { char buf[256]; /* Only if an error occurred & the message was not saved / dumped */ @@ -654,7 +656,7 @@ CHECK_FCT_DO( fd_msg_rescode_set(msg, "DIAMETER_COMMAND_UNSUPPORTED", "Or maybe the P-bit or application Id are erroneous.", NULL, 1 ), break ); /* Send the answer */ - CHECK_FCT_DO( fd_out_send(&msg, peer->p_cnxctx, peer), break ); + CHECK_FCT_DO( fd_out_send(&msg, peer->p_cnxctx, peer, 0), break ); } while (0); } else { /* We did ASK for it ??? */ diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/p_sr.c --- a/libfdcore/p_sr.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/p_sr.c Thu Oct 10 16:08:46 2013 +0200 @@ -336,6 +336,7 @@ } /* The list of expiring requests must be empty now */ ASSERT( FD_IS_LIST_EMPTY(&srlist->exp) ); + ASSERT( srlist->cnt == 0 ); /* debug the counter management if needed */ CHECK_POSIX_DO( pthread_mutex_unlock(&srlist->mtx), /* continue anyway */ ); diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/peers.c --- a/libfdcore/peers.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/peers.c Thu Oct 10 16:08:46 2013 +0200 @@ -549,7 +549,7 @@ fd_hook_call(HOOK_PEER_CONNECT_FAILED, *cer, NULL, "Received CER with invalid Origin-Host AVP", NULL); - CHECK_FCT( fd_out_send(cer, *cnx, NULL) ); + CHECK_FCT( fd_out_send(cer, *cnx, NULL, 0) ); return EINVAL; } diff -r a0d9fb49694e -r 8f9684264fe0 libfdcore/routing_dispatch.c --- a/libfdcore/routing_dispatch.c Sat Sep 14 12:56:05 2013 +0200 +++ b/libfdcore/routing_dispatch.c Thu Oct 10 16:08:46 2013 +0200 @@ -414,7 +414,7 @@ if (is_loc) { CHECK_FCT( fd_fifo_post(fd_g_incoming, pmsg) ); } else { - CHECK_FCT( fd_out_send(pmsg, NULL, peer) ); + CHECK_FCT( fd_out_send(pmsg, NULL, peer, 1) ); } /* Done */ @@ -892,7 +892,7 @@ hdr->msg_hbhid = qry_hdr->msg_hbhid; /* Push the message into this peer */ - CHECK_FCT( fd_out_send(&msgptr, NULL, peer) ); + CHECK_FCT( fd_out_send(&msgptr, NULL, peer, 1) ); /* We're done with this answer */ return 0; @@ -1007,7 +1007,7 @@ if (fd_peer_getstate(peer) == STATE_OPEN) { /* Send to this one */ - CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer), continue ); + CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer, 1), continue ); /* If the sending was successful */ break;