<p></p>

<h3>Description</h3>
<p>I wanted to change 478 response to 503 in case of t_relay() failure, but leave default behavior in rest error cases. I used part of code from "Example 1.1." inside <a href="https://www.kamailio.org/docs/modules/devel/modules/outbound.html" rel="nofollow">https://www.kamailio.org/docs/modules/devel/modules/outbound.html</a>. When I get -478 from t_relay() it works fine, but when this code is different sl_reply_erorr() don't use it as it should be.</p>
<p>This is my part of kamailio.cfg:</p>
<pre><code>route[RELAY] {
    if (!t_relay()) {
        switch($rc) {
            case -478:
                xlog("L_WARN","T_Relay returned 478, sending back 503.\n");
                sl_send_reply("503", "Service Unavailable");
                exit;
            default:
                sl_reply_error();
                exit;
        }
    }
    exit;
}
</code></pre>
<p>When I log $rc value before sl_reply_error() it is valid, but not used by sl_reply_error() as SIP error value, it sends 500 instead.</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>I've added incorrect hostnames with flag 16 to set where the message should be sent and t_relay() returns -478. To check the default case inside switch I changed case -478 to -479.</p>
<h4>Log Messages</h4>

<pre><code>1(8) ERROR: <core> [core/resolve.c:1731]: sip_hostport2su(): could not resolve hostname: "va4brhino"
 1(8) ERROR: tm [ut.h:309]: uri2dst2(): failed to resolve "va4brhino"
 1(8) ERROR: tm [t_fwd.c:1759]: t_forward_nonack(): failure to add branches
 1(8) ERROR: sl [sl_funcs.c:414]: sl_reply_error(): stateless error reply used: I'm terribly sorry, server error occurred (1/SL)
</code></pre>
<p>Logs with different route relay</p>
<pre><code>route[RELAY] {
    if (!t_relay()) {
        switch($rc) {
            case -479:
                xlog("L_WARN","T_Relay returned 479, sending back 503.\n");
                sl_send_reply("503", "Service Unavailable");
                exit;
            default:
                xlog("L_WARN","Return code: $rc\n");
                sl_reply_error();
                exit;
        }
    }
    exit;
}
</code></pre>
<pre><code> 1(8) ERROR: <core> [core/resolve.c:1731]: sip_hostport2su(): could not resolve hostname: "va4brhino"
 1(8) ERROR: tm [ut.h:309]: uri2dst2(): failed to resolve "va4brhino"
 1(8) ERROR: tm [t_fwd.c:1759]: t_forward_nonack(): failure to add branches
 1(8) WARNING: <script>: Return code: -478
 1(8) ERROR: sl [sl_funcs.c:414]: sl_reply_error(): stateless error reply used: I'm terribly sorry, server error occurred (1/SL)
</code></pre>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.5.0 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_
DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 4.8.4
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>Linux v4bkamailio 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
</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/2802">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZMUIQJIUIETSC2VN2TTYWAV5ANCNFSM5AV42Z5A">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZKCW6EEHZ6ZW5OYRYTTYWAV5A5CNFSM5AV42Z5KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OEMBWSA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2802",
"url": "https://github.com/kamailio/kamailio/issues/2802",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>