### Description
I tried to set the `alias` configuration option using an ID set by `#!substdef` but this leads to `grep_sock_info()` to fail, falling back to `corex_check_self()` and failing altogether finally.
### Troubleshooting
#### Reproduction
The basic setup given `BASE_HOST=example.org`:
``` #!substdef "/BASE_HOST/$env(BASE_HOST)/"
alias="BASE_HOST"
listen=tcp:0.0.0.0:80
route[AUTH] { # ... if (from_uri!=myself && uri!=myself) { sl_send_reply("403","Not relaying"); exit; }
return; } ```
With this, any properly authenticated `REGISTER` call leads to a `403 Not Relaying`.
However, this works perfectly fine if I use a static value instead:
``` alias=example.org ```
#### Log Messages
``` kamailio_1 | 12(17) DEBUG: <core> [core/socket_info.c:628]: grep_sock_info(): checking if host==us: 11==7 && [example.org] == [0.0.0.0] kamailio_1 | 12(17) DEBUG: <core> [core/socket_info.c:635]: grep_sock_info(): checking if port 80 (advertise 0) matches port 5060 kamailio_1 | 12(17) DEBUG: <core> [core/forward.c:412]: check_self(): host != me kamailio_1 | 12(17) DEBUG: corex [corex_lib.c:200]: corex_check_self(): check self for: 0:example.org:5060 kamailio_1 | 12(17) DEBUG: corex [corex_lib.c:227]: corex_check_self(): no match found kamailio_1 | 12(17) DEBUG: <core> [core/socket_info.c:628]: grep_sock_info(): checking if host==us: 11==7 && [example.org] == [0.0.0.0] kamailio_1 | 12(17) DEBUG: <core> [core/socket_info.c:635]: grep_sock_info(): checking if port 80 (advertise 0) matches port 5060 kamailio_1 | 12(17) DEBUG: <core> [core/forward.c:412]: check_self(): host != me kamailio_1 | 12(17) DEBUG: corex [corex_lib.c:200]: corex_check_self(): check self for: 0:example.org:5060 kamailio_1 | 12(17) DEBUG: corex [corex_lib.c:227]: corex_check_self(): no match found ```
Output with the static value:
``` kamailio_1 | 11(16) DEBUG: <core> [core/socket_info.c:628]: grep_sock_info(): checking if host==us: 11==7 && [example.org] == [0.0.0.0] kamailio_1 | 11(16) DEBUG: <core> [core/socket_info.c:635]: grep_sock_info(): checking if port 80 (advertise 0) matches port 5060 kamailio_1 | 11(16) DEBUG: <core> [core/socket_info.c:628]: grep_sock_info(): checking if host==us: 11==7 && [example.org] == [0.0.0.0] kamailio_1 | 11(16) DEBUG: <core> [core/socket_info.c:635]: grep_sock_info(): checking if port 80 (advertise 0) matches port 5060 ```
### Possible Solutions
Right now I need to work around this issue by including a separate `kamailio-aliases.cfg` file which must then be provided in each environment.
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` version: kamailio 5.3.3 (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_BLACKLIST, 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 5.3.1
```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `uname -a`) -->
Using the Docker image `kamailio/kamailio:5.3.3-xenial`. Info from the Docker host:
``` # uname -a Linux ubuntu-s-1vcpu-1gb-fra1-01-sip 4.4.0-177-generic #207-Ubuntu SMP Mon Mar 16 01:16:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux # lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial ```
Aliases and sockets have a special grammar to get their value, given the combination of protocols/addresses/interface name/ports and associated addresses. Subst preprocessor works on string values and define on standalone ids.
What do you get for:
``` kamctl rpc core.aliases_list ```
This is what I get:
```json { "jsonrpc": "2.0", "result": { "myself_callbacks": "no", "aliases": [{ "alias": { "proto": "*", "address": "example.org", "port": "*" } }] }, "id": 24 }
```
The list of aliases seems ok, the address is the value of the environment variable, unless you got the `kamctl rpc core.aliases_list` for the config with static alias value.
If you got it with the config using env variable, do it with the master branch and debug=3 in kamailio.cfg, then send the log debug messages when matching the myself. I just pushed a commit to print more details when matching the aliases list. It should reveal what is compared.
I just tested with this configuration file:
``` #!KAMAILIO
debug=2 children=2
listen=udp:0.0.0.0:8280
loadmodule "pv.so" #!substdef "/BASE_HOST/$env(BASE_HOST)/"
alias="BASE_HOST"
loadmodule "jsonrpcs.so" loadmodule "sl.so" loadmodule "corex.so" loadmodule "kex.so"
request_route { # ... if (uri!=myself) { sl_send_reply("403","Not relaying"); exit; } sl_send_reply("200", "OK");
exit; } ```
Then:
``` export BASE_HOST=lab01.asipto.com ```
Started kamailio and used sipsak to push a request:
``` sipsak -p 127.0.0.1 -r 8280 -s sip:lab01.asipto.com -vvv ```
And I got 200ok, so myself matched, logs showing that as well:
``` 1(19850) DEBUG: <core> [core/parser/msg_parser.c:152]: get_hdr_field(): cseq <CSeq>: <1> <OPTIONS> 1(19850) DEBUG: <core> [core/receive.c:324]: receive_msg(): --- received sip message - request - call-id: [2107224131@192.168.178.75] - cseq: [1 OPTIONS] 1(19850) DEBUG: <core> [core/receive.c:379]: receive_msg(): preparing to run routing scripts... 1(19850) DEBUG: <core> [core/socket_info.c:646]: grep_sock_info(): checking if host==us: 20==7 && [lab01.asipto.com] == [0.0.0.0] 1(19850) DEBUG: <core> [core/socket_info.c:649]: grep_sock_info(): checking if port 8280 (advertise 0) matches port 5060 1(19850) DEBUG: <core> [core/name_alias.h:64]: grep_aliases(): matching (0:lab01.asipto.com:5060) vs. (0:lab01.asipto.com:0) 1(19850) DEBUG: <core> [core/forward.c:422]: check_self(): host (0:lab01.asipto.com:5060) == me ```
I used master for seend the debug messages, but the alias value is taken in cosideration via the environment variable. Closing this one, if still an issue, reopen and provide the logs with latest master branch.
Closed #2310.
Thanks for the followup. I'll try this as soon ASAP. (Currently in a sprint.)
I finally was able to have another look at this and it works just fine now. Thanks a lot for your help!