comparison src/routeconfig.h @ 0:48d06780cf77

initial version
author Carl Byington <carl@five-ten-sg.com>
date Tue, 13 May 2008 14:03:10 -0700
parents
children 180d26aa2a17
comparison
equal deleted inserted replaced
-1:000000000000 0:48d06780cf77
1 /*
2
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
4 the GPL version 3 or any later version at your choice available at
5 http://www.gnu.org/licenses/gpl-3.0.txt
6
7 */
8
9
10 class ROUTECONFIG;
11 class CONFIG;
12
13 enum pattern_style {style_reset, style_path, style_announce, style_withdraw, style_ip};
14 enum suspicion {suspicious_none, suspicious_origin, suspicious_adjacency};
15
16 class PATTERN {
17 pattern_style style;
18 char * pattern; // owned by the string table
19 regex_t re;
20 int index1; // zero based substring of the regex match that contains the as list or prefix value
21 int index2; // zero based substring of the regex match that contains the prefix length
22 public:
23 ~PATTERN();
24 PATTERN(TOKEN &tok, pattern_style style_, char *pattern_, int index1_, int index2_);
25 bool process(char *buf, CONFIG &con, char *file_name, int pattern_index);
26 void dump(int level, int index, char *token);
27 void dump(int level);
28 };
29
30 typedef ROUTECONFIG * ROUTECONFIGP;
31 typedef PATTERN * PATTERNP;
32 typedef list<ROUTECONFIGP> routeconfig_list;
33 typedef list<PATTERNP> pattern_list;
34 const int buflen = 1024;
35
36 class ROUTECONFIG {
37 TOKEN * tokp;
38 char * file_name; // name of the syslog file
39 pattern_list patterns; // owns the patterns
40 int fd;
41 struct stat openfdstat;
42 int len; // bytes in the buffer
43 char buf[buflen];
44 public:
45 ROUTECONFIG(TOKEN &tok, char *file_name_);
46 ~ROUTECONFIG();
47 bool failed() { return (fd == -1); };
48 void open(bool msg);
49 bool read(CONFIG &con);
50 void close();
51 void add_pattern(PATTERNP pat);
52 void process(CONFIG &con);
53 void dump(int level);
54 };
55
56 class CONFIG {
57 public:
58 // the only mutable stuff once it has been loaded from the config file
59 int reference_count; // protected by the global config_mutex
60 // all the rest is constant after loading from the config file
61 int generation;
62 time_t load_time;
63 string_set config_files;
64 routeconfig_list routeconfigs; // owns all the route configs
65
66 CONFIG();
67 ~CONFIG();
68 void add_routeconfig(ROUTECONFIGP con) {routeconfigs.push_back(con);};
69 void dump();
70 void read();
71 };
72
73 void discard(string_set &s);
74 char* register_string(string_set &s, char *name);
75 char* register_string(char *name);
76 void clear_strings();
77 void clear_rib();
78 int ip_address(char *have);
79 bool load_conf(CONFIG &dc, char *fn);
80 void routing_hourly_update();
81 void token_init();
82
83 extern char *token_announce_aslist_index;
84 extern char *token_announce_pattern;
85 extern char *token_announce_prelen_index;
86 extern char *token_announce_preval_index;
87 extern char *token_file;
88 extern char *token_include;
89 extern char *token_lbrace;
90 extern char *token_rbrace;
91 extern char *token_semi;
92 extern char *token_slash;
93 extern char *token_withdraw_aslist_index;
94 extern char *token_withdraw_pattern;
95 extern char *token_withdraw_prelen_index;
96 extern char *token_withdraw_preval_index;
97