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);