Statistics
| Branch: | Revision:

iof-bird-daemon / conf / conf.c @ 31b3e1bb

History | View | Annotate | Download (1.9 KB)

1
/*
2
 *        BIRD Internet Routing Daemon -- Configuration File Handling
3
 *
4
 *        (c) 1999 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include <setjmp.h>
10
#include <stdarg.h>
11

    
12
#include "nest/bird.h"
13
#include "nest/protocol.h"
14
#include "nest/iface.h"
15
#include "lib/resource.h"
16
#include "lib/string.h"
17
#include "conf/conf.h"
18
#include "filter/filter.h"
19

    
20
static jmp_buf conf_jmpbuf;
21

    
22
struct config *config, *new_config;
23

    
24
struct config *
25
config_alloc(byte *name)
26
{
27
  pool *p = rp_new(&root_pool, "Config");
28
  linpool *l = lp_new(p, 1024);
29
  struct config *c = lp_allocz(l, sizeof(struct config));
30

    
31
  c->pool = p;
32
  cfg_mem = c->mem = l;
33
  init_list(&c->protos);
34
  c->file_name = cfg_strdup(name);
35
  return c;
36
}
37

    
38
int
39
config_parse(struct config *c)
40
{
41
  struct proto_config *p;
42

    
43
  debug("Parsing configuration file <%s>\n", c->file_name);
44
  new_config = c;
45
  cfg_pool = c->pool;
46
  cfg_mem = c->mem;
47
  if (setjmp(conf_jmpbuf))
48
    return 0;
49
  cf_lex_init(1);
50
  cf_lex_init_tables();
51
  protos_preconfig(c);
52
  cf_parse();
53
#if 0                                        /* FIXME: We don't have interface list yet :( */
54
  if (!c->router_id && !(c->router_id = auto_router_id()))
55
    cf_error("Cannot determine router ID (no suitable network interface found), please configure it manually");
56
#endif
57
  filters_postconfig();                        /* FIXME: Do we really need this? */
58
  protos_postconfig(c);
59
  return 1;
60
}
61

    
62
void
63
config_free(struct config *c)
64
{
65
  rfree(c->pool);
66
}
67

    
68
void
69
config_commit(struct config *c)
70
{
71
  config = c;
72
  protos_commit(c);
73
}
74

    
75
void
76
cf_error(char *msg, ...)
77
{
78
  char buf[1024];
79
  va_list args;
80

    
81
  va_start(args, msg);
82
  if (bvsnprintf(buf, sizeof(buf), msg, args) < 0)
83
    strcpy(buf, "<bug: error message too long>");
84
  new_config->err_msg = cfg_strdup(buf);
85
  new_config->err_lino = conf_lino;
86
  longjmp(conf_jmpbuf, 1);
87
}
88

    
89
char *
90
cfg_strdup(char *c)
91
{
92
  int l = strlen(c) + 1;
93
  char *z = cfg_allocu(l);
94
  memcpy(z, c, l);
95
  return z;
96
}