From 03fc6574489cf68b7095c7e8e6ab9481eb4aeb04 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 14:59:46 +0800 Subject: [PATCH 01/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configm/config-server/include/brconfig.h | 4 + .../configm/config-server/include/parsefile.h | 7 + .../config-server/netconfig/bridge/brconfig.c | 71 +++++++- .../config-server/netconfig/parsefile.c | 159 ++++++++++++++++-- 4 files changed, 219 insertions(+), 22 deletions(-) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 3b8c4dd00..3b2c6cd70 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -11,8 +11,12 @@ typedef enum { BR_CREATE_EVENT = 1, BR_DELETE_EVENT, + BR_CREATE_EVENT_PRE, + BR_DELETE_EVENT_PRE, BR_IF_JOIN_EVENT, BR_IF_LEAVE_EVENT, + BR_IF_JOIN_EVENT_PRE, + BR_IF_LEAVE_EVENT_PRE, BR_EVENT_INVALID } BR_EVENT_TYPE; diff --git a/Platform/user/configm/config-server/include/parsefile.h b/Platform/user/configm/config-server/include/parsefile.h index caa1c5888..5bc6f51ce 100644 --- a/Platform/user/configm/config-server/include/parsefile.h +++ b/Platform/user/configm/config-server/include/parsefile.h @@ -4,7 +4,14 @@ #define IFCONFIG_PATH "/etc/network/interfaces" #define IF_BUFF_LEN 128 +ret_code if_conf_file_add(char *if_name); +ret_code if_conf_file_del(char *if_name); +ret_code if_conf_file_set(char *if_name, char *conf_name, char *conf_buff); +ret_code if_conf_file_get(char *if_name, char *conf_name, char *conf_buff); + void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff); void ip_conf_file_del(char *if_name, char *conf_buff); +ret_code del_sub_string(char *str_in,char *str_sub); + #endif diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 8a54afff0..82f1c6066 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -11,6 +11,7 @@ #include "parsefile.h" #include "libbridge.h" #include "brnetlink.h" +#include "parsefile.h" #include "list.h" #ifndef DESC("事件通知函数") @@ -184,7 +185,54 @@ ret_code br_if_bridge_check(char *port_list, int cnt, uint config_type) return RET_OK; } -ret_code br_if_bridge_add(char * br_name, char *port_list, int cnt, int *sys_err) +ret_code br_save_file(BR_EVENT_TYPE event_type, + char *br_name, char *port_name) +{ + char *key_str = "bridge_ports"; + char config_str[IF_BUFF_LEN] = {0}; + ret_code ret; + + switch(event_type) + { + case BR_CREATE_EVENT: + if_conf_file_add(br_name); + break; + case BR_DELETE_EVENT: + if_conf_file_del(br_name) + break; + case BR_IF_JOIN_EVENT: + if(if_conf_file_get(br_name, key_str, config_str) == RET_OK) + { + if(strstr(config_str, port_name) != NULL) + { + return RET_OK; + } + strcat(config_str, " "); + strcat(config_str, port_name); + } + if_conf_file_set(br_name, key_str, config_str); + break; + case BR_IF_LEAVE_EVENT: + if(if_conf_file_get(br_name, key_str, config_str) == RET_OK) + { + if(strstr(config_str, port_name) != NULL) + { + del_sub_string(config_str, port_name); + rpc_log_info("BR_IF_LEAVE_EVENT: %s\n", config_str); + if_conf_file_set(br_name, key_str, config_str); + return RET_OK; + } + } + break; + default: + break; + } + + return RET_OK; +} + + +ret_code br_if_bridge_add(char *br_name, char *port_list, int cnt, int *sys_err) { ret_code ret = RET_OK; char *port_name; @@ -193,6 +241,7 @@ ret_code br_if_bridge_add(char * br_name, char *port_list, int cnt, int *sys_err for(i = 0; i < cnt) { + br_invoke_event(BR_IF_JOIN_EVENT_PRE, event_arg); port_name = port_list + INTERFACE_NAMSIZ * i; err = br_add_interface(br_name, port_name); if(err != 0) @@ -204,6 +253,8 @@ ret_code br_if_bridge_add(char * br_name, char *port_list, int cnt, int *sys_err br_event_t event_arg = {br_name, port_name}; br_invoke_event(BR_IF_JOIN_EVENT, event_arg); + + br_save_file(BR_IF_JOIN_EVENT, br_name, port_name); } return ret; @@ -218,6 +269,7 @@ ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err for(i = 0; i < cnt) { + br_invoke_event(BR_IF_LEAVE_EVENT_PRE, event_arg); port_name = port_list + INTERFACE_NAMSIZ * i; err = br_del_interface(br_name, port_name); if(err != 0) @@ -229,6 +281,8 @@ ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err br_event_t event_arg = {br_name, port_name}; br_invoke_event(BR_IF_LEAVE_EVENT, event_arg); + + br_save_file(BR_IF_LEAVE_EVENT, br_name, port_name); } return ret; @@ -244,10 +298,12 @@ int br_if_bridge_num(char *br_name) return cnt; } -ret_code br_bridge_add(char * br_name, int *sys_err) +ret_code br_bridge_add(char *br_name, int *sys_err) { br_event_t event_arg = {br_name, NULL}; int sys_ret = 0; + + br_invoke_event(BR_CREATE_EVENT_PRE, event_arg); sys_ret = br_add_bridge(br_name); *sys_err = sys_ret; @@ -258,7 +314,9 @@ ret_code br_bridge_add(char * br_name, int *sys_err) } br_invoke_event(BR_CREATE_EVENT, event_arg); - + + br_save_file(BR_CREATE_EVENT, br_name, NULL); + return RET_OK; } @@ -267,6 +325,8 @@ ret_code br_bridge_del(char * br_name, int *sys_err) br_event_t event_arg = {br_name, NULL}; int sys_ret = 0; + br_invoke_event(BR_DELETE_EVENT_PRE, event_arg); + sys_ret = br_del_bridge(br_name); *sys_err = sys_ret; @@ -276,9 +336,10 @@ ret_code br_bridge_del(char * br_name, int *sys_err) } br_invoke_event(BR_DELETE_EVENT, event_arg); - + + br_save_file(BR_DELETE_EVENT, br_name, NULL); + return RET_OK; - } #endif diff --git a/Platform/user/configm/config-server/netconfig/parsefile.c b/Platform/user/configm/config-server/netconfig/parsefile.c index 854bbbb26..8ff29a715 100644 --- a/Platform/user/configm/config-server/netconfig/parsefile.c +++ b/Platform/user/configm/config-server/netconfig/parsefile.c @@ -151,6 +151,116 @@ int conf_value_in_block_exist(char *conf_path, char *conf_buff) return RET_NOTFOUND; } +/* 设置指定配置块中的配置 */ +int conf_value_in_block_set_ex(char *conf_path, + char *start_str, char *end_str, + char *conf_name, char *conf_buff) +{ + char config_linebuf[IF_BUFF_LEN]; + int configbuf_lenth = strlen(conf_buff) + 5; + long config_lenth = 0; + boolean next_flag = FALSE; + char *start_line = NULL; + char *config_line = NULL; + FILE *f; + + f = fopen(conf_path,"r+"); + if(f == NULL) + { + rpc_log_error("OPEN CONFIG %s FALID\n", conf_path); + return RET_ERR; + } + + fseek(f, 0, SEEK_END); + + config_lenth = ftell(f); + + char sum_buf[config_lenth + configbuf_lenth]; + + memset(sum_buf, 0, sizeof(sum_buf)); + + fseek(f, 0, SEEK_SET); + + memset(config_linebuf, 0, sizeof(config_linebuf)); + + while(fgets(config_linebuf, IF_BUFF_LEN, f) != NULL) + { + /* 该做的事情已经做完 */ + if(next_flag == TRUE) + { + strcat(sum_buf, config_linebuf); + goto next_while; + } + + /* 判断是否是空行 */ + if(strlen(config_linebuf) < 3) + { + strcat(sum_buf, config_linebuf); + goto next_while; + } + + /* 没有找到配置块,则继续循环 */ + if(start_line == NULL) + { + start_line = strstr(config_linebuf, start_str); + strcat(sum_buf, config_linebuf); + goto next_while; + } + + /* 配置块结束 */ + if(strstr(config_linebuf, end_str)) + { + if(config_line == NULL) + { + strcat(sum_buf, conf_buff); + } + + strcat(sum_buf, config_linebuf); + next_flag = TRUE; + + goto next_while; + } + + if(config_line == NULL) + { + config_line = strstr(config_linebuf, conf_name); + + /* 找到配置行 */ + if(config_line) + { + next_flag = TRUE; + strcat(sum_buf, conf_buff); + goto next_while; + } + } + + strcat(sum_buf, config_linebuf); + +next_while: + if(fgetc(f)==EOF) + { + break; + } + + fseek(f,-1,SEEK_CUR); + + memset(config_linebuf, 0, sizeof(config_linebuf)); + } + + fclose(f); + + /* 整个配置块都没有,则新创建该配置块 */ + if( next_flag == FALSE ) + { + return RET_NOTFOUND; + } + + remove(conf_path); + + rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf); + + return conf_file_write(conf_path, sum_buf); +} /* 设置指定配置块中的配置 */ int conf_value_in_block_set(char *conf_path, @@ -530,51 +640,45 @@ int conf_value_block_del(char *conf_path, char *start_str, char *end_str) } /* 增加接口配置块 */ -void if_conf_file_add(char *if_name) +ret_code if_conf_file_add(char *if_name) { char auto_str[IF_BUFF_LEN] = {0}; sprintf(auto_str, "auto %s", if_name); - conf_value_block_add(IFCONFIG_PATH, auto_str); - - return; + return conf_value_block_add(IFCONFIG_PATH, auto_str); } /* 删除整个接口配置块 */ -void if_conf_file_del(char *if_name) +ret_code if_conf_file_del(char *if_name) { char auto_str[IF_BUFF_LEN] = {0}; sprintf(auto_str, "auto %s", if_name); - conf_value_block_del(IFCONFIG_PATH, auto_str, "auto"); - - return; + return conf_value_block_del(IFCONFIG_PATH, auto_str, "auto"); } /* 设置接口中的配置 */ -void if_conf_file_set(char *if_name, char *conf_name, char *conf_buff) +ret_code if_conf_file_set(char *if_name, char *conf_name, char *conf_buff) { char auto_str[IF_BUFF_LEN] = {0}; sprintf(auto_str, "auto %s", if_name); - conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff); - - return; + return conf_value_in_block_set_ex(IFCONFIG_PATH, auto_str, + "auto", conf_name, conf_buff); } /* 获取接口中的配置 */ -void if_conf_file_get(char *if_name, char *conf_name, char *conf_buff) +ret_code if_conf_file_get(char *if_name, char *conf_name, char *conf_buff) { char auto_str[IF_BUFF_LEN] = {0}; sprintf(auto_str, "auto %s", if_name); - conf_value_in_block_get(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff); - - return; + return conf_value_in_block_get(IFCONFIG_PATH, auto_str, + "auto", conf_name, conf_buff); } ret_code if_conf_file_exist(char *if_name, char *conf_buff) @@ -610,7 +714,6 @@ void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff) return; } - /* *删除配置文件内容 * @@ -628,3 +731,25 @@ void ip_conf_file_del(char *if_name, char *conf_buff) return; } +ret_code del_sub_string(char *str_in,char *str_sub) +{ + char* str_out = (char *)malloc(strlen(str_in) + 1); + char* p; + + if(str_out == NULL) + { + return RET_NULLP; + } + + while((p = strstr(str_in, str_sub)) != NULL) + { + *p = '\0'; + + strcpy(str_out, p + strlen(str_sub)); + strcat(str_in, str_out); + } + + return RET_OK; +} + + From 0c75e14a95b9f93620a9bf06ede374db87e44902 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 15:28:22 +0800 Subject: [PATCH 02/19] =?UTF-8?q?MOD=20aaa-12=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9=E5=AD=90=20SOL=20?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=92=A9=E5=AD=90=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangl?= =?UTF-8?q?iang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/configm/config-server/configserver.c | 21 +++++++++++++++++++ .../configm/config-server/include/configm.h | 21 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Platform/user/configm/config-server/configserver.c b/Platform/user/configm/config-server/configserver.c index f95d63bb9..dbfc41c44 100644 --- a/Platform/user/configm/config-server/configserver.c +++ b/Platform/user/configm/config-server/configserver.c @@ -11,6 +11,7 @@ config_service_t g_config_service[] = CONFIG_SERVICE_ARRAY; +config_init_t g_config_init[] = CONFIG_INIT_ARRAY; void test_big_data(rpc_conn *conn, pointer input, int input_len, void* data) { char buf[input_len]; @@ -145,6 +146,23 @@ ret_code cm_config_get_allconfig(uint source, return ret; } +void cm_config_module_init() +{ + int len = sizeof(g_config_init) / sizeof(CONFIG_INIT_ARRAY); + config_init_t *config_svr; + int config_idx; + + for(config_idx = 0; config_idx < len; config_idx++) + { + config_svr = &(g_config_init[config_idx]); + + rpc_log_info("MODULE %d init\n", config_svr->config_mudlue); + if(config_svr->init_callback) + { + config_svr->init_callback(); + } + } +} /* 配置恢复 */ void cm_config_recovery() @@ -382,6 +400,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + /* 模块初始化 */ + cm_config_module_init(); + /* 配置恢复 */ cm_config_recovery(); diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 4dc6cb5a3..8d1f02768 100644 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -37,6 +37,13 @@ #define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4) #define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5) +#define CONFIG_INIT_ARRAY \ +{\ + {\ + IPCONFIG_V4,\ + NULL\ + }\ +}\ /* 1、配置ID,全局唯一,用于寻找对应的配置业务 @@ -133,6 +140,10 @@ }\ } +typedef ret_code (*cm_config_init)(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + typedef ret_code (*cm_config_chk)(uint source, uint *config_type, pointer input, int *input_len, pointer output, int *output_len); @@ -148,9 +159,17 @@ typedef ret_code (*cm_config_get)(uint source, typedef ret_code (*cm_config_get_all)(uint source, pointer output, int *output_len); +/* 配置注册 */ +struct _config_init { + uint config_mudlue; + cm_config_init init_callback; +}; +typedef struct _config_init config_init_t; + + /* 配置注册 */ struct _config_service { - uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ + uint32 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ boolean multi_inst; /* 是否是多实例 */ From ee27856922dcc4a0299c2e70db3802d73969079a Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 15:33:53 +0800 Subject: [PATCH 03/19] =?UTF-8?q?MOD=20aaa-12=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9=E5=AD=90=20SOL=20?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=92=A9=E5=AD=90=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangl?= =?UTF-8?q?iang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2j.h | 12 ++++++ Common/s2j/s2jdef.h | 40 ++++++++++++++++++- .../configm/config-server/include/configm.h | 2 +- .../configm/config-server/include/parsefile.h | 2 + 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Common/s2j/s2j.h b/Common/s2j/s2j.h index ff67266a6..8d2642e30 100644 --- a/Common/s2j/s2j.h +++ b/Common/s2j/s2j.h @@ -72,10 +72,22 @@ extern "C" { #define s2j_struct_get_basic_element(to_struct, from_json, type, element) \ S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element) +#define s2j_struct_get_string_element(to_struct, from_json, type, element, n) \ + S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, type, element, n) + /* Get array type element for structure object */ #define s2j_struct_get_array_element(to_struct, from_json, type, element) \ S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element) +/* Get array type element for structure object */ +#define s2j_struct_get_array_element_n(to_struct, from_json, type, element, NUM) \ + S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element) + +/* Get array type element for structure object */ +#define s2j_struct_get_array_string_n(to_struct, from_json, type, element, NUM, BUFFLEN) \ + S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, element, NUM, BUFFLEN) + + /* Get child structure type element for structure object */ #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \ S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element) diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index 9002b088e..cd27ac78e 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -52,8 +52,9 @@ typedef struct { #define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \ json_temp = cJSON_GetObjectItem(from_json, #_element); \ - if (json_temp && json_temp->valuestring && n > 1)\ - strncpy((to_struct)->_element, json_temp->valuestring, n-1); + if (json_temp && json_temp->valuestring && n > 1){\ + strncpy((to_struct)->_element, json_temp->valuestring, n - 1);\ + to_struct->_element[n - 1] = '\0';} #define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \ json_temp = cJSON_GetObjectItem(from_json, #_element); \ @@ -65,6 +66,9 @@ typedef struct { #define S2J_STRUCT_ARRAY_GET_string_ELEMENT(to_struct, from_json, _element, index) \ strcpy((to_struct)->_element[index], from_json->valuestring); +#define S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, from_json, _element, index, maxlen) \ + strncpy((to_struct)->_element + maxlen * index, from_json->valuestring, maxlen - 1); + #define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \ (to_struct)->_element[index] = from_json->valuedouble; @@ -145,6 +149,38 @@ typedef struct { } \ } +#define S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM) \ + { \ + cJSON *array, *array_element; \ + size_t index = 0, size = 0; \ + array = cJSON_GetObjectItem(from_json, #_element); \ + if (array) { \ + size = cJSON_GetArraySize(array); \ + while (index < size && index < NUM) { \ + array_element = cJSON_GetArrayItem(array, index); \ + if (array_element) S2J_STRUCT_ARRAY_GET_ELEMENT(to_struct, array_element, type, _element, index++); \ + } \ + } \ + } + +#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM, LEN) \ + { \ + cJSON *array, *array_element; \ + size_t index = 0, size = 0; \ + array = cJSON_GetObjectItem(from_json, #_element); \ + if (array) { \ + size = cJSON_GetArraySize(array); \ + NUM = size;\ + (to_struct)->_element = (char *)malloc(size * LEN);\ + memset((to_struct)->_element, 0, size * LEN);\ + while (index < size) { \ + array_element = cJSON_GetArrayItem(array, index); \ + if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, type, _element, index++, LEN); \ + } \ + } \ + } + + #define S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, _element) \ type *child_struct = &((to_struct)->_element); \ cJSON *child_json = cJSON_GetObjectItem(from_json, #_element); diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 8d1f02768..e30e9d5d0 100644 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -169,7 +169,7 @@ typedef struct _config_init config_init_t; /* 配置注册 */ struct _config_service { - uint32 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ + uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ boolean multi_inst; /* 是否是多实例 */ diff --git a/Platform/user/configm/config-server/include/parsefile.h b/Platform/user/configm/config-server/include/parsefile.h index 5bc6f51ce..92b5bdbe5 100644 --- a/Platform/user/configm/config-server/include/parsefile.h +++ b/Platform/user/configm/config-server/include/parsefile.h @@ -1,6 +1,8 @@ #ifndef PARSEFILE_H_ #define PARSEFILE_H_ +#include "rpc_common.h" + #define IFCONFIG_PATH "/etc/network/interfaces" #define IF_BUFF_LEN 128 From c254a1558bfab296d25a8c0fd14ac21e7351f88a Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 15:35:56 +0800 Subject: [PATCH 04/19] =?UTF-8?q?MOD=20aaa-12=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9=E5=AD=90=20SOL=20?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=92=A9=E5=AD=90=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangl?= =?UTF-8?q?iang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/user/configm/config-server/include/configm.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index e30e9d5d0..0688c8bdc 100644 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -40,7 +40,7 @@ #define CONFIG_INIT_ARRAY \ {\ {\ - IPCONFIG_V4,\ + NETCONFIG_MODULE,\ NULL\ }\ }\ @@ -140,9 +140,7 @@ }\ } -typedef ret_code (*cm_config_init)(uint source, uint *config_type, - pointer input, int *input_len, - pointer output, int *output_len); +typedef ret_code (*cm_config_init)(); typedef ret_code (*cm_config_chk)(uint source, uint *config_type, pointer input, int *input_len, From 5bc56588647bb5161afdc91aefba855658c7f790 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 15:41:15 +0800 Subject: [PATCH 05/19] =?UTF-8?q?MOD=20aaa-12=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96=E9=92=A9=E5=AD=90=20SOL=20?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=92=A9=E5=AD=90=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangl?= =?UTF-8?q?iang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/user/configm/config-server/configserver.c | 2 +- Platform/user/configm/config-server/include/configm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Platform/user/configm/config-server/configserver.c b/Platform/user/configm/config-server/configserver.c index dbfc41c44..44df0603b 100644 --- a/Platform/user/configm/config-server/configserver.c +++ b/Platform/user/configm/config-server/configserver.c @@ -148,7 +148,7 @@ ret_code cm_config_get_allconfig(uint source, void cm_config_module_init() { - int len = sizeof(g_config_init) / sizeof(CONFIG_INIT_ARRAY); + int len = sizeof(g_config_init) / sizeof(config_init_t); config_init_t *config_svr; int config_idx; diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 0688c8bdc..5ce54a515 100644 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -43,7 +43,7 @@ NETCONFIG_MODULE,\ NULL\ }\ -}\ +} /* 1、配置ID,全局唯一,用于寻找对应的配置业务 From ade5d6bb6a7763772a1c46ddfdc618edccd145e8 Mon Sep 17 00:00:00 2001 From: ChenLing Date: Fri, 2 Aug 2019 17:10:33 +0800 Subject: [PATCH 06/19] =?UTF-8?q?Mod=20=20aaa-12=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=86=85=E6=A0=B8=E6=80=81hsah=E8=A1=A8review=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=BA=EF=BC=9Achenling=20=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E4=BA=BA=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Product/modules/userhash/k-userhash.c | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Product/modules/userhash/k-userhash.c b/Product/modules/userhash/k-userhash.c index a9564c505..054df99c4 100644 --- a/Product/modules/userhash/k-userhash.c +++ b/Product/modules/userhash/k-userhash.c @@ -1,5 +1,10 @@ #include "k-userhash.h" #include +#include +#include + +/*声明读写锁 */ +DEFINE_RWLOCK(g_obj_lock); /*定义大小为HASH_SIZE的hashtable */ static struct list_head hash_array[HASH_SIZE]; @@ -15,7 +20,7 @@ void init_hashMap(void) /*获取hashtable位置索引 */ int get_hash_index(uint32_t ip) { - unsigned int val = ip % HASH_SIZE; + int val = ip % HASH_SIZE; return val; } @@ -29,15 +34,8 @@ USERINFO *search_user(uint32_t ip) index = get_hash_index(ip); - /*判断表中该单元是否为NLL */ - /* list_empty - tests whether a list is empty*/ - /* @head: the list to test.*/ - if( list_empty(&hash_array[index])) - { - return NULL; - } - /*查找用户IP */ + read_lock(&g_obj_lock); list_for_each(pos, &hash_array[index]) { @@ -47,9 +45,10 @@ USERINFO *search_user(uint32_t ip) * @member: the name of the list_head within the struct. */ pNode = list_entry(pos, USERINFO, hnode); if(pNode != NULL) - printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id); + printk("user ip:%ld user id:%d\n", pNode->user_ip, pNode->user_id); return pNode; } + read_unlock(&g_obj_lock); return NULL; } @@ -71,11 +70,10 @@ int add_user(uint32_t ip, int id) pNode = (USERINFO *)kmalloc(sizeof(USERINFO), GFP_KERNEL); if (pNode == NULL) { - return -1; + return ENOMEM; } - pNode->user_ip = ip; - + list_add_tail(&pNode->hnode,&hash_array[index]); } printk("IP ALEADY EXISTED\n"); @@ -88,7 +86,7 @@ int add_user(uint32_t ip, int id) void del_user(uint32_t ip) { int index; - struct list_head *pos; + struct list_head *pos, *n; USERINFO *pNode; index = get_hash_index(ip); @@ -100,13 +98,15 @@ void del_user(uint32_t ip) } /*查找用户ip */ - list_for_each(pos, &hash_array[index]) + write_lock(&g_obj_lock); + list_for_each_safe(pos, n, &hash_array[index]) { pNode = list_entry(pos, USERINFO, hnode); if(pNode->user_ip == ip) list_del(&pNode->hnode); kfree(pNode); } + write_unlock(&g_obj_lock); return; } @@ -123,12 +123,14 @@ void free_all_user(void) { if(list_empty(&hash_array[i])) continue; + write_lock(&g_obj_lock); list_for_each_safe(pos, n, &hash_array[i]) { pNode = list_entry(pos, USERINFO, hnode); list_del(&pNode->hnode); kfree(pNode); } + write_unlock(&g_obj_lock); } } @@ -142,11 +144,13 @@ void printk_all_user(void) for(i = 0; i < HASH_SIZE; i++) continue; + read_lock(&g_obj_lock); list_for_each_safe(pos, n, &hash_array[i]) { pNode = list_entry(pos, USERINFO, hnode); printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id); } + read_unlock(&g_obj_lock); } From 5ea4f283da3cb2015ce0eff508ccceaa055bb5c6 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 17:47:38 +0800 Subject: [PATCH 07/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configm/config-server/include/brconfig.h | 4 +- .../config-server/netconfig/bridge/brconfig.c | 4 +- .../netconfig/bridge/brnetlink.c | 1 + .../bridge/{ => include}/brnetlink.h | 0 .../config.h.in => include/libbrconfig.h} | 53 ++++++++++--------- .../bridge/{libbridge => include}/libbridge.h | 0 .../libbridge_private.h | 2 +- .../netconfig/bridge/libbridge/.gitignore | 2 - .../netconfig/bridge/libbridge/Makefile.in | 41 -------------- 9 files changed, 33 insertions(+), 74 deletions(-) rename Platform/user/configm/config-server/netconfig/bridge/{ => include}/brnetlink.h (100%) rename Platform/user/configm/config-server/netconfig/bridge/{libbridge/config.h.in => include/libbrconfig.h} (67%) rename Platform/user/configm/config-server/netconfig/bridge/{libbridge => include}/libbridge.h (100%) rename Platform/user/configm/config-server/netconfig/bridge/{libbridge => include}/libbridge_private.h (98%) delete mode 100644 Platform/user/configm/config-server/netconfig/bridge/libbridge/.gitignore delete mode 100644 Platform/user/configm/config-server/netconfig/bridge/libbridge/Makefile.in diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 3b2c6cd70..001b4ee3c 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -20,8 +20,6 @@ typedef enum { BR_EVENT_INVALID } BR_EVENT_TYPE; -typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type, br_event_t event_arg); - /************************************************************/ /* 结构体 */ /************************************************************/ @@ -109,6 +107,8 @@ struct _br_fdb_status{ }; typedef struct _br_fdb_status br_fdb_status_t; +typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type, br_event_t event_arg); + /* **********************************************************/ /* 提供给其他模块调用的函数 */ /************************************************************/ diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 82f1c6066..f4ded66cc 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -4,15 +4,15 @@ #include #include #include +#include "list.h" #include "configm.h" #include "brconfig.h" #include "rpc.h" #include "parsefile.h" -#include "libbridge.h" #include "brnetlink.h" #include "parsefile.h" -#include "list.h" +#include "libbridge.h" #ifndef DESC("事件通知函数") struct br_event_head_t br_event_tbl = {.lock = 0, .init = false}; diff --git a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c index eeea5c1d3..1b3ae8074 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c @@ -12,6 +12,7 @@ #include #include "brnetlink.h" +#include "rpc_common.h" #define BR_NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) diff --git a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.h b/Platform/user/configm/config-server/netconfig/bridge/include/brnetlink.h similarity index 100% rename from Platform/user/configm/config-server/netconfig/bridge/brnetlink.h rename to Platform/user/configm/config-server/netconfig/bridge/include/brnetlink.h diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/config.h.in b/Platform/user/configm/config-server/netconfig/bridge/include/libbrconfig.h similarity index 67% rename from Platform/user/configm/config-server/netconfig/bridge/libbridge/config.h.in rename to Platform/user/configm/config-server/netconfig/bridge/include/libbrconfig.h index 22d1d7a85..9ea046017 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/config.h.in +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libbrconfig.h @@ -1,79 +1,80 @@ +/* libbridge/config.h. Generated from config.h.in by configure. */ /* libbridge/config.h.in. Generated from configure.in by autoheader. */ /* Define to 1 if you have the `gethostname' function. */ -#undef HAVE_GETHOSTNAME +#define HAVE_GETHOSTNAME 1 /* Define to 1 if you have the `if_indextoname' function. */ -#undef HAVE_IF_INDEXTONAME +#define HAVE_IF_INDEXTONAME 1 /* Define to 1 if you have the `if_nametoindex' function. */ -#undef HAVE_IF_NAMETOINDEX +#define HAVE_IF_NAMETOINDEX 1 /* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H +#define HAVE_INTTYPES_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H +#define HAVE_MEMORY_H 1 /* Define to 1 if you have the `socket' function. */ -#undef HAVE_SOCKET +#define HAVE_SOCKET 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H +#define HAVE_STDINT_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H +#define HAVE_STDLIB_H 1 /* Define to 1 if you have the `strdup' function. */ -#undef HAVE_STRDUP +#define HAVE_STRDUP 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H +#define HAVE_STRINGS_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H +#define HAVE_STRING_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_SYS_IOCTL_H +#define HAVE_SYS_IOCTL_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H +#define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TIME_H +#define HAVE_SYS_TIME_H 1 /* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H +#define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the `uname' function. */ -#undef HAVE_UNAME +#define HAVE_UNAME 1 /* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H +#define HAVE_UNISTD_H 1 /* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT +#define PACKAGE_BUGREPORT "" /* Define to the full name of this package. */ -#undef PACKAGE_NAME +#define PACKAGE_NAME "bridge-utils" /* Define to the full name and version of this package. */ -#undef PACKAGE_STRING +#define PACKAGE_STRING "bridge-utils 1.6" /* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME +#define PACKAGE_TARNAME "bridge-utils" /* Define to the home page for this package. */ -#undef PACKAGE_URL +#define PACKAGE_URL "" /* Define to the version of this package. */ -#undef PACKAGE_VERSION +#define PACKAGE_VERSION "1.6" /* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS +#define STDC_HEADERS 1 /* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME +#define TIME_WITH_SYS_TIME 1 /* Define to empty if `const' does not conform to ANSI C. */ -#undef const +/* #undef const */ diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge.h b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h similarity index 100% rename from Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge.h rename to Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_private.h b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h similarity index 98% rename from Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_private.h rename to Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h index 99a511dae..2089667b2 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_private.h +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h @@ -19,7 +19,7 @@ #ifndef _LIBBRIDGE_PRIVATE_H #define _LIBBRIDGE_PRIVATE_H -#include "config.h" +#include "libbrconfig.h.h" #include #include diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/.gitignore b/Platform/user/configm/config-server/netconfig/bridge/libbridge/.gitignore deleted file mode 100644 index f61154864..000000000 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -config.h -stamp-h1 diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/Makefile.in b/Platform/user/configm/config-server/netconfig/bridge/libbridge/Makefile.in deleted file mode 100644 index 20512c455..000000000 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/Makefile.in +++ /dev/null @@ -1,41 +0,0 @@ - -KERNEL_HEADERS=-I@KERNEL_HEADERS@ - -AR=ar -RANLIB=@RANLIB@ - -CC=@CC@ -CFLAGS = -Wall -g $(KERNEL_HEADERS) - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -includedir=@includedir@ -libdir=@libdir@ - -libbridge_SOURCES= \ - libbridge_devif.c \ - libbridge_if.c \ - libbridge_init.c \ - libbridge_misc.c - -libbridge_OBJECTS=$(libbridge_SOURCES:.c=.o) - -all: libbridge.a - -# At present there is no need for a bridge-utils-devel package -install: - - -clean: - rm -f *.o libbridge.a - -libbridge.a: $(libbridge_OBJECTS) - $(AR) rcs $@ $(libbridge_OBJECTS) - $(RANLIB) $@ - -%.o: %.c libbridge.h libbridge_private.h - $(CC) $(CFLAGS) $(INCLUDE) -c $< - -libbridge_compat.o: libbridge_compat.c if_index.c - $(CC) $(CFLAGS) -c libbridge_compat.c - From dd6153aac369155914331c0538762a3430fc03f0 Mon Sep 17 00:00:00 2001 From: zhangtaohz Date: Fri, 2 Aug 2019 17:58:02 +0800 Subject: [PATCH 08/19] =?UTF-8?q?Add=20=20aaa-12=20add=20log=20configure?= =?UTF-8?q?=20manager=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Azhangtao=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/build/user.configm.Makefile | 9 +-- Platform/build/user.ulog.log_sched.Makefile | 2 +- Platform/common/configm/configmapi.h | 0 Platform/common/ulog/ulog_in.h | 11 ++++ .../configm/config-server/include/configm.h | 24 ++++++- .../config-server/include/log_config.h | 17 +++++ .../log_config/log_config_console.c | 63 +++++++++++++++++++ .../config-server/log_config/log_config_h.h | 7 +++ .../log_config/log_config_init.c | 27 ++++++++ Platform/user/ulog/log-sched/log_common.c | 2 +- Platform/user/ulog/log-sched/log_common.h | 2 +- Platform/user/ulog/log-sched/log_console.c | 1 + Platform/user/ulog/log-sched/log_console.h | 6 -- Platform/user/ulog/log-sched/log_pty.c | 1 + Platform/user/ulog/log-sched/log_pty.h | 2 - Platform/user/ulog/log-sched/log_remote.c | 2 +- Platform/user/ulog/log-sched/log_sched.c | 8 +-- 17 files changed, 160 insertions(+), 24 deletions(-) mode change 100644 => 100755 Platform/common/configm/configmapi.h create mode 100755 Platform/common/ulog/ulog_in.h mode change 100644 => 100755 Platform/user/configm/config-server/include/configm.h create mode 100755 Platform/user/configm/config-server/include/log_config.h create mode 100755 Platform/user/configm/config-server/log_config/log_config_console.c create mode 100755 Platform/user/configm/config-server/log_config/log_config_h.h create mode 100755 Platform/user/configm/config-server/log_config/log_config_init.c diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index 52534b784..da676a649 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -34,13 +34,14 @@ COMMON_SRCS = configserver.c \ jumppage_config/jumppage.c \ agingtime_config/agingtime.c \ user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \ - user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c + user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \ + log_config/log_config_console.c log_config/log_config_init.c # MRS Board Source Files PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_ARM64_SRCS = $(COMMON_SRCS) -COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable +COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog # gcc CFLAGS PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include @@ -49,10 +50,10 @@ PLAT_ARM64_LDFLAGS := PLAT_LINUX_LDFLAGS := #gcc libs -ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so +ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so ./libulogapi-arm64.so ARM64_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so +LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so ./libulogapi-linux.so LINUX_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis ifeq ($(PLAT_ARM64), TRUE) diff --git a/Platform/build/user.ulog.log_sched.Makefile b/Platform/build/user.ulog.log_sched.Makefile index 134a94902..f4645297a 100755 --- a/Platform/build/user.ulog.log_sched.Makefile +++ b/Platform/build/user.ulog.log_sched.Makefile @@ -34,7 +34,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_ARM64_SRCS = $(COMMON_SRCS) # gcc CFLAGS -PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../user/ulog +PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../common/ulog -I../user/ulog PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) diff --git a/Platform/common/configm/configmapi.h b/Platform/common/configm/configmapi.h old mode 100644 new mode 100755 diff --git a/Platform/common/ulog/ulog_in.h b/Platform/common/ulog/ulog_in.h new file mode 100755 index 000000000..23a6d400b --- /dev/null +++ b/Platform/common/ulog/ulog_in.h @@ -0,0 +1,11 @@ +#ifndef _ULOG_IN_H +#define _ULOG_IN_H + +#define SERVICE_LOG_FILE_NAME "log-file" +#define SERIVCE_LOG_CONSOLE_NAME "log-console" +#define SERVICE_LOG_PTY_NAME "log-pty" +#define SERVICE_LOG_REMOTE_NAME "log-remote" + +#define CONF_LOG_CONSOLE_FUNC "conf_log_console" + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h old mode 100644 new mode 100755 index 5ce54a515..1a93e807e --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -7,6 +7,7 @@ #include "../../../../../Common/commuapinl.h" #include "../user_manager_config/user_group_config.h" #include "../user_manager_config/user_account_config.h" +#include "log_config.h" #include "authfree.h" #include "localportal.h" #include "jumppage.h" @@ -24,6 +25,9 @@ /*PORTAL SERVER CONFIG */ #define LOCALAUTH_CONFIG_MODULE 0x00000003 +#define LOG_CONFIG_MODULE 0x00000004 + + /* config id define*/ #define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1) @@ -37,12 +41,18 @@ #define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4) #define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5) +#define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1) + #define CONFIG_INIT_ARRAY \ {\ {\ NETCONFIG_MODULE,\ NULL\ - }\ + },\ + { \ + LOG_CONFIG_MODULE, \ + log_config_init \ + } \ } /* @@ -137,7 +147,17 @@ user_config_proc, \ user_config_get, \ user_config_get_all \ - }\ + },\ + {\ + LOG_CONFIG_CONSOLE, \ + CONFIG_FROM_WEB, \ + FALSE, \ + FALSE, \ + log_console_config_chk, \ + log_console_config_proc, \ + NULL, \ + NULL \ + }\ } typedef ret_code (*cm_config_init)(); diff --git a/Platform/user/configm/config-server/include/log_config.h b/Platform/user/configm/config-server/include/log_config.h new file mode 100755 index 000000000..bf4bd92de --- /dev/null +++ b/Platform/user/configm/config-server/include/log_config.h @@ -0,0 +1,17 @@ +#ifndef _LOG_CONFIG_H +#define _LOG_CONFIG_H + +#include + +#include "rpc_types.h" +#include "rpc_common.h" + +ret_code log_config_init(); +ret_code log_console_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); +ret_code log_console_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/log_config/log_config_console.c b/Platform/user/configm/config-server/log_config/log_config_console.c new file mode 100755 index 000000000..6fd98cebf --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_console.c @@ -0,0 +1,63 @@ +#include + +#include "rpc_server.h" +#include "log_config.h" +#include "configm.h" +#include "log_types.h" +#include "ulog_in.h" +#include "log_config_h.h" + +ret_code log_console_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len) +{ + if (input == NULL) { + ULOG_ERR(g_log_h, "input can't null"); + return RET_INPUTERR; + } + + cJSON *json_obj = cJSON_Parse(input); + if(!json_obj) + { + ULOG_ERR(g_log_h, "Error log console format"); + return RET_INPUTERR; + } + + ULOG_DEBUG("json input: %s", cJSON_Print(json_obj)); + + s2j_create_struct_obj(log_console, log_console_t); + if(log_console == NULL) + { + cJSON_Delete(json_obj); + ULOG_ERR(g_log_h, "Creating log console of object is failure"); + return RET_NOMEM; + } + + s2j_struct_get_basic_element(log_console, json_obj, int, level); + s2j_struct_get_basic_element(log_console, json_obj, int, on); + S2J_STRUCT_GET_STRING_ELEMENT_N(log_console, json_obj, module_name, MAX_MODULE_NAME_SZ); + + *input_len = sizeof(*log_console); + memcpy(input, log_console, *input_len); + + return RET_OK; +} + +ret_code log_console_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len) +{ + if ((input == NULL) + && input_len < sizeof(log_console_t)) { + return RET_INPUTERR; + } + + ret_code ret = rpc_client_call(g_log_client, SERIVCE_LOG_CONSOLE_NAME, + CONF_LOG_CONSOLE_FUNC, input, input_len, NULL, NULL); + if (ret != RET_OK) { + ULOG_ERR(g_log_h, "rpc call is failure[ret:%u, method:%s]", ret, CONF_LOG_CONSOLE_FUNC); + } + + return ret; +} + diff --git a/Platform/user/configm/config-server/log_config/log_config_h.h b/Platform/user/configm/config-server/log_config/log_config_h.h new file mode 100755 index 000000000..33dc5b285 --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_h.h @@ -0,0 +1,7 @@ +#ifndef _LOG_CONFIG_H_H +#define _LOG_CONFIG_H_H + +extern rpc_client *g_log_client; +extern ulog_t *g_log_h; + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/log_config/log_config_init.c b/Platform/user/configm/config-server/log_config/log_config_init.c new file mode 100755 index 000000000..9b4066e5c --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_init.c @@ -0,0 +1,27 @@ +#include "rpc_server.h" +#include "log_config.h" +#include "ulog_in.h" +#include "ulog_api.h" + +rpc_client *g_log_client; +ulog_t *g_log_h; + + +ret_code log_config_init() +{ + g_log_h = ulog_init("log_config", 1); + if (g_log_h) { + fprintf(stderr, "Initiating log_config is failure"); + return RET_ERR; + } + + g_log_client = rpc_client_connect_ex(RPC_MODULE_SYSLOG_NAME); + if (g_log_client == NULL) { + ULOG_ERR(g_log_h, "Initiating rpc client is failure"); + return RET_ERR; + } + + return RET_OK; +} + + diff --git a/Platform/user/ulog/log-sched/log_common.c b/Platform/user/ulog/log-sched/log_common.c index 383cedb09..f6e978fe1 100755 --- a/Platform/user/ulog/log-sched/log_common.c +++ b/Platform/user/ulog/log-sched/log_common.c @@ -124,7 +124,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file return __log_conf("a", level, conf_path, conf_file, filter_mod, cb_content, arg); } -int log_level_to_str(const u8 level, char *str, u8 len) +int log_level_to_str(const u8 level, char *str, u32 len) { u8 i; char tmp[20]; diff --git a/Platform/user/ulog/log-sched/log_common.h b/Platform/user/ulog/log-sched/log_common.h index bc789cbbb..885e8f942 100755 --- a/Platform/user/ulog/log-sched/log_common.h +++ b/Platform/user/ulog/log-sched/log_common.h @@ -41,7 +41,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file int (*cb_content)(FILE *fp, const u8 level, const char *filter_mod, void *arg), void *arg); int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg); int write_conf_content_authorizing(FILE *fp, const u8 level, const char *filter_mod, void *arg); -int log_level_to_str(const u8 level, char *str, u8 len); +int log_level_to_str(const u8 level, char *str, u32 len); #endif diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index f78eabd90..2635d6542 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -3,6 +3,7 @@ #include #include "log_console.h" +#include "log_types.h" #include "log_common.h" #define LOG_CONF_COSOLE_FILE_NAME "log-console.conf" diff --git a/Platform/user/ulog/log-sched/log_console.h b/Platform/user/ulog/log-sched/log_console.h index f4aac8489..9296cb79f 100755 --- a/Platform/user/ulog/log-sched/log_console.h +++ b/Platform/user/ulog/log-sched/log_console.h @@ -5,12 +5,6 @@ #include "common_types.h" #include "rpc_common.h" -typedef struct _log_console { - u8 level; - u8 on; - char module_name[MAX_MODULE_NAME_SZ]; -} log_console_t; - void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data); #endif diff --git a/Platform/user/ulog/log-sched/log_pty.c b/Platform/user/ulog/log-sched/log_pty.c index 2be07f7d1..5fecc9b68 100755 --- a/Platform/user/ulog/log-sched/log_pty.c +++ b/Platform/user/ulog/log-sched/log_pty.c @@ -4,6 +4,7 @@ #include #include "log_pty.h" +#include "log_types.h" #include "log_common.h" #define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/" diff --git a/Platform/user/ulog/log-sched/log_pty.h b/Platform/user/ulog/log-sched/log_pty.h index 9a940bb25..8e9d6bfca 100755 --- a/Platform/user/ulog/log-sched/log_pty.h +++ b/Platform/user/ulog/log-sched/log_pty.h @@ -3,8 +3,6 @@ #include "log_console.h" -typedef log_console_t log_pty_t; - void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data); #endif \ No newline at end of file diff --git a/Platform/user/ulog/log-sched/log_remote.c b/Platform/user/ulog/log-sched/log_remote.c index c4990daca..8be0bdc46 100755 --- a/Platform/user/ulog/log-sched/log_remote.c +++ b/Platform/user/ulog/log-sched/log_remote.c @@ -172,7 +172,7 @@ static int remote_conf_level_content(FILE *fp, const u8 level) ULOG_DEBUG(g_log, "Recover old line:%s to file:%s", rewrite_line, path); n1 = fwrite(rewrite_line, 1, n3, fp); if (n3 != n1) { - ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", line, strerror(errno)); + ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", rewrite_line, strerror(errno)); goto END; } } diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index d8952a6ba..2094d5eca 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -12,15 +12,11 @@ #include "log_pty.h" #include "log_remote.h" #include "rpc_module.h" +#include "ulog_in.h" #define LOG_SCHED_MODULE_NAME "log-sched" -#define SERVICE_LOG_FILE_NAME "log-file" -#define SERIVCE_LOG_CONSOLE_NAME "log-console" -#define SERVICE_LOG_PTY_NAME "log-pty" -#define SERVICE_LOG_REMOTE_NAME "log-remote" - #define DEFAULT_CONFIG_FILE "/etc/log-sched.conf" ulog_t *g_log = NULL; @@ -89,7 +85,7 @@ int main(int argc, char **argv) /* 注册配置处理函数 */ rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file); - rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, "conf_log_console", rpc_conf_log_console); + rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console); rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, "conf_log_pty", rpc_conf_log_pty); rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_add_remote", rpc_conf_log_add_remote); rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_del_remote", rpc_conf_log_del_remote); From 7e6b2d02d3d7568025ba132c85d4ee928606dc3f Mon Sep 17 00:00:00 2001 From: zhangtaohz Date: Fri, 2 Aug 2019 18:03:13 +0800 Subject: [PATCH 09/19] =?UTF-8?q?Add=20=20aaa-12=20add=20log=20configure?= =?UTF-8?q?=20manager=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Azhangtao=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/log_types.h | 14 ++++++++++++++ Makefile | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100755 Common/log_types.h diff --git a/Common/log_types.h b/Common/log_types.h new file mode 100755 index 000000000..c3ea4a21a --- /dev/null +++ b/Common/log_types.h @@ -0,0 +1,14 @@ +#ifndef _LOG_CONFIG_API_H +#define _LOG_CONFIG_API_H + +#include "ulog_api.h" + +typedef struct _log_console { + u8 level; + u8 on; + char module_name[MAX_MODULE_NAME_SZ]; +} log_console_t; + +typedef log_console_t log_pty_t; + +#endif \ No newline at end of file diff --git a/Makefile b/Makefile index 5e06bcfb2..936327a05 100755 --- a/Makefile +++ b/Makefile @@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l) endif endif -.PHONY : demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable +.PHONY : openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable -all: demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable +all: openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable ifeq ($(OPT), install) #$(shell `find ../release -name "*.zip" -delete`) From c1dee62cbc7eb802b355ed97cac0838809c8976a Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 18:11:34 +0800 Subject: [PATCH 10/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configm/config-server/include/brconfig.h | 5 ++- .../config-server/netconfig/bridge/brconfig.c | 39 ++++++------------- .../netconfig/bridge/brnetlink.c | 3 ++ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 001b4ee3c..395612abf 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -30,6 +30,9 @@ struct _br_event { }; typedef struct _br_event br_event_t; +typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type, + br_event_t event_arg); + struct _br_event_node { struct hlist_node list; BR_EVENT_TYPE br_event; @@ -107,8 +110,6 @@ struct _br_fdb_status{ }; typedef struct _br_fdb_status br_fdb_status_t; -typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type, br_event_t event_arg); - /* **********************************************************/ /* 提供给其他模块调用的函数 */ /************************************************************/ diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index f4ded66cc..211c0cb61 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -14,8 +14,8 @@ #include "parsefile.h" #include "libbridge.h" -#ifndef DESC("事件通知函数") -struct br_event_head_t br_event_tbl = {.lock = 0, .init = false}; +/* 事件通知函数 */ +br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = false}; int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg) { @@ -38,7 +38,8 @@ int br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) br_event_node_t *hnode = NULL; if(br_event_tbl.init == false) - { INIT_HLIST_HEAD(&(br_event_tbl.head); + { + INIT_HLIST_HEAD(&(br_event_tbl.head)); pthread_mutex_init(&(br_event_tbl.lock), NULL); br_event_tbl.init = true; } @@ -87,8 +88,7 @@ int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) return 0; } -#endif -#ifndef DESC("桥配置辅助函数") +/* 桥配置辅助函数 */ int br_copy_port_name(const char *b, const char *p, void *arg) { br_if_temp_t *br_if = (br_if_temp_t *)arg; @@ -342,10 +342,7 @@ ret_code br_bridge_del(char * br_name, int *sys_err) return RET_OK; } -#endif - - -#ifndef DESC("桥配置json格式转换函数") +/* 桥配置json格式转换函数 */ ret_code br_config_json_parse(pointer input, uint *conf_type, char *br_name) { @@ -511,9 +508,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br return RET_OK; } -#endif - -#ifndef DESC("桥配置钩子函数") +/* 桥配置钩子函数 */ ret_code br_config_chk(uint source,uint *config_type, pointer input, int *input_len, pointer output, int *output_len) @@ -583,10 +578,7 @@ ret_code br_config_proc(uint source, uint config_type, return ret; } -#endif - - -#ifndef DESC("桥接口配置钩子函数") +/* 桥接口配置钩子函数 */ ret_code br_if_config_chk(uint source,uint *config_type, pointer input, int *input_len, pointer output, int *output_len) @@ -714,10 +706,7 @@ ret_code br_if_config_get_all(uint source, return ret; } - -#endif - -#ifndef DESC("桥FDB配置辅助函数") +/* 桥FDB配置辅助函数 */ void br_format_time(const struct timeval *tv, char *str, int len) { @@ -852,9 +841,7 @@ int br_fdb_cpy(br_fdb_status_t *fdb_status, struct fdb_entry *fdb) return i; } -#endif - -#ifndef DESC("桥FDB配置json格式转换") +/* 桥FDB配置json格式转换 */ ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_t *br_fdb) { cJSON *json_obj; @@ -937,10 +924,7 @@ int br_fdb_to_json_string(br_fdb_status_t *fdb_status, char *output) return (strlen(output) + 1); } -#endif - - -#ifndef DESC("桥FDB表配置钩子函数") +/* 桥FDB表配置钩子函数 */ ret_code br_fdb_config_chk(uint source,uint *config_type, pointer input, int *input_len, pointer output, int *output_len) @@ -1007,4 +991,3 @@ ret_code br_fdb_config_get(uint source, return ret; } -#endif diff --git a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c index 1b3ae8074..c352fed98 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c @@ -12,6 +12,9 @@ #include #include "brnetlink.h" +#include "ipconfig.h" +#include "brconfig.h" +#include "rpc_util.h" #include "rpc_common.h" #define BR_NLMSG_TAIL(nmsg) \ From 119abe73baacc71384a3e5fe51ac3450b0647f1a Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 18:49:50 +0800 Subject: [PATCH 11/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configm/config-server/include/brconfig.h | 2 +- .../config-server/netconfig/bridge/brconfig.c | 64 +++++++++++-------- .../netconfig/bridge/brnetlink.c | 12 +++- .../bridge/include/libbridge_private.h | 2 +- .../bridge/libbridge/libbridge_init.c | 2 +- 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 395612abf..c5db06298 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -115,7 +115,7 @@ typedef struct _br_fdb_status br_fdb_status_t; /************************************************************/ /* 通过接口名获取所在桥名 */ -int br_if_bridge_get(char *port_name , char *br_name); +ret_code br_if_bridge_get(char *port_name , char *br_name); /* 向桥中添加接口 */ ret_code br_if_bridge_add(char *br_name, char *port_list, diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 211c0cb61..8b908a0cb 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -13,9 +13,10 @@ #include "brnetlink.h" #include "parsefile.h" #include "libbridge.h" +#include "libbridge_private.h" /* 事件通知函数 */ -br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = false}; +br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = FALSE}; int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg) { @@ -37,11 +38,11 @@ int br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) { br_event_node_t *hnode = NULL; - if(br_event_tbl.init == false) + if(br_event_tbl.init == FALSE) { INIT_HLIST_HEAD(&(br_event_tbl.head)); pthread_mutex_init(&(br_event_tbl.lock), NULL); - br_event_tbl.init = true; + br_event_tbl.init = TRUE; } hnode = (br_event_node_t *)rpc_new0(br_event_node_t, 1); @@ -97,7 +98,7 @@ int br_copy_port_name(const char *b, const char *p, void *arg) br_if->if_list = realloc(br_if->if_list, INTERFACE_NAMSIZ); ASSERT_PTR_RET(br_if->if_list); - dst_ptr = br_if->if_list + br_if->index * INTERFACE_NAMSIZ + dst_ptr = br_if->if_list + br_if->index * INTERFACE_NAMSIZ; strncpy(dst_ptr, p, INTERFACE_NAMSIZ - 1); br_if->index++; @@ -122,7 +123,7 @@ int br_name_cmp(char *br_name, void *args) if(strcmp(br_name, cmp_args->br_name) == 0) { - cmp_args->result = true; + cmp_args->result = TRUE; return 1; } @@ -198,7 +199,7 @@ ret_code br_save_file(BR_EVENT_TYPE event_type, if_conf_file_add(br_name); break; case BR_DELETE_EVENT: - if_conf_file_del(br_name) + if_conf_file_del(br_name); break; case BR_IF_JOIN_EVENT: if(if_conf_file_get(br_name, key_str, config_str) == RET_OK) @@ -234,24 +235,27 @@ ret_code br_save_file(BR_EVENT_TYPE event_type, ret_code br_if_bridge_add(char *br_name, char *port_list, int cnt, int *sys_err) { + br_event_t event_arg = {0}; ret_code ret = RET_OK; char *port_name; int err = 0; int i; - for(i = 0; i < cnt) + for(i = 0; i < cnt; i++) { br_invoke_event(BR_IF_JOIN_EVENT_PRE, event_arg); port_name = port_list + INTERFACE_NAMSIZ * i; err = br_add_interface(br_name, port_name); if(err != 0) { - sys_err = err; + *sys_err = err; ret = RET_SYSERR; continue; } - br_event_t event_arg = {br_name, port_name}; + event_arg.br_name = br_name; + event_arg.if_name = port_name; + br_invoke_event(BR_IF_JOIN_EVENT, event_arg); br_save_file(BR_IF_JOIN_EVENT, br_name, port_name); @@ -262,24 +266,27 @@ ret_code br_if_bridge_add(char *br_name, char *port_list, int cnt, int *sys_err) ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err) { + br_event_t event_arg = {0}; ret_code ret = RET_OK; - char *port_name; + char *port_name; int err = 0; int i; - for(i = 0; i < cnt) + for(i = 0; i < cnt; i++) { br_invoke_event(BR_IF_LEAVE_EVENT_PRE, event_arg); port_name = port_list + INTERFACE_NAMSIZ * i; err = br_del_interface(br_name, port_name); if(err != 0) { - sys_err = err; + *sys_err = err; ret = RET_SYSERR; continue; } - br_event_t event_arg = {br_name, port_name}; + event_arg.br_name = br_name; + event_arg.if_name = port_name; + br_invoke_event(BR_IF_LEAVE_EVENT, event_arg); br_save_file(BR_IF_LEAVE_EVENT, br_name, port_name); @@ -383,7 +390,7 @@ int br_json_to_string( cJSON *json_obj, pointer output) return 0; } - json_str = cJSON_PrintUnformatted(json_array); + json_str = cJSON_PrintUnformatted(json_obj); output_len = strlen(json_str) + 1; if(output_len > CM_BUFF_SIZE) @@ -403,8 +410,6 @@ int br_json_to_string( cJSON *json_obj, pointer output) cJSON *br_config_format_json(br_config_t *br_config) { - cJSON *json_obj; - s2j_create_json_obj(json_obj); if(json_obj == NULL) { @@ -427,7 +432,7 @@ ret_code br_bridge_info( char *br_name, cJSON *json_obj, int *err) br_if.index = 0; br_if.if_list = NULL; - *err = br_foreach_port(br_name, br_copy_port_name, &br_if) + *err = br_foreach_port(br_name, br_copy_port_name, &br_if); if (*err >= 0) { strncpy(br_config.br_name, br_name, BR_NAMSIZ - 1); @@ -448,7 +453,7 @@ ret_code br_bridge_info( char *br_name, cJSON *json_obj, int *err) return ret; } -int br_bridge_info_each(const char *br_name, void *args) +int br_bridge_info_each(char *br_name, void *args) { cJSON *json_array = (cJSON *)args; cJSON *json_obj = NULL; @@ -488,7 +493,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br if(br_if_conf->config_type != CM_CONFIG_GET_ALL) { - s2j_struct_get_string_element(br_if_conf, json_obj, string, br_name, BR_NAMSIZ); + s2j_struct_get_string_element(br_if_conf, json_obj, br_name, BR_NAMSIZ); strncpy(br_if->br_name, br_if_conf->br_name, BR_NAMSIZ - 1); } @@ -727,7 +732,8 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname) int ifindices[MAX_PORTS]; unsigned long args[4] = { BRCTL_GET_PORT_LIST, (unsigned long)ifindices, MAX_PORTS, 0 }; - struct ifreq ifr; + struct ifreq ifr; + int br_fd = -1; if (port_no >= MAX_PORTS) return -1; @@ -736,17 +742,27 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname) strncpy(ifr.ifr_name, brname, IFNAMSIZ); ifr.ifr_data = (char *) &args; - if (ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr) < 0) { + + + if ((br_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) + { + return -1; + } + + if (ioctl(br_fd, SIOCDEVPRIVATE, &ifr) < 0) { dprintf("get_portno: get ports of %s failed: %s\n", brname, strerror(errno)); + close(br_fd); return -1; } if(if_indextoname(ifindices[port_no], ifname) == NULL) { + close(br_fd); return -1; } - + + close(br_fd); return 0; } @@ -876,9 +892,8 @@ ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_ ret_code br_each_fdb_to_json_string(cJSON *json_array, fdb_info_t *fdb_info) { - cJSON *fdb_obj; - s2j_create_json_obj(fdb_obj); + if(fdb_obj == NULL) { return RET_NOMEM; @@ -896,7 +911,6 @@ ret_code br_each_fdb_to_json_string(cJSON *json_array, fdb_info_t *fdb_info) int br_fdb_to_json_string(br_fdb_status_t *fdb_status, char *output) { - cJSON *br_obj; cJSON *fdb_array; char *json_str; int i; diff --git a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c index c352fed98..886ca3c9a 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c @@ -7,15 +7,21 @@ #include #include +#include #include #include #include +#include "list.h" -#include "brnetlink.h" -#include "ipconfig.h" -#include "brconfig.h" +#include "rpc_types.h" #include "rpc_util.h" #include "rpc_common.h" +#include "brnetlink.h" + +#include "ipconfig.h" +#include "brconfig.h" +#include "libbridge.h" + #define BR_NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) diff --git a/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h index 2089667b2..f19b89e27 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge_private.h @@ -19,7 +19,7 @@ #ifndef _LIBBRIDGE_PRIVATE_H #define _LIBBRIDGE_PRIVATE_H -#include "libbrconfig.h.h" +#include "libbrconfig.h" #include #include diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c b/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c index 764a60faf..66a6f47da 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c +++ b/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c @@ -151,7 +151,7 @@ int br_cnt_num(const char *name, void *arg) (*cnt)++; - return 0 + return 0; } int br_for_bridge_num(int *cnt) From 95dc8feac9d42ac6d5e8adf1db0ca3763c111274 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 19:06:01 +0800 Subject: [PATCH 12/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2j.h | 4 +- .../config-server/netconfig/bridge/brconfig.c | 15 +- .../netconfig/bridge/brnetlink.c | 2 +- .../netconfig/bridge/include/libnetlink.h | 280 ++++++++++++++++++ 4 files changed, 291 insertions(+), 10 deletions(-) create mode 100644 Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h diff --git a/Common/s2j/s2j.h b/Common/s2j/s2j.h index 8d2642e30..19912706b 100644 --- a/Common/s2j/s2j.h +++ b/Common/s2j/s2j.h @@ -72,8 +72,8 @@ extern "C" { #define s2j_struct_get_basic_element(to_struct, from_json, type, element) \ S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element) -#define s2j_struct_get_string_element(to_struct, from_json, type, element, n) \ - S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, type, element, n) +#define s2j_struct_get_string_element(to_struct, from_json, element, n) \ + S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, element, n) /* Get array type element for structure object */ #define s2j_struct_get_array_element(to_struct, from_json, type, element) \ diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 8b908a0cb..e77e66931 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -68,7 +68,7 @@ int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) br_event_node_t *hnode = NULL; struct hlist_node *n; - if(br_event_tbl.init == false) + if(br_event_tbl.init == FALSE) { return 0; } @@ -117,7 +117,7 @@ ret_code br_name_chk(char *br_name) return RET_OK; } -int br_name_cmp(char *br_name, void *args) +int br_name_cmp(const char *br_name, void *args) { br_temp_t *cmp_args = (br_temp_t *)args; @@ -132,7 +132,7 @@ int br_name_cmp(char *br_name, void *args) boolean br_is_exist(char *br_name) { - br_temp_t cmp_args = {br_name, false}; + br_temp_t cmp_args = {br_name, FALSE}; br_foreach_bridge(br_name_cmp, &cmp_args); @@ -298,6 +298,7 @@ ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err int br_if_bridge_num(char *br_name) { int cnt = 0; + int err = 0; err = br_for_port_num(br_name, &cnt); cnt = (err != 0) ? 0 : cnt; @@ -423,7 +424,7 @@ cJSON *br_config_format_json(br_config_t *br_config) return json_obj; } -ret_code br_bridge_info( char *br_name, cJSON *json_obj, int *err) +ret_code br_bridge_info(const char *br_name, cJSON *json_obj, int *err) { ret_code ret = RET_OK; br_if_temp_t br_if = {0}; @@ -453,7 +454,7 @@ ret_code br_bridge_info( char *br_name, cJSON *json_obj, int *err) return ret; } -int br_bridge_info_each(char *br_name, void *args) +int br_bridge_info_each(const char *br_name, void *args) { cJSON *json_array = (cJSON *)args; cJSON *json_obj = NULL; @@ -610,7 +611,7 @@ ret_code br_if_config_chk(uint source,uint *config_type, goto exit; } - if(br_is_exist(br_config.br_name) == false) + if(br_is_exist(br_config.br_name) == FALSE) { ret = RET_NOTFOUND; goto exit; @@ -906,7 +907,7 @@ ret_code br_each_fdb_to_json_string(cJSON *json_array, fdb_info_t *fdb_info) cJSON_AddItemToArray(json_array, fdb_obj); - return RET_OK + return RET_OK; } int br_fdb_to_json_string(br_fdb_status_t *fdb_status, char *output) diff --git a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c index 886ca3c9a..35b6f8117 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brnetlink.c @@ -7,10 +7,10 @@ #include #include -#include #include #include #include +#include "libnetlink.h" #include "list.h" #include "rpc_types.h" diff --git a/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h b/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h new file mode 100644 index 000000000..cdd064663 --- /dev/null +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h @@ -0,0 +1,280 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBNETLINK_H__ +#define __LIBNETLINK_H__ 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rtnl_handle { + int fd; + struct sockaddr_nl local; + struct sockaddr_nl peer; + __u32 seq; + __u32 dump; + int proto; + FILE *dump_fp; +#define RTNL_HANDLE_F_LISTEN_ALL_NSID 0x01 +#define RTNL_HANDLE_F_SUPPRESS_NLERR 0x02 +#define RTNL_HANDLE_F_STRICT_CHK 0x04 + int flags; +}; + +struct nlmsg_list { + struct nlmsg_list *next; + struct nlmsghdr h; +}; + +struct nlmsg_chain { + struct nlmsg_list *head; + struct nlmsg_list *tail; +}; + +extern int rcvbuf; + +int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) + __attribute__((warn_unused_result)); + +int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions, + int protocol) + __attribute__((warn_unused_result)); + +void rtnl_close(struct rtnl_handle *rth); +void rtnl_set_strict_dump(struct rtnl_handle *rth); + +typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen); + +int rtnl_addrdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); +int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); +int rtnl_routedump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); +int rtnl_ruledump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); +int rtnl_neighdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); +int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); +int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); +int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); +int rtnl_nsiddump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); + +int rtnl_linkdump_req(struct rtnl_handle *rth, int fam) + __attribute__((warn_unused_result)); +int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) + __attribute__((warn_unused_result)); + +int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam, + req_filter_fn_t fn) + __attribute__((warn_unused_result)); +int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); +int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) + __attribute__((warn_unused_result)); +int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, + int len) + __attribute__((warn_unused_result)); +int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n) + __attribute__((warn_unused_result)); + +struct rtnl_ctrl_data { + int nsid; +}; + +typedef int (*rtnl_filter_t)(struct nlmsghdr *n, void *); + +typedef int (*rtnl_listen_filter_t)(struct rtnl_ctrl_data *, + struct nlmsghdr *n, void *); + +typedef int (*nl_ext_ack_fn_t)(const char *errmsg, uint32_t off, + const struct nlmsghdr *inner_nlh); + +struct rtnl_dump_filter_arg { + rtnl_filter_t filter; + void *arg1; + __u16 nc_flags; +}; + +int rtnl_dump_filter_nc(struct rtnl_handle *rth, + rtnl_filter_t filter, + void *arg, __u16 nc_flags); +#define rtnl_dump_filter(rth, filter, arg) \ + rtnl_dump_filter_nc(rth, filter, arg, 0) +int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, + struct nlmsghdr **answer) + __attribute__((warn_unused_result)); +int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen, + struct nlmsghdr **answer) + __attribute__((warn_unused_result)); +int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n, + struct nlmsghdr **answer) + __attribute__((warn_unused_result)); +int rtnl_send(struct rtnl_handle *rth, const void *buf, int) + __attribute__((warn_unused_result)); +int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int) + __attribute__((warn_unused_result)); +int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn); + +int addattr(struct nlmsghdr *n, int maxlen, int type); +int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data); +int addattr16(struct nlmsghdr *n, int maxlen, int type, __u16 data); +int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data); +int addattr64(struct nlmsghdr *n, int maxlen, int type, __u64 data); +int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *data); + +int addattr_l(struct nlmsghdr *n, int maxlen, int type, + const void *data, int alen); +int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len); +struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type); +int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); +struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, + const void *data, int len); +int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest); +int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data); +int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data); +int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); +int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data); +int rta_addattr_l(struct rtattr *rta, int maxlen, int type, + const void *data, int alen); + +int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); +int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, + int len, unsigned short flags); +struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); +int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len); + +struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type); +int rta_nest_end(struct rtattr *rta, struct rtattr *nest); + +#define RTA_TAIL(rta) \ + ((struct rtattr *) (((void *) (rta)) + \ + RTA_ALIGN((rta)->rta_len))) + +#define parse_rtattr_nested(tb, max, rta) \ + (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) + +#define parse_rtattr_one_nested(type, rta) \ + (parse_rtattr_one(type, RTA_DATA(rta), RTA_PAYLOAD(rta))) + +#define parse_rtattr_nested_compat(tb, max, rta, data, len) \ + ({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \ + __parse_rtattr_nested_compat(tb, max, rta, len); }) + +static inline __u8 rta_getattr_u8(const struct rtattr *rta) +{ + return *(__u8 *)RTA_DATA(rta); +} +static inline __u16 rta_getattr_u16(const struct rtattr *rta) +{ + return *(__u16 *)RTA_DATA(rta); +} +static inline __be16 rta_getattr_be16(const struct rtattr *rta) +{ + return ntohs(rta_getattr_u16(rta)); +} +static inline __u32 rta_getattr_u32(const struct rtattr *rta) +{ + return *(__u32 *)RTA_DATA(rta); +} +static inline __be32 rta_getattr_be32(const struct rtattr *rta) +{ + return ntohl(rta_getattr_u32(rta)); +} +static inline __u64 rta_getattr_u64(const struct rtattr *rta) +{ + __u64 tmp; + + memcpy(&tmp, RTA_DATA(rta), sizeof(__u64)); + return tmp; +} +static inline __s32 rta_getattr_s32(const struct rtattr *rta) +{ + return *(__s32 *)RTA_DATA(rta); +} +static inline __s64 rta_getattr_s64(const struct rtattr *rta) +{ + __s64 tmp; + + memcpy(&tmp, RTA_DATA(rta), sizeof(tmp)); + return tmp; +} +static inline const char *rta_getattr_str(const struct rtattr *rta) +{ + return (const char *)RTA_DATA(rta); +} + +int rtnl_listen_all_nsid(struct rtnl_handle *); +int rtnl_listen(struct rtnl_handle *, rtnl_listen_filter_t handler, + void *jarg); +int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, + void *jarg); + +#define NLMSG_TAIL(nmsg) \ + ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) + +#ifndef IFA_RTA +#define IFA_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg)))) +#endif +#ifndef IFA_PAYLOAD +#define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg)) +#endif + +#ifndef IFLA_RTA +#define IFLA_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg)))) +#endif +#ifndef IFLA_PAYLOAD +#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg)) +#endif + +#ifndef NDA_RTA +#define NDA_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg)))) +#endif +#ifndef NDA_PAYLOAD +#define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ndmsg)) +#endif + +#ifndef NDTA_RTA +#define NDTA_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg)))) +#endif +#ifndef NDTA_PAYLOAD +#define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ndtmsg)) +#endif + +#ifndef NETNS_RTA +#define NETNS_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtgenmsg)))) +#endif +#ifndef NETNS_PAYLOAD +#define NETNS_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct rtgenmsg)) +#endif + +#ifndef IFLA_STATS_RTA +#define IFLA_STATS_RTA(r) \ + ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct if_stats_msg)))) +#endif + +/* User defined nlmsg_type which is used mostly for logging netlink + * messages from dump file */ +#define NLMSG_TSTAMP 15 + +#endif /* __LIBNETLINK_H__ */ + From 578e113ad48e3de5dd6ebad7cee3641bd923537b Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 19:40:56 +0800 Subject: [PATCH 13/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2j.h | 4 +- Common/s2j/s2jdef.h | 2 +- .../configm/config-server/include/brconfig.h | 2 +- .../configm/config-server/include/configm.h | 2 +- .../config-server/netconfig/bridge/brconfig.c | 37 +++++++++---------- .../netconfig/bridge/include/libnetlink.h | 6 +-- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Common/s2j/s2j.h b/Common/s2j/s2j.h index 19912706b..6d7816415 100644 --- a/Common/s2j/s2j.h +++ b/Common/s2j/s2j.h @@ -84,8 +84,8 @@ extern "C" { S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element) /* Get array type element for structure object */ -#define s2j_struct_get_array_string_n(to_struct, from_json, type, element, NUM, BUFFLEN) \ - S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, element, NUM, BUFFLEN) +#define s2j_struct_get_array_string_n(to_struct, from_json, element, NUM, BUFFLEN) \ + S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, element, NUM, BUFFLEN) /* Get child structure type element for structure object */ diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index cd27ac78e..e4224288b 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -163,7 +163,7 @@ typedef struct { } \ } -#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM, LEN) \ +#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, _element, NUM, LEN) \ { \ cJSON *array, *array_element; \ size_t index = 0, size = 0; \ diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index c5db06298..658251186 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -51,7 +51,7 @@ typedef struct _br_event_head br_event_head_t; /* 临时数据结构 */ struct _brif_temp { int index; - char *if_list; + char **ports; }; typedef struct _brif_temp br_if_temp_t; diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 1a93e807e..cadbd1be6 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -157,7 +157,7 @@ log_console_config_proc, \ NULL, \ NULL \ - }\ + }\ } typedef ret_code (*cm_config_init)(); diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index e77e66931..59cde4ea9 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -93,13 +93,11 @@ int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) int br_copy_port_name(const char *b, const char *p, void *arg) { br_if_temp_t *br_if = (br_if_temp_t *)arg; - char *dst_ptr = NULL; - br_if->if_list = realloc(br_if->if_list, INTERFACE_NAMSIZ); - ASSERT_PTR_RET(br_if->if_list); + br_if->ports[br_if->index] = rpc_new0(char, INTERFACE_NAMSIZ); + ASSERT_PTR_RET(br_if->ports[br_if->index]); - dst_ptr = br_if->if_list + br_if->index * INTERFACE_NAMSIZ; - strncpy(dst_ptr, p, INTERFACE_NAMSIZ - 1); + strncpy(br_if->ports[br_if->index], p, INTERFACE_NAMSIZ - 1); br_if->index++; return 0; @@ -409,7 +407,7 @@ int br_json_to_string( cJSON *json_obj, pointer output) return output_len; } -cJSON *br_config_format_json(br_config_t *br_config) +cJSON *br_config_format_json(const char *br_name, br_if_temp_t *br_if) { s2j_create_json_obj(json_obj); if(json_obj == NULL) @@ -418,8 +416,7 @@ cJSON *br_config_format_json(br_config_t *br_config) } s2j_json_set_basic_element(json_obj, br_config, string, br_name); - s2j_json_set_array_element(json_obj, br_config, string, - ports, br_config->port_num); + s2j_json_set_array_element(json_obj, br_config, string, ports, br_if->index); return json_obj; } @@ -428,29 +425,30 @@ ret_code br_bridge_info(const char *br_name, cJSON *json_obj, int *err) { ret_code ret = RET_OK; br_if_temp_t br_if = {0}; - br_config_t br_config = {0}; + int i = 0; br_if.index = 0; - br_if.if_list = NULL; + br_if.ports = NULL; *err = br_foreach_port(br_name, br_copy_port_name, &br_if); if (*err >= 0) { - strncpy(br_config.br_name, br_name, BR_NAMSIZ - 1); - br_config.ports = br_if.if_list; - br_config.port_num = br_if.index; - json_obj = br_config_format_json(&br_config); + json_obj = br_config_format_json(&br_if); } else { ret = RET_SYSERR; } - - if(br_if.if_list) + + for(i = 0; i < br_if.index; i++) { - rpc_free(br_if.if_list); + if(br_if.ports[i]) + { + rpc_free(br_if.ports[i]); + } } + return ret; } @@ -501,8 +499,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br if(br_if_conf->config_type == CM_CONFIG_ADD || br_if_conf->config_type == CM_CONFIG_DEL) { - s2j_struct_get_array_string_n(br_if_conf, json_obj, string, - ports, port_num, INTERFACE_NAMSIZ); + s2j_struct_get_array_string_n(br_if_conf, json_obj, ports, port_num, INTERFACE_NAMSIZ); br_if->port_num = port_num; br_if->ports = br_if_conf->ports; /*指针赋值,后续需要对该指针进行内存释放*/ br_if_conf->ports = NULL; @@ -880,7 +877,7 @@ ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_ return RET_NOMEM; } - s2j_struct_get_string_element(br_fdb_conf, json_obj, string, br_name, BR_NAMSIZ); + s2j_struct_get_string_element(br_fdb_conf, json_obj, br_name, BR_NAMSIZ); *conf_type = br_fdb_conf->config_type; strncpy(br_fdb->br_name, br_fdb_conf->br_name, BR_NAMSIZ - 1); diff --git a/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h b/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h index cdd064663..7cc4b9add 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libnetlink.h @@ -115,9 +115,9 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth, void *arg, __u16 nc_flags); #define rtnl_dump_filter(rth, filter, arg) \ rtnl_dump_filter_nc(rth, filter, arg, 0) -int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, +/*int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, struct nlmsghdr **answer) - __attribute__((warn_unused_result)); + __attribute__((warn_unused_result));*/ int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen, struct nlmsghdr **answer) __attribute__((warn_unused_result)); @@ -152,7 +152,7 @@ int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data); int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen); -int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); +/*int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);*/ int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, int len, unsigned short flags); struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); From c7221db5cefe8593e2d42574d57922c51cf7d020 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 10:11:14 +0800 Subject: [PATCH 14/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2jdef.h | 2 +- Platform/common/rpc/rpc_util.h | 6 ++--- .../configm/config-server/include/brconfig.h | 1 + .../config-server/netconfig/bridge/brconfig.c | 22 +++++++++---------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index e4224288b..80efc5588 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -175,7 +175,7 @@ typedef struct { memset((to_struct)->_element, 0, size * LEN);\ while (index < size) { \ array_element = cJSON_GetArrayItem(array, index); \ - if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, type, _element, index++, LEN); \ + if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, _element, index++, LEN); \ } \ } \ } diff --git a/Platform/common/rpc/rpc_util.h b/Platform/common/rpc/rpc_util.h index 51ec9b874..faac2446b 100755 --- a/Platform/common/rpc/rpc_util.h +++ b/Platform/common/rpc/rpc_util.h @@ -75,12 +75,12 @@ do { \ }\ } while (0) -#define ASSERT_PTR_RET(ptr) \ +#define ASSERT_PTR(ptr, RET_REASON) \ do { \ if (ptr == NULL) \ {\ - rpc_log_error("ret error: %s\n", rpc_code_format(RET_NULLP));\ - return RET_NULLP;\ + rpc_log_error("Assert PTR NULL\n");\ + return RET_REASON;\ }\ } while (0) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 658251186..40986b6c7 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -50,6 +50,7 @@ typedef struct _br_event_head br_event_head_t; /* 临时数据结构 */ struct _brif_temp { + char br_name[BR_NAMSIZ]; int index; char **ports; }; diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 59cde4ea9..873035b7e 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -95,7 +95,7 @@ int br_copy_port_name(const char *b, const char *p, void *arg) br_if_temp_t *br_if = (br_if_temp_t *)arg; br_if->ports[br_if->index] = rpc_new0(char, INTERFACE_NAMSIZ); - ASSERT_PTR_RET(br_if->ports[br_if->index]); + ASSERT_PTR(br_if->ports[br_if->index], RET_NULLP); strncpy(br_if->ports[br_if->index], p, INTERFACE_NAMSIZ - 1); @@ -355,7 +355,7 @@ ret_code br_config_json_parse(pointer input, uint *conf_type, char *br_name) cJSON *json_obj; json_obj = cJSON_Parse(input); - ASSERT_PTR_RET(json_obj); + ASSERT_PTR(json_obj, RET_NULLP); rpc_log_info("json input:\n %s\n", cJSON_Print(json_obj)); @@ -407,16 +407,13 @@ int br_json_to_string( cJSON *json_obj, pointer output) return output_len; } -cJSON *br_config_format_json(const char *br_name, br_if_temp_t *br_if) +cJSON *br_config_format_json(br_if_temp_t *br_if) { s2j_create_json_obj(json_obj); - if(json_obj == NULL) - { - return NULL; - } + ASSERT_PTR(json_obj, NULL); - s2j_json_set_basic_element(json_obj, br_config, string, br_name); - s2j_json_set_array_element(json_obj, br_config, string, ports, br_if->index); + s2j_json_set_basic_element(json_obj, br_if, string, br_name); + s2j_json_set_array_element(json_obj, br_if, string, ports, br_if->index); return json_obj; } @@ -426,11 +423,12 @@ ret_code br_bridge_info(const char *br_name, cJSON *json_obj, int *err) ret_code ret = RET_OK; br_if_temp_t br_if = {0}; int i = 0; - + + strncpy(br_if.br_name, br_name, BR_NAMSIZ); br_if.index = 0; br_if.ports = NULL; - *err = br_foreach_port(br_name, br_copy_port_name, &br_if); + *err = br_foreach_port(br_if.br_name, br_copy_port_name, &br_if); if (*err >= 0) { json_obj = br_config_format_json(&br_if); @@ -475,7 +473,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br int port_num = 0; json_obj = cJSON_Parse(input); - ASSERT_PTR_RET(json_obj); + ASSERT_PTR(json_obj, RET_NULLP); rpc_log_info("json input:\n %s\n", cJSON_Print(json_obj)); From 6957eb74f87ecf5dc6860d3b9e137f15b00f2f1f Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 10:26:49 +0800 Subject: [PATCH 15/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/build/user.configm.Makefile | 6 ++- .../configm/config-server/include/configm.h | 48 +++++++++++++------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index da676a649..599051336 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -28,7 +28,9 @@ VPATH = ../user/configm/config-server COMMON_SRCS = configserver.c \ netconfig/ipconfig/ipconfig.c netconfig/parsefile.c \ - authfree_config/authfree.c \ + netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \ + netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\ + authfree_config/authfree.c \ localportal_config/localportal.c \ userlock_config/userlock.c \ jumppage_config/jumppage.c \ @@ -41,7 +43,7 @@ COMMON_SRCS = configserver.c \ PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_ARM64_SRCS = $(COMMON_SRCS) -COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog +COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/bridge/include # gcc CFLAGS PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index cadbd1be6..8d665a9f4 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -13,6 +13,7 @@ #include "jumppage.h" #include "userlock.h" #include "agingtime.h" +#include "brconfig.h" /* 类型定义 */ @@ -30,7 +31,11 @@ /* config id define*/ -#define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1) +#define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1) +#define BR_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|2) +#define BRIF_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|3) +#define BRFDB_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|4) + #define USER_MANAGER_CONFIG_GROUP (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|1) #define USER_MANAGER_CONFIG_USER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|2) @@ -45,10 +50,6 @@ #define CONFIG_INIT_ARRAY \ {\ - {\ - NETCONFIG_MODULE,\ - NULL\ - },\ { \ LOG_CONFIG_MODULE, \ log_config_init \ @@ -72,17 +73,42 @@ IPCONFIG_V4, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ ip_config_chk, \ ip_config_proc, \ ip_config_get, \ ip_config_get_all \ },\ + {\ + BR_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_config_chk, \ + br_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + BRIF_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_if_config_chk, \ + br_if_config_proc, \ + br_if_config_get, \ + br_if_config_get_all \ + },\ + {\ + BRFDB_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + br_fdb_config_chk, \ + NULL, \ + br_fdb_config_get, \ + NULL \ + },\ {\ USER_MANAGER_CONFIG_GROUP, \ CONFIG_FROM_WEB, \ FALSE, \ - FALSE, \ usergroup_config_chk, \ usergroup_config_proc, \ usergroup_config_get, \ @@ -92,7 +118,6 @@ PORTALSERVER_CONFIG, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ portalserver_config_chk, \ portalserver_config_proc, \ NULL, \ @@ -102,7 +127,6 @@ AUTHFREE_CONFIG, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ freeauth_config_chk, \ freeauth_config_proc, \ NULL, \ @@ -112,7 +136,6 @@ USERLOCK_CONFIG, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ userlock_config_chk, \ userlock_config_proc, \ NULL, \ @@ -122,7 +145,6 @@ JUMPPAGE_CONFIG, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ NULL, \ jumppage_config_proc, \ NULL, \ @@ -132,7 +154,6 @@ AGINGTIME_CONFIG, \ CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ FALSE, \ - FALSE, \ agingtime_config_chk, \ agingtime_config_proc, \ agingtime_config_get, \ @@ -142,7 +163,6 @@ USER_MANAGER_CONFIG_USER, \ CONFIG_FROM_WEB, \ FALSE, \ - FALSE, \ user_config_chk, \ user_config_proc, \ user_config_get, \ @@ -152,7 +172,6 @@ LOG_CONFIG_CONSOLE, \ CONFIG_FROM_WEB, \ FALSE, \ - FALSE, \ log_console_config_chk, \ log_console_config_proc, \ NULL, \ @@ -190,7 +209,6 @@ struct _config_service { uint64 config_id; /* 配置ID,全局唯一,用于寻找对应的配置业务*/ uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位,第一位表示web,后续配置扩展 */ boolean recovery; /* 配置恢复处理函数,如果为FALSE则不进行配置恢复 */ - boolean multi_inst; /* 是否是多实例 */ cm_config_chk chk_callback; /* 配置校验回调函数 */ cm_config_proc proc_callback; /* 配置接口 */ cm_config_get get_callback; /* 获取配置接口 */ From b89e1f0bfca8a6d9d77e975b261f69314d7b8d92 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 10:31:09 +0800 Subject: [PATCH 16/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20?= =?UTF-8?q?=E6=A1=A5=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BA=BA=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/user/configm/config-server/include/brconfig.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 40986b6c7..5aac863ed 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -1,6 +1,8 @@ #ifndef BRCONFIG_H_ #define BRCONFIG_H_ +#include "list.h" + #define BR_NAMSIZ INTERFACE_NAMSIZ #define MAC_STRSIZ 32 #define LOCAL_STRSIZ 16 From 3c7b5df4bd40ac2342c9d4b39e69ed32c3a64246 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 10:41:01 +0800 Subject: [PATCH 17/19] =?UTF-8?q?MOD=20aaa-12=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A1=A5=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=20SOL=20=20=E5=A2=9E=E5=8A=A0=E6=A1=A5=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=9C=BA=E5=88=B6=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configm/config-server/include/brconfig.h | 6 +++++ .../config-server/netconfig/bridge/brconfig.c | 23 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 5aac863ed..bedf0c707 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -131,6 +131,12 @@ ret_code br_if_bridge_del(char *br_name, char *port_list, /* 获取桥中接口数量 */ int br_if_bridge_num(char *br_name); +ret_code br_event_register(BR_EVENT_TYPE event_type, + BR_EVENT_FUNC event_func); + +ret_code br_event_unregister(BR_EVENT_TYPE event_type, + BR_EVENT_FUNC event_func); + /* **********************************************************/ /* 配置管理注册函数 */ /************************************************************/ diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 873035b7e..72b2e569c 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -28,13 +28,14 @@ int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg) if(hnode->br_event == event_type) { hnode->event_func(event_type, event_arg); + rpc_log_info("br event:%d\n", event_type); } } pthread_mutex_unlock(&(br_event_tbl.lock)); } -int br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) +ret_code br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) { br_event_node_t *hnode = NULL; @@ -45,34 +46,34 @@ int br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) br_event_tbl.init = TRUE; } + rpc_log_info("br event register:%d\n", event_type); + hnode = (br_event_node_t *)rpc_new0(br_event_node_t, 1); - if(!hnode) - { - rpc_log_error("br_event_register failed\n"); - return -1; - } + ASSERT_PTR(hnode, RET_NOMEM); INIT_HLIST_NODE(&hnode->list); hnode->br_event = event_type; hnode->event_func = event_func; - pthread_mutex_lock(&(br_event_tbl.lock)); + pthread_mutex_lock(&(br_event_tbl.lock)); hlist_add_head(&hnode->list, &(br_event_tbl.head)); pthread_mutex_unlock(&(br_event_tbl.lock)); - return 0; + return RET_OK; } -int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) +ret_code br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) { br_event_node_t *hnode = NULL; struct hlist_node *n; if(br_event_tbl.init == FALSE) { - return 0; + return RET_OK; } + rpc_log_info("br event unregister:%d\n", event_type); + pthread_mutex_lock(&(br_event_tbl.lock)); hlist_for_each_entry_safe(hnode, n, &(br_event_tbl.head), list) { @@ -86,7 +87,7 @@ int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) } pthread_mutex_unlock(&(br_event_tbl.lock)); - return 0; + return RET_OK; } /* 桥配置辅助函数 */ From a6360d2201dff86452378429ab017b6b91f4b9fd Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 11:00:05 +0800 Subject: [PATCH 18/19] =?UTF-8?q?MOD=20aaa-12=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=A1=A5=E7=9A=84=E5=88=9B=E5=BB=BA=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=20SOL=20=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=A1=A5=E7=9A=84=E5=88=9B=E5=BB=BA=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E6=94=B9=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhangliang=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Azhang?= =?UTF-8?q?liang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Platform/user/configm/config-server/include/brconfig.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index bedf0c707..292b79aa2 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -117,6 +117,12 @@ typedef struct _br_fdb_status br_fdb_status_t; /* 提供给其他模块调用的函数 */ /************************************************************/ +/* 添加桥,sys_err 表示内核返回的系统错误码*/ +ret_code br_bridge_add(char *br_name, int *sys_err); + +/* 删除桥,sys_err 表示内核返回的系统错误码 */ +ret_code br_bridge_del(char * br_name, int *sys_err); + /* 通过接口名获取所在桥名 */ ret_code br_if_bridge_get(char *port_name , char *br_name); @@ -131,9 +137,11 @@ ret_code br_if_bridge_del(char *br_name, char *port_list, /* 获取桥中接口数量 */ int br_if_bridge_num(char *br_name); +/* 注册桥事件通知函数 */ ret_code br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func); +/* 去注册桥事件通知函数 */ ret_code br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func); From b201b3d7d69dc5d9ce61c46d5e68a62a3ace0035 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Mon, 5 Aug 2019 18:04:00 +0800 Subject: [PATCH 19/19] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=87=AA=E6=B5=8B=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=20SOL=20=20=E6=A1=A5=E6=8E=A5=E5=8F=A3=E8=87=AA=E6=B5=8B?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2jdef.h | 7 +- .../configm/config-server/include/brconfig.h | 14 +- .../configm/config-server/include/configm.h | 4 + .../config-server/netconfig/bridge/brconfig.c | 179 ++++++++++++------ .../netconfig/bridge/include/libbridge.h | 1 + .../bridge/libbridge/libbridge_init.c | 5 + 6 files changed, 141 insertions(+), 69 deletions(-) diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index 80efc5588..82be52cc2 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -67,7 +67,7 @@ typedef struct { strcpy((to_struct)->_element[index], from_json->valuestring); #define S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, from_json, _element, index, maxlen) \ - strncpy((to_struct)->_element + maxlen * index, from_json->valuestring, maxlen - 1); + strncpy((to_struct)->_element[index], from_json->valuestring, maxlen - 1); #define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \ (to_struct)->_element[index] = from_json->valuedouble; @@ -171,10 +171,11 @@ typedef struct { if (array) { \ size = cJSON_GetArraySize(array); \ NUM = size;\ - (to_struct)->_element = (char *)malloc(size * LEN);\ - memset((to_struct)->_element, 0, size * LEN);\ + (to_struct)->_element = (char **)malloc(size * sizeof(char *));\ + memset((to_struct)->_element, 0, size * sizeof(char *));\ while (index < size) { \ array_element = cJSON_GetArrayItem(array, index); \ + (to_struct)->_element[index] = (char *)calloc(1, LEN);\ if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, _element, index++, LEN); \ } \ } \ diff --git a/Platform/user/configm/config-server/include/brconfig.h b/Platform/user/configm/config-server/include/brconfig.h index 292b79aa2..b8a2c45cb 100644 --- a/Platform/user/configm/config-server/include/brconfig.h +++ b/Platform/user/configm/config-server/include/brconfig.h @@ -51,13 +51,6 @@ typedef struct _br_event_head br_event_head_t; /* 临时数据结构 */ -struct _brif_temp { - char br_name[BR_NAMSIZ]; - int index; - char **ports; -}; -typedef struct _brif_temp br_if_temp_t; - struct _br_temp { char *br_name; boolean result; @@ -68,7 +61,7 @@ typedef struct _br_temp br_temp_t; struct _br_config { char br_name[BR_NAMSIZ]; int port_num; - char *ports; + char **ports; }; typedef struct _br_config br_config_t; @@ -87,7 +80,7 @@ typedef struct _br_config_string br_config_string_t; struct _br_if_config_string { int config_type; char br_name[BR_NAMSIZ]; - char *ports; + char **ports; }; typedef struct _br_if_config_string br_if_config_string_t; @@ -181,4 +174,7 @@ ret_code br_fdb_config_get(uint source, pointer input, int input_len, pointer output, int *output_len); +/* 模块初始化 */ +ret_code br_bridge_init(); + #endif diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 8d665a9f4..45f66c879 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -50,6 +50,10 @@ #define CONFIG_INIT_ARRAY \ {\ + { \ + NETCONFIG_MODULE, \ + br_bridge_init \ + }, \ { \ LOG_CONFIG_MODULE, \ log_config_init \ diff --git a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c index 72b2e569c..741d24112 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/brconfig.c +++ b/Platform/user/configm/config-server/netconfig/bridge/brconfig.c @@ -93,14 +93,14 @@ ret_code br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func) /* 桥配置辅助函数 */ int br_copy_port_name(const char *b, const char *p, void *arg) { - br_if_temp_t *br_if = (br_if_temp_t *)arg; + br_config_t *br_if = (br_config_t *)arg; - br_if->ports[br_if->index] = rpc_new0(char, INTERFACE_NAMSIZ); - ASSERT_PTR(br_if->ports[br_if->index], RET_NULLP); + br_if->ports[br_if->port_num] = rpc_new0(char, INTERFACE_NAMSIZ); + ASSERT_PTR(br_if->ports[br_if->port_num], RET_NULLP); - strncpy(br_if->ports[br_if->index], p, INTERFACE_NAMSIZ - 1); + strncpy(br_if->ports[br_if->port_num], p, INTERFACE_NAMSIZ - 1); - br_if->index++; + br_if->port_num++; return 0; } @@ -156,14 +156,14 @@ ret_code br_if_bridge_get(char *port_name, char* br_name) return RET_NOTFOUND; } -ret_code br_if_bridge_check(char *port_list, int cnt, uint config_type) +ret_code br_if_bridge_check(char **port_list, int cnt, uint config_type) { char *ptr_name = NULL; int i; for(i = 0; i< cnt; i++) { - ptr_name = port_list + INTERFACE_NAMSIZ * i; + ptr_name = port_list [i]; if (if_nametoindex(ptr_name) == 0) { return RET_NOTFOUND; @@ -408,46 +408,74 @@ int br_json_to_string( cJSON *json_obj, pointer output) return output_len; } -cJSON *br_config_format_json(br_if_temp_t *br_if) +cJSON *br_config_format_json(br_config_t *br_if) { s2j_create_json_obj(json_obj); ASSERT_PTR(json_obj, NULL); s2j_json_set_basic_element(json_obj, br_if, string, br_name); - s2j_json_set_array_element(json_obj, br_if, string, ports, br_if->index); + if(br_if->port_num) + { + s2j_json_set_array_element(json_obj, br_if, string, ports, br_if->port_num); + } + + if (DEBUG_INFO) + { + char *json_str; + + json_str = cJSON_PrintUnformatted(json_obj); + + rpc_log_info("bridge info: %s", json_str); + rpc_free(json_str); + } return json_obj; } -ret_code br_bridge_info(const char *br_name, cJSON *json_obj, int *err) +ret_code br_bridge_info(const char *br_name, cJSON **json_obj, int *err) { ret_code ret = RET_OK; - br_if_temp_t br_if = {0}; + br_config_t br_if = {0}; + int port_num = 0; int i = 0; - strncpy(br_if.br_name, br_name, BR_NAMSIZ); - br_if.index = 0; - br_if.ports = NULL; + rpc_log_info("get bridge %s info ",br_name); + port_num = br_if_bridge_num((char *)br_name); - *err = br_foreach_port(br_if.br_name, br_copy_port_name, &br_if); - if (*err >= 0) - { - json_obj = br_config_format_json(&br_if); - } - else - { - ret = RET_SYSERR; - } + strncpy(br_if.br_name, br_name, BR_NAMSIZ); + br_if.port_num = 0; + br_if.ports = NULL; - for(i = 0; i < br_if.index; i++) + if(port_num > 0) + { + br_if.ports = rpc_new0(char *, port_num); + + *err = br_foreach_port(br_if.br_name, br_copy_port_name, &br_if); + if (*err < 0) + { + ret = RET_SYSERR; + } + } + + rpc_log_info("ret %d\n",ret); + + *json_obj = br_config_format_json(&br_if); + + rpc_log_info("bridge %s has %d ports\n",br_name, br_if.port_num); + + for(i = 0; i < br_if.port_num; i++) { if(br_if.ports[i]) { rpc_free(br_if.ports[i]); } } - - + + if(br_if.ports) + { + rpc_free(br_if.ports); + } + return ret; } @@ -458,7 +486,7 @@ int br_bridge_info_each(const char *br_name, void *args) ret_code ret = RET_OK; int err = 0; - ret = br_bridge_info(br_name, json_obj, &err); + ret = br_bridge_info(br_name, &json_obj, &err); if(json_obj) { @@ -587,12 +615,12 @@ ret_code br_if_config_chk(uint source,uint *config_type, { ret_code ret = RET_OK; br_config_t br_config = {0}; - br_config_t *temp_conf = NULL; int cfg_len = 0; - + int i = 0; + br_if_config_json_parse(input, config_type, &br_config); - cfg_len = BR_NAMSIZ + sizeof(br_config.port_num) + cfg_len = sizeof(br_config) + br_config.port_num * INTERFACE_NAMSIZ; if(cfg_len > CM_BUFF_SIZE) @@ -600,20 +628,23 @@ ret_code br_if_config_chk(uint source,uint *config_type, ret = RET_NOMEM; goto exit; } - - ret = br_name_chk(br_config.br_name); - if(ret != RET_OK) + + if(*config_type != CM_CONFIG_GET_ALL) { - goto exit; + ret = br_name_chk(br_config.br_name); + if(ret != RET_OK) + { + goto exit; + } + + if(br_is_exist(br_config.br_name) == FALSE) + { + ret = RET_NOTFOUND; + goto exit; + } } - if(br_is_exist(br_config.br_name) == FALSE) - { - ret = RET_NOTFOUND; - goto exit; - } - - if(*config_type != CM_CONFIG_ADD && *config_type != CM_CONFIG_DEL) + if(*config_type < CM_CONFIG_ADD && *config_type > CM_CONFIG_GET_ALL) { ret = RET_INPUTERR; goto exit; @@ -626,17 +657,33 @@ ret_code br_if_config_chk(uint source,uint *config_type, } memset(input, 0, *input_len); - temp_conf = (br_config_t *)input; - strncpy(temp_conf->br_name, br_config.br_name, BR_NAMSIZ - 1); - temp_conf->port_num = br_config.port_num; - memcpy(temp_conf->ports, br_config.ports, br_config.port_num * INTERFACE_NAMSIZ); + strncpy(input, br_config.br_name, BR_NAMSIZ - 1); + input += BR_NAMSIZ; + *(int *)input = br_config.port_num; + input += sizeof(int); + + for(i = 0; i < br_config.port_num; i++) + { + if(br_config.ports[i]) + { + strncpy(input, br_config.ports[i], INTERFACE_NAMSIZ); + rpc_free(br_config.ports[i]); + + input += INTERFACE_NAMSIZ; + } + } *input_len = cfg_len; exit: RET_ERR_FORMART(ret, 0, output, *output_len); - rpc_free(br_config.ports); + + if(br_config.ports) + { + rpc_free(br_config.ports); + } + return ret; } @@ -644,19 +691,27 @@ ret_code br_if_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len) { - br_config_t *br_conf = (br_config_t *)input; + char *br_name = NULL; + char *port_list = NULL; + int *port_num = NULL; ret_code ret = RET_OK; int err = 0; + + br_name = input; + input += BR_NAMSIZ; + + port_num = (int *)input; + input += sizeof(int); + + port_list = input; if(config_type == CM_CONFIG_ADD) { - ret = br_if_bridge_add(br_conf->br_name, br_conf->ports, - br_conf->port_num, &err); + ret = br_if_bridge_add(br_name, port_list, *port_num, &err); } else if(config_type == CM_CONFIG_DEL) { - ret = br_if_bridge_del(br_conf->br_name, br_conf->ports, - br_conf->port_num, &err); + ret = br_if_bridge_del(br_name, port_list, *port_num, &err); } RET_ERR_FORMART(ret, err, output, *output_len); @@ -671,9 +726,9 @@ ret_code br_if_config_get(uint source, cJSON *json_obj = NULL; int err = 0; - ret = br_bridge_info((char *)input, json_obj, &err); + ret = br_bridge_info((char *)input, &json_obj, &err); - if(ret != RET_OK) + if(ret != RET_OK || json_obj == NULL) { RET_ERR_FORMART(ret, err, output, *output_len); } @@ -741,7 +796,7 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname) - if ((br_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) + if ((br_fd = br_ioctl_sock()) < 0) { return -1; } @@ -749,17 +804,14 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname) if (ioctl(br_fd, SIOCDEVPRIVATE, &ifr) < 0) { dprintf("get_portno: get ports of %s failed: %s\n", brname, strerror(errno)); - close(br_fd); return -1; } if(if_indextoname(ifindices[port_no], ifname) == NULL) { - close(br_fd); return -1; } - close(br_fd); return 0; } @@ -1002,3 +1054,16 @@ ret_code br_fdb_config_get(uint source, return ret; } +ret_code br_bridge_init() +{ + int err; + + err = br_init(); + if (err < 0) + { + rpc_log_error("bridge init fail:%s\n",strerror(err)); + } +} + + + diff --git a/Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h index 6ae82151a..dda441603 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h +++ b/Platform/user/configm/config-server/netconfig/bridge/include/libbridge.h @@ -86,6 +86,7 @@ struct port_info }; extern int br_init(void); +extern int br_ioctl_sock(); extern int br_refresh(void); extern void br_shutdown(void); diff --git a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c b/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c index 66a6f47da..a1cf5d777 100644 --- a/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c +++ b/Platform/user/configm/config-server/netconfig/bridge/libbridge/libbridge_init.c @@ -37,6 +37,11 @@ int br_init(void) return 0; } +int br_ioctl_sock() +{ + return br_socket_fd; +} + void br_shutdown(void) { close(br_socket_fd);