Revision 9b9a7143

View differences:

conf/cf-lex.l
70 70
static struct sym_scope *conf_this_scope;
71 71

  
72 72
static int cf_hash(byte *c);
73
static struct symbol *cf_find_sym(byte *c, unsigned int h0);
73
static inline struct symbol * cf_get_sym(byte *c, uint h0);
74 74

  
75 75
linpool *cfg_mem;
76 76

  
......
194 194
	}
195 195
      k=k->next;
196 196
    }
197
  cf_lval.s = cf_find_sym(yytext, h);
197
  cf_lval.s = cf_get_sym(yytext, h);
198 198
  return SYM;
199 199
}
200 200

  
......
426 426
}
427 427

  
428 428
static struct symbol *
429
cf_new_sym(byte *c, unsigned int h)
429
cf_new_sym(byte *c, uint h0)
430 430
{
431
  uint h = h0 & (SYM_HASH_SIZE-1);
431 432
  struct symbol *s, **ht;
432 433
  int l;
433 434

  
......
449 450
}
450 451

  
451 452
static struct symbol *
452
cf_find_sym(byte *c, unsigned int h0)
453
cf_find_sym(struct config *cfg, byte *c, uint h0)
453 454
{
454
  unsigned int h = h0 & (SYM_HASH_SIZE-1);
455
  uint h = h0 & (SYM_HASH_SIZE-1);
455 456
  struct symbol *s, **ht;
456 457

  
457
  if (ht = new_config->sym_hash)
458
  if (ht = cfg->sym_hash)
458 459
    {
459 460
      for(s = ht[h]; s; s=s->next)
460 461
	if (!strcmp(s->name, c) && s->scope->active)
461 462
	  return s;
462 463
    }
463
  if (new_config->sym_fallback)
464
  if (ht = cfg->sym_fallback)
464 465
    {
465 466
      /* We know only top-level scope is active */
466
      for(s = new_config->sym_fallback[h]; s; s=s->next)
467
      for(s = ht[h]; s; s=s->next)
467 468
	if (!strcmp(s->name, c) && s->scope->active)
468 469
	  return s;
469 470
    }
470
  return cf_new_sym(c, h);
471

  
472
  return NULL;
473
}
474

  
475
static inline struct symbol *
476
cf_get_sym(byte *c, uint h0)
477
{
478
  return cf_find_sym(new_config, c, h0) ?: cf_new_sym(c, h0);
471 479
}
472 480

  
473 481
/**
474 482
 * cf_find_symbol - find a symbol by name
483
 * @cfg: specificed config
484
 * @c: symbol name
485
 *
486
 * This functions searches the symbol table in the config @cfg for a symbol of
487
 * given name. First it examines the current scope, then the second recent one
488
 * and so on until it either finds the symbol and returns a pointer to its
489
 * &symbol structure or reaches the end of the scope chain and returns %NULL to
490
 * signify no match.
491
 */
492
struct symbol *
493
cf_find_symbol(struct config *cfg, byte *c)
494
{
495
  return cf_find_sym(cfg, c, cf_hash(c));
496
}
497

  
498
/**
499
 * cf_get_symbol - get a symbol by name
475 500
 * @c: symbol name
476 501
 *
477
 * This functions searches the symbol table for a symbol of given
478
 * name. First it examines the current scope, then the second recent
479
 * one and so on until it either finds the symbol and returns a pointer
480
 * to its &symbol structure or reaches the end of the scope chain
481
 * and returns %NULL to signify no match.
502
 * This functions searches the symbol table of the currently parsed config
503
 * (@new_config) for a symbol of given name. It returns either the already
504
 * existing symbol or a newly allocated undefined (%SYM_VOID) symbol if no
505
 * existing symbol is found.
482 506
 */
483 507
struct symbol *
484
cf_find_symbol(byte *c)
508
cf_get_symbol(byte *c)
485 509
{
486
  return cf_find_sym(c, cf_hash(c));
510
  return cf_get_sym(c, cf_hash(c));
487 511
}
488 512

  
489 513
struct symbol *
490 514
cf_default_name(char *template, int *counter)
491 515
{
492
  char buf[32];
516
  char buf[SYM_MAX_LEN];
493 517
  struct symbol *s;
494 518
  char *perc = strchr(template, '%');
495 519

  
496 520
  for(;;)
497 521
    {
498 522
      bsprintf(buf, template, ++(*counter));
499
      s = cf_find_sym(buf, cf_hash(buf));
500
      if (!s)
501
	break;
523
      s = cf_get_sym(buf, cf_hash(buf));
502 524
      if (s->class == SYM_VOID)
503 525
	return s;
504 526
      if (!perc)
......
529 551
    {
530 552
      if (sym->scope == conf_this_scope)
531 553
	cf_error("Symbol already defined");
532
      sym = cf_new_sym(sym->name, cf_hash(sym->name) & (SYM_HASH_SIZE-1));
554
      sym = cf_new_sym(sym->name, cf_hash(sym->name));
533 555
    }
534 556
  sym->class = type;
535 557
  sym->def = def;
conf/conf.c
20 20
 *
21 21
 * There can exist up to four different configurations at one time: an active
22 22
 * one (pointed to by @config), configuration we are just switching from
23
 * (@old_config), one queued for the next reconfiguration (@future_config;
24
 * if there is one and the user wants to reconfigure once again, we just
25
 * free the previous queued config and replace it with the new one) and
26
 * finally a config being parsed (@new_config). The stored @old_config 
27
 * is also used for undo reconfiguration, which works in a similar way.
28
 * Reconfiguration could also have timeout (using @config_timer) and undo
29
 * is automatically called if the new configuration is not confirmed later.
23
 * (@old_config), one queued for the next reconfiguration (@future_config; if
24
 * there is one and the user wants to reconfigure once again, we just free the
25
 * previous queued config and replace it with the new one) and finally a config
26
 * being parsed (@new_config). The stored @old_config is also used for undo
27
 * reconfiguration, which works in a similar way. Reconfiguration could also
28
 * have timeout (using @config_timer) and undo is automatically called if the
29
 * new configuration is not confirmed later. The new config (@new_config) and
30
 * associated linear pool (@cfg_mem) is non-NULL only during parsing.
30 31
 *
31
 * Loading of new configuration is very simple: just call config_alloc()
32
 * to get a new &config structure, then use config_parse() to parse a
33
 * configuration file and fill all fields of the structure
34
 * and finally ask the config manager to switch to the new
35
 * config by calling config_commit().
32
 * Loading of new configuration is very simple: just call config_alloc() to get
33
 * a new &config structure, then use config_parse() to parse a configuration
34
 * file and fill all fields of the structure and finally ask the config manager
35
 * to switch to the new config by calling config_commit().
36 36
 *
37 37
 * CLI commands are parsed in a very similar way -- there is also a stripped-down
38 38
 * &config structure associated with them and they are lex-ed and parsed by the
......
91 91
  linpool *l = lp_new(p, 4080);
92 92
  struct config *c = lp_allocz(l, sizeof(struct config));
93 93

  
94
  /* Duplication of name string in local linear pool */
95
  uint nlen = strlen(name) + 1;
96
  char *ndup = lp_allocu(l, nlen);
97
  memcpy(ndup, name, nlen);
98

  
94 99
  c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
95 100
  c->pool = p;
96
  cfg_mem = c->mem = l;
97
  c->file_name = cfg_strdup(name);
101
  c->mem = l;
102
  c->file_name = ndup;
98 103
  c->load_time = now;
99 104
  c->tf_route = c->tf_proto = (struct timeformat){"%T", "%F", 20*3600};
100 105
  c->tf_base = c->tf_log = (struct timeformat){"%F %T", NULL, 0};
......
119 124
int
120 125
config_parse(struct config *c)
121 126
{
127
  int done = 0;
122 128
  DBG("Parsing configuration file `%s'\n", c->file_name);
123 129
  new_config = c;
124 130
  cfg_mem = c->mem;
125 131
  if (setjmp(conf_jmpbuf))
126
    return 0;
132
    goto cleanup;
133

  
127 134
  cf_lex_init(0, c);
128 135
  sysdep_preconfig(c);
129 136
  protos_preconfig(c);
......
137 144
  if (!c->router_id)
138 145
    cf_error("Router ID must be configured manually on IPv6 routers");
139 146
#endif
140
  return 1;
147
  done = 1;
148

  
149
cleanup:
150
  new_config = NULL;
151
  cfg_mem = NULL;
152
  return done;
141 153
}
142 154

  
143 155
/**
......
150 162
int
151 163
cli_parse(struct config *c)
152 164
{
153
  new_config = c;
165
  int done = 0;
154 166
  c->sym_fallback = config->sym_hash;
167
  new_config = c;
155 168
  cfg_mem = c->mem;
156 169
  if (setjmp(conf_jmpbuf))
157
    return 0;
170
    goto cleanup;
171

  
158 172
  cf_lex_init(1, c);
159 173
  cf_parse();
160
  return 1;
174
  done = 1;
175

  
176
cleanup:
177
  c->sym_fallback = NULL;
178
  new_config = NULL;
179
  cfg_mem = NULL;
180
  return done;
161 181
}
162 182

  
163 183
/**
......
237 257
  if (old_config && !config->shutdown)
238 258
    log(L_INFO "Reconfiguring");
239 259

  
240
  /* This should not be necessary, but it seems there are some
241
     functions that access new_config instead of config */
242
  new_config = config;
243

  
244 260
  if (old_config)
245 261
    old_config->obstacle_count++;
246 262

  
......
254 270
  DBG("protos_commit\n");
255 271
  protos_commit(c, old_config, force_restart, type);
256 272

  
257
  /* Just to be sure nobody uses that now */
258
  new_config = NULL;
259

  
260 273
  int obs = 0;
261 274
  if (old_config)
262 275
    obs = --old_config->obstacle_count;
conf/conf.h
147 147
void cf_lex_init(int is_cli, struct config *c);
148 148
void cf_lex_unwind(void);
149 149

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

  
152
struct symbol *cf_get_symbol(byte *c);
151 153
struct symbol *cf_default_name(char *template, int *counter);
152 154
struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
153 155
void cf_push_scope(struct symbol *);
nest/proto.c
521 521
      WALK_LIST(oc, old->protos)
522 522
	{
523 523
	  p = oc->proto;
524
	  sym = cf_find_symbol(oc->name);
524
	  sym = cf_find_symbol(new, oc->name);
525 525
	  if (sym && sym->class == SYM_PROTO && !new->shutdown)
526 526
	    {
527 527
	      /* Found match, let's check if we can smoothly switch to new configuration */
nest/rt-roa.c
311 311
  if (old)
312 312
    WALK_LIST(t, roa_table_list)
313 313
      {
314
	struct symbol *sym = cf_find_symbol(t->name);
314
	struct symbol *sym = cf_find_symbol(new, t->name);
315 315
	if (sym && sym->class == SYM_ROA)
316 316
	  {
317 317
	    /* Found old table in new config */
nest/rt-table.c
1663 1663
void
1664 1664
rt_preconfig(struct config *c)
1665 1665
{
1666
  struct symbol *s = cf_find_symbol("master");
1666
  struct symbol *s = cf_get_symbol("master");
1667 1667

  
1668 1668
  init_list(&c->tables);
1669 1669
  c->master_rtc = rt_new_table(s);
......
1903 1903
	  rtable *ot = o->table;
1904 1904
	  if (!ot->deleted)
1905 1905
	    {
1906
	      struct symbol *sym = cf_find_symbol(o->name);
1906
	      struct symbol *sym = cf_find_symbol(new, o->name);
1907 1907
	      if (sym && sym->class == SYM_TABLE && !new->shutdown)
1908 1908
		{
1909 1909
		  DBG("\t%s: same\n", o->name);
sysdep/unix/main.c
96 96
static inline void
97 97
add_num_const(char *name, int val)
98 98
{
99
  struct symbol *s = cf_find_symbol(name);
99
  struct symbol *s = cf_get_symbol(name);
100 100
  s->class = SYM_CONSTANT | T_INT;
101 101
  s->def = cfg_allocz(sizeof(struct f_val));
102 102
  SYM_TYPE(s) = T_INT;

Also available in: Unified diff