00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "packet_in.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 extern u_int32_t g_broadcast_ip;
00037 extern u_int32_t g_my_ip;
00038 extern struct flood_id_queue_entry *multicast_id_queue;
00039
00040 #ifdef AODV_MULTICAST
00041 extern struct socket * multicast_sock;
00042 #endif
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 int check_packet (int numbytes, int type, void *data_in)
00064 {
00065
00066 int *data;
00067
00068 struct rerr *tmp_rerr;
00069 data=(int *) data_in;
00070
00071 switch (type)
00072 {
00073
00074 case 1:
00075
00076
00077 if (numbytes == 24)
00078 return 0;
00079 if (numbytes<=26)
00080 return 1;
00081 if (data[25]==3 && data[26]==8 && numbytes==24+2+8)
00082 return 0;
00083 if (data[25]==4 && data[26]==2 && numbytes==24+2+2)
00084 return 0;
00085 break;
00086
00087
00088 case 2:
00089
00090 if (numbytes == 20)
00091 return 0;
00092 if (numbytes<= 22)
00093 return 1;
00094 if (data[21]==5 && data[22]==6 && numbytes==20+2+6)
00095
00096 break;
00097
00098
00099 case 3:
00100
00101
00102 tmp_rerr=data_in;
00103 if (numbytes == sizeof(struct rerr) + (sizeof(struct rerrdst) * tmp_rerr->dst_count))
00104 {
00105 return 0;
00106 }
00107 break;
00108
00109 case 4:
00110 if (numbytes == 2)
00111 return 0;
00112 break;
00113
00114 default:
00115 break;
00116 }
00117
00118 return 1;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 int packet_in(struct sk_buff *packet)
00133 {
00134 struct net_device *dev;
00135 struct route_table_entry *tmp_route;
00136 struct iphdr *ip;
00137 u_int32_t tmp_ip;
00138
00139
00140
00141 u_int8_t aodv_type;
00142
00143
00144
00145 int start_point=sizeof(struct udphdr)+sizeof(struct iphdr);
00146
00147
00148
00149 ip = packet->nh.iph;
00150 dev = packet->dev;
00151
00152
00153
00154 tmp_ip=find_dev_ip(dev);
00155
00156
00157 if (tmp_ip==ip->saddr)
00158 {
00159 return NF_DROP;
00160 }
00161
00162 if ((strcmp(dev->name,"lo")==0) && !USE_LO)
00163 {
00164 return NF_DROP;
00165 }
00166
00167 if ((ip->daddr!=g_broadcast_ip) && (adhoc_subnet_test(ip->daddr)))
00168 {
00169 tmp_route=find_route_table_entry(ip->daddr);
00170 if ((tmp_route==NULL) || !tmp_route->route_valid)
00171 {
00172 printk( KERN_NOTICE "AODV: Undestination, %s, unable to forward...\n", inet_ntoa(ip->daddr));
00173 host_unr(ip->daddr);
00174 }
00175 }
00176
00177
00178
00179
00180 aodv_type = (int)packet->data[start_point];
00181
00182 if (check_packet(packet->len-start_point,aodv_type,packet->data+start_point))
00183 {
00184 printk(KERN_NOTICE "AODV: Packet of type: %d and of size %u failed packet check!\n",aodv_type,packet->len-start_point);
00185 return NF_DROP;
00186
00187 }
00188
00189 tmp_route=find_route_table_entry(ip->saddr);
00190
00191 if ((tmp_route!=NULL) && (tmp_route->route_valid))
00192 {
00193 tmp_route->lifetime=(HELLO_INTERVAL * ALLOWED_HELLO_LOSS) + getcurrtime();
00194 }
00195
00196
00197 insert_event_queue_entry(aodv_type,packet);
00198
00199 return NF_ACCEPT;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 unsigned int input_handler(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
00211 {
00212 struct iphdr *ip = (*skb)->nh.iph;
00213 void *p = (uint32_t *) ip + ip->ihl;
00214 struct udphdr *hdr=p;
00215
00216 struct ethhdr *mac = (*skb)->mac.ethernet;
00217
00218
00219 #ifdef AODV_MULTICAST
00220 unsigned char *ucp;
00221 #endif
00222
00223
00224
00225
00226
00227
00228
00229 #ifdef AODV_MULTICAST
00230 if ((ip!=NULL) && (multicast_test(ip->daddr)) && (ip->saddr!=g_my_ip))
00231 {
00232 if (check_check(ip->saddr,ntohs(ip->id)))
00233 {
00234 ucp=(unsigned char *)&(ip->saddr);
00235
00236
00237
00238
00239
00240 if (sock_wspace(multicast_sock->sk)>40000)
00241 insert_rebroadcast_queue_entry(ip->daddr,(*skb)->len,(*skb)->data,ip->ttl);
00242
00243 }
00244 else
00245 {
00246
00247 return NF_DROP;
00248 }
00249
00250 }
00251 #endif
00252
00253
00254 if ((*skb)->h.uh!=NULL)
00255 {
00256 if ((hdr->dest==htons(AODVPORT)) && (mac->h_proto==htons(ETH_P_IP)) )
00257 {
00258
00259 return packet_in(*(skb));
00260 }
00261 }
00262
00263 return NF_ACCEPT;
00264
00265 }
00266
00267