Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
08c053afd7
|
@ -32,6 +32,9 @@
|
|||
/*nat config */
|
||||
#define NAT_CONFIG_MODULE 0x00000008
|
||||
|
||||
/*static routing*/
|
||||
#define STATIC_ROUTING_CONFIG_MODULE 0x00000009
|
||||
|
||||
/************************* 模块定义结束 **********************/
|
||||
|
||||
/************************ config id定义 **********************/
|
||||
|
@ -69,8 +72,8 @@
|
|||
|
||||
#define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1)
|
||||
|
||||
|
||||
|
||||
#define STATIC_ROUTING_CONFIG (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|1)
|
||||
#define GET_ALL_ROUTING_INFO (uint64)((uint64)STATIC_ROUTING_CONFIG_MODULE<<32|2)
|
||||
/************************ config id定义 end**********************/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#define MAX_MODULE_NAME_SZ 16
|
||||
|
||||
typedef struct _klog {
|
||||
char module_name[MAX_MODULE_NAME_SZ];
|
||||
char module_name[MAX_MODULE_NAME_SZ+1];
|
||||
}klog_t;
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ typedef uint ret_code;
|
|||
#define RET_EXIST 11
|
||||
#define RET_FULL 12
|
||||
#define RET_SENDERR 13
|
||||
#define RET_NOCMID 14
|
||||
#define RET_SRCERR 15
|
||||
|
||||
/* NETCONFIG_MODULE 0x00010000 ~ 0x0001ffff*/
|
||||
#define RET_IPINVALID (uint)((uint)NETCONFIG_MODULE<<16|1)
|
||||
|
@ -50,6 +52,8 @@ typedef uint ret_code;
|
|||
{ RET_EXIST, "AlreadyExist"},\
|
||||
{ RET_FULL, "Full"},\
|
||||
{ RET_SENDERR, "SendErr"},\
|
||||
{ RET_NOCMID, "CanNotFindConfig"},\
|
||||
{ RET_SRCERR, "ConfigSourceErr"},\
|
||||
\
|
||||
{ RET_IPINVALID, "IpInvalid"},\
|
||||
{ RET_BRNAMEERR, "BrNameInvalid"}\
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define MAX_MODULE_NAME_SZ 16
|
||||
|
||||
typedef struct _ulog {
|
||||
char module_name[MAX_MODULE_NAME_SZ];
|
||||
char module_name[MAX_MODULE_NAME_SZ+1];
|
||||
} ulog_t;
|
||||
|
||||
ulog_t *ulog_init(const char *module_name, u8 is_print);
|
||||
|
|
13
Makefile
13
Makefile
|
@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
|
|||
endif
|
||||
endif
|
||||
|
||||
.PHONY : demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging
|
||||
.PHONY : demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging ulog_test
|
||||
|
||||
all: demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging
|
||||
all: demo database openrpc ulog klog klog_test conntrack netlink trace redismq usermanager configm webauth matchrule logging ulog_test
|
||||
|
||||
ifeq ($(OPT), install)
|
||||
#$(shell `find ../release -name "*.zip" -delete`)
|
||||
|
@ -228,4 +228,13 @@ else ifeq ($(OPT), install)
|
|||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f module.klog_api.test.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=test_klog_api
|
||||
else
|
||||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f module.klog_api.test.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=test_klog_api
|
||||
endif
|
||||
|
||||
ulog_test:
|
||||
ifeq ($(OPT), clean)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=test_ulog_api
|
||||
else ifeq ($(OPT), install)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile install MLOG=$(MLOG) MAKE_TARGET=test_ulog_api
|
||||
else
|
||||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.ulog-test.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=test_ulog_api
|
||||
endif
|
|
@ -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=configm
|
||||
|
||||
|
@ -39,6 +40,10 @@ COMMON_SRCS = configserver.c \
|
|||
log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c log_config/log_config_file.c \
|
||||
nat_config/natconfig.c \
|
||||
vlan_config/vlan_config.c \
|
||||
dhcp_config/dhcp_client_config.c dhcp_config/dhcp_dhcpd_lease.c dhcp_config/dhcp_host_config.c dhcp_config/dhcp_lib.c dhcp_config/dhcp_relay_config.c dhcp_config/dhcp_shared_network_config.c dhcp_config/dhcp_subnet_config.c\
|
||||
static_routing_config/static_routing_config.c \
|
||||
|
||||
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
|
|
|
@ -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);
|
||||
|
||||
if (len >= MAX_MODULE_NAME_SZ) {
|
||||
printk(KERN_ERR"The length:%d of module_name must be less than %d, but input module_name is %s", len, MAX_MODULE_NAME_SZ, module_name);
|
||||
if (len > MAX_MODULE_NAME_SZ) {
|
||||
printk(KERN_ERR"The length:%d of module_name must be not more than %d, but input module_name is %s", len, MAX_MODULE_NAME_SZ, module_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ klog_t *klog_init(const char *module_name)
|
|||
printk(KERN_ERR"Allocating log memory is failure");
|
||||
return NULL;
|
||||
}
|
||||
memset(log->module_name, '\0', MAX_MODULE_NAME_SZ);
|
||||
memset(log->module_name, '\0', MAX_MODULE_NAME_SZ+1);
|
||||
strncpy(log->module_name, module_name, len);
|
||||
|
||||
return log;
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
0
Platform/thirdparty/x86_64/libev-linux.so → Platform/thirdparty/x86_64/usr/local/lib/libev-linux.so
vendored
Executable file → Normal file
0
Platform/thirdparty/x86_64/libev-linux.so → Platform/thirdparty/x86_64/usr/local/lib/libev-linux.so
vendored
Executable file → Normal file
|
@ -327,14 +327,14 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
|
|||
config_svr = cm_config_service_get(config_msg->config_id);
|
||||
if(config_svr == NULL)
|
||||
{
|
||||
cm_return(conn, RET_NULLP, "NULL pointer");
|
||||
cm_return(conn, RET_NOCMID, "can not find config id");
|
||||
return;
|
||||
}
|
||||
|
||||
/*source check*/
|
||||
if(!(config_svr->config_src & config_msg->source))
|
||||
{
|
||||
cm_return(conn, RET_CHKERR, "source check error!\r\n");
|
||||
cm_return(conn, RET_SRCERR, "source check error!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,46 @@
|
|||
#include "dhcp_lib.h"
|
||||
|
||||
void dhcp_config_init(void)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
ret = br_event_register(BR_DELETE_EVENT_PRE,del_interface_dhcp_cb);
|
||||
}
|
||||
|
||||
int del_interface_dhcp_cb(BR_EVENT_TYPE event_type, br_event_t event_arg)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
char *segment = get_interface_subnet(event_arg.br_name);
|
||||
if(NULL == segment){
|
||||
return ret;
|
||||
}
|
||||
char *mask = get_interface_mask(event_arg.br_name);
|
||||
if(NULL == mask){
|
||||
return ret;
|
||||
}
|
||||
int len = 500;
|
||||
char *cmd = (char *)malloc(len + 1);
|
||||
if(NULL == cmd)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
memset(cmd, 0, len + 1);
|
||||
snprintf(cmd, len, "sed -r -i 's/%s //g' /etc/default/isc-dhcp-server", event_arg.br_name);
|
||||
system(cmd);
|
||||
memset(cmd, 0, len + 1);
|
||||
snprintf(cmd, len, "sed -r -i ':a;N;$!ba;s/[ \\t]*subnet[ \\t]+%s[ \\t]+netmask[ \\t]+%s[ \\t]*\\{[a-zA-Z#:; \\t\\n0-9\\.\\,\\-]+\\}/#/g' /etc/dhcp/dhcpd.conf", segment, mask);
|
||||
system(cmd);
|
||||
system("sed -r -i '/#/d' /etc/dhcp/dhcpd.conf");
|
||||
if(segment){
|
||||
free(segment);
|
||||
}
|
||||
if(mask){
|
||||
free(mask);
|
||||
}
|
||||
/*ÔËÐÐÅäÖÃÎļþ*/
|
||||
system("service isc-dhcp-server restart");
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *getfileall(char *fname)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#include "../web_config/auth_recover_config.h"
|
||||
#include "natconfig.h"
|
||||
#include "vlan_config.h"
|
||||
#include "dhcp_lib.h"
|
||||
#include "static_routing.h"
|
||||
|
||||
|
||||
#define RET_CODE_LEN 16
|
||||
#define RET_MSG_LEN 128
|
||||
|
@ -31,7 +34,11 @@
|
|||
{ \
|
||||
VLAN_CONFIG_MODULE, \
|
||||
vlan_config_init \
|
||||
} \
|
||||
}, \
|
||||
{ \
|
||||
DHCP_CONFIG_MODULE, \
|
||||
dhcp_config_init \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -217,6 +224,78 @@
|
|||
vlan_config_proc, \
|
||||
vlan_config_get, \
|
||||
vlan_config_get_all \
|
||||
},\
|
||||
{\
|
||||
DHCP_HOST_CONFIG, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_host_config_chk, \
|
||||
dhcp_host_config_proc, \
|
||||
dhcp_host_config_get, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
DHCP_SUBNET_CONFIG, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_subnet_config_chk, \
|
||||
dhcp_subnet_config_proc, \
|
||||
dhcp_subnet_config_get, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
DHCP_RELAY_CONFIG, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_relay_config_chk, \
|
||||
dhcp_relay_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
DHCP_CLIENT_CONFIG, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_client_config_chk, \
|
||||
dhcp_client_config_proc, \
|
||||
dhcp_client_get, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
DHCP_DHCPD_LEASE, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_dhcpd_lease_config_chk, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
dhcp_dhcpd_lease_get_all \
|
||||
},\
|
||||
{\
|
||||
DHCP_SHARED_NETWORK_CONFIG, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
dhcp_shared_network_config_chk, \
|
||||
dhcp_shared_network_config_proc, \
|
||||
NULL, \
|
||||
dhcp_shared_network_config_get_all \
|
||||
},\
|
||||
{\
|
||||
STATIC_ROUTING_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
TRUE, \
|
||||
routing_config_chk, \
|
||||
routing_config_proc, \
|
||||
NULL, \
|
||||
routing_config_get_all \
|
||||
},\
|
||||
{\
|
||||
GET_ALL_ROUTING_INFO, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
all_routing_config_chk, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
all_routing_get_all \
|
||||
}\
|
||||
}
|
||||
|
||||
|
@ -270,3 +349,4 @@ int cm_format_data(ret_code ret_code, cJSON *json_obj, char *output);
|
|||
|
||||
#endif /* RPC_COMMON_H_ */
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,19 @@
|
|||
#include "rpc.h"
|
||||
#include "netconfig.h"
|
||||
|
||||
#include "dhcp_client_config.h"
|
||||
#include "dhcp_host_config.h"
|
||||
#include "dhcp_relay_config.h"
|
||||
#include "dhcp_shared_network_config.h"
|
||||
#include "dhcp_subnet_config.h"
|
||||
#include "dhcp_dhcpd_lease.h"
|
||||
|
||||
|
||||
void dhcp_config_init(void);
|
||||
|
||||
int del_interface_dhcp_cb(BR_EVENT_TYPE event_type, br_event_t event_arg);
|
||||
|
||||
|
||||
char *getfileall(char *fname);
|
||||
|
||||
char *getfilefirstline(char *fname);
|
||||
|
|
|
@ -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
|
File diff suppressed because it is too large
Load Diff
|
@ -16,7 +16,7 @@
|
|||
/*定义结构体数组 存在免认证规则 */
|
||||
freeauth_configure_t freeauth_array[RULE_MAX_NUM] = {0};
|
||||
|
||||
#define UNAMESIZE (127 + 1)
|
||||
#define UNAMESIZE (60 + 1)
|
||||
#define SPECHAR(element) (strpbrk((element), "~!@#$%^&*()_+{}|:\"<>?\\,./;\'[]-=`")) //校验特殊字符
|
||||
|
||||
#ifdef FREEAUTH_ACK_COOKIES
|
||||
|
@ -536,6 +536,8 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
|||
int i;
|
||||
int cnt;
|
||||
cJSON *res;
|
||||
cJSON *pJsonArry;
|
||||
cJSON *pJsonsub;
|
||||
authfree_result_t authfree_result;
|
||||
freeauth_configure_t *freeauth_configure = NULL;
|
||||
uint conf_type = FREEAUTH_CONFIG_GET;
|
||||
|
@ -564,6 +566,9 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
|||
freeauth_configure[j].dip, freeauth_configure[j].dport, freeauth_configure[j].dport, j);
|
||||
}
|
||||
|
||||
pJsonArry= cJSON_CreateArray(); /*创建数组*/
|
||||
|
||||
|
||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
/*两个字符串相等 strcmp值为0*/
|
||||
|
@ -602,35 +607,43 @@ ret_code freeauth_config_mod_proc(uint source, uint config_type,
|
|||
commcfgnl_close();
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
#endif
|
||||
|
||||
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对象*/
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
|
||||
if(!res) {
|
||||
return RET_ERR;
|
||||
/*在json对象上添加键值对*/
|
||||
char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator
|
||||
//in real code you would check for errors in malloc here
|
||||
if (result_message == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
/*将json对象转换成json字符串 返回处理结果*/
|
||||
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
|
||||
cJSON_AddStringToObject(res, "message", authfree_result.message);
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
strcpy(result_message, freeauth_configure[j].name);
|
||||
strcat(result_message, authfree_result.message);
|
||||
printf("%s\n", result_message);
|
||||
|
||||
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
|
||||
cJSON_AddStringToObject(pJsonsub, "message", result_message);
|
||||
|
||||
ret_char = cJSON_Print(pJsonArry);
|
||||
ret_int = strlen(ret_char);
|
||||
|
||||
if(output_len) {
|
||||
if(output_len)
|
||||
{
|
||||
*output_len = ret_int;
|
||||
}
|
||||
|
||||
/*超出2k的内存,报错 */
|
||||
if(ret_int >= 1024 * 2) {
|
||||
if(ret_int >= 1024 * 2)
|
||||
{
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
cJSON_Delete(pJsonArry);
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
memcpy(output, ret_char, ret_int + 1);
|
||||
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
free(ret_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -651,6 +664,8 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
int i;
|
||||
int cnt;
|
||||
cJSON *res;
|
||||
cJSON *pJsonArry;
|
||||
cJSON *pJsonsub;
|
||||
authfree_result_t authfree_result;
|
||||
freeauth_configure_t *freeauth_configure = NULL;
|
||||
uint conf_type = FREEAUTH_CONFIG_GET;
|
||||
|
@ -679,6 +694,7 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
printf("[%s %d]\n", freeauth_configure[j].name, j);
|
||||
}
|
||||
|
||||
pJsonArry= cJSON_CreateArray(); /*创建数组*/
|
||||
|
||||
/*查找要修改的免认证规则名字,不存在则退出程序 */
|
||||
for(i = 0; i < RULE_MAX_NUM; i++) {
|
||||
|
@ -719,18 +735,24 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
printf("cfgchannel main exit!\r\n");
|
||||
#endif
|
||||
|
||||
/*创建json对象 */
|
||||
res = cJSON_CreateObject();
|
||||
|
||||
if(!res)
|
||||
cJSON_AddItemToArray(pJsonArry, pJsonsub=cJSON_CreateObject());
|
||||
|
||||
/*在json对象上添加键值对*/
|
||||
char *result_message = malloc(strlen(freeauth_configure[j].name)+strlen(authfree_result.message)+1);//+1 for the zero-terminator
|
||||
//in real code you would check for errors in malloc here
|
||||
if (result_message == NULL)
|
||||
{
|
||||
return RET_ERR;
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
/*将json对象转换成json字符串 返回处理结果*/
|
||||
cJSON_AddNumberToObject(res, "resultcode", authfree_result.resultcode);
|
||||
cJSON_AddStringToObject(res, "message", authfree_result.message);
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
strcpy(result_message, freeauth_configure[j].name);
|
||||
strcat(result_message, authfree_result.message);
|
||||
printf("%s\n", result_message);
|
||||
|
||||
cJSON_AddNumberToObject(pJsonsub, "resultcode", authfree_result.resultcode);
|
||||
cJSON_AddStringToObject(pJsonsub, "message", result_message);
|
||||
|
||||
ret_char = cJSON_Print(pJsonArry);
|
||||
ret_int = strlen(ret_char);
|
||||
|
||||
if(output_len)
|
||||
|
@ -748,8 +770,7 @@ ret_code freeauth_config_del_proc(uint source, uint config_type,
|
|||
|
||||
memcpy(output, ret_char, ret_int + 1);
|
||||
|
||||
free(ret_char);
|
||||
cJSON_Delete(res);
|
||||
free(ret_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
@ -9,46 +10,60 @@
|
|||
#include "sev_sched.h"
|
||||
|
||||
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"
|
||||
|
||||
#define LOG_REDIRECT_CONSOLE "/dev/console"
|
||||
#define PROC_SERIAL_INFO_PATH "/proc/tty/driver/serial"
|
||||
|
||||
#define SERIAL_DRIVER_PREFIX "uart"
|
||||
#define SERIAL_NO_DRIVER_KEY SERIAL_DRIVER_PREFIX":unknown"
|
||||
#define SERIAL_PREFIX "ttyS"
|
||||
|
||||
static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||
{
|
||||
DIR *dir;
|
||||
|
||||
if ((dir = opendir(LOG_DEV_DIR)) == NULL) {
|
||||
ULOG_ERR(g_log, "Open dir:[%s] is failure:%d", LOG_DEV_DIR, strerror(errno));
|
||||
return -1;
|
||||
int ret = -1;
|
||||
FILE *driver_fp = NULL;
|
||||
driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r");
|
||||
if (driver_fp == NULL) {
|
||||
ULOG_ERR(g_log, "Opening file:%s is failure:%s", PROC_SERIAL_INFO_PATH, strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct dirent *ptr;
|
||||
char *line = NULL;
|
||||
size_t n;
|
||||
int num;
|
||||
char path[MAX_PATH_SZ];
|
||||
while ((ptr = readdir(dir)) != NULL) {
|
||||
if ((strcmp(ptr->d_name, ".") == 0)
|
||||
|| (strcmp(ptr->d_name, "..") == 0)
|
||||
|| (ptr->d_type == DT_DIR)) { ///current dir OR parrent dir
|
||||
ULOG_DEBUG(g_log,"The file:[%s] or directory jump over", ptr->d_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((strstr(ptr->d_name, "ttyS") == NULL)) {
|
||||
ULOG_DEBUG(g_log,"The file:[%s] isn't redirected", ptr->d_name);
|
||||
while ((n = getline(&line, &n, driver_fp)) != -1) {
|
||||
ULOG_DEBUG(g_log, "Serial line:%s", line);
|
||||
if (strstr(line, SERIAL_DRIVER_PREFIX) == NULL) {
|
||||
ULOG_DEBUG(g_log, "%s isn't driver line", line);
|
||||
continue;
|
||||
}
|
||||
|
||||
num = atoi(line);
|
||||
if (strstr(line, SERIAL_NO_DRIVER_KEY) != NULL) {
|
||||
ULOG_DEBUG(g_log, "%s%d don't have serial", SERIAL_PREFIX, num);
|
||||
continue;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log, "ttyS name:%s", ptr->d_name);
|
||||
if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_DIR, ptr->d_name) < 0) {
|
||||
ULOG_ERR(g_log, "Setting %s of log console is failure", ptr->d_name);
|
||||
return -1;
|
||||
|
||||
if (snprintf(path, sizeof(path), "%s%s%d", LOG_DEV_DIR, SERIAL_PREFIX, num) < 0) {
|
||||
ULOG_ERR(g_log, "Setting %s%d of log console is failure", SERIAL_PREFIX, num);
|
||||
goto END;
|
||||
}
|
||||
ULOG_DEBUG(g_log, "ttyS name:%s", path);
|
||||
if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) {
|
||||
ULOG_ERR(g_log, "Writing tty[module:%s] of log is failure", filter_mod);
|
||||
return -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
END:
|
||||
if (line != NULL) {
|
||||
free(line);
|
||||
}
|
||||
|
||||
return 0;
|
||||
fclose(driver_fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int main(int argc, char **argv)
|
|||
|
||||
g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon);
|
||||
if (g_log == NULL) {
|
||||
fprintf(stderr, "Initiating ulog is failure");
|
||||
fprintf(stderr, "Initiating ulog is failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,19 +13,27 @@
|
|||
ulog_t *ulog_init(const char *module_name, u8 is_print)
|
||||
{
|
||||
ulog_t *log;
|
||||
u32 len = strlen(module_name);
|
||||
|
||||
u32 len = 0;
|
||||
|
||||
if (NULL == module_name) {
|
||||
fprintf(stderr, "Bad input: module_name is NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = strlen(module_name);
|
||||
|
||||
if (len > MAX_MODULE_NAME_SZ) {
|
||||
fprintf(stderr, "The length:%d of module_name can't more than %d", len, MAX_MODULE_NAME_SZ);
|
||||
fprintf(stderr, "The length:%d of module_name can't more than %d\n", len, MAX_MODULE_NAME_SZ);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
log = (ulog_t *)malloc(sizeof(*log));
|
||||
if (log == NULL) {
|
||||
fprintf(stderr, "Allocating log memory is failure");
|
||||
fprintf(stderr, "Allocating log memory is failure\n");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(log->module_name, module_name, len);
|
||||
log->module_name[len] = '\0';
|
||||
|
||||
int opt = LOG_PERROR |LOG_PID;
|
||||
if (is_print > 0) {
|
||||
|
@ -47,7 +55,7 @@ void ulog_close(ulog_t *log)
|
|||
void ulog_record(const ulog_t *log, int level, const char *fmt, ...)
|
||||
{
|
||||
if (log == NULL) {
|
||||
fprintf(stderr, "Log is null");
|
||||
fprintf(stderr, "Log is null\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -23,10 +23,10 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
|||
WEBM_HANDLE_LOGIN,
|
||||
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,
|
||||
|
||||
/* <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_UUID_GROUP,
|
||||
WEBM_HANDLE_CONFIG_MOD_GROUP,
|
||||
|
@ -40,7 +40,12 @@ typedef enum { WEBM_HANDLE_INVALID_INDEX = -1,
|
|||
WEBM_HANDLE_CONFIG_IPV4,
|
||||
WEBM_HANDLE_CONFIG_VLAN_SET,
|
||||
WEBM_HANDLE_CONFIG_VLAN_GET,
|
||||
WEBM_HANDLE_MAX
|
||||
WEBM_HANDLE_MAX,
|
||||
|
||||
WEBM_HANDLE_CONFIG_MOD_AUTHPARA,
|
||||
WEBM_HANDLE_CONFIG_ADD_AUTHRULE,
|
||||
WEBM_HANDLE_CONFIG_MOD_AUTHRULE,
|
||||
WEBM_HANDLE_CONFIG_DEL_AUTHRULE
|
||||
} webm_handle_index;
|
||||
|
||||
typedef struct _webm_config_st
|
||||
|
@ -185,6 +190,37 @@ extern int webm_config_send_proc(server *srv, uint32_t config_type, uint64 confg
|
|||
CM_CONFIG_GET, \
|
||||
VLAN_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_MOD_AUTHPARA, \
|
||||
"/FSG-CF/userauth-parameters-mod", \
|
||||
CM_CONFIG_SET, \
|
||||
FREEPARAMETERS_CONFIG , \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_ADD_AUTHRULE, \
|
||||
"/FSG-GF/userauth-rule-add", \
|
||||
CM_CONFIG_SET, \
|
||||
AUTHFREE_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_MOD_AUTHRULE, \
|
||||
"/FSG-GF/userauth-rule-mod", \
|
||||
CM_CONFIG_SET, \
|
||||
AUTHFREE_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
}, \
|
||||
\
|
||||
{\
|
||||
WEBM_HANDLE_CONFIG_DEL_AUTHRULE, \
|
||||
"/FSG-GF/userauth-rule-del", \
|
||||
CM_CONFIG_SET, \
|
||||
AUTHFREE_CONFIG, \
|
||||
webm_config_send_proc \
|
||||
} \
|
||||
\
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
diff -uprN -x build -x comp_sql cJSON_orig/CMakeLists.txt cJSON/CMakeLists.txt
|
||||
--- cJSON_orig/CMakeLists.txt 2019-08-28 11:06:20.851852257 +0800
|
||||
+++ cJSON/CMakeLists.txt 2019-08-28 11:06:52.346617001 +0800
|
||||
@@ -12,6 +12,33 @@ set(CJSON_VERSION_SO 1)
|
||||
set(CJSON_UTILS_VERSION_SO 1)
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
+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-linux-gnu-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()
|
||||
|
||||
set(custom_compiler_flags)
|
||||
|
|
@ -1,278 +0,0 @@
|
|||
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
||||
cmake_minimum_required(VERSION 2.8.5)
|
||||
|
||||
project(cJSON C)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(PROJECT_VERSION_MAJOR 1)
|
||||
set(PROJECT_VERSION_MINOR 7)
|
||||
set(PROJECT_VERSION_PATCH 12)
|
||||
set(CJSON_VERSION_SO 1)
|
||||
set(CJSON_UTILS_VERSION_SO 1)
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
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-linux-gnu-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()
|
||||
|
||||
set(custom_compiler_flags)
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags" ON)
|
||||
if (ENABLE_CUSTOM_COMPILER_FLAGS)
|
||||
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU"))
|
||||
list(APPEND custom_compiler_flags
|
||||
-std=c89
|
||||
-pedantic
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wstrict-prototypes
|
||||
-Wwrite-strings
|
||||
-Wshadow
|
||||
-Winit-self
|
||||
-Wcast-align
|
||||
-Wformat=2
|
||||
-Wmissing-prototypes
|
||||
-Wstrict-overflow=2
|
||||
-Wcast-qual
|
||||
-Wundef
|
||||
-Wswitch-default
|
||||
-Wconversion
|
||||
-Wc++-compat
|
||||
-fstack-protector-strong
|
||||
-Wcomma
|
||||
-Wdouble-promotion
|
||||
-Wparentheses
|
||||
-Wformat-overflow
|
||||
-Wunused-macros
|
||||
-Wmissing-variable-declarations
|
||||
-Wused-but-marked-unused
|
||||
-Wswitch-enum
|
||||
)
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# Disable warning c4001 - nonstandard extension 'single line comment' was used
|
||||
# Define _CRT_SECURE_NO_WARNINGS to disable deprecation warnings for "insecure" C library functions
|
||||
list(APPEND custom_compiler_flags
|
||||
/GS
|
||||
/Za
|
||||
/sdl
|
||||
/W4
|
||||
/wd4001
|
||||
/D_CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF)
|
||||
if (ENABLE_SANITIZERS)
|
||||
list(APPEND custom_compiler_flags
|
||||
-fno-omit-frame-pointer
|
||||
-fsanitize=address
|
||||
-fsanitize=undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fsanitize-address-use-after-scope
|
||||
-fsanitize=integer
|
||||
-01
|
||||
-fno-sanitize-recover
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_SAFE_STACK "Enables the SafeStack instrumentation pass by the Code Pointer Integrity Project" OFF)
|
||||
if (ENABLE_SAFE_STACK)
|
||||
if (ENABLE_SANITIZERS)
|
||||
message(FATAL_ERROR "ENABLE_SAFE_STACK cannot be used in combination with ENABLE_SANITIZERS")
|
||||
endif()
|
||||
list(APPEND custom_compiler_flags
|
||||
-fsanitize=safe-stack
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On)
|
||||
if (ENABLE_PUBLIC_SYMBOLS)
|
||||
list(APPEND custom_compiler_flags -fvisibility=hidden)
|
||||
add_definitions(-DCJSON_EXPORT_SYMBOLS -DCJSON_API_VISIBILITY)
|
||||
endif()
|
||||
option(ENABLE_HIDDEN_SYMBOLS "Hide library symbols." Off)
|
||||
if (ENABLE_HIDDEN_SYMBOLS)
|
||||
add_definitions(-DCJSON_HIDE_SYMBOLS -UCJSON_API_VISIBILITY)
|
||||
endif()
|
||||
|
||||
# apply custom compiler flags
|
||||
foreach(compiler_flag ${custom_compiler_flags})
|
||||
#remove problematic characters
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "" current_variable ${compiler_flag})
|
||||
|
||||
CHECK_C_COMPILER_FLAG(${compiler_flag} "FLAG_SUPPORTED_${current_variable}")
|
||||
if (FLAG_SUPPORTED_${current_variable})
|
||||
list(APPEND supported_compiler_flags)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_flag}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${supported_compiler_flags}")
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)
|
||||
|
||||
#cJSON
|
||||
set(CJSON_LIB cjson)
|
||||
|
||||
file(GLOB HEADERS cJSON.h)
|
||||
set(SOURCES cJSON.c)
|
||||
|
||||
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off)
|
||||
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" OFF)
|
||||
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" ON)
|
||||
|
||||
if ((CJSON_OVERRIDE_BUILD_SHARED_LIBS AND CJSON_BUILD_SHARED_LIBS) OR ((NOT CJSON_OVERRIDE_BUILD_SHARED_LIBS) AND BUILD_SHARED_LIBS))
|
||||
set(CJSON_LIBRARY_TYPE SHARED)
|
||||
else()
|
||||
set(CJSON_LIBRARY_TYPE STATIC)
|
||||
endif()
|
||||
|
||||
|
||||
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
|
||||
add_library("${CJSON_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS}" "${SOURCES}")
|
||||
else()
|
||||
# See https://cmake.org/Wiki/CMake_FAQ#How_do_I_make_my_shared_and_static_libraries_have_the_same_root_name.2C_but_different_suffixes.3F
|
||||
add_library("${CJSON_LIB}" SHARED "${HEADERS}" "${SOURCES}")
|
||||
add_library("${CJSON_LIB}-static" STATIC "${HEADERS}" "${SOURCES}")
|
||||
set_target_properties("${CJSON_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_LIB}")
|
||||
set_target_properties("${CJSON_LIB}-static" PROPERTIES PREFIX "lib")
|
||||
endif()
|
||||
if (NOT WIN32)
|
||||
target_link_libraries("${CJSON_LIB}" m)
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
|
||||
|
||||
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
||||
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_LIB}")
|
||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
|
||||
endif()
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# export library information for CMake projects
|
||||
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
set_target_properties("${CJSON_LIB}"
|
||||
PROPERTIES
|
||||
SOVERSION "${CJSON_VERSION_SO}"
|
||||
VERSION "${PROJECT_VERSION}")
|
||||
|
||||
#cJSON_Utils
|
||||
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
|
||||
if(ENABLE_CJSON_UTILS)
|
||||
set(CJSON_UTILS_LIB cjson_utils)
|
||||
|
||||
file(GLOB HEADERS_UTILS cJSON_Utils.h)
|
||||
set(SOURCES_UTILS cJSON_Utils.c)
|
||||
|
||||
if (NOT BUILD_SHARED_AND_STATIC_LIBS)
|
||||
add_library("${CJSON_UTILS_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")
|
||||
else()
|
||||
add_library("${CJSON_UTILS_LIB}" SHARED "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")
|
||||
add_library("${CJSON_UTILS_LIB}-static" STATIC "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
||||
target_link_libraries("${CJSON_UTILS_LIB}-static" "${CJSON_LIB}-static")
|
||||
set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_UTILS_LIB}")
|
||||
set_target_properties("${CJSON_UTILS_LIB}-static" PROPERTIES PREFIX "lib")
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
|
||||
|
||||
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
|
||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
|
||||
endif()
|
||||
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# export library information for CMake projects
|
||||
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
set_target_properties("${CJSON_UTILS_LIB}"
|
||||
PROPERTIES
|
||||
SOVERSION "${CJSON_UTILS_VERSION_SO}"
|
||||
VERSION "${PROJECT_VERSION}")
|
||||
endif()
|
||||
|
||||
# create the other package config files
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfig.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
|
||||
|
||||
# Install package config files
|
||||
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
|
||||
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
|
||||
if(ENABLE_CJSON_TEST)
|
||||
enable_testing()
|
||||
|
||||
set(TEST_CJSON cJSON_test)
|
||||
add_executable("${TEST_CJSON}" test.c)
|
||||
target_link_libraries("${TEST_CJSON}" "${CJSON_LIB}")
|
||||
|
||||
add_test(NAME ${TEST_CJSON} COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${TEST_CJSON}")
|
||||
|
||||
# Disable -fsanitize=float-divide-by-zero for cJSON_test
|
||||
if (FLAG_SUPPORTED_fsanitizefloatdividebyzero)
|
||||
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero")
|
||||
else()
|
||||
target_compile_options(${TEST_CJSON} PRIVATE "-fno-sanitize=float-divide-by-zero")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#"check" target that automatically builds everything and runs the tests
|
||||
add_custom_target(check
|
||||
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
|
||||
DEPENDS ${TEST_CJSON})
|
||||
endif()
|
||||
|
||||
# Enable the use of locales
|
||||
option(ENABLE_LOCALES "Enable the use of locales" ON)
|
||||
if(ENABLE_LOCALES)
|
||||
add_definitions(-DENABLE_LOCALES)
|
||||
endif()
|
||||
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(fuzzing)
|
|
@ -0,0 +1,70 @@
|
|||
diff -uprN -x build -x comp_sql mysql-5.7.27_orig/CMakeLists.txt mysql-5.7.27/CMakeLists.txt
|
||||
--- mysql-5.7.27_orig/CMakeLists.txt 2019-06-10 22:43:20.000000000 +0800
|
||||
+++ mysql-5.7.27/CMakeLists.txt 2019-08-28 09:08:51.947233400 +0800
|
||||
@@ -43,7 +43,33 @@ IF(CMAKE_VERSION VERSION_EQUAL "3.0.0" O
|
||||
ENDIF()
|
||||
|
||||
MESSAGE(STATUS "Running cmake version ${CMAKE_VERSION}")
|
||||
+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()
|
||||
# Will set GIT_EXECUTABLE and GIT_FOUND
|
||||
FIND_PACKAGE(Git)
|
||||
|
||||
diff -uprN -x build -x comp_sql mysql-5.7.27_orig/storage/innobase/lock/lock0lock.cc mysql-5.7.27/storage/innobase/lock/lock0lock.cc
|
||||
--- mysql-5.7.27_orig/storage/innobase/lock/lock0lock.cc 2019-06-10 22:43:20.000000000 +0800
|
||||
+++ mysql-5.7.27/storage/innobase/lock/lock0lock.cc 2019-08-28 09:29:44.927757019 +0800
|
||||
@@ -1647,7 +1647,7 @@ RecLock::mark_trx_for_rollback(trx_t* tr
|
||||
bool cas;
|
||||
os_thread_id_t thread_id = os_thread_get_curr_id();
|
||||
|
||||
- cas = os_compare_and_swap_thread_id(&trx->killed_by, 0, thread_id);
|
||||
+ cas = os_compare_and_swap_lint(&trx->killed_by, 0, thread_id);
|
||||
|
||||
ut_a(cas);
|
||||
|
||||
diff -uprN -x build -x comp_sql mysql-5.7.27_orig/storage/innobase/trx/trx0trx.cc mysql-5.7.27/storage/innobase/trx/trx0trx.cc
|
||||
--- mysql-5.7.27_orig/storage/innobase/trx/trx0trx.cc 2019-06-10 22:43:20.000000000 +0800
|
||||
+++ mysql-5.7.27/storage/innobase/trx/trx0trx.cc 2019-08-28 09:33:18.500084963 +0800
|
||||
@@ -193,7 +193,7 @@ trx_init(
|
||||
if (!TrxInInnoDB::is_async_rollback(trx)) {
|
||||
|
||||
os_thread_id_t thread_id = trx->killed_by;
|
||||
- os_compare_and_swap_thread_id(&trx->killed_by, thread_id, 0);
|
||||
+ os_compare_and_swap_uint32(&trx->killed_by, thread_id, 0);
|
||||
|
||||
/* Note: Do not set to 0, the ref count is decremented inside
|
||||
the TrxInInnoDB() destructor. We only need to clear the flags. */
|
||||
@@ -3381,7 +3381,7 @@ trx_kill_blocking(trx_t* trx)
|
||||
ut_ad(victim_trx->version == version);
|
||||
|
||||
os_thread_id_t thread_id = victim_trx->killed_by;
|
||||
- os_compare_and_swap_thread_id(&victim_trx->killed_by,
|
||||
+ os_compare_and_swap_uint32(&victim_trx->killed_by,
|
||||
thread_id, 0);
|
||||
|
||||
victim_trx->in_innodb &= TRX_FORCE_ROLLBACK_MASK;
|
|
@ -0,0 +1,3 @@
|
|||
cmake -G "Unix Makefiles" -DPLAT_ARM64=TRUE ../ -DWITH_BOOST=/home/hx/my_projects/boost_1_59_0 \
|
||||
-DSTACK_DIRECTION=1 -DHAVE_IB_GCC_ATOMIC_COMPARE_EXCHANGE=TRUE -DWITH_UNIXODBC=TRUE \
|
||||
-DWITH_EMBEDDED_SERVER=TRUE -DCMAKE_INSTALL_PREFIX=/usr -DWITH_DEBUG=FALSE -DWITH_UNIT_TESTS=FALSE
|
|
@ -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