Add aaa-12 添加VLAN自定义错误码并替换

SOL 添加VLAN自定义错误码并替换
修改人:yinbin
检视人:yinbin

Signed-off-by: yinbin <yinbin@cmhi.chinamobile.com>
This commit is contained in:
yinbin 2019-08-29 05:42:26 -07:00
parent dfec2c88da
commit a5d88222d5
2 changed files with 73 additions and 56 deletions

View File

@ -33,6 +33,20 @@ typedef uint ret_code;
#define RET_IPINVALID (uint)((uint)NETCONFIG_MODULE<<16|1)
#define RET_BRNAMEERR (uint)((uint)NETCONFIG_MODULE<<16|1)
/* VLANCONFIG_MODULE 0x00050000 ~ 0x0005ffff*/
#define RET_VIDNUM_INVALID (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_VID_INVALID (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_VID_EXIST (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_VID_NOT_EXIST (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_INTERFACE_NOT_EXIST (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_ATTR_INVALID (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_OPTYPE_ERR (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_SYS_VCONFIG_ERR (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_SYS_IFCONFIG_ERR (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define RET_SYS_FILEOP_ERR (uint)((uint)VLAN_CONFIG_MODULE<<16|1)
#define ERR_STR_LEN 64
/* 错误码描述 */
@ -56,7 +70,18 @@ typedef uint ret_code;
{ RET_SRCERR, "ConfigSourceErr"},\
\
{ RET_IPINVALID, "IpInvalid"},\
{ RET_BRNAMEERR, "BrNameInvalid"}\
{ RET_BRNAMEERR, "BrNameInvalid"},\
\
{ RET_VIDNUM_INVALID, "VidNumInvalid"},\
{ RET_VID_INVALID, "VidValueInvalid"},\
{ RET_VID_EXIST, "VidHasExist"},\
{ RET_VID_NOT_EXIST, "VidHasNotExist"},\
{ RET_INTERFACE_NOT_EXIST, "InterfaceHasNotExist"},\
{ RET_ATTR_INVALID, "AttrInvalid"},\
{ RET_OPTYPE_ERR, "OperationTypeError"},\
{ RET_SYS_VCONFIG_ERR, "SystemVconfigError"},\
{ RET_SYS_IFCONFIG_ERR, "SystemIfconfigError"},\
{ RET_SYS_FILEOP_ERR, "SystemFileOperationError"}\
}
struct err_disc {

View File

@ -359,7 +359,7 @@ ret_code add_vlan_sub_interface(char *if_name, int *vlan_bitmap)
status = system(buf);
if(status != 0){
printf("[vlan]add_vlan_sub_if: subif status error. (%s)\n", strerror(errno));
return RET_SYSERR;
return RET_SYS_VCONFIG_ERR;
}
memset(buf, 0, SYSCALL_BUF_LEN);
@ -370,7 +370,7 @@ ret_code add_vlan_sub_interface(char *if_name, int *vlan_bitmap)
status = system(buf);
if(status != 0){
printf("[vlan]add_vlan_sub_if: ifconfig subif status error. (%s)\n", strerror(errno));
return RET_SYSERR;
return RET_SYS_IFCONFIG_ERR;
}
memset(buf, 0, SYSCALL_BUF_LEN);
@ -468,7 +468,7 @@ ret_code add_interface_vlan(interface_vlan_info *if_vlan_info)
}
else{
printf("[vlan]add_interface_vlan: LINK-TYPE attr(%d) input error.\n", new_attr);
return RET_INPUTERR;
return RET_ATTR_INVALID;
}
/* 更新全局接口vlan数据结构 */
@ -619,7 +619,7 @@ ret_code del_vlan_sub_interface(char *if_name, int *vlan_bitmap)
status = system(buf);
if(status != 0){
printf("[vlan]del_vlan_sub_if:status error. (%s)\n", strerror(errno));
return RET_ERR;
return RET_SYS_VCONFIG_ERR;
}
memset(buf, 0, SYSCALL_BUF_LEN);
memset(tmp_brname, 0, BR_VLAN_NAME_LEN);
@ -633,7 +633,7 @@ ret_code del_vlan_sub_interface(char *if_name, int *vlan_bitmap)
/* 如果br-vlxx不存在,报错返回 */
if(br_is_exist(br_vlname) == FALSE){
printf("[vlan]del_vlan_sub_interface: %s is not exist, error,return.\n", br_vlname);
return RET_ERR;
return RET_UNKNOWN;
}
/* brctl delif删除br-vl上的vlan子接口 */
@ -650,7 +650,7 @@ ret_code del_vlan_sub_interface(char *if_name, int *vlan_bitmap)
status = system(buf);
if(status != 0){
printf("[vlan]del_vlan_sub_if:status error. (%s)\n",strerror(errno));
return RET_ERR;
return RET_SYS_VCONFIG_ERR;
}
memset(buf, 0, SYSCALL_BUF_LEN);
@ -933,9 +933,11 @@ ret_code vlan_save_conf_file_add(interface_vlan_info *if_vlan_info)
for(vid = VID_MIN; vid <= VID_MAX; vid++){
if(vlan_bitmap_check(if_vlan_info->vlan_bitmap, vid)){
(void)if_vlan2subif(if_vlan_info->if_name, vid, subif);
printf("[vlan]save_conf_file_add: vid is %d, subif is %s\n", vid, subif);
ip_conf_file_set(subif, addr_name, addr_buff);
}
}
printf("[vlan]save_conf_file_add: save file add end.\n");
return RET_OK;
}
@ -952,7 +954,7 @@ ret_code vlan_conf_file_del(char *if_name, char *address)
status = system(buf);
if(status != 0){
printf("[vlan]vlan_conf_file_del1: status error. (%s)\n", strerror(errno));
return RET_SYSERR;
return RET_SYS_FILEOP_ERR;
}
memset(buf, 0, 100);
@ -960,7 +962,7 @@ ret_code vlan_conf_file_del(char *if_name, char *address)
status = system(buf);
if(status != 0){
printf("[vlan]vlan_conf_file_del2: status error. (%s)\n", strerror(errno));
return RET_SYSERR;
return RET_SYS_FILEOP_ERR;
}
memset(buf, 0, 100);
@ -986,7 +988,8 @@ ret_code vlan_save_conf_file_del(interface_vlan_info *if_vlan_info)
if(!if_vlan_info){
return RET_NULLP;
}
//ifnode = get_ifnode_from_global(if_vlan_info->if_name);
//ifnode = get_ifnode_from_global(if_vlan_info->if_name);
printf("[vlan]vlan_save_conf_file_del: begin.\n");
for(vid = VID_MIN; vid <= VID_MAX; vid++){
if(vlan_bitmap_check(if_vlan_info->vlan_bitmap, vid)){
(void)if_vlan2subif(if_vlan_info->if_name, vid, subif);
@ -998,6 +1001,7 @@ ret_code vlan_save_conf_file_del(interface_vlan_info *if_vlan_info)
}
}
}
printf("[vlan]vlan_save_conf_file_del: save file del end.\n");
return RET_OK;
}
@ -1021,7 +1025,7 @@ ret_code vlan_save_conf_file(interface_vlan_info *if_vlan_info)
}
else{
printf("[vlan]vlan_save_conf_file: OP_TYPE ERROR.return\n");
ret = RET_UNKNOWN;
ret = RET_OPTYPE_ERR;
}
return ret;
}
@ -1055,7 +1059,7 @@ ret_code refresh_if_vlan_info(interface_vlan_info *if_vlan_info)
}
else {
printf("[vlan]refresh_if_vlan_info: OP_TYPE ERROR.return\n");
ret = RET_UNKNOWN;
ret = RET_OPTYPE_ERR;
}
return ret;
@ -1105,7 +1109,7 @@ ret_code del_interface_vlan(interface_vlan_info *if_vlan_info)
}
else {
printf("[vlan]del_interface_vlan: LINK-TYPE attr(%d) input error.\n", old_attr);
return RET_UNKNOWN;
return RET_ATTR_INVALID;
}
/* 更新全局接口vlan数据结构 */
ret = refresh_if_vlan_info(if_vlan_info);
@ -1195,7 +1199,7 @@ ret_code interface_vlan_set(interface_vlan_info *if_vlan_info)
}
else{
printf("[vlan]interface_vlan_set: op_type error.\n");
ret = RET_INPUTERR;
ret = RET_OPTYPE_ERR;
}
return ret;
}
@ -1263,7 +1267,7 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info
ret = RET_INPUTERR;
goto out;
}
cJSON *node;
cJSON *node = NULL;
for(i = 0; i < if_num; i++){
/* 给每个接口的op_type赋值 */
@ -1320,7 +1324,7 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info
}
else {
printf("[vlan]vlan_config_json_parse: errror: is not trunk or access.\n");
ret = RET_INPUTERR;
ret = RET_ATTR_INVALID;
goto out;
}
cJSON *vId = cJSON_GetObjectItem(node, "vid");
@ -1353,7 +1357,6 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info
ret = vid_value_chk(item->valueint);
if(ret != RET_OK){
printf("[vlan]vlan_config_json_parse: vid check failed.\n");
ret = RET_INPUTERR;
goto out;
}
vlan_bitmap_set(if_vlan_info[i].vlan_bitmap, item->valueint);
@ -1388,36 +1391,17 @@ ret_code vlan_config_proc(uint source, uint config_type,
interface_vlan_info if_vlan_info[MAX_INTERFACES] = {0};
printf("[vlan]===config-proc begin.===\n");
/* 配置下发 */
if(source == CONFIG_FROM_WEB){
ret = vlan_config_json_parse(input, if_vlan_info, &if_vl_num);
ret = vlan_config_json_parse(input, if_vlan_info, &if_vl_num);
if(ret != RET_OK){
printf("[vlan]vlan_config_proc: source:%d, json parse failed(%d).\n", source, ret);
return ret;
}
for(i = 0; i < if_vl_num; i++){
ret = interface_vlan_set(&if_vlan_info[i]);
if(ret != RET_OK){
printf("[vlan]vlan_config_proc: source:%d, json parse failed(%d).\n", source, ret);
printf("[vlan]vlan_config_proc: source:%d, vlan set failed(%d).\n", source, ret);
return ret;
}
for(i = 0; i < if_vl_num; i++){
ret = interface_vlan_set(&if_vlan_info[i]);
if(ret != RET_OK){
printf("[vlan]vlan_config_proc: source:%d, vlan set failed(%d).\n", source, ret);
return ret;
}
}
}
/* ÅäÖûָ´ */
else if(source == CONFIG_FROM_RECOVER1){
ret = vlan_config_json_parse(input, if_vlan_info, &if_vl_num);
if(ret != RET_OK){
printf("[vlan]vlan_config_proc: source:%d, json parse failed(%d).\n", source, ret);
return ret;
}
for(i = 0; i < if_vl_num; i++){
ret = interface_vlan_set(&if_vlan_info[i]);
if(ret != RET_OK){
printf("[vlan]vlan_config_proc: source:%d, vlan set failed(%d).\n", source, ret);
return ret;
}
}
}
return RET_OK;
@ -1509,7 +1493,15 @@ ret_code vlan_get_json_parse(int *interface, pointer input)
}
cJSON *ifName = cJSON_GetObjectItem(node, "if-name");
if(!ifName){
continue;
//continue;
printf("[vlan]vlan_get_json_parse: json has no ifName node.\n");
ret = RET_INPUTERR;
goto out;
}
if(NULL == ifName->valuestring){
printf("[vlan]vlan_get_json_parse: ifName->valuestring is null.\n");
ret = RET_INPUTERR;
goto out;
}
//if_vlan_info[i].if_name= ifName->valuestring;//memcpy
/* 如果找到了对应的ifnode,则对应下标置1 */
@ -1559,7 +1551,7 @@ ret_code vlan_config_format_json(int *interface, pointer output, int *output_len
cJSON_AddStringToObject(js_list , "if-name", g_if_vlan_info[i].if_name);
cJSON_AddNumberToObject(js_list , "if-attr", g_if_vlan_info[i].attr);
cJSON_AddItemToObject(js_list, "vid", js_vid = cJSON_CreateArray());
for(vid = 0; vid < MAX_VLAN;vid++){
for(vid = VID_MIN; vid <= VID_MAX;vid++){
if(vlan_bitmap_check(g_if_vlan_info[i].vlan_bitmap, vid)){
cJSON_AddItemToArray(js_vid, cJSON_CreateNumber(vid));
}
@ -1637,7 +1629,7 @@ ret_code vlan_get_from_conf_file(int *interface)
char line[FILE_BUF_LINE] = {0};
if(!(fp = fopen(ETC_NETWORK_IFS, "r"))){
printf("[vlan]vlan_get_from_conf_file: file open failed.\n");
return RET_ERR;
return RET_SYS_FILEOP_ERR;
}
//fseek(fp,0,SEEK_END);
//rewind(fp);
@ -1825,7 +1817,7 @@ ret_code vid_value_chk(int vid)
{
if(!(vid >= VID_MIN && vid <= VID_MAX)){
printf("[vlan]vid_value_chk: vid value error,return error\n");
return RET_INPUTERR;
return RET_VID_INVALID;
}
return RET_OK;
}
@ -1856,7 +1848,7 @@ ret_code vid_num_chk(char *if_name, operation_type op_type, int num)
}
if(op_type == OP_ADD && total > EACH_PORT_MAX_VLAN_NUM){
printf("[vlan]vid_num_chk: ADD operation's total vid num > EACH_PORT_MAX_VLAN_NUM\n");
return RET_INPUTERR;
return RET_VIDNUM_INVALID;
}
return RET_OK;
@ -1873,7 +1865,7 @@ ret_code if_attr_chk(interface_vlan_info *if_vlan_info)
{
if(if_vlan_info->attr != LINK_TYPE_TRUNK){
printf("[vlan]if_attr_chk: now we only support link-type trunk.\n");
return RET_INPUTERR;
return RET_ATTR_INVALID;
}
return RET_OK;
}
@ -1899,7 +1891,7 @@ ret_code op_type_add_chk(interface_vlan_info *if_vlan_info)
if(vlan_bitmap_check(if_vlan_info->vlan_bitmap, vid)
&& vlan_bitmap_check(g_if_vlan_info[ifnode].vlan_bitmap, vid)){
printf("[vlan]op_type_add_chk: Already have vid[%d], now return\n", vid);
return RET_INPUTERR;
return RET_VID_EXIST;
}
}
return RET_OK;
@ -1919,7 +1911,7 @@ ret_code op_type_del_chk(interface_vlan_info *if_vlan_info)
ifnode = get_ifnode_from_global(if_vlan_info->if_name);
if(ifnode == -1){
printf("[vlan]op_type_del_chk: get_ifnode failed.\n");
ret = RET_INPUTERR;
ret = RET_INTERFACE_NOT_EXIST;
goto out;
}
@ -1928,7 +1920,7 @@ ret_code op_type_del_chk(interface_vlan_info *if_vlan_info)
if(vlan_bitmap_check(if_vlan_info->vlan_bitmap, vid)
&& !vlan_bitmap_check(g_if_vlan_info[ifnode].vlan_bitmap, vid)){
printf("[vlan]op_type_del_chk: node[%d] do not have vid[%d], now return\n", ifnode, vid);
ret = RET_INPUTERR;
ret = RET_VID_NOT_EXIST;
goto out;
}
}
@ -1957,7 +1949,7 @@ ret_code op_type_chk(interface_vlan_info *if_vlan_info)
}
else {
printf("[vlan]op_type_chk: op_type error.\n");
ret = RET_INPUTERR;
ret = RET_OPTYPE_ERR;
}
return ret;
}
@ -1972,7 +1964,7 @@ ret_code if_name_chk(interface_vlan_info *if_vlan_info)
{
if(!(strcmp(if_vlan_info->if_name, ""))){
printf("[vlan]if_name_chk: if-name is emptyp, return error.\n");
return RET_ERR;
return RET_INPUTERR;
}
return RET_OK;
}
@ -2190,7 +2182,7 @@ ret_code vlan_config_chk(uint source,uint *config_type,
}
else {
printf("[vlan]vlan_config_chk: oper_type is unknown(%d).\n", oper_type);
ret = RET_UNKNOWN;
ret = RET_OPTYPE_ERR;
}
out: