diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index 2fd52fb67..56e28c26c 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -1,79 +1,83 @@ -# target name, the target name must have the same name of c source file -TARGET_NAME=configm - -# target -# for linux module driver: KO -# for application: EXE -# for dynamic library: DLL -TARGET_TYPE = EXE - -# target object -# for application: APP -# for device driver: DRV -TARGET_OBJ = APP - -# custom install dir -TARGET_BOX = - -#debug mode or release mode -DEBUG = TRUE - -PLAT_LINUX ?= TRUE -PLAT_ARM64 ?= TRUE - -VPATH = ../user/configm/config-server -# source code - -# set the source file, don't used .o because of ... - -COMMON_SRCS = configserver.c \ - netconfig/parsefile.c netconfig/ifconfig.c netconfig/netmain.c\ - netconfig/ipconfig/ipconfig.c \ - netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \ - netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\ - web_config/config-adm/user_authpara.c \ - web_config/config-adm/user_authfree.c \ - web_config/authfree.c web_config/auth_parameters.c\ - user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \ - user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \ - log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c - -# MRS Board Source Files -PLAT_LINUX_SRCS = $(COMMON_SRCS) -PLAT_ARM64_SRCS = $(COMMON_SRCS) - -COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/database -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/ -I../user/configm/config-server/netconfig/bridge/include -# gcc CFLAGS -PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) - -PLAT_ARM64_LDFLAGS := -PLAT_LINUX_LDFLAGS := - -#gcc libs -ARM64_LIBS := -lopenrpc-arm64 -lnetlinku-arm64 -lredismq-arm64 -lulogapi-arm64 -ldatabase-arm64 -ARM64_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -lodbc -lev -ldl - -LINUX_LIBS := -lopenrpc-linux -lnetlinku-linux -lredismq-linux -lulogapi-linux -ldatabase-linux -LINUX_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -lodbc -lev -ldl - - -# this line must be at below of thus, because of... -include ../../Common/common.Makefile - -ifneq ($(MAKECMDGOALS), clean) -ifneq ($(MAKECMDGOALS), cleanall) -ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB))) -$(shell $(CP) $(DEPEND_LIB) ./) -endif -endif -endif - -ifeq ($(MAKECMDGOALS), ) -$(shell find ./ -name "$(TARGET)-*.ko" -delete) -else -ifeq ($(MAKECMDGOALS), all) -$(shell find ./ -name "$(TARGET)-*.ko" -delete) -endif -endif - +# target name, the target name must have the same name of c source file +TARGET_NAME=configm + +# target +# for linux module driver: KO +# for application: EXE +# for dynamic library: DLL +TARGET_TYPE = EXE + +# target object +# for application: APP +# for device driver: DRV +TARGET_OBJ = APP + +# custom install dir +TARGET_BOX = + +#debug mode or release mode +DEBUG = TRUE + +PLAT_LINUX ?= TRUE +PLAT_ARM64 ?= TRUE + +VPATH = ../user/configm/config-server +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = configserver.c \ + netconfig/parsefile.c netconfig/ifconfig.c netconfig/netmain.c\ + netconfig/ipconfig/ipconfig.c \ + netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \ + netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\ + web_config/config-adm/user_authpara.c \ + web_config/config-adm/user_authfree.c \ + web_config/authfree.c web_config/auth_parameters.c\ + user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \ + user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \ + log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \ + nat_config/natconfig.c + + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + + +COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/database -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/ -I../user/configm/config-server/netconfig/bridge/include + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) +PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) + +PLAT_ARM64_LDFLAGS := +PLAT_LINUX_LDFLAGS := + +#gcc libs +ARM64_LIBS := -lopenrpc-arm64 -lnetlinku-arm64 -lredismq-arm64 -lulogapi-arm64 -ldatabase-arm64 +ARM64_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -lodbc -lev -ldl + +LINUX_LIBS := -lopenrpc-linux -lnetlinku-linux -lredismq-linux -lulogapi-linux -ldatabase-linux +LINUX_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -lodbc -lev -ldl + + +# this line must be at below of thus, because of... +include ../../Common/common.Makefile + +ifneq ($(MAKECMDGOALS), clean) +ifneq ($(MAKECMDGOALS), cleanall) +ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB))) +$(shell $(CP) $(DEPEND_LIB) ./) +endif +endif +endif + +ifeq ($(MAKECMDGOALS), ) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +else +ifeq ($(MAKECMDGOALS), all) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +endif +endif + diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 6d0ce19a0..81bd290eb 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -10,6 +10,8 @@ #include "log_config.h" #include "../web_config/authfree.h" #include "../web_config/auth_parameters.h" +#include "natconfig.h" + #define CONFIG_INIT_ARRAY \ @@ -162,7 +164,16 @@ log_file_config_proc, \ NULL, \ NULL \ - }\ + },\ + {\ + NAT4_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + nat_config_chk, \ + nat_config_proc, \ + NULL, \ + nat_config_get_all \ + }\ } typedef ret_code (*cm_config_init)(); diff --git a/Platform/user/configm/config-server/include/natconfig.h b/Platform/user/configm/config-server/include/natconfig.h new file mode 100644 index 000000000..b434971cc --- /dev/null +++ b/Platform/user/configm/config-server/include/natconfig.h @@ -0,0 +1,23 @@ +#ifndef _NAT_CONFIG_H +#define _NAT_CONFIG_H + +#include + +#include "rpc_types.h" +#include "rpc_common.h" + +ret_code nat_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + +ret_code nat_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + +ret_code nat_config_get(uint source, + pointer input, int input_len, + pointer output, int *output_len); + +ret_code nat_config_get_all(uint source, pointer output, int *output_len); + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/nat_config/0x0000000800000001 b/Platform/user/configm/config-server/nat_config/0x0000000800000001 new file mode 100644 index 000000000..9aa3baa12 --- /dev/null +++ b/Platform/user/configm/config-server/nat_config/0x0000000800000001 @@ -0,0 +1 @@ +{"config_type":1,"-t":"nat","action":"-A","chain":"POSTROUTING","-i":"ens33","-s":"192.168.12.12","-j":"DNAT","--to-destionation":"172.18.2.72"} \ No newline at end of file diff --git a/Platform/user/configm/config-server/nat_config/natconfig.c b/Platform/user/configm/config-server/nat_config/natconfig.c index b6ba11db0..784853031 100644 --- a/Platform/user/configm/config-server/nat_config/natconfig.c +++ b/Platform/user/configm/config-server/nat_config/natconfig.c @@ -1,610 +1,40 @@ -#include "configm.h" -#include "ipconfig.h" -#include "rpc.h" -#include "parsefile.h" - -uchar ip_masklen(struct in_addr netmask) -{ - uint tmp = ~ntohl(netmask.s_addr); - if (tmp) - /* clz: count leading zeroes. sadly, the behaviour of this - * builtin - * is undefined for a 0 argument, even though most CPUs give 32 - */ - return __builtin_clz(tmp); - else - return 32; -} - - -/* Convert masklen into IP address's netmask (network byte order). */ -void masklen2ip(const int masklen, struct in_addr *netmask) -{ - if(masklen < 0 || masklen > IPV4_MAX_BITLEN) - { - return; - } - - /* left shift is only defined for less than the size of the type. - * we unconditionally use long long in case the target platform - * has defined behaviour for << 32 (or has a 64-bit left shift) */ - - if (sizeof(unsigned long long) > 4) - netmask->s_addr = htonl(0xffffffffULL << (32 - masklen)); - else - netmask->s_addr = - htonl(masklen ? 0xffffffffU << (32 - masklen) : 0); -} - -void ip_save_file(ip_config_t *ip_conf, uint config_type) -{ - char *addr_name = "address"; - char *mask_name = "netmask"; - struct in_addr netmask; - char addr_buff[IF_BUFF_LEN] = {0}; - char mask_buff[IF_BUFF_LEN] = {0}; - - if(config_type == CM_CONFIG_SET) - { - sprintf(addr_buff, "address %s\n", inet_ntoa(ip_conf->prefix)); - masklen2ip(ip_conf->prefixlen, &netmask); - sprintf(mask_buff, "netmask %s\n", inet_ntoa(netmask)); - rpc_log_info("%s %s",addr_buff, mask_buff); - - ip_conf_file_set(ip_conf->ifname, addr_name, addr_buff); - ip_conf_file_set(ip_conf->ifname, mask_name, mask_buff); - } - else if(config_type == CM_CONFIG_DEL) - { - ip_conf_file_del(ip_conf->ifname, addr_name); - ip_conf_file_del(ip_conf->ifname, mask_name); - } -} - -/* call ioctl system call */ -ret_code if_ioctl(unsigned long request, caddr_t ifreq, int *ret) -{ - int sock; - int err = 0; - - *ret = 0; - - sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) - { - rpc_log_error("Cannot create UDP socket"); - return RET_SYSERR; - } - if ((*ret = ioctl(sock, request, ifreq)) < 0) - { - err = errno; - rpc_log_error("Ioctl error: %s\n", strerror(errno)); - - } - - close(sock); - - if (*ret < 0) - { - errno = err; - *ret = err; - return RET_SYSERR; - } - - return RET_OK; -} - - -ret_code ip_config_json_parse(pointer input, uint *conf_type, ip_config_t *config_buff) -{ - //ip_config_string_t *ip_config; - 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)); - - s2j_create_struct_obj(ip_config, ip_config_string_t); - - if(ip_config == NULL) - { - cJSON_Delete(json_obj); - return RET_NOMEM; - } - - s2j_struct_get_basic_element(ip_config, json_obj, int, config_type); - S2J_STRUCT_GET_STRING_ELEMENT_N(ip_config, json_obj, ifname, INTERFACE_NAMSIZ); - s2j_struct_get_basic_element(ip_config, json_obj, int, family); - S2J_STRUCT_GET_STRING_ELEMENT_N(ip_config, json_obj, ipaddr, DOT_IP_STR); - s2j_struct_get_basic_element(ip_config, json_obj, int, prefixlen); - - strncpy(config_buff->ifname, ip_config->ifname, INTERFACE_NAMSIZ - 1); - - config_buff->family = (uchar)ip_config->family; - config_buff->prefixlen = (uchar)ip_config->prefixlen; - config_buff->prefix.s_addr = inet_addr(ip_config->ipaddr); - - *conf_type = ip_config->config_type; - - s2j_delete_struct_obj(ip_config); - cJSON_Delete(json_obj); - - return RET_OK; -} - -ret_code ip_config_json_parse_array(pointer input, uint *conf_type, - ip_config_t *config_buff, int *cnt) -{ - //ip_config_string_t *ip_config; - cJSON *json_obj; - cJSON* pArrayItem; - int iCount = 0, i = 0; - - json_obj = cJSON_Parse(input); - if(!json_obj) - { - return RET_INPUTERR; - } - - rpc_log_info("json input:%s \n", cJSON_Print(json_obj)); - - iCount = cJSON_GetArraySize(json_obj); /*获取数组长度*/ - - config_buff = rpc_new0(ip_config_t, iCount); - conf_type = rpc_new0(uint, iCount); - if(!config_buff || !conf_type) - { - return RET_NOMEM; - } - - s2j_create_struct_obj(ip_config, ip_config_string_t); - if(ip_config == NULL) - { - cJSON_Delete(json_obj); - rpc_free(config_buff); - return RET_NOMEM; - } - - *cnt = 0; - for(i = 0; i < iCount; i++) - { - pArrayItem = cJSON_GetArrayItem(json_obj, i); - if(pArrayItem) - { - memset(ip_config, 0, sizeof(ip_config_string_t)); - - s2j_struct_get_basic_element(ip_config, json_obj, int, config_type); - s2j_struct_get_basic_element(ip_config, json_obj, string, ifname); - s2j_struct_get_basic_element(ip_config, json_obj, int, family); - s2j_struct_get_basic_element(ip_config, json_obj, string, ipaddr); - s2j_struct_get_basic_element(ip_config, json_obj, int, prefixlen); - - strncpy(config_buff[*cnt].ifname, ip_config->ifname, INTERFACE_NAMSIZ - 1); - config_buff[*cnt].family = (uchar)ip_config->family; - config_buff[*cnt].prefixlen = (uchar)ip_config->prefixlen; - config_buff[*cnt].prefix.s_addr = inet_addr(ip_config->ipaddr); - conf_type[*cnt] = ip_config->config_type; - - (*cnt)++; - } - } - - s2j_delete_struct_obj(ip_config); - cJSON_Delete(json_obj); - - return RET_OK; -} - - -ret_code ip_config_format_json(int config_type, ip_config_t *config_buff, - pointer output, int *outlen) -{ - ip_config_string_t tem_buff = {0}; - ip_config_string_t *ip_config = &tem_buff; - //cJSON *json_obj = NULL; - char *json_ip; - - ip_config->config_type = config_type; - ip_config->family = AF_INET; - ip_config->prefixlen = config_buff->prefixlen; - - strncpy(ip_config->ifname, config_buff->ifname, INTERFACE_NAMSIZ - 1); - strncpy(ip_config->ipaddr, inet_ntoa(config_buff->prefix), DOT_IP_STR - 1); - - /* create Student JSON object */ - s2j_create_json_obj(json_obj); - if(json_obj == NULL) - { - return RET_NOMEM; - } - - s2j_json_set_basic_element(json_obj, ip_config, int, config_type); - s2j_json_set_basic_element(json_obj, ip_config, string, ifname); - s2j_json_set_basic_element(json_obj, ip_config, int, family); - s2j_json_set_basic_element(json_obj, ip_config, string, ipaddr); - s2j_json_set_basic_element(json_obj, ip_config, int, prefixlen); - - json_ip = cJSON_PrintUnformatted(json_obj); - *outlen = strlen(json_ip) + 1; - memcpy(output, json_ip, *outlen); - - free(json_ip); - cJSON_Delete(json_obj); - - return RET_OK; -} - -ret_code ip_config_format_json_array(int config_type, ip_config_t *config_buff, - int count, pointer output, int *outlen) -{ - ip_config_string_t tem_buff = {0}; - ip_config_string_t *ip_config = &tem_buff; - cJSON *json_array = NULL; - //cJSON *json_obj = NULL; - char *json_ip; - int i; - - json_array = cJSON_CreateArray(); - if(json_array == NULL) - { - return RET_NOMEM; - } - - for(i = 0; i < count; i++) - { - memset(ip_config, 0, sizeof(ip_config_string_t)); - - ip_config->config_type = config_type; - ip_config->family = AF_INET; - ip_config->prefixlen = config_buff[i].prefixlen; - strncpy(ip_config->ifname, config_buff[i].ifname, INTERFACE_NAMSIZ - 1); - strncpy(ip_config->ipaddr, inet_ntoa(config_buff[i].prefix), DOT_IP_STR - 1); - - /* create Student JSON object */ - s2j_create_json_obj(json_obj); - if(json_obj == NULL) - { - return RET_NOMEM; - } - - cJSON_AddItemToArray(json_array, json_obj); - - s2j_json_set_basic_element(json_obj, ip_config, int, config_type); - s2j_json_set_basic_element(json_obj, ip_config, string, ifname); - s2j_json_set_basic_element(json_obj, ip_config, int, family); - s2j_json_set_basic_element(json_obj, ip_config, string, ipaddr); - s2j_json_set_basic_element(json_obj, ip_config, int, prefixlen); - } - - json_ip = cJSON_PrintUnformatted(json_array); - *outlen = strlen(json_ip) + 1; - memcpy(output, json_ip, *outlen); - - free(json_ip); - cJSON_Delete(json_array); - - return RET_OK; -} - - -ret_code if_set_prefix(ip_config_t *ip_conf, int *code) -{ - ret_code ret; - struct ifreq ifreq = {0}; - struct sockaddr_in addr; - struct sockaddr_in mask; - - strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1); - addr.sin_addr = ip_conf->prefix; - addr.sin_family = ip_conf->family; - memcpy(&ifreq.ifr_addr, &addr, sizeof(struct sockaddr_in)); - - ret = if_ioctl(SIOCSIFADDR, (caddr_t)&ifreq, code); - ASSERT_RET(ret); - - if(ip_conf->prefix.s_addr != 0) - { - masklen2ip(ip_conf->prefixlen, &mask.sin_addr); - mask.sin_family = ip_conf->family; - memcpy(&ifreq.ifr_netmask, &mask, sizeof(struct sockaddr_in)); - - ret = if_ioctl(SIOCSIFNETMASK, (caddr_t)&ifreq, code); - ASSERT_RET(ret); - } - - - return 0; -} - -ret_code if_get_prefix_all(pointer output, int *output_len, int *code) -{ - struct ifreq ifreq[MAX_IF_NUM]; - struct sockaddr_in *addr; - struct ifreq netmask; - ip_config_t *ip_conf; - struct ifconf ifc; - int if_count = 0; - ret_code ret; - int mask_ret; - int i; - - memset(&ifc, 0, sizeof(struct ifconf)); - memset(&ifreq, 0, MAX_IF_NUM * sizeof(struct ifreq)); - - ifc.ifc_len = MAX_IF_NUM * sizeof(struct ifreq); - ifc.ifc_buf = (char *)ifreq; - - ret = if_ioctl(SIOCGIFCONF, (caddr_t)&ifc, code); - ASSERT_RET(ret); - - if_count = ifc.ifc_len / (sizeof(struct ifreq)); - - rpc_log_info("if num is %d\n", if_count); - - if((if_count * sizeof(ip_config_t) > CM_BUFF_SIZE) - || (if_count == 0)) - { - ret = RET_NOMEM; - ASSERT_RET(ret); - } - - ip_conf = rpc_new(ip_config_t, MAX_IF_NUM); - if(ip_conf == NULL) - { - return RET_NOMEM; - } - memset(ip_conf, 0, MAX_IF_NUM * sizeof(ip_config_t)); - - for(i = 0; i < if_count; i++) - { - rpc_log_info("get interface %s info\n", ifreq[i].ifr_name); - strncpy(ip_conf[i].ifname, ifreq[i].ifr_name, INTERFACE_NAMSIZ - 1); - ip_conf[i].family = AF_INET; - ip_conf[i].prefix = ((struct sockaddr_in *)&(ifreq[i].ifr_addr))->sin_addr; - - memset(&netmask, 0, sizeof(netmask)); - strncpy(netmask.ifr_name, ifreq[i].ifr_name, sizeof(netmask.ifr_name) - 1); - - ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&netmask, &mask_ret); - ASSERT_RET_NO(ret); - - addr = ( struct sockaddr_in * )&(netmask.ifr_netmask ); - ip_conf[i].prefixlen = ip_masklen(addr->sin_addr); - } - - ip_config_format_json_array(CM_CONFIG_GET, ip_conf, if_count, output, output_len); - - rpc_free(ip_conf); - return RET_OK; -} - -ret_code nat_get_prefix(ip_config_t *ip_conf, int *code) -{ - struct sockaddr_in *addr; - struct ifreq netmask; - struct ifreq ifreq; - ret_code ret = RET_OK; - int mask_ret; - int i; - - if(ip_conf->family != AF_INET) - { - ret = RET_INPUTERR; - } - - ASSERT_RET(ret); - - memset(&ifreq, 0, sizeof(struct ifreq)); - - rpc_log_info("get interface %s info\n", ip_conf->ifname); - - strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1); - - ret = if_ioctl(SIOCGIFADDR, (caddr_t)&ifreq, code); - ASSERT_RET(ret); - - - ip_conf->prefix = ((struct sockaddr_in *)&(ifreq.ifr_addr))->sin_addr; - - memset(&ifreq, 0, sizeof(ifreq)); - strncpy(ifreq.ifr_name, ip_conf->ifname, sizeof(ifreq.ifr_name) - 1); - - ret = if_ioctl(SIOCGIFNETMASK, (caddr_t)&ifreq, &mask_ret); - ASSERT_RET_NO(ret); - - addr = ( struct sockaddr_in * )&(ifreq.ifr_netmask); - ip_conf->prefixlen = ip_masklen(addr->sin_addr); - - return ret; -} - -ret_code nat_config_set_chk(uint source,uint config_type, - pointer input, int input_len, - pointer output, int *output_len) -{ - ret_code ret = RET_OK; - ip_config_t *ip_conf; - - ip_conf = (ip_config_t *)input; - - if(input_len < sizeof(ip_config_t) - || strlen(ip_conf->ifname) == 0) - { - ret = RET_INPUTERR; - } - - if (config_type != CM_CONFIG_DEL && ipv4_martian(&ip_conf->prefix)) - { - ret = RET_IPINVALID; - } - - - ASSERT_RET(ret); - - if(ip_conf->prefixlen == 0 || ip_conf->prefixlen > IPV4_MAX_PREFIXLEN) - { - ip_conf->prefixlen = IPV4_DEFAULT_PREFIXLEN; - } - - return RET_OK; -} - -ret_code nat_config_get_chk(uint source,uint config_type, - pointer input, int input_len, - pointer output, int *output_len) -{ - ret_code ret = RET_OK; - ip_config_t *ip_conf; - - ip_conf = (ip_config_t *)input; - - if(input_len < sizeof(ip_config_t) - || strlen(ip_conf->ifname) == 0 ) - { - ret = RET_INPUTERR; - } - - return ret; -} - -ret_code nat_config_getall_chk(uint source,uint config_type, - pointer input, int input_len, - pointer output, int *output_len) -{ - ret_code ret = RET_OK; - - if(*output_len < MAX_IF_NUM * sizeof(ip_config_t)) - { - ret = RET_INPUTERR; - } - - return ret; -} - - -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); - uint conf_type = CM_CONFIG_GET; - ip_config_t ip_config = {0}; - ret_code ret = RET_OK; - int code = 0; - - ip_config_json_parse(input, &conf_type, &ip_config); - - switch (conf_type) - { - case CM_CONFIG_SET: - case CM_CONFIG_DEL: - ret = ip_config_set_chk(source, conf_type, - &ip_config, config_len, - output, output_len); - break; - case CM_CONFIG_GET: - ret = ip_config_get_chk(source, conf_type, - &ip_config, config_len, - output, output_len); - break; - case CM_CONFIG_GET_ALL: - ret = ip_config_getall_chk(source, conf_type, - &ip_config, config_len, - output, output_len); - break; - default: - ret = RET_NOTSUPPORT; - } - - /* 灏嗕紶鍏ョ殑json鏁版嵁杞崲鎴愮粨鏋勪綋锛屼究浜庡悗缁鐞 */ - if(config_len <= CM_BUFF_SIZE) - { - memset(input, 0, *input_len); - memcpy(input, &ip_config, config_len); - *config_type = conf_type; - *input_len = config_len; - } - else - { - ret = RET_NOMEM; - } - - RET_ERR_FORMART(ret, code, output, *output_len); - - return ret; -} - -ret_code nat_config_proc(uint source, uint config_type, - pointer input, int input_len, - pointer output, int *output_len) -{ - uint conf_type = config_type; - ip_config_t conf_buff = {0}; - ip_config_t *ip_conf = &conf_buff; - ret_code ret = RET_OK; - int code; - - ip_conf = (ip_config_t *)input; - - if(conf_type == CM_CONFIG_DEL) - { - ip_conf->prefix.s_addr = 0; - ip_conf->prefixlen = IPV4_DEFAULT_PREFIXLEN; - } - - rpc_log_info("config type is %d, if %s ip %s prefixlen %d\n", - conf_type, ip_conf->ifname, - inet_ntoa(ip_conf->prefix), - ip_conf->prefixlen); - - ret = if_set_prefix(ip_conf, &code); - - RET_ERR_FORMART(ret, code, output, *output_len); - ASSERT_RET(ret); - - ip_save_file(ip_conf, conf_type); - - return RET_OK; -} - -ret_code nat_config_get(uint source, - pointer input, int input_len, - pointer output, int *output_len) -{ - ip_config_t *ip_conf; - ret_code ret = RET_OK; - int code, conf_type; - - ip_conf = (ip_config_t *)input; - - ret = if_get_prefix(ip_conf, &code); - - RET_ERR_FORMART(ret, code, output, *output_len); - ASSERT_RET(ret); - - ip_config_format_json(CM_CONFIG_GET, ip_conf, output, output_len); - - return ret; -} - -ret_code nat_config_get_all(uint source, pointer output, int *output_len) -{ - ret_code ret = RET_OK; - int code = 0; - - *output_len = 0; - ret = if_get_prefix_all(output, output_len, &code); - - rpc_log_info("ip_config_get_all: %s\n", output); - - RET_ERR_FORMART(ret, code, output, *output_len); - ASSERT_RET(ret); - - return RET_OK; - -} +#include "configm.h" +#include "rpc.h" +#include "parsefile.h" + + + +ret_code nat_config_chk(uint source,uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len) + +{ + return RET_OK; +} + +ret_code nat_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len) +{ + + + return RET_OK; +} + +ret_code nat_config_get(uint source, + pointer input, int input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + + return ret; +} + + +ret_code nat_config_get_all(uint source, pointer output, int *output_len) +{ + + return RET_OK; + +} +