2018-08-21 16:11:50 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <openssl/ossl_typ.h>
|
|
|
|
|
#include <event2/event.h>
|
|
|
|
|
|
|
|
|
|
#include <tfe_stream.h>
|
|
|
|
|
#include <tfe_stat.h>
|
|
|
|
|
#include <cert.h>
|
|
|
|
|
|
|
|
|
|
struct tfe_thread_ctx
|
|
|
|
|
{
|
|
|
|
|
pthread_t thr;
|
|
|
|
|
unsigned int thread_id;
|
|
|
|
|
size_t load;
|
|
|
|
|
|
|
|
|
|
struct event_base * evbase;
|
|
|
|
|
unsigned char running;
|
|
|
|
|
|
|
|
|
|
struct tfe_stats stat;
|
|
|
|
|
struct cert_mgr * cert_mgr;
|
|
|
|
|
|
|
|
|
|
struct sess_cache * dsess_cache;
|
|
|
|
|
struct sess_cache * ssess_cache;
|
|
|
|
|
|
|
|
|
|
unsigned int nr_modules;
|
|
|
|
|
const struct tfe_plugin * modules;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Downstream: comunication form client to proxy
|
|
|
|
|
//Upstream: communication form proxy to server
|
|
|
|
|
struct ssl_downstream
|
|
|
|
|
{
|
|
|
|
|
/* server name indicated by client in SNI TLS extension */
|
|
|
|
|
char * sni;
|
|
|
|
|
SSL * ssl;
|
|
|
|
|
X509 * fake_cert_ref;//?
|
|
|
|
|
int keyring_id;
|
|
|
|
|
struct future * future_sni_peek;
|
|
|
|
|
struct future * future_get_cert;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ssl_upstream
|
|
|
|
|
{
|
|
|
|
|
X509 * orig_cert;
|
|
|
|
|
SSL * ssl;
|
|
|
|
|
struct future * conn_ssl_srv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum tfe_plugin_state
|
|
|
|
|
{
|
|
|
|
|
PLUG_STATE_READONLY,
|
|
|
|
|
PLUG_STATE_PREEPTION,
|
|
|
|
|
PLUG_STATE_DETACHED
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct plugin_ctx
|
|
|
|
|
{
|
|
|
|
|
enum tfe_plugin_state state;
|
|
|
|
|
void * pme;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tfe_stream_write_ctx
|
|
|
|
|
{
|
|
|
|
|
struct tfe_stream_private * _stream;
|
|
|
|
|
enum tfe_conn_dir dir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tfe_conn_private
|
|
|
|
|
{
|
|
|
|
|
evutil_socket_t fd;
|
|
|
|
|
struct bufferevent * bev;
|
|
|
|
|
uint8_t on_writing;
|
|
|
|
|
uint8_t closed;
|
|
|
|
|
uint8_t need_shutdown;
|
|
|
|
|
struct tfe_stream_write_ctx w_ctx;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tfe_stream_private
|
|
|
|
|
{
|
|
|
|
|
struct tfe_stream head;
|
2018-08-23 11:23:05 +08:00
|
|
|
struct tfe_proxy *proxy;
|
|
|
|
|
|
2018-08-21 16:11:50 +08:00
|
|
|
enum tfe_session_proto session_type;
|
|
|
|
|
struct tfe_conn_private conn_upstream;
|
|
|
|
|
struct tfe_conn_private conn_downstream;
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct ssl_downstream * ssl_downstream;
|
|
|
|
|
void * raw_downstream;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct ssl_upstream * ssl_upstream;
|
|
|
|
|
void * raw_upstream;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint8_t is_plugin_opened;
|
|
|
|
|
int calling_idx;
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-08-21 16:11:50 +08:00
|
|
|
size_t forward_bytes;
|
|
|
|
|
size_t defere_bytes;
|
|
|
|
|
size_t drop_bytes;
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-08-21 16:11:50 +08:00
|
|
|
enum tfe_app_proto app_proto;
|
|
|
|
|
int plugin_num;
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-08-21 16:11:50 +08:00
|
|
|
struct plugin_ctx * plug_ctx;
|
|
|
|
|
unsigned char passthrough; /* 1 if SSL passthrough is active */
|
|
|
|
|
|
|
|
|
|
evutil_socket_t fd_downstream;
|
|
|
|
|
evutil_socket_t fd_upstream;
|
|
|
|
|
|
|
|
|
|
struct tfe_thread_ctx * thrmgr_ref;
|
|
|
|
|
future * async_future;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tfe_stream_private * tfe_stream_create(evutil_socket_t fd_downstream, evutil_socket_t fd_upstream,
|
|
|
|
|
enum tfe_session_proto session_type, tfe_thread_ctx * thread);
|
|
|
|
|
|
|
|
|
|
void tfe_stream_setup(struct tfe_stream_private * _stream);
|
|
|
|
|
|