From c9702415579b8c7c2eb525accc909a586c17c2d1 Mon Sep 17 00:00:00 2001 From: Henning Westerholt Date: Wed, 31 Mar 2021 13:28:30 +0000 Subject: [PATCH] topos: add functionality to set a variable host part for the Contact header - add functionality to set a variable host part for the Contact header - could be refactored to use a xavp instead of avp, together with the other parameters in this area ([a,b]_contact_avp) --- src/modules/topos/doc/topos_admin.xml | 30 ++++++++++++++++++++++++++- src/modules/topos/topos_mod.c | 14 ++++++++++++- src/modules/topos/tps_storage.c | 23 +++++++++++++++----- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/modules/topos/doc/topos_admin.xml b/src/modules/topos/doc/topos_admin.xml index 1cabfccf076..0ca8bb8c0f3 100644 --- a/src/modules/topos/doc/topos_admin.xml +++ b/src/modules/topos/doc/topos_admin.xml @@ -292,7 +292,8 @@ modparam("topos", "event_mode", 2) <varname>contact_host</varname> (str) You may need to control the host part of the Contact header added - by topos. + by topos. If the contact_host_avp parameter is set, this value is + ignored. For example when using TLS with TOPOS the remote UAS must be able to open a new TLS socket to the contact header. @@ -433,6 +434,33 @@ modparam("topos", "b_contact_avp", "$avp(tps-bct)") ... modparam("topos", "rr_update", 1) ... + + + +
+ <varname>contact_host_avp</varname> (str) + + You may need to control the host part of the Contact header added + by topos. This parameter allows to take the value from an AVP + during run-time. If this parameter is set, the contact_host + parameter is ignored. + + For example when using TLS with TOPOS the remote UAS must be able to open + a new TLS socket to the contact header. + In this case, the contact header must contain a domain name with a trusted CA + signed certitificate. + + + + Default value is empty, not set. + + + + Set <varname>contact_host_avp</varname> parameter + +... +modparam("topos", "contact_host_avp", "$avp(contact_host)") +...
diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c index a8dbf5b9be7..52167bf1649 100644 --- a/src/modules/topos/topos_mod.c +++ b/src/modules/topos/topos_mod.c @@ -96,6 +96,8 @@ static int _tps_eventrt_sending = -1; static str _tps_eventrt_sending_name = str_init("topos:msg-sending"); str _tps_contact_host = str_init(""); int _tps_contact_mode = 0; +str _tps_contact_host_avp = str_init(""); +pv_spec_t _tps_contact_host_avp_spec; str _tps_cparam_name = str_init("tps"); str _tps_acontact_avp; str _tps_bcontact_avp; @@ -142,7 +144,8 @@ static param_export_t params[]={ {"cparam_name", PARAM_STR, &_tps_cparam_name}, {"a_contact_avp", PARAM_STR, &_tps_acontact_avp}, {"b_contact_avp", PARAM_STR, &_tps_bcontact_avp}, - {"rr_update", PARAM_INT, &_tps_rr_update}, + {"contact_host_avp", PARAM_STR, &_tps_contact_host_avp}, + {"rr_update", PARAM_INT, &_tps_rr_update}, {0,0,0} }; @@ -235,6 +238,15 @@ static int mod_init(void) } } + if(_tps_contact_host_avp.len > 0 && _tps_contact_host_avp.s != NULL) { + if(pv_parse_spec(&_tps_contact_host_avp, &_tps_contact_host_avp_spec) == 0 + || _tps_contact_host_avp_spec.type != PVT_AVP) { + LM_ERR("malformed or non AVP %.*s AVP definition\n", + _tps_contact_host_avp.len, _tps_contact_host_avp.s); + return -1; + } + } + sr_event_register_cb(SREV_NET_DATA_IN, tps_msg_received); sr_event_register_cb(SREV_NET_DATA_OUT, tps_msg_sent); diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c index c0bf33be357..f98697f9996 100644 --- a/src/modules/topos/tps_storage.c +++ b/src/modules/topos/tps_storage.c @@ -61,6 +61,8 @@ extern str _tps_acontact_avp; extern str _tps_bcontact_avp; extern pv_spec_t _tps_acontact_spec; extern pv_spec_t _tps_bcontact_spec; +extern str _tps_contact_host_avp; +extern pv_spec_t _tps_contact_host_avp_spec; #define TPS_STORAGE_LOCK_SIZE 1<<9 static gen_lock_set_t *_tps_storage_lock_set = NULL; @@ -343,12 +345,23 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir, td->cp++; } - if (_tps_contact_host.len) { // using configured hostname in the contact header - memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len); - td->cp += _tps_contact_host.len; + // contact_host AVP takes preference + if (_tps_contact_host_avp.len) { + if ((pv_get_spec_value(msg, &_tps_contact_host_avp_spec, &pv_val) != 0) && + (pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) { + LM_ERR("could not evaluate contact_host AVP\n"); + return -1; + } + memcpy(td->cp, pv_val.rs.s, pv_val.rs.len); + td->cp += pv_val.rs.len; } else { - memcpy(td->cp, puri.host.s, puri.host.len); - td->cp += puri.host.len; + if (_tps_contact_host.len) { // using configured hostname in the contact header + memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len); + td->cp += _tps_contact_host.len; + } else { + memcpy(td->cp, puri.host.s, puri.host.len); + td->cp += puri.host.len; + } } if(puri.port.len>0) { *td->cp = ':';