diff --git a/platform/include/internal/platform.h b/platform/include/internal/platform.h index 9248009..3ecfd87 100644 --- a/platform/include/internal/platform.h +++ b/platform/include/internal/platform.h @@ -153,6 +153,9 @@ struct tfe_stream_private /* OFFSET FOR LOG */ size_t downstream_rx_offset; size_t upstream_rx_offset; + + /* Decrypted Traffic Steering */ + bool is_decrypted_traffic_steering; }; static inline void * __STREAM_LOGGER(struct tfe_stream_private * _stream) diff --git a/platform/src/tcp_stream.cpp b/platform/src/tcp_stream.cpp index 279173b..46c0b33 100644 --- a/platform/src/tcp_stream.cpp +++ b/platform/src/tcp_stream.cpp @@ -634,9 +634,7 @@ static void __stream_bev_readcb(struct bufferevent * bev, void * arg) struct evbuffer * outbuf = NULL; int inbuff_len = 0; - if (steering_device_is_available() && ( - (STREAM_PROTO_PLAIN == _stream->session_type && _stream->proxy_ref->traffic_steering_options.enable_steering_http) || - (STREAM_PROTO_SSL == _stream->session_type &&_stream->proxy_ref->traffic_steering_options.enable_steering_ssl))) + if (_stream->is_decrypted_traffic_steering) { if (bev == _stream->conn_downstream->bev) { @@ -846,9 +844,7 @@ static void __stream_bev_writecb(struct bufferevent * bev, void * arg) struct tfe_conn_private ** ref_peer_conn{}; struct ssl_stream ** ref_this_ssl_stream{}; - if (steering_device_is_available() && ( - (STREAM_PROTO_PLAIN == _stream->session_type && _stream->proxy_ref->traffic_steering_options.enable_steering_http) || - (STREAM_PROTO_SSL == _stream->session_type &&_stream->proxy_ref->traffic_steering_options.enable_steering_ssl))) + if (_stream->is_decrypted_traffic_steering) { // TODO 增加计数 TFE_LOG_DEBUG(__STREAM_LOGGER(_stream), "decrypted traffic steering, %s %s run writecb", @@ -985,9 +981,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void * need_close_connection = 1; } - if (steering_device_is_available() && ( - (STREAM_PROTO_PLAIN == _stream->session_type && _stream->proxy_ref->traffic_steering_options.enable_steering_http) || - (STREAM_PROTO_SSL == _stream->session_type &&_stream->proxy_ref->traffic_steering_options.enable_steering_ssl))) + if (_stream->is_decrypted_traffic_steering) { TFE_LOG_DEBUG(__STREAM_LOGGER(_stream), "decrypted traffic steering, %s %s run eventcb, %s %s", _stream->str_stream_addr, @@ -1251,7 +1245,7 @@ void ssl_downstream_create_on_success(future_result_t * result, void * user) __conn_private_enable(_stream->conn_downstream); __conn_private_enable(_stream->conn_upstream); - if (steering_device_is_available() && _stream->proxy_ref->traffic_steering_options.enable_steering_ssl) + if (_stream->is_decrypted_traffic_steering) { __conn_private_enable(_stream->conn_fake_c); __conn_private_enable(_stream->conn_fake_s); @@ -1771,6 +1765,11 @@ int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downst _stream->fd_fake_c = fd_fake_c; _stream->fd_fake_s = fd_fake_s; + if (fd_fake_c > 0 && fd_fake_s > 0) + { + _stream->is_decrypted_traffic_steering = 1; + } + _stream->head.addr = tfe_stream_addr_create_by_fd(fd_downstream, CONN_DIR_DOWNSTREAM); if (unlikely(_stream->head.addr == NULL)) { @@ -1784,10 +1783,7 @@ int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downst __stream_fd_option_setup(_stream, fd_downstream, CONN_DIR_DOWNSTREAM); __stream_fd_option_setup(_stream, fd_upstream, CONN_DIR_UPSTREAM); - if (steering_device_is_available() && ( - (STREAM_PROTO_PLAIN == _stream->session_type && _stream->proxy_ref->traffic_steering_options.enable_steering_http) || - (STREAM_PROTO_SSL == _stream->session_type &&_stream->proxy_ref->traffic_steering_options.enable_steering_ssl) - )) + if (_stream->is_decrypted_traffic_steering) { __stream_fd_option_setup(_stream, fd_fake_s, CONN_DIR_DOWNSTREAM); __stream_fd_option_setup(_stream, fd_fake_c, CONN_DIR_UPSTREAM); @@ -1838,7 +1834,7 @@ int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downst __conn_private_enable(_stream->conn_downstream); __conn_private_enable(_stream->conn_upstream); - if (steering_device_is_available() && _stream->proxy_ref->traffic_steering_options.enable_steering_http) + if (_stream->is_decrypted_traffic_steering) { __conn_private_enable(_stream->conn_fake_s); __conn_private_enable(_stream->conn_fake_c);