annotate src/routeconfig.h @ 7:3c0db610c641

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