]> git.ipfire.org Git - thirdparty/bird.git/blame - conf/conf.h
Unit Testing for BIRD
[thirdparty/bird.git] / conf / conf.h
CommitLineData
fe7cec12
MM
1/*
2 * BIRD Internet Routing Daemon -- Configuration File Handling
3 *
50fe90ed 4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
fe7cec12
MM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_CONF_H_
10#define _BIRD_CONF_H_
11
9b0a0ba9
OZ
12#include "sysdep/config.h"
13#include "lib/ip.h"
fe7cec12 14#include "lib/resource.h"
7152e5ef 15#include "sysdep/unix/timer.h"
fe7cec12 16
48ec367a 17
31b3e1bb
MM
18/* Configuration structure */
19
20struct config {
21 pool *pool; /* Pool the configuration is stored in */
22 linpool *mem; /* Linear pool containing configuration data */
23 list protos; /* Configured protocol instances (struct proto_config) */
4107df1d 24 list tables; /* Configured routing tables (struct rtable_config) */
c8cafc8e 25 list logfiles; /* Configured log files (sysdep) */
9b0a0ba9 26 list tests; /* Configured unit tests */
af582c48 27
cf31112f 28 int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */
44d4ab7a 29 char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
f4a60a9b 30 struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
79b4e12e 31 struct iface_patt *router_id_from; /* Configured list of router ID iface patterns */
cf31112f 32
31b3e1bb 33 u32 router_id; /* Our Router ID */
d72cdff4
OZ
34 ip_addr listen_bgp_addr; /* Listening BGP socket should use this address */
35 unsigned listen_bgp_port; /* Listening BGP socket should use this port (0 is default) */
36 u32 listen_bgp_flags; /* Listening BGP socket should use these flags */
cf31112f
OZ
37 unsigned proto_default_debug; /* Default protocol debug mask */
38 unsigned proto_default_mrtdump; /* Default protocol mrtdump mask */
c37e7851
OZ
39 struct timeformat tf_route; /* Time format for 'show route' */
40 struct timeformat tf_proto; /* Time format for 'show protocol' */
41 struct timeformat tf_log; /* Time format for the logfile */
42 struct timeformat tf_base; /* Time format for other purposes */
0c791f87 43 u32 gr_wait; /* Graceful restart wait timeout */
c37e7851 44
4761efdb 45 int cli_debug; /* Tracing of CLI connections and commands */
8bcb5fb1
OZ
46 int latency_debug; /* I/O loop tracks duration of each event */
47 u32 latency_limit; /* Events with longer duration are logged (us) */
48 u32 watchdog_warning; /* I/O loop watchdog limit for warning (us) */
49 u32 watchdog_timeout; /* Watchdog timeout (in seconds, 0 = disabled) */
31b3e1bb
MM
50 char *err_msg; /* Parser error message */
51 int err_lino; /* Line containing error */
48ec367a
OF
52 char *err_file_name; /* File name containing error */
53 char *file_name; /* Name of main configuration file */
54 int file_fd; /* File descriptor of main configuration file */
c9aae7f4
MM
55 struct symbol **sym_hash; /* Lexer: symbol hash table */
56 struct symbol **sym_fallback; /* Lexer: fallback symbol hash table */
50fe90ed 57 int obstacle_count; /* Number of items blocking freeing of this config */
bf8558bc 58 int shutdown; /* This is a pseudo-config for daemon shutdown */
43270902 59 bird_clock_t load_time; /* When we've got this configuration */
31b3e1bb
MM
60};
61
31b3e1bb 62/* Please don't use these variables in protocols. Use proto_config->global instead. */
50fe90ed
MM
63extern struct config *config; /* Currently active configuration */
64extern struct config *new_config; /* Configuration being parsed */
bf8558bc 65
9b0a0ba9 66struct config *config_alloc(const char *name);
31b3e1bb 67int config_parse(struct config *);
bc2fb680 68int cli_parse(struct config *);
31b3e1bb 69void config_free(struct config *);
a92cf57d
OZ
70int config_commit(struct config *, int type, int timeout);
71int config_confirm(void);
72int config_undo(void);
73void config_init(void);
1a7daab1 74void cf_error(const char *msg, ...) NORET;
50fe90ed
MM
75void config_add_obstacle(struct config *);
76void config_del_obstacle(struct config *);
bf8558bc 77void order_shutdown(void);
50fe90ed 78
a92cf57d
OZ
79#define RECONFIG_NONE 0
80#define RECONFIG_HARD 1
81#define RECONFIG_SOFT 2
82#define RECONFIG_UNDO 3
83
84#define CONF_DONE 0
85#define CONF_PROGRESS 1
86#define CONF_QUEUED 2
87#define CONF_UNQUEUED 3
88#define CONF_CONFIRM 4
89#define CONF_SHUTDOWN -1
90#define CONF_NOTHING -2
91
31b3e1bb 92
49e4a4d1
MM
93/* Pools */
94
b35d72ac 95extern linpool *cfg_mem;
fe7cec12 96
b35d72ac
MM
97#define cfg_alloc(size) lp_alloc(cfg_mem, size)
98#define cfg_allocu(size) lp_allocu(cfg_mem, size)
99#define cfg_allocz(size) lp_allocz(cfg_mem, size)
c8cafc8e 100char *cfg_strdup(const char *c);
a7f23f58 101void cfg_copy_list(list *dest, list *src, unsigned node_size);
49e4a4d1 102
fe7cec12
MM
103/* Lexer */
104
ae80a2de 105extern int (*cf_read_hook)(byte *buf, uint max, int fd);
fe7cec12
MM
106
107struct symbol {
108 struct symbol *next;
c8f61a01 109 struct sym_scope *scope;
fe7cec12 110 int class;
0b62c3a7 111 int aux;
083c43e2 112 void *aux2;
fe7cec12
MM
113 void *def;
114 char name[1];
115};
116
bc7f4e0e
OZ
117#define SYM_MAX_LEN 64
118
c0b2f646 119/* Remember to update cf_symbol_class_name() */
fe7cec12 120#define SYM_VOID 0
8450be97 121#define SYM_PROTO 1
1103b32e 122#define SYM_TEMPLATE 2
cbc31830
MM
123#define SYM_FUNCTION 3
124#define SYM_FILTER 4
125#define SYM_TABLE 5
fe7cec12 126
cbc31830 127#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
1103b32e
OZ
128#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
129
130#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type)
131#define SYM_VAL(s) (((struct f_val *) (s)->def)->val)
ba921648 132
48ec367a 133struct include_file_stack {
4be266a9
OZ
134 void *buffer; /* Internal lexer state */
135 char *file_name; /* File name */
136 int fd; /* File descriptor */
137 int lino; /* Current line num */
138 int depth; /* Include depth, 0 = cannot include */
139
140 struct include_file_stack *prev; /* Previous record in stack */
141 struct include_file_stack *up; /* Parent (who included this file) */
48ec367a
OF
142};
143
9b7fdfc8 144extern struct include_file_stack *ifs;
48ec367a 145
31b3e1bb 146
fe7cec12 147int cf_lex(void);
48ec367a 148void cf_lex_init(int is_cli, struct config *c);
0c3d9dac
OZ
149void cf_lex_unwind(void);
150
9b9a7143
OZ
151struct symbol *cf_find_symbol(struct config *cfg, byte *c);
152
153struct symbol *cf_get_symbol(byte *c);
d272fe22 154struct symbol *cf_default_name(char *template, int *counter);
04dc62a0 155struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
df8b85e3
MM
156void cf_push_scope(struct symbol *);
157void cf_pop_scope(void);
4b87e256
MM
158struct symbol *cf_walk_symbols(struct config *cf, struct symbol *sym, int *pos);
159char *cf_symbol_class_name(struct symbol *sym);
fe7cec12 160
b2f00837
OZ
161static inline int cf_symbol_is_constant(struct symbol *sym)
162{ return (sym->class & 0xff00) == SYM_CONSTANT; }
163
164
fe7cec12
MM
165/* Parser */
166
9b0a0ba9 167extern char *cf_text;
fe7cec12
MM
168int cf_parse(void);
169
7c0cc76e
MM
170/* Sysdep hooks */
171
172void sysdep_preconfig(struct config *);
50fe90ed 173int sysdep_commit(struct config *, struct config *);
bf8558bc 174void sysdep_shutdown_done(void);
7c0cc76e 175
fe7cec12 176#endif