From d447b5d5a771008ed83c03b4cf5fad8addd371e2 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sun, 14 Jan 2018 00:35:30 +0100 Subject: [PATCH] net/haproxy: make stick-table config more flexible, refs #202 --- .../OPNsense/HAProxy/forms/dialogBackend.xml | 49 +++++++++++++++++ .../app/models/OPNsense/HAProxy/HAProxy.xml | 55 +++++++++++++++++++ .../templates/OPNsense/HAProxy/haproxy.conf | 34 ++++++++++-- 3 files changed, 133 insertions(+), 5 deletions(-) diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml index 6c7d1fbe9..b311cfca5 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogBackend.xml @@ -81,6 +81,13 @@ HAProxy documentation for a full description.
NOTE: Consider not using this feature in multi-process mode, it can result in random behaviours.
]]>
Choose a persistence type. + + backend.stickiness_dataTypes + + select_multiple + + HAProxy documentation for a full description.]]> + backend.stickiness_expire @@ -107,6 +114,48 @@ text + + backend.stickiness_connRatePeriod + + text + + true + + + backend.stickiness_sessRatePeriod + + text + + true + + + backend.stickiness_httpReqRatePeriod + + text + + true + + + backend.stickiness_httpErrRatePeriod + + text + + true + + + backend.stickiness_bytesInRatePeriod + + text + + true + + + backend.stickiness_bytesOutRatePeriod + + text + + true + header diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml index c7717b67d..acbef1629 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml @@ -540,6 +540,25 @@ Stick on RDP-Cookie + + N + Y + + Connection count + Current connections + Connection rate + Session count + Session rate + HTTP request count + HTTP request rate + HTTP error count + HTTP error rate + Bytes in count (client to server) + Bytes in rate (client to server) + Bytes out count (server to client) + Bytes out rate (server to client) + + Y 30m @@ -565,6 +584,42 @@ Please specify a value between 1 and 10000. N + + 10s + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + + + 10s + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + + + 10s + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + + + 10s + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + + + 1m + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + + + 1m + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u + Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". + N + /^([0-9]{1,8}(?:us|ms|s|m|h|d)?)/u Should be a number between 1 and 8 characters, optionally followed by either "d", "h", "m", "s", "ms" or "us". diff --git a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf index ccaefda24..9eb5f0976 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -816,21 +816,45 @@ backend {{backend.name}} {# # (redundant) GUI option for this. #} mode {{backend.mode}} balance {{backend.algorithm}} -{# # ignore if stickiness is disabled (set to "None") #} +{# # check if stickiness is disabled (set to "None") #} {% if backend.stickiness_pattern|default("") != "" %} # stickiness +{# # check if additional data types are configured #} +{% if backend.stickiness_dataTypes|default("") != "" %} +{% set stickiness_datatypes = [] %} +{% for datatype in backend.stickiness_dataTypes.split(",") %} +{# # add time period to all types where this is required #} +{% if datatype == 'conn_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_connRatePeriod ~ ')') %} +{% elif datatype == 'sess_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_sessRatePeriod ~ ')') %} +{% elif datatype == 'http_req_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_httpReqRatePeriod ~ ')') %} +{% elif datatype == 'http_err_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_httpErrRatePeriod ~ ')') %} +{% elif datatype == 'bytes_in_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_bytesInRatePeriod ~ ')') %} +{% elif datatype == 'bytes_out_rate' %} +{% do stickiness_datatypes.append(datatype ~ '(' ~ backend.stickiness_bytesOutRatePeriod ~ ')') %} +{% else %} +{% do stickiness_datatypes.append(datatype) %} +{% endif %} +{% endfor %} +{% set stickiness_store = 'store ' ~ stickiness_datatypes|join(',') %} +{% endif %} +{# # check stick-table type #} {% if backend.stickiness_pattern == "sourceipv4" %} - stick-table type ip size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} + stick-table type ip size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} {{stickiness_store}} stick on src {% elif backend.stickiness_pattern == "sourceipv6" %} - stick-table type ipv6 size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} + stick-table type ipv6 size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} {{stickiness_store}} stick on src {% elif backend.stickiness_pattern == "cookievalue" %} - stick-table type string len {{backend.stickiness_cookielength}} size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} + stick-table type string len {{backend.stickiness_cookielength}} size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} {{stickiness_store}} stick store-response res.cook({{backend.stickiness_cookiename}}) stick on req.cook({{backend.stickiness_cookiename}}) {% elif backend.stickiness_pattern == "rdpcookie" %} - stick-table type binary len {{backend.stickiness_cookielength}} size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} + stick-table type binary len {{backend.stickiness_cookielength}} size {{backend.stickiness_size}} expire {{backend.stickiness_expire}} {{stickiness_store}} stick on req.rdp_cookie(mstshash) {% endif %} {% endif %}