Forum Discussion

Jon_46219's avatar
Jon_46219
Icon for Nimbostratus rankNimbostratus
May 06, 2010

Cath error and print virtual server

I have an Irule where I execute: "HTTP::header insert X-Forwarded-For..." and sometimes I get an error.

 

 

I have this irule applied in serveral virtual servers so I don't know in which one is happening the problem.

 

 

It's possible to print the virtual server's name when error happens?

 

 

Thanks.

2 Replies

  • This would be the closest I can think of without writing a custom iRule for each Virtual Server.

    This will give you the Host / URL that caused the iRule to be executed:

    
     when HTTP_REQUEST {
    HTTP::header insert X-Forwarder-For [IP::client_addr]
    log local0. "X-Forwarded for:  [HTTP::host]"
    }
    

    If you wanted to do this for something that is highly specific for each Virtual Server you could do this:

    
     when HTTP_REQUEST {
    HTTP::header insert X-Forwarder-For [IP::client_addr]
    log local0. "X-Forwarded for:  My Virutal Server Name"
    }
    

    You can also do X-Forwarder Inserts with an HTTP Profile instead of an iRule if that is something that interests you.

    Create a Custom HTTP Profile based on the default and set these options:

    Request Header Insert - X-Forwarded-For:true

    Insert XForwarded For - Enabled

    We actually set the "Maximum Header Size" option as well.
  • I agree with Michael that inserting the XFF header using a custom HTTP profile is simpler, more efficient and won't be susceptible to this issue. If you did want to get more information from the iRule, you could log the virtual server name before attempting the header insert. This way you're sure to get the debug logging before the runtime TCL error occurs. Also, you can use the virtual command to log the virtual server name:

    http://devcentral.f5.com/wiki/default.aspx/iRules/virtual

    
    when HTTP_REQUEST {
       log local0. "[IP::client_addr]:[TCP::client_port]: Inserting X-Forwarded-For for [virtual name]"
       HTTP::header insert X-Forwarder-For [IP::client_addr]
    }
    

    The actual TCL error is probably caused by a conflict between an iRule redirect and header insert. If you do need to use an iRule to do the header insert and you're doing a redirect in the same or another iRule, you can add logic to prevent both the redirect and header insert from triggering on the same HTTP request.

    Aaron