<div dir="ltr"><div>In a nutshell, with TCP, it's the OS's network stack that assigns the port.</div><div><br></div><div>For more: <a href="https://lists.kamailio.org/pipermail/sr-users/2018-May/101529.html">https://lists.kamailio.org/pipermail/sr-users/2018-May/101529.html</a><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 29, 2020 at 4:00 PM Noah Mehl <<a href="mailto:noahmehl@gmail.com">noahmehl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div style="overflow-wrap: break-word;">Alex,</div><div style="overflow-wrap: break-word;"><br></div><div style="overflow-wrap: break-word;">Is there no way to send the requests from the listen port?<div><br></div><div>And if they’re not going to come from the listen port, can you please help me with the a way to update the message for the worker chosen rport?<br><div><br></div><div>~Noah<br><div><br><blockquote type="cite"><div>On Oct 29, 2020, at 3:37 PM, Alex Balashov <<a href="mailto:abalashov@evaristesys.com" target="_blank">abalashov@evaristesys.com</a>> wrote:</div><br><div><div dir="auto">Sorry to have missed your other question: <div><br></div><div>The “resource temporarily unavailable” is a normal occurrence in a nonblocking connect(), and nothing to worry about. </div><div><br></div><div>Unless the socket literally connects instantaneously, EAGAIN is what it’ll throw out when polled until connection is established.<br><br><div dir="ltr">—<div>Sent from mobile, with due apologies for brevity and errors.</div></div><div dir="ltr"><br><blockquote type="cite">On Oct 29, 2020, at 3:27 PM, Alex Balashov <<a href="mailto:abalashov@evaristesys.com" target="_blank">abalashov@evaristesys.com</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">Internally generated requests are a little quirky in that they’re generated by outside timer processes or tasks in core timers — activity that takes place outside the SIP worker pool. However, the expectation is that any replies will be processed (in this case, absorbed) by the SIP workers. <div><br></div><div>Asymmetric signalling is permitted in SIP, so sending from source port X while specifying a return port of Y in the top Via hop is perfectly acceptable.</div><div><br></div><div>— Alex<br><br><div dir="ltr">—<div>Sent from mobile, with due apologies for brevity and errors.</div></div><div dir="ltr"><br><blockquote type="cite">On Oct 29, 2020, at 3:21 PM, Noah Mehl <<a href="mailto:noahmehl@gmail.com" target="_blank">noahmehl@gmail.com</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">Hey all,<div><br></div><div>I’m a little stuck on an implementation of a set of dispatchers via TCP. There are some oddities about the behavior of the TCP source port of the Kamailio tcp worker/s, and maybe this is expected, but it doesn’t seem valid. For instance, I have a dispatcher:</div><div><br></div><div><span style="white-space:pre-wrap"> </span>"RECORDS":<span style="white-space:pre-wrap"> </span>[{<br><span style="white-space:pre-wrap"> </span>"SET":<span style="white-space:pre-wrap"> </span>{<br><span style="white-space:pre-wrap"> </span>"ID":<span style="white-space:pre-wrap"> </span>1,<br><span style="white-space:pre-wrap"> </span>"TARGETS":<span style="white-space:pre-wrap"> </span>[{<br><span style="white-space:pre-wrap"> </span>"DEST":<span style="white-space:pre-wrap"> </span>{<br><span style="white-space:pre-wrap"> </span>"URI":<span style="white-space:pre-wrap"> </span>“<a>sip:2.2.2.2:5060;transport=tcp</a>",<br><span style="white-space:pre-wrap"> </span>"FLAGS":<span style="white-space:pre-wrap"> </span>"AP",<br><span style="white-space:pre-wrap"> </span>"PRIORITY":<span style="white-space:pre-wrap"> </span>5<br><span style="white-space:pre-wrap"> </span>}<br><span style="white-space:pre-wrap"> </span>}]<br><span style="white-space:pre-wrap"> </span>}<br><span style="white-space:pre-wrap"> </span>}]</div><div><br></div><div>But when Kamailio sends an OPTIONS keep alive, the source port for the worker is 33940, and not 5060 (which is the TCP listen port), as received by Freeswitch:</div><div><br></div><div>recv 447 bytes from tcp/[1.1.1.1]:33940 at 18:58:24.958720:<br> ------------------------------------------------------------------------<br> OPTIONS <a>sip:2.2.2.2:5060;transport=tcp</a> SIP/2.0<br> Via: SIP/2.0/TCP 1.1.1.1;branch=z9hG4bK1525.80a9e442000000000000000000000000.0<br> To: <<a>sip:2.2.2.2:5060;transport=tcp</a>><br> From: <<a>sip:inbound-kamailio-01</a>>;tag=3c52ba62ee4c4621b9660728159919d3-cda8066f<br> CSeq: 10 OPTIONS<br> Call-ID: <a href="mailto:3aa18693487268dc-2790@1.1.1.1" target="_blank">3aa18693487268dc-2790@1.1.1.1</a><br> Max-Forwards: 70<br> Content-Length: 0<br> User-Agent: kamailio (5.4.2 (x86_64/linux))<br> <br> ------------------------------------------------------------------------<br><br></div><div>Also, I get weird debug messages when this tcp worker is spun up (specifically about Resource temporarily unavailable):</div><div><br></div><div>11(2790) DEBUG: dispatcher [dispatch.c:3340]: ds_ping_result_helper(): probe all, mode DS_PROBE_ALL<br>11(2790) DEBUG: dispatcher [dispatch.c:3383]: ds_ping_set(): probing set #1, URI <a>sip:2.2.2.2:5060;transport=tcp</a><br>11(2790) DEBUG: dispatcher [dispatch.c:3414]: ds_ping_set(): Default ping_from: <a>sip:inbound-kamailio-01</a><br>11(2790) DEBUG: dispatcher [dispatch.c:3424]: ds_ping_set(): Default outbound proxy: <br>11(2790) DEBUG: tm [uac.c:450]: t_uac_prepare(): next_hop=<<a>sip:2.2.2.2:5060;transport=tcp</a>><br>11(2790) DEBUG: tm [uac.c:158]: dlg2hash(): hashid 21073<br>11(2790) DEBUG: <core> [core/tcp_main.c:1993]: tcp_send(): no open tcp connection found, opening new one<br>11(2790) DEBUG: <core> [core/ip_addr.c:229]: print_ip(): tcpconn_new: new tcp connection: 2.2.2.2<br>11(2790) DEBUG: <core> [core/tcp_main.c:1175]: tcpconn_new(): on port 5060, type 2, socket -1<br>11(2790) DEBUG: <core> [core/tcp_main.c:1494]: tcpconn_add(): hashes: 2712:0:0, 1<br>11(2790) DEBUG: <core> [core/tcp_main.c:2886]: tcpconn_1st_send(): pending write on new connection 0x7f24e64c1e18 sock 8 (-1/447 bytes written) (err: 11 - Resource temporarily unavailable)<br>11(2790) DEBUG: tm [uac.c:678]: send_prepared_request_impl(): uac: 0x7f24e65285a8 branch: 0 to <a href="http://2.2.2.2:5060" target="_blank">2.2.2.2:5060</a><br>11(2790) DEBUG: <core> [core/onsend.c:50]: run_onsend(): required parameters are not available - ignoring<br>27(2806) DEBUG: <core> [core/tcp_main.c:3792]: handle_ser_child(): read response= 7f24e64c1e18, 5, fd 46 from 11 (2790)<br>27(2806) DEBUG: <core> [core/io_wait.h:375]: io_watch_add(): DBG: io_watch_add(0x56490f0f8060, 46, 2, 0x7f24e64c1e18), fd_no=37<br>27(2806) DEBUG: <core> [core/io_wait.h:782]: io_watch_chg(): DBG: io_watch_chg (0x56490f0f8060, 46, 0x1, 0xffffffff) fd_no=38 called<br>27(2806) DEBUG: <core> [core/io_wait.h:600]: io_watch_del(): DBG: io_watch_del (0x56490f0f8060, 46, -1, 0x0) fd_no=38 called<br>27(2806) DEBUG: <core> [core/tcp_main.c:4457]: handle_tcpconn_ev(): sending to child, events 1<br>27(2806) DEBUG: <core> [core/tcp_main.c:4127]: send2child(): selected tcp worker idx:0 proc:19 pid:2798 for activity on [tcp:<a href="http://1.1.1.1:5060" target="_blank">1.1.1.1:5060</a>], 0x7f24e64c1e18<br>19(2798) DEBUG: <core> [core/tcp_read.c:1749]: handle_io(): received n=8 con=0x7f24e64c1e18, fd=8<br>19(2798) DEBUG: <core> [core/tcp_read.c:1548]: tcp_read_req(): content-length=0<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:620]: parse_msg(): SIP Reply (status):<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:622]: parse_msg(): version: <SIP/2.0><br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:624]: parse_msg(): status: <200><br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:626]: parse_msg(): reason: <OK><br>19(2798) DEBUG: <core> [core/parser/parse_via.c:1303]: parse_via_param(): Found param type 232, <branch> = <z9hG4bK1525.80a9e442000000000000000000000000.0>; state=6<br>19(2798) DEBUG: <core> [core/parser/parse_via.c:1303]: parse_via_param(): Found param type 235, <rport> = <33940>; state=16<br>19(2798) DEBUG: <core> [core/parser/parse_via.c:2639]: parse_via(): end of header reached, state=5<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:498]: parse_headers(): Via found, flags=2<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:500]: parse_headers(): this is the first via<br>19(2798) DEBUG: <core> [core/parser/parse_addr_spec.c:185]: parse_to_param(): add param: tag=1mB9HryQ8ZBFc<br>19(2798) DEBUG: <core> [core/parser/parse_addr_spec.c:864]: parse_addr_spec(): end of header reached, state=29<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:171]: get_hdr_field(): <To> [59]; uri=[<a>sip:2.2.2.2:5060;transport=tcp</a>]<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:174]: get_hdr_field(): to body (39)[<<a>sip:2.2.2.2:5060;transport=tcp</a>>], to tag (13)[1mB9HryQ8ZBFc]<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:152]: get_hdr_field(): cseq <CSeq>: <10> <OPTIONS><br>19(2798) DEBUG: <core> [core/receive.c:319]: receive_msg(): --- received sip message - reply - call-id: [<a href="mailto:3aa18693487268dc-2790@1.1.1.1" target="_blank">3aa18693487268dc-2790@1.1.1.1</a>] - cseq: [10 OPTIONS]<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:185]: get_hdr_field(): content_length=0<br>19(2798) DEBUG: <core> [core/parser/msg_parser.c:89]: get_hdr_field(): found end of header</div><div><br></div><div>Are these SIP messages expected to come from other ports than the listen port (5060 in this case)? Also, if the worker source port is not 5060, shouldn’t the SIP message get updated with the correct port?</div><div><br></div><div>In the case of OPTIONS, Freeswitch is replying correctly to the source port: 33940.</div><div><br></div><div>However, in the case of an in dialog BYE, Freeswitch is NOT replying to the source port of the Kamailio messages, but only to port 5060. Here is an example (relayed from web sockets to freeswitch over TCP) INVITE (as received from Freeswitch):</div><div><br></div><div>recv 1481 bytes from tcp/[1.1.1.1]:33940 at 16:56:47.920698:<br> ------------------------------------------------------------------------<br> INVITE <a>sip:991012@sip.domain</a>.com SIP/2.0<br> Record-Route: <<a>sip:1.1.1.1;transport=tcp;r2=on;lr;nat=yes</a>><br> Record-Route: <<a>sip:1.1.1.1:5061;transport=tls;r2=on;lr;nat=yes</a>><br> Via: SIP/2.0/TCP 1.1.1.1;branch=z9hG4bKd408.3f53e940ccb20c1033df4b3a8ebd8a34.0;i=1<br> Via: SIP/2.0/TLS 172.22.199.110:55304;received=5.5.5.5;rport=39518;branch=z9hG4bKPj5Css6JomCt9Cli2cCINbXi4FbPM5wewG;alias<br> Max-Forwards: 69<br> From: "Noah Mehl" <<a>sip:5135555555@inbound-jail</a>>;tag=s3i3y2tiOCgnUId5TD4Vp0UChf9GyEy9<br> To: <<a>sip:991012@inbound-jail</a>><br> Contact: <<a>sip:74895612@172.22.199.110:54887;transport=tls;alias=5.5.5.5~39518~3</a>><br> Call-ID: 5aoRBMBHahxqSLzrIpFnlfRz.UcGsmfq<br> CSeq: 27271 INVITE<br> Allow: SUBSCRIBE, NOTIFY, INVITE, ACK, BYE, CANCEL, UPDATE, MESSAGE, REFER<br> Supported: replaces, norefersub, gruu<br> User-Agent: Blink Pro 4.6.0 (MacOSX)<br> Content-Type: application/sdp<br> Content-Length: 528<br> <br> v=0<br> o=- 3812979407 3812979407 IN IP4 5.5.5.5<br> s=Blink Pro 4.6.0 (MacOSX)<br> t=0 0<br> m=audio 50016 RTP/SAVP 113 0 101<br> c=IN IP4 5.5.5.5<br> a=rtcp:50017<br> a=rtpmap:113 opus/48000/2<br> a=fmtp:113 useinbandfec=1<br> a=rtpmap:0 PCMU/8000<br> a=rtpmap:101 telephone-event/8000<br> a=fmtp:101 0-16<br> a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:UhHq6hth9HqALmiJ3AEeoGkixObBzkLURG60wJKT<br> a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:VKYaSCVwgvXCPaRvudTrgLORhWmOA7wyDJVeGjcu<br> a=sendrecv<br> a=oldmediaip:172.22.199.110<br> a=oldmediaip:172.22.199.110<br> ------------------------------------------------------------------------<br><br></div><div>This doesn’t seem valid, as the top Via doesn’t have a port specified?</div><div><br></div><div>For reference, just rebuilt form the 5.4 branch today:</div><div><br></div><div>commit 62dff5b8b157236cae7defe64291a6e4a8ae27b5 (upstream/5.4)<br>Author: Kamailio Dev <<a href="mailto:kamailio.dev@kamailio.org" target="_blank">kamailio.dev@kamailio.org</a>><br>Date: Wed Oct 28 20:16:28 2020 +0100<br><br> modules: readme files regenerated - modules ... [skip ci]<br><br></div><div>Thanks!</div><div><br></div><div>~Noah</div><div><br></div><span>_______________________________________________</span><br><span>Kamailio (SER) - Users Mailing List</span><br><span><a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a></span><br><span><a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a></span><br></div></blockquote></div></div></blockquote></div></div>_______________________________________________<br>Kamailio (SER) - Users Mailing List<br><a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br><a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br></div></blockquote></div><br></div></div></div></div>_______________________________________________<br>
Kamailio (SER) - Users Mailing List<br>
<a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote></div>