Statistics
| Branch: | Revision:

iof-bird-daemon / conf / confbase.Y @ 23b1539b

History | View | Annotate | Download (1.87 KB)

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

    
9
CF_HDR
10

    
11
#include "nest/bird.h"
12
#include "conf/conf.h"
13
#include "lib/resource.h"
14
#include "lib/socket.h"
15
#include "lib/timer.h"
16
#include "nest/protocol.h"
17
#include "nest/iface.h"
18
#include "nest/route.h"
19
#include "filter/filter.h"
20

    
21
CF_DECLS
22

    
23
%union {
24
  int i;
25
  ip_addr a;
26
  struct symbol *s;
27
  char *t;
28
  struct f_inst *x;
29
  struct filter *f;
30
}
31

    
32
%token END
33
%token <i> NUM
34
%token <a> IPA
35
%token <s> SYM
36
%token <t> TEXT
37

    
38
%type <i> expr bool pxlen
39

    
40
%nonassoc '=' '<' '>'
41
%left '+' '-'
42
%left '*' '/' '%'
43
%left '!'
44

    
45
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
46

    
47
CF_GRAMMAR
48

    
49
/* Basic config file structure */
50

    
51
config: conf_entries END {
52
	return 0;
53
   }
54
 ;
55

    
56
conf_entries:
57
   /* EMPTY */
58
 | conf_entries conf
59
 ;
60

    
61
CF_ADDTO(conf, ';')
62

    
63
/* Constant expressions */
64

    
65
expr:
66
   NUM
67
 | expr '+' expr { $$ = $1 + $3; }
68
 | expr '-' expr { $$ = $1 - $3; }
69
 | expr '*' expr { $$ = $1 * $3; }
70
 | expr '/' expr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); }
71
 | expr '%' expr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); }
72
 | '(' expr ')' { $$ = $2; }
73
 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
74
 ;
75

    
76
CF_ADDTO(conf, definition)
77
definition:
78
   DEFINE SYM '=' expr ';' {
79
     if ($2->class != SYM_VOID) cf_error("Symbol already defined");
80
     $2->class = SYM_NUMBER;
81
     $2->aux = $4;
82
   }
83
 ;
84

    
85
/* Switches */
86

    
87
bool:
88
   expr {$$ = !!$1; }
89
 | ON { $$ = 1; }
90
 | YES { $$ = 1; }
91
 | OFF { $$ = 0; }
92
 | NO { $$ = 0; }
93
 | /* Silence means agreement */ { $$ = 1; }
94
 ;
95

    
96
/* Prefixes and netmasks */
97

    
98
pxlen:
99
   '/' NUM {
100
     if ($2 < 0 || $2 > 32) cf_error("Invalid prefix length %d", $2);
101
     $$ = $2;
102
   }
103
 | ':' IPA {
104
     $$ = ipa_mklen($2);
105
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
106
   }
107
 ;
108

    
109
CF_CODE
110

    
111
CF_END