Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_contact_alias() issue with clients adding it to their Contact #2308

Closed
mtryfoss opened this issue Apr 28, 2020 · 14 comments
Closed

set_contact_alias() issue with clients adding it to their Contact #2308

mtryfoss opened this issue Apr 28, 2020 · 14 comments

Comments

@mtryfoss
Copy link
Member

I'm using set_contact_alias() to fix nat registrations, in this case with a Bria client.
Somehow Bria learns that I'm using this - probably through the Contact in the 200 OK reply of save(). Bria then adds this to the Contact when replying to incoming INVITE.

After some time, something happens in the network at client side and the connection gets a new port through the router. Bria does not notice and still sends the old alias-parameter with the port not used anymore. When I'm calling handle_ruri_alias(), Kamailio reads this instead of the actual port and the ACK to 200 OK is sent to a port not used anymore.

This can probably be solved by either, in preferred order:

  • rewrite set_contact_alias() and add_contact_alias() to replace existing alias parameters
  • regexp remove of alias parameter from Contact of all messages coming from clients
  • regexp remove of alias parameter from Contact returned by save()

Br,
Morten

@miconda
Copy link
Member

miconda commented May 2, 2020

set_contact_alias() should not be used for registrations, but for requests that are typically forwarded. If you do it on an edge proxy between device and registrar server, then you should use path module and leave the contact unchanged.

If you use it in the registrar server config, then you should replace it with fix_nated_register(), like in the default kamailio.cfg.

Otherwise, if you really want to use it, then in case you have to deal with such UA, then yes, you will have to remove (or replace) the alias parameter in Contact. Probably you can play with the replace/subst functions from textops and if you can't get it, then new C code has to be added. A pull request is of course appreciated.

@mtryfoss
Copy link
Member Author

mtryfoss commented May 3, 2020

Thank you for your reply.

Does the manual somewhere state that set_contact_alias() should not be used for REGISTER?
Actually, some examples suggest using this instead of fix_nated_contact() - http://www.evaristesys.com/blog/server-side-nat-traversal-with-kamailio-the-definitive-guide/

The reason for using set_contact_alias() instead of fix_nated_contact() is that one client seemed to have an issue with the contact being changed.

I'm actually using in on an edge proxy and already using Path, but I guess I missed setting this on the edge: modparam("path", "use_received", 1)

Fixed it already temp with a subst on the reply for REGISTERs, as you wrote.

@pafels
Copy link

pafels commented May 4, 2020

Would you please share how you fixed it with subst?

@mtryfoss
Copy link
Member Author

mtryfoss commented May 4, 2020

All done on edge proxy. I'm not a regex-pro.
It will not work if done locally on the registrar (the node doing the save()).

https://gist.github.com/mtryfoss/9a0811dbc4462b91afe87d7dd5a210e8

@miconda
Copy link
Member

miconda commented May 4, 2020

@mtryfoss - the set_contact_alias() is indeed for use instead of fix_nated_contact(). But fix_nated_contact() is not for REGISTER, for it the fix_nated_register() should be used. However, fix_nated_register() has to be used only if the registrar server is next to the nat router. If registrar is behind an edge proxy (SBC), then it should work without touching the contact and using the Path module (with use_received indeed).

Now, as you noticed, set_contact_alias() may work also for REGISTER, but some UAs don't like it (or use it inappropriately). You are more than welcome to make a pull request to the docs of this function to explain better its purpose based on your experiences.

@miconda
Copy link
Member

miconda commented May 4, 2020

@mtryfoss: regarding the subst, probably it does the job with ipv4 and the alias value set by Kamailio, which is what you need.

However in regexp . is matching any char, if you want to restrict it to match . as a char, one way is to enclose it inside square brackets, like:

subst("/;alias=[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+~[0-9]+~[0-9]+//g");

@miconda
Copy link
Member

miconda commented May 13, 2020

Going to close this one, solutions being found. If someone wants to make a pull request adding a function to cope with this specific case, it is more than welcome!

@miconda miconda closed this as completed May 13, 2020
@eschmidbauer
Copy link
Contributor

curious on this topic- we use set_contact_alias()on our SIP REGISTERs/INVITEs because we can't use the received parameter. we can't use the received parameter because our registrars are setup to accept traffic from two sets of edge proxies. one set of proxies supports the received param, the other set of proxies does not support the received param due to different network conditions.
but in any case, our setup works great, handle_ruri_alias() should be stripping the contact alias before it reaches the UAC and your edge proxy should be adding the contact alias on each request from the UAC. im wondering if you can share more of your config with me so i can understand how this is happening.

@mtryfoss
Copy link
Member Author

mtryfoss commented Jul 2, 2020

handle_ruri_alias() only handle alias in Request-URI, not the Contact returned by the registrar for REGISTER.

For most phone clients this is not a problem but Bria used that info in subsequent requests.
So, when the proxy again doing set_contact_alias() on an INVITE from Bria (already containing an alias), you'll end up with two alias parameters. One of them might be outdated if port/source-ip has changed through NAT since initial registration.

When proxy then calls handle_ruri_alias() the first parameter is handled and removed, and you'll send the one which the proxy actually added back to the client. The ip/port used in the reply might be wrong if the alias Bria added is outdated.

@eschmidbauer
Copy link
Contributor

ohhh i understand now.
I believe set_contact_alias() should overwrite any previous contact alias on the request.
have you tried on 5.3 latest? perhaps this should be a setting in nathelper as it would make sense to overwrite it in some cases like this

@mtryfoss
Copy link
Member Author

mtryfoss commented Jul 2, 2020

I've only been testing 5.3.3. Of course, the alias should probably be replaced if it exists rather than append one more without the need for a specific setting/parameter.

I'm not that into Kamailio source and did not have time to get going there when I found the issue, so I fixed it quickly by a regexp replace.

@miconda
Copy link
Member

miconda commented Jul 2, 2020

Master branch (upcoming 5.4.0) has now a function to remove parameters from Contact header URI (see siputils module).

@eschmidbauer
Copy link
Contributor

https://github.com/kamailio/kamailio/compare/nathelper-set_contact_alias-trim?expand=1
@mtryfoss
i've added support for trimming an already existing alias. I've tested it locally and it works- but can you please test it in your setup?
just call the function with "1" param like so set_contact_alias("1");

@mtryfoss
Copy link
Member Author

mtryfoss commented Jul 2, 2020

Thanks!

I've lost my staging environment temporarily because of some physical re-location of our servers.
I will try to test it when I'm returning from vacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants