NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_defs_aodv.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * Copyright (C) 2001 Uppsala University & 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 #ifndef NA_DEFS_H
00023 #define NA_DEFS_H
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #ifndef  _MSC_VER
00028 #include <unistd.h>
00029 #include <sys/time.h>
00030 #include <sys/types.h>
00031 //#include <syslog.h>
00032 #endif
00033 #include "compatibility.h"
00034 
00035 
00036 #ifndef NS_PORT
00037 #include <sys/signal.h>
00038 #include <netinet/in.h>
00039 #include <arpa/inet.h>
00040 #include <netinet/ip.h>
00041 #include <sys/ioctl.h>
00042 #endif
00043 
00044 
00045 
00046 #include <errno.h>
00047 #include <string.h>
00048 #include <fcntl.h>
00049 
00050 #ifndef NS_PORT
00051 #include "NA_timer_queue_aodv.h"
00052 #endif
00053 
00054 #ifdef NS_PORT
00055 #define NS_CLASS NA_AODVUU::
00056 #define NS_OUTSIDE_CLASS ::
00057 #define NS_STATIC
00058 #define NS_INLINE
00059 /* NS_PORT: Using network device 0, with interface index 0. */
00060 #ifndef OMNETPP
00061 // Omnet use integer variables defined in omnet_uu_omnet.h
00062 #define NS_DEV_NR 0
00063 #define NS_IFINDEX NS_DEV_NR
00064 #endif
00065 #else
00066 #define NS_CLASS
00067 #define NS_OUTSIDE_CLASS
00068 #define NS_STATIC static
00069 #define NS_INLINE inline
00070 #endif
00071 
00072 #define AODV_UU_VERSION "0.9"
00073 #define DRAFT_VERSION "rfc3561"
00074 
00075 #ifdef NS_PORT
00076 /* NS_PORT: Log filename split into prefix and suffix. */
00077 #define AODV_LOG_PATH_PREFIX "aodv-uu-"
00078 #define AODV_RT_LOG_PATH_SUFFIX ".rtlog"
00079 #define AODV_LOG_PATH_SUFFIX ".log"
00080 #else
00081 #define AODV_LOG_PATH "/var/log/aodvd.log"
00082 #define AODV_RT_LOG_PATH "/var/log/aodvd.rtlog"
00083 #endif              /* NS_PORT */
00084 
00085 #ifdef OMNETPP
00086 using std::max;
00087 #else
00088 #define max(A,B) ( (A) > (B) ? (A):(B))
00089 #endif   /* OMNETPP */
00090 
00091 #define MINTTL 1        /* min TTL in the packets sent locally */
00092 
00093 #define MAX_NR_INTERFACES 10
00094 #define MAX_IFINDEX (MAX_NR_INTERFACES - 1)
00095 
00096 #if !defined(IFNAMSIZ)
00097 #define IFNAMSIZ 16
00098 #endif
00099 
00100 /* Data for a network device */
00101 struct dev_info
00102 {
00103     int enabled;        /* 1 if struct is used, else 0 */
00104     int sock;           /* AODV socket associated with this device */
00105 #ifdef CONFIG_GATEWAY
00106     int psock;          /* Socket to send buffered data packets. */
00107 #endif
00108     unsigned int ifindex;
00109     char ifname[IFNAMSIZ];
00110     struct in_addr ipaddr;  /* The local IP address */
00111     struct in_addr netmask; /* The netmask we use */
00112     struct in_addr broadcast;
00113 };
00114 
00115 struct host_info
00116 {
00117     u_int32_t seqno;        /* Sequence number */
00118     struct timeval bcast_time;  /* The time of the last broadcast msg sent */
00119     struct timeval fwd_time;    /* The time a data packet was last forwarded */
00120     u_int32_t rreq_id;      /* RREQ id */
00121     int nif;            /* Number of interfaces to broadcast on */
00122     struct dev_info devs[MAX_NR_INTERFACES];
00123 };
00124 
00125 /*
00126   NS_PORT: TEMPORARY SOLUTION: Moved the two variables into the AODVUU class,
00127   and placed the function definition after the AODVUU class definition.
00128 
00129   (This is to avoid running several passes through defs.h during the source
00130   code extraction performed by the AODVUU class.)
00131 
00132   TODO: Find some smarter way to accomplish this.
00133 */
00134 #ifndef NS_PORT
00135 /* This will point to a struct containing information about the host */
00136 struct host_info this_host;
00137 
00138 /* Array of interface indexes */
00139 unsigned int dev_indices[MAX_NR_INTERFACES];
00140 
00141 /* Given a network interface index, return the index into the
00142    devs array, Necessary because ifindex is not always 0, 1,
00143    2... */
00144 static inline int ifindex2devindex(unsigned int ifindex)
00145 {
00146     int i;
00147 
00148     for (i = 0; i < this_host.nif; i++)
00149         if (dev_indices[i] == ifindex)
00150             return i;
00151 
00152     return -1;
00153 }
00154 
00155 static inline struct dev_info *devfromsock(int sock)
00156 {
00157     int i;
00158 
00159     for (i = 0; i < this_host.nif; i++)
00160     {
00161         if (this_host.devs[i].sock == sock)
00162             return &this_host.devs[i];
00163     }
00164     return NULL;
00165 }
00166 
00167 static inline int name2index(char *name)
00168 {
00169     int i;
00170 
00171     for (i = 0; i < this_host.nif; i++)
00172         if (strcmp(name, this_host.devs[i].ifname) == 0)
00173             return this_host.devs[i].ifindex;
00174 
00175     return -1;
00176 }
00177 
00178 #endif
00179 
00180 
00181 /* Two macros to simplify retriving of a dev_info struct. Either using
00182    an ifindex or a device number (index into devs array). */
00183 #ifndef OMNETPP
00184 #define DEV_IFINDEX(ifindex) (this_host.devs[ifindex2devindex(ifindex)])
00185 #define DEV_NR(n) (this_host.devs[n])
00186 #else
00187 #define DEV_IFINDEX(n) (this_host.devs[n])
00188 #define DEV_NR(n) (this_host.devs[n])
00189 #endif
00190 /* Broadcast address according to draft (255.255.255.255) */
00191 #define AODV_BROADCAST ((in_addr_t) 0xFFFFFFFF)
00192 
00193 #define AODV_PORT 654
00194 
00195 /* AODV Message types */
00196 #define AODV_HELLO    0     /* Really never used as a separate type... */
00197 #define AODV_RREQ     1
00198 #define AODV_RREP     2
00199 #define AODV_RERR     3
00200 #define AODV_RREP_ACK 4
00201 
00202 #ifndef OMNETPP
00203 /* An generic AODV extensions header */
00204 typedef struct
00205 {
00206     u_int8_t type;
00207     u_int8_t length;
00208     /* Type specific data follows here */
00209 } AODV_ext;
00210 
00211 /* A generic AODV packet header struct... */
00212 #ifdef NS_PORT
00213 struct AODV_msg
00214 {
00215 #else
00216 typedef struct
00217 {
00218 #endif
00219     u_int8_t type;
00220 
00221     /* NS_PORT: Additions for the AODVUU packet type in ns-2 */
00222 #ifdef NS_PORT
00223     static int offset_;     // Required by PacketHeaderManager
00224 
00225     inline static int &offset()
00226     {
00227         return offset_;
00228     }
00229     inline static AODV_msg *access(const Packet * p)
00230     {
00231         return (AODV_msg *) p->access(offset_);
00232     }
00233 
00234     int size();
00235 };
00236 
00237 typedef AODV_msg hdr_aodvuu;    // Name convention for headers
00238 #define HDR_AODVUU(p) ((hdr_aodvuu *) hdr_aodvuu::access(p))
00239 #else
00240 } AODV_msg;
00241 #endif
00242 
00243 
00244 /* MACROS to access AODV extensions... */
00245 #define AODV_EXT_HDR_SIZE sizeof(AODV_ext)
00246 #define AODV_EXT_DATA(ext) ((char *)((char *)ext + AODV_EXT_HDR_SIZE))
00247 #define AODV_EXT_NEXT(ext) ((AODV_ext *)((char *)ext + AODV_EXT_HDR_SIZE + ext->length))
00248 #define AODV_EXT_SIZE(ext) (AODV_EXT_HDR_SIZE + ext->length)
00249 #endif
00250 
00251 /* AODV Extension types */
00252 #define RREQ_EXT 1
00253 #define RREP_EXT 1
00254 #define RREP_HELLO_INTERVAL_EXT 2
00255 #define RREP_HELLO_NEIGHBOR_SET_EXT 3
00256 #define RREP_INET_DEST_EXT 4
00257 
00258 
00259 
00260 #ifndef NS_PORT
00261 /* The callback function */
00262 typedef void (*callback_func_t) (int);
00263 extern int attach_callback_func(int fd, callback_func_t func);
00264 #endif
00265 
00266 #endif              /* DEFS_H */
 All Classes Files Functions Variables Typedefs Enumerator Defines