comparison src/routeconfig.cpp @ 2:bb3f804f13a0

add random unsynchronization to hourly timer, trust prefix only for same origin AS, ignore self adjacency
author Carl Byington <carl@five-ten-sg.com>
date Mon, 19 May 2008 21:45:45 -0700
parents 48d06780cf77
children 180d26aa2a17
comparison
equal deleted inserted replaced
1:47f787af96c1 2:bb3f804f13a0
64 void add_route(aspath path_, a_history &adj_history); 64 void add_route(aspath path_, a_history &adj_history);
65 void remove_route(int prefix_length); 65 void remove_route(int prefix_length);
66 uint32_t prefix() const { return prefix_value; }; 66 uint32_t prefix() const { return prefix_value; };
67 bool active() const { return announced; }; 67 bool active() const { return announced; };
68 adjacent aspair(int i) const { return adjacent(path[i], path[i+1]); }; 68 adjacent aspair(int i) const { return adjacent(path[i], path[i+1]); };
69 bool selfpair(int i) const { return (path[1] == path[i+1]); };
69 bool empty() const { return !announced && origin_history.empty(); }; 70 bool empty() const { return !announced && origin_history.empty(); };
70 void update_history(a_set &adj_set); 71 void update_history(a_set &adj_set);
71 suspicion suspicious(a_history &adj_history, bool debug = false, int prefix_length = 0, uint32_t ip = 0); 72 suspicion suspicious(a_history &adj_history, bool debug = false, int prefix_length = 0, uint32_t ip = 0);
72 void record_smtp(uint32_t ip); 73 void record_smtp(uint32_t ip);
73 string name(int length) const; 74 string name(int length) const;
165 166
166 167
167 void route_prefix::add_route(aspath path_, a_history &adj_history) 168 void route_prefix::add_route(aspath path_, a_history &adj_history)
168 { 169 {
169 suspicion s = suspicious(adj_history); 170 suspicion s = suspicious(adj_history);
170 trusted = announced && (s == suspicious_none); 171 int oldorig = path.empty() ? 0 : path [path.size() - 1];
172 int neworig = path_.empty() ? 0 : path_[path_.size() - 1];
173 trusted = announced && (s == suspicious_none) && (oldorig == neworig);
171 announced = true; 174 announced = true;
172 path = path_; 175 path = path_;
173 } 176 }
174 177
175 178
224 float &count = (*j).second; 227 float &count = (*j).second;
225 count++; 228 count++;
226 } 229 }
227 // update current adjacency set 230 // update current adjacency set
228 for (int k=0; k<n; k++) { 231 for (int k=0; k<n; k++) {
229 adj_set.insert(aspair(k)); 232 if (!selfpair(k)) adj_set.insert(aspair(k));
230 } 233 }
231 } 234 }
232 235
233 // remove origin history entries below the threshold 236 // remove origin history entries below the threshold
234 for (o_history::iterator i = origin_history.begin(); i != origin_history.end();) { 237 for (o_history::iterator i = origin_history.begin(); i != origin_history.end();) {
270 return suspicious_origin; 273 return suspicious_origin;
271 } 274 }
272 275
273 // check as adjacency stability 276 // check as adjacency stability
274 for (int k=0; k<n; k++) { 277 for (int k=0; k<n; k++) {
275 adjacent aa = aspair(k); 278 if (!selfpair(k)) {
276 a_history::iterator a = adj_history.find(aa); 279 adjacent aa = aspair(k);
277 if (a == adj_history.end()) { 280 a_history::iterator a = adj_history.find(aa);
278 if (debug) { 281 if (a == adj_history.end()) {
279 char buf[maxlen]; 282 if (debug) {
280 snprintf(buf, sizeof(buf), "debug suspicious adjacency (%d,%d) missing count %s", 283 char buf[maxlen];
281 aa.first, aa.second, name(prefix_length).c_str()); 284 snprintf(buf, sizeof(buf), "debug suspicious adjacency (%d,%d) missing count %s",
282 my_syslog(buf); 285 aa.first, aa.second, name(prefix_length).c_str());
286 my_syslog(buf);
287 }
288 record_smtp(ip);
289 return suspicious_adjacency;
283 } 290 }
284 record_smtp(ip); 291 float &count = (*a).second;
285 return suspicious_adjacency; 292 if (count < adjacent_threshold) {
286 } 293 if (debug) {
287 float &count = (*a).second; 294 char buf[maxlen];
288 if (count < adjacent_threshold) { 295 snprintf(buf, sizeof(buf), "debug suspicious adjacency (%d,%d) count %5.2f vs %5.2f %s",
289 if (debug) { 296 aa.first, aa.second, count, adjacent_threshold, name(prefix_length).c_str());
290 char buf[maxlen]; 297 my_syslog(buf);
291 snprintf(buf, sizeof(buf), "debug suspicious adjacency (%d,%d) count %5.2f vs %5.2f %s", 298 }
292 aa.first, aa.second, count, adjacent_threshold, name(prefix_length).c_str()); 299 record_smtp(ip);
293 my_syslog(buf); 300 return suspicious_adjacency;
294 } 301 }
295 record_smtp(ip);
296 return suspicious_adjacency;
297 } 302 }
298 } 303 }
299 return suspicious_none; 304 return suspicious_none;
300 } 305 }
301 306