forked from wujingbang/aodv-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_out.c
executable file
·110 lines (97 loc) · 3.45 KB
/
packet_out.c
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
/***************************************************************************
packet_out.c - description
-------------------
begin : Mon Aug 4 2003
copyright : (C) 2003 by Luke Klein-Berndt
email : [email protected]
***************************************************************************/
/***************************************************************************
Modified by Miguel Catalan Cid - [email protected] - Version: Mon Jan 1 2010
***************************************************************************/
#include "packet_out.h"
extern u_int32_t g_broadcast_ip;
extern u_int32_t g_mesh_ip;
extern u_int8_t g_aodv_gateway;
extern u_int32_t g_null_ip;
extern u_int8_t g_routing_metric;
extern int initialized;
unsigned int output_handler(unsigned int hooknum, struct sk_buff *skb,
const struct net_device *in, const struct net_device *out, int (*okfn) (struct sk_buff *)) {
unsigned char *ucp;
struct iphdr *ip= ip_hdr(skb);
u_int32_t source = g_null_ip;
u_int32_t destination = g_null_ip;
aodv_route *tmp_route;
// aodv_neigh *tmp_neigh;
void *p = (uint32_t *) ip + ip->ihl;
struct udphdr *udp = (struct udphdr *) p;
if (!initialized) { // this is required otherwise kernel calls this function without insmod completing the module loading process.
return NF_ACCEPT;
}
//Case 1: AODV-SIGNALLING or Broadcast - ACCEPT!
ucp = (unsigned char *) &ip->daddr;
if ( (ip->daddr == g_broadcast_ip) || ((ucp[3] & 0xff) == 0xff)
|| (udp->dest == htons(AODVPORT)) || (udp->dest == htons(DHCP1))
|| (udp->dest == htons(DHCP2))) // either all 255s or last octet is 255 or the AODVPORT (RREP, ETT...)
{
return NF_ACCEPT;
}
if (is_internal(ip->daddr))
destination = ip->daddr;
if (is_internal(ip->saddr))
source = ip->saddr;
//This packet should not be routed using FB-AODV
// Its upto the kernel route table entry to handle these data packets.
if (destination == source)
return NF_ACCEPT;
tmp_route = find_aodv_route(source, destination, ip->tos);
#ifdef DEBUG
if (tmp_route) {
char src[16];
char dst[16];
char nex[16];
strcpy(src, inet_ntoa(tmp_route->src_ip));
strcpy(dst, inet_ntoa(tmp_route->dst_ip));
strcpy(nex, inet_ntoa(tmp_route->next_hop));
printk ("output_handler: find_aodv_route: from %s to %s, next:%s \n",src, dst, nex);
}
#endif
if ((tmp_route == NULL) || (tmp_route->state == INVALID)) {
if (source == g_mesh_ip || (source == g_null_ip && g_aodv_gateway)) {
if (gen_rreq(source, destination, ip->tos)){
printk("NF_QUEUE1\n");
return NF_QUEUE;
}
else {
printk("NF_DROP2\n");
return NF_DROP;
}
}
else if (destination == g_null_ip && g_aodv_gateway) //i'am a gateway, routing to Internet!
return NF_ACCEPT;
else {
printk("NF_DROP3\n");
return NF_DROP;
}
}
else{
if (tmp_route->state==REPLIED) {
tmp_route->state = ACTIVE;
if (g_routing_metric == WCIM)
insert_timer_simple(TASK_UPDATE_LOAD, 1, g_mesh_ip);
}
tmp_route->lifetime = getcurrtime() + ACTIVE_ROUTE_TIMEOUT;
#ifdef DEBUG
if (tmp_route) {
char src[16];
char dst[16];
char nex[16];
strcpy(src, inet_ntoa(tmp_route->src_ip));
strcpy(dst, inet_ntoa(tmp_route->dst_ip));
strcpy(nex, inet_ntoa(tmp_route->next_hop));
printk ("output_handler: Sending a ICMP: from %s to %s, next:%s \n",src, dst, nex);
}
#endif
return NF_ACCEPT;
}
}