#include "config.h"#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <map>#include "Active.h"#include "util.h"#include "Dict.h"Include dependency graph for Active.cc:

Go to the source code of this file.
Functions | |
| declare (PDict, string) | |
| typedef | PDict (string) MachineMap |
| declare (PDict, MachineMap) | |
| typedef | PDict (MachineMap) ActiveMap |
| declare (PDict, NumericData) | |
| typedef | PDict (NumericData) ActiveMapNumeric |
| bool | get_map_result (uint32 ip_addr, const char *key, string &result) |
| bool | get_map_result (uint32 ip_addr, const NumericData *&result) |
| char * | chop (char *s) |
| bool | load_mapping_table (const char *map_file) |
Variables | |
| ActiveMap | active_map |
| ActiveMapNumeric | active_map_numeric |
| MachineMap | default_values |
| NumericData | default_values_numeric |
| bool | map_was_loaded = false |
| map< const char *, ReassemblyPolicy, ltstr > | reassem_names |
|
|
Definition at line 81 of file Active.cc. Referenced by load_mapping_table().
00082 {
00083 s[strlen(s) - 1] = 0;
00084 return s;
00085 }
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 63 of file Active.cc. References active_map_numeric, default_values_numeric, and uint32. Referenced by NetSessions::DoNextPacket(), TCP_Connection::NextPacket(), and Reassembler::Reassembler().
00064 {
00065 #ifndef ACTIVE_MAPPING
00066 result = &default_values_numeric;
00067 return true;
00068 #endif
00069 HashKey machinekey(&ip_addr, 1);
00070 NumericData* entry = active_map_numeric.Lookup(&machinekey);
00071
00072 if ( ! entry )
00073 result = &default_values_numeric;
00074 else
00075 result = entry;
00076
00077 return true;
00078 }
|
|
||||||||||||||||
|
Definition at line 33 of file Active.cc.
00034 {
00035 const MachineMap* machine_map;
00036 #ifndef ACTIVE_MAPPING
00037 machine_map = &default_values;
00038 #else
00039 HashKey machinekey(ip_addr);
00040 machine_map = active_map.Lookup(&machinekey);
00041
00042 if ( ! machine_map )
00043 machine_map = &default_values;
00044 #endif
00045 HashKey mapkey(key);
00046 string* entry = machine_map->Lookup(&mapkey);
00047 if ( ! entry )
00048 {
00049 entry = default_values.Lookup(&mapkey);
00050 }
00051
00052 if ( ! entry )
00053 {
00054 internal_error("Unknown active mapping entry requested: %s", key);
00055 return false;
00056 }
00057
00058 result = *entry;
00059
00060 return true;
00061 }
|
|
|
Definition at line 90 of file Active.cc. References NumericData::accepts_rst_in_sequence, NumericData::accepts_rst_in_window, NumericData::accepts_rst_outside_window, active_map, active_map_numeric, chop(), default_values, default_values_numeric, error(), NumericData::hops, NumericData::ip_reassem, map_was_loaded, NumericData::path_MTU, reassem_names, RP_BSD, RP_FIRST, RP_LAST, RP_LINUX, RP_UNKNOWN, streq(), string, NumericData::tcp_reassem, uint32, and warn(). Referenced by main().
00091 {
00092 reassem_names["BSD"] = RP_BSD;
00093 reassem_names["linux"] = RP_LINUX;
00094 reassem_names["last"] = RP_LAST;
00095 reassem_names["first"] = RP_FIRST;
00096
00097 // Default values are read in from AM file under IP address 0.0.0.0
00098 default_values.Insert(new HashKey("accepts_rst_outside_window"),
00099 new string("no"));
00100 default_values.Insert(new HashKey("accepts_rst_in_window"),
00101 new string("yes"));
00102 default_values.Insert(new HashKey("accepts_rst_in_sequence"),
00103 new string("yes"));
00104 default_values.Insert(new HashKey("mtu"),
00105 new string("0"));
00106
00107 default_values_numeric.path_MTU = 0; // 0 = unknown
00108 default_values_numeric.hops = 0; // 0 = unknown;
00109 default_values_numeric.ip_reassem = RP_UNKNOWN;
00110 default_values_numeric.tcp_reassem = RP_UNKNOWN;
00111 default_values_numeric.accepts_rst_in_window = true;
00112 default_values_numeric.accepts_rst_outside_window = false;
00113
00114
00115 if ( map_file && strlen(map_file) )
00116 {
00117 FILE* f = fopen(map_file, "r");
00118 if ( ! f )
00119 return false;
00120
00121 char buf[512];
00122 if ( ! fgets(buf, sizeof(buf), f) )
00123 error("Error reading mapping file.\n");
00124
00125 int num_fields = atoi(buf);
00126
00127 string* field_names = new string[num_fields];
00128 for ( int i = 0; i < num_fields; ++i )
00129 {
00130 if ( ! fgets(buf, sizeof(buf), f) )
00131 error("Error reading mapping file.\n");
00132 field_names[i] = chop(buf);
00133 }
00134
00135 if ( ! fgets(buf, sizeof(buf), f) )
00136 error("Error reading mapping file.\n");
00137
00138 int num_machines = atoi(buf);
00139
00140 for ( int j = 0; j < num_machines; ++j )
00141 { // read ip address, parse it
00142 if ( ! fgets(buf, sizeof(buf), f) )
00143 error("Error reading mapping file.\n");
00144
00145 uint32 ip;
00146 in_addr in;
00147 if ( ! inet_aton(chop(buf), &in) )
00148 error("Error reading mapping file.\n");
00149
00150 ip = in.s_addr;
00151
00152 MachineMap* newmap;
00153 NumericData* newnumeric;
00154
00155 if ( ip ) // ip = 0.0.0.0 = default values
00156 {
00157 newmap = new MachineMap;
00158 newnumeric = new NumericData;
00159 }
00160 else
00161 {
00162 newmap = &default_values;
00163 newnumeric = &default_values_numeric;
00164 }
00165
00166 for ( int i = 0; i < num_fields; ++i )
00167 {
00168 if ( ! fgets(buf, sizeof(buf), f) )
00169 error("Error reading mapping file.\n");
00170
00171 string fname = field_names[i];
00172
00173 chop(buf);
00174
00175 // Don't try to parse an unknown value ("").
00176 if ( streq(buf, "") )
00177 continue;
00178
00179 HashKey mapkey(fname.c_str());
00180 newmap->Insert(&mapkey, new string(buf));
00181
00182 if ( fname == "mtu" )
00183 newnumeric->path_MTU = atoi(buf);
00184
00185 else if ( fname == "hops" )
00186 newnumeric->hops = atoi(buf);
00187
00188 else if ( fname == "tcp_segment_overlap" )
00189 newnumeric->tcp_reassem = reassem_names[buf];
00190
00191 else if ( fname == "overlap_policy" )
00192 newnumeric->ip_reassem = reassem_names[buf];
00193
00194 else if ( fname == "accepts_rst_in_window" )
00195 newnumeric->accepts_rst_in_window = streq(buf, "yes");
00196
00197 else if ( fname == "accepts_rst_outside_window" )
00198 newnumeric->accepts_rst_outside_window = streq(buf, "yes");
00199
00200 else if ( fname == "accepts_rst_in_sequence" )
00201 newnumeric->accepts_rst_in_sequence = streq(buf, "yes");
00202
00203 else
00204 warn("unrecognized mapping file tag:", fname.c_str());
00205 }
00206
00207 HashKey machinekey(&ip, 1);
00208 active_map.Insert(&machinekey, newmap);
00209 active_map_numeric.Insert(&machinekey, newnumeric);
00210 }
00211
00212 delete [] field_names;
00213 }
00214
00215 map_was_loaded = true;
00216
00217 return true;
00218 }
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 25 of file Active.cc. Referenced by get_map_result(), and load_mapping_table(). |
|
|
Definition at line 26 of file Active.cc. Referenced by get_map_result(), and load_mapping_table(). |
|
|
Definition at line 28 of file Active.cc. Referenced by get_map_result(), and load_mapping_table(). |
|
|
Definition at line 29 of file Active.cc. Referenced by get_map_result(), and load_mapping_table(). |
|
|
Definition at line 31 of file Active.cc. Referenced by load_mapping_table(). |
|
|
Definition at line 87 of file Active.cc. Referenced by load_mapping_table(). |
1.3.5