Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proxy/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ libproxy_a_SOURCES = \
ProtocolProbeSessionAccept.h \
ProxySession.cc \
ProxySession.h \
PoolableSession.h \
ProxyTransaction.cc \
ProxyTransaction.h \
ReverseProxy.cc \
Expand Down
192 changes: 192 additions & 0 deletions proxy/PoolableSession.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/** @file

PoolableSession - class that extends ProxySession so that they can be cataloged for reuse.

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include "ProxySession.h"

class PoolableSession : public ProxySession
{
using self_type = PoolableSession;
using super_type = ProxySession;

public:
enum PooledState {
INIT,
SSN_IN_USE, // actively in use
KA_RESERVED, // stuck to client
KA_POOLED, // free for reuse
};

/// Hash map descriptor class for IP map.
struct IPLinkage {
self_type *_next = nullptr;
self_type *_prev = nullptr;

static self_type *&next_ptr(self_type *);
static self_type *&prev_ptr(self_type *);
static uint32_t hash_of(sockaddr const *key);
static sockaddr const *key_of(self_type const *ssn);
static bool equal(sockaddr const *lhs, sockaddr const *rhs);
// Add a couple overloads for internal convenience.
static bool equal(sockaddr const *lhs, PoolableSession const *rhs);
static bool equal(PoolableSession const *lhs, sockaddr const *rhs);
} _ip_link;

/// Hash map descriptor class for FQDN map.
struct FQDNLinkage {
self_type *_next = nullptr;
self_type *_prev = nullptr;

static self_type *&next_ptr(self_type *);
static self_type *&prev_ptr(self_type *);
static uint64_t hash_of(CryptoHash const &key);
static CryptoHash const &key_of(self_type *ssn);
static bool equal(CryptoHash const &lhs, CryptoHash const &rhs);
} _fqdn_link;

CryptoHash hostname_hash;
PooledState state = INIT;

// Copy of the owning SM's server session sharing settings
TSServerSessionSharingMatchMask sharing_match = TS_SERVER_SESSION_SHARING_MATCH_MASK_NONE;
TSServerSessionSharingPoolType sharing_pool = TS_SERVER_SESSION_SHARING_POOL_GLOBAL;

// Keep track of connection limiting and a pointer to the
// singleton that keeps track of the connection counts.
OutboundConnTrack::Group *conn_track_group = nullptr;

void set_active();
bool is_active();
void set_private(bool new_private = true);
bool is_private() const;

void set_netvc(NetVConnection *newvc);

private:
// Sessions become if authentication headers
// are sent over them
bool private_session = false;
};

inline void
PoolableSession::set_active()
{
state = SSN_IN_USE;
}
inline bool
PoolableSession::is_active()
{
return state == SSN_IN_USE;
}
inline void
PoolableSession::set_private(bool new_private)
{
private_session = new_private;
}
inline bool
PoolableSession::is_private() const
{
return private_session;
}

inline void
PoolableSession::set_netvc(NetVConnection *newvc)
{
ProxySession::_vc = newvc;
}

//
// LINKAGE

inline PoolableSession *&
PoolableSession::IPLinkage::next_ptr(self_type *ssn)
{
return ssn->_ip_link._next;
}

inline PoolableSession *&
PoolableSession::IPLinkage::prev_ptr(self_type *ssn)
{
return ssn->_ip_link._prev;
}

inline uint32_t
PoolableSession::IPLinkage::hash_of(sockaddr const *key)
{
return ats_ip_hash(key);
}

inline sockaddr const *
PoolableSession::IPLinkage::key_of(self_type const *ssn)
{
return ssn->get_remote_addr();
}

inline bool
PoolableSession::IPLinkage::equal(sockaddr const *lhs, sockaddr const *rhs)
{
return ats_ip_addr_port_eq(lhs, rhs);
}

inline bool
PoolableSession::IPLinkage::equal(sockaddr const *lhs, PoolableSession const *rhs)
{
return ats_ip_addr_port_eq(lhs, key_of(rhs));
}

inline bool
PoolableSession::IPLinkage::equal(PoolableSession const *lhs, sockaddr const *rhs)
{
return ats_ip_addr_port_eq(key_of(lhs), rhs);
}

inline PoolableSession *&
PoolableSession::FQDNLinkage::next_ptr(self_type *ssn)
{
return ssn->_fqdn_link._next;
}

inline PoolableSession *&
PoolableSession::FQDNLinkage::prev_ptr(self_type *ssn)
{
return ssn->_fqdn_link._prev;
}

inline uint64_t
PoolableSession::FQDNLinkage::hash_of(CryptoHash const &key)
{
return key.fold();
}

inline CryptoHash const &
PoolableSession::FQDNLinkage::key_of(self_type *ssn)
{
return ssn->hostname_hash;
}

inline bool
PoolableSession::FQDNLinkage::equal(CryptoHash const &lhs, CryptoHash const &rhs)
{
return lhs == rhs;
}
18 changes: 13 additions & 5 deletions proxy/ProxySession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ProxySession::set_session_active()
{
if (!m_active) {
m_active = true;
this->increment_current_active_client_connections_stat();
this->increment_current_active_connections_stat();
}
}

Expand All @@ -44,7 +44,7 @@ ProxySession::clear_session_active()
{
if (m_active) {
m_active = false;
this->decrement_current_active_client_connections_stat();
this->decrement_current_active_connections_stat();
}
}

Expand Down Expand Up @@ -201,12 +201,12 @@ ProxySession::connection_id() const
}

bool
ProxySession::attach_server_session(Http1ServerSession *ssession, bool transaction_done)
ProxySession::attach_server_session(PoolableSession *ssession, bool transaction_done)
{
return false;
}

Http1ServerSession *
PoolableSession *
ProxySession::get_server_session() const
{
return nullptr;
Expand Down Expand Up @@ -236,6 +236,14 @@ ProxySession::cancel_inactivity_timeout()
}
}

void
ProxySession::cancel_active_timeout()
{
if (_vc) {
_vc->cancel_active_timeout();
}
}

int
ProxySession::populate_protocol(std::string_view *result, int size) const
{
Expand All @@ -249,7 +257,7 @@ ProxySession::protocol_contains(std::string_view tag_prefix) const
}

sockaddr const *
ProxySession::get_client_addr()
ProxySession::get_remote_addr() const
{
return _vc ? _vc->get_remote_addr() : nullptr;
}
Expand Down
15 changes: 8 additions & 7 deletions proxy/ProxySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <memory>
#include "P_Net.h"
#include "InkAPIInternal.h"
#include "http/Http1ServerSession.h"
#include "http/HttpSessionAccept.h"
#include "IPAllow.h"
#include "private/SSLProxySession.h"
Expand All @@ -41,6 +40,7 @@
#define SsnDebug(ssn, tag, ...) SpecificDebug((ssn)->debug(), tag, __VA_ARGS__)

class ProxyTransaction;
class PoolableSession;

enum class ProxyErrorClass {
NONE,
Expand Down Expand Up @@ -89,18 +89,17 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
// Virtual Methods
virtual void new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOBufferReader *reader) = 0;
virtual void start() = 0;
virtual bool attach_server_session(Http1ServerSession *ssession, bool transaction_done = true);
virtual bool attach_server_session(PoolableSession *ssession, bool transaction_done = true);

virtual void release(ProxyTransaction *trans) = 0;

virtual void destroy() = 0;
virtual void free();

virtual void increment_current_active_client_connections_stat() = 0;
virtual void decrement_current_active_client_connections_stat() = 0;
virtual void increment_current_active_connections_stat() = 0;
virtual void decrement_current_active_connections_stat() = 0;

// Virtual Accessors
NetVConnection *get_netvc() const;
virtual int get_transact_count() const = 0;
virtual const char *get_protocol_string() const = 0;

Expand All @@ -111,20 +110,22 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
virtual void set_half_close_flag(bool flag);
virtual bool get_half_close_flag() const;

virtual Http1ServerSession *get_server_session() const;
virtual PoolableSession *get_server_session() const;

// Replicate NetVConnection API
virtual sockaddr const *get_client_addr();
virtual sockaddr const *get_remote_addr() const;
virtual sockaddr const *get_local_addr();

virtual void set_active_timeout(ink_hrtime timeout_in);
virtual void set_inactivity_timeout(ink_hrtime timeout_in);
virtual void cancel_inactivity_timeout();
virtual void cancel_active_timeout();

virtual int populate_protocol(std::string_view *result, int size) const;
virtual const char *protocol_contains(std::string_view tag_prefix) const;

// Non-Virtual Methods
NetVConnection *get_netvc() const;
int do_api_callout(TSHttpHookID id);

void set_debug(bool flag);
Expand Down
34 changes: 32 additions & 2 deletions proxy/ProxyTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

#include "http/HttpSM.h"
#include "http/Http1ServerSession.h"
#include "Plugin.h"

#define HttpTxnDebug(fmt, ...) SsnDebug(this, "http_txn", fmt, __VA_ARGS__)
Expand Down Expand Up @@ -57,7 +56,7 @@ ProxyTransaction::new_transaction(bool from_early_data)
}

bool
ProxyTransaction::attach_server_session(Http1ServerSession *ssession, bool transaction_done)
ProxyTransaction::attach_server_session(PoolableSession *ssession, bool transaction_done)
{
return _proxy_ssn->attach_server_session(ssession, transaction_done);
}
Expand Down Expand Up @@ -185,3 +184,34 @@ ProxyTransaction::transaction_done()
SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread());
this->decrement_client_transactions_stat();
}

// Implement VConnection interface.
VIO *
ProxyTransaction::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
{
return _proxy_ssn->do_io_read(c, nbytes, buf);
}
VIO *
ProxyTransaction::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner)
{
return _proxy_ssn->do_io_write(c, nbytes, buf, owner);
}

void
ProxyTransaction::do_io_close(int lerrno)
{
_proxy_ssn->do_io_close(lerrno);
// this->destroy(); Parent owns this data structure. No need for separate destroy.
}

void
ProxyTransaction::do_io_shutdown(ShutdownHowTo_t howto)
{
_proxy_ssn->do_io_shutdown(howto);
}

void
ProxyTransaction::reenable(VIO *vio)
{
_proxy_ssn->reenable(vio);
}
Loading