-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink_list.c
More file actions
117 lines (105 loc) · 3.37 KB
/
link_list.c
File metadata and controls
117 lines (105 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <linux/module.h>
#include "link_list.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Nachum Barcohen <nachum.barcohen@gmail.com>");
static int __init md_init(void) {
printk("+ module link_list started!\n");
return 0;
}
static void __exit md_exit(void) {
printk("+ module link_list unloaded!\n");
}
extern proto_db_element* proto_db_create(void) {
proto_db_element* head = (proto_db_element*)kmalloc(sizeof(proto_db_element), GFP_KERNEL);
head->next = NULL;
head->proc_hdr_func = NULL;
head->proto_name = NULL;
head->proto_hex_code = 0;
return head;
}
EXPORT_SYMBOL(proto_db_create);
extern void proto_db_purge(proto_db_element* head) {
proto_db_element* current_element = head;
while(current_element) {
current_element = current_element->next;
kfree(head);
head = current_element;
}
}
EXPORT_SYMBOL(proto_db_purge);
extern bool proto_db_add(proto_db_element* head, char* name, u_short hex, void (*func_ptr)(struct sk_buff*)) {
proto_db_element* current_element = head;
while(current_element->next) {
current_element = current_element->next;
}
current_element->next = (proto_db_element*)kmalloc(sizeof(proto_db_element), GFP_KERNEL);
if(!current_element->next) {
return false;
}
current_element = current_element->next;
current_element->proto_name = (char*)kmalloc(sizeof(char)*4, GFP_KERNEL);
current_element->proto_name = name;
current_element->proto_hex_code = hex;
current_element->proc_hdr_func = *func_ptr;
current_element->next = NULL;
return true;
}
EXPORT_SYMBOL(proto_db_add);
extern bool proto_db_del(proto_db_element* head, int type, void* param) {
proto_db_element* current_element = head->next;
proto_db_element* previous = head;
bool flag = 0;
while(current_element) {
//0 - search for name
//1 - search for hex code
switch(type) {
case 0:
if(*(current_element->proto_name) == *((char*)param)) {
flag = 1;
}
break;
case 1:
if(current_element->proto_hex_code == *((u_short*)param)) {
flag = 1;
}
break;
default:
return false;
}
if(flag) {
previous->next = current_element->next;
kfree(current_element);
return true;
}
previous->next = current_element;
current_element = current_element->next;
}
return false;
}
EXPORT_SYMBOL(proto_db_del);
extern proto_db_element* proto_db_find(proto_db_element* head, int type, void* param) {
proto_db_element* current_element = head->next;
while(current_element) {
//0 - search for name
//1 - search for hex code
switch(type) {
case 0:
if(*(current_element->proto_name) == *((char*)param)) {
return current_element;
}
break;
case 1:
if(current_element->proto_hex_code == *((u_short*)param)) {
return current_element;
}
break;
default:
return NULL;
}
current_element = current_element->next;
}
return NULL;
}
EXPORT_SYMBOL(proto_db_find);
module_init(md_init);
module_exit(md_exit);