Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f833a44ccd
|
@ -38,7 +38,7 @@ ret_code routing_to_json(int count, routing_t *buff_total, pointer output, int *
|
|||
if(ret_root == NULL)
|
||||
{
|
||||
cJSON_Delete(ret_root);
|
||||
return RET_NOMEM;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(ret_root,"total number",count);
|
||||
|
@ -48,7 +48,7 @@ ret_code routing_to_json(int count, routing_t *buff_total, pointer output, int *
|
|||
if(json_array == NULL)
|
||||
{
|
||||
cJSON_Delete(json_array);
|
||||
return RET_NOMEM;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
if(count > 0)
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
{
|
||||
rpc_log_info("json obj is NULL \n");
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_INPUTERR;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
rpc_log_info("json input:\n %s \n", cJSON_Print(json_obj));
|
||||
|
@ -114,7 +114,7 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
if(NULL == operate)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_INPUTERR;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
/*根据operate的值给conf_type赋值*/
|
||||
|
@ -133,7 +133,7 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
}
|
||||
else
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_WRONG_TYPE;
|
||||
}
|
||||
|
||||
route = cJSON_GetObjectItem(json_obj,"route");
|
||||
|
@ -141,13 +141,13 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
if(NULL == route)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
return RET_INPUTERR;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
version = cJSON_GetObjectItem(route,"version");
|
||||
if(!version)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_VERSION_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
destip = cJSON_GetObjectItem(route,"destip");
|
||||
if(!destip)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_DESTIP_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -168,9 +168,9 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
rpc_log_info("destip:%s \n", conf_buff->destip);
|
||||
|
||||
netmask = cJSON_GetObjectItem(route,"netmask");
|
||||
if(!netmask)
|
||||
if((!netmask) || (netmask->valueint < 0) || (netmask->valueint > 128))
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_NETMASK_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff
|
|||
if((!metric) || (metric->valueint) < 0 || (metric->valueint)
|
||||
> 10000)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_METRIC_ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -235,7 +235,7 @@ ret_code insert_into_file(char *string)
|
|||
if(NULL == f)
|
||||
{
|
||||
rpc_log_error("open config file fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
@ -279,7 +279,7 @@ ret_code delete_from_file(char *string)
|
|||
if(NULL == f)
|
||||
{
|
||||
rpc_log_error("open config file fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_END);
|
||||
|
@ -338,14 +338,14 @@ ret_code add_routing_exe (char *string)
|
|||
|
||||
if(NULL == string)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
status = system(string);
|
||||
if (-1 == status)
|
||||
{
|
||||
rpc_log_error("system shell error!\n");
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
else {
|
||||
if (WIFEXITED(status)){
|
||||
|
@ -355,12 +355,12 @@ ret_code add_routing_exe (char *string)
|
|||
}
|
||||
else{
|
||||
rpc_log_error("run shell script fail,script exit code:%d\n",WEXITSTATUS(status));
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
rpc_log_error("exit status = [%d]\n",WEXITSTATUS(status));
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,14 +375,14 @@ ret_code del_routing_exe (char *string, char *string_del)
|
|||
|
||||
if(NULL == string || NULL == string_del)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
status = system(string);
|
||||
if (-1 == status)
|
||||
{
|
||||
rpc_log_error("system shell error!\n");
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
else {
|
||||
if (WIFEXITED(status)){
|
||||
|
@ -404,13 +404,13 @@ ret_code del_routing_exe (char *string, char *string_del)
|
|||
}
|
||||
else
|
||||
{
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
rpc_log_error("exit status = [%d]\n",WEXITSTATUS(status));
|
||||
return RET_SYSERR;
|
||||
return RET_EXEC_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,7 +478,7 @@ ret_code default_routing_proc(routing_t *conf_buff, uint config_type){
|
|||
|
||||
if (conf_buff == NULL)
|
||||
{
|
||||
return RET_NULLP;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
judge_para(&flag,gw_t,dev_t);
|
||||
|
@ -536,7 +536,7 @@ ret_code default_routing_proc(routing_t *conf_buff, uint config_type){
|
|||
|
||||
else
|
||||
{
|
||||
return RET_ERR;
|
||||
return RET_VERSION_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,11 +591,16 @@ ret_code default_routing_proc(routing_t *conf_buff, uint config_type){
|
|||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return RET_VERSION_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return RET_ERR;
|
||||
return RET_WRONG_TYPE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -620,7 +625,7 @@ ret_code routing_add(routing_t *conf_buff)
|
|||
|
||||
if (metric_t < 1)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_METRIC_ERR;
|
||||
}
|
||||
|
||||
judge_para(&flag,gw_t,dev_t);
|
||||
|
@ -641,7 +646,8 @@ ret_code routing_add(routing_t *conf_buff)
|
|||
}
|
||||
else
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
rpc_log_info("netmask error \n");
|
||||
return RET_NETMASK_ERR;
|
||||
}
|
||||
|
||||
switch (flag){
|
||||
|
@ -664,10 +670,6 @@ ret_code routing_add(routing_t *conf_buff)
|
|||
|
||||
else if (version_t == IPV6_VERSION)
|
||||
{
|
||||
if(netmask_t < 0 || netmask_t >128)
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
switch(flag){
|
||||
case 1:
|
||||
sprintf(string,"route -A inet6 add %s/%d gw %s dev %s metric %d\n",destip_t,netmask_t,gw_t,dev_t,metric_t);
|
||||
|
@ -686,6 +688,7 @@ ret_code routing_add(routing_t *conf_buff)
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -721,7 +724,7 @@ ret_code routing_del(routing_t *conf_buff)
|
|||
}
|
||||
else
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_NETMASK_ERR;
|
||||
}
|
||||
|
||||
switch (flag){
|
||||
|
@ -797,14 +800,14 @@ ret_code get_all_from_file (pointer output, int *output_len)
|
|||
if(NULL == f)
|
||||
{
|
||||
rpc_log_error("open config file fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
buff_total = rpc_new0(routing_t, ROUTING_TABLE_MAX_NUMBER);
|
||||
//buff_total = (routing_t *)malloc(ROUTING_TABLE_MAX_NUMBER*sizeof(routing_t));
|
||||
if(buff_total == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
return RET_EMPTY_STRING;
|
||||
}
|
||||
|
||||
memset(buff,0,sizeof(buff));
|
||||
|
@ -952,7 +955,7 @@ ret_code config_recovery()
|
|||
if(NULL == f)
|
||||
{
|
||||
rpc_log_error("open config file fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
memset(buff,0,sizeof(buff));
|
||||
|
@ -1046,13 +1049,13 @@ ret_code routing_config_chk(uint source, uint *config_type,
|
|||
/*判断协议是否正确*/
|
||||
if((conf_buff->version != IPV4_VERSION) && (conf_buff->version != IPV6_VERSION))
|
||||
{
|
||||
return RET_CHKERR;
|
||||
return RET_VERSION_ERR;
|
||||
}
|
||||
|
||||
else if(strcmp(conf_buff->gateway,"") == 0 && strcmp(conf_buff->dev,"") == 0)
|
||||
{
|
||||
rpc_log_info(" gateway and dev are NULL\n");
|
||||
return RET_CHKERR;
|
||||
return RET_GW_DEV_ERR;
|
||||
}
|
||||
|
||||
else if(conf_buff->version == IPV4_VERSION)
|
||||
|
@ -1063,7 +1066,7 @@ ret_code routing_config_chk(uint source, uint *config_type,
|
|||
if(a<0 || a>255 || b<0 || b>255 || c<0 || c>255 || d<0 |d>255)
|
||||
{
|
||||
rpc_log_info("ip address wrong:%d %d %d %d\n",a,b,c,d);
|
||||
return RET_CHKERR;
|
||||
return RET_DESTIP_ERR;
|
||||
}
|
||||
|
||||
if(strcmp(conf_buff->gateway,"") != 0)
|
||||
|
@ -1072,7 +1075,7 @@ ret_code routing_config_chk(uint source, uint *config_type,
|
|||
if(a1<0 || a1>255 || b1<0 || b1>255 || c1<0 || c1>255 || d1<0 |d1>255)
|
||||
{
|
||||
rpc_log_info("gateway address wrong:%d %d %d %d\n",a1,b1,c1,d1);
|
||||
return RET_CHKERR;
|
||||
return RET_GATEWAY_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1084,13 +1087,13 @@ ret_code routing_config_chk(uint source, uint *config_type,
|
|||
if ((*output_len)<(ROUTING_TABLE_MAX_NUMBER * sizeof(routing_t)))
|
||||
{
|
||||
rpc_log_info("getall check error\n");
|
||||
return RET_CHKERR;
|
||||
return RET_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return RET_CHKERR;
|
||||
return RET_WRONG_TYPE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1150,7 +1153,7 @@ ret_code routing_config_proc(uint source, uint config_type,
|
|||
}
|
||||
else
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_NETMASK_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1166,7 +1169,7 @@ ret_code routing_config_proc(uint source, uint config_type,
|
|||
break;
|
||||
|
||||
default:
|
||||
ret = RET_NOTSUPPORT;
|
||||
ret = RET_WRONG_TYPE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1224,12 +1227,12 @@ ret_code all_routing_config_chk(uint source, uint * config_type,
|
|||
if ((*output_len)<(ROUTING_TABLE_MAX_NUMBER * sizeof(routing_t)))
|
||||
{
|
||||
rpc_log_info("getall check error\n");
|
||||
return RET_CHKERR;
|
||||
return RET_NOMEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return RET_INPUTERR;
|
||||
return RET_WRONG_TYPE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1265,7 +1268,7 @@ ret_code all_routing_get_all(uint source,
|
|||
if (NULL == f)
|
||||
{
|
||||
rpc_log_error("get ipv4 routing info fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
conf_buff = rpc_new0(routing_t,ROUTING_TABLE_MAX_NUMBER);
|
||||
|
@ -1325,7 +1328,7 @@ next_while:
|
|||
if (NULL == f)
|
||||
{
|
||||
rpc_log_error("get ipv6 routing info fail\n");
|
||||
return RET_SYSERR;
|
||||
return RET_OPEN_FILE_ERR;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
|
Loading…
Reference in New Issue