Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
9c3e989ff9
|
@ -32,6 +32,9 @@
|
||||||
/*nat config */
|
/*nat config */
|
||||||
#define NAT_CONFIG_MODULE 0x00000008
|
#define NAT_CONFIG_MODULE 0x00000008
|
||||||
|
|
||||||
|
/*static routing*/
|
||||||
|
#define STATIC_ROUTING_CONFIG_MODULE 0x00000009
|
||||||
|
|
||||||
/************************* 模块定义结束 **********************/
|
/************************* 模块定义结束 **********************/
|
||||||
|
|
||||||
/************************ config id定义 **********************/
|
/************************ config id定义 **********************/
|
||||||
|
@ -69,8 +72,8 @@
|
||||||
|
|
||||||
#define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1)
|
#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**********************/
|
/************************ config id定义 end**********************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#define MAX_MODULE_NAME_SZ 16
|
#define MAX_MODULE_NAME_SZ 16
|
||||||
|
|
||||||
typedef struct _klog {
|
typedef struct _klog {
|
||||||
char module_name[MAX_MODULE_NAME_SZ];
|
char module_name[MAX_MODULE_NAME_SZ+1];
|
||||||
}klog_t;
|
}klog_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#define MAX_MODULE_NAME_SZ 16
|
#define MAX_MODULE_NAME_SZ 16
|
||||||
|
|
||||||
typedef struct _ulog {
|
typedef struct _ulog {
|
||||||
char module_name[MAX_MODULE_NAME_SZ];
|
char module_name[MAX_MODULE_NAME_SZ+1];
|
||||||
} ulog_t;
|
} ulog_t;
|
||||||
|
|
||||||
ulog_t *ulog_init(const char *module_name, u8 is_print);
|
ulog_t *ulog_init(const char *module_name, u8 is_print);
|
||||||
|
|
|
@ -14,9 +14,14 @@ module device-status {
|
||||||
grouping cpu-status {
|
grouping cpu-status {
|
||||||
container cpu-infos {
|
container cpu-infos {
|
||||||
description "CPU的状态信息";
|
description "CPU的状态信息";
|
||||||
leaf usage-rate {
|
list cpu-info {
|
||||||
type int16 {
|
leaf position {
|
||||||
range "0..100";
|
type string ;
|
||||||
|
}
|
||||||
|
leaf usage-rate {
|
||||||
|
type int16 {
|
||||||
|
range "0..100";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +30,17 @@ module device-status {
|
||||||
grouping mem-status {
|
grouping mem-status {
|
||||||
container memory-infos {
|
container memory-infos {
|
||||||
description "内存的状态信息";
|
description "内存的状态信息";
|
||||||
leaf memory-total {
|
list memory-info {
|
||||||
type int64 ;
|
leaf position {
|
||||||
}
|
type string ;
|
||||||
leaf usage-rate {
|
}
|
||||||
type int16 {
|
leaf memory-total {
|
||||||
range "0..100";
|
type int64 ;
|
||||||
|
}
|
||||||
|
leaf usage-rate {
|
||||||
|
type int16 {
|
||||||
|
range "0..100";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,8 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import org.opendaylight.controller.md.sal.binding.api.*;
|
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.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.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;
|
||||||
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.CpuInfos;
|
||||||
import org.opendaylight.yang.gen.v1.http.www.huawei.com.netconf.vrp.huawei.devm.rev181123.devm.MemoryInfos;
|
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.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.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.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.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.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.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.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.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.TpInfosBuilder;
|
||||||
import org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.tp.extension.rev190809.tp.status.tp.infos.IpAddress;
|
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<ConnectorInf
|
||||||
} catch (ReadFailedException e) {
|
} catch (ReadFailedException e) {
|
||||||
throw new IllegalStateException("Unexpected error reading data from " + nodeId, e);
|
throw new IllegalStateException("Unexpected error reading data from " + nodeId, e);
|
||||||
}
|
}
|
||||||
List<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos> ifcList = new ArrayList<>();
|
List<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.cpu.infos.CpuInfo> ifcList = new ArrayList<>();
|
||||||
if (cupInfos.isPresent()) {
|
if (cupInfos.isPresent()) {
|
||||||
List<CpuInfo> cpuInfoList = cupInfos.get().getCpuInfo();
|
List<CpuInfo> cpuInfoList = cupInfos.get().getCpuInfo();
|
||||||
for (CpuInfo cpuInfo : cpuInfoList) {
|
for (CpuInfo cpuInfo : cpuInfoList) {
|
||||||
LOG.info("Show cpu with serial {},cpu usage is {} ",
|
LOG.info("Show cpu with serial {},cpu usage is {} ",
|
||||||
cpuInfo.getKey().getPosition(), cpuInfo.getSystemCpuUsage());
|
cpuInfo.getKey().getPosition(), cpuInfo.getSystemCpuUsage());
|
||||||
CpuInfosBuilder builder = new CpuInfosBuilder();
|
org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.cpu.infos.CpuInfo temp =
|
||||||
org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos temp = builder.setUsageRate(cpuInfo.getSystemCpuUsage().shortValue()).build();
|
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);
|
ifcList.add(temp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("No data present on path '{}' for mountpoint: {}",
|
LOG.info("No data present on path '{}' for mountpoint: {}",
|
||||||
iid, nodeId);
|
iid, nodeId);
|
||||||
}
|
}
|
||||||
|
CpuInfosBuilder cpuInfosBuilder = new CpuInfosBuilder().setCpuInfo(ifcList);
|
||||||
//write cpu information to layer
|
//write cpu information to layer
|
||||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos> cpuIid = NETCONF_TOPO_IID
|
InstanceIdentifier<NodeCpu> cpuIid = NETCONF_TOPO_IID
|
||||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
||||||
.augmentation(NodeCpu.class)
|
.augmentation(NodeCpu.class);
|
||||||
.child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.cpu.status.CpuInfos.class);
|
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
||||||
for (int i = 0; i < ifcList.size(); i++) {
|
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, cpuIid,
|
||||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
new NodeCpuBuilder()
|
||||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, cpuIid, ifcList.get(i));
|
.setCpuInfos(cpuInfosBuilder.build())
|
||||||
Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
|
.build()
|
||||||
@Override
|
);
|
||||||
public void onFailure(Throwable throwable) {
|
Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable throwable) {
|
||||||
|
if (throwable instanceof OptimisticLockFailedException) {
|
||||||
|
LOG.warn("Write cpu information 捕获 乐观锁异常,本次获取忽略!");
|
||||||
|
} else {
|
||||||
LOG.error("Write cpu information failed." + throwable.getMessage());
|
LOG.error("Write cpu information failed." + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Void avoid) {
|
public void onSuccess(Void avoid) {
|
||||||
LOG.info("Write cpu information success.");
|
LOG.info("Write cpu information success.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Identifier path is equivalent to:
|
// Identifier path is equivalent to:
|
||||||
// '.../yang-ext:mount/huawei-devm:devm/memoryInfos'
|
// '.../yang-ext:mount/huawei-devm:devm/memoryInfos'
|
||||||
|
@ -372,98 +381,110 @@ public class HuaweiNetconfSpeaker implements DataTreeChangeListener<ConnectorInf
|
||||||
} catch (ReadFailedException e) {
|
} catch (ReadFailedException e) {
|
||||||
throw new IllegalStateException("Unexpected error reading data from " + nodeId, e);
|
throw new IllegalStateException("Unexpected error reading data from " + nodeId, e);
|
||||||
}
|
}
|
||||||
List<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos> memoryList = new ArrayList<>();
|
List<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.memory.infos.MemoryInfo> memoryList = new ArrayList<>();
|
||||||
if (memoryInfosOptional.isPresent()) {
|
if (memoryInfosOptional.isPresent()) {
|
||||||
List<MemoryInfo> memoryInfoList = memoryInfosOptional.get().getMemoryInfo();
|
List<MemoryInfo> memoryInfoList = memoryInfosOptional.get().getMemoryInfo();
|
||||||
for (MemoryInfo memoryInfo : memoryInfoList) {
|
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());
|
memoryInfo.getKey().getPosition(), memoryInfo.getDoMemoryUsage());
|
||||||
MemoryInfosBuilder builder = new MemoryInfosBuilder();
|
|
||||||
LOG.info("Huawei Device {} OsMemoryTotal is: {}", nodeId, memoryInfo.getOsMemoryTotal());
|
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()).
|
org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.memory.infos.MemoryInfo temp =
|
||||||
setUsageRate(memoryInfo.getOsMemoryUsage().shortValue()).build();
|
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);
|
memoryList.add(temp);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("No data present on path '{}' for mountpoint: {}",
|
LOG.info("No data present on path '{}' for mountpoint: {}",
|
||||||
iid, nodeId);
|
iid, nodeId);
|
||||||
}
|
}
|
||||||
|
MemoryInfosBuilder memoryInfosBuilder = new MemoryInfosBuilder().setMemoryInfo(memoryList);
|
||||||
|
|
||||||
//write memory information to layer
|
//write memory information to layer
|
||||||
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos> customMemoryIID = NETCONF_TOPO_IID
|
InstanceIdentifier<NodeMemory> customMemoryIID = NETCONF_TOPO_IID
|
||||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
||||||
.augmentation(NodeMemory.class)
|
.augmentation(NodeMemory.class);
|
||||||
.child(org.opendaylight.yang.gen.v1.urn.cmcc.cmhi.adaptation.layer.device.status.rev190809.mem.status.MemoryInfos.class);
|
final WriteTransaction writeTransaction2 = dataBroker.newWriteOnlyTransaction();
|
||||||
for (int i = 0; i < memoryList.size(); i++) {
|
writeTransaction2.put(LogicalDatastoreType.OPERATIONAL, customMemoryIID,
|
||||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
new NodeMemoryBuilder()
|
||||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, customMemoryIID, memoryList.get(i));
|
.setMemoryInfos(memoryInfosBuilder.build())
|
||||||
Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
|
.build()
|
||||||
@Override
|
);
|
||||||
public void onFailure(Throwable throwable) {
|
Futures.addCallback(writeTransaction2.submit(), new FutureCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable throwable) {
|
||||||
|
if (throwable instanceof OptimisticLockFailedException) {
|
||||||
|
LOG.warn("Write memory information 捕获 乐观锁异常,本次获取忽略!");
|
||||||
|
} else {
|
||||||
LOG.error("Write memory information failed." + throwable.getMessage());
|
LOG.error("Write memory information failed." + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Void avoid) {
|
|
||||||
LOG.info("Write memory information success.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceIdentifier<Interfaces> interfacesIID =
|
|
||||||
InstanceIdentifier.create(Ifm.class).child(Interfaces.class);
|
|
||||||
|
|
||||||
Optional<Interfaces> 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<TpInfos> tpInfosList = new ArrayList<>();
|
|
||||||
if (interfacesOptional.isPresent()) {
|
|
||||||
List<Interface> 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<IpAddress> 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
|
// InstanceIdentifier<Interfaces> interfacesIID =
|
||||||
for (int i = 0; i < tpInfosList.size(); i++) {
|
// InstanceIdentifier.create(Ifm.class).child(Interfaces.class);
|
||||||
InstanceIdentifier<TpInfos> tpinfosIID = NETCONF_TOPO_IID
|
//
|
||||||
.child(Node.class, new NodeKey(new NodeId(nodeId)))
|
// Optional<Interfaces> interfacesOptional;
|
||||||
.child(TerminationPoint.class, new TerminationPointKey(new TpId(tpInfosList.get(i).getTpName())))
|
// try {
|
||||||
.augmentation(TpExt.class).child(TpInfos.class);
|
// // Read from a transaction is asynchronous, but a simple
|
||||||
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
|
// // get/checkedGet makes the call synchronous
|
||||||
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, tpinfosIID, tpInfosList.get(i));
|
// interfacesOptional = hwNodeReadTx.read(LogicalDatastoreType.OPERATIONAL, interfacesIID).checkedGet();
|
||||||
Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
|
// } catch (ReadFailedException e) {
|
||||||
@Override
|
// throw new IllegalStateException("Unexpected error reading data from " + nodeId, e);
|
||||||
public void onFailure(Throwable throwable) {
|
// }
|
||||||
LOG.error("Write tp information information failed." + throwable.getMessage());
|
// List<TpInfos> tpInfosList = new ArrayList<>();
|
||||||
}
|
// if (interfacesOptional.isPresent()) {
|
||||||
|
// List<Interface> interfaceList = interfacesOptional.get().getInterface();
|
||||||
@Override
|
// for (Interface intf : interfaceList) {
|
||||||
public void onSuccess(Void avoid) {
|
// LOG.info("Show memory with serial {},ipv4 config is {} ",
|
||||||
LOG.info("Write tp information information success.");
|
// intf.getKey().getIfName(), intf.getIpv4Config());
|
||||||
}
|
// TpInfosBuilder tpInfosBuilder = new TpInfosBuilder();
|
||||||
});
|
// List<IpAddress> 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<TpExt> 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<Void>() {
|
||||||
|
// @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.");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
Makefile
13
Makefile
|
@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
|
||||||
endif
|
endif
|
||||||
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)
|
ifeq ($(OPT), install)
|
||||||
#$(shell `find ../release -name "*.zip" -delete`)
|
#$(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
|
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f module.klog_api.test.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=test_klog_api
|
||||||
else
|
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
|
$(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
|
endif
|
|
@ -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
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
# target name, the target name must have the same name of c source file
|
# target name, the target name must have the same name of c source file
|
||||||
TARGET_NAME=configm
|
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 \
|
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 \
|
nat_config/natconfig.c \
|
||||||
vlan_config/vlan_config.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
|
# MRS Board Source Files
|
||||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -18,8 +18,8 @@ klog_t *klog_init(const char *module_name)
|
||||||
|
|
||||||
len = strlen(module_name);
|
len = strlen(module_name);
|
||||||
|
|
||||||
if (len >= MAX_MODULE_NAME_SZ) {
|
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);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ klog_t *klog_init(const char *module_name)
|
||||||
printk(KERN_ERR"Allocating log memory is failure");
|
printk(KERN_ERR"Allocating log memory is failure");
|
||||||
return NULL;
|
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);
|
strncpy(log->module_name, module_name, len);
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
|
|
|
@ -0,0 +1,296 @@
|
||||||
|
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/init.h>
|
||||||
|
#include <linux/timer.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
|
#include <linux/sysctl.h>
|
||||||
|
#include <linux/ip.h>
|
||||||
|
#include <linux/ipv6.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 三元组超时时间设置为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");
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,46 @@
|
||||||
#include "dhcp_lib.h"
|
#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)
|
char *getfileall(char *fname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
#include "../web_config/auth_recover_config.h"
|
#include "../web_config/auth_recover_config.h"
|
||||||
#include "natconfig.h"
|
#include "natconfig.h"
|
||||||
#include "vlan_config.h"
|
#include "vlan_config.h"
|
||||||
|
#include "dhcp_lib.h"
|
||||||
|
#include "static_routing.h"
|
||||||
|
|
||||||
|
|
||||||
#define RET_CODE_LEN 16
|
#define RET_CODE_LEN 16
|
||||||
#define RET_MSG_LEN 128
|
#define RET_MSG_LEN 128
|
||||||
|
@ -31,7 +34,11 @@
|
||||||
{ \
|
{ \
|
||||||
VLAN_CONFIG_MODULE, \
|
VLAN_CONFIG_MODULE, \
|
||||||
vlan_config_init \
|
vlan_config_init \
|
||||||
} \
|
}, \
|
||||||
|
{ \
|
||||||
|
DHCP_CONFIG_MODULE, \
|
||||||
|
dhcp_config_init \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -217,6 +224,78 @@
|
||||||
vlan_config_proc, \
|
vlan_config_proc, \
|
||||||
vlan_config_get, \
|
vlan_config_get, \
|
||||||
vlan_config_get_all \
|
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_ */
|
#endif /* RPC_COMMON_H_ */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,19 @@
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
#include "netconfig.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 *getfileall(char *fname);
|
||||||
|
|
||||||
char *getfilefirstline(char *fname);
|
char *getfilefirstline(char *fname);
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
#ifndef STATIC_ROUTING_H_
|
||||||
|
#define STATIC_ROUTING_H_
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
|
@ -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 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;
|
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);
|
pos = strstr(line, key_str);
|
||||||
if (pos != NULL)
|
if (pos != NULL)
|
||||||
{
|
{
|
||||||
/* 跳过key与value间的"=" */
|
/* 跳过key与value间的"=" */
|
||||||
strcpy(value_str, pos+strlen(key_str)+1);
|
strcpy(value_str, pos+strlen(key_str)+1);
|
||||||
|
|
||||||
/* 滤除掉段尾的回车换行 */
|
/* 滤除掉段尾的回车换行 */
|
||||||
if ('\n' == value_str[strlen(value_str)-1])
|
if ('\n' == value_str[strlen(value_str)-1])
|
||||||
{
|
{
|
||||||
value_str[strlen(value_str)-1] = '\0';
|
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 cm_log_check_file_is_exist(const char *file_str)
|
||||||
{
|
{
|
||||||
int is_exist = 0;
|
int is_exist = 0;
|
||||||
|
@ -91,7 +91,7 @@ int cm_log_check_file_is_exist(const char *file_str)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 如果文件存在,access返回0,不存在,access返回-1 */
|
/* 如果文件存在,access返回0,不存在,access返回-1 */
|
||||||
is_exist = ((access(file_str, 0) == 0) ? 1 : 0);
|
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.conf与log-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 cm_log_get_module_from_file(const char *file_str, char *value_str, int value_len)
|
||||||
{
|
{
|
||||||
ret_code ret = RET_ERR;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 适用于log-console.conf与log-pty.conf的解析 */
|
/* 适用于log-console.conf与log-pty.conf的解析 */
|
||||||
ret_code cm_log_get_level_from_file(const char *file_str, u8 *value)
|
ret_code cm_log_get_level_from_file(const char *file_str, u8 *value)
|
||||||
{
|
{
|
||||||
ret_code ret = RET_ERR;
|
ret_code ret = RET_ERR;
|
||||||
|
|
|
@ -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));
|
memset(log_file_conf, 0, sizeof(*log_file_conf));
|
||||||
|
|
||||||
/* level、path、is_compress、del_over_days暂未实现 */
|
/* level、path、is_compress、del_over_days暂未实现 */
|
||||||
|
|
||||||
/* 日志文件大小上限:del_over_size */
|
/* 日志文件大小上限:del_over_size */
|
||||||
memset(value, 0, MAX_LINE_SZ);
|
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)
|
if (cm_log_get_keyvalue_from_file(CM_LOG_CONF_LOGFILE_FILE, LOG_CONF_KEY_FILE_MAX_SIZE_STR, value, sizeof(value)) == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
memset(tmp_str, 0, sizeof(tmp_str));
|
||||||
|
|
||||||
/* 提取日志等级 */
|
/* 提取日志等级 */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
pos2 = strstr(pos, ".=");
|
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;
|
ret_host->level = (u8)tmp_value;
|
||||||
|
|
||||||
/* 提取IP地址 */
|
/* 提取IP地址 */
|
||||||
pos = strstr(pos2, "@");
|
pos = strstr(pos2, "@");
|
||||||
if (NULL == pos)
|
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);
|
strncpy(ret_host->host, pos, tmp_len);
|
||||||
|
|
||||||
|
|
||||||
/* 提取端口 */
|
/* 提取端口 */
|
||||||
pos2 ++;
|
pos2 ++;
|
||||||
pos = pos2;
|
pos = pos2;
|
||||||
pos2 = strstr(pos, ":");
|
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;
|
ret_host->port = (u16)tmp_value;
|
||||||
|
|
||||||
/* 提取日志存放格式 */
|
/* 提取日志存放格式 */
|
||||||
pos2++;
|
pos2++;
|
||||||
pos = 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')
|
if (hosts[cnt].host[0] == '\0')
|
||||||
{
|
{
|
||||||
/* 无效数据 */
|
/* 无效数据 */
|
||||||
memset(hosts+cnt, 0, sizeof(log_remote_host_x_t));
|
memset(hosts+cnt, 0, sizeof(log_remote_host_x_t));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1246,11 +1246,12 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if(!(operate = cJSON_GetObjectItem(root, "operate"))){
|
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;
|
ret = RET_INPUTERR;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if(!(conf_ifvlan = cJSON_GetObjectItem(root, "conf-ifvlan"))){
|
if(!(conf_ifvlan = cJSON_GetObjectItem(root, "conf-ifvlan"))){
|
||||||
|
printf("[vlan]vlan_config_json_parse: Json No conf_ifvlan node.\n");
|
||||||
ret = RET_INPUTERR;
|
ret = RET_INPUTERR;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1258,7 +1259,7 @@ ret_code vlan_config_json_parse(pointer input, interface_vlan_info *if_vlan_info
|
||||||
/* 解析最外层interface数组 */
|
/* 解析最外层interface数组 */
|
||||||
if_num = cJSON_GetArraySize(conf_ifvlan);
|
if_num = cJSON_GetArraySize(conf_ifvlan);
|
||||||
if(if_num == 0){
|
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;
|
ret = RET_INPUTERR;
|
||||||
goto out;
|
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");
|
cJSON *ifName = cJSON_GetObjectItem(node, "if-name");
|
||||||
if(!ifName){
|
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){
|
if(NULL == ifName->valuestring){
|
||||||
printf("[vlan]vlan_config_json_parse: ifName->valuestring is null.\n");
|
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);
|
printf("[vlan]if_vlan_info[%d].if_name=%s\n", i, if_vlan_info[i].if_name);
|
||||||
cJSON *ifAttr = cJSON_GetObjectItem(node, "if-attr");
|
cJSON *ifAttr = cJSON_GetObjectItem(node, "if-attr");
|
||||||
if(!ifAttr){
|
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){
|
if(NULL == ifAttr->valuestring){
|
||||||
printf("[vlan]vlan_config_json_parse: ifAttr->valuestring is null.\n");
|
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")){
|
else if(!strcmp(ifAttr->valuestring, "access")){
|
||||||
if_vlan_info[i].attr = LINK_TYPE_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");
|
cJSON *vId = cJSON_GetObjectItem(node, "vid");
|
||||||
if(!vId){
|
if(!vId){
|
||||||
continue;
|
//continue;
|
||||||
|
printf("[vlan]vlan_config_json_parse: Json has no vId node.\n");
|
||||||
|
ret = RET_INPUTERR;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 解析内层vid数组 */
|
/* 解析内层vid数组 */
|
||||||
vl_num = cJSON_GetArraySize(vId);
|
vl_num = cJSON_GetArraySize(vId);
|
||||||
if(vl_num == 0){
|
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;
|
ret = RET_INPUTERR;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -2077,7 +2092,11 @@ ret_code vlan_operate_parse(pointer input, int *oper_type)
|
||||||
ret = RET_OK;
|
ret = RET_OK;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
printf("[vlan]vlan_operate_chk: operate-val is UNKNOWN, error.\n");
|
||||||
|
ret = RET_INPUTERR;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
if(root){
|
if(root){
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
/*定义结构体数组 存在免认证规则 */
|
/*定义结构体数组 存在免认证规则 */
|
||||||
freeauth_configure_t freeauth_array[RULE_MAX_NUM] = {0};
|
freeauth_configure_t freeauth_array[RULE_MAX_NUM] = {0};
|
||||||
|
|
||||||
#define UNAMESIZE (127 + 1)
|
#define UNAMESIZE (60 + 1)
|
||||||
#define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符
|
#define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符
|
||||||
|
|
||||||
#ifdef FREEAUTH_ACK_COOKIES
|
#ifdef FREEAUTH_ACK_COOKIES
|
||||||
|
@ -536,6 +536,8 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
||||||
int i;
|
int i;
|
||||||
int cnt;
|
int cnt;
|
||||||
cJSON *res;
|
cJSON *res;
|
||||||
|
cJSON *pJsonArry;
|
||||||
|
cJSON *pJsonsub;
|
||||||
authfree_result_t authfree_result;
|
authfree_result_t authfree_result;
|
||||||
freeauth_configure_t *freeauth_configure = NULL;
|
freeauth_configure_t *freeauth_configure = NULL;
|
||||||
uint conf_type = FREEAUTH_CONFIG_GET;
|
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);
|
freeauth_configure[j].dip, freeauth_configure[j].dport, freeauth_configure[j].dport, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pJsonArry= cJSON_CreateArray(); /*创建数组*/
|
||||||
|
|
||||||
|
|
||||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||||
/*两个字符串相等 strcmp值为0*/
|
/*两个字符串相等 strcmp值为0*/
|
||||||
|
@ -602,35 +607,43 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
||||||
commcfgnl_close();
|
commcfgnl_close();
|
||||||
printf("cfgchannel main exit!\r\n");
|
printf("cfgchannel main exit!\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对象*/
|
||||||
|
|
||||||
/*创建json对象 */
|
/*在json对象上添加键值对*/
|
||||||
res = cJSON_CreateObject();
|
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(!res) {
|
if (result_message == NULL)
|
||||||
return RET_ERR;
|
{
|
||||||
|
return RET_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*将json对象转换成json字符串 返回处理结果*/
|
strcpy(result_message, freeauth_configure[j].name);
|
||||||
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
|
strcat(result_message, authfree_result.message);
|
||||||
cJSON_AddStringToObject(res, "message", authfree_result.message);
|
printf("%s\n", result_message);
|
||||||
ret_char = cJSON_PrintUnformatted(res);
|
|
||||||
|
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
|
||||||
|
cJSON_AddStringToObject(pJsonsub, "message", result_message);
|
||||||
|
|
||||||
|
ret_char = cJSON_Print(pJsonArry);
|
||||||
ret_int = strlen(ret_char);
|
ret_int = strlen(ret_char);
|
||||||
|
|
||||||
if(output_len) {
|
if(output_len)
|
||||||
|
{
|
||||||
*output_len = ret_int;
|
*output_len = ret_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*超出2k的内存,报错 */
|
/*超出2k的内存,报错 */
|
||||||
if(ret_int >= 1024 * 2) {
|
if(ret_int >= 1024 * 2)
|
||||||
|
{
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
cJSON_Delete(pJsonArry);
|
||||||
return RET_NOMEM;
|
return RET_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(output, ret_char, ret_int + 1);
|
memcpy(output, ret_char, ret_int + 1);
|
||||||
|
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -651,6 +664,8 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
||||||
int i;
|
int i;
|
||||||
int cnt;
|
int cnt;
|
||||||
cJSON *res;
|
cJSON *res;
|
||||||
|
cJSON *pJsonArry;
|
||||||
|
cJSON *pJsonsub;
|
||||||
authfree_result_t authfree_result;
|
authfree_result_t authfree_result;
|
||||||
freeauth_configure_t *freeauth_configure = NULL;
|
freeauth_configure_t *freeauth_configure = NULL;
|
||||||
uint conf_type = FREEAUTH_CONFIG_GET;
|
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);
|
printf("[%s %d]\n", freeauth_configure[j].name, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pJsonArry= cJSON_CreateArray(); /*创建数组*/
|
||||||
|
|
||||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
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");
|
printf("cfgchannel main exit!\r\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*创建json对象 */
|
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject());
|
||||||
res = cJSON_CreateObject();
|
|
||||||
|
/*在json对象上添加键值对*/
|
||||||
if(!res)
|
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字符串 返回处理结果*/
|
strcpy(result_message, freeauth_configure[j].name);
|
||||||
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
|
strcat(result_message, authfree_result.message);
|
||||||
cJSON_AddStringToObject(res, "message", authfree_result.message);
|
printf("%s\n", result_message);
|
||||||
ret_char = cJSON_PrintUnformatted(res);
|
|
||||||
|
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
|
||||||
|
cJSON_AddStringToObject(pJsonsub, "message", result_message);
|
||||||
|
|
||||||
|
ret_char = cJSON_Print(pJsonArry);
|
||||||
ret_int = strlen(ret_char);
|
ret_int = strlen(ret_char);
|
||||||
|
|
||||||
if(output_len)
|
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);
|
memcpy(output, ret_char, ret_int + 1);
|
||||||
|
|
||||||
free(ret_char);
|
free(ret_char);
|
||||||
cJSON_Delete(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,85 @@ log_cmd_t *get_cb_by_cmd(const char *cmd)
|
||||||
return NULL;
|
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 <level> [<module_name>]\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 [<module_name>]\n", LOGGING_MODULE_NAME, g_log_cmd[0].cmd);
|
||||||
|
fprintf(stdout, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
|
||||||
|
fprintf(stdout, " <module_name> 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 <ip_addr> [<port>] [<RFCfmt>]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
|
||||||
|
fprintf(stdout, " %s %s del <ip_addr> [<port>] [<RFCfmt>]\n", LOGGING_MODULE_NAME, g_log_cmd[2].cmd);
|
||||||
|
fprintf(stdout, " %s %s get <ip_addr>\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, " <ip_addr> is the ip address of remote syslog server\n");
|
||||||
|
fprintf(stdout, " <port> is the port of remote syslog server\n");
|
||||||
|
fprintf(stdout, " <RFCfmt> = 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 <level>\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, " <level> = 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 <level> [<file_path>] [<is_compress>] [<del_over_days>] [<del_over_size>]\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, " <level> = emerg | alert | crit | err | warn | notice | info | debug\n");
|
||||||
|
fprintf(stdout, " <file_path> is the path of syslog files saved\n");
|
||||||
|
fprintf(stdout, " <is_compress> = 0 | 1 , which 0 is syslog files is not compress while 1 is compress\n");
|
||||||
|
fprintf(stdout, " <del_over_days> is the syslog files life-time (days)\n");
|
||||||
|
fprintf(stdout, " <del_over_size> 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 main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stdout, "Parameter too few\n");
|
fprintf(stdout, "Parameter too few\n");
|
||||||
|
logging_usage();
|
||||||
return ret;
|
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);
|
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
|
||||||
if (g_log == NULL) {
|
if (g_log == NULL) {
|
||||||
|
|
|
@ -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 <linux/prefetch.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
|
@ -0,0 +1,468 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <regex.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
@ -9,46 +10,64 @@
|
||||||
#include "sev_sched.h"
|
#include "sev_sched.h"
|
||||||
|
|
||||||
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"
|
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"
|
||||||
|
|
||||||
#define LOG_REDIRECT_CONSOLE "/dev/console"
|
#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)
|
static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
int ret = -1;
|
||||||
|
FILE *driver_fp = NULL;
|
||||||
if ((dir = opendir(LOG_DEV_DIR)) == NULL) {
|
driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r");
|
||||||
ULOG_ERR(g_log, "Open dir:[%s] is failure:%d", LOG_DEV_DIR, strerror(errno));
|
if (driver_fp == NULL) {
|
||||||
return -1;
|
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];
|
char path[MAX_PATH_SZ];
|
||||||
while ((ptr = readdir(dir)) != NULL) {
|
while ((n = getline(&line, &n, driver_fp)) != -1) {
|
||||||
if ((strcmp(ptr->d_name, ".") == 0)
|
ULOG_DEBUG(g_log, "Serial line:%s", line);
|
||||||
|| (strcmp(ptr->d_name, "..") == 0)
|
if (strstr(line, SERIAL_DRIVER_PREFIX) == NULL) {
|
||||||
|| (ptr->d_type == DT_DIR)) { ///current dir OR parrent dir
|
ULOG_DEBUG(g_log, "%s isn't driver line", line);
|
||||||
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);
|
|
||||||
continue;
|
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) {
|
if (snprintf(path, sizeof(path), "%s%s%d", LOG_DEV_DIR, SERIAL_PREFIX, num) < 0) {
|
||||||
ULOG_ERR(g_log, "Setting %s of log console is failure", ptr->d_name);
|
ULOG_ERR(g_log, "Setting %s%d of log console is failure", SERIAL_PREFIX, num);
|
||||||
return -1;
|
goto END;
|
||||||
}
|
}
|
||||||
|
ULOG_DEBUG(g_log, "ttyS name:%s", path);
|
||||||
if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) {
|
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);
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,7 @@
|
||||||
#include "rpc_common.h"
|
#include "rpc_common.h"
|
||||||
|
|
||||||
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data);
|
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||||
|
ret_code console_initial();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,22 +1,170 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
|
||||||
#include "log_pty.h"
|
#include "log_pty.h"
|
||||||
#include "log_types.h"
|
#include "log_types.h"
|
||||||
#include "log_common.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_DEV_PTY_DIR LOG_DEV_DIR"pts/"
|
||||||
#define LOG_CONF_PTY_FILE_NAME "log-pty.conf"
|
#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)
|
static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
if ((dir = opendir(LOG_DEV_PTY_DIR)) == NULL) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +193,12 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (start_dev_pty_monitor() != RET_OK) {
|
||||||
|
ULOG_ERR(g_log, "Starting pty monitor is failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +209,8 @@ static int config_log_pty(const log_pty_t *conf)
|
||||||
|
|
||||||
switch (conf->on)
|
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);
|
ret = log_off_with_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
||||||
break;
|
break;
|
||||||
case LOG_ON:
|
case LOG_ON:
|
||||||
|
|
|
@ -23,6 +23,17 @@ ulog_t *g_log = NULL;
|
||||||
FILE *g_conf_fp;
|
FILE *g_conf_fp;
|
||||||
char g_conf_file[MAX_PATH_SZ];
|
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()
|
void signal_exit()
|
||||||
{
|
{
|
||||||
log_sev_exit();
|
log_sev_exit();
|
||||||
|
@ -47,7 +58,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon);
|
g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon);
|
||||||
if (g_log == NULL) {
|
if (g_log == NULL) {
|
||||||
fprintf(stderr, "Initiating ulog is failure");
|
fprintf(stderr, "Initiating ulog is failure\n");
|
||||||
return -1;
|
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);
|
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,19 +13,27 @@
|
||||||
ulog_t *ulog_init(const char *module_name, u8 is_print)
|
ulog_t *ulog_init(const char *module_name, u8 is_print)
|
||||||
{
|
{
|
||||||
ulog_t *log;
|
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) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
log = (ulog_t *)malloc(sizeof(*log));
|
log = (ulog_t *)malloc(sizeof(*log));
|
||||||
if (log == NULL) {
|
if (log == NULL) {
|
||||||
fprintf(stderr, "Allocating log memory is failure");
|
fprintf(stderr, "Allocating log memory is failure\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strncpy(log->module_name, module_name, len);
|
strncpy(log->module_name, module_name, len);
|
||||||
|
log->module_name[len] = '\0';
|
||||||
|
|
||||||
int opt = LOG_PERROR |LOG_PID;
|
int opt = LOG_PERROR |LOG_PID;
|
||||||
if (is_print > 0) {
|
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, ...)
|
void ulog_record(const ulog_t *log, int level, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (log == NULL) {
|
if (log == NULL) {
|
||||||
fprintf(stderr, "Log is null");
|
fprintf(stderr, "Log is null\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/sh -v
|
#!/bin/sh -v
|
||||||
|
|
||||||
|
|
||||||
user=$(whoami)
|
user=$(whoami)
|
||||||
|
|
||||||
cd /home/${user}/secogateway/kernel/
|
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/Product_usr/)
|
||||||
echo $(cp /home/${user}/secogateway/_install/debug/targets/ARM64/*.so usr/lib/)
|
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 /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 $(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/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/)
|
echo $(ln -s /customize_service/* /home/${user}/secogateway/kernel/rootfs/etc/systemd/system/multi-user.target.wants/)
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
||||||
WEBM_HANDLE_LOGIN,
|
WEBM_HANDLE_LOGIN,
|
||||||
WEBM_HANDLE_HOMEPAGE,
|
WEBM_HANDLE_HOMEPAGE,
|
||||||
|
|
||||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>չʾ<EFBFBD><EFBFBD>case<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷŵ<EFBFBD>һ<EFBFBD><EFBFBD> */
|
/* 以下是页面取数展示的case,后续提升性能可能通过数据库查询,所以先放到一起 */
|
||||||
WEBM_HANDLE_CONFIG_LIST_GROUP,
|
WEBM_HANDLE_CONFIG_LIST_GROUP,
|
||||||
|
|
||||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>case */
|
/* 以下是配置操作相关的case */
|
||||||
WEBM_HANDLE_CONFIG_ADD_GROUP,
|
WEBM_HANDLE_CONFIG_ADD_GROUP,
|
||||||
WEBM_HANDLE_CONFIG_UUID_GROUP,
|
WEBM_HANDLE_CONFIG_UUID_GROUP,
|
||||||
WEBM_HANDLE_CONFIG_MOD_GROUP,
|
WEBM_HANDLE_CONFIG_MOD_GROUP,
|
||||||
|
@ -40,7 +40,12 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
||||||
WEBM_HANDLE_CONFIG_IPV4,
|
WEBM_HANDLE_CONFIG_IPV4,
|
||||||
WEBM_HANDLE_CONFIG_VLAN_SET,
|
WEBM_HANDLE_CONFIG_VLAN_SET,
|
||||||
WEBM_HANDLE_CONFIG_VLAN_GET,
|
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;
|
} webm_handle_index;
|
||||||
|
|
||||||
typedef struct _webm_config_st
|
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, \
|
CM_CONFIG_GET, \
|
||||||
VLAN_CONFIG, \
|
VLAN_CONFIG, \
|
||||||
webm_config_send_proc \
|
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 \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue