Which transport did Endpoint come with?

Hi

I have an endpoint configuration that does not have an explicit transport definition. The user can come from X or Y transport. Is there a way to know which transport it came from in the dial plan?

exten => NoOp(TRANSPORT: ${TRANSPORT_ID})
[transportX]
type=transport
bind=x.x.x.x:5060
protocol=udp

[transportY]
type=transport
bind=y.y.y.y:5060
protocol=udp

[1001]
type=endpoint
aors=1001
auth=1001
callerid="User 1001" <1001>
context=from-inside

[1001]
type=auth
auth_type=userpass
password=1234567
username=1001

[1001]
type=aor
max_contacts=3
qualify_frequency=60
qualify_timeout=6.0

Not really, things don’t keep track like that. The packet just comes in.

We had to solve this issue by writing a simple module. I would like to share it for those who need it. It only works on the incoming channel. Additions can also be made for the outgoing channel.

exten => n,NoOp(${TRANSPORT_ID})

    -- Executing [1001@from-inside:2] NoOp("PJSIP/1001-00000000", "transportX") in new stack
#include "asterisk.h"

#include <pjsip.h>
#include <pjsip_ua.h>

#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/module.h"
//#include "asterisk/strings.h"
#include "asterisk/pbx.h"

/*** MODULEINFO
	<depend>pjproject</depend>
	<depend>res_pjsip</depend>
	<depend>res_pjsip_session</depend>
	<support_level>core</support_level>
 ***/

static int set_transport_variable(struct ast_sip_session *session, pjsip_rx_data *rdata)
{
	const char *transport_id;

	if (!ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":")) {
		return PJ_FALSE;
	}

	transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1;
	pbx_builtin_setvar_helper(session->channel, "TRANSPORT_ID", transport_id);
	return PJ_TRUE;
}

static int pbxhelper_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
{
    set_transport_variable(session, rdata);

    return 0;
}

static struct ast_sip_session_supplement pbxhelper_supplement = {
    .method = "INVITE",
	.priority = AST_SIP_SUPPLEMENT_PRIORITY_LAST,
    //.outgoing_request = auto_answer_outgoing_request,
    .incoming_request = pbxhelper_incoming_request,
};

static int load_module(void)
{
    ast_sip_session_register_supplement(&pbxhelper_supplement);
    return AST_MODULE_LOAD_SUCCESS;
}

static int unload_module(void)
{
    ast_sip_session_unregister_supplement(&pbxhelper_supplement);
    return 0;
}

AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PBX Helper",
    .support_level = AST_MODULE_SUPPORT_CORE,
    .load = load_module,
    .unload = unload_module,
    .load_pri = AST_MODPRI_APP_DEPEND,
);
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.