diff --git a/Common/config_manager.h b/Common/config_manager.h index c07b5c42f..f4f8c02ae 100755 --- a/Common/config_manager.h +++ b/Common/config_manager.h @@ -32,6 +32,9 @@ /*nat config */ #define NAT_CONFIG_MODULE 0x00000008 +/*static routing*/ +#define STATIC_ROUTING_CONFIG_MODULE 0x00000009 + /************************* 模块定义结束 **********************/ /************************ config id定义 **********************/ @@ -69,8 +72,8 @@ #define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1) - - +#define STATIC_ROUTING_CONFIG (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|1) +#define GET_ALL_ROUTING_INFO (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|2) /************************ config id定义 end**********************/ #endif diff --git a/Common/klog_api.h b/Common/klog_api.h index 5292a31b9..8a078ae2a 100644 --- a/Common/klog_api.h +++ b/Common/klog_api.h @@ -7,7 +7,7 @@ #define MAX_MODULE_NAME_SZ 16 typedef struct _klog { - char module_name[MAX_MODULE_NAME_SZ]; + char module_name[MAX_MODULE_NAME_SZ+1]; }klog_t; diff --git a/Common/ulog_api.h b/Common/ulog_api.h index 1d199e2e6..fd2fbb90e 100755 --- a/Common/ulog_api.h +++ b/Common/ulog_api.h @@ -8,7 +8,7 @@ #define MAX_MODULE_NAME_SZ 16 typedef struct _ulog { - char module_name[MAX_MODULE_NAME_SZ]; + char module_name[MAX_MODULE_NAME_SZ+1]; } ulog_t; ulog_t *ulog_init(const char *module_name, u8 is_print); diff --git a/ControlPlatform/driver-layer/adaptation-layer/src/main/yang/device-status.yang b/ControlPlatform/driver-layer/adaptation-layer/src/main/yang/device-status.yang index 2ae2220d9..de55d4405 100644 --- a/ControlPlatform/driver-layer/adaptation-layer/src/main/yang/device-status.yang +++ b/ControlPlatform/driver-layer/adaptation-layer/src/main/yang/device-status.yang @@ -14,9 +14,14 @@ module device-status { grouping cpu-status { container cpu-infos { description "CPU的状态信息"; - leaf usage-rate { - type int16 { - range "0..100"; + list cpu-info { + leaf position { + type string ; + } + leaf usage-rate { + type int16 { + range "0..100"; + } } } } @@ -25,12 +30,17 @@ module device-status { grouping mem-status { container memory-infos { description "内存的状态信息"; - leaf memory-total { - type int64 ; - } - leaf usage-rate { - type int16 { - range "0..100"; + list memory-info { + leaf position { + type string ; + } + leaf memory-total { + type int64 ; + } + leaf usage-rate { + type int16 { + range "0..100"; + } } } } diff --git a/ControlPlatform/driver-layer/drivers/huawei/src/main/java/com/cmcc/cmhi/huawei/impl/HuaweiNetconfSpeaker.java b/ControlPlatform/driver-layer/drivers/huawei/src/main/java/com/cmcc/cmhi/huawei/impl/HuaweiNetconfSpeaker.java index 18735c1da..4bc1f9c9b 100644 --- a/ControlPlatform/driver-layer/drivers/huawei/src/main/java/com/cmcc/cmhi/huawei/impl/HuaweiNetconfSpeaker.java +++ b/ControlPlatform/driver-layer/drivers/huawei/src/main/java/com/cmcc/cmhi/huawei/impl/HuaweiNetconfSpeaker.java @@ -15,9 +15,8 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.opendaylight.controller.md.sal.binding.api.*; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.devm.rev181123.Devm; import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.devm.rev181123.devm.CpuInfos; import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.devm.rev181123.devm.MemoryInfos; @@ -30,10 +29,13 @@ import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.ifm.r import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.ifm.rev181123.ifm.interfaces._interface.ipv4config.am4cfgaddrs.Am4CfgAddr; import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.ifm.rev181123.ifm.interfaces._interface.ipv6config.am6cfgaddrs.Am6CfgAddr; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.NodeCpu; +import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.NodeCpuBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.NodeMemory; +import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.NodeMemoryBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfosBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfosBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.TpExt; +import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.TpExtBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.tp.status.TpInfos; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.tp.status.TpInfosBuilder; import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.tp.status.tp.infos.IpAddress; @@ -325,40 +327,47 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener ifcList = new ArrayList<>(); + List ifcList = new ArrayList<>(); if (cupInfos.isPresent()) { List cpuInfoList = cupInfos.get().getCpuInfo(); for (CpuInfo cpuInfo : cpuInfoList) { LOG.info("Show cpu with serial {},cpu usage is {} ", cpuInfo.getKey().getPosition(), cpuInfo.getSystemCpuUsage()); - CpuInfosBuilder builder = new CpuInfosBuilder(); - org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos temp = builder.setUsageRate(cpuInfo.getSystemCpuUsage().shortValue()).build(); + org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.cpu.infos.CpuInfo temp = + new org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.cpu.infos.CpuInfoBuilder().setPosition(cpuInfo.getKey().getPosition()) + .setUsageRate(cpuInfo.getSystemCpuUsage().shortValue()).build(); ifcList.add(temp); } } else { LOG.info("No data present on path '{}' for mountpoint: {}", iid, nodeId); } + CpuInfosBuilder cpuInfosBuilder = new CpuInfosBuilder().setCpuInfo(ifcList); //write cpu information to layer - InstanceIdentifier cpuIid = NETCONF_TOPO_IID + InstanceIdentifier cpuIid = NETCONF_TOPO_IID .child(Node.class, new NodeKey(new NodeId(nodeId))) - .augmentation(NodeCpu.class) - .child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos.class); - for (int i = 0; i < ifcList.size(); i++) { - final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.OPERATIONAL, cpuIid, ifcList.get(i)); - Futures.addCallback(writeTransaction.submit(), new FutureCallback() { - @Override - public void onFailure(Throwable throwable) { + .augmentation(NodeCpu.class); + final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.put(LogicalDatastoreType.OPERATIONAL, cpuIid, + new NodeCpuBuilder() + .setCpuInfos(cpuInfosBuilder.build()) + .build() + ); + Futures.addCallback(writeTransaction.submit(), new FutureCallback() { + @Override + public void onFailure(Throwable throwable) { + if (throwable instanceof OptimisticLockFailedException) { + LOG.warn("Write cpu information 捕获 乐观锁异常,本次获取忽略!"); + } else { LOG.error("Write cpu information failed." + throwable.getMessage()); } + } - @Override - public void onSuccess(Void avoid) { - LOG.info("Write cpu information success."); - } - }); - } + @Override + public void onSuccess(Void avoid) { + LOG.info("Write cpu information success."); + } + }); // Identifier path is equivalent to: // '.../yang-ext:mount/huawei-devm:devm/memoryInfos' @@ -372,98 +381,110 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener memoryList = new ArrayList<>(); + List memoryList = new ArrayList<>(); if (memoryInfosOptional.isPresent()) { List memoryInfoList = memoryInfosOptional.get().getMemoryInfo(); for (MemoryInfo memoryInfo : memoryInfoList) { - LOG.info("Show memory with serial {},cpu usage is {} ", + LOG.info("Show memory with serial {},memory usage is {} ", memoryInfo.getKey().getPosition(), memoryInfo.getDoMemoryUsage()); - MemoryInfosBuilder builder = new MemoryInfosBuilder(); LOG.info("Huawei Device {} OsMemoryTotal is: {}", nodeId, memoryInfo.getOsMemoryTotal()); - org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos temp = builder.setMemoryTotal(memoryInfo.getOsMemoryTotal()). - setUsageRate(memoryInfo.getOsMemoryUsage().shortValue()).build(); + org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.memory.infos.MemoryInfo temp = + new org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.memory.infos.MemoryInfoBuilder() + .setPosition(memoryInfo.getKey().getPosition()) + .setMemoryTotal(memoryInfo.getOsMemoryTotal()) + .setUsageRate(memoryInfo.getDoMemoryUsage().shortValue()) + .build(); memoryList.add(temp); - } } else { LOG.info("No data present on path '{}' for mountpoint: {}", iid, nodeId); } + MemoryInfosBuilder memoryInfosBuilder = new MemoryInfosBuilder().setMemoryInfo(memoryList); //write memory information to layer - InstanceIdentifier customMemoryIID = NETCONF_TOPO_IID + InstanceIdentifier customMemoryIID = NETCONF_TOPO_IID .child(Node.class, new NodeKey(new NodeId(nodeId))) - .augmentation(NodeMemory.class) - .child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos.class); - for (int i = 0; i < memoryList.size(); i++) { - final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.OPERATIONAL, customMemoryIID, memoryList.get(i)); - Futures.addCallback(writeTransaction.submit(), new FutureCallback() { - @Override - public void onFailure(Throwable throwable) { + .augmentation(NodeMemory.class); + final WriteTransaction writeTransaction2 = dataBroker.newWriteOnlyTransaction(); + writeTransaction2.put(LogicalDatastoreType.OPERATIONAL, customMemoryIID, + new NodeMemoryBuilder() + .setMemoryInfos(memoryInfosBuilder.build()) + .build() + ); + Futures.addCallback(writeTransaction2.submit(), new FutureCallback() { + @Override + public void onFailure(Throwable throwable) { + if (throwable instanceof OptimisticLockFailedException) { + LOG.warn("Write memory information 捕获 乐观锁异常,本次获取忽略!"); + } else { LOG.error("Write memory information failed." + throwable.getMessage()); } - - @Override - public void onSuccess(Void avoid) { - LOG.info("Write memory information success."); - } - }); - } - - InstanceIdentifier interfacesIID = - InstanceIdentifier.create(Ifm.class).child(Interfaces.class); - - Optional interfacesOptional; - try { - // Read from a transaction is asynchronous, but a simple - // get/checkedGet makes the call synchronous - interfacesOptional = hwNodeReadTx.read(LogicalDatastoreType.OPERATIONAL, interfacesIID).checkedGet(); - } catch (ReadFailedException e) { - throw new IllegalStateException("Unexpected error reading data from " + nodeId, e); - } - List tpInfosList = new ArrayList<>(); - if (interfacesOptional.isPresent()) { - List interfaceList = interfacesOptional.get().getInterface(); - for (Interface intf : interfaceList) { - LOG.info("Show memory with serial {},ipv4 config is {} ", - intf.getKey().getIfName(), intf.getIpv4Config()); - TpInfosBuilder tpInfosBuilder = new TpInfosBuilder(); - List ipsOnIntf = getiplist(intf); - tpInfosBuilder.setIpAddress(ipsOnIntf); - tpInfosBuilder.setMtu(intf.getIfMtu().shortValue()); - tpInfosBuilder.setTpName(intf.getIfName().getValue()); - tpInfosBuilder.setTpNumber(intf.getIfNumber()); - tpInfosBuilder.setTpAdminStatus(buildTpAdmin(intf.getIfAdminStatus())); - tpInfosBuilder.setTpPhyType(intf.getIfPhyType().getName()); - tpInfosList.add(tpInfosBuilder.build()); } - } else { - LOG.info("No data present on path '{}' for mountpoint: {}", - iid, nodeId); - } + @Override + public void onSuccess(Void avoid) { + LOG.info("Write memory information success."); + } + }); - //write interface information to layer - for (int i = 0; i < tpInfosList.size(); i++) { - InstanceIdentifier tpinfosIID = NETCONF_TOPO_IID - .child(Node.class, new NodeKey(new NodeId(nodeId))) - .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpInfosList.get(i).getTpName()))) - .augmentation(TpExt.class).child(TpInfos.class); - final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.OPERATIONAL, tpinfosIID, tpInfosList.get(i)); - Futures.addCallback(writeTransaction.submit(), new FutureCallback() { - @Override - public void onFailure(Throwable throwable) { - LOG.error("Write tp information information failed." + throwable.getMessage()); - } - - @Override - public void onSuccess(Void avoid) { - LOG.info("Write tp information information success."); - } - }); - } +// InstanceIdentifier interfacesIID = +// InstanceIdentifier.create(Ifm.class).child(Interfaces.class); +// +// Optional interfacesOptional; +// try { +// // Read from a transaction is asynchronous, but a simple +// // get/checkedGet makes the call synchronous +// interfacesOptional = hwNodeReadTx.read(LogicalDatastoreType.OPERATIONAL, interfacesIID).checkedGet(); +// } catch (ReadFailedException e) { +// throw new IllegalStateException("Unexpected error reading data from " + nodeId, e); +// } +// List tpInfosList = new ArrayList<>(); +// if (interfacesOptional.isPresent()) { +// List interfaceList = interfacesOptional.get().getInterface(); +// for (Interface intf : interfaceList) { +// LOG.info("Show memory with serial {},ipv4 config is {} ", +// intf.getKey().getIfName(), intf.getIpv4Config()); +// TpInfosBuilder tpInfosBuilder = new TpInfosBuilder(); +// List ipsOnIntf = getiplist(intf); +// tpInfosBuilder.setIpAddress(ipsOnIntf); +// tpInfosBuilder.setMtu(intf.getIfMtu().shortValue()); +// tpInfosBuilder.setTpName(intf.getIfName().getValue()); +// tpInfosBuilder.setTpNumber(intf.getIfNumber()); +// tpInfosBuilder.setTpAdminStatus(buildTpAdmin(intf.getIfAdminStatus())); +// tpInfosBuilder.setTpPhyType(intf.getIfPhyType().getName()); +// tpInfosList.add(tpInfosBuilder.build()); +// } +// } else { +// LOG.info("No data present on path '{}' for mountpoint: {}", +// iid, nodeId); +// } +// +// +// //write interface information to layer +// final WriteTransaction writeTransaction3 = dataBroker.newWriteOnlyTransaction(); +// for (int i = 0; i < tpInfosList.size(); i++) { +// InstanceIdentifier tpinfosIID = NETCONF_TOPO_IID +// .child(Node.class, new NodeKey(new NodeId(nodeId))) +// .child(TerminationPoint.class, new TerminationPointKey(new TpId(tpInfosList.get(i).getTpName()))) +// .augmentation(TpExt.class); +// writeTransaction3.put(LogicalDatastoreType.OPERATIONAL, tpinfosIID, +// new TpExtBuilder() +// .setTpInfos(tpInfosList.get(i)) +// .build() +// ); +// } +// Futures.addCallback(writeTransaction3.submit(), new FutureCallback() { +// @Override +// public void onFailure(Throwable throwable) { +// LOG.error("Write tp information information failed." + throwable.getMessage()); +// } +// +// @Override +// public void onSuccess(Void avoid) { +// LOG.info("Write tp information information success."); +// } +// }); } diff --git a/Makefile b/Makefile index 234e7fdc7..574c8548f 100755 --- a/Makefile +++ b/Makefile @@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l) endif endif -.PHONY : demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging +.PHONY : demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging ulog_test -all: demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging +all: demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging ulog_test ifeq ($(OPT), install) #$(shell `find ../release -name "*.zip" -delete`) @@ -228,4 +228,13 @@ else ifeq ($(OPT), install) $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f module.klog_api.test.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=test_klog_api else $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f module.klog_api.test.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=test_klog_api +endif + +ulog_test: +ifeq ($(OPT), clean) + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=test_ulog_api +else ifeq ($(OPT), install) + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile install MLOG=$(MLOG) MAKE_TARGET=test_ulog_api +else + $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=test_ulog_api endif \ No newline at end of file diff --git a/Platform/build/module.rpdb.Makefile b/Platform/build/module.rpdb.Makefile new file mode 100755 index 000000000..a11fcfa4e --- /dev/null +++ b/Platform/build/module.rpdb.Makefile @@ -0,0 +1,50 @@ +# target name, the target name must have the same name of c source file +TARGET_NAME=rpdb + +# target +# for linux module driver: KO +# for application: EXE +# for dynamic library: DLL +TARGET_TYPE = KO + +# target object +# for application: APP +# for device driver: DRV +TARGET_OBJ = DRV + +# custom install dir +TARGET_BOX = + +#debug mode or release mode +DEBUG = TRUE + +PLAT_LINUX ?= TRUE +PLAT_ARM64 ?= TRUE + +VPATH = ../modules + +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = ./rpdb/dpi_trie_cache.c + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := +PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) + +# this line must be at below of thus, because of... +include ../../Common/common.Makefile + +ifeq ($(MAKECMDGOALS), ) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +else +ifeq ($(MAKECMDGOALS), all) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +endif +endif + diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index cea8c2a28..9536bcef2 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -1,3 +1,4 @@ + # target name, the target name must have the same name of c source file TARGET_NAME=configm @@ -39,6 +40,10 @@ COMMON_SRCS = configserver.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 \ vlan_config/vlan_config.c \ + dhcp_config/dhcp_client_config.c dhcp_config/dhcp_dhcpd_lease.c dhcp_config/dhcp_host_config.c dhcp_config/dhcp_lib.c dhcp_config/dhcp_relay_config.c dhcp_config/dhcp_shared_network_config.c dhcp_config/dhcp_subnet_config.c\ + static_routing_config/static_routing_config.c \ + + # MRS Board Source Files PLAT_LINUX_SRCS = $(COMMON_SRCS) diff --git a/Platform/build/user.rpdb.Makefile b/Platform/build/user.rpdb.Makefile new file mode 100644 index 000000000..ccbbc55e2 --- /dev/null +++ b/Platform/build/user.rpdb.Makefile @@ -0,0 +1,67 @@ +# target name, the target name must have the same name of c source file +TARGET_NAME=librpdb + +# target +# for linux module driver: KO +# for application: EXE +# for dynamic library: DLL +TARGET_TYPE = DLL + +# 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/rpdb/ + +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = rpdb.c + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpdb +PLAT_LINUX_CFLAGS := -fPIC -I../../Common -I../common/rpdb + + +PLAT_ARM64_LDFLAGS := -fPIC -shared +PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS) + + +#gcc libs +ARM64_LIBS := +LINUX_LIBS := + +# 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/build/user.ulog.ulog-test.Makefile b/Platform/build/user.ulog.ulog-test.Makefile new file mode 100644 index 000000000..4986b5f72 --- /dev/null +++ b/Platform/build/user.ulog.ulog-test.Makefile @@ -0,0 +1,66 @@ +# target name, the target name must have the same name of c source file +TARGET_NAME=test_ulog_api + +# 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/ulog/ulog-test + +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = ulog_test.c + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/ulog -I../user/ulog +PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) + + +PLAT_ARM64_LDFLAGS := +PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS) + +#gcc libs +ARM64_LIBS := -lopenrpc-arm64 -lulogapi-arm64 -lpthread -lm -lev +LINUX_LIBS := -lopenrpc-linux -lulogapi-linux -lpthread -lm -lev + +# 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/modules/klog_api/api/klog_api.c b/Platform/modules/klog_api/api/klog_api.c index 3e6237056..a25a9d763 100644 --- a/Platform/modules/klog_api/api/klog_api.c +++ b/Platform/modules/klog_api/api/klog_api.c @@ -18,8 +18,8 @@ klog_t *klog_init(const char *module_name) len = strlen(module_name); - if (len >= MAX_MODULE_NAME_SZ) { - printk(KERN_ERR"The length:%d of module_name must be less than %d, but input module_name is %s", len, MAX_MODULE_NAME_SZ, module_name); + if (len > MAX_MODULE_NAME_SZ) { + printk(KERN_ERR"The length:%d of module_name must be not more than %d, but input module_name is %s", len, MAX_MODULE_NAME_SZ, module_name); return NULL; } @@ -28,7 +28,7 @@ klog_t *klog_init(const char *module_name) printk(KERN_ERR"Allocating log memory is failure"); return NULL; } - memset(log->module_name, '\0', MAX_MODULE_NAME_SZ); + memset(log->module_name, '\0', MAX_MODULE_NAME_SZ+1); strncpy(log->module_name, module_name, len); return log; diff --git a/Platform/modules/rpdb/dpi_trie_cache.c b/Platform/modules/rpdb/dpi_trie_cache.c new file mode 100644 index 000000000..643d61131 --- /dev/null +++ b/Platform/modules/rpdb/dpi_trie_cache.c @@ -0,0 +1,296 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + * 三元组超时时间设置为120s + */ +int dpi_cache_node_timeout = 120; + +/* + * 三元组数据结构 +*/ +struct dpi_cache_node { + struct list_head list; + + union { + struct in6_addr ip6; + struct in_addr ip4; + + }ip; + + __u16 proto; + __u16 port; + __u32 appid; + uint64_t uptime; +}; + + +/* + * 初始化cache链表 + */ +#define TRIPLE_CAHCE_HASH_SIZE (2048) +struct list_head dpi_cache_head[TRIPLE_CAHCE_HASH_SIZE] = {0}; + +typedef struct pkt_info{ + unsigned int srcip; + unsigned short sport; + unsigned int dstip; + unsigned short dport; + unsigned short proto; +}pkt_info_t; + +#define POLY 0x01101 // CRC20生成多项式x^20+x^12+x^8+1即:01101 CRC32:04C11DB7L +static unsigned int crc_table[256] = {0}; + +unsigned int get_sum_poly(unsigned char data) +{ + unsigned int sum_poly = data; + int j; + sum_poly <<= 24; + for(j = 0; j < 8; j++) + { + int hi = sum_poly&0x80000000; // 取得reg的最高位 + sum_poly <<= 1; + if(hi) sum_poly = sum_poly^POLY; + } + return sum_poly; +} + +void create_crc_table(void) //在使用CRC20_key函数应该先建立crc表 +{ + int i; + for(i = 0; i < 256; i++) + { + crc_table[i] = get_sum_poly(i&0xFF); + } +} + +unsigned int CRC20_key(unsigned char* data, int len) +{ + int i; + unsigned int reg = 0xFFFFFFFF;// 0xFFFFFFFF,见后面解释 + for(i = 0; i < len; i++) + { + reg = (reg<<8) ^ crc_table[((reg>>24)&0xFF) ^ data[i]]; + } + return (reg&0XFFFFF);//得到的reg取后20作为key值 +} + +/* + * 初始化dpi三元组hash链表 + */ +void dpi_cache_list_init(void) +{ + int i = 0; + for (i = 0; i < TRIPLE_CAHCE_HASH_SIZE; i++){ + INIT_LIST_HEAD(&dpi_cache_head[i]); + } + + return; +} + + +/* + * 三元组hash值计算 + */ +int dpi_cache_node_hash(struct dpi_cache_node node) +{ + int i = 0; + int dip = 0; + + pkt_info_t info; + info.dport = node.port; + info.sport = 0; + info.srcip = 0; + info.proto = node.proto; + if (node.ip.ip4.s_addr !=0 ) { + info.dstip = node.ip.ip4.s_addr; + } else { + for (i = 0; i < 4; ++i) { + dip ^= node.ip.ip6.s6_addr32[i]; + } + info.dstip = dip; + } + + return CRC20_key((unsigned char *)&info, sizeof(pkt_info_t))&(TRIPLE_CAHCE_HASH_SIZE - 1); +} + + +/* + * src 和dst比较,并更新dst的appid,update_appid=true,update +*/ +bool dpi_cache_node_compare(struct dpi_cache_node src,struct dpi_cache_node dst,bool update_appid) +{ + int i = 0; + if (src.port != dst.port){ + return false; + } + + if (src.proto != dst.proto){ + return false; + } + + if(src.ip.ip4.s_addr != 0){ + if(src.ip.ip4.s_addr != dst.ip.ip4.s_addr){ + return false; + } + }else{ + for (i = 0; i < 4; i++){ + if (src.ip.ip6.s6_addr32[i] != dst.ip.ip6.s6_addr32[i]){ + return false; + } + } + + } + + if (update_appid){ + dst.appid = src.appid; + dst.uptime = get_jiffies_64(); + } + + return true; +} + + +/* + *遍历hash链表,查找node + */ +bool dpi_cache_node_search(struct dpi_cache_node node,int flag) +{ + struct list_head * pList; + struct dpi_cache_node *pNode; + int hash = dpi_cache_node_hash(node); + list_for_each(pList,&dpi_cache_head[hash]){ + pNode = list_entry(pList,struct dpi_cache_node,list); + if (dpi_cache_node_compare(node,*pNode,flag)){ + return true; + } + } + + return false; +} + + +/* + * DPI 信息记录,外部接口调用 +*/ +bool dpi_cache_node_add(struct dpi_cache_node node) +{ + int hash = 0; + struct dpi_cache_node *pNode =NULL; + + if (dpi_cache_node_search(node,true)) { + return true; + } + + pNode = kmalloc(sizeof(struct dpi_cache_node), GFP_KERNEL); + if (NULL == pNode) { + return false; + } + + hash = dpi_cache_node_hash(node); + pNode->uptime = get_jiffies_64(); + pNode->appid = node.appid; + list_add_tail(&pNode->list,&dpi_cache_head[hash]); + return true; +} + + +/* + * 释放hash链表上所有node节点 +*/ +void dpi_cache_list_release(void) +{ + struct list_head * pList = NULL; + struct dpi_cache_node *pNode = NULL; + int i = 0; + + for (i = 0; i < TRIPLE_CAHCE_HASH_SIZE; i++){ + list_for_each(pList,&dpi_cache_head[i]){ + pNode = list_entry(pList,struct dpi_cache_node,list); + if(pNode){ + list_del(&pNode->list); + } + + } + } +} + + +/* + *定时器超时,删除超时的节点 + */ +void dpi_cache_node_timeout_func(void) +{ + struct list_head * pList = NULL; + struct dpi_cache_node *pNode = NULL; + int i = 0; + + for (i = 0; i < TRIPLE_CAHCE_HASH_SIZE; i++){ + list_for_each(pList,&dpi_cache_head[i]){ + pNode = list_entry(pList,struct dpi_cache_node,list); + if(pNode&& + (get_jiffies_64() - pNode->uptime >= dpi_cache_node_timeout)){ + list_del(&pNode->list); + } + + + } + } +} + +/* + * 定时器操作 + */ +struct timer_list gTimer; + +void dpi_cache_timer_handler(unsigned long data) { + printk(KERN_INFO"timer pending:%d\n", timer_pending(&gTimer)); + dpi_cache_node_timeout_func(); + mod_timer(&gTimer, jiffies+msecs_to_jiffies(dpi_cache_node_timeout*1000)); + +} + +int dpi_cache_timer_init(void) { + printk(KERN_INFO"%s jiffies:%ld\n", __func__, jiffies); + printk(KERN_INFO"ji:%d,HZ:%d\n", jiffies_to_msecs(250), HZ); + init_timer(&gTimer); + gTimer.expires = jiffies + dpi_cache_node_timeout*HZ; + gTimer.function = dpi_cache_timer_handler; + add_timer(&gTimer); + printk(KERN_INFO"timer pending:%d\n", timer_pending(&gTimer)); + return 0; +} + +void dpi_cache_timer_exit(void) { + printk(KERN_INFO"%s jiffies:%ld\n", __func__, jiffies); + del_timer(&gTimer); +} + +int dpi_cahce_module_init(void) +{ + dpi_cache_timer_init(); + dpi_cache_list_init(); + return 1; +} + +int dpi_cache_module_exit(void) +{ + dpi_cache_timer_exit(); + dpi_cache_list_release(); + return 1; +} + +module_init(dpi_cahce_module_init); +module_exit(dpi_cache_timer_exit); +MODULE_LICENSE("GPL"); + + diff --git a/Platform/user/configm/config-server/dhcp_config/dhcp_lib.c b/Platform/user/configm/config-server/dhcp_config/dhcp_lib.c index c25d43113..dc61a9c5b 100644 --- a/Platform/user/configm/config-server/dhcp_config/dhcp_lib.c +++ b/Platform/user/configm/config-server/dhcp_config/dhcp_lib.c @@ -1,5 +1,46 @@ #include "dhcp_lib.h" +void dhcp_config_init(void) +{ + ret_code ret = RET_OK; + ret = br_event_register(BR_DELETE_EVENT_PRE,del_interface_dhcp_cb); +} + +int del_interface_dhcp_cb(BR_EVENT_TYPE event_type, br_event_t event_arg) +{ + ret_code ret = RET_OK; + char *segment = get_interface_subnet(event_arg.br_name); + if(NULL == segment){ + return ret; + } + char *mask = get_interface_mask(event_arg.br_name); + if(NULL == mask){ + return ret; + } + int len = 500; + char *cmd = (char *)malloc(len + 1); + if(NULL == cmd) + { + return RET_ERR; + } + + memset(cmd, 0, len + 1); + snprintf(cmd, len, "sed -r -i 's/%s //g' /etc/default/isc-dhcp-server", event_arg.br_name); + system(cmd); + memset(cmd, 0, len + 1); + snprintf(cmd, len, "sed -r -i ':a;N;$!ba;s/[ \\t]*subnet[ \\t]+%s[ \\t]+netmask[ \\t]+%s[ \\t]*\\{[a-zA-Z#:; \\t\\n0-9\\.\\,\\-]+\\}/#/g' /etc/dhcp/dhcpd.conf", segment, mask); + system(cmd); + system("sed -r -i '/#/d' /etc/dhcp/dhcpd.conf"); + if(segment){ + free(segment); + } + if(mask){ + free(mask); + } + /*ļ*/ + system("service isc-dhcp-server restart"); + return ret; +} char *getfileall(char *fname) { diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index e6c97eac7..0a68990d5 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -14,6 +14,9 @@ #include "../web_config/auth_recover_config.h" #include "natconfig.h" #include "vlan_config.h" +#include "dhcp_lib.h" +#include "static_routing.h" + #define RET_CODE_LEN 16 #define RET_MSG_LEN 128 @@ -31,7 +34,11 @@ { \ VLAN_CONFIG_MODULE, \ vlan_config_init \ - } \ + }, \ + { \ + DHCP_CONFIG_MODULE, \ + dhcp_config_init \ + } \ } /* @@ -217,6 +224,78 @@ vlan_config_proc, \ vlan_config_get, \ vlan_config_get_all \ + },\ + {\ + DHCP_HOST_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_host_config_chk, \ + dhcp_host_config_proc, \ + dhcp_host_config_get, \ + NULL \ + },\ + {\ + DHCP_SUBNET_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_subnet_config_chk, \ + dhcp_subnet_config_proc, \ + dhcp_subnet_config_get, \ + NULL \ + },\ + {\ + DHCP_RELAY_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_relay_config_chk, \ + dhcp_relay_config_proc, \ + NULL, \ + NULL \ + },\ + {\ + DHCP_CLIENT_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_client_config_chk, \ + dhcp_client_config_proc, \ + dhcp_client_get, \ + NULL \ + },\ + {\ + DHCP_DHCPD_LEASE, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_dhcpd_lease_config_chk, \ + NULL, \ + NULL, \ + dhcp_dhcpd_lease_get_all \ + },\ + {\ + DHCP_SHARED_NETWORK_CONFIG, \ + CONFIG_FROM_WEB, \ + FALSE, \ + dhcp_shared_network_config_chk, \ + dhcp_shared_network_config_proc, \ + NULL, \ + dhcp_shared_network_config_get_all \ + },\ + {\ + STATIC_ROUTING_CONFIG, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + TRUE, \ + routing_config_chk, \ + routing_config_proc, \ + NULL, \ + routing_config_get_all \ + },\ + {\ + GET_ALL_ROUTING_INFO, \ + CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \ + FALSE, \ + all_routing_config_chk, \ + NULL, \ + NULL, \ + all_routing_get_all \ }\ } @@ -270,3 +349,4 @@ int cm_format_data(ret_code ret_code, cJSON *json_obj, char *output); #endif /* RPC_COMMON_H_ */ + diff --git a/Platform/user/configm/config-server/include/dhcp_lib.h b/Platform/user/configm/config-server/include/dhcp_lib.h index 8ee1c12a9..0901c6e53 100644 --- a/Platform/user/configm/config-server/include/dhcp_lib.h +++ b/Platform/user/configm/config-server/include/dhcp_lib.h @@ -20,6 +20,19 @@ #include "rpc.h" #include "netconfig.h" +#include "dhcp_client_config.h" +#include "dhcp_host_config.h" +#include "dhcp_relay_config.h" +#include "dhcp_shared_network_config.h" +#include "dhcp_subnet_config.h" +#include "dhcp_dhcpd_lease.h" + + +void dhcp_config_init(void); + +int del_interface_dhcp_cb(BR_EVENT_TYPE event_type, br_event_t event_arg); + + char *getfileall(char *fname); char *getfilefirstline(char *fname); diff --git a/Platform/user/configm/config-server/include/static_routing.h b/Platform/user/configm/config-server/include/static_routing.h new file mode 100644 index 000000000..8c19a4d2d --- /dev/null +++ b/Platform/user/configm/config-server/include/static_routing.h @@ -0,0 +1,73 @@ +#ifndef STATIC_ROUTING_H_ +#define STATIC_ROUTING_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define IP_MAX_LENGTH 128 +#define INTERFACE_MAX_LENGTH 20 +#define LINE_MAX_LENGTH 128 +#define ROUTING_TABLE_MAX_NUMBER 100 + +#define STRING_LENGTH 128 +#define IPV4_GET_STATIC_ROUTING "route -n" +#define IPV6_GET_STATIC_ROUTING "route -6" +#define IPV4_VERSION 4 +#define IPV6_VERSION 6 +#define ACTION_LENGTH 10 + +#define STATIC_ROUTING_PATH "/etc/network/static_routing" + + +struct routing_string{ + int version; + char destip[IP_MAX_LENGTH]; + int netmask; + char gateway[IP_MAX_LENGTH]; + char dev[INTERFACE_MAX_LENGTH]; + int metric; +}; + + + +typedef struct routing_string routing_t; + + + +/*static routing config */ +ret_code routing_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + +ret_code routing_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + + +ret_code routing_config_get_all(uint source, + pointer output, int *output_len); + + +/*ȡ·Ϣ*/ + +ret_code all_routing_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); + +ret_code all_routing_get_all(uint source, + pointer output, int *output_len); + + + + + +#endif diff --git a/Platform/user/configm/config-server/log_config/log_config_cm.c b/Platform/user/configm/config-server/log_config/log_config_cm.c index cad81f0d1..e0ba16b95 100755 --- a/Platform/user/configm/config-server/log_config/log_config_cm.c +++ b/Platform/user/configm/config-server/log_config/log_config_cm.c @@ -24,7 +24,7 @@ ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int } -/* ԡkey=valueʽýlog-sched.confĽ */ +/* 仅适用于以“key=value”方式保存的配置解析,适用于log-sched.conf的解析 */ ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str, char *value_str, int value_len) { ret_code ret = RET_ERR; @@ -57,10 +57,10 @@ ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str pos = strstr(line, key_str); if (pos != NULL) { - /* keyvalue"=" */ + /* 跳过key与value间的"=" */ strcpy(value_str, pos+strlen(key_str)+1); - /* ˳βĻس */ + /* 滤除掉段尾的回车换行 */ if ('\n' == value_str[strlen(value_str)-1]) { value_str[strlen(value_str)-1] = '\0'; @@ -80,7 +80,7 @@ ret_code cm_log_get_keyvalue_from_file(const char *file_str, const char *key_str } -/* ļڣ1򣬱0 */ +/* 检查的文件存在,本函数返回1,否则,本函数返回0 */ int cm_log_check_file_is_exist(const char *file_str) { int is_exist = 0; @@ -91,7 +91,7 @@ int cm_log_check_file_is_exist(const char *file_str) } else { - /* ļڣaccess0ڣaccess-1 */ + /* 如果文件存在,access返回0,不存在,access返回-1 */ is_exist = ((access(file_str, 0) == 0) ? 1 : 0); } @@ -99,7 +99,7 @@ int cm_log_check_file_is_exist(const char *file_str) } -/* log-console.conflog-pty.confĽ */ +/* 适用于log-console.conf与log-pty.conf的解析 */ ret_code cm_log_get_module_from_file(const char *file_str, char *value_str, int value_len) { ret_code ret = RET_ERR; @@ -154,7 +154,7 @@ ret_code cm_log_get_module_from_file(const char *file_str, char *value_str, int return ret; } -/* log-console.conflog-pty.confĽ */ +/* 适用于log-console.conf与log-pty.conf的解析 */ ret_code cm_log_get_level_from_file(const char *file_str, u8 *value) { ret_code ret = RET_ERR; diff --git a/Platform/user/configm/config-server/log_config/log_config_file.c b/Platform/user/configm/config-server/log_config/log_config_file.c index 15d05c630..0d297c68e 100755 --- a/Platform/user/configm/config-server/log_config/log_config_file.c +++ b/Platform/user/configm/config-server/log_config/log_config_file.c @@ -38,9 +38,9 @@ static ret_code cm_get_log_file_elems(log_file_t *log_file_conf, int *err_no) memset(log_file_conf, 0, sizeof(*log_file_conf)); - /* levelpathis_compressdel_over_daysδʵ */ + /* level、path、is_compress、del_over_days暂未实现 */ - /* ־ļСޣdel_over_size */ + /* 日志文件大小上限:del_over_size */ memset(value, 0, MAX_LINE_SZ); if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_LOGFILE_FILE, LOG_CONF_KEY_FILE_MAX_SIZE_STR, value, sizeof(value)) == 0) { diff --git a/Platform/user/configm/config-server/log_config/log_config_remote.c b/Platform/user/configm/config-server/log_config/log_config_remote.c index 6ca945a44..55c758cdd 100755 --- a/Platform/user/configm/config-server/log_config/log_config_remote.c +++ b/Platform/user/configm/config-server/log_config/log_config_remote.c @@ -166,7 +166,7 @@ static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_hos memset(tmp_str, 0, sizeof(tmp_str)); - /* ȡ־ȼ */ + /* 提取日志等级 */ while (1) { pos2 = strstr(pos, ".="); @@ -202,7 +202,7 @@ static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_hos } ret_host->level = (u8)tmp_value; - /* ȡIPַ */ + /* 提取IP地址 */ pos = strstr(pos2, "@"); if (NULL == pos) { @@ -230,7 +230,7 @@ static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_hos strncpy(ret_host->host, pos, tmp_len); - /* ȡ˿ */ + /* 提取端口 */ pos2 ++; pos = pos2; pos2 = strstr(pos, ":"); @@ -250,7 +250,7 @@ static ret_code cm_log_prase_host_from_str(char *const input_str, log_remote_hos } ret_host->port = (u16)tmp_value; - /* ȡ־Ÿʽ */ + /* 提取日志存放格式 */ pos2++; pos = pos2; @@ -415,7 +415,7 @@ static ret_code cm_log_getall_host_from_file(const char *file_str, log_remote_ho if (hosts[cnt].host[0] == '\0') { - /* Ч */ + /* 无效数据 */ memset(hosts+cnt, 0, sizeof(log_remote_host_x_t)); continue; } diff --git a/Platform/user/configm/config-server/static_routing_config/static_routing b/Platform/user/configm/config-server/static_routing_config/static_routing new file mode 100644 index 000000000..e69de29bb diff --git a/Platform/user/configm/config-server/static_routing_config/static_routing_config.c b/Platform/user/configm/config-server/static_routing_config/static_routing_config.c new file mode 100644 index 000000000..00a3cfe6d --- /dev/null +++ b/Platform/user/configm/config-server/static_routing_config/static_routing_config.c @@ -0,0 +1,1393 @@ +#include "configm.h" +#include "rpc.h" +#include "parsefile.h" +#include "static_routing.h" +#include "ipconfig.h" + +/*ṹתΪjson + +{ + "total number": 2, + "route": [{ + "version": 4, + "destip": " 192.168.5.0", + "netmask": 24, + "gateway": "192.168.121.2", + "dev": "ens33", + "metric": 100 + }, { + "version": 4, + "destip": " 192.168.5.10", + "netmask": 32, + "gateway": "192.168.121.2", + "metric": 1000 + }] +} +*/ +ret_code routing_to_json(int count, routing_t *buff_total, pointer output, int *output_len) +{ + + ret_code ret = RET_OK; + char *json_routing; + int i; + + cJSON *ret_root = cJSON_CreateObject(); + if(ret_root == NULL) + { + cJSON_Delete(ret_root); + return RET_NOMEM; + } + + cJSON_AddNumberToObject(ret_root,"total number",count); + + cJSON *json_array = cJSON_CreateArray(); + + if(json_array == NULL) + { + cJSON_Delete(json_array); + return RET_NOMEM; + } + if(count > 0) + { + for(i = 0; i < count; i++) + { + cJSON *json_obj = cJSON_CreateObject(); + if (NULL == json_obj) + { + continue; + } + + cJSON_AddNumberToObject(json_obj,"version",buff_total[i].version); + cJSON_AddStringToObject(json_obj,"destip", buff_total[i].destip); + cJSON_AddNumberToObject(json_obj,"netmask",buff_total[i].netmask); + if(strcmp(buff_total[i].gateway,"") !=0) + { + cJSON_AddStringToObject(json_obj,"gateway", buff_total[i].gateway); + } + + if(strcmp(buff_total[i].dev,"") !=0) + { + cJSON_AddStringToObject(json_obj,"dev", buff_total[i].dev); + } + cJSON_AddNumberToObject(json_obj,"metric",buff_total[i].metric); + + cJSON_AddItemToArray(json_array, json_obj); + rpc_log_info("json_obj: %s\n",cJSON_Print(json_obj)); + + } + + cJSON_AddItemToObject(ret_root,"route",json_array); + } + rpc_log_info("check: %s\n",cJSON_Print(ret_root)); + + json_routing = cJSON_PrintUnformatted(ret_root); + *output_len = strlen(json_routing) + 1; + memcpy(output, json_routing, *output_len); + + free(json_routing); + cJSON_Delete(ret_root); + + return ret; +} + +/*jsonṹ*/ +ret_code routing_json_parse(pointer input, uint *conf_type, routing_t *conf_buff) +{ + cJSON *json_obj, *operate, *route, *version, *destip, *netmask, *gateway, *dev, *metric; + + json_obj = cJSON_Parse(input); + + if(NULL == json_obj) + { + rpc_log_info("json obj is NULL \n"); + cJSON_Delete(json_obj); + return RET_INPUTERR; + } + + rpc_log_info("json input:\n %s \n", cJSON_Print(json_obj)); + + operate = cJSON_GetObjectItem(json_obj,"operate"); + + if(NULL == operate) + { + cJSON_Delete(json_obj); + return RET_INPUTERR; + } + +/*operateֵconf_typeֵ*/ + if(strcmp(operate->valuestring,"add") == 0) + { + *conf_type = CM_CONFIG_ADD; + } + else if (strcmp(operate->valuestring,"del") == 0) + { + *conf_type = CM_CONFIG_DEL; + } + else if (strcmp(operate->valuestring,"getall") == 0) + { + *conf_type = CM_CONFIG_GET_ALL; + return RET_OK; + } + else + { + return RET_INPUTERR; + } + + route = cJSON_GetObjectItem(json_obj,"route"); + + if(NULL == route) + { + cJSON_Delete(json_obj); + return RET_INPUTERR; + } + + version = cJSON_GetObjectItem(route,"version"); + if(!version) + { + return RET_INPUTERR; + } + else + { + conf_buff->version = version->valueint; + } + + rpc_log_info("version:%d \n", conf_buff->version); + + destip = cJSON_GetObjectItem(route,"destip"); + if(!destip) + { + return RET_INPUTERR; + } + else + { + strcpy(conf_buff->destip,destip->valuestring); + } + rpc_log_info("destip:%s \n", conf_buff->destip); + + netmask = cJSON_GetObjectItem(route,"netmask"); + if(!netmask) + { + return RET_INPUTERR; + } + else + { + conf_buff->netmask = netmask->valueint; + } + rpc_log_info("netmask:%d \n", conf_buff->netmask); + + gateway = cJSON_GetObjectItem(route,"gateway"); + if(!gateway) + { + //memset(conf_buff->gateway,'\0',sizeof(conf_buff->gateway)); + strcpy(conf_buff->gateway,""); + } + else + { + strcpy(conf_buff->gateway,gateway->valuestring); + } + rpc_log_info("gateway:%s \n", conf_buff->gateway); + + dev = cJSON_GetObjectItem(route,"dev"); + if(!dev) + { + strcpy(conf_buff->dev,""); + } + else + { + strcpy(conf_buff->dev,dev->valuestring); + } + rpc_log_info("dev: %s \n", conf_buff->dev); + + metric = cJSON_GetObjectItem(route,"metric"); + if(!metric) + { + return RET_INPUTERR; + } + else + { + conf_buff->metric = metric->valueint; + } + rpc_log_info("metric:%d \n", conf_buff->metric); + + cJSON_Delete(json_obj); + + return RET_OK; + +} + + + +/*ļ*/ +ret_code insert_into_file(char *string) +{ + FILE *f; + ret_code ret = RET_OK; + char *temp_buff[LINE_MAX_LENGTH]; + int flag = 0; + + rpc_log_info("string: %s\n",string); + + f = fopen (STATIC_ROUTING_PATH,"at+"); + if(NULL == f) + { + rpc_log_error("open config file fail\n"); + return RET_SYSERR; + } + + fseek(f,0,SEEK_SET); + while(fgets(temp_buff,sizeof(temp_buff),f) != NULL) + { + if (strstr(temp_buff,string) != NULL) + { + flag = 1; + rpc_log_info("config info exist \n"); + } + + if(fgetc(f) == EOF) + { + break; + } + + memset(temp_buff,0,sizeof(temp_buff)); + fseek(f,-1,SEEK_CUR); + } + + if(!flag) + { + fputs(string,f); + } + rpc_log_info("flag: %d\n",flag); + fclose(f); + + return ret; +} + +/*ļɾ*/ +ret_code delete_from_file(char *string) +{ + FILE *f; + ret_code ret = RET_ERR; + int length; + char buff_line[LINE_MAX_LENGTH]; + int flag =0; + + f = fopen (STATIC_ROUTING_PATH,"r+"); + if(NULL == f) + { + rpc_log_error("open config file fail\n"); + return RET_SYSERR; + } + + fseek(f,0,SEEK_END); + length = ftell(f); + + char buff[length]; + + memset(buff,0,sizeof(buff)); + memset(buff_line,0,sizeof(buff_line)); + + fseek(f,0,SEEK_SET); + + while (fgets(buff_line, sizeof(buff_line), f) != NULL) + { + rpc_log_info("check buff_line:%s\n", buff_line); + + if (strstr(buff_line, string) != NULL) + { + flag = 1; + rpc_log_info("config info match \n"); + } + else + { + strcat(buff, buff_line); + } + + if(fgetc(f) == EOF) + { + break; + } + + fseek(f,-1,SEEK_CUR); + memset(buff_line, 0, sizeof(buff_line)); + } + + fclose(f); + + rpc_log_info("flag:%d \n", flag); + + if (flag) + { + ret = conf_file_write (STATIC_ROUTING_PATH, buff); + rpc_log_info("rewrite config file \n"); + } + + return ret; +} + +/*·*/ +ret_code add_routing_exe (char *string) +{ + int status; + ret_code ret = RET_OK; + + rpc_log_info("string:%s\n",string); + + if(NULL == string) + { + return RET_INPUTERR; + } + + status = system(string); + if (-1 == status) + { + rpc_log_error("system shell error!\n"); + return RET_SYSERR; + } + else { + if (WIFEXITED(status)){ + if (0 == WEXITSTATUS(status)){ + rpc_log_info("run shell successfully!\n"); + ret = insert_into_file(string); + } + else{ + rpc_log_error("run shell script fail,script exit code:%d\n",WEXITSTATUS(status)); + return RET_SYSERR; + } + } + else { + rpc_log_error("exit status = [%d]\n",WEXITSTATUS(status)); + return RET_SYSERR; + } + } + + return ret; +} + +/*ɾ·*/ +ret_code del_routing_exe (char *string, char *string_del) +{ + int status; + ret_code ret = RET_OK; + + if(NULL == string || NULL == string_del) + { + return RET_INPUTERR; + } + + status = system(string); + if (-1 == status) + { + rpc_log_error("system shell error!\n"); + return RET_SYSERR; + } + else { + if (WIFEXITED(status)){ + if (0 == WEXITSTATUS(status)){ + rpc_log_info("run shell successfully!\n"); + delete_from_file(string_del); + /*ret = delete_from_file(string_del); //ҪǷɾûȥ·ɣûбļеģϵǷ񷵻ret + if(ret != RET_OK) + { + system(string_del); + }*/ + } + else{ + rpc_log_error("run shell script fail,script exit code:%d\n",WEXITSTATUS(status)); + ret = delete_from_file(string_del); /*ǽӿdown£·ûˣļл*/ + if (ret == RET_OK) + { + return RET_OK; + } + else + { + return RET_SYSERR; + } + } + } + else { + rpc_log_error("exit status = [%d]\n",WEXITSTATUS(status)); + return RET_SYSERR; + } + } + + return ret; + +} + + +/*жgatewaydevǷΪ*/ +void judge_para(int *flag, char *gateway, char *dev) +{ + if (strcmp(gateway,"") != 0) + { + if (strcmp(dev,"") != 0) + { + *flag = 1; + } + + else + { + *flag = 2; + } + + } + else + { + *flag = 3; + } + +} + +/*flag־ǷҪgwdev*/ +void judge_buff(int *flag, char *buff) +{ + if (strstr(buff,"gw") != NULL) + { + if (strstr(buff,"dev") != NULL) + { + *flag = 1; + } + else + { + *flag = 2; + } + } + + else + { + *flag = 3; + } + +} + +/*Ĭ·*/ +ret_code default_routing_proc(routing_t *conf_buff, uint config_type){ + + char string[STRING_LENGTH]; + char string_del[STRING_LENGTH]; + //uint config_type = conf_buff->conf_type; + char *gw_t = conf_buff->gateway; + char *dev_t = conf_buff->dev; + int metric_t = conf_buff->metric; + ret_code ret = RET_OK; + int flag = 0; + + if (conf_buff == NULL) + { + return RET_NULLP; + } + + judge_para(&flag,gw_t,dev_t); + + memset(string, 0, sizeof(string)); + memset(string_del, 0, sizeof(string_del)); + +/*config_typeжӻɾ, +versionжIPV4IPV6 +flagֵװstring*/ + + if (config_type == CM_CONFIG_ADD) + { + if(conf_buff->version == IPV4_VERSION) + { + switch (flag) { + case 1: + sprintf(string,"route add default gw %s dev %s metric %d\n", + gw_t,dev_t,metric_t); + ret = add_routing_exe(string); + break; + case 2: + sprintf(string,"route add default gw %s metric %d\n",gw_t,metric_t); + ret = add_routing_exe(string); + break; + case 3: + sprintf(string,"route add default dev %s metric %d\n",dev_t,metric_t); + ret = add_routing_exe(string); + break; + default: + return RET_ERR; + } + } + + else if (conf_buff->version == IPV6_VERSION) + { + switch (flag) { + case 1: + sprintf(string,"route -A inet6 add default gw %s dev %s metric %d\n", + gw_t,dev_t,metric_t); + ret = add_routing_exe(string); + break; + case 2: + sprintf(string,"route -A inet6 add default gw %s metric %d\n",gw_t,metric_t); + ret = add_routing_exe(string); + break; + case 3: + sprintf(string,"route -A inet6 add default dev %s metric %d\n",dev_t,metric_t); + ret = add_routing_exe(string); + break; + default: + return RET_ERR; + } + } + + else + { + return RET_ERR; + } + } + + else if (config_type == CM_CONFIG_DEL) + { + if(conf_buff->version == IPV4_VERSION) + { + switch (flag) { + case 1: + sprintf(string,"route del default gw %s dev %s metric %d", + gw_t,dev_t,metric_t); + sprintf(string_del,"route add default gw %s dev %s metric %d", + gw_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 2: + sprintf(string,"route del default gw %s metric %d",gw_t,metric_t); + sprintf(string_del,"route add default gw %s metric %d",gw_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 3: + sprintf(string,"route del default dev %s metric %d",dev_t,metric_t); + sprintf(string_del,"route add default dev %s metric %d",dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + default: + return RET_ERR; + } + } + + else if(conf_buff->version == IPV6_VERSION) + { + switch (flag) { + case 1: + sprintf(string,"route -A inet6 del default gw %s dev %s metric %d", + gw_t,dev_t,metric_t); + sprintf(string_del,"route -A inet6 add default gw %s dev %s metric %d", + gw_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 2: + sprintf(string,"route -A inet6 del default gw %s metric %d",gw_t,metric_t); + sprintf(string_del,"route -A inet6 add default gw %s metric %d",gw_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 3: + sprintf(string,"route -A inet6 del default dev %s metric %d",dev_t,metric_t); + sprintf(string_del,"route -A inet6 add default dev %s metric %d",dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + default: + return RET_ERR; + } + } + } + + else + { + return RET_ERR; + } + + return ret; + +} + +/*жIPV4/IPV6 +ж·/· +װshell*/ +ret_code routing_add(routing_t *conf_buff) +{ + char string[STRING_LENGTH]; + uint version_t = conf_buff->version; + uint netmask_t = conf_buff->netmask; + char route_type[10] = {0}; + ret_code ret = RET_OK; + char *destip_t = conf_buff->destip; + char *gw_t = conf_buff->gateway; + char *dev_t = conf_buff->dev; + int metric_t = conf_buff->metric; + int flag = 0; + + judge_para(&flag,gw_t,dev_t); + + rpc_log_info("flag: %d\n",flag); + + memset(string, 0, sizeof(string)); + + if(version_t == IPV4_VERSION) + { + if(metric_t < 0) + { + return RET_INPUTERR; + } + if (netmask_t > 0 && netmask_t < 32) + { + strcpy(route_type,"-net"); + } + else if(netmask_t == 32) + { + strcpy(route_type,"-host"); + } + else + { + return RET_INPUTERR; + } + + switch (flag){ + case 1: + sprintf(string,"route add %s %s/%d gw %s dev %s metric %d\n",route_type,destip_t,netmask_t,gw_t,dev_t,metric_t); + ret = add_routing_exe(string); + break; + case 2: + sprintf(string,"route add %s %s/%d gw %s metric %d\n",route_type,destip_t,netmask_t,gw_t,metric_t); + ret = add_routing_exe(string); + break; + case 3: + sprintf(string,"route add %s %s/%d dev %s metric %d\n",route_type,destip_t,netmask_t,dev_t,metric_t); + ret = add_routing_exe(string); + break; + default: + return RET_INPUTERR; + } + } + + else if (version_t == IPV6_VERSION) + { + if (metric_t < 1) + { + return RET_INPUTERR; + } + 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); + ret = add_routing_exe(string); + break; + case 2: + sprintf(string,"route -A inet6 add %s/%d gw %s metric %d\n",destip_t,netmask_t,gw_t,metric_t); + ret = add_routing_exe(string); + break; + case 3: + sprintf(string,"route -A inet6 add %s/%d dev %s metric %d\n",destip_t,netmask_t,dev_t,metric_t); + ret = add_routing_exe(string); + break; + default: + return RET_INPUTERR; + + } + } + return ret; +} + + +ret_code routing_del(routing_t *conf_buff) +{ + char string[STRING_LENGTH]; + char string_del[STRING_LENGTH]; + uint version_t = conf_buff->version; + uint netmask_t = conf_buff->netmask; + char route_type[10] = {0}; + ret_code ret = RET_OK; + char *destip_t = conf_buff->destip; + char *gw_t = conf_buff->gateway; + char *dev_t = conf_buff->dev; + int metric_t = conf_buff->metric; + int flag = 0; + + judge_para(&flag,gw_t,dev_t); + + memset(string, 0, sizeof(string)); + memset(string_del, 0, sizeof(string_del)); + + if(version_t == IPV4_VERSION) + { + if (netmask_t > 0 && netmask_t < 32) + { + strcpy(route_type,"-net"); + } + else if(netmask_t == 32) + { + strcpy(route_type,"-host"); + } + else + { + return RET_INPUTERR; + } + + switch (flag){ + case 1: + sprintf(string,"route del %s %s/%d gw %s dev %s metric %d",route_type,destip_t,netmask_t,gw_t,dev_t,metric_t); + sprintf(string_del,"route add %s %s/%d gw %s dev %s metric %d",route_type,destip_t,netmask_t,gw_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 2: + sprintf(string,"route del %s %s/%d gw %s metric %d",route_type,destip_t,netmask_t,gw_t,metric_t); + sprintf(string_del,"route add %s %s/%d gw %s metric %d",route_type,destip_t,netmask_t,gw_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 3: + sprintf(string,"route del %s %s/%d dev %s metric %d",route_type,destip_t,netmask_t,dev_t,metric_t); + sprintf(string_del,"route add %s %s/%d dev %s metric %d",route_type,destip_t,netmask_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + default: + return RET_INPUTERR; + } + } + + else if (version_t == IPV6_VERSION) + { + switch(flag){ + case 1: + sprintf(string,"route -A inet6 del %s/%d gw %s dev %s metric %d",destip_t,netmask_t,gw_t,dev_t,metric_t); + sprintf(string_del,"route -A inet6 add %s/%d gw %s dev %s metric %d",destip_t,netmask_t,gw_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 2: + sprintf(string,"route -A inet6 del %s/%d gw %s metric %d",destip_t,netmask_t,gw_t,metric_t); + sprintf(string_del,"route -A inet6 add %s/%d gw %s metric %d",destip_t,netmask_t,gw_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + case 3: + sprintf(string,"route -A inet6 del %s/%d dev %s metric %d",destip_t,netmask_t,dev_t,metric_t); + sprintf(string_del,"route -A inet6 add %s/%d dev %s metric %d",destip_t,netmask_t,dev_t,metric_t); + ret = del_routing_exe(string,string_del); + break; + default: + return RET_INPUTERR; + + } + } + return ret; +} + +/*ļжȡ·Ϣ*/ +ret_code get_all_from_file (pointer output, int *output_len) +{ + int ret = RET_OK; + FILE *f; + char buff[LINE_MAX_LENGTH]; + int ipv4_count = 0; + int ipv6_count = 0; + int count = 0; + routing_t *buff_total; + + int flag = 0; + int version = 0; + char destip[IP_MAX_LENGTH] = {0}; + int netmask = 0; + char gateway[IP_MAX_LENGTH] = {0}; + char dev[INTERFACE_MAX_LENGTH] = {0}; + int metric = 100; + + rpc_log_info("check1\n"); + + f = fopen(STATIC_ROUTING_PATH,"r"); + + if(NULL == f) + { + rpc_log_error("open config file fail\n"); + return RET_SYSERR; + } + + 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; + } + + memset(buff,0,sizeof(buff)); + memset(buff_total,0,sizeof(buff_total)); + + fseek(f,0,SEEK_SET); + + while (fgets(buff,sizeof(buff),f) != NULL) + { + if(strstr(buff,"route") != NULL) + { + judge_buff(&flag,buff); + rpc_log_info("check2 flag: %d\n", flag); + + + if(strstr(buff,"inet6") != NULL) + { + version = IPV6_VERSION; + if (strstr(buff,"default") != NULL) + { + + switch(flag){ + case 1: + sscanf(buff,"%*s%*s%*s%*s%*s%*s%s%*s%s%*s%d",gateway,dev, &metric); + break; + case 2: + sscanf(buff,"%*s%*s%*s%*s%*s%*s%s%*s%d",gateway, &metric); + break; + case 3: + sscanf(buff,"%*s%*s%*s%*s%*s%*s%s%*s%d",dev, &metric); + break; + default: + ret = RET_ERR; + } + netmask = 0; + strcpy(destip,"::"); + ipv6_count++; + } + else + { + + switch(flag){ + case 1: + sscanf(buff,"%*s%*s%*s%*s%[^/]/%d%*s%s%*s%s%*s%d",destip,&netmask,gateway,dev, &metric); + break; + case 2: + sscanf(buff,"%*s%*s%*s%*s%[^/]/%d%*s%s%*s%d",destip,&netmask,gateway,&metric); + break; + case 3: + sscanf(buff,"%*s%*s%*s%*s%[^/]/%d%*s%s%*s%d",destip,&netmask,dev,&metric); + break; + default: + ret = RET_ERR; + } + ipv6_count ++; + } + } + else if (strstr(buff,"default") != NULL) + { + version = IPV4_VERSION; + switch(flag){ + case 1: + sscanf(buff,"%*s%*s%*s%*s%s%*s%s%*s%d",gateway,dev, &metric); + rpc_log_info("check3: %s %s %d\n", gateway,dev,metric); + break; + case 2: + sscanf(buff,"%*s%*s%*s%*s%s%*s%d",gateway, &metric); + break; + case 3: + sscanf(buff,"%*s%*s%*s%*s%s%*s%d",dev, &metric); + break; + default: + ret = RET_ERR; + } + netmask = 0; + strcpy(destip,"0.0.0.0"); + ipv4_count++; + } + + else + { + version = IPV4_VERSION; + switch(flag){ + case 1: + sscanf(buff,"%*s%*s%*s%[^/]/%d%*s%s%*s%s%*s%d",destip,&netmask,gateway,dev, &metric); + break; + case 2: + sscanf(buff,"%*s%*s%*s%[^/]/%d%*s%s%*s%d",destip,&netmask,gateway,&metric); + break; + case 3: + sscanf(buff,"%*s%*s%*s%[^/]/%d%*s%s%*s%d",destip,&netmask,dev,&metric); + break; + default: + ret = RET_ERR; + } + ipv4_count++; + } + + buff_total[count].version = version; + strcpy(buff_total[count].destip,destip); + buff_total[count].netmask = netmask; + strcpy(buff_total[count].gateway,gateway); + strcpy(buff_total[count].dev,dev); + buff_total[count].metric = metric; + + count ++; + rpc_log_info("check4: ipv4 count %d total count %d\n", ipv4_count,count); + + version = 0; + memset(destip,0,IP_MAX_LENGTH); + netmask = 0; + memset(gateway,0,IP_MAX_LENGTH); + memset(dev,0,INTERFACE_MAX_LENGTH); + metric = 100; + } + + if(fgetc(f) == EOF) + { + break; + } + + fseek(f,-1,SEEK_CUR); + memset(buff,0,sizeof(buff)); + } + + fclose(f); + ret = routing_to_json (count, buff_total, output, output_len); + + rpc_free(buff_total); + return ret; +} + +/*ûָ*/ +ret_code config_recovery() +{ + ret_code ret = RET_OK; + FILE *f; + char buff[LINE_MAX_LENGTH]; + char buff_total[LINE_MAX_LENGTH*ROUTING_TABLE_MAX_NUMBER]; + int status; + + f= fopen(STATIC_ROUTING_PATH,"r"); + + if(NULL == f) + { + rpc_log_error("open config file fail\n"); + return RET_SYSERR; + } + + memset(buff,0,sizeof(buff)); + memset(buff_total,0,sizeof(buff_total)); + + fseek(f,0,SEEK_SET); + + while (fgets(buff,sizeof(buff),f) != NULL) + { + if(strstr(buff,"route") != NULL) + { + + if(strlen(buff) < 3) + { + goto next_while; + } + + status = system(buff); + + if (-1 == status) + { + rpc_log_error("system shell error!\n"); + goto next_while; + } + else { + if (WIFEXITED(status)){ + if (0 == WEXITSTATUS(status)){ + rpc_log_info("run shell successfully!\n"); + rpc_log_info("routing recovery!\n"); + strcat(buff_total,buff); + goto next_while; + } + else{ + rpc_log_error("run shell script fail,script exit code:%d\n",WEXITSTATUS(status)); + goto next_while; + } + } + else { + rpc_log_error("exit status = [%d]\n",WEXITSTATUS(status)); + goto next_while; + } + } + } +next_while: + if(fgetc(f) == EOF) + { + break; + } + + fseek(f,-1,SEEK_CUR); + memset(buff,0,sizeof(buff)); + } + fclose(f); + + ret = conf_file_write(STATIC_ROUTING_PATH,buff_total); + + return ret; +} + + +/*jsonҸֵṹ*/ +ret_code routing_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len){ + + if(source == CONFIG_FROM_RECOVER1) + { + return RET_OK; + } + + if(source == CONFIG_FROM_RECOVER2) + { + return RET_CHKERR; + } + + int conf_length = sizeof(routing_t); + routing_t routing_buff = {0}; + routing_t *conf_buff = &routing_buff; + ret_code ret = RET_OK; + int code = 0; + + ret = routing_json_parse(input,config_type,conf_buff); + + rpc_log_info("conf_buff:%s\n", conf_buff->destip); + rpc_log_info("conf_buff:%d\n", *config_type); + + + /*жgatewaydevǷΪNULL*/ + if((*config_type == CM_CONFIG_ADD) || (*config_type == CM_CONFIG_DEL)) + { + /*жЭǷȷ*/ + if((conf_buff->version != IPV4_VERSION) && (conf_buff->version != IPV6_VERSION)) + { + return RET_CHKERR; + } + else if(strcmp(conf_buff->gateway,"") == 0 && strcmp(conf_buff->dev,"") == 0) + { + rpc_log_info(" gateway and dev are NULL\n"); + return RET_CHKERR; + } + + } + + else if ((*config_type == CM_CONFIG_GET_ALL)) + { + if ((*output_len)<(ROUTING_TABLE_MAX_NUMBER * sizeof(routing_t))) + { + rpc_log_info("getall check error\n"); + return RET_CHKERR; + } + } + + else + { + return RET_CHKERR; + } + + + if(conf_length <= CM_BUFF_SIZE) + { + *input_len = conf_length; + memset(input, 0, *input_len); + memcpy(input, conf_buff, conf_length); + } + else + { + ret = RET_NOMEM; + } + + return ret; +} + + + +/*ӻɾ·*/ +ret_code routing_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + + if(source == CONFIG_FROM_RECOVER1 || source == CONFIG_FROM_RECOVER2) + { + ret = config_recovery(); + return ret; + } + + char string[STRING_LENGTH]; + uint conf_type = config_type; + routing_t conf_buff = {0}; + routing_t *routing_conf = &conf_buff; + int flag = 0; + + routing_conf = (routing_t *)input; + + rpc_log_info("routing info: config_type %d, version %d, destip %s, netmask %d, gateway %s, dev %s, metric %d\n", + conf_type, + routing_conf->version, + routing_conf->destip, + routing_conf->netmask, + routing_conf->gateway, + routing_conf->dev, + routing_conf->metric); + +/*жǷĬ·*/ + if(strcmp(routing_conf->destip,"0.0.0.0") == 0 || strcmp(routing_conf->destip,"::") == 0) + { + if ((routing_conf->netmask) == 0) + { + ret = default_routing_proc(routing_conf,conf_type); + return ret; + } + else + { + return RET_INPUTERR; + } + } + + +/*̬·*/ + switch(config_type){ + case CM_CONFIG_ADD: + ret = routing_add(routing_conf); + break; + + case CM_CONFIG_DEL: + ret = routing_del(routing_conf); + break; + + default: + ret = RET_NOTSUPPORT; + } + + return ret; + +} + + +/*ȡӵľ̬·*/ +ret_code routing_config_get_all(uint source, + pointer output, int *output_len){ + + if (source == CONFIG_FROM_RECOVER1 || source == CONFIG_FROM_RECOVER2) + { + return RET_OK; + } + + rpc_log_info("in function getall\n"); + + int ret = RET_OK; + *output_len = 0; + //int code = 0; + ret = get_all_from_file(output,output_len); + + rpc_log_info("routing_config_get_all: %s\n", output); + + //RET_ERR_FORMART(ret, code, output, *output_len); + ASSERT_RET(ret); + + return ret; + +} + + + + + +/*-------------------------------------------------------------------------*/ + +ret_code all_routing_config_chk(uint source, uint * config_type, + pointer input, int * input_len, + pointer output, int * output_len) +{ + rpc_log_info("test check\n"); + + ret_code ret = RET_OK; + routing_t routing_buff = {0}; + routing_t *conf_buff = &routing_buff; + + routing_json_parse(input,config_type,conf_buff); + + rpc_log_info("conf_buff:%d\n", *config_type); + + if ((*config_type == CM_CONFIG_GET_ALL)) + { + if ((*output_len)<(ROUTING_TABLE_MAX_NUMBER * sizeof(routing_t))) + { + rpc_log_info("getall check error\n"); + return RET_CHKERR; + } + } + + return ret; +} + + + + + +/*ȡ·Ϣ*/ + +ret_code all_routing_get_all(uint source, + pointer output, int *output_len) +{ + FILE *f; + ret_code ret = RET_OK; + routing_t *conf_buff; + int count = 0; + int ipv4_number = 0; + int ipv6_number = 0; + int status; + char temp_buff[LINE_MAX_LENGTH]; + char destip[IP_MAX_LENGTH] = {0}; + char gateway[IP_MAX_LENGTH] = {0}; + char gateway_new[IP_MAX_LENGTH] = {0}; + char netmask[IP_MAX_LENGTH] = {0}; + char dev[INTERFACE_MAX_LENGTH]; + int metric = 100; + struct in_addr addr; + int netmask_int = 0; + + f = popen(IPV4_GET_STATIC_ROUTING,"r"); + if (NULL == f) + { + rpc_log_error("get ipv4 routing info fail\n"); + return RET_SYSERR; + } + + conf_buff = rpc_new0(routing_t,ROUTING_TABLE_MAX_NUMBER); + memset(conf_buff,0,sizeof(conf_buff)); + memset(temp_buff,0,LINE_MAX_LENGTH); + + fseek(f,0,SEEK_SET); + + for(int i=0;i<2;i++) + { + fgets(temp_buff,LINE_MAX_LENGTH,f); + fseek(f,0,SEEK_CUR); + memset(temp_buff,0,LINE_MAX_LENGTH); + } + + while(fgets(temp_buff,LINE_MAX_LENGTH,f) != NULL) + { + if(strlen(temp_buff) <3) + { + goto next_while; + } + + sscanf(temp_buff,"%s %s %s %*s %d %*s %*s %s",destip,gateway,netmask,&metric,dev); + inet_aton(netmask,&addr); + netmask_int = ip_masklen(addr); + conf_buff[count].version = 4; + strcpy(conf_buff[count].destip,destip); + conf_buff[count].netmask = netmask_int; + strcpy(conf_buff[count].gateway,gateway); + strcpy(conf_buff[count].dev,dev); + conf_buff[count].metric = metric; + + count ++; + ipv4_number++; + + memset(destip,0,IP_MAX_LENGTH); + memset(netmask,0,IP_MAX_LENGTH); + memset(gateway,0,IP_MAX_LENGTH); + memset(dev,0,INTERFACE_MAX_LENGTH); + metric = 100; + + goto next_while; + +next_while: + /*if (fgetc(f) == EOF) + { + break; + }*/ + fseek(f,-1,SEEK_CUR); + memset(temp_buff,0,sizeof(temp_buff)); + } + + + fclose(f); + + f = popen(IPV6_GET_STATIC_ROUTING,"r"); + if (NULL == f) + { + rpc_log_error("get ipv6 routing info fail\n"); + return RET_SYSERR; + } + + fseek(f,0,SEEK_SET); + + for(int k=0;k<2;k++) + { + fgets(temp_buff,LINE_MAX_LENGTH,f); + fseek(f,0,SEEK_CUR); + memset(temp_buff,0,LINE_MAX_LENGTH); + } + + while(fgets(temp_buff,LINE_MAX_LENGTH,f) != NULL) + { + if(strlen(temp_buff) <3) + { + fseek(f,-1,SEEK_CUR); + memset(temp_buff,0,sizeof(temp_buff)); + continue; + } + + sscanf(temp_buff,"%[^/]/%d %s %*s %d %*s %*s %s",destip,&netmask_int,gateway,&metric,dev); + rpc_log_info("check 5 after sscanf\n"); + rpc_log_info("check 6: destip %s gateway %s netmask %d metric %d dev %s\n",destip,gateway,netmask_int,metric,dev); + if(metric > 0) + { + sscanf(gateway,"[%[^]]",gateway_new); + conf_buff[count].version = 6; + if (strcmp(destip,"[::]") == 0) + { + strcpy(conf_buff[count].destip,"::"); + } + else + { + strcpy(conf_buff[count].destip,destip); + } + conf_buff[count].netmask = netmask_int; + strcpy(conf_buff[count].gateway,gateway_new); + strcpy(conf_buff[count].dev,dev); + conf_buff[count].metric = metric; + + count ++; + ipv6_number++; + + memset(destip,0,IP_MAX_LENGTH); + memset(netmask,0,IP_MAX_LENGTH); + memset(gateway,0,IP_MAX_LENGTH); + memset(dev,0,INTERFACE_MAX_LENGTH); + metric = 100; + + fseek(f,-1,SEEK_CUR); + memset(temp_buff,0,sizeof(temp_buff)); + } + + else + { + memset(destip,0,IP_MAX_LENGTH); + memset(netmask,0,IP_MAX_LENGTH); + memset(gateway,0,IP_MAX_LENGTH); + memset(dev,0,INTERFACE_MAX_LENGTH); + metric = 100; + fseek(f,-1,SEEK_CUR); + memset(temp_buff,0,sizeof(temp_buff)); + } + + } + + + fclose(f); + + ret = routing_to_json(count,conf_buff, output, output_len); + + rpc_log_info("routing_config_get_all: %s\n", output); + + rpc_free(conf_buff); + + //RET_ERR_FORMART(ret, code, output, *output_len); + ASSERT_RET(ret); + + return ret; +} + + + + + + + + + + + + + + diff --git a/Platform/user/configm/config-server/vlan_config/vlan_config.c b/Platform/user/configm/config-server/vlan_config/vlan_config.c index ac7d9ad33..f6a6fe1ad 100644 --- a/Platform/user/configm/config-server/vlan_config/vlan_config.c +++ b/Platform/user/configm/config-server/vlan_config/vlan_config.c @@ -1246,11 +1246,12 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info goto out; } if(!(operate = cJSON_GetObjectItem(root, "operate"))){ - printf("[vlan]vlan_config_json_parse: No operate node.\n"); + printf("[vlan]vlan_config_json_parse: Json No operate node.\n"); ret = RET_INPUTERR; goto out; } if(!(conf_ifvlan = cJSON_GetObjectItem(root, "conf-ifvlan"))){ + printf("[vlan]vlan_config_json_parse: Json No conf_ifvlan node.\n"); ret = RET_INPUTERR; goto out; } @@ -1258,7 +1259,7 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info /* interface */ if_num = cJSON_GetArraySize(conf_ifvlan); if(if_num == 0){ - printf("[vlan]vlan_config_json_parse: json array has no interface.\n"); + printf("[vlan]vlan_config_json_parse: Json array has no interface.\n"); ret = RET_INPUTERR; goto out; } @@ -1287,7 +1288,10 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info } cJSON *ifName = cJSON_GetObjectItem(node, "if-name"); if(!ifName){ - continue; + //continue; + printf("[vlan]vlan_config_json_parse: json has no ifName node.\n"); + ret = RET_INPUTERR; + goto out; } if(NULL == ifName->valuestring){ printf("[vlan]vlan_config_json_parse: ifName->valuestring is null.\n"); @@ -1298,7 +1302,10 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info printf("[vlan]if_vlan_info[%d].if_name=%s\n", i, if_vlan_info[i].if_name); cJSON *ifAttr = cJSON_GetObjectItem(node, "if-attr"); if(!ifAttr){ - continue; + //continue; + printf("[vlan]vlan_config_json_parse: Json has no ifAttr node.\n"); + ret = RET_INPUTERR; + goto out; } if(NULL == ifAttr->valuestring){ printf("[vlan]vlan_config_json_parse: ifAttr->valuestring is null.\n"); @@ -1311,15 +1318,23 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info else if(!strcmp(ifAttr->valuestring, "access")){ if_vlan_info[i].attr = LINK_TYPE_ACCESS; } + else { + printf("[vlan]vlan_config_json_parse: errror: is not trunk or access.\n"); + ret = RET_INPUTERR; + goto out; + } cJSON *vId = cJSON_GetObjectItem(node, "vid"); if(!vId){ - continue; + //continue; + printf("[vlan]vlan_config_json_parse: Json has no vId node.\n"); + ret = RET_INPUTERR; + goto out; } /* ڲvid */ vl_num = cJSON_GetArraySize(vId); if(vl_num == 0){ - printf("[vlan]vlan_config_json_parse: json array has no vid.\n"); + printf("[vlan]vlan_config_json_parse: Json array has no vid element.\n"); ret = RET_INPUTERR; goto out; } @@ -2077,7 +2092,11 @@ ret_code vlan_operate_parse(pointer input, int *oper_type) ret = RET_OK; goto out; } - + else { + printf("[vlan]vlan_operate_chk: operate-val is UNKNOWN, error.\n"); + ret = RET_INPUTERR; + goto out; + } out: if(root){ cJSON_Delete(root); diff --git a/Platform/user/configm/config-server/web_config/authfree.c b/Platform/user/configm/config-server/web_config/authfree.c index 7d8723ed8..edb404324 100644 --- a/Platform/user/configm/config-server/web_config/authfree.c +++ b/Platform/user/configm/config-server/web_config/authfree.c @@ -16,7 +16,7 @@ /*定义结构体数组 存在免认证规则 */ freeauth_configure_t freeauth_array[RULE_MAX_NUM] = {0}; -#define UNAMESIZE (127 + 1) +#define UNAMESIZE (60 + 1) #define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符 #ifdef FREEAUTH_ACK_COOKIES @@ -536,6 +536,8 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type, int i; int cnt; cJSON *res; + cJSON *pJsonArry; + cJSON *pJsonsub; authfree_result_t authfree_result; freeauth_configure_t *freeauth_configure = NULL; uint conf_type = FREEAUTH_CONFIG_GET; @@ -564,6 +566,9 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type, freeauth_configure[j].dip, freeauth_configure[j].dport, freeauth_configure[j].dport, j); } + pJsonArry= cJSON_CreateArray(); /*创建数组*/ + + /*查找要修改的免认证规则名字,不存在则退出程序 */ for(i = 0; i < RULE_MAX_NUM; i++) { /*两个字符串相等 strcmp值为0*/ @@ -602,35 +607,43 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type, commcfgnl_close(); printf("cfgchannel main exit!\r\n"); #endif + + cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对象*/ - /*创建json对象 */ - res = cJSON_CreateObject(); - - if(!res) { - return RET_ERR; + /*在json对象上添加键值对*/ + char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator + //in real code you would check for errors in malloc here + if (result_message == NULL) + { + return RET_NOMEM; } - /*将json对象转换成json字符串 返回处理结果*/ - cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode); - cJSON_AddStringToObject(res, "message", authfree_result.message); - ret_char = cJSON_PrintUnformatted(res); + strcpy(result_message, freeauth_configure[j].name); + strcat(result_message, authfree_result.message); + printf("%s\n", result_message); + + cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode); + cJSON_AddStringToObject(pJsonsub, "message", result_message); + + ret_char = cJSON_Print(pJsonArry); ret_int = strlen(ret_char); - if(output_len) { + if(output_len) + { *output_len = ret_int; } /*超出2k的内存,报错 */ - if(ret_int >= 1024 * 2) { + if(ret_int >= 1024 * 2) + { free(ret_char); - cJSON_Delete(res); + cJSON_Delete(pJsonArry); return RET_NOMEM; } memcpy(output, ret_char, ret_int + 1); - free(ret_char); - cJSON_Delete(res); + free(ret_char); } } } @@ -651,6 +664,8 @@ ret_code freeauth_config_del_proc(uint source, uint config_type, int i; int cnt; cJSON *res; + cJSON *pJsonArry; + cJSON *pJsonsub; authfree_result_t authfree_result; freeauth_configure_t *freeauth_configure = NULL; uint conf_type = FREEAUTH_CONFIG_GET; @@ -679,6 +694,7 @@ ret_code freeauth_config_del_proc(uint source, uint config_type, printf("[%s %d]\n", freeauth_configure[j].name, j); } + pJsonArry= cJSON_CreateArray(); /*创建数组*/ /*查找要修改的免认证规则名字,不存在则退出程序 */ for(i = 0; i < RULE_MAX_NUM; i++) { @@ -719,18 +735,24 @@ ret_code freeauth_config_del_proc(uint source, uint config_type, printf("cfgchannel main exit!\r\n"); #endif - /*创建json对象 */ - res = cJSON_CreateObject(); - - if(!res) + cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject()); + + /*在json对象上添加键值对*/ + char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator + //in real code you would check for errors in malloc here + if (result_message == NULL) { - return RET_ERR; + return RET_NOMEM; } - /*将json对象转换成json字符串 返回处理结果*/ - cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode); - cJSON_AddStringToObject(res, "message", authfree_result.message); - ret_char = cJSON_PrintUnformatted(res); + strcpy(result_message, freeauth_configure[j].name); + strcat(result_message, authfree_result.message); + printf("%s\n", result_message); + + cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode); + cJSON_AddStringToObject(pJsonsub, "message", result_message); + + ret_char = cJSON_Print(pJsonArry); ret_int = strlen(ret_char); if(output_len) @@ -748,8 +770,7 @@ ret_code freeauth_config_del_proc(uint source, uint config_type, memcpy(output, ret_char, ret_int + 1); - free(ret_char); - cJSON_Delete(res); + free(ret_char); } } } diff --git a/Platform/user/logging/logging_main.c b/Platform/user/logging/logging_main.c index 8d56acc45..ff73c9be6 100755 --- a/Platform/user/logging/logging_main.c +++ b/Platform/user/logging/logging_main.c @@ -36,13 +36,85 @@ log_cmd_t *get_cb_by_cmd(const char *cmd) return NULL; } +static void logging_usage() +{ + int i = 0; + char tmp_str[1024] = ""; + fprintf(stdout, "-----------------------------------------------------------------------------------------\n"); + fprintf(stdout, "usage of %s:", LOGGING_MODULE_NAME); + for (int i = 0; i < (sizeof(g_log_cmd) / sizeof(log_cmd_t)); i++) { + strcat(tmp_str, g_log_cmd[i].cmd); + if (i < (sizeof(g_log_cmd) / sizeof(log_cmd_t))-1) { + strcat(tmp_str, "|"); + } + } + fprintf(stdout, " %s %s\n", LOGGING_MODULE_NAME, tmp_str); + fprintf(stdout, "\n"); + + fprintf(stdout, "1. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s []\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s get []\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " = emerg | alert | crit | err | warn | notice | info | debug\n"); + fprintf(stdout, " the filtering module_name, only recode this module's log while set\n"); + fprintf(stdout, " eg: %s %s info moudle1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s off\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, " %s %s get module1\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd); + fprintf(stdout, "\n"); + + fprintf(stdout, "2. usage of %s %s is simple as %s\n", LOGGING_MODULE_NAME, g_log_cmd[1].cmd, g_log_cmd[0].cmd); + fprintf(stdout, "\n"); + + fprintf(stdout, "3. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s add [] []\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s del [] []\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s get \n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " is the ip address of remote syslog server\n"); + fprintf(stdout, " is the port of remote syslog server\n"); + fprintf(stdout, " = RFC3164fmt|RFC5424fmt, is the version of syslog format\n"); + fprintf(stdout, " eg: %s %s add 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s del 192.168.100.1 514 RFC3164fmt\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s get 192.168.100.1\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, " %s %s getall\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd); + fprintf(stdout, "\n"); + + fprintf(stdout, "4. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd); + fprintf(stdout, " %s %s \n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd); + fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd); + fprintf(stdout, " = emerg | alert | crit | err | warn | notice | info | debug \n"); + fprintf(stdout, " eg: %s %s info\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd); + fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[3].cmd); + fprintf(stdout, "\n"); + + fprintf(stdout, "5. usage of %s %s:\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd); + fprintf(stdout, " %s %s [] [] [] []\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd); + fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd); + fprintf(stdout, " = emerg | alert | crit | err | warn | notice | info | debug\n"); + fprintf(stdout, " is the path of syslog files saved\n"); + fprintf(stdout, " = 0 | 1 , which 0 is syslog files is not compress while 1 is compress\n"); + fprintf(stdout, " is the syslog files life-time (days)\n"); + fprintf(stdout, " is the syslog files life-size (bytes)\n"); + fprintf(stdout, " eg: %s %s info /var/log/syslog-files 0 100 1024000\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd); + fprintf(stdout, " %s %s get\n", LOGGING_MODULE_NAME, g_log_cmd[4].cmd); + + fprintf(stdout, "-----------------------------------------------------------------------------------------\n"); +} + int main(int argc, char **argv) { int ret = -1; if (argc < 2) { fprintf(stdout, "Parameter too few\n"); + logging_usage(); return ret; - } + } + + if (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0) { + logging_usage(); + return 0; + } g_log = ulog_init(LOGGING_MODULE_NAME, 1); if (g_log == NULL) { diff --git a/Platform/user/rpdb/list.h b/Platform/user/rpdb/list.h new file mode 100644 index 000000000..6541971ec --- /dev/null +++ b/Platform/user/rpdb/list.h @@ -0,0 +1,641 @@ +#ifndef _LINUX_LIST_H +#define _LINUX_LIST_H + +#define container_of(ptr,type,member) ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + + +//#if defined(__KERNEL__) || defined(_LVM_H_INCLUDE) + +//#include + +/* + * Simple doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ + +typedef struct list_head { + struct list_head *next, *prev; +} list_t; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) + +#define INIT_LIST_HEAD(ptr) do { \ + (ptr)->next = (ptr); (ptr)->prev = (ptr); \ +} while (0) + +/* + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ + +static void inline prefetch(void *p){} + +static inline void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + +/** + * list_add_tail - add a new entry + * @new: new entry to be added + * @head: list head to add it before + * + * Insert a new entry before the specified head. + * This is useful for implementing queues. + */ +static inline void list_add_tail(struct list_head *new, struct list_head *head) +{ + __list_add(new, head->prev, head); +} + +/* + * Delete a list entry by making the prev/next entries + * point to each other. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static inline void __list_del(struct list_head *prev, struct list_head *next) +{ + next->prev = prev; + prev->next = next; +} + +/** + * list_del - deletes entry from list. + * @entry: the element to delete from the list. + * Note: list_empty on entry does not return true after this, the entry is in an undefined state. + */ +static inline void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + entry->next = (void *) 0; + entry->prev = (void *) 0; +} + +/** + * list_replace - replace old entry by new one + * @old : the element to be replaced + * @new : the new element to insert + * + * If @old was empty, it will be overwritten. + */ +static inline void list_replace(struct list_head *old, + struct list_head *new) +{ + new->next = old->next; + new->next->prev = new; + new->prev = old->prev; + new->prev->next = new; +} + +static inline void list_replace_init(struct list_head *old, + struct list_head *new) +{ + list_replace(old, new); + INIT_LIST_HEAD(old); +} + +/** + * list_del_init - deletes entry from list and reinitialize it. + * @entry: the element to delete from the list. + */ +static inline void list_del_init(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + INIT_LIST_HEAD(entry); +} + +/** + * list_move - delete from one list and add as another's head + * @list: the entry to move + * @head: the head that will precede our entry + */ +static inline void list_move(struct list_head *list, struct list_head *head) +{ + __list_del(list->prev, list->next); + list_add(list, head); +} + +/** + * list_move_tail - delete from one list and add as another's tail + * @list: the entry to move + * @head: the head that will follow our entry + */ +static inline void list_move_tail(struct list_head *list, + struct list_head *head) +{ + __list_del(list->prev, list->next); + list_add_tail(list, head); +} + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static inline int list_empty(const struct list_head *head) +{ + return head->next == head; +} + +static inline void __list_splice(struct list_head *list, + struct list_head *head) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + struct list_head *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; +} + +/** + * list_splice - join two lists + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice(struct list_head *list, struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head); +} + +/** + * list_splice_init - join two lists and reinitialise the emptied list. + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * The list at @list is reinitialised + */ +static inline void list_splice_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head); + INIT_LIST_HEAD(list); + } +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + */ +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +/** + * list_last_entry - get the last element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_last_entry(ptr, type, member) \ + list_entry((ptr)->prev, type, member) + +/** + * list_first_entry_or_null - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_first_entry_or_null(ptr, type, member) \ + (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) + +/** + * list_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +/** + * list_prev_entry - get the prev element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_prev_entry(pos, member) \ + list_entry((pos)->member.prev, typeof(*(pos)), member) + +/** + * list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + */ +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +/** + * list_for_each_prev - iterate over a list backwards + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + */ +#define list_for_each_prev(pos, head) \ + for (pos = (head)->prev; pos != (head); pos = pos->prev) + +/** + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_safe(pos, n, head) \ + for (pos = (head)->next, n = pos->next; pos != (head); \ + pos = n, n = pos->next) + +/** + * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_prev_safe(pos, n, head) \ + for (pos = (head)->prev, n = pos->prev; \ + pos != (head); \ + pos = n, n = pos->prev) + +/** + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_last_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_prev_entry(pos, member)) + +/** + * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_head within the struct. + * + * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ? : list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - continue iteration over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_prev_entry(pos, member); \ + &pos->member != (head); \ + pos = list_prev_entry(pos, member)) + +/** + * list_for_each_entry_from - iterate over list of given type from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from(pos, head, member) \ + for (; &pos->member != (head); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member), \ + n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_continue - continue list iteration safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_next_entry(pos, member), \ + n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_from - iterate over list from current point safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_next_entry(n, member)) + +/** + * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_last_entry(head, typeof(*pos), member), \ + n = list_prev_entry(pos, member); \ + &pos->member != (head); \ + pos = n, n = list_prev_entry(n, member)) + +/** + * list_safe_reset_next - reset a stale list_for_each_entry_safe loop + * @pos: the loop cursor used in the list_for_each_entry_safe loop + * @n: temporary storage used in list_for_each_entry_safe + * @member: the name of the list_head within the struct. + * + * list_safe_reset_next is not safe to use in general if the list may be + * modified concurrently (eg. the lock is dropped in the loop body). An + * exception to this is if the cursor element (pos) is pinned in the list, + * and list_safe_reset_next is called after re-taking the lock and before + * completing the current iteration of the loop body. + */ +#define list_safe_reset_next(pos, n, member) \ + n = list_next_entry(pos, member) + + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ +#define LIST_POISON1 NULL +#define LIST_POISON2 NULL + +#define READ_ONCE(x) (x) +#define WRITE_ONCE(x, val) x=(val) + + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline int hlist_empty(const struct hlist_head *h) +{ + return !READ_ONCE(h->first); +} + +static inline void __hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + + WRITE_ONCE(*pprev, next); + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (!hlist_unhashed(n)) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + WRITE_ONCE(h->first, n); + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) +{ + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + WRITE_ONCE(*(n->pprev), n); +} + +static inline void hlist_add_behind(struct hlist_node *n, + struct hlist_node *prev) +{ + n->next = prev->next; + WRITE_ONCE(prev->next, n); + n->pprev = &prev->next; + + if (n->next) + n->next->pprev = &n->next; +} + +/* after that we'll appear to be on some hlist and hlist_del will work */ +static inline void hlist_add_fake(struct hlist_node *n) +{ + n->pprev = &n->next; +} + +static inline int hlist_fake(struct hlist_node *h) +{ + return h->pprev == &h->next; +} + +/* + * Check whether the node is the only node of the head without + * accessing head: + */ +static inline int +hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h) +{ + return !n->next && n->pprev == &h->first; +} + +/* + * Move a list from one list head to another. Fixup the pprev + * reference of the first entry if it exists. + */ +static inline void hlist_move_list(struct hlist_head *old, + struct hlist_head *new) +{ + new->first = old->first; + if (new->first) + new->first->pprev = &new->first; + old->first = NULL; +} + +#define hlist_entry(ptr, type, member) container_of(ptr,type,member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos ; pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ + pos = n) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +/** + * hlist_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after current point + * @pos: the type * to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(pos, member) \ + for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from current point + * @pos: the type * to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(pos, member) \ + for (; pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_safe(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + + +#endif diff --git a/Platform/user/rpdb/rpdb.c b/Platform/user/rpdb/rpdb.c new file mode 100644 index 000000000..7230b1c03 --- /dev/null +++ b/Platform/user/rpdb/rpdb.c @@ -0,0 +1,468 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "list.h" + + + +struct rpdb_mark { + struct list_head list; + union { + struct in6_addr ip6; + struct in_addr ip4; + + }ip; + + int mark; +}; + + + + +char rt_table[11][128]= { + "# reserved values", + "#", + "255 local", + "254 main", + "253 default", + "0 unspe", + "#", + "# local", + "#", + "#1 inr.ruhep" +}; + + +#define RT_TABLES_PATH ("/etc/iproute2/rt_tables") +#define IPV4_PATTERN "^([0-9]|[1-9][0-9]|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])$" +#define IPV6_PATTERN "^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$" + +#define RPDP_MARK_HASH_DEPTH (1024) +static int gRpdbMark = 0; + +/* + * mark hash list,save mark + */ +struct list_head gRpdbMarkList[RPDP_MARK_HASH_DEPTH] = {0}; + + +/* + popen +*/ + + +void +print_result(FILE *fp) +{ + char buf[100]; + + if(!fp) { + return; + } + printf("\n>>>\n"); + memset(buf, 0, sizeof(buf)); + fgets(buf, sizeof(buf) - 1, fp) ; + + + printf("%s", buf); + + + printf("\n<<<\n"); +} + +int rpdb_popen(char *cmd) +{ + FILE *fp = NULL; + + + fp = NULL; + fp = popen(cmd, "r"); + if(!fp) + { + perror("popen"); + exit(EXIT_FAILURE); + } + print_result(fp); + pclose(fp); + sleep(1); + return 0; +} + +/* + * rpdb 初始化接口 +*/ +bool rpdb_init_route() +{ + FILE *fp = NULL; + int i = 0; + + system("echo > /etc/iproute2/rt_tables"); + fp = fopen(RT_TABLES_PATH,"w"); + if (fp) + { + for (i = 0; i < 11; i++) + { + fprintf(fp,"%s\n",rt_table[i]); + } + } + else + { + return false; + } + + fclose(fp); + + + /* + 初始化链表 + */ + for (i = 0; i < RPDP_MARK_HASH_DEPTH; i++) + { + INIT_LIST_HEAD(&gRpdbMarkList[i]); + } + + return true; +} + + + +static int gRpdbTableIndex = 1; /* 1 - 252 */ +#define RPDB_TABLE_ADD (0) +#define RPDB_TABLE_DEL (1) +bool rpdb_add_delete_table(const char* gateway,const char *tbl_name,int op) +{ + char table_name[128] = {0}; + char line_cnt[1024] = {0}; + FILE *fp = NULL; + FILE *fp_tmp = NULL; + bool ret = false; + int i = 0; + int cn_num = 0; + if (tbl_name == NULL) + { + memset(table_name,0,sizeof(table_name)); + sprintf(table_name,"table_%s",gateway); + } + else + { + if (strlen(tbl_name) < 1) /* 检查name的合法性*/ + { + memset(table_name,0,sizeof(table_name)); + sprintf(table_name,"%s",tbl_name); + } + else + { + return false; + } + } + + fp = fopen(RT_TABLES_PATH,"ra+"); + if (NULL == fp) + { + return false; + } + else + { + while(!feof(fp)) /* 遍历文件每一行,查找 路由表是否存在 */ + { + memset(line_cnt,0,1024); + fgets(line_cnt,1024,fp); + if(strstr(line_cnt,table_name)) + { + if (op == RPDB_TABLE_ADD) + { + fclose(fp); + return true; + } + } + } + } + + /* + 向文件最后一行添加 路由表项 + */ + if (op == RPDB_TABLE_ADD) + { + if (gRpdbTableIndex > 252) + { + return false; + } + + memset(line_cnt,0,1024); + sprintf(line_cnt,"%d %s",gRpdbTableIndex,table_name); + printf("RPDB_TABLE_ADD:%s\n",line_cnt); + fprintf(fp,"%s\n",line_cnt); + fclose(fp); + gRpdbTableIndex++; + return true; + } + + if (op == RPDB_TABLE_DEL) + { + fp = fopen(RT_TABLES_PATH,"r+"); + if (NULL == fp) + { + return false; + } + else + { + fp_tmp = fopen("/tmp/rt_tables","w"); + if (fp_tmp == NULL) return false; + while(!feof(fp)) /* 遍历文件每一行,查找 路由表是否存在 */ + { + memset(line_cnt,0,1024); + fgets(line_cnt,1024,fp); + if(!strstr(line_cnt,table_name)) + { + fprintf(fp_tmp,"%s",line_cnt); + } + + } + + fclose(fp); + fclose(fp_tmp); + system("cp -fr /tmp/rt_tables /etc/iproute2/rt_tables"); + } + + } + return true; +} + +/* + * 判断ip地址是否合法 + */ + +int rpdb_ipaddr_match(char *ip_addr,int flag) +{ + regex_t reg; + regmatch_t match[1]; + int retval = 0; + + if (flag == 1) + { + retval = regcomp(®, IPV4_PATTERN, REG_EXTENDED | REG_NEWLINE); + } + else + { + retval = regcomp(®, IPV6_PATTERN, REG_EXTENDED | REG_NEWLINE); + } + + retval = regexec(®,ip_addr, sizeof match / sizeof match[0], match, 0); + printf("%s is %s\n", ip_addr, retval == 0 ? "legal" : "illegal"); + regfree(®); + return retval; +} + + +int rpdb_ip_hash(struct rpdb_mark node) +{ + int ip_value = 0; + int hash = 0; + int i = 0; + if (node.ip.ip4.s_addr !=0 ) + { + ip_value = node.ip.ip4.s_addr; + } + else + { + for (i = 0; i < 4; ++i) + { + ip_value += node.ip.ip6.s6_addr32[i]; + } + } + hash = (ip_value&0xF) + ((ip_value >> 8)&0xF) + ((ip_value >> 16)&0xF) + ((ip_value >> 24)&0xF); + hash = hash&(1024-1); + return hash; +} + + +/* + * node比较 +*/ + +bool rpdb_mark_node_compare(struct rpdb_mark node1,struct rpdb_mark node2) +{ + if (node1.ip.ip4.s_addr == node2.ip.ip4.s_addr) + { + return true; + } + else + { + return false; + } +} + + +/* + * mark 查找,返回链上的node节点 + */ +struct rpdb_mark * rpdb_mark_search(struct rpdb_mark node) +{ + struct list_head * pList; + struct rpdb_mark *pNode; + int hash = rpdb_ip_hash(node); + + list_for_each(pList,&gRpdbMarkList[hash]) { + pNode = list_entry(pList,struct rpdb_mark,list); + printf("%s,%d,%d,%d\n",__FUNCTION__,__LINE__,pNode->ip.ip4.s_addr,pNode->mark); + if (rpdb_mark_node_compare(node,*pNode)){ + printf("%s,%d,mark = %d\n",__FUNCTION__,__LINE__,pNode->mark); + return pNode; + } + } + + return NULL; +} + +/* + * mark +*/ +int rpdb_mark_hash_add(struct rpdb_mark node) +{ + + struct rpdb_mark *pNode = NULL; + int hash = 0; + + pNode = rpdb_mark_search(node); + if (pNode != NULL) + { + return pNode->mark; + } + + pNode = (struct rpdb_mark*)malloc(sizeof(struct rpdb_mark)); + if (NULL == pNode) + { + return false; + } + + hash = rpdb_ip_hash(node); + node.mark = ++gRpdbMark; + memcpy((char*)pNode,(char*)&node,sizeof(struct rpdb_mark)); + + printf("%s,%d,%d,%d\n",__FUNCTION__,__LINE__,pNode->ip.ip4.s_addr,pNode->mark); + /* + 节点添加到链尾部 + */ + list_add_tail(&pNode->list,&gRpdbMarkList[hash]); + + return gRpdbMark; +} + + +/* + * 根据下一跳地址生成mark +*/ +int rpdb_gen_mark(const char* gateway) +{ + in_addr_t addr; + if (NULL == gateway) + { + return -1; + } + + addr = inet_addr(gateway); + struct rpdb_mark node; + node.ip.ip4.s_addr = addr; + return rpdb_mark_hash_add(node); +} + +/* + * 路由添加接口 +*/ +bool rpdb_add_route(const char* gateway,const char *tbl_name) +{ + char cmd[256] = {0}; + int status = 0; + char table_name[128] = {0}; + int mark = 0; + if (tbl_name == NULL) + { + memset(table_name,0,sizeof(table_name)); + sprintf(table_name,"table_%s",gateway); + } + else + { + if (strlen(tbl_name) < 1) /* 检查name的合法性*/ + { + memset(table_name,0,sizeof(table_name)); + sprintf(table_name,"%s",tbl_name); + } + else + { + return false; + } + } + + if (rpdb_add_delete_table(gateway,tbl_name,RPDB_TABLE_ADD) == false) + { + return false; + } + + if (strstr(":",gateway)) + { + sprintf(cmd,"ip -6 route add default via %s table %s",gateway,table_name); + } + else + { + sprintf(cmd,"ip route add default via %s table %s",gateway,table_name); + } + + printf("%s\n",cmd); + rpdb_popen(cmd); + + mark = rpdb_gen_mark(gateway); + memset(cmd,0,sizeof(cmd)); + sprintf(cmd,"ip rule add fwmark %d table %s",mark,table_name); + printf("%s\n",cmd); + rpdb_popen(cmd); + + return 0; +} + + +int main() +{ + //ipaddr_match("192.168.1.1",1); + + //ipaddr_match("192.168.1.300",1); + + //ipaddr_match("2000:0:0:0:0:0:0:1 ",2); + //ipaddr_match("fe80:0000:0000:0000:0204:61ff:fe9d:ffffff15",2); + struct rpdb_mark mark_value; + struct rpdb_mark mark_value1; + in_addr_t addr; + rpdb_init_route(); + rpdb_add_delete_table("1.1.2.1",NULL,RPDB_TABLE_ADD); + rpdb_add_delete_table("1.1.2.1",NULL,RPDB_TABLE_ADD); + rpdb_add_delete_table("1.2.2.1",NULL,RPDB_TABLE_ADD); + rpdb_add_delete_table("2.1.2.1",NULL,RPDB_TABLE_ADD); + + rpdb_add_delete_table("2.1.2.1",NULL,RPDB_TABLE_DEL); + //rpdb_add_delete_table("2.1.2.1",NULL,RPDB_TABLE_DEL); + //rpdb_add_delete_table("1.1.2.1",NULL,RPDB_TABLE_DEL); + addr = inet_addr("2006.6.6.6"); + mark_value.ip.ip4.s_addr = addr; + rpdb_mark_hash_add(mark_value); + rpdb_mark_hash_add(mark_value); + rpdb_mark_hash_add(mark_value); + rpdb_mark_hash_add(mark_value); + + addr = inet_addr("7.7.7.7"); + mark_value1.ip.ip4.s_addr = addr; + rpdb_mark_hash_add(mark_value1); + rpdb_mark_hash_add(mark_value1); + + + + rpdb_add_route("1.2.3.3",NULL); + rpdb_add_route("2.2.4.3",NULL); + rpdb_add_route("3.2.4.3",NULL); + rpdb_add_route("4.2.4.3",NULL); + + return 0; +} diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index 7ef36bfdd..08fca2ebf 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -9,46 +10,64 @@ #include "sev_sched.h" #define LOG_CONF_COSOLE_FILE_NAME "log-console.conf" - #define LOG_REDIRECT_CONSOLE "/dev/console" +#define PROC_SERIAL_INFO_PATH "/proc/tty/driver/serial" + +#define SERIAL_DRIVER_PREFIX "uart" +#define SERIAL_NO_DRIVER_KEY SERIAL_DRIVER_PREFIX":unknown" +#define SERIAL_PREFIX "ttyS" + +#ifndef CM_LOG_CONF_CONSOLE_FILE +#define CM_LOG_CONF_CONSOLE_FILE "/etc/rsyslog.d/log-console.conf" +#endif static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg) { - DIR *dir; - - if ((dir = opendir(LOG_DEV_DIR)) == NULL) { - ULOG_ERR(g_log, "Open dir:[%s] is failure:%d", LOG_DEV_DIR, strerror(errno)); - return -1; + int ret = -1; + FILE *driver_fp = NULL; + driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r"); + if (driver_fp == NULL) { + ULOG_ERR(g_log, "Opening file:%s is failure:%s", PROC_SERIAL_INFO_PATH, strerror(errno)); + return ret; } - struct dirent *ptr; + char *line = NULL; + size_t n; + int num; char path[MAX_PATH_SZ]; - while ((ptr = readdir(dir)) != NULL) { - if ((strcmp(ptr->d_name, ".") == 0) - || (strcmp(ptr->d_name, "..") == 0) - || (ptr->d_type == DT_DIR)) { ///current dir OR parrent dir - ULOG_DEBUG(g_log,"The file:[%s] or directory jump over", ptr->d_name); - continue; - } - - if ((strstr(ptr->d_name, "ttyS") == NULL)) { - ULOG_DEBUG(g_log,"The file:[%s] isn't redirected", ptr->d_name); + while ((n = getline(&line, &n, driver_fp)) != -1) { + ULOG_DEBUG(g_log, "Serial line:%s", line); + if (strstr(line, SERIAL_DRIVER_PREFIX) == NULL) { + ULOG_DEBUG(g_log, "%s isn't driver line", line); continue; } + + num = atoi(line); + if (strstr(line, SERIAL_NO_DRIVER_KEY) != NULL) { + ULOG_DEBUG(g_log, "%s%d don't have serial", SERIAL_PREFIX, num); + continue; + } - ULOG_DEBUG(g_log, "ttyS name:%s", ptr->d_name); - if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_DIR, ptr->d_name) < 0) { - ULOG_ERR(g_log, "Setting %s of log console is failure", ptr->d_name); - return -1; + + if (snprintf(path, sizeof(path), "%s%s%d", LOG_DEV_DIR, SERIAL_PREFIX, num) < 0) { + ULOG_ERR(g_log, "Setting %s%d of log console is failure", SERIAL_PREFIX, num); + goto END; } + ULOG_DEBUG(g_log, "ttyS name:%s", path); if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) { ULOG_ERR(g_log, "Writing tty[module:%s] of log is failure", filter_mod); - return -1; + goto END; } - - } + } + + ret = 0; +END: + if (line != NULL) { + free(line); + } - return 0; + fclose(driver_fp); + return ret; } @@ -111,3 +130,72 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer */ } + +ret_code console_initial() +{ + ret_code ret = RET_ERR; + FILE *fp = NULL; + char *pos = NULL; + char *pos2 = NULL; + char ttyfile_str[128] = ""; + int str_len = 0; + + fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r"); + if (NULL == fp) { + return ret; + } + + if (fseek(fp, 0, SEEK_SET) == -1) + { + ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno)); + + fclose(fp); + return ret; + } + + ssize_t n; + char *line = NULL; + while ((getline(&line, &n, fp)) != -1) + { + pos = strstr(line, "/"); + if (pos != NULL) + { + if ((pos2 = strstr(pos, " ")) != NULL) + { + str_len = strlen(pos) - strlen(pos2); + } + else + { + str_len = strlen(pos); + } + + memset(ttyfile_str, 0, sizeof(ttyfile_str)); + strncpy(ttyfile_str, pos, str_len); + + /* 滤除掉段尾的回车换行 */ + if ('\n' == ttyfile_str[strlen(ttyfile_str)-1]) + { + ttyfile_str[strlen(ttyfile_str)-1] = '\0'; + } + + + if(modify_authorizing(ttyfile_str) == RET_OK) + { + ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str); + } + else + { + ULOG_DEBUG(g_log, "Modify authorizing %s failed.", ttyfile_str); + } + } + } + + ret = RET_OK; + if (NULL != fp) + { + fclose(fp); + } + return ret; + +} + diff --git a/Platform/user/ulog/log-sched/log_console.h b/Platform/user/ulog/log-sched/log_console.h index 9296cb79f..9c73ffd70 100755 --- a/Platform/user/ulog/log-sched/log_console.h +++ b/Platform/user/ulog/log-sched/log_console.h @@ -6,5 +6,7 @@ #include "rpc_common.h" void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data); +ret_code console_initial(); + #endif diff --git a/Platform/user/ulog/log-sched/log_pty.c b/Platform/user/ulog/log-sched/log_pty.c index 419d0681c..f1a981f41 100755 --- a/Platform/user/ulog/log-sched/log_pty.c +++ b/Platform/user/ulog/log-sched/log_pty.c @@ -1,22 +1,170 @@ #include -#include +#include #include #include +#include +#include +#include +#include #include "log_pty.h" #include "log_types.h" #include "log_common.h" +#include "ret_errno.h" +#define MAX_EVENT_NUMBER 64 #define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/" #define LOG_CONF_PTY_FILE_NAME "log-pty.conf" +int g_epoll_fd = -1; +int g_watch_fd = -1; +int g_inotify_fd = -1; +pthread_t g_monitor_thread; + +static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg); + +static void *pty_monitor_thread(void *arg) +{ + struct epoll_event events[MAX_EVENT_NUMBER]; + int ret; + char buf[MAX_LINE_SZ]; + ssize_t len; + char *ptr; + struct inotify_event *inotify_ev; + + ULOG_DEBUG(g_log, "Monitor pty is begining"); + while (1) { + //ULOG_DEBUG(g_log, "Epoll is waiting"); + ret = epoll_wait(g_epoll_fd, events, MAX_EVENT_NUMBER, 1000); + if (ret == -1) { + if (errno == EBADF) { + ULOG_DEBUG(g_log, "Epoll has been shut or invalid"); + } else { + ULOG_ERR(g_log, "Waiting epoll is failure:%s, code:%d", strerror(errno), errno); + } + break; + } + if (ret == 0) { // 超时 + continue; + } + + for (int i = 0; i < MAX_EVENT_NUMBER; i++) { + ULOG_DEBUG(g_log, "Epoll event value is 0x%x", events[i].events); + if ((events[i].events & EPOLLIN) != EPOLLIN) { + continue; + } + len = read(g_inotify_fd, buf, sizeof(buf)); + if ((len == -1) && (errno != EAGAIN)) { + ULOG_ERR(g_log, "Reading inotify is failure:%s", strerror(errno)); + break; + } + if (len <= 0) { + continue; + } + + for (ptr = buf; ptr < buf + len; + ptr += sizeof(struct inotify_event) + inotify_ev->len) { + inotify_ev = (struct inotify_event *) ptr; + if (((inotify_ev->mask & IN_CREATE) != IN_CREATE) + && ((inotify_ev->mask & IN_DELETE) != IN_DELETE)) { + ULOG_DEBUG(g_log, "Current ev mask:%u, anything willn't be done", inotify_ev->mask); + continue; + } + + // sleep一下,防止权限修改不成功 + sleep(1); + + ULOG_DEBUG(g_log, "Current ev mask:%u, wo will write configure and restart rsyslog", inotify_ev->mask); + log_conf(LOG_INFO, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, NULL, + write_pty_content, NULL); + + if (log_sev_restart() != 0) { + ULOG_ERR(g_log, "Pty monitor restart rsyslog 2 is failure"); + } + } + } + + } + + ULOG_ERR(g_log, "Monitor pty is end"); +} + +static void close_monitor() +{ + if (g_epoll_fd != -1) { + close(g_epoll_fd); + g_epoll_fd = -1; + } + + if (g_watch_fd != -1) { + inotify_rm_watch(g_inotify_fd, g_watch_fd); + close(g_watch_fd); + g_watch_fd = -1; + } + if (g_inotify_fd != -1) { + close(g_inotify_fd); + g_inotify_fd = -1; + } +} + +static ret_code start_dev_pty_monitor() +{ + if (g_inotify_fd != -1) { + ULOG_ERR(g_log, "Monitoring pty has started up, value:%d", g_inotify_fd); + return RET_OK; + } + + g_inotify_fd = inotify_init(); + if (g_inotify_fd == -1) { + ULOG_ERR(g_log, "Initiating file notify is failure:%s", strerror(errno)); + return RET_ERR; + } + g_watch_fd = inotify_add_watch(g_inotify_fd, LOG_DEV_PTY_DIR, IN_CREATE | IN_DELETE); + if(g_watch_fd == -1) { + ULOG_ERR(g_log, "Intify add watch is failure:%s", strerror(errno)); + goto FAIL; + } + + g_epoll_fd = epoll_create1(0); + if (g_epoll_fd == -1) { + ULOG_ERR(g_log, "Creating epoll is failure:%s", strerror(errno)); + goto FAIL; + } + + struct epoll_event ev; + ev.events = EPOLLIN; + ev.data.fd = g_inotify_fd; + if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, g_inotify_fd, &ev) == -1) { + ULOG_ERR(g_log, "Setting epoll is failure:%s", strerror(errno)); + goto FAIL; + } + + int ret = pthread_create(&g_monitor_thread, NULL, pty_monitor_thread, NULL); + if (ret != 0) { + ULOG_ERR(g_log, "Creating monitor thread is failure:%d", ret); + goto FAIL; + } + + return RET_OK; +FAIL: + close_monitor(); + return RET_ERR; +} + +static void stop_dev_pty_monitor() +{ + ULOG_DEBUG(g_log, "Stopping dev pty monitor"); + close_monitor(); + pthread_join(g_monitor_thread, NULL); +} + static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg) { DIR *dir; if ((dir = opendir(LOG_DEV_PTY_DIR)) == NULL) { - ULOG_ERR(g_log, "Open dir:[%s] is failure:%d\n", LOG_DEV_PTY_DIR, strerror(errno)); + ULOG_ERR(g_log, "Open dir:[%s] is failure:%d", LOG_DEV_PTY_DIR, strerror(errno)); return -1; } @@ -45,7 +193,12 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v return -1; } - } + } + + if (start_dev_pty_monitor() != RET_OK) { + ULOG_ERR(g_log, "Starting pty monitor is failure"); + return -1; + } return 0; } @@ -56,7 +209,8 @@ static int config_log_pty(const log_pty_t *conf) switch (conf->on) { - case LOG_OFF: + case LOG_OFF: + stop_dev_pty_monitor(); ret = log_off_with_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME); break; case LOG_ON: diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index f34fda764..df4b06451 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -23,6 +23,17 @@ ulog_t *g_log = NULL; FILE *g_conf_fp; char g_conf_file[MAX_PATH_SZ]; +typedef ret_code (*initial_cb)(); +typedef struct _log_initial { + char type[20]; + initial_cb cb; +} log_initial_t; + +log_initial_t g_log_initial[] = { + {"console", console_initial} +}; + + void signal_exit() { log_sev_exit(); @@ -47,7 +58,7 @@ int main(int argc, char **argv) g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon); if (g_log == NULL) { - fprintf(stderr, "Initiating ulog is failure"); + fprintf(stderr, "Initiating ulog is failure\n"); return -1; } @@ -65,6 +76,11 @@ int main(int argc, char **argv) } } + /* 各类配置初始化 */ + for (int i = 0; i < (sizeof(g_log_initial) / sizeof(log_initial_t)); i++) { + g_log_initial[i].cb(); + } + rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME); if (server == NULL) { diff --git a/Platform/user/ulog/ulog-api/ulog_api.c b/Platform/user/ulog/ulog-api/ulog_api.c index 4cdd75a31..5c84de244 100755 --- a/Platform/user/ulog/ulog-api/ulog_api.c +++ b/Platform/user/ulog/ulog-api/ulog_api.c @@ -13,19 +13,27 @@ ulog_t *ulog_init(const char *module_name, u8 is_print) { ulog_t *log; - u32 len = strlen(module_name); - + u32 len = 0; + + if (NULL == module_name) { + fprintf(stderr, "Bad input: module_name is NULL\n"); + return NULL; + } + + len = strlen(module_name); + if (len > MAX_MODULE_NAME_SZ) { - fprintf(stderr, "The length:%d of module_name can't more than %d", len, MAX_MODULE_NAME_SZ); + fprintf(stderr, "The length:%d of module_name can't more than %d\n", len, MAX_MODULE_NAME_SZ); return NULL; } log = (ulog_t *)malloc(sizeof(*log)); if (log == NULL) { - fprintf(stderr, "Allocating log memory is failure"); + fprintf(stderr, "Allocating log memory is failure\n"); return NULL; } strncpy(log->module_name, module_name, len); + log->module_name[len] = '\0'; int opt = LOG_PERROR |LOG_PID; if (is_print > 0) { @@ -47,7 +55,7 @@ void ulog_close(ulog_t *log) void ulog_record(const ulog_t *log, int level, const char *fmt, ...) { if (log == NULL) { - fprintf(stderr, "Log is null"); + fprintf(stderr, "Log is null\n"); return; } diff --git a/Platform/user/ulog/ulog-test/ulog_test.c b/Platform/user/ulog/ulog-test/ulog_test.c new file mode 100644 index 000000000..15cda4b88 --- /dev/null +++ b/Platform/user/ulog/ulog-test/ulog_test.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +#include "ulog_api.h" +#include "ulog_in.h" + + +ulog_t *g_log = NULL; + + +static void test_ulog_api() +{ + ULOG_DEBUG (g_log, "test for ulog_api %s", "debug"); + ULOG_INFO (g_log, "test for ulog_api %s", "info"); + ULOG_NOTICE (g_log, "test for ulog_api %s", "notice"); + ULOG_WARNING(g_log, "test for ulog_api %s", "warning"); + ULOG_ERR (g_log, "test for ulog_api %s", "err"); + ULOG_CRIT (g_log, "test for ulog_api %s", "crit"); + ULOG_ALERT (g_log, "test for ulog_api %s", "alert"); + ULOG_EMERG (g_log, "test for ulog_api %s", "emerg"); +} + +static void ulog_test_usage(const char *pname) +{ + if (NULL == pname) + { + return; + } + + fprintf(stderr, "--------------------------------------------------------\n"); + fprintf(stderr, " usage of %s:\n", pname); + fprintf(stderr, " %s [-d] [-a module_name] [-h]\n", pname); + fprintf(stderr, " \n", pname); + fprintf(stderr, " -d: daemon\n", pname); + fprintf(stderr, " -a: set module name, no longer than 16 bytes\n"); + fprintf(stderr, " -h: help\n"); + fprintf(stderr, "--------------------------------------------------------\n"); +} + +/* usage: + test_ulog_api + test_ulog_api -a test_ulog_api + test_ulog_api -a test2 + test_ulog_api -a 123456789012345 + test_ulog_api -a 1234567890123456 + test_ulog_api -a 12345678901234567 + + test_ulog_api -d + test_ulog_api -d -a test_ulog_api + test_ulog_api -d -a test2 + test_ulog_api -d -a 123456789012345 + test_ulog_api -d -a 1234567890123456 + test_ulog_api -d -a 12345678901234567 +*/ +int main(int argc, char **argv) +{ + char *options = "da:h"; + int opt; + u8 run_daemon = 0; + char module_name[MAX_MODULE_NAME_SZ+4] = ""; + + while ((opt = getopt(argc, argv, options)) != -1) { + switch (opt) { + case 'd': + run_daemon = 1; + break; + case 'a': + memset(module_name, 0, MAX_MODULE_NAME_SZ+4); + strncpy(module_name, optarg, MAX_MODULE_NAME_SZ+3); + break; + case 'h': + ulog_test_usage(argv[0]); + return 0; + } + } + + g_log = ulog_init(module_name, run_daemon); + if (NULL == g_log) + { + goto END; + } + + if (run_daemon) { + if (daemon(0, 0) == -1) { + ULOG_ERR(g_log, "Setting daemon running is failure:%s", strerror(errno)); + goto END; + } + } + + test_ulog_api(); + +END: + if (NULL != g_log) + { + ulog_close(g_log); + } + return 0; +} diff --git a/build_rootfs.sh b/build_rootfs.sh index a1771fc94..66e5496b7 100755 --- a/build_rootfs.sh +++ b/build_rootfs.sh @@ -1,5 +1,6 @@ #!/bin/sh -v + user=$(whoami) cd /home/${user}/secogateway/kernel/ @@ -14,12 +15,14 @@ echo $(cp /home/${user}/secogateway/_install/debug/targets/ARM64/*.ko lib/module echo $(cp /home/${user}/secogateway/_install/debug/targets/ARM64/*.so usr/Product_usr/) echo $(cp /home/${user}/secogateway/_install/debug/targets/ARM64/*.so usr/lib/) echo $(cp /home/${user}/secogateway/_install/debug/targets/ARM64/*.exe usr/Product_usr/) +echo $(cp -rf /home/${user}/secogateway/libs/files usr/Product_usr/) +echo $(cp -rf /opt/huachen_sysroot/usr/* usr/) echo $(mkdir customize_service) echo $(rm /home/${user}/secogateway/kernel/rootfs/etc/systemd/system/multi-user.target.wants/platform*.service) -#echo $(rm /home/${user}/secogateway/kernel/rootfs/etc/systemd/system/multi-user.target.wants/product*.service) - +echo $(rm /home/${user}/secogateway/kernel/rootfs/etc/systemd/system/multi-user.target.wants/product*.service) +echo $(cp -rf /home/${user}/secogateway/systemd_service/*.service /customize_service/) echo $(ln -s /customize_service/* /home/${user}/secogateway/kernel/rootfs/etc/systemd/system/multi-user.target.wants/) diff --git a/libs/src/lighttpd-1.4.51/src/mod_webm.c b/libs/src/lighttpd-1.4.51/src/mod_webm.c index e62a09694..26017deb8 100644 --- a/libs/src/lighttpd-1.4.51/src/mod_webm.c +++ b/libs/src/lighttpd-1.4.51/src/mod_webm.c @@ -23,10 +23,10 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1, WEBM_HANDLE_LOGIN, WEBM_HANDLE_HOMEPAGE, - /* ������ҳ��ȡ��չʾ��case�������������ܿ���ͨ�����ݿ��ѯ�������ȷŵ�һ�� */ + /* ҳȡչʾcaseܿͨݿѯȷŵһ */ WEBM_HANDLE_CONFIG_LIST_GROUP, - /* ���������ò�����ص�case */ + /* òصcase */ WEBM_HANDLE_CONFIG_ADD_GROUP, WEBM_HANDLE_CONFIG_UUID_GROUP, WEBM_HANDLE_CONFIG_MOD_GROUP, @@ -40,7 +40,12 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1, WEBM_HANDLE_CONFIG_IPV4, WEBM_HANDLE_CONFIG_VLAN_SET, WEBM_HANDLE_CONFIG_VLAN_GET, - WEBM_HANDLE_MAX + WEBM_HANDLE_MAX, + + WEBM_HANDLE_CONFIG_MOD_AUTHPARA, + WEBM_HANDLE_CONFIG_ADD_AUTHRULE, + WEBM_HANDLE_CONFIG_MOD_AUTHRULE, + WEBM_HANDLE_CONFIG_DEL_AUTHRULE } webm_handle_index; typedef struct _webm_config_st @@ -185,6 +190,37 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg CM_CONFIG_GET, \ VLAN_CONFIG, \ webm_config_send_proc \ + }, \ + {\ + WEBM_HANDLE_CONFIG_MOD_AUTHPARA, \ + "/FSG-CF/userauth-parameters-mod", \ + CM_CONFIG_SET, \ + FREEPARAMETERS_CONFIG , \ + webm_config_send_proc \ + }, \ +\ + {\ + WEBM_HANDLE_CONFIG_ADD_AUTHRULE, \ + "/FSG-GF/userauth-rule-add", \ + CM_CONFIG_SET, \ + AUTHFREE_CONFIG, \ + webm_config_send_proc \ + }, \ +\ + {\ + WEBM_HANDLE_CONFIG_MOD_AUTHRULE, \ + "/FSG-GF/userauth-rule-mod", \ + CM_CONFIG_SET, \ + AUTHFREE_CONFIG, \ + webm_config_send_proc \ + }, \ +\ + {\ + WEBM_HANDLE_CONFIG_DEL_AUTHRULE, \ + "/FSG-GF/userauth-rule-del", \ + CM_CONFIG_SET, \ + AUTHFREE_CONFIG, \ + webm_config_send_proc \ } \ \ } diff --git a/patchs/mysql/0001-aarch64-mysql-5.7.27-cmake-cross-compile-and-fix-compile-error.patch b/patchs/mysql-5.3.27/0001-aarch64-mysql-5.7.27-cmake-cross-compile-and-fix-compile-error.patch similarity index 100% rename from patchs/mysql/0001-aarch64-mysql-5.7.27-cmake-cross-compile-and-fix-compile-error.patch rename to patchs/mysql-5.3.27/0001-aarch64-mysql-5.7.27-cmake-cross-compile-and-fix-compile-error.patch diff --git a/patchs/mysql/cmake_cmd.txt b/patchs/mysql-5.3.27/cmake_cmd.txt similarity index 100% rename from patchs/mysql/cmake_cmd.txt rename to patchs/mysql-5.3.27/cmake_cmd.txt diff --git a/patchs/mysql-connector-5.3.13/0001-aarch64-cmake-cross-compile.patch b/patchs/mysql-connector-5.3.13/0001-aarch64-cmake-cross-compile.patch new file mode 100644 index 000000000..c1f45a793 --- /dev/null +++ b/patchs/mysql-connector-5.3.13/0001-aarch64-cmake-cross-compile.patch @@ -0,0 +1,36 @@ +--- mysql-connector-odbc-5.3.13-src/CMakeLists.txt 2019-04-16 00:56:34.000000000 +0800 ++++ mysql-connector-odbc-5.3.13-src_arm/CMakeLists.txt 2019-08-28 11:42:59.514993586 +0800 +@@ -56,6 +56,33 @@ endmacro() + endif() + + #----------------------------------------------------- ++if(PLAT_ARM64) ++ # this one is important ++ SET(CMAKE_SYSTEM_NAME Linux) ++ #this one not so much ++ SET(CMAKE_SYSTEM_VERSION 1) ++ # this is install root directory ++ SET(CMAKE_INSTALL_PREFIX /usr) ++ ++ # specify the cross compiler ++ SET(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) ++ SET(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) ++ SET(CMAKE_STRIP aarch64-fsl-linux-strip) ++ ++ # specify the cross compile and link flags ++ set(CMAKE_C_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}") ++ set(CMAKE_SHARED_LINKER_FLAGS "--sysroot=$ENV{SDKTARGETSYSROOT}") ++ SET(CMAKE_LIBRARY_PATH $ENV{SDKTARGETSYSROOT}/usr/lib) ++ ++ # where is the target environment ++ SET(CMAKE_FIND_ROOT_PATH ${SDKTARGETSYSROOT}) ++ ++ # search for programs in the build host directories ++ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) ++ # for libraries and headers in the target directories ++ SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) ++ SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) ++endif() + + FIND_PACKAGE(Threads) + diff --git a/patchs/mysql-connector-5.3.13/cmake_cmd.txt b/patchs/mysql-connector-5.3.13/cmake_cmd.txt new file mode 100644 index 000000000..8c9a9846d --- /dev/null +++ b/patchs/mysql-connector-5.3.13/cmake_cmd.txt @@ -0,0 +1,3 @@ +cmake -G "Unix Makefiles" -DPLAT_ARM64=TRUE ../ -DWITH_UNIXODBC=TRUE -DSIZEOF_INT=4 \ + -DHAVE_POSIX_TIMERS=TRUE -DHAVE_STRUCT_TIMESPEC=TRUE -DSIZEOF_CHARP=4 \ + -DHAVE_PWD_H=TRUE -DHAVE_GETRUSAGE=FALSE -DDISABLE_GUI=TRUE \ No newline at end of file