Forum Discussion

SK391_339749's avatar
SK391_339749
Icon for Nimbostratus rankNimbostratus
Nov 27, 2018

Understanding IRules and Syntax

Hi, I'm reading the irule 101 article series. Just wanted some help with the basic understanding of how the irules are structured together.

 

For example would someone be able to break down the following syntax into its basic core components please. I'm trying to understand how it all links together. I'm not a programmer so I've very limited experience with any languages but happy to put some time investment to help me understand.

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::header exists "x-forwarded-for"]] } { log local0. "XFF_HEADER=[HTTP::header values "X-Forwarded-For"] " }

 

What is this irule actually doing?

 

When the HTTP Request some in the F5 takes the HTTP::header and makes it lower case? What does the ' :: ' actually mean ? Is the irule checking to see if an X-forwarded-for exists in the HTTP::header if it does, does it log it to the local log file ( /var/log/ltm ) with a starting statement of XFF header.

 

How do I know where to add in all the [] and {} I'm getting confused with it all and any help would be brilliant.

 

Thanks in advance.

 

1 Reply

  • when LTM receive a HTTP Request, do the following code

    when HTTP_REQUEST {

    execute the command HTTP::header exists "x-forwarded-for"

    Inserting this command between brackets allow to retreive the result of the command.

    the command [HTTP::header exists "x-forwarded-for"] will return 0 if doesn't exist (for false), 1 if exist (for true)

    Then [string tolower [HTTP::header exists "x-forwarded-for"]] convert the result of command to lowercase... doesn't make sense because lowercase of a number stay the same...

    and finally, if the result is a number different than 0, execute the code between curly brackets

    if { [string tolower [HTTP::header exists "x-forwarded-for"]] } {

    log in /var/log/ltm the line XFF_HEADER=W.X.Y.Z where W.X.Y.Z is the value of HTTP header X-Forwarded-For

    log local0. "XFF_HEADER=[HTTP::header values "X-Forwarded-For"] " } }