Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
f0926ad064
22
Makefile
22
Makefile
|
@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY : demo conntrack netlink trace openrpc redismq usermanager configm ulog database
|
.PHONY : demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable
|
||||||
|
|
||||||
all: demo conntrack netlink trace openrpc redismq usermanager configm ulog database
|
all: demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable
|
||||||
|
|
||||||
ifeq ($(OPT), install)
|
ifeq ($(OPT), install)
|
||||||
#$(shell `find ../release -name "*.zip" -delete`)
|
#$(shell `find ../release -name "*.zip" -delete`)
|
||||||
|
@ -180,3 +180,21 @@ else ifeq ($(OPT), install)
|
||||||
else
|
else
|
||||||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.database.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=database
|
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.database.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=database
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
webauth:
|
||||||
|
ifeq ($(OPT), clean)
|
||||||
|
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f user.web-auth.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=webauth
|
||||||
|
else ifeq ($(OPT), install)
|
||||||
|
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f user.web-auth.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=webauth
|
||||||
|
else
|
||||||
|
$(MLOG)make all $(MAKE_FLAGS) -C Product/build -f user.web-auth.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=webauth
|
||||||
|
endif
|
||||||
|
|
||||||
|
khashtable:
|
||||||
|
ifeq ($(OPT), clean)
|
||||||
|
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f module.khash.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=khashtable
|
||||||
|
else ifeq ($(OPT), install)
|
||||||
|
$(MLOG)make $(MAKE_FLAGS) -C Product/build -f module.khash.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=khashtable
|
||||||
|
else
|
||||||
|
$(MLOG)make all $(MAKE_FLAGS) -C Product/build -f module.khash.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=khashtable
|
||||||
|
endif
|
|
@ -0,0 +1,77 @@
|
||||||
|
# target name, the target name must have the same name of c source file
|
||||||
|
TARGET_NAME=khashtable
|
||||||
|
|
||||||
|
# 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 ?= FALSE
|
||||||
|
|
||||||
|
VPATH = ../modules/userhash
|
||||||
|
|
||||||
|
# source code
|
||||||
|
|
||||||
|
# set the source file, don't used .o because of ...
|
||||||
|
|
||||||
|
COMMON_SRCS = k-userhash.c
|
||||||
|
|
||||||
|
# MRS Board Source Files
|
||||||
|
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||||
|
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||||
|
|
||||||
|
# gcc CFLAGS
|
||||||
|
PLAT_ARM64_CFLAGS := -I../../Common -I../common
|
||||||
|
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
PLAT_ARM64_LDFLAGS :=
|
||||||
|
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
#gcc libs
|
||||||
|
ARM64_LIBS :=
|
||||||
|
LINUX_LIBS :=
|
||||||
|
|
||||||
|
ifeq ($(PLAT_ARM64), TRUE)
|
||||||
|
DEPEND_LIB +=
|
||||||
|
USER_CLEAN_ITEMS +=
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLAT_LINUX), TRUE)
|
||||||
|
DEPEND_LIB +=
|
||||||
|
USER_CLEAN_ITEMS +=
|
||||||
|
endif
|
||||||
|
|
||||||
|
# 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,156 @@
|
||||||
|
#include "k-userhash.h"
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
|
/*定义大小为HASH_SIZE的hashtable */
|
||||||
|
static struct list_head hash_array[HASH_SIZE];
|
||||||
|
|
||||||
|
/*init hashtable */
|
||||||
|
void init_hashMap(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < HASH_SIZE; i++)
|
||||||
|
INIT_LIST_HEAD(&hash_array[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*获取hashtable位置索引 */
|
||||||
|
int get_hash_index(uint32_t ip)
|
||||||
|
{
|
||||||
|
unsigned int val = ip % HASH_SIZE;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* search node */
|
||||||
|
USERINFO *search_user(uint32_t ip)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
struct list_head *pos;
|
||||||
|
USERINFO *pNode;
|
||||||
|
|
||||||
|
index = get_hash_index(ip);
|
||||||
|
|
||||||
|
/*判断表中该单元是否为NLL */
|
||||||
|
/* list_empty - tests whether a list is empty*/
|
||||||
|
/* @head: the list to test.*/
|
||||||
|
if( list_empty(&hash_array[index]))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*查找用户IP */
|
||||||
|
list_for_each(pos, &hash_array[index])
|
||||||
|
{
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
pNode = list_entry(pos, USERINFO, hnode);
|
||||||
|
if(pNode != NULL)
|
||||||
|
printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id);
|
||||||
|
return pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*add user */
|
||||||
|
int add_user(uint32_t ip, int id)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
USERINFO *pNode = NULL;
|
||||||
|
|
||||||
|
/*获取hashtable位置索引 */
|
||||||
|
index = get_hash_index(ip);
|
||||||
|
pNode = search_user(ip);
|
||||||
|
|
||||||
|
if( NULL == pNode)
|
||||||
|
{
|
||||||
|
/*分配存储空间——GFP_KERNEL内核内存的正常分配. 可能睡眠. */
|
||||||
|
pNode = (USERINFO *)kmalloc(sizeof(USERINFO), GFP_KERNEL);
|
||||||
|
if (pNode == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pNode->user_ip = ip;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("IP ALEADY EXISTED\n");
|
||||||
|
pNode->user_id = id;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*delete a node */
|
||||||
|
void del_user(uint32_t ip)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
struct list_head *pos;
|
||||||
|
USERINFO *pNode;
|
||||||
|
index = get_hash_index(ip);
|
||||||
|
|
||||||
|
/*判断hashtable中该单元是否为空 */
|
||||||
|
if( list_empty(&hash_array[index]))
|
||||||
|
{
|
||||||
|
printk("node is NULL\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*查找用户ip */
|
||||||
|
list_for_each(pos, &hash_array[index])
|
||||||
|
{
|
||||||
|
pNode = list_entry(pos, USERINFO, hnode);
|
||||||
|
if(pNode->user_ip == ip)
|
||||||
|
list_del(&pNode->hnode);
|
||||||
|
kfree(pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*delete all node */
|
||||||
|
void free_all_user(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct list_head *pos, *n;
|
||||||
|
USERINFO *pNode;
|
||||||
|
|
||||||
|
/*判断hashtable单元是否为NULL */
|
||||||
|
for(i = 0; i < HASH_SIZE; i++)
|
||||||
|
{
|
||||||
|
if(list_empty(&hash_array[i]))
|
||||||
|
continue;
|
||||||
|
list_for_each_safe(pos, n, &hash_array[i])
|
||||||
|
{
|
||||||
|
pNode = list_entry(pos, USERINFO, hnode);
|
||||||
|
list_del(&pNode->hnode);
|
||||||
|
kfree(pNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*printf all nodes */
|
||||||
|
void printk_all_user(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct list_head *pos, *n;
|
||||||
|
USERINFO * pNode;
|
||||||
|
|
||||||
|
for(i = 0; i < HASH_SIZE; i++)
|
||||||
|
continue;
|
||||||
|
list_for_each_safe(pos, n, &hash_array[i])
|
||||||
|
{
|
||||||
|
pNode = list_entry(pos, USERINFO, hnode);
|
||||||
|
printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef _KUSERHASH_H
|
||||||
|
#define _KUSERHASH_H
|
||||||
|
|
||||||
|
#include <linux/list.h>
|
||||||
|
|
||||||
|
/*定义hash表大小 */
|
||||||
|
#define HASH_SIZE 100
|
||||||
|
|
||||||
|
typedef struct userinfo
|
||||||
|
{
|
||||||
|
struct list_head hnode;
|
||||||
|
int user_id;
|
||||||
|
uint32_t user_ip;
|
||||||
|
}USERINFO;
|
||||||
|
|
||||||
|
/*init hashtable */
|
||||||
|
void init_hashMap(void);
|
||||||
|
|
||||||
|
/*获取hashtable位置索引 */
|
||||||
|
int get_hash_index(uint32_t ip);
|
||||||
|
|
||||||
|
/* search node */
|
||||||
|
USERINFO *search_user(uint32_t ip);
|
||||||
|
|
||||||
|
/*add user */
|
||||||
|
int add_user(uint32_t ip, int id);
|
||||||
|
|
||||||
|
/*delete a node */
|
||||||
|
void del_user(uint32_t ip);
|
||||||
|
|
||||||
|
/*delete all node */
|
||||||
|
void free_all_user(void);
|
||||||
|
|
||||||
|
/*printf all nodes */
|
||||||
|
void printk_all_user(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -165,6 +165,24 @@ ret_code user_auth(pointer content, RESULT *uresult)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int args, char** argv)
|
||||||
|
{
|
||||||
|
RESULT *output;
|
||||||
|
ret_code ret;
|
||||||
|
|
||||||
|
/*创建内存地址 */
|
||||||
|
output = (RESULT*)malloc(sizeof(RESULT));
|
||||||
|
if (NULL == output)
|
||||||
|
{
|
||||||
|
ret = RET_NOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *test = "{\"username\": \"用户02\",\"password\": \"123456\"}";
|
||||||
|
ret = user_auth(test, output);
|
||||||
|
|
||||||
|
printf("%d\n", ret);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ do { \
|
||||||
}; \
|
}; \
|
||||||
|
|
||||||
/* 定义用户认证结果记录表 */
|
/* 定义用户认证结果记录表 */
|
||||||
static USER_AUTH_LIST g_user_auth_ret_table[AUTH_USER_INDEX_MAX] = { 0 };
|
USER_AUTH_LIST g_user_auth_ret_table[AUTH_USER_INDEX_MAX] = { 0 };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* config_lock_time 锁定后-时间,单位(分钟)
|
* config_lock_time 锁定后-时间,单位(分钟)
|
||||||
|
|
Loading…
Reference in New Issue