[MEDIUM] add ability to connect to a server from an IP found in a header
Using get_ip_from_hdr2() we can look for occurrence #X or #-X and
extract the IP it contains. This is typically designed for use with
the X-Forwarded-For header.
Using "usesrc hdr_ip(name,occ)", it becomes possible to use the IP address
found in <name>, and possibly specify occurrence number <occ>, as the
source to connect to a server. This is possible both in a server and in
a backend's source statement. This is typically used to use the source
IP previously set by a upstream proxy.
diff --git a/include/common/defaults.h b/include/common/defaults.h
index 7746a98..845319d 100644
--- a/include/common/defaults.h
+++ b/include/common/defaults.h
@@ -63,6 +63,11 @@
#define MAX_HTTP_HDR ((BUFSIZE+79)/80)
#endif
+// max # of headers in history when looking for header #-X
+#ifndef MAX_HDR_HISTORY
+#define MAX_HDR_HISTORY 10
+#endif
+
// max # of loops we can perform around a read() which succeeds.
// It's very frequent that the system returns a few TCP segments at a time.
#ifndef MAX_READ_POLL_LOOPS
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index 8213e3b..e7181ec 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -92,6 +92,8 @@
void http_capture_bad_message(struct error_snapshot *es, struct session *s,
struct buffer *buf, struct http_msg *msg,
struct proxy *other_end);
+unsigned int get_ip_from_hdr2(struct http_msg *msg, const char *hname, int hlen,
+ struct hdr_idx *idx, int occ);
void http_init_txn(struct session *s);
void http_end_txn(struct session *s);
diff --git a/include/types/proxy.h b/include/types/proxy.h
index cc23117..c3fd01a 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -249,6 +249,9 @@
struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
+ char *bind_hdr_name; /* bind to this header name if defined */
+ int bind_hdr_len; /* length of the name of the header above */
+ int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */
#endif
int iface_len; /* bind interface name length */
char *iface_name; /* bind interface name or NULL */
diff --git a/include/types/server.h b/include/types/server.h
index bf3d6b0..00251d8 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -106,6 +106,9 @@
struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
+ char *bind_hdr_name; /* bind to this header name if defined */
+ int bind_hdr_len; /* length of the name of the header above */
+ int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */
#endif
int iface_len; /* bind interface name length */
char *iface_name; /* bind interface name or NULL */