How to get Public IPs in PJSIP Channel?

Hey guys,
We have an asterisk 19.8 server with a reverse proxy in place.
In a WebRTC scenario local and remote addresses are 127.0.0.1 but we need to pass the real public ips to the provider.
We would like to expose the real public IP address of local and remote parties in Asterisk PJSIP Channel to be able to read it via Dialplan or in asterisk core.

AOR IP is not good because of the reverse proxy. I need to extract it from ice candidate (Conn in SDP) but don’t know how exactly.

What is the best way to achieve this matter?

Thank you for helping us.
Mike

How is WebRTC relevant to the provider?

For incoming and outgoing calls they need to log the real ip of that user who made or received that call. in DumpChan() all we can see is 127.0.0.1 and no public IP.
AOR IP is not good because of the reverse proxy and it shows 127.0.0.1.
I need to extract it from ice candidate (Conn in SDP) but don’t know how exactly.

No provider I know of expects to be contacted using web sockets, so my first suspicion is that you have completely the wrong transport specified.

At least for the standard, UDP, TCP and TLS transports, the external addresses are set in the type=transport section:

WebRTC does lots of things in strange ways. I think it uses dummy addresses in requests assuming that the other side will always use the underlying TCP connection, for signalling, and will use the ICE candidates for media. However, I have no real expertise one WebRTC, and I am surprised that you are not being rejected based on transport=wss.

Asterisk <–> Provider connection is UDP. :white_check_mark:
Alice <–> Asterisk is WSS / WebRTC.
Alice <–> Asterisk <–> Provider. I need all public IPs here. but Alice and Asterisk are using 127.0.0.1. So I need to extract Alice IP from C line in ICE which I don’t know how.

direct media rarely works with a provider. I’d suggest just disabling direct media and letting Asterisk relay the RTP.

There is no ability to get the signaling address provided by the proxy from the HTTP signaling. You can retrieve the RTP remote address using the CHANNEL dialplan function[1].

[1 ]Asterisk 20 Function_CHANNEL - Asterisk Project - Asterisk Project Wiki

Thanks but we tried this and because of the reverse proxy we still get 127.0.0.1 IPs.

Also tried building an asterisk patch for our use case to extract Conn from pjsip_rdata_sdp_info but don’t know the correct flow of how to get ips of both parties.
Can you guide us on how we can extract the C line from SDP in chan_pjsip.c

For INVITE (SDP) both local/remote offer and answer, and also RE-INVITE.

Tried what exactly? Be specific.

For example we tried to log and see we if we can see the IP address in SDP. (we are still Noob to Asterisk)

static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
{
        RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
        struct transport_info_data *transport_data;
        pjsip_tx_data *packet = NULL;
        SCOPE_ENTER(3, “%s\n”, ast_sip_session_get_name(session));
        if (session->channel) {
                SCOPE_EXIT_RTN_VALUE(0, “%s: No channel\n”, ast_sip_session_get_name(session));
        }
        ast_log(LOG_WARNING, “---Before rdata---“);
        pjsip_rdata_sdp_info *sdp = pjsip_rdata_get_sdp_info(rdata);
        if (sdp && sdp->body.ptr) {
                        ast_log(LOG_WARNING, “---Before Var init---“);
                        char host_inc[NI_MAXHOST];
                        ast_log(LOG_WARNING, “---VAR Init rdata---“);
                        ast_copy_pj_str(host_inc, &sdp->sdp->conn->addr, sizeof(host_inc));
                        ast_log(LOG_WARNING, “SDP Conn rdata ‘%s’“, host_inc);
         }

I’m sorry, I won’t look at code. Someone else may be able to provide feedback on it.

Thanks. got it.

If you don’t mind, can you just point us to the right direction then?
Where in asterisk code can we retrieve the SDP data from, for INVITE (SDP) local/remote (offer/answer), and also RE-INVITE(SDP)?

I’d suggest looking at how the SDP negotiation works and that whole interaction.

I should also add that in WebRTC the media path is negotiated using ICE, and not c=.

Oh I see. By C= I meant we thought we might be able to extract the Public IP from ICE srflx candidate type.

Whilst I’m pretty sure that you are well outside the intended usage of Asterisk and should not be doing any media path optimisation, so should not be exposing addresses for the WebRTC side to the provider, my understanding of ICE is that part of the process is actually testing if candidates work, so the contents of the SDP exchange isn’t enough to determine the addresses actually used.

However, I’ve never really got into WebRTC, nor do I have deep knowledge of the chan_pjsip/PJProject code.

Also, this seems to have become a developer question, which is really outside the scope of the forum.

As such, I doubt that I can contribute any more.

1 Like

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