From a2a4c323848e4cc4eef29c065377d31577d92c77 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Fri, 30 Dec 2022 15:53:16 +0800 Subject: [PATCH] =?UTF-8?q?TSG-13204=20Decrypted=20Traffic=20Steering?= =?UTF-8?q?=E9=80=82=E9=85=8D=E7=AC=AC=E4=B8=89=E6=96=B9=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E5=88=87=E6=8D=A2=20->=20=E5=BD=93?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E8=AE=BE=E5=A4=87=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BB=8E=E5=8F=AF=E7=94=A8=E5=8F=98=E4=B8=BA=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E6=97=B6=20=20=20=20=20*=20=E5=BD=93?= =?UTF-8?q?=E5=89=8DStream=E4=BE=9D=E7=84=B6=E6=8C=89=E7=85=A7Steering?= =?UTF-8?q?=E7=9A=84=E6=B5=81=E7=A8=8B=E5=A4=84=E7=90=86=EF=BC=8C=E4=BB=8E?= =?UTF-8?q?eventcb=E4=B8=AD=E9=80=80=E5=87=BA=20=20=20=20=20*=20=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=96=B0=E7=9A=84Stream=E5=BC=80=E5=A7=8BUnS?= =?UTF-8?q?teering=20->=20=E5=BD=93=E7=AC=AC=E4=B8=89=E6=96=B9=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=9A=84=E7=8A=B6=E6=80=81=E4=BB=8E=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E5=8F=98=E4=B8=BA=E5=8F=AF=E7=94=A8=E6=97=B6=20=20=20?= =?UTF-8?q?=20=20*=20=E5=BD=93=E5=89=8DStream=E4=BE=9D=E7=84=B6=E6=8C=89?= =?UTF-8?q?=E7=85=A7UnSteering=E7=9A=84=E6=B5=81=E7=A8=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86=20=20=20=20=20*=20=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=96=B0Stream=E5=BC=80=E5=A7=8BSteering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/include/internal/platform.h | 3 +++ platform/src/tcp_stream.cpp | 26 +++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) 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);