]> git.ipfire.org Git - thirdparty/bird.git/blob - conf/confbase.Y
Fixes syntactic priority of '.' .
[thirdparty/bird.git] / conf / confbase.Y
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_trie *trie;
38 struct f_val v;
39 struct f_path_mask *h;
40 struct password_item *p;
41 struct rt_show_data *ra;
42 void *g;
43 bird_clock_t time;
44 struct prefix px;
45 struct proto_spec ps;
46 struct timeformat *tf;
47 }
48
49 %token END CLI_MARKER INVALID_TOKEN
50 %token GEQ LEQ NEQ AND OR
51 %token PO PC
52 %token <i> NUM ENUM
53 %token <i32> RTRID
54 %token <a> IPA
55 %token <s> SYM
56 %token <t> TEXT
57
58 %type <i> expr bool pxlen
59 %type <time> datetime
60 %type <a> ipa
61 %type <px> prefix prefix_or_ipa
62 %type <t> text_or_none
63
64 %nonassoc PREFIX_DUMMY
65 %left AND OR
66 %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC
67 %left '+' '-'
68 %left '*' '/' '%'
69 %left '!'
70 %nonassoc '.'
71
72 CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
73
74 CF_GRAMMAR
75
76 /* Basic config file structure */
77
78 config: conf_entries END { return 0; }
79 | CLI_MARKER cli_cmd { return 0; }
80 ;
81
82 conf_entries:
83 /* EMPTY */
84 | conf_entries conf
85 ;
86
87 CF_ADDTO(conf, ';')
88
89 /* Constant expressions */
90
91 expr:
92 NUM
93 | '(' term ')' { $$ = f_eval_int($2); }
94 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
95 ;
96
97 CF_ADDTO(conf, definition)
98 definition:
99 DEFINE SYM '=' expr ';' {
100 cf_define_symbol($2, SYM_NUMBER, NULL);
101 $2->aux = $4;
102 }
103 | DEFINE SYM '=' IPA ';' {
104 cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
105 *(ip_addr *)$2->def = $4;
106 }
107 ;
108
109 /* Switches */
110
111 bool:
112 expr {$$ = !!$1; }
113 | ON { $$ = 1; }
114 | YES { $$ = 1; }
115 | OFF { $$ = 0; }
116 | NO { $$ = 0; }
117 | /* Silence means agreement */ { $$ = 1; }
118 ;
119
120 /* Addresses, prefixes and netmasks */
121
122 ipa:
123 IPA
124 | SYM {
125 if ($1->class != SYM_IPA) cf_error("IP address expected");
126 $$ = *(ip_addr *)$1->def;
127 }
128 ;
129
130 prefix:
131 ipa pxlen {
132 if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
133 $$.addr = $1; $$.len = $2;
134 }
135 ;
136
137 prefix_or_ipa:
138 prefix
139 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
140 ;
141
142 pxlen:
143 '/' expr {
144 if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
145 $$ = $2;
146 }
147 | ':' ipa {
148 $$ = ipa_mklen($2);
149 if ($$ < 0) cf_error("Invalid netmask %I", $2);
150 }
151 ;
152
153 datetime:
154 TEXT {
155 $$ = tm_parse_datetime($1);
156 if (!$$)
157 cf_error("Invalid date and time");
158 }
159 ;
160
161 text_or_none:
162 TEXT { $$ = $1; }
163 | { $$ = NULL; }
164 ;
165
166 CF_CODE
167
168 CF_END