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 <stdlib.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 #include "NA_list.h" 00035 #else 00036 #include "NA_seek_list.h" 00037 #include "NA_timer_queue_aodv.h" 00038 #include "NA_aodv_timeout.h" 00039 #include "NA_defs_aodv.h" 00040 #include "NA_params.h" 00041 #include "NA_debug_aodv.h" 00042 #include "NA_list.h" 00043 #endif 00044 00045 #ifndef NS_PORT 00046 /* The seek list is a linked list of destinations we are seeking 00047 (with RREQ's). */ 00048 00049 static LIST(seekhead); 00050 00051 #ifdef SEEK_LIST_DEBUG 00052 void seek_list_print(); 00053 #endif 00054 #endif /* NS_PORT */ 00055 #ifndef AODV_USE_STL 00056 seek_list_t *NS_CLASS seek_list_insert(struct in_addr dest_addr, 00057 u_int32_t dest_seqno, 00058 int ttl, u_int8_t flags, 00059 struct ip_data *ipd) 00060 { 00061 seek_list_t *entry; 00062 00063 if ((entry = (seek_list_t *) malloc(sizeof(seek_list_t))) == NULL) 00064 { 00065 fprintf(stderr, "Failed malloc\n"); 00066 exit(-1); 00067 } 00068 00069 entry->dest_addr = dest_addr; 00070 entry->dest_seqno = dest_seqno; 00071 entry->flags = flags; 00072 entry->reqs = 0; 00073 entry->ttl = ttl; 00074 entry->ipd = ipd; 00075 00076 timer_init(&entry->seek_timer, &NS_CLASS route_discovery_timeout, entry); 00077 00078 list_add(&seekhead, &entry->l); 00079 #ifdef SEEK_LIST_DEBUG 00080 seek_list_print(); 00081 #endif 00082 return entry; 00083 } 00084 00085 int NS_CLASS seek_list_remove(seek_list_t * entry) 00086 { 00087 if (!entry) 00088 return 0; 00089 00090 list_detach(&entry->l); 00091 00092 /* Make sure any timers are removed */ 00093 timer_remove(&entry->seek_timer); 00094 00095 if (entry->ipd) 00096 free(entry->ipd); 00097 00098 free(entry); 00099 return 1; 00100 } 00101 00102 seek_list_t *NS_CLASS seek_list_find(struct in_addr dest_addr) 00103 { 00104 list_t *pos; 00105 00106 list_foreach(pos, &seekhead) 00107 { 00108 seek_list_t *entry = (seek_list_t *) pos; 00109 00110 if (entry->dest_addr.s_addr == dest_addr.s_addr) 00111 return entry; 00112 } 00113 return NULL; 00114 } 00115 00116 #ifdef SEEK_LIST_DEBUG 00117 void NS_CLASS seek_list_print() 00118 { 00119 list_t *pos; 00120 00121 list_foreach(pos, &seekhead) 00122 { 00123 seek_list_t *entry = (seek_list_t *) pos; 00124 printf("%s %u %d %d\n", ip_to_str(entry->dest_addr), 00125 entry->dest_seqno, entry->reqs, entry->ttl); 00126 } 00127 } 00128 #endif 00129 #else 00130 seek_list_t *NS_CLASS seek_list_insert(struct in_addr dest_addr, 00131 u_int32_t dest_seqno, 00132 int ttl, u_int8_t flags, 00133 struct ip_data *ipd) 00134 { 00135 seek_list_t *entry; 00136 00137 entry = new seek_list_t; 00138 if (entry == NULL) 00139 { 00140 fprintf(stderr, "Failed malloc\n"); 00141 exit(-1); 00142 } 00143 00144 entry->dest_addr = dest_addr; 00145 entry->dest_seqno = dest_seqno; 00146 entry->flags = flags; 00147 entry->reqs = 0; 00148 entry->ttl = ttl; 00149 entry->ipd = ipd; 00150 00151 timer_init(&entry->seek_timer, &NS_CLASS route_discovery_timeout, entry); 00152 seekhead.insert(std::make_pair(dest_addr.s_addr,entry)); 00153 00154 #ifdef SEEK_LIST_DEBUG 00155 seek_list_print(); 00156 #endif 00157 return entry; 00158 } 00159 00160 int NS_CLASS seek_list_remove(seek_list_t * entry) 00161 { 00162 if (!entry) 00163 return 0; 00164 00165 for (SeekHead::iterator it =seekhead.begin();it != seekhead.end(); it++) 00166 { 00167 if (it->second == entry) 00168 { 00169 seekhead.erase(it); 00170 break; 00171 } 00172 } 00173 00174 /* Make sure any timers are removed */ 00175 timer_remove(&entry->seek_timer); 00176 00177 if (entry->ipd) 00178 free(entry->ipd); 00179 00180 delete entry; 00181 return 1; 00182 } 00183 00184 seek_list_t *NS_CLASS seek_list_find(struct in_addr dest_addr) 00185 { 00186 SeekHead::iterator it =seekhead.find(dest_addr.s_addr); 00187 if (it != seekhead.end()) 00188 return it->second; 00189 return NULL; 00190 } 00191 00192 #ifdef SEEK_LIST_DEBUG 00193 void NS_CLASS seek_list_print() 00194 { 00195 for (SeekHead::iterator it =seekhead.begin();it != seekhead.end(); it++) 00196 { 00197 seek_list_t *entry = it->second; 00198 printf("%s %u %d %d\n", ip_to_str(entry->dest_addr), 00199 entry->dest_seqno, entry->reqs, entry->ttl); } 00200 } 00201 #endif 00202 #endif 00203