1998-11-27 19:35:10 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Configuration File Handling
|
|
|
|
*
|
2000-01-16 16:44:50 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-11-27 19:35:10 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_CONF_H_
|
|
|
|
#define _BIRD_CONF_H_
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
#include "sysdep/config.h"
|
2018-08-13 09:41:27 +00:00
|
|
|
#include "nest/cli.h"
|
2016-11-09 15:36:34 +00:00
|
|
|
#include "lib/ip.h"
|
2017-05-25 21:30:39 +00:00
|
|
|
#include "lib/hash.h"
|
1998-11-27 19:35:10 +00:00
|
|
|
#include "lib/resource.h"
|
2017-11-28 16:43:20 +00:00
|
|
|
#include "lib/timer.h"
|
1998-11-27 19:35:10 +00:00
|
|
|
|
2011-09-11 19:21:47 +00:00
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
/* Configuration structure */
|
|
|
|
|
|
|
|
struct config {
|
|
|
|
pool *pool; /* Pool the configuration is stored in */
|
|
|
|
linpool *mem; /* Linear pool containing configuration data */
|
|
|
|
list protos; /* Configured protocol instances (struct proto_config) */
|
1999-05-17 20:06:19 +00:00
|
|
|
list tables; /* Configured routing tables (struct rtable_config) */
|
2016-11-08 16:46:29 +00:00
|
|
|
list logfiles; /* Configured log files (sysdep) */
|
2016-11-30 09:21:43 +00:00
|
|
|
list tests; /* Configured unit tests (f_bt_test_suite) */
|
2012-03-18 16:32:30 +00:00
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */
|
2010-04-07 09:00:36 +00:00
|
|
|
char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
|
2012-12-27 11:56:23 +00:00
|
|
|
struct iface_patt *router_id_from; /* Configured list of router ID iface patterns */
|
2010-01-03 11:17:52 +00:00
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
u32 router_id; /* Our Router ID */
|
2010-01-03 11:17:52 +00:00
|
|
|
unsigned proto_default_debug; /* Default protocol debug mask */
|
|
|
|
unsigned proto_default_mrtdump; /* Default protocol mrtdump mask */
|
2010-02-02 23:19:24 +00:00
|
|
|
struct timeformat tf_route; /* Time format for 'show route' */
|
|
|
|
struct timeformat tf_proto; /* Time format for 'show protocol' */
|
|
|
|
struct timeformat tf_log; /* Time format for the logfile */
|
|
|
|
struct timeformat tf_base; /* Time format for other purposes */
|
2017-06-21 12:43:49 +00:00
|
|
|
u32 gr_wait; /* Graceful restart wait timeout (sec) */
|
2010-02-02 23:19:24 +00:00
|
|
|
|
2000-05-29 22:10:18 +00:00
|
|
|
int cli_debug; /* Tracing of CLI connections and commands */
|
2015-03-02 08:41:14 +00:00
|
|
|
int latency_debug; /* I/O loop tracks duration of each event */
|
|
|
|
u32 latency_limit; /* Events with longer duration are logged (us) */
|
|
|
|
u32 watchdog_warning; /* I/O loop watchdog limit for warning (us) */
|
|
|
|
u32 watchdog_timeout; /* Watchdog timeout (in seconds, 0 = disabled) */
|
2017-05-25 21:30:39 +00:00
|
|
|
HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */
|
|
|
|
struct config *fallback; /* Link to regular config for CLI parsing */
|
2000-01-16 16:44:50 +00:00
|
|
|
int obstacle_count; /* Number of items blocking freeing of this config */
|
2000-01-16 17:40:26 +00:00
|
|
|
int shutdown; /* This is a pseudo-config for daemon shutdown */
|
2017-06-06 14:47:30 +00:00
|
|
|
btime load_time; /* When we've got this configuration */
|
1999-02-05 21:37:34 +00:00
|
|
|
};
|
|
|
|
|
2018-08-13 09:41:27 +00:00
|
|
|
struct conf_state {
|
|
|
|
void *buffer; /* Internal lexer state */
|
|
|
|
const char *name; /* Current file name */
|
|
|
|
uint lino; /* Current line */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct conf_order {
|
|
|
|
struct config *new_config; /* Store the allocated config here */
|
|
|
|
struct cf_context *ctx; /* Internal config context, do not set */
|
|
|
|
struct conf_state *state;
|
|
|
|
struct pool *pool; /* If set, use this resource pool */
|
|
|
|
struct linpool *lp; /* If set, use this linpool */
|
2018-08-23 19:54:35 +00:00
|
|
|
const char *buf;
|
|
|
|
uint len;
|
2018-08-13 09:41:27 +00:00
|
|
|
int (*cf_read_hook)(struct conf_order *order, byte *buf, uint max);
|
|
|
|
void (*cf_include)(struct conf_order *order, char *name, uint len);
|
|
|
|
int (*cf_outclude)(struct conf_order *order);
|
|
|
|
void (*cf_error)(struct conf_order *order, const char *msg, va_list args);
|
|
|
|
};
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
/* Please don't use these variables in protocols. Use proto_config->global instead. */
|
2000-01-16 16:44:50 +00:00
|
|
|
extern struct config *config; /* Currently active configuration */
|
2000-01-16 17:40:26 +00:00
|
|
|
|
2018-08-13 09:41:27 +00:00
|
|
|
/**
|
|
|
|
* Parse configuration
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* @order provides callbacks to read config files
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 1 on success; order->new_config is then set to the parsed config
|
|
|
|
* 0 on fail; order->new_config is undefined
|
|
|
|
**/
|
|
|
|
int config_parse(struct conf_order *order);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse CLI command
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* @order provides callbacks to read command line
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 1 on success
|
|
|
|
* 0 on fail
|
|
|
|
*
|
|
|
|
* Parsed config is never kept, order->new_config should be zero after return.
|
|
|
|
**/
|
|
|
|
int cli_parse(struct conf_order *order);
|
|
|
|
|
|
|
|
/** Callback for returning error from parser hooks */
|
|
|
|
void cf_error(struct cf_context *, const char *msg, ...) NORET;
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
void config_free(struct config *);
|
2017-06-21 12:43:49 +00:00
|
|
|
int config_commit(struct config *, int type, uint timeout);
|
2012-12-26 11:40:48 +00:00
|
|
|
int config_confirm(void);
|
|
|
|
int config_undo(void);
|
|
|
|
void config_init(void);
|
2000-01-16 16:44:50 +00:00
|
|
|
void config_add_obstacle(struct config *);
|
|
|
|
void config_del_obstacle(struct config *);
|
2000-01-16 17:40:26 +00:00
|
|
|
void order_shutdown(void);
|
2000-01-16 16:44:50 +00:00
|
|
|
|
2012-12-26 11:40:48 +00:00
|
|
|
#define RECONFIG_NONE 0
|
|
|
|
#define RECONFIG_HARD 1
|
|
|
|
#define RECONFIG_SOFT 2
|
|
|
|
#define RECONFIG_UNDO 3
|
|
|
|
|
|
|
|
#define CONF_DONE 0
|
|
|
|
#define CONF_PROGRESS 1
|
|
|
|
#define CONF_QUEUED 2
|
|
|
|
#define CONF_UNQUEUED 3
|
|
|
|
#define CONF_CONFIRM 4
|
|
|
|
#define CONF_SHUTDOWN -1
|
|
|
|
#define CONF_NOTHING -2
|
|
|
|
|
1998-11-29 21:59:37 +00:00
|
|
|
/* Pools */
|
|
|
|
|
2018-08-13 09:41:27 +00:00
|
|
|
void *cf_alloc(struct cf_context *ctx, unsigned size);
|
|
|
|
void *cf_allocu(struct cf_context *ctx, unsigned size);
|
|
|
|
void *cf_allocz(struct cf_context *ctx, unsigned size);
|
|
|
|
void cf_copy_list(struct cf_context *ctx, list *dest, list *src, unsigned node_size);
|
|
|
|
char *cf_strdup(struct cf_context *ctx, const char *c);
|
1998-11-29 21:59:37 +00:00
|
|
|
|
1998-11-27 19:35:10 +00:00
|
|
|
/* Lexer */
|
|
|
|
|
|
|
|
struct symbol {
|
|
|
|
struct symbol *next;
|
1999-11-04 13:51:52 +00:00
|
|
|
struct sym_scope *scope;
|
1998-11-27 19:35:10 +00:00
|
|
|
int class;
|
1998-11-27 21:32:45 +00:00
|
|
|
int aux;
|
2008-12-25 10:55:27 +00:00
|
|
|
void *aux2;
|
1998-11-27 19:35:10 +00:00
|
|
|
void *def;
|
|
|
|
char name[1];
|
|
|
|
};
|
|
|
|
|
2017-05-25 21:30:39 +00:00
|
|
|
struct sym_scope {
|
|
|
|
struct sym_scope *next; /* Next on scope stack */
|
|
|
|
struct symbol *name; /* Name of this scope */
|
|
|
|
int active; /* Currently entered */
|
|
|
|
};
|
|
|
|
|
2015-02-21 11:42:31 +00:00
|
|
|
#define SYM_MAX_LEN 64
|
|
|
|
|
2000-06-03 16:56:00 +00:00
|
|
|
/* Remember to update cf_symbol_class_name() */
|
1998-11-27 19:35:10 +00:00
|
|
|
#define SYM_VOID 0
|
1998-11-27 21:07:02 +00:00
|
|
|
#define SYM_PROTO 1
|
2013-07-25 20:33:57 +00:00
|
|
|
#define SYM_TEMPLATE 2
|
1999-11-15 11:34:51 +00:00
|
|
|
#define SYM_FUNCTION 3
|
|
|
|
#define SYM_FILTER 4
|
|
|
|
#define SYM_TABLE 5
|
1998-11-27 19:35:10 +00:00
|
|
|
|
1999-11-15 11:34:51 +00:00
|
|
|
#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
|
2013-07-25 20:33:57 +00:00
|
|
|
#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
|
|
|
|
|
|
|
|
#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type)
|
|
|
|
#define SYM_VAL(s) (((struct f_val *) (s)->def)->val)
|
1999-03-29 20:21:28 +00:00
|
|
|
|
2015-11-08 23:42:02 +00:00
|
|
|
struct symbol *cf_find_symbol(struct config *cfg, byte *c);
|
|
|
|
|
2000-01-19 12:30:19 +00:00
|
|
|
char *cf_symbol_class_name(struct symbol *sym);
|
1998-11-27 19:35:10 +00:00
|
|
|
|
2014-10-02 09:02:14 +00:00
|
|
|
static inline int cf_symbol_is_constant(struct symbol *sym)
|
|
|
|
{ return (sym->class & 0xff00) == SYM_CONSTANT; }
|
|
|
|
|
1999-12-06 13:44:45 +00:00
|
|
|
/* Sysdep hooks */
|
|
|
|
|
2018-08-13 09:41:27 +00:00
|
|
|
void sysdep_preconfig(struct cf_context *ctx);
|
2000-01-16 16:44:50 +00:00
|
|
|
int sysdep_commit(struct config *, struct config *);
|
2000-01-16 17:40:26 +00:00
|
|
|
void sysdep_shutdown_done(void);
|
1999-12-06 13:44:45 +00:00
|
|
|
|
1998-11-27 19:35:10 +00:00
|
|
|
#endif
|