diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routeconfig.h	Tue May 13 14:03:10 2008 -0700
@@ -0,0 +1,97 @@
+/*
+
+Copyright (c) 2007 Carl Byington - 510 Software Group, released under
+the GPL version 3 or any later version at your choice available at
+http://www.gnu.org/licenses/gpl-3.0.txt
+
+*/
+
+
+class ROUTECONFIG;
+class CONFIG;
+
+enum pattern_style {style_reset, style_path, style_announce, style_withdraw, style_ip};
+enum suspicion     {suspicious_none, suspicious_origin, suspicious_adjacency};
+
+class PATTERN {
+    pattern_style   style;
+    char *          pattern;    // owned by the string table
+    regex_t         re;
+    int             index1;     // zero based substring of the regex match that contains the as list or prefix value
+    int             index2;     // zero based substring of the regex match that contains the prefix length
+public:
+    ~PATTERN();
+    PATTERN(TOKEN &tok, pattern_style style_, char *pattern_, int index1_, int index2_);
+    bool    process(char *buf, CONFIG &con, char *file_name, int pattern_index);
+    void    dump(int level, int index, char *token);
+    void    dump(int level);
+};
+
+typedef ROUTECONFIG *           ROUTECONFIGP;
+typedef PATTERN *               PATTERNP;
+typedef list<ROUTECONFIGP>      routeconfig_list;
+typedef list<PATTERNP>          pattern_list;
+const int buflen = 1024;
+
+class ROUTECONFIG {
+    TOKEN *         tokp;
+    char *          file_name;  // name of the syslog file
+    pattern_list    patterns;   // owns the patterns
+    int             fd;
+    struct stat     openfdstat;
+    int             len;        // bytes in the buffer
+    char            buf[buflen];
+public:
+    ROUTECONFIG(TOKEN &tok, char *file_name_);
+    ~ROUTECONFIG();
+    bool    failed()    { return (fd == -1); };
+    void    open(bool msg);
+    bool    read(CONFIG &con);
+    void    close();
+    void    add_pattern(PATTERNP pat);
+    void    process(CONFIG &con);
+    void    dump(int level);
+};
+
+class CONFIG {
+public:
+    // the only mutable stuff once it has been loaded from the config file
+    int                 reference_count;    // protected by the global config_mutex
+    // all the rest is constant after loading from the config file
+    int                 generation;
+    time_t              load_time;
+    string_set          config_files;
+    routeconfig_list    routeconfigs;       // owns all the route configs
+
+    CONFIG();
+    ~CONFIG();
+    void    add_routeconfig(ROUTECONFIGP con) {routeconfigs.push_back(con);};
+    void    dump();
+    void    read();
+};
+
+void        discard(string_set &s);
+char*       register_string(string_set &s, char *name);
+char*       register_string(char *name);
+void        clear_strings();
+void        clear_rib();
+int         ip_address(char *have);
+bool        load_conf(CONFIG &dc, char *fn);
+void        routing_hourly_update();
+void        token_init();
+
+extern char *token_announce_aslist_index;
+extern char *token_announce_pattern;
+extern char *token_announce_prelen_index;
+extern char *token_announce_preval_index;
+extern char *token_file;
+extern char *token_include;
+extern char *token_lbrace;
+extern char *token_rbrace;
+extern char *token_semi;
+extern char *token_slash;
+extern char *token_withdraw_aslist_index;
+extern char *token_withdraw_pattern;
+extern char *token_withdraw_prelen_index;
+extern char *token_withdraw_preval_index;
+