This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/platform/include/internal/proxy.h

122 lines
2.6 KiB
C

#pragma once
#include <tfe_stream.h>
#include <event2/event.h>
#include <ssl_stream_core.h>
struct ssl_mgr;
struct key_keeper;
struct kni_acceptor;
enum TFE_STAT_FIELD
{
STAT_SIGPIPE,
/* FDs */
STAT_FD_OPEN_BY_KNI_ACCEPT,
STAT_FD_CLOSE_BY_KNI_ACCEPT_FAIL,
/* FDs */
STAT_FD_INSTANT_CLOSE,
STAT_FD_DEFER_CLOSE_IN_QUEUE,
STAT_FD_DEFER_CLOSE_SUCCESS,
/* Stream */
STAT_STREAM_OPEN,
STAT_STREAM_CLS,
STAT_STREAM_CLS_DOWN_EOF,
STAT_STREAM_CLS_UP_EOF,
STAT_STREAM_CLS_DOWN_ERR,
STAT_STREAM_CLS_UP_ERR,
STAT_STREAM_CLS_KILL,
/* Stream Protocol */
STAT_STREAM_TCP_PLAIN,
STAT_STREAM_TCP_SSL,
TFE_STAT_MAX
};
struct tfe_proxy_tcp_options
{
/* TCP OPTIONS */
int sz_rcv_buffer;
int sz_snd_buffer;
int so_keepalive;
int tcp_keepidle;
int tcp_keepintvl;
int tcp_keepcnt;
int tcp_user_timeout;
/* TRACE FOR DEBUG */
int tcp_ttl_upstream;
int tcp_ttl_downstream;
};
struct tfe_proxy_rate_limit_options
{
unsigned int read_rate;
unsigned int read_burst;
unsigned int write_rate;
unsigned int write_burst;
};
struct tfe_proxy_accept_para
{
/* Both upstream and downstream FDs */
evutil_socket_t upstream_fd;
evutil_socket_t downstream_fd;
/* Session Type */
bool is_set_session_type;
enum tfe_stream_proto session_type;
bool passthrough;
/* addition info */
unsigned int keyring_id;
};
struct tfe_proxy
{
char name[TFE_SYMBOL_MAX];
struct event_base * evbase;
struct event * sev[8];
struct event * gcev;
void * logger;
void * fs_handle;
unsigned int nr_work_threads;
struct tfe_thread_ctx * work_threads[TFE_THREAD_MAX];
/* buffer options */
unsigned int buffer_output_limit;
unsigned int nr_modules;
struct tfe_plugin * modules;
struct ssl_mgr * ssl_mgr_handler;
struct ssl_policy_enforcer* ssl_ply_enforcer;
struct key_keeper * key_keeper_handler;
struct kni_acceptor * kni_acceptor_handler;
/* DEBUG OPTIONS */
unsigned int tcp_all_passthrough;
struct tfe_proxy_tcp_options tcp_options;
/* GLOBAL RATELIMIT */
unsigned int en_rate_limit;
struct tfe_proxy_rate_limit_options rate_limit_options;
/* PERFOMANCE MONIOTR VARIABLES*/
long long stat_val[TFE_STAT_MAX];
int fs_id[TFE_STAT_MAX];
};
extern struct tfe_proxy * g_default_proxy;
#define TFE_PROXY_STAT_INCREASE(field, val) \
do { __atomic_fetch_add(&g_default_proxy->stat_val[field], val, __ATOMIC_RELAXED); } while(0)
struct tfe_thread_ctx * tfe_proxy_thread_ctx_acquire(struct tfe_proxy * ctx);
void tfe_proxy_thread_ctx_release(struct tfe_thread_ctx * thread_ctx);
struct tfe_proxy * tfe_proxy_new(const char * profile);
int tfe_proxy_fds_accept(struct tfe_proxy * ctx, const struct tfe_proxy_accept_para * para);
void tfe_proxy_run(struct tfe_proxy * proxy);