For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Shiraz's avatar
Shiraz
Icon for Altostratus rankAltostratus
Dec 12, 2016

Combining Two irules as one irule

Dears,

Any idea on combing the below two irules as one irule.

       when HTTP_REQUEST {
   if { ([IP::addr [client_addr] equals 12.x.x.0/24]) and ([HTTP::uri] contains "/something") } {
       pool something_http_pool
} else {
  if { ([IP::addr [client_addr] equals 12.xx.x.x/21]) and ([HTTP::uri] contains "/something") } {
       pool something_http_pool
} elseif { ([HTTP::uri] contains "/something") } {
  log "_discard_something"
   discard
}
}
}

and

when HTTP_REQUEST {
  switch [HTTP::host] {
    "http-abc.xyz.com" {
      pool http_api_abc_test_pool
    }
    "webportal-abc.xyz.com" {
      pool webportal_abc_test_pool
    }
    "abc.xyz.com" {
      pool abc_test_pool
    }
    "two-abc.xyz.com" {
      pool two_way_abc_test_pool
    }
    "xml-api-abc.xyz.com" {
      pool xml_abc_test_pool
    }
    "smpp-abc.xyz.com" {
      pool smpp_abc_test_pool
    }
  }
}

Regards

2 Replies

  • You can try this by creating 2 datagroups - CLASS_NETWORK with 12.x network and CLASS_DOMAIN_POOL that has the domain name as the "key" and the corresponding pool as the "value":

    when CLIENT_ACCEPTED {
    set DEFAULT [LB::server pool]
    }
    
    when HTTP_REQUEST {
    
    if { ([HTTP::uri] contains "/something") } {
        if { ([class match [IP::client_addr] equals CLASS_Network]) } {
            pool something_http_pool
        } else {
            log local0. "_discard_something"
            discard
        }
    
    } elseif { [class match [HTTP::host] eq CLASS_DOMAIN_POOL] } {
         set POOL_SELECTED [class match -value [HTTP::host] contains CLASS_DOMAIN_POOL] 
         pool $POOL_SELECTED
    
    } else {
        pool $DEFAULT
    } 
    }
    

    I have never used "switch" within an if-statement but you can try to see if this will work by using "switch" within the "else" :

    when HTTP_REQUEST {
    
    if { ([HTTP::uri] contains "/something") } {
        if { ([class match [IP::client_addr] equals CLASS_Network]) } {
            pool something_http_pool
        } else {
            log local0. "_discard_something"
            discard
        }
    
    } else {
      switch [HTTP::host] {
        "http-abc.xyz.com" { pool http_api_abc_test_pool }
        "webportal-abc.xyz.com" { pool webportal_abc_test_pool }
        "abc.xyz.com" { pool abc_test_pool }
        "two-abc.xyz.com" { pool two_way_abc_test_pool }
        "xml-api-abc.xyz.com" { pool xml_abc_test_pool } 
        "smpp-abc.xyz.com" { pool smpp_abc_test_pool }
       }
    }
    }
    
  • Thanks Odaah,

     

    The second irule provided by you worked for me.

     

    Regards...