From d8dc223574f9b4c716ed76830aa6a89aeb761224 Mon Sep 17 00:00:00 2001 From: herlesupreeth Date: Mon, 25 Dec 2023 12:08:34 +0100 Subject: [PATCH] cdp: add destination realm avp only if not present --- src/modules/cdp/authstatemachine.c | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/modules/cdp/authstatemachine.c b/src/modules/cdp/authstatemachine.c index 4a8d6f12ed9..a5aadb1c274 100644 --- a/src/modules/cdp/authstatemachine.c +++ b/src/modules/cdp/authstatemachine.c @@ -751,7 +751,7 @@ void auth_server_stateless_sm_process( int dup_routing_avps(AAAMessage *src, AAAMessage *dest) { - AAA_AVP *avp; + AAA_AVP *avp, *avp2; str dest_realm; if(!src) @@ -782,18 +782,24 @@ int dup_routing_avps(AAAMessage *src, AAAMessage *dest) LM_DBG("dup_routing_avps: Origin Realm AVP present, duplicating %.*s\n", avp->data.len, avp->data.s); dest_realm = avp->data; - avp = AAACreateAVP(AVP_Destination_Realm, AAA_AVP_FLAG_MANDATORY, 0, - dest_realm.s, dest_realm.len, AVP_DUPLICATE_DATA); - if(!avp) { - LM_ERR("dup_routing_avps: Failed creating Destination Host avp\n"); - goto error; - } - if(AAAAddAVPToMessage(dest, avp, dest->avpList.tail) - != AAA_ERR_SUCCESS) { - LM_ERR("dup_routing_avps: Failed adding Destination Host avp to " - "message\n"); - AAAFreeAVP(&avp); - goto error; + avp2 = AAAFindMatchingAVP(src, src->avpList.head, AVP_Destination_Realm, + 0, AAA_FORWARD_SEARCH); + if(!avp2) { + avp = AAACreateAVP(AVP_Destination_Realm, AAA_AVP_FLAG_MANDATORY, 0, + dest_realm.s, dest_realm.len, AVP_DUPLICATE_DATA); + if(!avp) { + LM_ERR("dup_routing_avps: Failed creating Destination Realm " + "avp\n"); + goto error; + } + if(AAAAddAVPToMessage(dest, avp, dest->avpList.tail) + != AAA_ERR_SUCCESS) { + LM_ERR("dup_routing_avps: Failed adding Destination Realm avp " + "to " + "message\n"); + AAAFreeAVP(&avp); + goto error; + } } }