forked from wujingbang/aodv-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrerr.c
More file actions
executable file
·126 lines (97 loc) · 3.13 KB
/
rerr.c
File metadata and controls
executable file
·126 lines (97 loc) · 3.13 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
/***************************************************************************
rerr.c - description
-------------------
begin : Mon Aug 11 2003
copyright : (C) 2003 by Luke Klein-Berndt
email : kleinb@nist.gov
***************************************************************************/
/***************************************************************************
Modified by Miguel Catalan Cid - miguel.catcid@gmail.com - Version: Mon Jan 1 2010
***************************************************************************/
#include "rerr.h"
extern u_int32_t g_mesh_ip;
extern u_int32_t g_null_ip;
extern u_int8_t g_aodv_gateway;
extern u_int8_t g_routing_metric;
int reply_to_rrer(u_int32_t source, u_int32_t destination) {
if (source == g_mesh_ip || (source == g_null_ip && g_aodv_gateway))
return 1;
return 0;
}
int gen_rerr(u_int32_t brk_dst_ip) {
aodv_route *tmp_route;
rerr *tmp_rerr;
int expired_routes = 0;
tmp_route = first_aodv_route();
//go through list
while (tmp_route != NULL) {
if ((tmp_route->next_hop == brk_dst_ip) && !tmp_route->self_route
&& !tmp_route->neigh_route) {
if (!reply_to_rrer(tmp_route->src_ip, tmp_route->dst_ip)) { //i'm source of the route, don't send the rerr
if (tmp_route->state != INVALID) {
if ((tmp_rerr = (rerr *) kmalloc(sizeof(rerr), GFP_ATOMIC))
== NULL) {
#ifdef DEBUG
printk("Can't allocate new rrep\n");
#endif
return 0;
}
tmp_rerr->type = RERR_MESSAGE;
tmp_rerr->dst_count = 0; //unused
tmp_rerr->reserved = 0;
tmp_rerr->n = 0;
tmp_rerr->num_hops = 0;
tmp_rerr->dst_ip = tmp_route->dst_ip;
tmp_rerr->dst_id = htonl(tmp_route->dst_id);
send_message(tmp_route->last_hop, NET_DIAMETER, tmp_rerr,
sizeof(rerr));
kfree(tmp_rerr);
}
}
if (tmp_route->state != INVALID){
expire_aodv_route(tmp_route);
expired_routes++;
}
}
//move on to the next entry
tmp_route = tmp_route->next;
}
if (g_routing_metric == WCIM && expired_routes != 0)
update_my_load();
return 0;
}
int recv_rerr(task * tmp_packet) {
aodv_route *tmp_route;
rerr *tmp_rerr;
int num_hops;
int expired_routes = 0;
tmp_rerr = (rerr *) tmp_packet->data;
num_hops = tmp_rerr->num_hops+1;
#ifdef DEBUG
printk("Recieved a route error from %s", inet_ntoa(tmp_packet->src_ip));
#endif
tmp_route
= find_aodv_route_by_id(tmp_rerr->dst_ip, ntohl(tmp_rerr->dst_id));
if (tmp_route && tmp_route->next_hop == tmp_packet->src_ip) {
if (!reply_to_rrer(tmp_route->src_ip, tmp_route->dst_ip)) {
if (tmp_route->state != INVALID) { //route with active traffic
tmp_rerr->type = RERR_MESSAGE;
tmp_rerr->dst_count = 0; //unused
tmp_rerr->reserved = 0;
tmp_rerr->n = 0;
tmp_rerr->num_hops = num_hops;
tmp_rerr->dst_ip = tmp_route->dst_ip;
tmp_rerr->dst_id = htonl(tmp_route->dst_id);
send_message(tmp_route->last_hop, NET_DIAMETER, tmp_rerr,
sizeof(rerr));
}
}
if (tmp_route->state != INVALID) {
expire_aodv_route(tmp_route);
expired_routes++;
}
}
if (g_routing_metric == WCIM && expired_routes != 0)
update_my_load();
return 0;
}