Commit a348222d authored by Geoff Simmons's avatar Geoff Simmons

Add the proxy_header attribute, introduced in Varnish 5.0.0.

parent f2769c85
......@@ -31,7 +31,7 @@ import backend_dyn [from "path"] ;
[DURATION connect_timeout,]
[DURATION first_byte_timeout,]
[DURATION between_bytes_timeout,]
[INT max_connections])
[INT max_connections,] [INT proxy_header])
BACKEND backend_dyn.by_name(STRING name)
......@@ -87,7 +87,7 @@ Examples::
host_header="www.mysite.com",
connect_timeout=1s, first_byte_timeout=2s,
between_bytes_timeout=3s,
max_connections=100)) {
max_connections=100, proxy_header=1)) {
return(fail);
}
......@@ -124,18 +124,19 @@ Examples::
CONTENTS
========
* BOOL create(PRIV_VCL, STRING, STRING, STRING, PROBE, STRING, DURATION, DURATION, DURATION, INT, INT)
* BACKEND by_name(PRIV_VCL, STRING)
* BOOL create(PRIV_VCL, STRING, STRING, STRING, PROBE, STRING, DURATION, DURATION, DURATION, INT)
* BOOL delete(PRIV_VCL, BACKEND)
* STRING version()
.. _func_create:
BOOL create(PRIV_VCL, STRING, STRING, STRING, PROBE, STRING, DURATION, DURATION, DURATION, INT)
-----------------------------------------------------------------------------------------------
create
------
Prototype
BOOL create(PRIV_VCL, STRING name, STRING host, STRING port, PROBE probe, STRING host_header, DURATION connect_timeout, DURATION first_byte_timeout, DURATION between_bytes_timeout, INT max_connections)
::
BOOL create(PRIV_VCL, STRING name, STRING host, STRING port="", PROBE probe=0, STRING host_header="", DURATION connect_timeout=0, DURATION first_byte_timeout=0, DURATION between_bytes_timeout=0, INT max_connections=0, INT proxy_header=0)
Create a backend with the given configuration. The parameters
correspond to the configuration fields of a static backend
......@@ -199,6 +200,10 @@ corresponding global parameter is used (``-p connect_timeout``, etc.).
``max_connections`` MUST be an integer. By default, there is no upper
bound for the connections to a backend.
``proxy_header`` MUST be 0, 1 or 2. If 1 or 2, then that version of
the PROXY protocol is used with the backend; if 0, then the PROXY
protocol is not used. Default is 0.
Examples::
if (!backend_dyn.create(name="be", host="myhost.com")) {
......@@ -213,10 +218,11 @@ Examples::
.. _func_by_name:
BACKEND by_name(PRIV_VCL, STRING)
---------------------------------
by_name
-------
::
Prototype
BACKEND by_name(PRIV_VCL, STRING name)
Return the backend created by the VMOD with the given name in the
......@@ -243,10 +249,11 @@ Examples::
.. _func_delete:
BOOL delete(PRIV_VCL, BACKEND)
------------------------------
delete
------
::
Prototype
BOOL delete(PRIV_VCL, BACKEND be)
Delete the backend created by the VMOD with the given name in the
......@@ -284,10 +291,11 @@ Examples::
.. _func_version:
STRING version()
----------------
version
-------
::
Prototype
STRING version()
Returns the version string for this vmod.
......@@ -369,3 +377,17 @@ This document is licensed under the same conditions as the
libvmod-backend_dyn project. See LICENSE for details.
* Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
COPYRIGHT
=========
::
Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
All rights reserved
Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
See LICENCE
varnishtest "Sending proxy headers to backend"
# This test is kind of hairy.
# We don't have code in server to validate PROXY headers
# so use a pipe of: c1 [proxy] v2 [proxy] v1 [http] s1
# Using proxy also between c1 and v2 allows us to test
# IPv6 processing over a IPv4 connection.
server s1 {
rxreq
expect req.url == "/1"
expect req.http.xyzzy1 == req.http.xyzzy2
expect req.http.xyzzy1 == 1111
expect req.http.x-forwarded-for == "1.2.3.4, 1.2.3.4"
txresp -body "proxy1"
rxreq
expect req.url == "/2"
expect req.http.xyzzy1 == req.http.xyzzy2
expect req.http.xyzzy1 == 2222
expect req.http.x-forwarded-for == "1.2.3.4, 1.2.3.4"
txresp -body "proxy2"
rxreq
expect req.url == "/3"
expect req.http.xyzzy1 == req.http.xyzzy2
expect req.http.xyzzy1 == 3333
expect req.http.x-forwarded-for == "1:f::2, 1:f::2"
txresp -body "proxy3"
rxreq
expect req.url == "/4"
expect req.http.xyzzy1 == req.http.xyzzy2
expect req.http.xyzzy1 == 4444
expect req.http.x-forwarded-for == "1:f::2, 1:f::2"
txresp -body "proxy4"
} -start
varnish v1 -proto PROXY -vcl+backend {
import std;
sub vcl_recv {
set req.http.xyzzy1 = std.port(client.ip);
}
} -start
varnish v2 -proto PROXY -vcl {
import std;
import backend_dyn from "${vmod_topbuild}/src/.libs/libvmod_backend_dyn.so";
backend dummy { .host="${bad_ip}"; }
sub vcl_init {
if (!backend_dyn.create(name="bp1", host="${v1_addr}",
port="${v1_port}", proxy_header=1)) {
return(fail);
}
if (!backend_dyn.create(name="bp2", host="${v1_addr}",
port="${v1_port}", proxy_header=2)) {
return(fail);
}
}
sub vcl_recv {
set req.http.xyzzy2 = std.port(client.ip);
if (req.url == "/1" || req.url == "/3") {
set req.backend_hint = backend_dyn.by_name("bp1");
} else {
set req.backend_hint = backend_dyn.by_name("bp2");
}
}
sub vcl_deliver {
set resp.http.connection = "close";
}
} -start
client c1 -connect ${v2_sock} -proxy1 "1.2.3.4:1111 5.6.7.8:5678" {
txreq -url /1
rxresp
expect resp.body == "proxy1"
} -run
delay .2
client c1 -connect ${v2_sock} -proxy1 "1.2.3.4:2222 5.6.7.8:5678" {
txreq -url /2
rxresp
expect resp.body == "proxy2"
} -run
delay .2
client c1 -connect ${v2_sock} -proxy1 "[1:f::2]:3333 [5:a::8]:5678" {
txreq -url /3
rxresp
expect resp.body == "proxy3"
} -run
delay .2
client c1 -connect ${v2_sock} -proxy1 "[1:f::2]:4444 [5:a::8]:5678" {
txreq -url /4
rxresp
expect resp.body == "proxy4"
} -run
delay .2
......@@ -145,7 +145,7 @@ vmod_create(VRT_CTX, struct vmod_priv *priv, VCL_STRING vcl_name,
VCL_STRING host, VCL_STRING port, VCL_PROBE probe,
VCL_STRING host_header, VCL_DURATION connect_timeout,
VCL_DURATION first_byte_timeout, VCL_DURATION between_bytes_timeout,
VCL_INT max_connections)
VCL_INT max_connections, VCL_INT proxy_header)
{
struct belist *belist;
struct bentry *bentry;
......@@ -170,6 +170,11 @@ vmod_create(VRT_CTX, struct vmod_priv *priv, VCL_STRING vcl_name,
errmsg(ctx, "vmod backend_dyn error: host must be non-empty");
return 0;
}
if (proxy_header < 0 || proxy_header > 2) {
errmsg(ctx, "vmod backend_dyn error: proxy_header must be 0, 1"
"or 2");
return 0;
}
if (hosthdr[0] == '\0')
hosthdr = host;
......
......@@ -16,7 +16,7 @@ $Module backend_dyn 3 Varnish Module to dynamically create and delete backends
[DURATION connect_timeout,]
[DURATION first_byte_timeout,]
[DURATION between_bytes_timeout,]
[INT max_connections])
[INT max_connections,] [INT proxy_header])
BACKEND backend_dyn.by_name(STRING name)
......@@ -72,7 +72,7 @@ Examples::
host_header="www.mysite.com",
connect_timeout=1s, first_byte_timeout=2s,
between_bytes_timeout=3s,
max_connections=100)) {
max_connections=100, proxy_header=1)) {
return(fail);
}
......@@ -110,7 +110,7 @@ $Function BOOL create(PRIV_VCL, STRING name, STRING host, STRING port="",
PROBE probe=0, STRING host_header="",
DURATION connect_timeout=0, DURATION first_byte_timeout=0,
DURATION between_bytes_timeout=0,
INT max_connections=0)
INT max_connections=0, INT proxy_header=0)
Create a backend with the given configuration. The parameters
correspond to the configuration fields of a static backend
......@@ -174,6 +174,10 @@ corresponding global parameter is used (``-p connect_timeout``, etc.).
``max_connections`` MUST be an integer. By default, there is no upper
bound for the connections to a backend.
``proxy_header`` MUST be 0, 1 or 2. If 1 or 2, then that version of
the PROXY protocol is used with the backend; if 0, then the PROXY
protocol is not used. Default is 0.
Examples::
if (!backend_dyn.create(name="be", host="myhost.com")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment