NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
00001 /***************************************************************************** 00002 * 00003 * Copyright (C) 2001 Uppsala University and Ericsson AB. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: Erik Nordstr�m, <erik.nordstrom@it.uu.se> 00020 * 00021 * 00022 *****************************************************************************/ 00023 #define NS_PORT 00024 #define OMNETPP 00025 00026 #include <time.h> 00027 00028 #ifdef NS_PORT 00029 #ifndef OMNETPP 00030 #include "ns/aodv-uu.h" 00031 #else 00032 #include "../NA_aodv_uu_omnet.h" 00033 #endif 00034 #else 00035 #include "NA_defs_aodv.h" 00036 #include "NA_aodv_timeout.h" 00037 #include "NA_aodv_socket.h" 00038 #include "NA_aodv_neighbor.h" 00039 #include "NA_aodv_rreq.h" 00040 #include "NA_aodv_hello.h" 00041 #include "NA_aodv_rerr.h" 00042 #include "NA_timer_queue_aodv.h" 00043 #include "NA_debug_aodv.h" 00044 #include "NA_params.h" 00045 #include "NA_routing_table.h" 00046 #include "NA_seek_list.h" 00047 #include "NA_nl.h" 00048 00049 extern int expanding_ring_search, local_repair; 00050 void route_delete_timeout(void *arg); 00051 00052 #endif 00053 00054 /* These are timeout functions which are called when timers expire... */ 00055 00056 void NS_CLASS route_discovery_timeout(void *arg) 00057 { 00058 struct timeval now; 00059 seek_list_t *seek_entry; 00060 rt_table_t *rt, *repair_rt; 00061 seek_entry = (seek_list_t *) arg; 00062 00063 #define TTL_VALUE seek_entry->ttl 00064 00065 /* Sanity check... */ 00066 if (!seek_entry) 00067 return; 00068 00069 gettimeofday(&now, NULL); 00070 00071 DEBUG(LOG_DEBUG, 0, "%s", ip_to_str(seek_entry->dest_addr)); 00072 00073 if (seek_entry->reqs < RREQ_RETRIES) 00074 { 00075 00076 if (expanding_ring_search) 00077 { 00078 00079 if (TTL_VALUE < TTL_THRESHOLD) 00080 TTL_VALUE += TTL_INCREMENT; 00081 else 00082 { 00083 TTL_VALUE = NET_DIAMETER; 00084 seek_entry->reqs++; 00085 } 00086 /* Set a new timer for seeking this destination */ 00087 timer_set_timeout(&seek_entry->seek_timer, RING_TRAVERSAL_TIME); 00088 } 00089 else 00090 { 00091 seek_entry->reqs++; 00092 timer_set_timeout(&seek_entry->seek_timer, 00093 seek_entry->reqs * 2 * NET_TRAVERSAL_TIME); 00094 } 00095 /* AODV should use a binary exponential backoff RREP waiting 00096 time. */ 00097 DEBUG(LOG_DEBUG, 0, "Seeking %s ttl=%d wait=%d", 00098 ip_to_str(seek_entry->dest_addr), 00099 TTL_VALUE, 2 * TTL_VALUE * NODE_TRAVERSAL_TIME); 00100 00101 /* A routing table entry waiting for a RREP should not be expunged 00102 before 2 * NET_TRAVERSAL_TIME... */ 00103 rt = rt_table_find(seek_entry->dest_addr); 00104 00105 #ifdef AODV_USE_STL 00106 if (rt && ((rt->rt_timer.timeout - simTime() ) < (2 * NET_TRAVERSAL_TIME))) 00107 rt_table_update_timeout(rt, 2 * NET_TRAVERSAL_TIME); 00108 #else 00109 if (rt && timeval_diff(&rt->rt_timer.timeout, &now) < (2 * NET_TRAVERSAL_TIME)) 00110 rt_table_update_timeout(rt, 2 * NET_TRAVERSAL_TIME); 00111 #endif 00112 rreq_send(seek_entry->dest_addr, seek_entry->dest_seqno, 00113 TTL_VALUE, seek_entry->flags); 00114 00115 } 00116 else 00117 { 00118 00119 DEBUG(LOG_DEBUG, 0, "NO ROUTE FOUND!"); 00120 00121 #ifdef NS_PORT 00122 std::vector<ManetAddress> list; 00123 getListRelatedAp(seek_entry->dest_addr.s_addr, list); 00124 for (unsigned int i = 0; i < list.size();i ++) 00125 { 00126 struct in_addr auxAaddr; 00127 auxAaddr.s_addr = list[i]; 00128 packet_queue_set_verdict(auxAaddr, PQ_DROP); 00129 } 00130 #else 00131 nl_send_no_route_found_msg(seek_entry->dest_addr); 00132 #endif 00133 repair_rt = rt_table_find(seek_entry->dest_addr); 00134 00135 seek_list_remove(seek_entry); 00136 00137 /* If this route has been in repair, then we should timeout 00138 the route at this point. */ 00139 if (repair_rt && (repair_rt->flags & RT_REPAIR)) 00140 { 00141 DEBUG(LOG_DEBUG, 0, "REPAIR for %s failed!", 00142 ip_to_str(repair_rt->dest_addr)); 00143 local_repair_timeout(repair_rt); 00144 } 00145 } 00146 } 00147 00148 void NS_CLASS local_repair_timeout(void *arg) 00149 { 00150 rt_table_t *rt; 00151 struct in_addr rerr_dest; 00152 RERR *rerr = NULL; 00153 00154 rt = (rt_table_t *) arg; 00155 00156 if (!rt) 00157 return; 00158 00159 if (rt->state == IMMORTAL) 00160 { 00161 DEBUG(LOG_DEBUG, 0, "Route %s is immortal!!!", 00162 ip_to_str(rt->dest_addr)); 00163 return; 00164 } 00165 00166 rerr_dest.s_addr = ManetAddress(IPv4Address(AODV_BROADCAST)); /* Default destination */ 00167 00168 /* Unset the REPAIR flag */ 00169 rt->flags &= ~RT_REPAIR; 00170 00171 #ifndef NS_PORT 00172 nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt); 00173 #else 00174 #ifdef OMNETPP 00175 /* delete route to omnet inet routing table ... */ 00176 /* if delete is true fiels next, hops and mask are nor used */ 00177 struct in_addr nm; 00178 nm.s_addr = ManetAddress(IPv4Address::ALLONES_ADDRESS); 00179 omnet_chg_rte(rt->dest_addr, rt->dest_addr, nm, rt->hcnt,true); 00180 #endif 00181 #endif 00182 /* Route should already be invalidated. */ 00183 00184 if (rt->nprec) 00185 { 00186 00187 rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno); 00188 00189 if (rt->nprec == 1) 00190 { 00191 #ifdef AODV_USE_STL_RT 00192 rerr_dest = rt->precursors[0].neighbor; 00193 #else 00194 rerr_dest = FIRST_PREC(rt->precursors)->neighbor; 00195 #endif 00196 00197 aodv_socket_send((AODV_msg *) rerr, rerr_dest, 00198 RERR_CALC_SIZE(rerr), 1, 00199 &DEV_IFINDEX(rt->ifindex)); 00200 } 00201 else 00202 { 00203 int i; 00204 00205 for (i = 0; i < MAX_NR_INTERFACES; i++) 00206 { 00207 if (!DEV_NR(i).enabled) 00208 continue; 00209 aodv_socket_send((AODV_msg *) rerr, rerr_dest, 00210 RERR_CALC_SIZE(rerr), 1, &DEV_NR(i)); 00211 } 00212 } 00213 DEBUG(LOG_DEBUG, 0, "Sending RERR about %s to %s", 00214 ip_to_str(rt->dest_addr), ip_to_str(rerr_dest)); 00215 } 00216 precursor_list_destroy(rt); 00217 00218 /* Purge any packets that may be queued */ 00219 /* packet_queue_set_verdict(rt->dest_addr, PQ_DROP); */ 00220 00221 rt->rt_timer.handler = &NS_CLASS route_delete_timeout; 00222 timer_set_timeout(&rt->rt_timer, DELETE_PERIOD); 00223 00224 DEBUG(LOG_DEBUG, 0, "%s removed in %u msecs", 00225 ip_to_str(rt->dest_addr), DELETE_PERIOD); 00226 } 00227 00228 00229 void NS_CLASS route_expire_timeout(void *arg) 00230 { 00231 rt_table_t *rt; 00232 00233 rt = (rt_table_t *) arg; 00234 00235 if (!rt) 00236 { 00237 alog(LOG_WARNING, 0, __FUNCTION__, "arg was NULL, ignoring timeout!"); 00238 return; 00239 } 00240 00241 if (rt->state == IMMORTAL) 00242 { 00243 DEBUG(LOG_DEBUG, 0, "Route %s is immortal!!!", 00244 ip_to_str(rt->dest_addr)); 00245 return; 00246 } 00247 00248 DEBUG(LOG_DEBUG, 0, "Route %s DOWN, seqno=%d", 00249 ip_to_str(rt->dest_addr), rt->dest_seqno); 00250 00251 if (rt->hcnt == 1) 00252 neighbor_link_break(rt); 00253 else 00254 { 00255 rt_table_invalidate(rt); 00256 precursor_list_destroy(rt); 00257 } 00258 00259 return; 00260 } 00261 00262 void NS_CLASS route_delete_timeout(void *arg) 00263 { 00264 rt_table_t *rt; 00265 00266 rt = (rt_table_t *) arg; 00267 00268 /* Sanity check: */ 00269 if (!rt) 00270 return; 00271 00272 if (rt->state == IMMORTAL) 00273 { 00274 DEBUG(LOG_DEBUG, 0, "Route %s is immortal!!!", 00275 ip_to_str(rt->dest_addr)); 00276 return; 00277 } 00278 00279 DEBUG(LOG_DEBUG, 0, "%s", ip_to_str(rt->dest_addr)); 00280 00281 rt_table_delete(rt); 00282 } 00283 00284 /* This is called when we stop receiveing hello messages from a 00285 node. For now this is basically the same as a route timeout. */ 00286 void NS_CLASS hello_timeout(void *arg) 00287 { 00288 rt_table_t *rt; 00289 struct timeval now; 00290 00291 rt = (rt_table_t *) arg; 00292 00293 if (!rt) 00294 return; 00295 00296 if (rt->state == IMMORTAL) 00297 { 00298 DEBUG(LOG_DEBUG, 0, "Route %s is immortal!!!", 00299 ip_to_str(rt->dest_addr)); 00300 return; 00301 } 00302 00303 00304 gettimeofday(&now, NULL); 00305 00306 DEBUG(LOG_DEBUG, 0, "LINK/HELLO FAILURE %s last HELLO: %d", 00307 ip_to_str(rt->dest_addr), timeval_diff(&now, &rt->last_hello_time)); 00308 00309 if (rt && rt->state == VALID && !(rt->flags & RT_UNIDIR)) 00310 { 00311 00312 /* If the we can repair the route, then mark it to be 00313 repaired.. */ 00314 if (local_repair && rt->hcnt <= MAX_REPAIR_TTL) 00315 { 00316 rt->flags |= RT_REPAIR; 00317 DEBUG(LOG_DEBUG, 0, "Marking %s for REPAIR", 00318 ip_to_str(rt->dest_addr)); 00319 #ifdef NS_PORT 00320 /* Buffer pending packets from interface queue */ 00321 #ifndef OMNETPP 00322 // Aodv in Omnet don't clear level 2 queue 00323 interfaceQueue((nsaddr_t) rt->dest_addr.s_addr, IFQ_BUFFER); 00324 #endif 00325 #endif 00326 } 00327 neighbor_link_break(rt); 00328 } 00329 } 00330 00331 void NS_CLASS rrep_ack_timeout(void *arg) 00332 { 00333 rt_table_t *rt; 00334 00335 /* We must be really sure here, that this entry really exists at 00336 this point... (Though it should). */ 00337 rt = (rt_table_t *) arg; 00338 00339 if (!rt) 00340 return; 00341 00342 /* When a RREP transmission fails (i.e. lack of RREP-ACK), add to 00343 blacklist set... */ 00344 rreq_blacklist_insert(rt->dest_addr); 00345 00346 DEBUG(LOG_DEBUG, 0, "%s", ip_to_str(rt->dest_addr)); 00347 } 00348 00349 void NS_CLASS wait_on_reboot_timeout(void *arg) 00350 { 00351 *((int *) arg) = 0; 00352 00353 DEBUG(LOG_DEBUG, 0, "Wait on reboot over!!"); 00354 } 00355 00356 #ifdef NS_PORT 00357 void NS_CLASS packet_queue_timeout(void *arg) 00358 { 00359 packet_queue_garbage_collect(); 00360 timer_set_timeout(&PQ.garbage_collect_timer, GARBAGE_COLLECT_TIME); 00361 } 00362 #endif