NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_routing_table.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  *****************************************************************************/
00023 #ifndef NA_ROUTING_TABLE_H
00024 #define NA_ROUTING_TABLE_H
00025 
00026 #ifndef NS_NO_GLOBALS
00027 #include "NA_defs_aodv.h"
00028 #include "NA_list.h"
00029 
00030 typedef struct rt_table rt_table_t;
00031 
00032 /* Neighbor struct for active routes in Route Table */
00033 #define FIRST_PREC(h) ((precursor_t *)((h).next))
00034 
00035 #define seqno_incr(s) ((s == 0) ? 0 : ((s == 0xFFFFFFFF) ? s = 1 : s++))
00036 
00037 typedef u_int32_t hash_value;   /* A hash value */
00038 
00039 #ifdef AODV_USE_STL_RT
00040 typedef struct precursor
00041 {
00042     struct in_addr neighbor;
00043 } precursor_t;
00044 
00045 struct rt_table
00046 {
00047     struct in_addr dest_addr;   /* IP address of the destination */
00048     u_int32_t dest_seqno;
00049     unsigned int ifindex;   /* Network interface index... */
00050     struct in_addr next_hop;    /* IP address of the next hop to the dest */
00051     u_int8_t hcnt;      /* Distance (in hops) to the destination */
00052     u_int16_t flags;        /* Routing flags */
00053     u_int8_t state;     /* The state of this entry */
00054     uint32_t    cost; // without the last node
00055     uint8_t     hopfix;
00056 
00057     struct timer rt_timer;  /* The timer associated with this entry */
00058     struct timer ack_timer; /* RREP_ack timer for this destination */
00059     struct timer hello_timer;
00060     struct timeval last_hello_time;
00061     hash_value hash;
00062     u_int8_t hello_cnt;
00063     int nprec;          /* Number of precursors */
00064     std::vector<precursor_t> precursors;      /* List of neighbors using the route */
00065 };
00066 #else
00067 typedef struct precursor
00068 {
00069     list_t l;
00070     struct in_addr neighbor;
00071 } precursor_t;
00072 
00073 /* Route table entries */
00074 struct rt_table
00075 {
00076     list_t l;
00077     struct in_addr dest_addr;   /* IP address of the destination */
00078     u_int32_t dest_seqno;
00079     unsigned int ifindex;   /* Network interface index... */
00080     struct in_addr next_hop;    /* IP address of the next hop to the dest */
00081     u_int8_t hcnt;      /* Distance (in hops) to the destination */
00082     u_int16_t flags;        /* Routing flags */
00083     u_int8_t state;     /* The state of this entry */
00084     uint32_t    cost; // without the last node
00085     uint8_t     hopfix;
00086 
00087     struct timer rt_timer;  /* The timer associated with this entry */
00088     struct timer ack_timer; /* RREP_ack timer for this destination */
00089     struct timer hello_timer;
00090     struct timeval last_hello_time;
00091     u_int8_t hello_cnt;
00092     hash_value hash;
00093     int nprec;          /* Number of precursors */
00094     list_t precursors;      /* List of neighbors using the route */
00095 };
00096 #endif
00097 
00098 /* Route entry flags */
00099 #define RT_UNIDIR        0x1
00100 #define RT_REPAIR        0x2
00101 #define RT_INV_SEQNO     0x4
00102 #define RT_INET_DEST     0x8    /* Mark for Internet destinations (to be relayed
00103 * through a Internet gateway. */
00104 #define RT_GATEWAY       0x10
00105 
00106 /* Route entry states */
00107 #define INVALID   0
00108 #define VALID     1
00109 #define IMMORTAL  2
00110 
00111 
00112 #define RT_TABLESIZE 64     /* Must be a power of 2 */
00113 #define RT_TABLEMASK (RT_TABLESIZE - 1)
00114 
00115 struct routing_table
00116 {
00117     unsigned int num_entries;
00118     unsigned int num_active;
00119     list_t tbl[RT_TABLESIZE];
00120 };
00121 void precursor_list_destroy(rt_table_t * rt);
00122 #endif              /* NS_NO_GLOBALS */
00123 
00124 
00125 #ifndef NS_NO_DECLARATIONS
00126 struct routing_table rt_tbl;
00127 
00128 void rt_table_init();
00129 void rt_table_destroy();
00130 rt_table_t *rt_table_insert(struct in_addr dest, struct in_addr next,
00131                             u_int8_t hops, u_int32_t seqno, u_int32_t life,
00132                             u_int8_t state, u_int16_t flags,
00133                             unsigned int ifindex,
00134                             uint32_t cost,uint8_t hopfix);
00135 rt_table_t *rt_table_update(rt_table_t * rt, struct in_addr next, u_int8_t hops,
00136                             u_int32_t seqno, u_int32_t lifetime, u_int8_t state,
00137                             u_int16_t flags,int iface,
00138                             uint32_t cost,uint8_t hopfix);
00139 
00140 NS_INLINE rt_table_t *rt_table_update_timeout(rt_table_t * rt,
00141         u_int32_t lifetime);
00142 void rt_table_update_route_timeouts(rt_table_t * fwd_rt, rt_table_t * rev_rt);
00143 rt_table_t *rt_table_find(struct in_addr dest);
00144 rt_table_t *rt_table_find_gateway();
00145 int rt_table_update_inet_rt(rt_table_t * gw, u_int32_t life);
00146 int rt_table_invalidate(rt_table_t * rt);
00147 void rt_table_delete(rt_table_t * rt);
00148 void precursor_add(rt_table_t * rt, struct in_addr addr);
00149 void precursor_remove(rt_table_t * rt, struct in_addr addr);
00150 
00151 #ifdef OMNETPP
00152 rt_table_t * modifyAODVTables(struct in_addr,
00153                               struct in_addr next,
00154                               u_int8_t hops, u_int32_t seqno,
00155                               u_int32_t life, u_int8_t state,
00156                               u_int16_t flags, unsigned int ifindex);
00157 #endif
00158 
00159 #endif              /* NS_NO_DECLARATIONS */
00160 
00161 #endif              /* ROUTING_TABLE_H */
 All Classes Files Functions Variables Typedefs Enumerator Defines