From 2a5b6803f2695b852047a1db25af6985f205653e Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Fri, 27 Dec 2019 09:40:26 +0800 Subject: [PATCH] =?UTF-8?q?#179=20traffic=5Fmirror=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20enable/disable=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E4=BD=86=E6=98=AF=E5=BD=93=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=20disable=20=E6=97=B6=EF=BC=8Ctraffic=5Fmirror=5Finit?= =?UTF-8?q?=5Fcb()=20return=20-1=EF=BC=8Ctfe=20=E7=9B=B4=E6=8E=A5=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../traffic-mirror/include/traffic_mirror.h | 1 + plugin/business/traffic-mirror/src/entry.cpp | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugin/business/traffic-mirror/include/traffic_mirror.h b/plugin/business/traffic-mirror/include/traffic_mirror.h index fdda9d6..d9828e1 100644 --- a/plugin/business/traffic-mirror/include/traffic_mirror.h +++ b/plugin/business/traffic-mirror/include/traffic_mirror.h @@ -21,6 +21,7 @@ enum traffic_mirror_target_addr_type struct traffic_mirror_instance { void * logger; + unsigned int enable; unsigned int nr_threads; Maat_feather_t maat_feather; diff --git a/plugin/business/traffic-mirror/src/entry.cpp b/plugin/business/traffic-mirror/src/entry.cpp index b3aa60d..c338698 100644 --- a/plugin/business/traffic-mirror/src/entry.cpp +++ b/plugin/business/traffic-mirror/src/entry.cpp @@ -480,19 +480,17 @@ int traffic_mirror_init(struct tfe_proxy * proxy) { int result = 0; struct traffic_mirror_instance * instance = g_traffic_mirror_instance; + instance->logger = tfe_proxy_get_error_logger(); /* Using PANGU-HTTP's profile */ - unsigned int is_enable = 1; - MESA_load_profile_uint_def("./conf/tfe/tfe.conf", "traffic_mirror", "enable", &is_enable, 1); - - if (!is_enable) + MESA_load_profile_uint_def("./conf/tfe/tfe.conf", "traffic_mirror", "enable", &(instance->enable), 1); + if (!instance->enable) { TFE_LOG_INFO(instance->logger, "traffic_mirror is disabled."); - return -1; + return 0; } /* INIT DECRYPT MIRROR INSTANCE */ - instance->logger = tfe_proxy_get_error_logger(); instance->nr_threads = tfe_proxy_get_work_thread_count(); /* MAAT Feather, the configuration is same with pangu-http */ @@ -559,6 +557,10 @@ int traffic_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thr /* Firstly, fetch destination address of traffic mirror */ struct traffic_mirror_me * me = NULL; struct traffic_mirror_instance * instance = g_traffic_mirror_instance; + if (!instance->enable) + { + return ACTION_FORWARD_DATA; + } struct tfe_cmsg * cmsg = tfe_stream_get0_cmsg(stream); unsigned int target_id; @@ -677,6 +679,11 @@ detach: enum tfe_stream_action traffic_mirror_on_data_cb(const struct tfe_stream * stream, unsigned int thread_id, enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme) { + struct traffic_mirror_instance * instance = g_traffic_mirror_instance; + if (!instance->enable) + { + return ACTION_FORWARD_DATA; + } struct traffic_mirror_me * me = (struct traffic_mirror_me *)(*pme); /* Rx offset of this callback */ @@ -737,6 +744,12 @@ errout: void traffic_mirror_on_close_cb(const struct tfe_stream * stream, unsigned int thread_id, enum tfe_stream_close_reason reason, void ** pme) { + struct traffic_mirror_instance * instance = g_traffic_mirror_instance; + if (!instance->enable) + { + return; + } + struct traffic_mirror_me * me = (struct traffic_mirror_me *)(*pme); traffic_mirror_rebuild_farewell(me->rebuild_ctx, thread_id); traffic_mirror_rebuild_destroy(me->rebuild_ctx);