# PJSIP - anonymous endpoint, dialing via proxy

**URL:** <https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857>\
**Category:** Asterisk General\
**Created:** [March 3, 2016, 7:57am UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857 "2016-03-03T07:57:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecnken](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@ecnken](https://community.asterisk.org/u/ecnken)\
**Post date:** [March 3, 2016, 7:57am UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/1 "2016-03-03T07:57:52Z")

</div>

Hi,

I’m in the process of migrating our Asterisk configuration from `chan_sip` to PJSIP, and have run into a problem with the way we do dial strings.

For some background, we’re using a very simple “bare bones” Asterisk configuration with `chan_sip` configured with `insecure=invite`, and a dialplan which just throws new channels into `stasis`. We have SIP proxies and registrars which manage registration and authentication where needed, and we orchestrate and manage our calls via ARI. Asterisk is not using any real-time configuration or pre-configured users.

We have multiple SIP proxies in front of the Asterisk services, and we dial in and out via these proxies. Our software which is orchestrating calls via ARI is also aware of all the proxies involved, and the various routes to/from our Asterisks and the outside world.

Now the problem. Using `chan_sip`, we could build dial strings which looked something like this:

`SIP/target-host/target-user/outbound-proxy`

This does the following for us:

- Creates an INVITE with a URI which looks like `sip:target-user@target-host`
- Sends the INVITE via `outbound-proxy`

This all works marvelously. We also have variations which append custom `Route:` headers for more complicated routing scenarios, using magical `__SIPADDHEADER5n` variables along with the ARI channel creation request (not even sure how this is going to interact with PJSIP, yet, one thing at a time).

I currently have an `anonymous` endpoint defined as follows in `pjsip.conf`:

```auto
[anonymous]
type=endpoint
transport=transport-udp
context=my-stasis-context
allow=all

```

This works for accepting inbound calls, and making outbound calls using an endpoint/dialstring of `pjsip/anonymous/sip:target-user@target-host`.

So my question is, how may I (or can I even) achieve the equivalent of our current `chan_sip` style dial strings, which allow software to determine the `outbound_proxy` dynamically at runtime, without the need for database reliance and the like?

---

<div class="post-metadata">

**Author:** ![ecnken](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@ecnken](https://community.asterisk.org/u/ecnken)\
**Post date:** [March 3, 2016, 10:08am UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/2 "2016-03-03T10:08:13Z")

</div>

I just noticed that if I construct an endpoint with an `outbound_proxy` in `pjsip.conf` (for testing, this is impractical in my use-case), and dial using `PJSIP/anonymous/sip:target-peer@target-host`, the outbound `INVITE` SIP URI is simply `sip:outbound-proxy` (the `To:` header is `target-peer@target-host` though), rather than the `chan_sip` format noted above as `sip:target-user@target-host`. This is both with and without an AoR of either `sip:user@proxy` or `sip:proxy`.

This can possibly be worked around at our `outbound-proxy` level with some URI rewriting, although I’d prefer to keep these changes limited to Asterisk configuration as much as possible, and some changes to our software where needed.

I should also note I’m using an Asterisk build pulled from the git `master` branch.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 3, 2016, 11:40am UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/3 "2016-03-03T11:40:06Z")

</div>

If you want to use loose routing (where the request URI is preserved) then you need to add ;lr to the end of the outbound proxy URI.

Example:  
outbound\_proxy=sip:proxy.voip.com;lr

As for control from the dialplan, this isn’t currently possible. The Dial string for PJSIP is extremely simple and EVERYTHING requires an endpoint. It would theoretically be possible to construct an ephemeral endpoint from the dialplan and use that, but noone has done so or experimented with it.

---

<div class="post-metadata">

**Author:** ![ecnken](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@ecnken](https://community.asterisk.org/u/ecnken)\
**Post date:** [March 3, 2016, 12:07pm UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/4 "2016-03-03T12:07:01Z")

</div>

Hi,

Thanks for the reply, I’ll try with loose routing.

Since endpoints are absolutely required per proxy I need to route via, I think I found the solution to my problems in [https://wiki.asterisk.org/wiki/display/AST/ARI+Push+Configuration](https://wiki.asterisk.org/wiki/display/AST/ARI+Push+Configuration).

I should be able to construct endpoints dynamically at runtime, and then dial them when required.

Thanks!

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 3, 2016, 2:15pm UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/5 "2016-03-03T14:15:18Z")

</div>

Yup! That should work fine.

---

<div class="post-metadata">

**Author:** ![carlos8888](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@carlos8888](https://community.asterisk.org/u/carlos8888)\
**Post date:** [March 29, 2016, 4:36am UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/6 "2016-03-29T04:36:26Z")

</div>

Hi I followed these instructions but Asterisk complains when it parses out the outbound\_proxy information  
Using Realtime ps\_endpoints Table.  
I have an endpoint configured with outbound\_proxy as having sip:proxy\_url;lr  
Asterisk says "as outbound proxy URI ‘lr’ is not valid"  
Thanks much

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 29, 2016, 1:42pm UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/7 "2016-03-29T13:42:05Z")

</div>

When putting it in a database you should be able to leave out the , the \ is used in configuration files to escape the next character. Without it the configuration file would consider the “;lr” a comment.

---

<div class="post-metadata">

**Author:** ![carlos8888](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@carlos8888](https://community.asterisk.org/u/carlos8888)\
**Post date:** [March 29, 2016, 8:05pm UTC](https://community.asterisk.org/t/pjsip-anonymous-endpoint-dialing-via-proxy/65857/8 "2016-03-29T20:05:04Z")

</div>

Thanks for response. Found out that I needed to put ^3Blr for ASCII characters. Seems to work.
