2018-08-23 11:23:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <tfe_stream.h>
|
|
|
|
|
#include <event2/event.h>
|
2019-06-02 16:29:43 +08:00
|
|
|
#include <sender_scm.h>
|
2019-05-20 15:08:42 +08:00
|
|
|
#include <ssl_stream_core.h>
|
2022-12-06 15:01:42 +08:00
|
|
|
#include <net/if.h>
|
2023-04-23 16:35:42 +08:00
|
|
|
#include <intercept_policy.h>
|
2018-08-27 21:10:45 +08:00
|
|
|
|
|
|
|
|
struct ssl_mgr;
|
|
|
|
|
struct key_keeper;
|
2019-06-02 13:49:44 +08:00
|
|
|
struct acceptor_kni_v2;
|
2019-06-18 16:09:20 +08:00
|
|
|
struct watchdog_kni;
|
2019-08-20 18:41:44 +08:00
|
|
|
struct breakpad_instance;
|
2018-11-02 13:52:30 +08:00
|
|
|
|
2018-10-05 14:34:51 +08:00
|
|
|
enum TFE_STAT_FIELD
|
2018-11-02 13:52:30 +08:00
|
|
|
{
|
2018-10-05 14:34:51 +08:00
|
|
|
STAT_SIGPIPE,
|
2018-11-02 13:52:30 +08:00
|
|
|
/* FDs */
|
|
|
|
|
STAT_FD_OPEN_BY_KNI_ACCEPT,
|
|
|
|
|
STAT_FD_CLOSE_BY_KNI_ACCEPT_FAIL,
|
2019-09-16 16:40:31 +08:00
|
|
|
STAT_FD_CLOSE,
|
2019-08-13 19:50:51 +08:00
|
|
|
|
2018-11-02 13:52:30 +08:00
|
|
|
/* Stream */
|
2018-12-14 03:06:34 +06:00
|
|
|
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,
|
|
|
|
|
|
2019-09-16 16:40:31 +08:00
|
|
|
/* Action */
|
|
|
|
|
STAT_STREAM_INTERCEPT,
|
|
|
|
|
STAT_STREAM_BYPASS,
|
|
|
|
|
STAT_STREAM_INCPT_BYTES,
|
|
|
|
|
STAT_STREAM_INCPT_DOWN_BYTES,
|
|
|
|
|
STAT_STREAM_INCPT_UP_BYTES,
|
|
|
|
|
|
|
|
|
|
/* Protocol */
|
2018-11-02 13:52:30 +08:00
|
|
|
STAT_STREAM_TCP_PLAIN,
|
|
|
|
|
STAT_STREAM_TCP_SSL,
|
2022-12-29 10:24:02 +08:00
|
|
|
|
|
|
|
|
/* Decrypted Traffic Steering */
|
|
|
|
|
STAT_STEERING_SSL_CONN,
|
|
|
|
|
STAT_STEERING_HTTP_CONN,
|
|
|
|
|
STAT_STEERING_CLIENT_TX_B,
|
|
|
|
|
STAT_STEERING_SERVER_RX_B,
|
|
|
|
|
STAT_STEERING_SERVER_TX_B,
|
|
|
|
|
STAT_STEERING_CLIENT_RX_B,
|
|
|
|
|
STAT_STEERING_CLIENT_ERR,
|
|
|
|
|
STAT_STEERING_SERVER_ERR,
|
|
|
|
|
STAT_STEERING_CLIENT_EOF,
|
|
|
|
|
STAT_STEERING_SERVER_EOF,
|
|
|
|
|
|
2018-10-05 14:34:51 +08:00
|
|
|
TFE_STAT_MAX
|
|
|
|
|
};
|
2018-08-27 21:10:45 +08:00
|
|
|
|
2018-09-21 16:11:54 +08:00
|
|
|
struct tfe_proxy_tcp_options
|
|
|
|
|
{
|
2018-11-08 19:14:47 +08:00
|
|
|
/* TCP OPTIONS */
|
2018-09-21 16:11:54 +08:00
|
|
|
int sz_rcv_buffer;
|
|
|
|
|
int sz_snd_buffer;
|
2020-07-21 20:00:14 +08:00
|
|
|
|
|
|
|
|
/* TRACE FOR DEBUG */
|
|
|
|
|
int enable_overwrite;
|
|
|
|
|
int tcp_nodelay;
|
2018-09-21 16:11:54 +08:00
|
|
|
int so_keepalive;
|
2020-07-21 20:00:14 +08:00
|
|
|
int tcp_keepidle;
|
|
|
|
|
int tcp_keepintvl;
|
|
|
|
|
int tcp_keepcnt;
|
|
|
|
|
int tcp_user_timeout;
|
2018-11-08 19:14:47 +08:00
|
|
|
|
2020-07-21 20:00:14 +08:00
|
|
|
int tcp_ttl_upstream;
|
|
|
|
|
int tcp_ttl_downstream;
|
2018-09-21 16:11:54 +08:00
|
|
|
};
|
|
|
|
|
|
2022-12-06 15:01:42 +08:00
|
|
|
struct tfe_traffic_steering_options
|
|
|
|
|
{
|
2022-12-20 14:49:53 +08:00
|
|
|
int enable_steering_http;
|
|
|
|
|
int enable_steering_ssl;
|
2022-12-06 15:01:42 +08:00
|
|
|
int so_mask_client;
|
|
|
|
|
int so_mask_server;
|
|
|
|
|
char device_client[IFNAMSIZ];
|
|
|
|
|
char device_server[IFNAMSIZ];
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-08 20:48:19 +06:00
|
|
|
struct tfe_proxy_rate_limit_options
|
|
|
|
|
{
|
|
|
|
|
unsigned int read_rate;
|
|
|
|
|
unsigned int read_burst;
|
|
|
|
|
unsigned int write_rate;
|
|
|
|
|
unsigned int write_burst;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-21 16:11:54 +08:00
|
|
|
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;
|
2018-10-19 19:50:27 +08:00
|
|
|
|
|
|
|
|
/* addition info */
|
|
|
|
|
unsigned int keyring_id;
|
2018-09-21 16:11:54 +08:00
|
|
|
};
|
|
|
|
|
|
2020-07-28 17:41:54 +08:00
|
|
|
enum tfe_load_balance_algo
|
|
|
|
|
{
|
|
|
|
|
LEAST_CONN = 0,
|
|
|
|
|
ROUND_ROBIN = 1,
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-27 21:10:45 +08:00
|
|
|
struct tfe_proxy
|
|
|
|
|
{
|
|
|
|
|
char name[TFE_SYMBOL_MAX];
|
|
|
|
|
struct event_base * evbase;
|
|
|
|
|
struct event * sev[8];
|
|
|
|
|
struct event * gcev;
|
|
|
|
|
|
2018-08-30 15:53:41 +08:00
|
|
|
void * logger;
|
2024-11-13 14:09:03 +08:00
|
|
|
struct fieldstat_easy *fs_handle;
|
2018-08-27 21:10:45 +08:00
|
|
|
unsigned int nr_work_threads;
|
2018-08-30 15:53:41 +08:00
|
|
|
struct tfe_thread_ctx * work_threads[TFE_THREAD_MAX];
|
2021-04-21 11:51:30 +08:00
|
|
|
int make_work_thread_sleep;
|
2018-08-27 21:10:45 +08:00
|
|
|
|
|
|
|
|
unsigned int nr_modules;
|
|
|
|
|
struct tfe_plugin * modules;
|
|
|
|
|
|
|
|
|
|
struct ssl_mgr * ssl_mgr_handler;
|
2023-04-23 16:35:42 +08:00
|
|
|
struct intercept_policy_enforcer *int_ply_enforcer;
|
2023-04-11 15:19:22 +08:00
|
|
|
struct tcp_policy_enforcer *tcp_ply_enforcer;
|
|
|
|
|
struct ssl_policy_enforcer *ssl_ply_enforcer;
|
2023-04-17 18:26:33 +08:00
|
|
|
struct chaining_policy_enforcer *chain_ply_enforcer;
|
2018-08-27 21:10:45 +08:00
|
|
|
struct key_keeper * key_keeper_handler;
|
2019-06-02 13:49:44 +08:00
|
|
|
|
2024-09-26 14:39:21 +08:00
|
|
|
//unsigned int en_kni_v1_acceptor;
|
|
|
|
|
//unsigned int en_kni_v2_acceptor;
|
|
|
|
|
//unsigned int en_kni_v3_acceptor;
|
|
|
|
|
//unsigned int en_kni_v4_acceptor;
|
|
|
|
|
|
|
|
|
|
//struct acceptor_kni_v1 * kni_v1_acceptor;
|
|
|
|
|
//struct acceptor_kni_v2 * kni_v2_acceptor;
|
|
|
|
|
//struct acceptor_kni_v3 * kni_v3_acceptor;
|
2023-04-18 16:03:57 +08:00
|
|
|
struct acceptor_kni_v4 * kni_v4_acceptor;
|
2019-06-02 16:29:43 +08:00
|
|
|
struct sender_scm * scm_sender;
|
2019-06-18 16:09:20 +08:00
|
|
|
struct watchdog_kni * watchdog_kni;
|
2021-08-20 11:32:33 +08:00
|
|
|
struct watchdog_tfe * watchdog_tfe;
|
2022-12-19 14:14:30 +08:00
|
|
|
struct watchdog_3rd_device * watchdog_3rd_device;
|
2018-08-30 15:53:41 +08:00
|
|
|
|
2018-09-21 16:11:54 +08:00
|
|
|
/* DEBUG OPTIONS */
|
2018-08-30 15:53:41 +08:00
|
|
|
unsigned int tcp_all_passthrough;
|
2018-09-21 16:11:54 +08:00
|
|
|
struct tfe_proxy_tcp_options tcp_options;
|
2018-10-05 14:34:51 +08:00
|
|
|
|
2018-12-08 20:48:19 +06:00
|
|
|
/* GLOBAL RATELIMIT */
|
|
|
|
|
unsigned int en_rate_limit;
|
|
|
|
|
struct tfe_proxy_rate_limit_options rate_limit_options;
|
|
|
|
|
|
2018-10-05 14:34:51 +08:00
|
|
|
/* PERFOMANCE MONIOTR VARIABLES*/
|
|
|
|
|
long long stat_val[TFE_STAT_MAX];
|
|
|
|
|
int fs_id[TFE_STAT_MAX];
|
2019-08-20 18:41:44 +08:00
|
|
|
|
|
|
|
|
/* Crash Report */
|
|
|
|
|
struct breakpad_instance * breakpad;
|
2020-07-28 16:43:37 +08:00
|
|
|
|
|
|
|
|
/* cpu affinity */
|
|
|
|
|
unsigned int enable_cpu_affinity;
|
|
|
|
|
unsigned int cpu_affinity_mask[TFE_THREAD_MAX];
|
2020-07-28 17:41:54 +08:00
|
|
|
|
|
|
|
|
/* load balancing */
|
|
|
|
|
enum tfe_load_balance_algo load_balance;
|
2022-12-06 15:01:42 +08:00
|
|
|
|
|
|
|
|
struct tfe_traffic_steering_options traffic_steering_options;
|
2018-08-27 21:10:45 +08:00
|
|
|
};
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-11-02 13:52:30 +08:00
|
|
|
extern struct tfe_proxy * g_default_proxy;
|
2023-05-31 19:41:18 +08:00
|
|
|
extern int worker_thread_ready;
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-11-02 13:52:30 +08:00
|
|
|
#define TFE_PROXY_STAT_INCREASE(field, val) \
|
|
|
|
|
do { __atomic_fetch_add(&g_default_proxy->stat_val[field], val, __ATOMIC_RELAXED); } while(0)
|
2018-08-23 11:23:05 +08:00
|
|
|
|
2018-08-30 15:53:41 +08:00
|
|
|
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);
|
|
|
|
|
|
2018-08-23 11:23:05 +08:00
|
|
|
struct tfe_proxy * tfe_proxy_new(const char * profile);
|
2022-12-06 15:01:42 +08:00
|
|
|
int tfe_proxy_fds_accept(struct tfe_proxy * ctx, int fd_downstream, int fd_upstream, int fd_fake_c, int fd_fake_s, struct tfe_cmsg * cmsg);
|
2018-08-23 11:23:05 +08:00
|
|
|
void tfe_proxy_run(struct tfe_proxy * proxy);
|
2020-07-28 16:43:37 +08:00
|
|
|
int tfe_thread_set_affinity(int core_id);
|