summaryrefslogtreecommitdiff
path: root/src/config/config_parse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/config_parse.cpp')
-rw-r--r--src/config/config_parse.cpp135
1 files changed, 68 insertions, 67 deletions
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index f126b09..3605ec6 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -13,10 +13,10 @@ extern "C" {
extern int g_overlay_layer_set[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
/*
- 说明:
- _sapp_toml_sample_file_image数组, _sapp_toml_sample_file_image_len变量是靠命令xxd -i 自动生成的,
- 保存在动态创建的文件sapp.toml.hex.array.c里,
- 此文件无需加入git仓库.
+ ˵��:
+ _sapp_toml_sample_file_image����, _sapp_toml_sample_file_image_len�����ǿ�����xxd -i �Զ����ɵ�,
+ �����ڶ�̬�������ļ�sapp.toml.hex.array.c��,
+ ���ļ��������git�ֿ�.
*/
extern const unsigned char _sapp_toml_sample_file_image[];
extern const int _sapp_toml_sample_file_image_len;
@@ -24,14 +24,14 @@ extern const int _sapp_toml_sample_file_image_len;
#define SAPP_CFG_OBSOLETE_FLAG 99999999
typedef struct __sapp_config_check{
int global_id;
- int depend_id; /* 1:必须的参数, 不依赖其他参数, 也不能缺失; 0:可选的, 可以没有, 不影响sapp主体功能; >=1000:悬而未决的, 取决于其他配置参数是否开启, 比如transparent模式必须配置packet_io.external.interface */
- int err_log_level; /* 10,20,30, 错误日志等级 */
+ int depend_id; /* 1:����IJ���, ��������������, Ҳ����ȱʧ; 0:��ѡ��, ����û��, ��Ӱ��sapp���幦��; >=1000:����δ����, ȡ�����������ò����Ƿ���, ����transparentģʽ��������packet_io.external.interface */
+ int err_log_level; /* 10,20,30, ������־�ȼ� */
const char *section;
const char *cfg_key;
- const char *depend_cfg_value; /* 仅当depend_id>1000时有效, 表示依赖参数的值符合预先定义时, 才检查当前参数是否合法, 比如mirro模式下根本不需要检查 packet_io.external.interface */
+ const char *depend_cfg_value; /* ����depend_id>1000ʱ��Ч, ��ʾ����������ֵ����Ԥ�ȶ���ʱ, �ż�鵱ǰ�����Ƿ�Ϸ�, ����mirroģʽ�¸�������Ҫ��� packet_io.external.interface */
int (*cfg_value_check_fun)(const struct __sapp_config_check *sapp_cfg_check_attr, int this_cfg_id, int depend_cfg_id, const char *cfg_value, const void *range_array, int array_num);
char *cfg_value; /* NULL is not found */
- const void *expect_range_array; /* 用于检测参数值的可选范围数组, 根据类型的不同可以是int *, 或者是char **类型 */
+ const void *expect_range_array; /* ���ڼ�����ֵ�Ŀ�ѡ��Χ����, �������͵IJ�ͬ������int *, ������char **���� */
int expect_array_num;
}sapp_config_check_t;
@@ -46,7 +46,7 @@ static const char *sapp_cfg_get_value_from_attr_by_id(const sapp_config_check_t
static const char *sapp_cfg_get_value_from_attr_by_section_key(const sapp_config_check_t *sapp_cfg_check_attr, const char *section, const char *key);
static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check_attr,int this_cfg_id,int depend_cfg_id, const char *raw_cfg_value, const void *expect_range_array, int array_num);
-static int g_interger_range_array[65536]; /* 一个int型的数组, 数值下标和数值一样, 即 g_interger_range_array[0]=0, g_interger_range_array[1]=1, 用于判断数值参数范围合法性 */
+static int g_interger_range_array[65536]; /* һ��int�͵�����, ��ֵ�±����ֵһ��, �� g_interger_range_array[0]=0, g_interger_range_array[1]=1, �����ж���ֵ������Χ�Ϸ��� */
static int cfg_value_check_integer_range(const sapp_config_check_t *sapp_cfg_check_attr,int this_cfg_id,int depend_cfg_id, const char *raw_cfg_value, const void *expect_range_array, int array_num)
@@ -127,11 +127,11 @@ static int cfg_value_check_bind_mask(const sapp_config_check_t *sapp_cfg_check_a
long bind_mask_array[SAPP_MAX_THREADS];
int ret;
- /* 暂时没有直接解析raw_cfg_value的函数, 此处再读取一遍配置文件 */
+ /* ��ʱû��ֱ�ӽ���raw_cfg_value�ĺ���, �˴��ٶ�ȡһ�������ļ� */
ret = tomlc99_wrap_load_long_array(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", bind_mask_array, &bind_mask_array_num);
if(ret < 0){
unsigned int load_profile_array[SAPP_MAX_THREADS];
- /* 带范围的配置, 如1-10,10-20等参数使用MESA_load_profile_uint_range解析, 此时要用字符串模式!!! */
+ /* ����Χ������, ��1-10,10-20�Ȳ���ʹ��MESA_load_profile_uint_range����, ��ʱҪ���ַ���ģʽ!!! */
ret = MESA_load_profile_uint_range(
ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask",
SAPP_MAX_THREADS, (unsigned int *)load_profile_array);
@@ -143,7 +143,7 @@ static int cfg_value_check_bind_mask(const sapp_config_check_t *sapp_cfg_check_a
}
if(0 == bind_mask_array_num){
- return 0; /* 允许空数组, 即不绑定CPU,不算错误 */
+ return 0; /* ����������, ������CPU,������� */
}
const char *raw_cfg_worker_threads_value = sapp_cfg_get_value_from_attr_by_id(sapp_cfg_check_attr, depend_cfg_id);
@@ -173,7 +173,7 @@ static int cfg_value_check_stream_id_base_time(const sapp_config_check_t *sapp_c
struct tm local_tm;
if(NULL == raw_cfg_value || strlen(raw_cfg_value) == 0){
- return 0; /* 可以为NULL,不算错误 */
+ return 0; /* ����ΪNULL,������� */
}
if(strptime(raw_cfg_value, "%Y-%m-%d %H:%M:%S", &local_tm) == NULL){
@@ -207,7 +207,7 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] =
{2002,0,RLOG_LV_DEBUG, "CPU", "send_only_threads_max", NULL,NULL, NULL, NULL, 0},
{2003,2001,RLOG_LV_FATAL,"CPU", "bind_mask", "",cfg_value_check_bind_mask, NULL, NULL, 0},
- {3001,0, RLOG_LV_INFO,"MEM", "dictator_enable", NULL,cfg_value_check_integer_range, NULL, g_interger_range_array, 2}, /* 只能是0或1, 所以就用前2个元素 */
+ {3001,0, RLOG_LV_INFO,"MEM", "dictator_enable", NULL,cfg_value_check_integer_range, NULL, g_interger_range_array, 2}, /* ֻ����0��1, ���Ծ���ǰ2��Ԫ�� */
{4000,0,RLOG_LV_DEBUG,"PACKET_IO", NULL, NULL, NULL,NULL, NULL, 0},
@@ -352,7 +352,7 @@ static const sapp_config_check_t g_sapp_cfg_check_attr[] =
{9201,0,RLOG_LV_INFO, "LIBRARY_LINK", "marsio_library_path", NULL,NULL, NULL, NULL, 0},
/******************************************************************************************************************/
- /*********** 以下是历史上曾经出现过的配置, 也不算错误,也不算不支持,输出告警信息表示被废弃掉了 *********************/
+ /*********** ��������ʷ���������ֹ�������, Ҳ�������,Ҳ���㲻֧��,����澯��Ϣ��ʾ���������� *********************/
/******************************************************************************************************************/
{SAPP_CFG_OBSOLETE_FLAG,0,RLOG_LV_INFO,"overlay_tunnel_definition","stream_compare_layer_cfg_file",NULL, NULL, NULL,NULL, 0},
{SAPP_CFG_OBSOLETE_FLAG,0,RLOG_LV_INFO,"overlay_tunnel_definition","vlan_flipping_cfg_file",NULL, NULL, NULL,NULL, 0},
@@ -437,7 +437,7 @@ static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check
depend_cfg_index = cfg_get_index_by_depend_id(depend_cfg_id);
depend_cfg_value = sapp_cfg_check_attr[depend_cfg_index].cfg_value;
- /* raw_cfg_value可能是NULL, 此时应该先判断depend_cfg_value, 这个是依赖配置, 不太可能是空 */
+ /* raw_cfg_value������NULL, ��ʱӦ�����ж�depend_cfg_value, �������������, ��̫�����ǿ� */
if(strncasecmp(depend_cfg_value, "vxlan_by_inline_device", strlen("vxlan_by_inline_device")) == 0){
expect_cfg_index = cfg_get_index_by_key_name("inject_mode_inline_device_sport");
@@ -526,7 +526,7 @@ static inline int is_file_exist(const char *filename)
static void update_overlay_vxlan_layer_set(void);
-/* 对于相同类型的配置, 命令行参数优先, 覆盖sapp.toml中的配置 */
+/* ������ͬ���͵�����, �����в�������, ����sapp.toml�е����� */
void sapp_cla_override_cfg_file(void)
{
char *cmd_args;
@@ -537,7 +537,7 @@ void sapp_cla_override_cfg_file(void)
}
if (sapp_get_cla_raw("dumpfile", &cmd_args) >= 0)
- { /* dumpfile模式自动覆盖interface配置 */
+ { /* dumpfileģʽ�Զ�����interface���� */
strncpy(pconfig->packet_io.depolyment_mode_str, "dumpfile", NAME_MAX);
pconfig->packet_io.depolyment_mode_bin = DEPOLYMENT_MODE_MIRROR;
sapp_global_val->individual_fixed.depolyment_mode_private = NET_CONN_PARALLEL;
@@ -627,7 +627,7 @@ static int parse_vlan_flipping_map_config(void)
fp = fopen(ABBR_VLAN_FLIPPING_CONF_FILE, "r");
if(NULL == fp){
sapp_log(RLOG_LV_INFO, ~0, ~0, "[warning]can't open vlan_flipping_cfg_file:%s", ABBR_VLAN_FLIPPING_CONF_FILE);
- /* 向前兼容, 如果文件不存在, 不算错误 */
+ /* ��ǰ����, ����ļ�������, ������� */
return 0;
}
@@ -796,7 +796,7 @@ static int parse_asymmetric_addr_layer_config(void)
fp = fopen(ABBR_ASYM_LAYER_ADDR_CONF_FILE, "r");
if(NULL == fp){
sapp_log(RLOG_LV_INFO, ~0, ~0, "[Warning]can't open asymmetric_addr_layer_cfg_file:%s", ABBR_ASYM_LAYER_ADDR_CONF_FILE);
- /* 向前兼容, 如果文件不存在, 不算错误 */
+ /* ��ǰ����, ����ļ�������, ������� */
return 0;
}
@@ -869,7 +869,7 @@ static int parse_stream_compare_layer_config(void)
fp = fopen(ABBR_STREAM_CMP_LAYER_CONF_FILE, "r");
if(NULL == fp){
sapp_log(RLOG_LV_INFO, ~0, ~0, "[Warning]can't open stream compare layer cfg_file:%s", ABBR_STREAM_CMP_LAYER_CONF_FILE);
- /* 向前兼容, 如果文件不存在, 不算错误 */
+ /* ��ǰ����, ����ļ�������, ������� */
return 0;
}
@@ -913,7 +913,7 @@ static void update_overlay_vxlan_layer_set(void)
g_overlay_layer_set[ADDR_TYPE_MAC][0] = 1;
g_overlay_layer_set[ADDR_TYPE_IPV4][1] = 1;
g_overlay_layer_set[__ADDR_TYPE_IP_PAIR_V4][1] = 1;
- g_overlay_layer_set[ADDR_TYPE_UDP][1] = 1; /* IP和udp合并算为一层, 所以此处还是用1 */
+ g_overlay_layer_set[ADDR_TYPE_UDP][1] = 1; /* IP��udp�ϲ���Ϊһ��, ���Դ˴�������1 */
g_overlay_layer_set[ADDR_TYPE_VXLAN][2] = 1;
}
@@ -941,7 +941,7 @@ static int parse_well_known_port_config(void)
{
FILE *fp;
char line_buf[256];
- int last_section_proto = -1; /* 段落标识: TCP or UDP */
+ int last_section_proto = -1; /* �����ʶ: TCP or UDP */
unsigned short *port_array = NULL;
int port_array_num = 0;
int tmpnum;
@@ -949,7 +949,7 @@ static int parse_well_known_port_config(void)
fp = fopen(ABBR_WELL_KNOWN_PORT_CONF_FILE, "r");
if(NULL == fp){
- return 0; /* 没有此文件, 不算错误 */
+ return 0; /* û�д��ļ�, ������� */
}
while(fgets(line_buf, sizeof(line_buf), fp)){
@@ -959,9 +959,9 @@ static int parse_well_known_port_config(void)
sapp_memmove_for_blank_table(line_buf, sizeof(line_buf));
del_last_rn(line_buf, sizeof(line_buf));
- if('[' == line_buf[0]){ /* [] 一个段落的起始 */
+ if('[' == line_buf[0]){ /* [] һ���������ʼ */
if(port_array != NULL){
- /* 上一个段落刚结束 */
+ /* ��һ������ս��� */
update_well_known_port_array(last_section_proto, port_array, port_array_num);
port_array = NULL;
port_array_num = 0;
@@ -1053,7 +1053,7 @@ static int parse_extract_linkdir_from_mac_cfg(void)
return 0;
}
-/* 配置格式转换, 如字符串类型转为int类型,便于程序处理 */
+/* ���ø�ʽת��, ���ַ�������תΪint����,���ڳ����� */
static int config_expression_convert(void)
{
sapp_config_t *pconfig;
@@ -1296,9 +1296,9 @@ static inline void old_config_file_detect(const char *old_filename, const char *
/*
- 配置文件合法性、相关性检查.
+ �����ļ��Ϸ��ԡ�����Լ��.
- TODO: 与参数检测引擎 g_sapp_cfg_check_attr[] 待合并, 某些参数检测功能是重复的!!!
+ TODO: ������������ g_sapp_cfg_check_attr[] ���ϲ�, ijЩ������⹦�����ظ���!!!
return value:
0: succ;
@@ -1313,7 +1313,7 @@ static int config_sanity_check(void)
struct streaminfo_private phony_stream_pr;
phony_stream_pr.layer_index = 0xF;
- assert(SAPP_SUPPORT_LAYER_NUM_MAX == phony_stream_pr.layer_index); /* 用于判断无意中修改了layer_index或SAPP_SUPPORT_LAYER_NUM_MAX, 两个变量不一致的情况 */
+ assert(SAPP_SUPPORT_LAYER_NUM_MAX == phony_stream_pr.layer_index); /* �����ж��������޸���layer_index��SAPP_SUPPORT_LAYER_NUM_MAX, ����������һ�µ���� */
if(SAPP_SUPPORT_LAYER_NUM_MAX != phony_stream_pr.layer_index){
sapp_log(RLOG_LV_FATAL, ~0, ~0, "SAPP_SUPPORT_LAYER_NUM_MAX is:%d, but streaminfo_private->layer_index max is:%d", SAPP_SUPPORT_LAYER_NUM_MAX, phony_stream_pr.layer_index);
return -1;
@@ -1445,7 +1445,7 @@ static int config_sanity_check(void)
/*
- 支持读写分离模式, 更新各种配置文件路径, 本地数据文件路径.
+ ֧�ֶ�д����ģʽ, ���¸��������ļ�·��, ���������ļ�·��.
*/
int sapp_get_secondary_file_path(void)
{
@@ -1618,7 +1618,7 @@ int sapp_get_secondary_file_path(void)
}
-/* 读取配置文件sapp.toml, 本函数只Load, 不做解析和错误处理 */
+/* ��ȡ�����ļ�sapp.toml, ������ֻLoad, ���������ʹ����� */
int sapp_parse_config(void)
{
int ret;
@@ -1640,7 +1640,7 @@ int sapp_parse_config(void)
/******************************* SYSTEM *********************************/
ret = tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"SYSTEM", (char *)"instance_name", pconfig->system.instance_name, NAME_MAX, "sapp_v4.2");
if(TOMLC99_RET_PATTERN_ERROR == ret){
- /* 首次解析判断如果是PATTERN_ERROR, 说明toml格式有问题, 不再继续解析 */
+ /* �״ν����ж������PATTERN_ERROR, ˵��toml��ʽ������, ���ټ������� */
sapp_log(30, ~0, ~0, "parse config file %s error!", ABBR_CFG_FILE_MAIN_ENTRY);
exit(1);
}
@@ -1663,7 +1663,7 @@ int sapp_parse_config(void)
tomlc99_wrap_load_long_array(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask", pconfig->cpu.bind_mask_array, &pconfig->cpu.bind_mask_array_num);
- /* 带范围的配置, 如1-10,10-20等参数使用MESA_load_profile_uint_range解析, 此时要用字符串模式!!! */
+ /* ����Χ������, ��1-10,10-20�Ȳ���ʹ��MESA_load_profile_uint_range����, ��ʱҪ���ַ���ģʽ!!! */
int tmp_bind_mask[SAPP_MAX_THREADS] = {};
ret = MESA_load_profile_uint_range(
ABBR_CFG_FILE_MAIN_ENTRY, (char *)"CPU", (char *)"bind_mask",
@@ -1700,6 +1700,7 @@ int sapp_parse_config(void)
tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"inject_mode_single_gateway_device", pconfig->packet_io.inject_mode_single_gateway_device, NAME_MAX, "lo");
tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"inject_mode_single_gateway_dst_mac", pconfig->packet_io.inject_mode_single_gateway_dst_mac_string, sizeof(pconfig->packet_io.inject_mode_single_gateway_dst_mac_string), "$");
}
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"inject_pkt_prepend_segment_id", &pconfig->packet_io.inject_pkt_prepend_segment_id, 0);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"inject_mode_inline_device_sport", &tmp_int, 54789);
if(tmp_int <= 0 || tmp_int > 65535){
sapp_log(30, ~0, ~0, "config parse error! invalid value of 'packet_io.feature.inject_mode_inline_device_sport %d'", tmp_int);
@@ -1734,7 +1735,7 @@ int sapp_parse_config(void)
pconfig->packet_io.dup_pkt_para.bloom_error_rate = strtod(str_tmp, NULL);
/******************************* packet_io.under_ddos ******************************/
- tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"stream_bypass_enabled", &pconfig->packet_io.under_ddos_config.enabled, 0); //向前兼容, 默认不开启
+ tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"stream_bypass_enabled", &pconfig->packet_io.under_ddos_config.enabled, 0); //��ǰ����, Ĭ�ϲ�����
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"get_cpu_usage_interval", &pconfig->packet_io.under_ddos_config.get_cpu_usage_interval, 50);
tomlc99_wrap_load_int_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.under_ddos", (char *)"smooth_avg_window", &pconfig->packet_io.under_ddos_config.smooth_avg_window, 3);
@@ -1881,9 +1882,9 @@ int sapp_parse_config(void)
}
/*
- 0: 不认识配置文件中的key-value;
- 1: 识别并存储配置文件中的key-value;
- 2: 包括某些已经被废弃的参数.
+ 0: ����ʶ�����ļ��е�key-value;
+ 1: ʶ�𲢴洢�����ļ��е�key-value;
+ 2: ����ijЩ�Ѿ��������IJ���.
*/
static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_attr, const char *section, const char *key, const char *value)
{
@@ -1892,7 +1893,7 @@ static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_
int found_cfg = 0;
for(i = 0; local_cfg_check_attr[i].global_id != -1; i++){
- if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] 等配置只有个section, 但是没有key */
+ if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] ������ֻ�и�section, ����û��key */
continue;
}
section_max_len = SAPP_MAX(strlen(local_cfg_check_attr[i].section), strlen(section));
@@ -1904,7 +1905,7 @@ static int sapp_config_check_update_option(sapp_config_check_t *local_cfg_check_
return 2;
}else{
if(NULL == value){
- local_cfg_check_attr[i].cfg_value = sapp_strdup(""); /* 没有配置有意的值, 比如bpf过滤条件为空, 但是key是存在的, 也算配置找到了 */
+ local_cfg_check_attr[i].cfg_value = sapp_strdup(""); /* û�����������ֵ, ����bpf��������Ϊ��, ����key�Ǵ��ڵ�, Ҳ�������ҵ��� */
}else{
local_cfg_check_attr[i].cfg_value = sapp_strdup(value);
}
@@ -1923,7 +1924,7 @@ extern char *sapp_memmove_for_blank_table(char *data, int max_len);
/*
- 是否需要检查当前配置的合法性.
+ �Ƿ���Ҫ��鵱ǰ���õĺϷ���.
*/
static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_array, const sapp_config_check_t *this_cfg_check_attr)
{
@@ -1932,7 +1933,7 @@ static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_ar
if(1 == this_cfg_check_attr->depend_id){
return 1;
}
- if(0 == this_cfg_check_attr->depend_id){ /* 可选的配置也检查 */
+ if(0 == this_cfg_check_attr->depend_id){ /* ��ѡ������Ҳ��� */
return 1;
}
@@ -1950,11 +1951,11 @@ static int cfg_value_need_be_check(const sapp_config_check_t *local_cfg_check_ar
}
/*
- 完全遍历一遍当前的sapp.toml, 检查是否有不认识的配置, 如果有说明:
- 1)sapp比sapp.toml的版本旧;
- 2)某些历史上的参数已经被废弃, 但是sapp.toml还存在;
+ ��ȫ����һ�鵱ǰ��sapp.toml, ����Ƿ��в���ʶ������, �����˵��:
+ 1)sapp��sapp.toml�İ汾��;
+ 2)ijЩ��ʷ�ϵIJ����Ѿ�������, ����sapp.toml������;
- 此处不用prof_load而是自行用fgets逐行读取, 因为事先不知道要获取什么, 要把所有的行都遍历一遍.
+ �˴�����prof_load����������fgets���ж�ȡ, ��Ϊ���Ȳ�֪��Ҫ��ȡʲô, Ҫ�����е��ж�����һ��.
*/
static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr)
{
@@ -1964,7 +1965,7 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr
char section_string[128] = {};
char *cfg_key;
char *cfg_value;
- const char *kname_delim = "="; /* 参数的值只能用=分割, 否则会把key的值里的空格\t删除, 比如bpf filter */
+ const char *kname_delim = "="; /* ������ֵֻ����=�ָ�, ������key��ֵ��Ŀո�\tɾ��, ����bpf filter */
const char *section_delim = "[] \t";
char *key_save_ptr, *section_save_ptr;
FILE *fp;
@@ -1982,12 +1983,12 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr
if('#' == raw_config_line[0]){
continue;
}
- if('\0' == raw_config_line[0]){ /* 纯空行 */
+ if('\0' == raw_config_line[0]){ /* ������ */
continue;
}
memcpy(config_line, raw_config_line, sizeof(raw_config_line));
- if('[' == raw_config_line[0]){ /* 以[开头表示是section段落开始 */
+ if('[' == raw_config_line[0]){ /* ��[��ͷ��ʾ��section���俪ʼ */
char *pure_sesion_str = strtok_r(config_line, section_delim, &section_save_ptr);
strncpy(section_string, pure_sesion_str, sizeof(section_string));
while(strtok_r(NULL, section_delim, &section_save_ptr));
@@ -2010,7 +2011,7 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr
sapp_memmove_for_blank_table(cfg_value, strlen(cfg_value));
- const char *kkvalue_delim = "\"'"; /* 参数的值可能被双引号保护了, 此时只能去掉引号但是不能再用空格\t分割了, 比如bpf_filter */
+ const char *kkvalue_delim = "\"'"; /* ������ֵ���ܱ�˫���ű�����, ��ʱֻ��ȥ�����ŵ��Dz������ÿո�\t�ָ���, ����bpf_filter */
char *pure_cfg_value_save_ptr;
char *pure_cfg_value = strtok_r(cfg_value, kkvalue_delim, &pure_cfg_value_save_ptr);
ret = sapp_config_check_update_option(local_cfg_check_attr, section_string, cfg_key, pure_cfg_value);
@@ -2028,8 +2029,8 @@ static int sapp_config_check_unsupport(sapp_config_check_t *local_cfg_check_attr
}
/*
- 把所有已知的参数从sapp.toml里读取一遍, 检查是否有不存在的配置, 如果有:
- 1)sapp比sapp.toml的版本新;
+ ��������֪�IJ�����sapp.toml���ȡһ��, ����Ƿ��в����ڵ�����, �����:
+ 1)sapp��sapp.toml�İ汾��;
*/
static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr)
{
@@ -2039,10 +2040,10 @@ static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr)
int fun_ret = 0;
for(i = 0; local_cfg_check_attr[i].global_id != -1; i++){
- if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] 等配置只有个section, 仅作为段落标识, 但是没有key */
+ if(NULL == local_cfg_check_attr[i].cfg_key){ /* [PACKET_IO], []DUPLICATE_PKT] ������ֻ�и�section, ����Ϊ�����ʶ, ����û��key */
continue;
}
- if(SAPP_CFG_OBSOLETE_FLAG == local_cfg_check_attr[i].global_id){ /* 已经废弃的配置, 不用于检查missing */
+ if(SAPP_CFG_OBSOLETE_FLAG == local_cfg_check_attr[i].global_id){ /* �Ѿ�����������, �����ڼ��missing */
continue;
}
if(cfg_value_need_be_check(local_cfg_check_attr, &local_cfg_check_attr[i]) == 0){
@@ -2050,24 +2051,24 @@ static int sapp_config_check_missing(sapp_config_check_t *local_cfg_check_attr)
}
ret1 = MESA_load_profile_string_nodef(ABBR_CFG_FILE_MAIN_ENTRY, local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key, cfg_value, sizeof(cfg_value));
if(ret1 < 0){
- /* 用profile接口读取不到有可能是toml格式的数组, 再用toml数组尝试解析一下 */
+ /* ��profile�ӿڶ�ȡ�����п�����toml��ʽ������, ����toml���鳢�Խ���һ�� */
array_num = 1024;
ret2 = tomlc99_wrap_load_int_array(ABBR_CFG_FILE_MAIN_ENTRY, local_cfg_check_attr[i].section, (char *)local_cfg_check_attr[i].cfg_key, cfg_array, &array_num);
if(ret2 < 0){
- /* 使用toml数组也没有读取到配置, 检查是否依赖其他配置项 */
+ /* ʹ��toml����Ҳû�ж�ȡ������, ����Ƿ��������������� */
if((local_cfg_check_attr[i].depend_id != 0) && (local_cfg_check_attr[i].cfg_value_check_fun != NULL)){
ret3 = local_cfg_check_attr[i].cfg_value_check_fun(local_cfg_check_attr, local_cfg_check_attr[i].global_id, local_cfg_check_attr[i].depend_id,
local_cfg_check_attr[i].cfg_value, local_cfg_check_attr[i].expect_range_array, local_cfg_check_attr[i].expect_array_num);
if(ret3 != 0){
fun_ret = SAPP_MAX(local_cfg_check_attr[i].err_log_level, fun_ret);
sapp_printf_colorful(fun_ret, "missing sapp.toml config: [%s] -> %s\n", local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key);
- /* 注意: 此处不要break, 检查所有的配置文件参数 */
+ /* ע��: �˴���Ҫbreak, ������е������ļ����� */
}
}else{
fun_ret = SAPP_MAX(local_cfg_check_attr[i].err_log_level, fun_ret);
sapp_printf_colorful(fun_ret, "missing sapp.toml config: [%s] -> %s\n", local_cfg_check_attr[i].section, local_cfg_check_attr[i].cfg_key);
- /* 注意: 此处不要break, 检查所有的配置文件参数 */
+ /* ע��: �˴���Ҫbreak, ������е������ļ����� */
}
}
}
@@ -2081,7 +2082,7 @@ static int sapp_config_check_missing_and_unsupport(sapp_config_check_t *local_cf
{
int ret;
- /* 注意: check_unsupport放在前面, 因为还有个附加作用, 就是把所有配置的值读取到全局变量: g_sapp_cfg_check_attr 中*/
+ /* ע��: check_unsupport����ǰ��, ��Ϊ���и���������, ���ǰ��������õ�ֵ��ȡ��ȫ�ֱ���: g_sapp_cfg_check_attr ��*/
ret = sapp_config_check_unsupport(local_cfg_check_attr);
if(ret != 0){
sapp_printf_colorful(ret, "maybe a typo, maybe some config is obsolete, or sapp is older than sapp.toml version!\n");
@@ -2098,7 +2099,7 @@ static int sapp_config_check_missing_and_unsupport(sapp_config_check_t *local_cf
}
/*
- 检查每个参数自身的合法性, 只是单纯看参数的值合不合法, 不做关联性检查.
+ ���ÿ�����������ĺϷ���, ֻ�ǵ�����������ֵ�ϲ��Ϸ�, ���������Լ��.
*/
static int sapp_config_check_single_validity(sapp_config_check_t *local_cfg_check_attr)
{
@@ -2126,9 +2127,9 @@ static int sapp_config_check_single_validity(sapp_config_check_t *local_cfg_chec
}
/*
- 多个从参数之间的关联性检查,
- 比如拓扑为transparent模式, 必须开启packet_io.external.interface;
- 比如开启了prometheus_enabled, 必须有prometheus_port和prometheus_url_path;
+ ����Ӳ���֮��Ĺ����Լ��,
+ ��������Ϊtransparentģʽ, ���뿪��packet_io.external.interface;
+ ���翪����prometheus_enabled, ������prometheus_port��prometheus_url_path;
*/
static int sapp_config_check_sanity(sapp_config_check_t *local_cfg_check_attr)
{
@@ -2142,15 +2143,15 @@ static int sapp_config_check_sanity(sapp_config_check_t *local_cfg_check_attr)
/*
check_level:
- t1: 只检查支持的参数在不在, 是否有不支持的新参数;
- t2: 检查每个参数的值是否合法, 比如packet_io.mode 不是mirror, inline, tansparent等;
- t3: 不仅检查单个参数, 尽可能的检查所有参数的相关性依赖问题, 比如transparent模式没有配置external网卡;
+ t1: ֻ���֧�ֵIJ����ڲ���, �Ƿ��в�֧�ֵ��²���;
+ t2: ���ÿ��������ֵ�Ƿ�Ϸ�, ����packet_io.mode ����mirror, inline, tansparent��;
+ t3: ������鵥������, �����ܵļ�����в������������������, ����transparentģʽû������external����;
*/
int sapp_config_check(void)
{
int i, ret1, ret2, final_ret = 0;
- /* 全局变量中有固定不变的配置, 也有动态从配置文件读取的数据, 所以此处copy一份临时数据 */
+ /* ȫ�ֱ������й̶����������, Ҳ�ж�̬�������ļ���ȡ������, ���Դ˴�copyһ����ʱ���� */
sapp_config_check_t *local_cfg_check_attr = (sapp_config_check_t *)sapp_mem_calloc(SAPP_MEM_FIX_GLOBAL_VAL, MEM_STAT_GLOBAL_THREAD_ID,sizeof(g_sapp_cfg_check_attr));
memcpy(local_cfg_check_attr, g_sapp_cfg_check_attr, sizeof(g_sapp_cfg_check_attr));