Forum Discussion

Marco_Lei's avatar
Marco_Lei
Icon for Altostratus rankAltostratus
Nov 29, 2018

Create iRule condition refers to a set of data (strings)

So I'm creating an iRule on DNS Listener that, when external ip (IP not in 172.16.0.0/12) query specific domain name (such as "abctest.example.com") , stop the query and reply the DNS query by NXDomain. Following scripts works well:

when DNS_REQUEST {
    if  { [DNS::question name] contains "abctest.example.com" && ![IP::addr [IP::client_addr] equals 172.16.0.0/12]} {
        DNS::header rcode NXDOMAIN
        DNS::return
    }
}

Beyond this, there's more than 1 (actually quite a few) domain name that need to perform such action. i. e. all below domain queried by external IP shall be returned by NXDomain:

  1. "abctest.example.com"
  2. "deftest.test.com"
  3. "abctest.foobar.com"
  4. "abctest.barfoo.com"
  5. "exampleabc.foo.com"

I would like to know if there's any efficient method to write such iRule conditions, other than copy the same condition parameters several times.

  • You can search in the list

    when DNS_REQUEST {
        set filter_list {"abctest.example.com" "deftest.test.com" "abctest.foobar.com" "abctest.barfoo.com" "exampleabc.foo.com"}
        if  { [lsearch -exact $filter_list [DNS::question name]] ne -1 && ![IP::addr [IP::client_addr] equals 172.16.0.0/12]} {
            DNS::header rcode NXDOMAIN
            DNS::return
        }
    }