summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-04-20 19:15:01 +0800
committeryangwei <[email protected]>2024-04-21 01:53:13 +0800
commitad61166674e0349048bdaf44fa7e2fb89c299cf0 (patch)
treebe34c0824a32a32bc0897b30bf67ad55daaa718f
parent0ed228dcf6f2f8524ed054e28b4aa838438436cd (diff)
Revert "✨ feat(bloom library): choose in sapp.toml"
This reverts commit 97cc3158b48973d96d451fc9cc52011ccba43d16.
-rw-r--r--CMakeLists.txt2
-rw-r--r--bin/etc/sapp.toml3
-rw-r--r--include/private/sapp_global_val.h9
-rw-r--r--src/config/config_parse.cpp9
-rw-r--r--src/dealpkt/duplicate_pkt_distinguish.c105
-rw-r--r--src/entry/CMakeLists.txt2
6 files changed, 40 insertions, 90 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 451ff7a..7233696 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -203,7 +203,7 @@ set(SAPP_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load MESA_htable MESA_fiel
set(SAPP_INNER_STATIC_LIB sapp_dev dealpkt packet_io packet_io_pcap packet_io_marsio common
config inline_keepalive gdev_assistant sapp_assistant sapp_metrics plugctrl project timer
md5 symbol_check tomlc99_wrap MESA_socket_wrap timestamp_record
- MESA_sleep dpdk_ip_hash cpu_limit timeout ap_bloom libdabloom token_bucket)
+ MESA_sleep dpdk_ip_hash cpu_limit timeout ap_bloom token_bucket)
if(LIBEVENT_ENABLED)
set(SAPP_INNER_STATIC_LIB ${SAPP_INNER_STATIC_LIB} libevent-static)
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index ed4d3a6..79c5f5b 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -128,9 +128,6 @@
bloom_capacity=10000000
bloom_error_rate=0.0000001
bloom_timeout=60
- bloom_slice_num=3
- # 0:disable bloom filter, 1:dabloom, 2:apbloom
- bloom_library=1
[STREAM]
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index bb7905f..b02c654 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -209,22 +209,15 @@ typedef struct{
}sapp_config_packet_io_tunnel_t;
-enum bloom_library{
- BLOOM_LIBRARY_NONE=0,
- BLOOM_LIBRARY_DABLOOM,
- BLOOM_LIBRARY_APBLOOM,
-};
-
typedef struct{
int kickout_udp_stream_enabled;
int dup_pkt_distinguish_all_inject;
int dup_pkt_distinguish_ipv4_tcp;
int dup_pkt_distinguish_ipv4_udp;
int bloom_capacity;
+ double bloom_error_rate;
int bloom_timeout;
int bloom_slice_num;
- enum bloom_library bloom_library;
- double bloom_error_rate;
}sapp_dup_pkt_t;
typedef struct{
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index 21ea84f..aaab7f9 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -1734,11 +1734,10 @@ int sapp_parse_config(void)
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.original", (char *)"original_ipv4_udp_enabled", &pconfig->packet_io.dup_pkt_para.dup_pkt_distinguish_ipv4_udp, 0);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.traffic.inject", (char *)"inject_all_enabled", &pconfig->packet_io.dup_pkt_para.dup_pkt_distinguish_all_inject, 0);
- tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_capacity", &pconfig->packet_io.dup_pkt_para.bloom_capacity, 10000000);
- tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_timeout", &pconfig->packet_io.dup_pkt_para.bloom_timeout, 60);
- tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_slice_num", &pconfig->packet_io.dup_pkt_para.bloom_slice_num, 3);
- tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_library", (int *)&pconfig->packet_io.dup_pkt_para.bloom_library, 1);//defaut bloom_library dabloom
- tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_error_rate", str_tmp, sizeof(str_tmp), "0.000001");
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_capacity", &pconfig->packet_io.dup_pkt_para.bloom_capacity, 1000000);
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_timeout", &pconfig->packet_io.dup_pkt_para.bloom_timeout, 10);
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_slice_num", &pconfig->packet_io.dup_pkt_para.bloom_slice_num, 10);
+ tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"dup_pkt.parameter", (char *)"bloom_error_rate", str_tmp, sizeof(str_tmp), "0.00001");
pconfig->packet_io.dup_pkt_para.bloom_error_rate = strtod(str_tmp, NULL);
/******************************* packet_io.under_ddos ******************************/
diff --git a/src/dealpkt/duplicate_pkt_distinguish.c b/src/dealpkt/duplicate_pkt_distinguish.c
index a81a04c..75e12ba 100644
--- a/src/dealpkt/duplicate_pkt_distinguish.c
+++ b/src/dealpkt/duplicate_pkt_distinguish.c
@@ -6,7 +6,6 @@ extern "C" {
#include "sapp_declaration.h"
#include "ap_bloom.h"
-#include "dablooms.h"
/*
识别因路由策略导致的重复流量, 首次收到数据包加入bloom filter,
@@ -27,63 +26,6 @@ extern "C" {
*/
-static inline void *bloom_new(const sapp_dup_pkt_t *dup_conf, struct timeval now)
-{
- switch(dup_conf->bloom_library)
- {
- case BLOOM_LIBRARY_APBLOOM:
- return AP_bloom_new(now, dup_conf->bloom_error_rate, dup_conf->bloom_capacity, dup_conf->bloom_timeout*1000, dup_conf->bloom_slice_num);
- case BLOOM_LIBRARY_DABLOOM:
- return expiry_dablooms_init(dup_conf->bloom_capacity, dup_conf->bloom_error_rate, now.tv_sec, dup_conf->bloom_timeout);
- default:
- return NULL;
- }
-}
-
-static inline void bloom_free(void *bloom_filter, const sapp_dup_pkt_t *dup_conf)
-{
- switch(dup_conf->bloom_library)
- {
- case BLOOM_LIBRARY_APBLOOM:
- AP_bloom_free(bloom_filter);
- case BLOOM_LIBRARY_DABLOOM:
- expiry_dablooms_destroy(bloom_filter);
- default:
- break;
- }
- return;
-}
-
-static inline int bloom_check(void *bloom_filter, const char *key, int key_len, const sapp_dup_pkt_t *dup_conf, struct timeval now)
-{
- switch(dup_conf->bloom_library)
- {
- case BLOOM_LIBRARY_APBLOOM:
- return AP_bloom_check((const struct AP_bloom *)bloom_filter,
- now, (const char *)key, key_len);
- case BLOOM_LIBRARY_DABLOOM:
- return expiry_dablooms_search((struct expiry_dablooms_handle *)bloom_filter,
- (const char *)key, key_len, (time_t)now.tv_sec);
- default:
- return 0;
- }
-}
-
-static inline void bloom_add(void *bloom_filter, const char *key, int key_len, const sapp_dup_pkt_t *dup_conf, struct timeval now)
-{
- switch(dup_conf->bloom_library)
- {
- case BLOOM_LIBRARY_APBLOOM:
- AP_bloom_add((struct AP_bloom *)bloom_filter,
- now, (const char *)key, key_len);
- case BLOOM_LIBRARY_DABLOOM:
- expiry_dablooms_add((struct expiry_dablooms_handle *)bloom_filter,
- (const char *)key, key_len, (time_t)now.tv_sec);
- default:
- break;
- }
- return;
-}
int sapp_dup_stream_search(struct streaminfo *a_stream)
{
@@ -100,11 +42,13 @@ int sapp_dup_stream_search(struct streaminfo *a_stream)
key_len=sizeof(struct stream_tuple4_v6);
}
- struct timeval now={g_CurrentTime, 0};
- return bloom_check(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now);
+ struct timeval now;
+ now.tv_sec = g_CurrentTime;
+ now.tv_usec=0;
+ return AP_bloom_check((const struct AP_bloom *)sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle,
+ now, (const char *)key, key_len);
}
-
void sapp_dup_stream_add(struct streaminfo *a_stream)
{
void *key=NULL;
@@ -119,8 +63,13 @@ void sapp_dup_stream_add(struct streaminfo *a_stream)
key = (void *)a_stream->addr.tuple4_v6;
key_len=sizeof(struct stream_tuple4_v6);
}
- struct timeval now={g_CurrentTime, 0};
- bloom_add(sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle, key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now);
+ struct timeval now;
+ now.tv_sec = g_CurrentTime;
+ now.tv_usec=0;
+ AP_bloom_add(
+ (struct AP_bloom *)sapp_global_val->mthread_volatile[a_stream->threadnum]->dup_pkt_distinguish_handle,
+ now,
+ (const char *)key, key_len);
}
static inline int sapp_set_dup_pkt_key(enum addr_type_t addr_type, enum stream_type_t stream_type, const void *iphdr,
@@ -178,15 +127,19 @@ int sapp_dup_pkt_identify(int tid, struct streaminfo_private *pstream_pr,
{
int is_dup_pkt = 0;
union sapp_dup_pkt_key dup_bloom_key;
- struct timeval now={g_CurrentTime, 0};
+ struct timeval now;
+ now.tv_sec = g_CurrentTime;
+ now.tv_usec=0;
size_t key_len = sapp_set_dup_pkt_key((enum addr_type_t)pstream_pr->stream_public.addr.addrtype, (enum stream_type_t)pstream_pr->stream_public.type, ip_hdr, (void *)l4_hdr, &dup_bloom_key);
- is_dup_pkt= bloom_check(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now);
+ is_dup_pkt= AP_bloom_check((const struct AP_bloom *)sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle,
+ now, (const char *)&dup_bloom_key, key_len);
if(is_dup_pkt != 0){
pstream_pr->has_duplicate_pkt = 1;
}else{
if(need_add_bloom_filter){
- bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now);
+ AP_bloom_add((struct AP_bloom *)sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle,
+ now, (const char *)&dup_bloom_key, key_len);
}
}
return is_dup_pkt;
@@ -197,9 +150,14 @@ void sapp_dup_pkt_mark_l4(struct streaminfo *a_stream, const void *ip_hdr, const
union sapp_dup_pkt_key dup_bloom_key;
size_t key_len = 0;
int ret = 0;
- struct timeval now={g_CurrentTime, 0};
+ struct timeval now;
+ now.tv_sec = g_CurrentTime;
+ now.tv_usec=0;
key_len = sapp_set_dup_pkt_key((enum addr_type_t)a_stream->addr.addrtype, (enum stream_type_t)a_stream->type, ip_hdr, l4_hdr, &dup_bloom_key);
- bloom_add(sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle, (const char*)&dup_bloom_key, key_len, &sapp_global_val->config.packet_io.dup_pkt_para, now);
+ AP_bloom_add(
+ (struct AP_bloom *)sapp_global_val->mthread_volatile[tid]->dup_pkt_distinguish_handle,
+ now, (const char *)&dup_bloom_key, key_len);
+
return;
}
@@ -218,14 +176,17 @@ int sapp_dup_pkt_init(void)
/* 流量入口有三个开关, 识别句柄只有一个,
拆分句柄多耗费内存, 且判断时每个包需要扫描多个句柄,
可能好处只是准确率高了一点点而已 */
- struct timeval now={time(NULL), 0};
+ struct timeval now;
+ now.tv_sec = time(NULL);
+ now.tv_usec=0;
for(i = 0; i < sapp_global_val->config.cpu.worker_threads; i++){
- sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle = bloom_new(p_dup_conf, now);
+ sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle = (void *)AP_bloom_new(now, p_dup_conf->bloom_error_rate, p_dup_conf->bloom_capacity, p_dup_conf->bloom_timeout*1000, p_dup_conf->bloom_slice_num);
if(NULL == sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle){
sapp_log(RLOG_LV_FATAL, 1, 1, "dup_pkt_distinguish init error!");
return -1;
}
}
+
sapp_log(RLOG_LV_DEBUG, 1, 1, "dup_pkt_distinguish init success");
return 0;
@@ -234,10 +195,10 @@ int sapp_dup_pkt_init(void)
void sapp_dup_pkt_destroy(void)
{
int i;
- const sapp_dup_pkt_t *p_dup_conf = &sapp_global_val->config.packet_io.dup_pkt_para;
+
for(i = 0; i < sapp_global_val->config.cpu.worker_threads; i++){
if(sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle){
- bloom_free(sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle,p_dup_conf);
+ AP_bloom_free(sapp_global_val->mthread_volatile[i]->dup_pkt_distinguish_handle);
}
}
diff --git a/src/entry/CMakeLists.txt b/src/entry/CMakeLists.txt
index 66f8e8c..16cf2cc 100644
--- a/src/entry/CMakeLists.txt
+++ b/src/entry/CMakeLists.txt
@@ -38,7 +38,7 @@ set(SAPP_MODULES timestamp_record md5
symbol_check MESA_sleep MESA_socket_wrap
packet_io dealpkt project plugctrl common
config timer tomlc99_wrap dpdk_ip_hash
- gdev_assistant inline_keepalive ap_bloom libdabloom
+ gdev_assistant inline_keepalive ap_bloom
sapp_dev sapp_assistant sapp_metrics
platform_support cpu_limit timeout token_bucket)