Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

URL and IP check iRule

Moayad_Hamdan_3
Nimbostratus
Nimbostratus

Hi all i have the following code:

when CLIENT_ACCEPTED {
  set poolDefault [LB::server pool] 
} 
when HTTP_REQUEST {
  set path [string tolower [HTTP::path]]
  if { $path contains "/g2b"} {
    pool G2B_Pool
  } elseif { $path contains "/portal/g2c"} {
      pool G2C_Pool
  } else {pool B2B_Pool}
}

i want to add this----->elseif { $path contains "/_layout/15"} and (IP=10.10.10.10 or ip=10.10.10.11) {pool G2b_Pool}

how to add it in the code?

1 ACCEPTED SOLUTION

VernonWells
F5 Employee
F5 Employee

 

when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "*/g2b*" { pool G2B_Pool }
        "*/portal/g2c*" { pool G2C_Pool }
        "*/_layout/15*" {
            if { [IP::client_addr] matches_glob "10.10.10.1\[01\]" } {
                pool G2B_Pool
            }
        }
    }
}

 

I removed the CLIENT_ACCEPTED code because, unless poolDefault is actually utilized elsewhere. I also removed the default branch (the else clause in the original code). If the pool associated with the Virtual Server is already set to B2B_Pool, then the default branch is redundant. Finally, I removed the string tolower for the path. Whether it makes sense depends on the path semantics for the webserver. See the Analysis section in this recipe for more details:

View solution in original post

5 REPLIES 5

VernonWells
F5 Employee
F5 Employee

 

when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "*/g2b*" { pool G2B_Pool }
        "*/portal/g2c*" { pool G2C_Pool }
        "*/_layout/15*" {
            if { [IP::client_addr] matches_glob "10.10.10.1\[01\]" } {
                pool G2B_Pool
            }
        }
    }
}

 

I removed the CLIENT_ACCEPTED code because, unless poolDefault is actually utilized elsewhere. I also removed the default branch (the else clause in the original code). If the pool associated with the Virtual Server is already set to B2B_Pool, then the default branch is redundant. Finally, I removed the string tolower for the path. Whether it makes sense depends on the path semantics for the webserver. See the Analysis section in this recipe for more details:

Hi Vernon

 

actually i am using default pool to redirect the traffic hitting the default URL (without /g2b or /g2c)

 

i want to add other condition for "/_layout/15" to check if ip= 10.10.10.61 or 10.10.10.63 then will redirect the traffic to pool g2c.

 

VernonWells
F5 Employee
F5 Employee

That's the reason for omitting the default branch: if a Request Target matches none of the conditions, then the default pool will automatically be used.

For the newest addition:

 

when HTTP_REQUEST {
    switch -glob [HTTP::path] {
        "*/g2b*" { pool G2B_Pool }
        "*/portal/g2c*" { pool G2C_Pool }
        "*/_layout/15*" {
            switch [IP::client_addr] {
                "10.10.10.10" -
                "10.10.10.11" { pool G2B_Pool }
                "10.10.10.61" -
                "10.10.10.63" { pool G2C_Pool }
            }
        }
    }
}

 

the ip address which i want to check is a response server ip address not the client.

 

after load balancer redirect the traffic to pool1 or pool2 , member servers of these two pools which are sharepoint servers are returning a url request to loadbalancer /_layout/15

 

load balancer will not redirect the traffic to correct pool , he will direct it to default pool because he can't detect \g2b or \g2c path.

 

i was thinking to make load balancer check the requester server ip and direct the traffic to correct pool.

 

i need load balancer to check both url and ip as all sharepoint servers in both pools will return the same url , load balancer should check the ip as well to direct the traffic correctly..

 

VernonWells
F5 Employee
F5 Employee

It sounds to me like you want to use persistence. Let's say that a client goes to /_layout/15 and the client IP is 10.10.10.10. Given the code above, pool G2B_Pool is selected. On a subsequent request from the same client, assuming some arbitrarily different Request Target, the default pool would be used. If you wish for this client to again use the same pool member selected in G2B_Pool, a persistence profile would accomplish this. For HTTP transactions, in general, Cookie Persistence makes the most sense.