Statistics
| Branch: | Revision:

iof-bird-daemon / conf / confbase.Y @ b8cc390e

History | View | Annotate | Download (3.1 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
#define PARSER 1
12

    
13
#include "nest/bird.h"
14
#include "conf/conf.h"
15
#include "lib/resource.h"
16
#include "lib/socket.h"
17
#include "lib/timer.h"
18
#include "lib/string.h"
19
#include "nest/protocol.h"
20
#include "nest/iface.h"
21
#include "nest/route.h"
22
#include "nest/cli.h"
23
#include "filter/filter.h"
24

    
25
/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
26

    
27
CF_DEFINES
28

    
29
static void
30
check_u16(unsigned val)
31
{
32
  if (val > 0xFFFF)
33
    cf_error("Value %d out of range (0-65535)", val);
34
}
35

    
36
CF_DECLS
37

    
38
%union {
39
  int i;
40
  u32 i32;
41
  ip_addr a;
42
  struct symbol *s;
43
  char *t;
44
  struct rtable_config *r;
45
  struct f_inst *x;
46
  struct filter *f;
47
  struct f_tree *e;
48
  struct f_trie *trie;
49
  struct f_val v;
50
  struct f_path_mask *h;
51
  struct password_item *p;
52
  struct rt_show_data *ra;
53
  void *g;
54
  bird_clock_t time;
55
  struct prefix px;
56
  struct proto_spec ps;
57
  struct timeformat *tf;
58
}
59

    
60
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
61
%token GEQ LEQ NEQ AND OR
62
%token PO PC
63
%token <i> NUM ENUM
64
%token <i32> RTRID
65
%token <a> IPA
66
%token <s> SYM
67
%token <t> TEXT
68

    
69
%type <i> expr bool pxlen
70
%type <time> datetime
71
%type <a> ipa
72
%type <px> prefix prefix_or_ipa
73
%type <t> text_or_none
74

    
75
%nonassoc PREFIX_DUMMY
76
%left AND OR
77
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC
78
%left '+' '-'
79
%left '*' '/' '%'
80
%left '!'
81
%nonassoc '.'
82

    
83
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
84

    
85
CF_GRAMMAR
86

    
87
/* Basic config file structure */
88

    
89
config: conf_entries END { return 0; }
90
 | CLI_MARKER cli_cmd { return 0; }
91
 ;
92

    
93
conf_entries:
94
   /* EMPTY */
95
 | conf_entries conf
96
 ;
97

    
98
CF_ADDTO(conf, ';')
99

    
100
/* Constant expressions */
101

    
102
expr:
103
   NUM
104
 | '(' term ')' { $$ = f_eval_int($2); }
105
 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
106
 ;
107

    
108
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
109

    
110
CF_ADDTO(conf, definition)
111
definition:
112
   DEFINE SYM '=' expr ';' {
113
     cf_define_symbol($2, SYM_NUMBER, NULL);
114
     $2->aux = $4;
115
   }
116
 | DEFINE SYM '=' IPA ';' {
117
     cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
118
     *(ip_addr *)$2->def = $4;
119
   }
120
 ;
121

    
122
/* Switches */
123

    
124
bool:
125
   expr {$$ = !!$1; }
126
 | ON { $$ = 1; }
127
 | YES { $$ = 1; }
128
 | OFF { $$ = 0; }
129
 | NO { $$ = 0; }
130
 | /* Silence means agreement */ { $$ = 1; }
131
 ;
132

    
133
/* Addresses, prefixes and netmasks */
134

    
135
ipa:
136
   IPA
137
 | SYM {
138
     if ($1->class != SYM_IPA) cf_error("IP address expected");
139
     $$ = *(ip_addr *)$1->def;
140
   }
141
 ;
142

    
143
prefix:
144
   ipa pxlen {
145
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
146
     $$.addr = $1; $$.len = $2;
147
   }
148
 ;
149

    
150
prefix_or_ipa:
151
   prefix
152
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
153
 ;
154

    
155
pxlen:
156
   '/' expr {
157
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
158
     $$ = $2;
159
   }
160
 | ':' ipa {
161
     $$ = ipa_mklen($2);
162
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
163
   }
164
 ;
165

    
166
datetime:
167
   TEXT {
168
     $$ = tm_parse_datetime($1);
169
     if (!$$)
170
       cf_error("Invalid date and time");
171
   }
172
 ;
173

    
174
text_or_none:
175
   TEXT { $$ = $1; }
176
 |      { $$ = NULL; }
177
 ;
178

    
179
CF_CODE
180

    
181
CF_END