forked from wujingbang/aodv-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaodv_neigh_2h.c
More file actions
executable file
·126 lines (95 loc) · 3.07 KB
/
aodv_neigh_2h.c
File metadata and controls
executable file
·126 lines (95 loc) · 3.07 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
118
119
120
121
122
123
124
125
126
/***************************************************************************
Created by Miguel Catalan Cid - miguel.catcid@gmail.com - Version: Mon Jan 1 2010
***************************************************************************/
#include "aodv_neigh_2h.h"
aodv_neigh_2h *aodv_neigh_list_2h;
void init_aodv_neigh_list_2h(void) {
aodv_neigh_list_2h=NULL;
}
void delete_aodv_neigh_list_2h(void) {
aodv_neigh_2h *tmp_entry = aodv_neigh_list_2h;
aodv_neigh_2h *prev_entry = NULL;
while (tmp_entry != NULL) {
prev_entry = tmp_entry;
tmp_entry = tmp_entry->next;
kfree(prev_entry);
}
}
aodv_neigh_2h *find_aodv_neigh_2h(u_int32_t target_ip) {
aodv_neigh_2h *tmp_neigh_2h;
//neigh_read_lock(); //unnecessary
tmp_neigh_2h = aodv_neigh_list_2h;
while ((tmp_neigh_2h != NULL) && (tmp_neigh_2h->ip <= target_ip)) {
if (tmp_neigh_2h->ip == target_ip) {
// neigh_read_unlock();
return tmp_neigh_2h;
}
tmp_neigh_2h = tmp_neigh_2h->next;
}
//neigh_read_unlock();
return NULL;
}
aodv_neigh_2h *create_aodv_neigh_2h(u_int32_t ip) {
aodv_neigh_2h *new_neigh_2h;
aodv_neigh_2h *prev_neigh_2h = NULL;
aodv_neigh_2h *tmp_neigh_2h = NULL;
if ((new_neigh_2h = kmalloc(sizeof(aodv_neigh_2h), GFP_ATOMIC)) == NULL) {
#ifdef DEBUG
printk("NEIGHBOR_LIST_2H: Can't allocate new entry\n");
#endif
return NULL;
}
tmp_neigh_2h = aodv_neigh_list_2h;
while ((tmp_neigh_2h != NULL) && (tmp_neigh_2h->ip < ip)) {
prev_neigh_2h = tmp_neigh_2h;
tmp_neigh_2h = tmp_neigh_2h->next;
}
if (tmp_neigh_2h && (tmp_neigh_2h->ip == ip)) {
#ifdef DEBUG
printk("NEIGHBOR_LIST_2H: Creating a duplicate 2h neighbor entry\n");
#endif
kfree(new_neigh_2h);
return NULL;
}
neigh_write_lock(); //to avoid conflicts with read_neigh_proc (uncontrolled interruption)
printk("NEW NEIGHBOR_2HOPS DETECTED: %s\n", inet_ntoa(ip));
new_neigh_2h->ip = ip;
new_neigh_2h->lifetime = getcurrtime() + NEIGHBOR_2H_TIMEOUT;
new_neigh_2h->next = NULL;
new_neigh_2h->load = 0;
new_neigh_2h->load_seq = 0;
if (prev_neigh_2h == NULL) {
new_neigh_2h->next = aodv_neigh_list_2h;
aodv_neigh_list_2h = new_neigh_2h;
} else {
new_neigh_2h->next = prev_neigh_2h->next;
prev_neigh_2h->next = new_neigh_2h;
}
neigh_write_unlock();
insert_timer_simple(TASK_NEIGHBOR_2H, NEIGHBOR_2H_TIMEOUT + 100, ip);
update_timer_queue();
return new_neigh_2h;
}
int delete_aodv_neigh_2h(u_int32_t ip) {
aodv_neigh_2h *tmp_neigh_2h;
aodv_neigh_2h *prev_neigh_2h = NULL;
neigh_write_lock(); //to avoid conflicts with read_neigh_proc (uncontrolled interruption)
tmp_neigh_2h = aodv_neigh_list_2h;
while (tmp_neigh_2h != NULL) {
if (tmp_neigh_2h->ip == ip) {
if (prev_neigh_2h != NULL) {
prev_neigh_2h->next = tmp_neigh_2h->next;
} else {
aodv_neigh_list_2h = tmp_neigh_2h->next;
}
neigh_write_unlock();
kfree(tmp_neigh_2h);
update_timer_queue();
return 1;
}
prev_neigh_2h = tmp_neigh_2h;
tmp_neigh_2h = tmp_neigh_2h->next;
}
neigh_write_unlock();
return 0;
}