# HG changeset patch # User Sebastien Decugis # Date 1436022397 -28800 # Node ID 035f489b845b8c9b900f0bd80864d22516cf9bef # Parent 0f215b0dda5ef3dbec12c42dd51c86590f144553 Added a new hook HOOK_MESSAGE_SENDING diff -r 0f215b0dda5e -r 035f489b845b contrib/debian/changelog --- a/contrib/debian/changelog Tue Jun 23 12:12:10 2015 +0800 +++ b/contrib/debian/changelog Sat Jul 04 23:06:37 2015 +0800 @@ -3,6 +3,8 @@ * New extension: rt_randomize (load-balancing on possible destinations) * New contrib: Gx extension. * rt_redirect.fdx and rt_load_balance.fdx improvement: use a hash table. Thanks Thomas. + * New hook HOOK_MESSAGE_SENDING to give a last chance to edit messages before they are sent. + This will be mostly used for enforcing interoperability constraints on non-compliant peers. * Simplified log output. Old output can be recovered with DEBUG_WITH_META build option. * Updated the internal counters for finer control on the load. * Fixes in message expiry mechanism. diff -r 0f215b0dda5e -r 035f489b845b extensions/dbg_msg_dumps/dbg_msg_dumps.c --- a/extensions/dbg_msg_dumps/dbg_msg_dumps.c Tue Jun 23 12:12:10 2015 +0800 +++ b/extensions/dbg_msg_dumps/dbg_msg_dumps.c Sat Jul 04 23:06:37 2015 +0800 @@ -118,6 +118,10 @@ LOG_N("RCV from '%s':", peer_name); LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); break; + case HOOK_MESSAGE_SENDING: + LOG_N("SNDING to '%s':", peer_name); + LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); + break; case HOOK_MESSAGE_SENT: LOG_N("SND to '%s':", peer_name); LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); @@ -204,6 +208,9 @@ case HOOK_MESSAGE_RECEIVED: LOG_N("RCV from '%s': %s", peer_name, buf); break; + case HOOK_MESSAGE_SENDING: + LOG_N("SNDING to '%s': %s", peer_name, buf); + break; case HOOK_MESSAGE_SENT: LOG_N("SND to '%s': %s", peer_name, buf); break; @@ -283,6 +290,9 @@ case HOOK_MESSAGE_RECEIVED: LOG_N("RCV from '%s': %s", peer_name, buf); break; + case HOOK_MESSAGE_SENDING: + LOG_N("SNDING to '%s': %s", peer_name, buf); + break; case HOOK_MESSAGE_SENT: LOG_N("SND to '%s': %s", peer_name, buf); break; @@ -341,7 +351,7 @@ } mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED ); - mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ); + mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ); /* We don t access SENDING hook here */ mask_routing= HOOK_MASK( HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ); mask_peers = HOOK_MASK( HOOK_PEER_CONNECT_FAILED, HOOK_PEER_CONNECT_SUCCESS ); diff -r 0f215b0dda5e -r 035f489b845b extensions/test_app/ta_cli.c --- a/extensions/test_app/ta_cli.c Tue Jun 23 12:12:10 2015 +0800 +++ b/extensions/test_app/ta_cli.c Sat Jul 04 23:06:37 2015 +0800 @@ -70,7 +70,6 @@ ASSERT( new == 0 ); CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return ); - TRACE_DEBUG( INFO, "%p %p", mi, data); ASSERT( (void *)mi == data ); } diff -r 0f215b0dda5e -r 035f489b845b include/freeDiameter/libfdcore.h --- a/include/freeDiameter/libfdcore.h Tue Jun 23 12:12:10 2015 +0800 +++ b/include/freeDiameter/libfdcore.h Sat Jul 04 23:06:37 2015 +0800 @@ -964,6 +964,16 @@ - {permsgdata} points to a new empty structure allocated for this request (cf. fd_hook_data_hdl) */ + HOOK_MESSAGE_SENDING, + /* Hook called when a message is about to be sent to a peer. The message pointer cannot be modified here, but the content of the message + could still be changed (for example add or remove some AVP. This is the last chance. + - {msg} points to the message. Some objects may not have been dictionary resolved. If you + try to call fd_msg_parse_dict, it will slow down the operation of the instance. + - {peer} is the one the message is being sent to. + - {other} is NULL. + - {permsgdata} points to existing structure if any, or a new structure otherwise. + */ + HOOK_MESSAGE_SENT, /* Hook called when a message has been sent to a peer. The message might be freed as soon as the hook function returns, so it is not safe to store the pointer for asynchronous processing. diff -r 0f215b0dda5e -r 035f489b845b libfdcore/hooks.c --- a/libfdcore/hooks.c Tue Jun 23 12:12:10 2015 +0800 +++ b/libfdcore/hooks.c Sat Jul 04 23:06:37 2015 +0800 @@ -344,6 +344,11 @@ break; } + case HOOK_MESSAGE_SENDING: { + LOG_A("SENDING message to '%s'", peer ? peer->p_hdr.info.pi_diamid : ""); + break; + } + case HOOK_MESSAGE_SENT: { CHECK_MALLOC_DO(fd_msg_dump_summary(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break); LOG_D("SENT to '%s': %s", peer ? peer->p_hdr.info.pi_diamid : "", hook_default_buf); diff -r 0f215b0dda5e -r 035f489b845b libfdcore/p_out.c --- a/libfdcore/p_out.c Tue Jun 23 12:12:10 2015 +0800 +++ b/libfdcore/p_out.c Sat Jul 04 23:06:37 2015 +0800 @@ -165,6 +165,8 @@ TRACE_ENTRY("%p %p %p", msg, cnx, peer); CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); + + fd_hook_call(HOOK_MESSAGE_SENDING, *msg, peer, NULL, fd_msg_pmdl_get(*msg)); if (update_reqin_cnt && peer) { CHECK_FCT( fd_msg_hdr(*msg, &hdr) );