<h3>Description</h3>
<p>Dispatcher destination attribute "socket", is not always respected.<br>
Syslog throws:</p>
<pre><code>ERROR: <core> [core/socket_info.c:2067]: parse_protohostport(): bad port number in udp:10.2.10.49:5064
</code></pre>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>relevant (I think) kamailio.cfg:</p>
<pre><code>listen=udp:127.0.0.1:5060        
listen=udp:10.2.10.49:5060
listen=udp:10.2.10.49:5064
listen=udp:10.2.10.49:5065
listen=udp:10.2.10.49:5066
auto_bind_ipv6=0
auto_aliases=0

modparam("dispatcher", "list_file", "/opt/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "dst_avp", "$avp(ds_dst)")
modparam("dispatcher", "grp_avp", "$avp(ds_grp)")
modparam("dispatcher", "cnt_avp", "$avp(ds_cnt)")
modparam("dispatcher", "dstid_avp", "$avp(ds_dstid)")
modparam("dispatcher", "ds_hash_size", 9)
modparam("dispatcher", "setid_pvname", "$var(ds_setid)")
modparam("dispatcher", "attrs_avp", "$avp(ds_attrs_dst)")
modparam("dispatcher", "attrs_pvname", "$avp(ds_attrs_from)")
modparam("dispatcher", "sock_avp", "$avp(ds_socket)")
modparam("dispatcher", "ds_default_socket", "udp:10.2.10.49:5066")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_interval", 10)
modparam("dispatcher", "ds_probing_mode", 3)
</code></pre>
<p>dispatcher.list:</p>
<pre><code>3 sip:127.0.0.1:1234;transport=udp 8 0 duid=abc;socket=udp:10.2.10.49:5064;pipe=p10
3 sip:127.0.0.1:1235;transport=udp 8 0 duid=abc;pipe=p10;socket=udp:10.2.10.49:5065
3 sip:127.0.0.1:1236;transport=udp 8 0 duid=abc;pipe=p10
</code></pre>
<p>Above kamailio.cfg and dispatcher.list demonstrates issue when probing (OPTIONS poll).<br>
I did not test actual request dispatching yet.</p>
<h4>Log Messages</h4>
<pre><code>20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2660]: ds_ping_set(): probing set #3, URI sip:127.0.0.1:1236;transport=udp
20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2674]: ds_ping_set(): >>>--- here2 - using default socket ---<<<
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:988]: request(): request
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:1027]: request(): uac_r->ssock==udp:10.2.10.49:5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2077]: lookup_local_socket(): lookup_local_socket() phostp==udp:10.2.10.49:5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:1978]: parse_protohostport(): parse_protohostport ins==udp:10.2.10.49:5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2082]: lookup_local_socket(): lookup_local_socket() grep_sock_info()
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==9 && [10.2.10.49] == [127.0.0.1]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5060 (advertise 0) matches port 5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5060 (advertise 0) matches port 5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5064 (advertise 0) matches port 5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5065 (advertise 0) matches port 5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5066 (advertise 0) matches port 5066
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:427]: t_uac_prepare(): next_hop=<sip:127.0.0.1:1236;transport=udp>
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:152]: dlg2hash(): hashid 37205
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:640]: send_prepared_request_impl(): uac: 0x802572e98  branch: 0  to 127.0.0.1:1236
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [./../../core/onsend.h:69]: run_onsend(): required parameters are not available - ignoring
20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2660]: ds_ping_set(): probing set #3, URI sip:127.0.0.1:1235;transport=udp
20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2670]: ds_ping_set(): >>>--- here1 - using destination specific socket ---<<<
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:988]: request(): request
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:1027]: request(): uac_r->ssock==udp:10.2.10.49:5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2077]: lookup_local_socket(): lookup_local_socket() phostp==udp:10.2.10.49:5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:1978]: parse_protohostport(): parse_protohostport ins==udp:10.2.10.49:5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2082]: lookup_local_socket(): lookup_local_socket() grep_sock_info()
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==9 && [10.2.10.49] == [127.0.0.1]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5060 (advertise 0) matches port 5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5060 (advertise 0) matches port 5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5064 (advertise 0) matches port 5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:564]: grep_sock_info(): checking if host==us: 10==10 && [10.2.10.49] == [10.2.10.49]
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:567]: grep_sock_info(): checking if port 5065 (advertise 0) matches port 5065
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:427]: t_uac_prepare(): next_hop=<sip:127.0.0.1:1235;transport=udp>
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:152]: dlg2hash(): hashid 37202
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:640]: send_prepared_request_impl(): uac: 0x802572148  branch: 0  to 127.0.0.1:1235
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [./../../core/onsend.h:69]: run_onsend(): required parameters are not available - ignoring
20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2660]: ds_ping_set(): probing set #3, URI sip:127.0.0.1:1234;transport=udp
20:26:37 freebsd11 kamailio[31694]: DEBUG: dispatcher [dispatch.c:2670]: ds_ping_set(): >>>--- here1 - using destination specific socket ---<<<
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:988]: request(): request
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:1027]: request(): uac_r->ssock==udp:10.2.10.49:5064
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2077]: lookup_local_socket(): lookup_local_socket() phostp==udp:10.2.10.49:5064
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:1978]: parse_protohostport(): parse_protohostport ins==udp:10.2.10.49:5064
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2020]: parse_protohostport(): B *tmp==;
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2024]: parse_protohostport(): Y looks like strtol() ran too far
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2026]: parse_protohostport(): ins->len  : 19
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2027]: parse_protohostport(): ins->s    : 0x80255fe88
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2028]: parse_protohostport(): first     : 0x80255fe8b
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2029]: parse_protohostport(): first+1   : 0x80255fe8c
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2030]: parse_protohostport(): second    : 0x80255fe96
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2031]: parse_protohostport(): second+1  : 0x80255fe97
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2032]: parse_protohostport(): ins s+len : 0x80255fe9b
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2033]: parse_protohostport(): tmp       : 0x80255fe9b
20:26:37 freebsd11 kamailio[31694]: ERROR: <core> [core/socket_info.c:2067]: parse_protohostport(): bad port number in udp:10.2.10.49:5064
20:26:37 freebsd11 kamailio[31694]: DEBUG: <core> [core/socket_info.c:2079]: lookup_local_socket(): lookup_local_socket() return NULL
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:427]: t_uac_prepare(): next_hop=<sip:127.0.0.1:1234;transport=udp>
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:152]: dlg2hash(): hashid 37203
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [uac.c:640]: send_prepared_request_impl(): uac: 0x8025713f8  branch: 0  to 127.0.0.1:1234
20:26:37 freebsd11 kamailio[31694]: DEBUG: tm [./../../core/onsend.h:69]: run_onsend(): required parameters are not available - ignoring
</code></pre>
<p>NOTE: above output contains additional debug statements, see below and <a href="https://github.com/kamailio/kamailio/commit/77394f06e8349de7565adcc58946da07ee0cf7d7" class="commit-link"><tt>77394f0</tt></a>.</p>
<h4>SIP Traffic</h4>
<pre><code>$ doas tcpdump -i lo0 -s 0 -n port 5060 or port 5064 or port 5065 or port 5066
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo0, link-type NULL (BSD loopback), capture size 262144 bytes
.
.
.
20:26:37.465870 IP 10.2.10.49.5066 > 127.0.0.1.1236: UDP, length 374
20:26:37.465885 IP 10.2.10.49.5065 > 127.0.0.1.1235: UDP, length 374
20:26:37.465894 IP 10.2.10.49.5060 > 127.0.0.1.1234: SIP: OPTIONS sip:127.0.0.1:1234;transport=udp SIP/2.0
20:26:37.968876 IP 10.2.10.49.5066 > 127.0.0.1.1236: UDP, length 374
20:26:37.969043 IP 10.2.10.49.5065 > 127.0.0.1.1235: UDP, length 374
20:26:37.969216 IP 10.2.10.49.5060 > 127.0.0.1.1234: SIP: OPTIONS sip:127.0.0.1:1234;transport=udp SIP/2.0
.
.
.
</code></pre>
<p>Summary of sent packets:<br>
src port 5066 == listener socket + dispatcher default socket<br>
src port 5065 == listener socket + explicitly set to destination 127.0.0.1:1235<br>
src port 5060 == listener socket, not mentioned in dispatcher config<br>
Probe packets to destination 127.0.0.1:1234 are sent with src port 5060, expected 5064.</p>
<h3>Possible Solutions</h3>
<p>Looks like <code>strtol(second+1, &tmp, 10)</code> in <code>core/socket_info.c</code> runs too far because it expects null terminated string but is passed <code>char*</code> of Kamailio <code>str</code> struct instead.<br>
Commit <a href="https://github.com/kamailio/kamailio/commit/77394f06e8349de7565adcc58946da07ee0cf7d7" class="commit-link"><tt>77394f0</tt></a> tries to highlights this.</p>
<h3>Additional Information</h3>
<p>Found initially in stable 5.0.2 with new configuration.<br>
Replicated in master (<a href="https://github.com/kamailio/kamailio/commit/20a961624bbe164d9120b7c9ac60df8ff1daaae4" class="commit-link"><tt>20a9616</tt></a>).</p>
<pre><code>version: kamailio 5.1.0-dev4 (x86_64/freebsd)
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, select, kqueue.
id: unknown
compiled on 19:21:12 Jun 21 2017 with clang39 3.9
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<p>FreeBSD 11</p>
<pre><code>$ uname -a
FreeBSD freebsd11 11.0-RELEASE-p9 FreeBSD 11.0-RELEASE-p9 #0: Tue Apr 11 08:48:40 UTC 2017     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1161">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZTW5sNGhUXh4O_BTXRKIA3GZpTqBks5sGWFtgaJpZM4OBWV5">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZRrr-4RISvYT9Dv2E25p2g_t7nI7ks5sGWFtgaJpZM4OBWV5.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/1161"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Dispatcher destination attribute \"socket\" does not always work (#1161)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1161"}}}</script>