Forum Discussion

Dave_Wu_20200's avatar
Dave_Wu_20200
Icon for Nimbostratus rankNimbostratus
Dec 09, 2011

Rate Shaping using url and ip address

Hi Guys,

 

I am attempting to write a irule to shape bandwidth by using source ip address xxx.xxx.xxx.xxx and host of xyz.com.

 

Could I use something like that

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "XYZ.com" && [IP::client_addr] == xxx.xxx.xxx.xxx }

 

{

 

rateclass rateshape1

 

}

 

}

 

 

Is my code correct?

 

 

Thanks in advance

 

 

  • Hi Dave,

    Just a couple of small suggestions. Set the host to lower case as it should be matched case insensitively. Also, using an equals operator like == or eq would (eventually) do a string comparison. A bitwise comparison with IP::addr will be more efficient and support CIDR.

    http://devcentral.f5.com/wiki/iRules.ip__addr.ashx

    when HTTP_REQUEST {
       if { [string tolower [HTTP::host]] equals "xyz.com" && [IP::addr [IP::client_addr] equals xxx.xxx.xxx.xxx] }
          rateclass rateshape1     
       }
    }

    Aaron