secgateway/Platform/user/configm/config-server/nat_config/natconfig.c

125 lines
3.0 KiB
C

#include "configm.h"
#include "rpc.h"
#include "parsefile.h"
#include "config.h"
const char *iptables_save_dir = \
"./iptables-conf.txt";
ret_code get_config_type(pointer input, uint *conf_type) {
cJSON *json_obj;
json_obj = cJSON_Parse(input);
if(!json_obj)
{
return RET_INPUTERR;
}
rpc_log_info("json input:\n %s \n", cJSON_Print(json_obj));
cJSON *__type_json = cJSON_GetObjectItem(json_obj, "config_type");
if (__type_json) *conf_type = __type_json->valueint;
else *conf_type = 0;
cJSON_Delete(json_obj);
return RET_OK;
}
ret_code nat_config_chk(uint source,uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
{
int config_len = sizeof(ip_config_t);
int code = 0;
ret_code ret = RET_OK;
if(source == CONFIG_FROM_RECOVER1) {
return RET_OK;
}
if(source == CONFIG_FROM_RECOVER2){
return RET_CHKERR;
}
get_config_type(input, config_type);
switch (*config_type)
{
case CM_CONFIG_SET:
case CM_CONFIG_DEL:
/*
ret = nat_config_set(source, *config_type,
input, input_len,
output, output_len);*/
break;
case CM_CONFIG_GET:
break;
case CM_CONFIG_GET_ALL:
/*ret = nat_config_get_all(source,
output, output_len);*/
break;
default:
ret = RET_NOTSUPPORT;
}
RET_ERR_FORMART(ret, output, *output_len);
ASSERT_RET(ret);
return ret;
}
ret_code nat_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
char *errmsg;
char *jsontxt = (char*)input;
int code = 0;
ret_code ret = RET_OK;
if(source == CONFIG_FROM_RECOVER1 || source == CONFIG_FROM_RECOVER2) {
ret = nat_config_recovery(&errmsg);
goto pass;
}
ret = set_iptables_config(jsontxt, &errmsg);
pass:
rpc_log_info("NAT message: %s \n", errmsg);
free(errmsg);
RET_ERR_FORMART(ret, output, *output_len);
ASSERT_RET(ret);
return ret;
}
ret_code nat_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len)
{
char *errmsg;
char *jsontxt = (char*)input;
int code = 0;
ret_code ret = RET_OK;
ret = get_iptables_config(jsontxt, iptables_save_dir, output, output_len, &errmsg);
rpc_log_info("NAT message:\n %s \n", errmsg);
free(errmsg);
RET_ERR_FORMART(ret, output, *output_len);
ASSERT_RET(ret);
return ret;
}
ret_code nat_config_get_all(uint source, pointer output, int *output_len)
{
return RET_OK;
}