From 578e113ad48e3de5dd6ebad7cee3641bd923537b Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Fri, 2 Aug 2019 19:40:56 +0800 Subject: [PATCH] =?UTF-8?q?MOD=20aaa-12=20=E6=A1=A5=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20SOL=20=20=E6=A1=A5?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=BB=A3=E7=A0=81=E4=B8=8A=E4=BC=A0=20?= =?UTF-8?q?=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);