Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
08f496cbc5
|
@ -1,5 +1,10 @@
|
|||
#include "k-userhash.h"
|
||||
#include <linux/slab.h>
|
||||
#include <asm/errno.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
/*声明读写锁 */
|
||||
DEFINE_RWLOCK(g_obj_lock);
|
||||
|
||||
/*定义大小为HASH_SIZE的hashtable */
|
||||
static struct list_head hash_array[HASH_SIZE];
|
||||
|
@ -15,7 +20,7 @@ void init_hashMap(void)
|
|||
/*获取hashtable位置索引 */
|
||||
int get_hash_index(uint32_t ip)
|
||||
{
|
||||
unsigned int val = ip % HASH_SIZE;
|
||||
int val = ip % HASH_SIZE;
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -29,15 +34,8 @@ USERINFO *search_user(uint32_t ip)
|
|||
|
||||
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 */
|
||||
read_lock(&g_obj_lock);
|
||||
list_for_each(pos, &hash_array[index])
|
||||
{
|
||||
|
||||
|
@ -47,9 +45,10 @@ USERINFO *search_user(uint32_t ip)
|
|||
* @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);
|
||||
printk("user ip:%ld user id:%d\n", pNode->user_ip, pNode->user_id);
|
||||
return pNode;
|
||||
}
|
||||
read_unlock(&g_obj_lock);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -71,11 +70,10 @@ int add_user(uint32_t ip, int id)
|
|||
pNode = (USERINFO *)kmalloc(sizeof(USERINFO), GFP_KERNEL);
|
||||
if (pNode == NULL)
|
||||
{
|
||||
return -1;
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
pNode->user_ip = ip;
|
||||
|
||||
list_add_tail(&pNode->hnode,&hash_array[index]);
|
||||
}
|
||||
|
||||
printk("IP ALEADY EXISTED\n");
|
||||
|
@ -88,7 +86,7 @@ int add_user(uint32_t ip, int id)
|
|||
void del_user(uint32_t ip)
|
||||
{
|
||||
int index;
|
||||
struct list_head *pos;
|
||||
struct list_head *pos, *n;
|
||||
USERINFO *pNode;
|
||||
index = get_hash_index(ip);
|
||||
|
||||
|
@ -100,13 +98,15 @@ void del_user(uint32_t ip)
|
|||
}
|
||||
|
||||
/*查找用户ip */
|
||||
list_for_each(pos, &hash_array[index])
|
||||
write_lock(&g_obj_lock);
|
||||
list_for_each_safe(pos, n, &hash_array[index])
|
||||
{
|
||||
pNode = list_entry(pos, USERINFO, hnode);
|
||||
if(pNode->user_ip == ip)
|
||||
list_del(&pNode->hnode);
|
||||
kfree(pNode);
|
||||
}
|
||||
write_unlock(&g_obj_lock);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -123,12 +123,14 @@ void free_all_user(void)
|
|||
{
|
||||
if(list_empty(&hash_array[i]))
|
||||
continue;
|
||||
write_lock(&g_obj_lock);
|
||||
list_for_each_safe(pos, n, &hash_array[i])
|
||||
{
|
||||
pNode = list_entry(pos, USERINFO, hnode);
|
||||
list_del(&pNode->hnode);
|
||||
kfree(pNode);
|
||||
}
|
||||
write_unlock(&g_obj_lock);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,11 +144,13 @@ void printk_all_user(void)
|
|||
|
||||
for(i = 0; i < HASH_SIZE; i++)
|
||||
continue;
|
||||
read_lock(&g_obj_lock);
|
||||
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);
|
||||
}
|
||||
read_unlock(&g_obj_lock);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue