[OpenSIPS-Users] socket_in(port) vs socket_in(advertised_port)

Liviu Chircu liviu at opensips.org
Wed Nov 16 11:35:07 UTC 2022


On 25.10.2022 19:11, Ross McKillop via Users wrote:
>
> I would have expected $socket_in(port) to contain the actual port that 
> was used (53235) and $socket_in(advertised_port) to contain the port 
> that is advertised as the listening port for that socket (e.g. 7700) - 
> however $socket_in(port) contains 7700 and $socket_in(advertised_port) 
> is null.
>
> Is this the intended behaviour and, if so, is there any way to access 
> the *actual* destination port that was used (even if it’s ephemeral)?
>
> Any advice anyone can offer would be much appreciated :)

Hey, Ross!

Regarding $socket: there is the READ-ONLY $socket_in [1], concerning the 
ingress traffic and $socket_out [2], READ-WRITE and fully optional, 
controlling the egress traffic.  And an OpenSIPS listener MAY 
additionally have an "advertised" component, for scenarios where it's 
sitting behind a NAT.

I can't think of many good ways of fetching/printing the ephemeral 
source port allocated by the Operating System for a TCP connection:

* Request time: you cannot print it while processing the INVITE since 
the source port is not even allocated until you run the very last t_relay()
* Reply time: replies will be routed using topmost Via, so *maybe* you 
have a chance at printing this port, by looking at the topmost Via 
header (OpenSIPS-generated), using transformations [3].  Even if 
OpenSIPS strips this header during loose_route(), you should still have 
access to it thanks to the "SIP message lumps" lazy evaluation mechanism.

Still: may I ask why you need the "egress ephemeral source port" 
information?  Maybe there is an alternative to the problem itself!

[1]: https://opensips.org/Documentation/Script-CoreVar-3-4#socket_in
[2]: https://opensips.org/Documentation/Script-CoreVar-3-4#socket_out
[3]: https://www.opensips.org/Documentation/Script-Tran-3-4

Best regards,

-- 
Liviu Chircu
www.twitter.com/liviuchircu  |www.opensips-solutions.com
OpenSIPS eBootcamp 5-16 Dec |www.opensips.org/training
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20221116/7cb3dabe/attachment.html>


More information about the Users mailing list