Forum Discussion

PhillyPDXMike's avatar
PhillyPDXMike
Icon for Altocumulus rankAltocumulus
Nov 20, 2020
Solved

What is the syntax equivalent of RESOLV::lookup with the RESOLVER::name_lookup command?

With RESOLV::lookup being deprecated as of version 15.1 in favor of the RESOLVER and DNSMSG namespaces, I am not finding detailed enough documentation and examples to convert my 14.1 iRule to the new...
  • JRahm's avatar
    Nov 20, 2020

    I wrote a gist to cover this, but also, a peer of mine, Paul, has a more complete solution in BUG 931149 (make sure you have a working net resolver in tmsh):

    proc resolv_ptr_v4 { addr_v4 } {
        # Convert $addr_v4 into its constituent bytes
        set ret [scan $addr_v4 {%d.%d.%d.%d} a b c d]
        if { $ret != 4 } {
            return
        }
     
        # Perform a PTR lookup on the IP address $addr_v4, and return the first answer
        set ret [RESOLVER::name_lookup "/Common/resolver-for-irules" "$d.$c.$b.$a.in-addr.arpa" PTR]
        set ret [lindex [DNSMSG::section $ret answer] 0]
        if { $ret eq "" } {
            # log local0.warn "DNS PTR lookup for $addr_v4 failed."
            return
        }
     
        # Last element in '1.1.1.10.in-addr.arpa.  600    IN      PTR     otters.example.com'
        return [lindex $ret end]
    }
     
    -- In an iRule, instead of:
        RESOLV::lookup @192.88.9.1 $ipv4_addr
    Use:
        call resolv_ptr_v4 $ipv4_addr

    For consistency across all record types, I'm going to flesh out that proc in the next few days so you can use the proc to pass the query and the query type so you don't have to have different logic in your main iRule just for PTR records.