[OpenSIPS-Users] mid_registrar and vpn and nat

Alberto alberto.rinaudo at gmail.com
Tue Dec 13 23:50:30 UTC 2022

I have a problem with a vpn setup, not really nat, or maybe it's nat...

The setup I have is:
Phone - openvpn - opensips - public internet - asterisk

openvpn subnet:
openvpn server:
opensips server:

In my configuration I have:

loadmodule "mid_registrar.so"
modparam("mid_registrar", "max_contacts", 1)
modparam("mid_registrar", "mode", 0)
modparam("mid_registrar", "received_avp", "$avp(rcv)")
modparam("mid_registrar", "tcp_persistent_flag",

if (nat_uac_test(119)) {
  if (is_method("REGISTER")) {
  } else {

if (is_method("REGISTER")) {
  mid_registrar_save("location", "p0");

if ($(tu{uri.param,ctid}) != NULL && mid_registrar_lookup("location")) {
  if (!t_relay()) {
    send_reply(500, "Internal Error");

So, when the phone sends a REGISTER to opensips, the contact header
contains the private ip of the vpn (10.0.0.X/24).
fix_nated_register is able to detect that the ip in the contact is
different from the source ip and sets the received avp.
But if I do opensips-cli -x mi ul_dump, I see that the contact still
contains the openvpn ip, and the received field contains the correct
openvpn ip.
This is a problem because when I do the mid_registrar_lookup, $ru is set to
the contact, which contains an ip that the opensips server is not aware of.
It should instead contain the openvpn server ip (, that could
then route the call to the phone.

I tried to change $rd manually, but that just breaks routing for ACK
What am I doing wrong?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20221213/3dd80be0/attachment.html>

More information about the Users mailing list