From 2a2bead767da8bf204c162ea19ffdc2c290e310c Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Thu, 29 Dec 2022 14:28:49 +0800 Subject: [PATCH] =?UTF-8?q?TSG-13196=20Decrypted=20Traffic=20Steering?= =?UTF-8?q?=E6=97=B6=E7=85=A7=E5=B8=B8=E7=BB=9F=E8=AE=A1intercept=20bytes?= =?UTF-8?q?=20=20=20=20=20*=20STAT=5FSTREAM=5FINCPT=5FDOWN=5FBYTES=20=20?= =?UTF-8?q?=20=20=20*=20STAT=5FSTREAM=5FINCPT=5FUP=5FBYTES=20=20=20=20=20*?= =?UTF-8?q?=20STAT=5FSTREAM=5FINCPT=5FBYTES?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/tcp_stream.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/platform/src/tcp_stream.cpp b/platform/src/tcp_stream.cpp index 01b77c0..70cdb1a 100644 --- a/platform/src/tcp_stream.cpp +++ b/platform/src/tcp_stream.cpp @@ -597,21 +597,19 @@ static void __stream_bev_readcb(struct bufferevent * bev, void * arg) struct tfe_conn_private * peer_conn = NULL; struct evbuffer * inbuf = NULL; 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))) { - enum TFE_STAT_FIELD stat_filed = TFE_STAT_MAX; if (bev == _stream->conn_downstream->bev) { peer_conn = _stream->conn_fake_c; - stat_filed = STAT_STEERING_CLIENT_TX_B; } else if (bev == _stream->conn_upstream->bev) { peer_conn = _stream->conn_fake_s; - stat_filed = STAT_STEERING_SERVER_TX_B; } else { @@ -623,22 +621,39 @@ static void __stream_bev_readcb(struct bufferevent * bev, void * arg) * This connection will be destoryed in __event_cb */ inbuf = bufferevent_get_input(bev); + inbuff_len = evbuffer_get_length(inbuf); if (peer_conn == NULL) { - evbuffer_drain(inbuf, evbuffer_get_length(inbuf)); + evbuffer_drain(inbuf, inbuff_len); return; } TFE_LOG_DEBUG(__STREAM_LOGGER(_stream), "decrypted traffic steering, %s send %d bytes from %s to %s", _stream->str_stream_addr, - evbuffer_get_length(inbuf), + inbuff_len, bev == _stream->conn_downstream->bev ? "conn_downstream" : "conn_upstream", bev == _stream->conn_downstream->bev ? "conn_fake_c" : "conn_fake_s"); - TFE_PROXY_STAT_INCREASE(stat_filed, evbuffer_get_length(inbuf)); outbuf = bufferevent_get_output(peer_conn->bev); evbuffer_add_buffer(outbuf, inbuf); + if (bev == _stream->conn_downstream->bev) + { + TFE_PROXY_STAT_INCREASE(STAT_STEERING_CLIENT_TX_B, inbuff_len); + // TODO: Delete the following code when support calling the tfe-plugin + TFE_PROXY_STAT_INCREASE(STAT_STREAM_INCPT_DOWN_BYTES, inbuff_len); + _stream->downstream_rx_offset += inbuff_len; + } + else + { + TFE_PROXY_STAT_INCREASE(STAT_STEERING_SERVER_TX_B, inbuff_len); + // TODO: Delete the following code when support calling the tfe-plugin + TFE_PROXY_STAT_INCREASE(STAT_STREAM_INCPT_UP_BYTES, inbuff_len); + _stream->upstream_rx_offset += inbuff_len; + } + + // TODO: Delete the following code when support calling the tfe-plugin + TFE_PROXY_STAT_INCREASE(STAT_STREAM_INCPT_BYTES, inbuff_len); return; }