MOD aaa-12 桥模型代码上传

SOL  桥模型代码上传
修改人:zhangliang
检视人:zhangliang
This commit is contained in:
zhanglianghy 2019-08-02 19:40:56 +08:00
parent 95dc8feac9
commit 578e113ad4
6 changed files with 25 additions and 28 deletions

View File

@ -84,8 +84,8 @@ extern "C" {
S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element) S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element)
/* Get array type element for structure object */ /* Get array type element for structure object */
#define s2j_struct_get_array_string_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, type, 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 */ /* Get child structure type element for structure object */

View File

@ -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; \ cJSON *array, *array_element; \
size_t index = 0, size = 0; \ size_t index = 0, size = 0; \

View File

@ -51,7 +51,7 @@ typedef struct _br_event_head br_event_head_t;
/* 临时数据结构 */ /* 临时数据结构 */
struct _brif_temp { struct _brif_temp {
int index; int index;
char *if_list; char **ports;
}; };
typedef struct _brif_temp br_if_temp_t; typedef struct _brif_temp br_if_temp_t;

View File

@ -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) 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_temp_t *br_if = (br_if_temp_t *)arg;
char *dst_ptr = NULL;
br_if->if_list = realloc(br_if->if_list, INTERFACE_NAMSIZ); br_if->ports[br_if->index] = rpc_new0(char, INTERFACE_NAMSIZ);
ASSERT_PTR_RET(br_if->if_list); ASSERT_PTR_RET(br_if->ports[br_if->index]);
dst_ptr = br_if->if_list + br_if->index * INTERFACE_NAMSIZ; strncpy(br_if->ports[br_if->index], p, INTERFACE_NAMSIZ - 1);
strncpy(dst_ptr, p, INTERFACE_NAMSIZ - 1);
br_if->index++; br_if->index++;
return 0; return 0;
@ -409,7 +407,7 @@ int br_json_to_string( cJSON *json_obj, pointer output)
return output_len; 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); s2j_create_json_obj(json_obj);
if(json_obj == NULL) 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_basic_element(json_obj, br_config, string, br_name);
s2j_json_set_array_element(json_obj, br_config, string, s2j_json_set_array_element(json_obj, br_config, string, ports, br_if->index);
ports, br_config->port_num);
return json_obj; return json_obj;
} }
@ -428,28 +425,29 @@ ret_code br_bridge_info(const char *br_name, cJSON *json_obj, int *err)
{ {
ret_code ret = RET_OK; ret_code ret = RET_OK;
br_if_temp_t br_if = {0}; br_if_temp_t br_if = {0};
br_config_t br_config = {0}; int i = 0;
br_if.index = 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); *err = br_foreach_port(br_name, br_copy_port_name, &br_if);
if (*err >= 0) if (*err >= 0)
{ {
strncpy(br_config.br_name, br_name, BR_NAMSIZ - 1); json_obj = br_config_format_json(&br_if);
br_config.ports = br_if.if_list;
br_config.port_num = br_if.index;
json_obj = br_config_format_json(&br_config);
} }
else else
{ {
ret = RET_SYSERR; 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; 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 if(br_if_conf->config_type == CM_CONFIG_ADD
|| br_if_conf->config_type == CM_CONFIG_DEL) || br_if_conf->config_type == CM_CONFIG_DEL)
{ {
s2j_struct_get_array_string_n(br_if_conf, json_obj, string, s2j_struct_get_array_string_n(br_if_conf, json_obj, ports, port_num, INTERFACE_NAMSIZ);
ports, port_num, INTERFACE_NAMSIZ);
br_if->port_num = port_num; br_if->port_num = port_num;
br_if->ports = br_if_conf->ports; /*指针赋值,后续需要对该指针进行内存释放*/ br_if->ports = br_if_conf->ports; /*指针赋值,后续需要对该指针进行内存释放*/
br_if_conf->ports = NULL; 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; 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; *conf_type = br_fdb_conf->config_type;
strncpy(br_fdb->br_name, br_fdb_conf->br_name, BR_NAMSIZ - 1); strncpy(br_fdb->br_name, br_fdb_conf->br_name, BR_NAMSIZ - 1);

View File

@ -115,9 +115,9 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth,
void *arg, __u16 nc_flags); void *arg, __u16 nc_flags);
#define rtnl_dump_filter(rth, filter, arg) \ #define rtnl_dump_filter(rth, filter, arg) \
rtnl_dump_filter_nc(rth, filter, arg, 0) 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) 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, int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
struct nlmsghdr **answer) struct nlmsghdr **answer)
__attribute__((warn_unused_result)); __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, int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
const void *data, int alen); 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 parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,
int len, unsigned short flags); int len, unsigned short flags);
struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);