Statistics
| Branch: | Revision:

iof-bird-daemon / conf / conf.h @ 9b0a0ba9

History | View | Annotate | Download (5.8 KB)

1
/*
2
 *        BIRD Internet Routing Daemon -- Configuration File Handling
3
 *
4
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
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

    
12
#include "sysdep/config.h"
13
#include "lib/ip.h"
14
#include "lib/resource.h"
15
#include "sysdep/unix/timer.h"
16

    
17

    
18
/* Configuration structure */
19

    
20
struct 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) */
24
  list tables;                                /* Configured routing tables (struct rtable_config) */
25
  list logfiles;                        /* Configured log files (sysdep) */
26
  list tests;                                /* Configured unit tests */
27

    
28
  int mrtdump_file;                        /* Configured MRTDump file (sysdep, fd in unix) */
29
  char *syslog_name;                        /* Name used for syslog (NULL -> no syslog) */
30
  struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
31
  struct iface_patt *router_id_from;        /* Configured list of router ID iface patterns */
32

    
33
  u32 router_id;                        /* Our Router ID */
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 */
37
  unsigned proto_default_debug;                /* Default protocol debug mask */
38
  unsigned proto_default_mrtdump;        /* Default protocol mrtdump mask */
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 */
43
  u32 gr_wait;                                /* Graceful restart wait timeout */
44

    
45
  int cli_debug;                        /* Tracing of CLI connections and commands */
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) */
50
  char *err_msg;                        /* Parser error message */
51
  int err_lino;                                /* Line containing error */
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 */
55
  struct symbol **sym_hash;                /* Lexer: symbol hash table */
56
  struct symbol **sym_fallback;                /* Lexer: fallback symbol hash table */
57
  int obstacle_count;                        /* Number of items blocking freeing of this config */
58
  int shutdown;                                /* This is a pseudo-config for daemon shutdown */
59
  bird_clock_t load_time;                /* When we've got this configuration */
60
};
61

    
62
/* Please don't use these variables in protocols. Use proto_config->global instead. */
63
extern struct config *config;                /* Currently active configuration */
64
extern struct config *new_config;        /* Configuration being parsed */
65

    
66
struct config *config_alloc(const char *name);
67
int config_parse(struct config *);
68
int cli_parse(struct config *);
69
void config_free(struct config *);
70
int config_commit(struct config *, int type, int timeout);
71
int config_confirm(void);
72
int config_undo(void);
73
void config_init(void);
74
void cf_error(const char *msg, ...) NORET;
75
void config_add_obstacle(struct config *);
76
void config_del_obstacle(struct config *);
77
void order_shutdown(void);
78

    
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

    
92

    
93
/* Pools */
94

    
95
extern linpool *cfg_mem;
96

    
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)
100
char *cfg_strdup(const char *c);
101
void cfg_copy_list(list *dest, list *src, unsigned node_size);
102

    
103
/* Lexer */
104

    
105
extern int (*cf_read_hook)(byte *buf, uint max, int fd);
106

    
107
struct symbol {
108
  struct symbol *next;
109
  struct sym_scope *scope;
110
  int class;
111
  int aux;
112
  void *aux2;
113
  void *def;
114
  char name[1];
115
};
116

    
117
#define SYM_MAX_LEN 64
118

    
119
/* Remember to update cf_symbol_class_name() */
120
#define SYM_VOID 0
121
#define SYM_PROTO 1
122
#define SYM_TEMPLATE 2
123
#define SYM_FUNCTION 3
124
#define SYM_FILTER 4
125
#define SYM_TABLE 5
126

    
127
#define SYM_VARIABLE 0x100        /* 0x100-0x1ff are variable types */
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)
132

    
133
struct include_file_stack {
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) */
142
};
143

    
144
extern struct include_file_stack *ifs;
145

    
146

    
147
int cf_lex(void);
148
void cf_lex_init(int is_cli, struct config *c);
149
void cf_lex_unwind(void);
150

    
151
struct symbol *cf_find_symbol(struct config *cfg, byte *c);
152

    
153
struct symbol *cf_get_symbol(byte *c);
154
struct symbol *cf_default_name(char *template, int *counter);
155
struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
156
void cf_push_scope(struct symbol *);
157
void cf_pop_scope(void);
158
struct symbol *cf_walk_symbols(struct config *cf, struct symbol *sym, int *pos);
159
char *cf_symbol_class_name(struct symbol *sym);
160

    
161
static inline int cf_symbol_is_constant(struct symbol *sym)
162
{ return (sym->class & 0xff00) == SYM_CONSTANT; }
163

    
164

    
165
/* Parser */
166

    
167
extern char *cf_text;
168
int cf_parse(void);
169

    
170
/* Sysdep hooks */
171

    
172
void sysdep_preconfig(struct config *);
173
int sysdep_commit(struct config *, struct config *);
174
void sysdep_shutdown_done(void);
175

    
176
#endif