Skip to content

Commit 6ca86f0

Browse files
authored
Add more options to session_sharing.match (#6566)
Co-authored-by: Susan Hinrichs <shinrich@verizonmedia.com>
1 parent 96e1f46 commit 6ca86f0

File tree

15 files changed

+233
-196
lines changed

15 files changed

+233
-196
lines changed

doc/admin-guide/files/records.config.en.rst

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -929,32 +929,29 @@ mptcp
929929
:overridable:
930930

931931
Enable and set the ability to re-use server connections across client
932-
connections. The valid values are:
933-
934-
======== ===================================================================
935-
Value Description
936-
======== ===================================================================
937-
``none`` Do not match and do not re-use server sessions. If using this in
938-
:ref:`ts-overridable-config` (like the :ref:`admin-plugins-conf-remap`),
939-
use the integer ``0`` instead.
940-
``both`` Re-use server sessions, if *both* the IP address and fully qualified
941-
domain name match. If using this in :ref:`ts-overridable-config` (like
942-
the :ref:`admin-plugins-conf-remap`), use the integer ``1`` instead.
943-
``ip`` Re-use server sessions, checking only that the IP address and port
944-
of the origin server matches. If using this in
945-
:ref:`ts-overridable-config` (like the :ref:`admin-plugins-conf-remap`),
946-
use the integer ``2`` instead.
947-
``host`` Re-use server sessions, checking only that the fully qualified
948-
domain name matches. If using this in :ref:`ts-overridable-config`
949-
(like the :ref:`admin-plugins-conf-remap`), use the integer ``3`` instead.
950-
======== ===================================================================
951-
952-
It is strongly recommended to use either ``none`` or ``both`` for this value
953-
unless you have a specific need for the other settings. The most common
954-
reason is virtual hosts that share an IP address in which case performance
955-
can be enhanced if those sessions can be re-used. However, not all web
956-
servers support requests for different virtual hosts on the same connection
957-
so use with caution.
932+
connections. Multiple values can be specified when separated by commas with no white spaces. Valid values are:
933+
934+
============= ===================================================================
935+
Value Description
936+
============= ===================================================================
937+
``none`` Do not match and do not re-use server sessions.
938+
``ip`` Re-use server sessions, checking only that the IP address and port
939+
of the origin server matches.
940+
``host`` Re-use server sessions, checking that the fully qualified
941+
domain name matches. In addition, if the session uses TLS, it also
942+
checks that the current transaction's host header value matchs the session's SNI.
943+
``both`` Equivalent to ``host,ip``.
944+
``hostonly`` Check that the fully qualified domain name matches.
945+
``sni`` Check that the SNI of the session matches the SNI that would be used to
946+
create a new session. Only applicable for TLS sessions.
947+
``cert`` Check that the certificate file name used for the server session matches the
948+
certificate file name that would be used for the new server session. Only
949+
applicable for TLS sessions.
950+
============= ===================================================================
951+
952+
The setting must contain at least one of ``ip``, ``host``, ``hostonly`` or ``both``
953+
for session reuse to operate. The other values may be used for greater control
954+
with TLS sessoin reuse.
958955

959956
.. note::
960957

doc/developer-guide/api/types/TSServerSessionSharingMatchType.en.rst

Lines changed: 0 additions & 46 deletions
This file was deleted.

doc/developer-guide/api/types/TSServerSessionSharingPoolType.en.rst

Lines changed: 0 additions & 42 deletions
This file was deleted.

include/ts/apidefs.h.in

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -599,22 +599,6 @@ typedef enum {
599599

600600
#ifndef _HTTP_PROXY_API_ENUMS_H_
601601
#define _HTTP_PROXY_API_ENUMS_H_
602-
/// Server session sharing values - match
603-
/// Must be identical to definition in HttpProxyAPIEnums.h
604-
typedef enum {
605-
TS_SERVER_SESSION_SHARING_MATCH_NONE,
606-
TS_SERVER_SESSION_SHARING_MATCH_BOTH,
607-
TS_SERVER_SESSION_SHARING_MATCH_IP,
608-
TS_SERVER_SESSION_SHARING_MATCH_HOST
609-
} TSServerSessionSharingMatchType;
610-
611-
/// Server session sharing values - pool
612-
/// Must be identical to definition in HttpProxyAPIEnums.h
613-
typedef enum {
614-
TS_SERVER_SESSION_SHARING_POOL_GLOBAL,
615-
TS_SERVER_SESSION_SHARING_POOL_THREAD,
616-
} TSServerSessionSharingPoolType;
617-
618602
/// Values for per server outbound connection tracking group definition.
619603
/// See proxy.config.http.per_server.match
620604
typedef enum {

proxy/hdrs/HTTP.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class HTTPHdr : public MIMEHdr
586586
@note The results are cached so this is fast after the first call.
587587
@return A pointer to the host name.
588588
*/
589-
const char *host_get(int *length = nullptr);
589+
const char *host_get(int *length = nullptr) const;
590590

591591
/** Get the target port.
592592
If the target port is not found then it is adjusted to the
@@ -857,7 +857,7 @@ HTTPHdr::_test_and_fill_target_cache() const
857857
-------------------------------------------------------------------------*/
858858

859859
inline const char *
860-
HTTPHdr::host_get(int *length)
860+
HTTPHdr::host_get(int *length) const
861861
{
862862
this->_test_and_fill_target_cache();
863863
if (m_target_in_url) {

proxy/http/Http1ServerSession.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Http1ServerSession::release()
180180
server_vc->control_flags.set_flags(0);
181181

182182
// Private sessions are never released back to the shared pool
183-
if (private_session || TS_SERVER_SESSION_SHARING_MATCH_NONE == sharing_match) {
183+
if (private_session || sharing_match == 0) {
184184
this->do_io_close();
185185
return;
186186
}

proxy/http/Http1ServerSession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Http1ServerSession : public VConnection
111111
bool private_session = false;
112112

113113
// Copy of the owning SM's server session sharing settings
114-
TSServerSessionSharingMatchType sharing_match = TS_SERVER_SESSION_SHARING_MATCH_BOTH;
114+
TSServerSessionSharingMatchMask sharing_match = TS_SERVER_SESSION_SHARING_MATCH_MASK_NONE;
115115
TSServerSessionSharingPoolType sharing_pool = TS_SERVER_SESSION_SHARING_POOL_GLOBAL;
116116

117117
/// Hash map descriptor class for IP map.

proxy/http/HttpConfig.cc

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ template <typename T> struct ConfigEnumPair {
7676
/// If found @a value is set to the corresponding value in @a list.
7777
template <typename T, unsigned N>
7878
static bool
79-
http_config_enum_search(const char *key, const ConfigEnumPair<T> (&list)[N], MgmtByte &value)
79+
http_config_enum_search(std::string_view key, const ConfigEnumPair<T> (&list)[N], MgmtByte &value)
8080
{
81+
Debug("http_config", "enum element %.*s", static_cast<int>(key.size()), key.data());
8182
// We don't expect any of these lists to be more than 10 long, so a linear search is the best choice.
8283
for (unsigned i = 0; i < N; ++i) {
83-
if (0 == strcasecmp(list[i]._key, key)) {
84+
if (key.compare(list[i]._key) == 0) {
8485
value = list[i]._value;
8586
return true;
8687
}
@@ -110,10 +111,56 @@ http_config_enum_read(const char *name, const ConfigEnumPair<T> (&list)[N], Mgmt
110111
////////////////////////////////////////////////////////////////
111112
/// Session sharing match types.
112113
static const ConfigEnumPair<TSServerSessionSharingMatchType> SessionSharingMatchStrings[] = {
113-
{TS_SERVER_SESSION_SHARING_MATCH_NONE, "none"},
114-
{TS_SERVER_SESSION_SHARING_MATCH_IP, "ip"},
115-
{TS_SERVER_SESSION_SHARING_MATCH_HOST, "host"},
116-
{TS_SERVER_SESSION_SHARING_MATCH_BOTH, "both"}};
114+
{TS_SERVER_SESSION_SHARING_MATCH_NONE, "none"}, {TS_SERVER_SESSION_SHARING_MATCH_IP, "ip"},
115+
{TS_SERVER_SESSION_SHARING_MATCH_HOST, "host"}, {TS_SERVER_SESSION_SHARING_MATCH_HOST, "hostsni"},
116+
{TS_SERVER_SESSION_SHARING_MATCH_BOTH, "both"}, {TS_SERVER_SESSION_SHARING_MATCH_HOSTONLY, "hostonly"},
117+
{TS_SERVER_SESSION_SHARING_MATCH_SNI, "sni"}, {TS_SERVER_SESSION_SHARING_MATCH_CERT, "cert"}};
118+
119+
bool
120+
HttpConfig::load_server_session_sharing_match(const char *key, MgmtByte &mask)
121+
{
122+
MgmtByte value;
123+
mask = 0;
124+
// Parse through and build up mask
125+
std::string_view key_list(key);
126+
size_t start = 0;
127+
size_t offset = 0;
128+
Debug("http_config", "enum mask value %s", key);
129+
do {
130+
offset = key_list.find(',', start);
131+
if (offset == std::string_view::npos) {
132+
std::string_view one_key = key_list.substr(start);
133+
if (!http_config_enum_search(one_key, SessionSharingMatchStrings, value)) {
134+
return false;
135+
}
136+
} else {
137+
std::string_view one_key = key_list.substr(start, offset - start);
138+
if (!http_config_enum_search(one_key, SessionSharingMatchStrings, value)) {
139+
return false;
140+
}
141+
start = offset + 1;
142+
}
143+
if (value < TS_SERVER_SESSION_SHARING_MATCH_NONE) {
144+
mask |= (1 << value);
145+
} else if (value == TS_SERVER_SESSION_SHARING_MATCH_BOTH) {
146+
mask |= TS_SERVER_SESSION_SHARING_MATCH_MASK_IP | TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY |
147+
TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC;
148+
} else if (value == TS_SERVER_SESSION_SHARING_MATCH_HOST) {
149+
mask |= TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY | TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC;
150+
}
151+
} while (offset != std::string_view::npos);
152+
return true;
153+
}
154+
155+
static bool
156+
http_config_enum_mask_read(const char *name, MgmtByte &value)
157+
{
158+
char key[512]; // it's just one key - painful UI if keys are longer than this
159+
if (REC_ERR_OKAY == RecGetRecordString(name, key, sizeof(key))) {
160+
return HttpConfig::load_server_session_sharing_match(key, value);
161+
}
162+
return false;
163+
}
117164

118165
static const ConfigEnumPair<TSServerSessionSharingPoolType> SessionSharingPoolStrings[] = {
119166
{TS_SERVER_SESSION_SHARING_POOL_GLOBAL, "global"},
@@ -200,7 +247,7 @@ http_server_session_sharing_cb(const char *name, RecDataT dtype, RecData data, v
200247
MgmtByte &match = c->oride.server_session_sharing_match;
201248
if (RECD_INT == dtype) {
202249
match = static_cast<TSServerSessionSharingMatchType>(data.rec_int);
203-
} else if (RECD_STRING == dtype && http_config_enum_search(data.rec_string, SessionSharingMatchStrings, match)) {
250+
} else if (RECD_STRING == dtype && HttpConfig::load_server_session_sharing_match(data.rec_string, match)) {
204251
// empty
205252
} else {
206253
valid_p = false;
@@ -1059,8 +1106,7 @@ HttpConfig::startup()
10591106

10601107
// [amc] This is a bit of a mess, need to figure out to make this cleaner.
10611108
RecRegisterConfigUpdateCb("proxy.config.http.server_session_sharing.match", &http_server_session_sharing_cb, &c);
1062-
http_config_enum_read("proxy.config.http.server_session_sharing.match", SessionSharingMatchStrings,
1063-
c.oride.server_session_sharing_match);
1109+
http_config_enum_mask_read("proxy.config.http.server_session_sharing.match", c.oride.server_session_sharing_match);
10641110
http_config_enum_read("proxy.config.http.server_session_sharing.pool", SessionSharingPoolStrings, c.server_session_sharing_pool);
10651111

10661112
RecRegisterConfigUpdateCb("proxy.config.http.insert_forwarded", &http_insert_forwarded_cb, &c);

proxy/http/HttpConfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ struct OverridableHttpConfigParams {
465465
MgmtByte keep_alive_post_out = 1; // share server sessions for post
466466

467467
MgmtInt server_min_keep_alive_conns = 0;
468-
MgmtByte server_session_sharing_match = TS_SERVER_SESSION_SHARING_MATCH_BOTH;
468+
MgmtByte server_session_sharing_match = 0;
469469
MgmtByte auth_server_session_private = 1;
470470
MgmtByte fwd_proxy_auth_to_parent = 0;
471471
MgmtByte uncacheable_requests_bypass_parent = 1;
@@ -821,6 +821,8 @@ class HttpConfig
821821
inkcoreapi static HttpConfigParams *acquire();
822822
inkcoreapi static void release(HttpConfigParams *params);
823823

824+
static bool load_server_session_sharing_match(const char *key, MgmtByte &mask);
825+
824826
// parse ssl ports configuration string
825827
static HttpConfigPortRange *parse_ports_list(char *ports_str);
826828

proxy/http/HttpProxyAPIEnums.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,37 @@
2929

3030
#pragma once
3131

32-
// This is use to signal apidefs.h to not define these again.
33-
#ifndef _HTTP_PROXY_API_ENUMS_H_
34-
#define _HTTP_PROXY_API_ENUMS_H_
35-
3632
/// Server session sharing values - match
3733
typedef enum {
34+
TS_SERVER_SESSION_SHARING_MATCH_IP,
35+
TS_SERVER_SESSION_SHARING_MATCH_HOSTONLY,
36+
TS_SERVER_SESSION_SHARING_MATCH_HOSTSNISYNC,
37+
TS_SERVER_SESSION_SHARING_MATCH_SNI,
38+
TS_SERVER_SESSION_SHARING_MATCH_CERT,
3839
TS_SERVER_SESSION_SHARING_MATCH_NONE,
3940
TS_SERVER_SESSION_SHARING_MATCH_BOTH,
40-
TS_SERVER_SESSION_SHARING_MATCH_IP,
41-
TS_SERVER_SESSION_SHARING_MATCH_HOST
41+
TS_SERVER_SESSION_SHARING_MATCH_HOST,
4242
} TSServerSessionSharingMatchType;
4343

44+
typedef enum {
45+
TS_SERVER_SESSION_SHARING_MATCH_MASK_NONE = 0,
46+
TS_SERVER_SESSION_SHARING_MATCH_MASK_IP = 0x1,
47+
TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY = 0x2,
48+
TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC = 0x4,
49+
TS_SERVER_SESSION_SHARING_MATCH_MASK_SNI = 0x8,
50+
TS_SERVER_SESSION_SHARING_MATCH_MASK_CERT = 0x10
51+
} TSServerSessionSharingMatchMask;
52+
4453
/// Server session sharing values - pool
4554
typedef enum {
4655
TS_SERVER_SESSION_SHARING_POOL_GLOBAL,
4756
TS_SERVER_SESSION_SHARING_POOL_THREAD,
4857
} TSServerSessionSharingPoolType;
4958

59+
// This is use to signal apidefs.h to not define these again.
60+
#ifndef _HTTP_PROXY_API_ENUMS_H_
61+
#define _HTTP_PROXY_API_ENUMS_H_
62+
5063
/// Values for per server outbound connection tracking group definition.
5164
/// See proxy.config.http.per_server.match
5265
typedef enum {
@@ -55,4 +68,5 @@ typedef enum {
5568
TS_SERVER_OUTBOUND_MATCH_HOST,
5669
TS_SERVER_OUTBOUND_MATCH_BOTH
5770
} TSOutboundConnectionMatchType;
71+
5872
#endif

0 commit comments

Comments
 (0)