I have a polling HTTP pakcet that the LTM does not see as a proper compliant HTTP packet.
Due to this the device sends a single packet in and the F5 closes the connection. This connection needs to remain open. To fix this, the HTTP profile is removed from the Virtual Server. The X-Forwarded header is needed fromn the packets that then flow through the LTM. The X-Forwarded header becomes the IP address of the LTM and not the source device.
I am looking for an iRule that will look at this packet and extract the X-Forwarded contents and send it through, as the souce address sent becomes the interface of the LTM.
Can you clarify this? Do you want LTM to spoof the value of the XFF header that a prior device in the chain inserted? Or do you want LTM to insert the IP address it received as the client into an XFF header?
Yes I need the iRule to put “X-Forwarded-for” of the original IP address otherwise, it puts the IP address of the LTM interface in the HTTP header.
If I used a HTTP profile it inserted this inthe packet. I configured the profile to insert the X-Forwarded-For but due to the nature of the sending device the F5 does not then see this as a complaint HTTP packet. SO I am unable to apply a HTTP profile of any sort. Unable to write a simple iRule as it then requires an HTTP profile.
SO if possible the packet that the back end server gets has the originator’s IP and NOT the LTM interface.
I have been reading some other threads and wondered, if I make the IIS server (back end server) Def Gateway to be the LTM interface and turn off SNAT on thr VS will this resolve my issue?
Will I be able to apply a HTTP profile and preserve the originating clients IP address ?Just a thought …
If you need to see the original client IP address in logs and cannot add an HTTP profile, it would be a lot more efficient in terms of LTM processing to change the default gateway to the LTM and turn off SNAT on the VIP. You wouldn’t need to insert the XFF header then or add an HTTP profile.
Thanks I will try that. BUt if this does not work, do you know of an iRule or could help me if needed to write one as its the packets being passed by the LTM that my back end client uses.
It would be more efficient to use an HTTP profile if you can. The alternative is to collect every TCP payload and insert the HTTP header in the TCP payload.
One option that could possibly work is to disable the HTTP profile after the HTTP headers of the first request have been parsed.
when HTTP_REQUEST {
Insert XFF header
HTTP::header insert X-Forwarded-For [IP::client_addr]
Disable the HTTP profile for the rest of this TCP connection
HTTP::disable
}
If that works, you should consider that the client may try to send multiple HTTP requests over the same TCP connection. Is this a possibility?
Used wireshark after applying the iRule and the first packet we saw in has the souce IP address as required but then all subsequent HTTP packets come though the IP of the LTM .
What VIP configuration are you using? Is SNAT enabled or disabled? Are you using an iRule?
Are you seeing the monitor traffic in your trace? If you have a redundant pair with SNAT enabled, the load balanced traffic would be sourced from LTM’s floating self IP address to the server IP’s. With/without SNAT, LTM’s monitor traffic will be sent from the non-floating self IP address(es).
I havnt changed to much. I have a basic HTTP profile with the iRule applied still SNAT and the back end server still configured NOT to use the LTM as Def Gateway.
If I dont use the iRule you posted above with the HTTP profile I only get a single pcket with the IP addres of the LTM. Using the iRule above my first packet contains the X-Forwarded-for but then reverts back to the LTM.
So it sounds like the client is making more than one HTTP request on the same TCP connection. If that happens, the HTTP profile and iRule would no longer be enabled, so the XFF header would not be inserted. That’s the downside to disabling the HTTP profile.
If you want to insert the XFF header in every request on a TCP connection, you would need to collect the TCP payload and search every packet for some delimiter like HTTP/1.0\r\n or HTTP/1.1\r\n and replace it with HTTP/1.x\r\nX-Forwarded-For: [IP::client_addr]\r\n where x is the HTTP version. You could also potentially do this with a stream profile as the HTTP headers (not the payload) would be modified.
The easiest option though would be to change the servers’ default gateway and remove the SNAT.
You’ll need to configure a virtual server or SNAT to allow the servers to originate traffic through LTM. The best option would be to configure a virtual server which points to a pool of one or more gateways with a FastL4 profile. You may need to enable SNAT on the outbound virtual server to ensure responses go back through LTM. You should also enable the outbound virtual server only on the servers’ VLAN. This will ensure that only the servers will be able to use this VIP to route through LTM.