Extract the IP address in iRule from ADDITIONAL SECTION response in DNS query
Hi,
I have a piece of code in iRule triggering a DNS query on a VS as follows :
set original_fqdn [findstr $RouteValue "sip:N" 4 ";"] if {$static::debug} {log local0.info "fqdn = $original_fqdn "}
set resolved_ip 0
set resolved_ip [RESOLV::lookup @/Common/iDNS__vs -naptr $original_fqdn]
if {$static::debug} {log local0.info "Checking $original_fqdn and NAME::response: $resolved_ip"}
set _ipaddress [lindex $resolved_ip 0]
The problem I have with this code is that it does not capture the right IP address, since they are in the ADDITIONAL SECTION
root@TBNHPVF5103-33:/S1-green-P:Active:Changes Pending] config dig -t naptr @172.16.16.4 NBG-ESCT.ims.telekom.de
; <<>> DiG 9.9.8-P4 <<>> -t naptr @172.16.16.4 NBG-ESCT.ims.telekom.de ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30400 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 8
;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;NBG-ESCT.ims.telekom.de. IN NAPTR
;; ANSWER SECTION: nbg-esct.ims.telekom.de. 100 IN NAPTR 110 50 "s" "SIP+D2T" "" _sip._tcp.NBG-ESCT.ims.telekom.de.
;; AUTHORITY SECTION: ims.telekom.de. 86400 IN NS nbg-edit712--gep-m0-s5.ims.telekom.de.
;; ADDITIONAL SECTION: nbg-esct711.ims.telekom.de. 100 IN A 37.50.134.26 nbg-esct721.ims.telekom.de. 100 IN A 37.50.134.18 nbg-esct751.ims.telekom.de. 100 IN A 80.149.128.17 nbg-edit712--gep-m0-s5.ims.telekom.de. 100 IN A 37.50.134.108 _sip._tcp.nbg-esct.ims.telekom.de. 100 IN SRV 0 10 5060 NBG-ESCT751.ims.telekom.de. _sip._tcp.nbg-esct.ims.telekom.de. 100 IN SRV 0 10 5060 NBG-ESCT711.ims.telekom.de. _sip._tcp.nbg-esct.ims.telekom.de. 100 IN SRV 0 10 5060 NBG-ESCT721.ims.telekom.de.
;; Query time: 8 msec ;; SERVER: 172.16.16.453(172.16.16.4) ;; WHEN: Thu May 31 19:43:06 CEST 2018 ;; MSG SIZE rcvd: 408
The variable I extract is wrong :
110 50 s SIP+D2T {} _sip._tcp.NBG-ESCT.ims.telekom.de instead of the actual IP address. I guess my lindex syntax is wrong here, but I am not sure...