Statistics
| Branch: | Revision:

iof-bird-daemon / conf / confbase.Y @ 758458be

History | View | Annotate | Download (2.54 KB)

1
/*
2
 *	BIRD -- Configuration Parser Top
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
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 "lib/string.h"
17
#include "nest/protocol.h"
18
#include "nest/iface.h"
19
#include "nest/route.h"
20
#include "nest/cli.h"
21
#include "filter/filter.h"
22

    
23
/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
24

    
25
CF_DECLS
26

    
27
%union {
28
  int i;
29
  u32 i32;
30
  ip_addr a;
31
  struct symbol *s;
32
  char *t;
33
  struct rtable_config *r;
34
  struct f_inst *x;
35
  struct filter *f;
36
  struct f_tree *e;
37
  struct f_val v;
38
  struct f_path_mask *h;
39
  struct password_item *p;
40
  struct rt_show_data *ra;
41
  void *g;
42
  bird_clock_t time;
43
  struct prefix px;
44
}
45

    
46
%token END CLI_MARKER INVALID_TOKEN
47
%token GEQ LEQ NEQ
48
%token <i> NUM ENUM
49
%token <i32> RTRID
50
%token <a> IPA
51
%token <s> SYM
52
%token <t> TEXT
53

    
54
%type <i> expr bool pxlen
55
%type <time> datetime
56
%type <px> prefix
57

    
58
%nonassoc '=' '<' '>' '~' '.' GEQ LEQ NEQ
59
%left '+' '-'
60
%left '*' '/' '%'
61
%left '!'
62

    
63
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
64

    
65
CF_GRAMMAR
66

    
67
/* Basic config file structure */
68

    
69
config: conf_entries END { return 0; }
70
 | CLI_MARKER cli_cmd { return 0; }
71
 ;
72

    
73
conf_entries:
74
   /* EMPTY */
75
 | conf_entries conf
76
 ;
77

    
78
CF_ADDTO(conf, ';')
79

    
80
/* Constant expressions */
81

    
82
expr:
83
   NUM
84
 | expr '+' expr { $$ = $1 + $3; }
85
 | expr '-' expr { $$ = $1 - $3; }
86
 | expr '*' expr { $$ = $1 * $3; }
87
 | expr '/' expr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); }
88
 | expr '%' expr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); }
89
 | '(' expr ')' { $$ = $2; }
90
 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
91
 ;
92

    
93
CF_ADDTO(conf, definition)
94
definition:
95
   DEFINE SYM '=' expr ';' {
96
     cf_define_symbol($2, SYM_NUMBER, NULL);
97
     $2->aux = $4;
98
   }
99
 ;
100

    
101
/* Switches */
102

    
103
bool:
104
   expr {$$ = !!$1; }
105
 | ON { $$ = 1; }
106
 | YES { $$ = 1; }
107
 | OFF { $$ = 0; }
108
 | NO { $$ = 0; }
109
 | /* Silence means agreement */ { $$ = 1; }
110
 ;
111

    
112
/* Prefixes and netmasks */
113

    
114
prefix:
115
   IPA pxlen {
116
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
117
     $$.addr = $1; $$.len = $2;
118
   }
119
 ;
120

    
121
pxlen:
122
   '/' NUM {
123
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
124
     $$ = $2;
125
   }
126
 | ':' IPA {
127
     $$ = ipa_mklen($2);
128
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
129
   }
130
 ;
131

    
132
datetime:
133
   TEXT {
134
     $$ = tm_parse_date($1);
135
     if (!$$)
136
       cf_error("Invalid date");
137
   }
138
 ;
139

    
140
CF_CODE
141

    
142
CF_END