When trying to use the pseudovar $dns(xyz=>addr[0]) Kamailio script parser complains there is a syntax error and script won't start. However if a variable with value 0 is used, it works.
There is no reason why one should not access those indexes directly using the value 0.
Piece of code that does not work:
if(dns_query("$rd", "ddst")) {
$var(dest_ip) = $dns(ddst=>addr[0]); # We just need first IP
}
Piece of code that works:
if(dns_query("$rd", "ddst")) {
$var(i) = 0;
$var(dest_ip) = $dns(ddst=>addr[$var(i)]); # We just need first IP
}
I tried using the 0 with quotes, but no luck. I had to use a variable to access the index 0.
I have not tried the "type" attribute, maybe same problem can happen with it.
Try adding this piece of code to the script:
if(dns_query("$rd", "ddst")) {
$var(dest_ip) = $dns(ddst=>addr[0]); # We just need first IP
}
This will output this error when running kamailio -c:
0(22439) ERROR: ipops [ipops_pv.c:249]: pv_parse_dns_name(): invalid index [ddst=>addr[0]]
0(22439) ERROR: ipops [ipops_pv.c:261]: pv_parse_dns_name(): error at PV dns name: ddst=>addr[0]
0(22439) ERROR: <core> [core/pvapi.c:952]: pv_parse_spec2(): pvar "dns" has an invalid name param [ddst=>addr[0]]
0(22439) ERROR: <core> [core/pvapi.c:1107]: pv_parse_spec2(): wrong char [)/41] in [$dns(ddst=>addr[0])] at [18 (5)]
0(22439) CRITICAL: <core> [core/cfg.y:3508]: yyerror_at(): parse error in config file /etc/kamailio/routing.cfg, line 2398, column 20-38: Can't get from cache: $dns(ddst=>addr[0])
Instead of direct index access with integer values, it is necessary to access it with a variable.
kamailio -v
# kamailio -v
version: kamailio 5.2.2 (x86_64/linux) 67f967
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, 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: 67f967
compiled on 11:40:41 Mar 11 2019 with gcc 4.8.5
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.