]>
Commit | Line | Data |
---|---|---|
f142750d MM |
1 | /* |
2 | * BIRD -- Configuration Parser Top | |
3 | * | |
aee539f2 | 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> |
f142750d MM |
5 | * |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | CF_HDR | |
10 | ||
93e868c7 OZ |
11 | #define PARSER 1 |
12 | ||
f142750d MM |
13 | #include "nest/bird.h" |
14 | #include "conf/conf.h" | |
c74c0e3c MM |
15 | #include "lib/resource.h" |
16 | #include "lib/socket.h" | |
17 | #include "lib/timer.h" | |
221135d6 | 18 | #include "lib/string.h" |
c74c0e3c | 19 | #include "nest/protocol.h" |
50d8424a | 20 | #include "nest/iface.h" |
166b9c49 | 21 | #include "nest/route.h" |
bc2fb680 | 22 | #include "nest/cli.h" |
b9d70dc8 | 23 | #include "filter/filter.h" |
f142750d | 24 | |
f2c6c80a MM |
25 | /* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */ |
26 | ||
b8cc390e OZ |
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 | ||
f142750d MM |
36 | CF_DECLS |
37 | ||
38 | %union { | |
39 | int i; | |
dce26783 | 40 | u32 i32; |
f142750d MM |
41 | ip_addr a; |
42 | struct symbol *s; | |
43 | char *t; | |
0e02abfd | 44 | struct rtable_config *r; |
e0f2e42f MM |
45 | struct f_inst *x; |
46 | struct filter *f; | |
38506f71 | 47 | struct f_tree *e; |
b1a597e0 | 48 | struct f_trie *trie; |
38506f71 | 49 | struct f_val v; |
dcab7890 | 50 | struct f_path_mask *h; |
9d79fec8 | 51 | struct password_item *p; |
730f2e2c | 52 | struct rt_show_data *ra; |
af582c48 | 53 | struct roa_show_data *ro; |
0f808c06 | 54 | struct sym_show_data *sd; |
20ab192b | 55 | struct lsadb_show_data *ld; |
69a8259c | 56 | struct iface *iface; |
af582c48 | 57 | struct roa_table *rot; |
4ab5331c | 58 | void *g; |
aee539f2 | 59 | bird_clock_t time; |
758458be | 60 | struct prefix px; |
e304fd4b | 61 | struct proto_spec ps; |
c37e7851 | 62 | struct timeformat *tf; |
f142750d MM |
63 | } |
64 | ||
b8cc390e | 65 | %token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT |
5f4aee76 | 66 | %token GEQ LEQ NEQ AND OR |
cf186034 | 67 | %token PO PC |
944f008a | 68 | %token <i> NUM ENUM |
dce26783 | 69 | %token <i32> RTRID |
f142750d MM |
70 | %token <a> IPA |
71 | %token <s> SYM | |
72 | %token <t> TEXT | |
69a8259c | 73 | %type <iface> ipa_scope |
f142750d | 74 | |
a1beb8f3 | 75 | %type <i> expr bool pxlen |
6a8d3f1c | 76 | %type <i32> expr_us |
aee539f2 | 77 | %type <time> datetime |
e3f2d5fc | 78 | %type <a> ipa |
d3abfbc6 | 79 | %type <px> prefix prefix_or_ipa |
9eceab33 | 80 | %type <t> text |
874b8685 | 81 | %type <t> text_or_none |
0b62c3a7 | 82 | |
60de3356 | 83 | %nonassoc PREFIX_DUMMY |
1960d203 | 84 | %left AND OR |
112d71a7 | 85 | %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC |
1960d203 | 86 | %left '+' '-' |
0b62c3a7 | 87 | %left '*' '/' '%' |
23b1539b | 88 | %left '!' |
112d71a7 | 89 | %nonassoc '.' |
0b62c3a7 | 90 | |
dcde7ae5 | 91 | CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT) |
0b62c3a7 | 92 | |
f142750d MM |
93 | CF_GRAMMAR |
94 | ||
0b62c3a7 MM |
95 | /* Basic config file structure */ |
96 | ||
bc2fb680 | 97 | config: conf_entries END { return 0; } |
ffb59d24 | 98 | | CLI_MARKER cli_cmd { return 0; } |
f142750d MM |
99 | ; |
100 | ||
101 | conf_entries: | |
102 | /* EMPTY */ | |
7f400d1c | 103 | | conf_entries conf |
f142750d MM |
104 | ; |
105 | ||
7f400d1c | 106 | CF_ADDTO(conf, ';') |
f142750d | 107 | |
1103b32e | 108 | |
72380a34 | 109 | /* Constant expressions */ |
0b62c3a7 | 110 | |
1103b32e OZ |
111 | CF_ADDTO(conf, definition) |
112 | definition: | |
113 | DEFINE SYM '=' term ';' { | |
114 | struct f_val *val = cfg_alloc(sizeof(struct f_val)); | |
115 | *val = f_eval($4, cfg_mem); | |
116 | if (val->type == T_RETURN) cf_error("Runtime error"); | |
117 | cf_define_symbol($2, SYM_CONSTANT | val->type, val); | |
118 | } | |
119 | ; | |
120 | ||
c9b66706 | 121 | expr: |
0b62c3a7 | 122 | NUM |
cc590a11 | 123 | | '(' term ')' { $$ = f_eval_int($2); } |
1103b32e OZ |
124 | | SYM { |
125 | if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected"); | |
126 | $$ = SYM_VAL($1).i; } | |
0b62c3a7 MM |
127 | ; |
128 | ||
6a8d3f1c | 129 | |
6a8d3f1c | 130 | expr_us: |
0e175f9f OZ |
131 | expr S { $$ = (u32) $1 * 1000000; } |
132 | | expr MS { $$ = (u32) $1 * 1000; } | |
133 | | expr US { $$ = (u32) $1 * 1; } | |
6a8d3f1c OZ |
134 | ; |
135 | ||
b8cc390e OZ |
136 | /* expr_u16: expr { check_u16($1); $$ = $1; }; */ |
137 | ||
166b9c49 MM |
138 | /* Switches */ |
139 | ||
140 | bool: | |
c9b66706 | 141 | expr {$$ = !!$1; } |
166b9c49 MM |
142 | | ON { $$ = 1; } |
143 | | YES { $$ = 1; } | |
144 | | OFF { $$ = 0; } | |
145 | | NO { $$ = 0; } | |
146 | | /* Silence means agreement */ { $$ = 1; } | |
147 | ; | |
148 | ||
e3f2d5fc MM |
149 | /* Addresses, prefixes and netmasks */ |
150 | ||
151 | ipa: | |
152 | IPA | |
153 | | SYM { | |
1103b32e OZ |
154 | if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected"); |
155 | $$ = SYM_VAL($1).px.ip; | |
e3f2d5fc MM |
156 | } |
157 | ; | |
89d2355d | 158 | |
69a8259c OZ |
159 | ipa_scope: |
160 | /* empty */ { $$ = NULL; } | |
161 | | '%' SYM { $$ = if_get_by_name($2->name); } | |
162 | ; | |
163 | ||
758458be | 164 | prefix: |
e3f2d5fc | 165 | ipa pxlen { |
758458be MM |
166 | if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix"); |
167 | $$.addr = $1; $$.len = $2; | |
168 | } | |
169 | ; | |
170 | ||
d3abfbc6 MM |
171 | prefix_or_ipa: |
172 | prefix | |
e3f2d5fc | 173 | | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; } |
d3abfbc6 MM |
174 | ; |
175 | ||
89d2355d | 176 | pxlen: |
e3f2d5fc | 177 | '/' expr { |
6db8c5a6 | 178 | if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2); |
89d2355d MM |
179 | $$ = $2; |
180 | } | |
e3f2d5fc | 181 | | ':' ipa { |
88a183c6 | 182 | $$ = ipa_masklen($2); |
89d2355d MM |
183 | if ($$ < 0) cf_error("Invalid netmask %I", $2); |
184 | } | |
185 | ; | |
186 | ||
16c07e3d | 187 | datetime: |
aee539f2 | 188 | TEXT { |
0d3effcf | 189 | $$ = tm_parse_datetime($1); |
aee539f2 | 190 | if (!$$) |
0d3effcf | 191 | cf_error("Invalid date and time"); |
aee539f2 | 192 | } |
9d79fec8 PM |
193 | ; |
194 | ||
9eceab33 OZ |
195 | text: |
196 | TEXT | |
197 | | SYM { | |
198 | if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected"); | |
199 | $$ = SYM_VAL($1).s; | |
200 | } | |
201 | ; | |
202 | ||
874b8685 OZ |
203 | text_or_none: |
204 | TEXT { $$ = $1; } | |
205 | | { $$ = NULL; } | |
206 | ; | |
207 | ||
f142750d MM |
208 | CF_CODE |
209 | ||
210 | CF_END |