Forum Discussion

Eric_27859's avatar
Eric_27859
Icon for Nimbostratus rankNimbostratus
Jul 29, 2011

X-Forwarded-For and Route Domains issue with '%'

Hello,

 

 

I'm using the header X-Forwarded-For to tell the server the remote client IP (using AutoMap in the Virtual Server). When a Route Domain is involved, all the IPs are written with this format "IP%RouteDomainID". I've searched in the Wiki for IP::client_addr and the IP::addr ussage and didn't found how to extract in an easy manner the IP without the Route Domain. I also tried to use TCL string last, string trim and another string functions but without success.

 

 

Would you give me a hint about how should I get only the IP without the route domain?

 

 

Thank you in advance!

 

10 Replies

  • Hi Eric,

     

    You can do this in an irule. Specifically split command with a string and scan command. You can find these commands on the following link http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm

     

     

     

    I hope this helps,

     

    Bhattman

     

     

  • I assume you want the X-Forwarded-For address updated yes? Try this and let me know how it goes.

     

     

    when HTTP_REQUEST {

     

    HTTP::header replace {X-Forwarded-For} [ getfield [HTTP::header {X-Forwarded-For}] {%} 1 ]

     

    }
  • I assume you want the X-Forwarded-For address updated yes? Try this and let me know how it goes.

     

     

    when HTTP_REQUEST {

     

    HTTP::header replace {X-Forwarded-For} [ getfield [HTTP::header {X-Forwarded-For}] {%} 1 ]

     

    }
  • HI Jarvil,

     

    Yes sorry about that. I, for some reason, misunderstood your question.

     

     

    Yes your correct taht HTTP::header command along with getfield will work

     

     

    Here is the typical code where you insert the field instead of replace it

     

     

    
    when HTTP_REQUEST {
          HTTP::header insert X-Forwarded-For [getfield [IP::client_addr] "%" 1]
    }
    

     

     

     

    Bhattman

     

  • Hi Bhattman,

     

     

    If he is already using the header X-Forwarded-For tcp profile option as stated, wouldn't the HTTP::header insert leave him with a duplicate header?

     

     

    Regards

     

     

    Jarvil

     

     

  • Hi Jarvil,

     

    Good question. I never tested it with the option turned on so, I suppose either you see 2 values or just one.

     

     

     

    Bhattman
  • You will see two X-Forwarded-For values as I just tested it. So the best solution is likely...

     

     

    when HTTP_REQUEST {

     

    HTTP::header replace X-Forwarded-For [getfield [IP::client_addr] "%" 1]

     

    }

     

  • Sorry about my absence.

     

     

    The key about my problem is "getfield" command that I wasn't aware of. I need to insert the HTTP header X-Forwarded-For, but as Jarvil pointed right, maybe this header is coming yet within the original request arriving to F5. In that case I would rather replace the header value.

     

     

    If the server log supports it, I will concatenate the arriving X-Forwarded-For value with the new one, separating with a coma, but I think that this maybe is not necessary regarding the actual server logs.

     

     

    Thank you all for your help!!
  • Sorry about my absence.

     

     

    The key about my problem is "getfield" command that I wasn't aware of. I need to insert the HTTP header X-Forwarded-For, but as Jarvil pointed right, maybe this header is coming yet within the original request arriving to F5. In that case I would rather replace the header value.

     

     

    If the server log supports it, I will concatenate the arriving X-Forwarded-For value with the new one, separating with a coma, but I think that this maybe is not necessary regarding the actual server logs.

     

     

    I will try this and update how this goes.

     

     

    Thank you all for your help!!
  • maybe this header is coming yet within the original request arriving to F5

     

     

    Actually its coming from the X-Forward-For setting in your HTTP profile whiich adds the header for you. Hence we need to update it and not add another one.