2 * BIRD -- Configuration Parser Top
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
13 #include "nest/bird.h"
14 #include "conf/conf.h"
15 #include "lib/resource.h"
16 #include "lib/socket.h"
17 #include "sysdep/unix/timer.h"
18 #include "lib/string.h"
19 #include "nest/protocol.h"
20 #include "nest/iface.h"
21 #include "nest/route.h"
23 #include "filter/filter.h"
25 /* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
30 check_u16(unsigned val)
33 cf_error("Value %d out of range (0-65535)", val);
49 struct rtable_config *r;
50 struct channel_config *cc;
56 struct f_path_mask *h;
57 struct password_item *p;
58 struct rt_show_data *ra;
59 struct sym_show_data *sd;
60 struct lsadb_show_data *ld;
66 struct channel_limit cl;
67 struct timeformat *tf;
68 mpls_label_stack *mls;
71 %token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
72 %token GEQ LEQ NEQ AND OR
80 %type <iface> ipa_scope
82 %type <i> expr bool pxlen4
86 %type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
87 %type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_
88 %type <mls> label_stack_start label_stack
90 %type <t> text opttext
92 %nonassoc PREFIX_DUMMY
94 %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
100 CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN)
104 /* Basic config file structure */
106 config: conf_entries END { return 0; }
107 | CLI_MARKER cli_cmd { return 0; }
118 /* Constant expressions */
120 CF_ADDTO(conf, definition)
122 DEFINE SYM '=' term ';' {
123 struct f_val *val = cfg_alloc(sizeof(struct f_val));
124 *val = f_eval($4, cfg_mem);
125 if (val->type == T_RETURN) cf_error("Runtime error");
126 cf_define_symbol($2, SYM_CONSTANT | val->type, val);
132 | '(' term ')' { $$ = f_eval_int($2); }
134 if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
135 $$ = SYM_VAL($1).i; }
140 expr S { $$ = (u32) $1 * 1000000; }
141 | expr MS { $$ = (u32) $1 * 1000; }
142 | expr US { $$ = (u32) $1 * 1; }
153 | /* Silence means agreement */ { $$ = 1; }
160 IP4 { $$ = ipa_from_ip4($1); }
161 | IP6 { $$ = ipa_from_ip6($1); }
163 if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
169 /* empty */ { $$ = NULL; }
170 | '%' SYM { $$ = if_get_by_name($2->name); }
174 /* Networks - internal */
178 if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
182 $$ = ip4_masklen($2);
183 if ($$ == 255) cf_error("Invalid netmask %I4", $2);
189 net_fill_ip4(&($$), $1, $2);
190 if (!net_validate_ip4((net_addr_ip4 *) &($$)))
191 cf_error("Invalid IPv4 prefix");
194 net_ip6_: IP6 '/' NUM
196 net_fill_ip6(&($$), $1, $3);
197 if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH)
198 cf_error("Invalid prefix length %d", $3);
199 if (!net_validate_ip6((net_addr_ip6 *) &($$)))
200 cf_error("Invalid IPv6 prefix");
203 net_vpn4_: VPN_RD net_ip4_
205 $$ = cfg_alloc(sizeof(net_addr_vpn4));
206 net_fill_vpn4($$, net4_prefix(&$2), net4_pxlen(&$2), $1);
209 net_vpn6_: VPN_RD net_ip6_
211 $$ = cfg_alloc(sizeof(net_addr_vpn6));
212 net_fill_vpn6($$, net6_prefix(&$2), net6_pxlen(&$2), $1);
215 net_roa4_: net_ip4_ MAX NUM AS NUM
217 $$ = cfg_alloc(sizeof(net_addr_roa4));
218 net_fill_roa4($$, net4_prefix(&$1), net4_pxlen(&$1), $3, $5);
219 if ($3 < (int) net4_pxlen(&$1) || $3 > IP4_MAX_PREFIX_LENGTH)
220 cf_error("Invalid max prefix length %d", $3);
223 net_roa6_: net_ip6_ MAX NUM AS NUM
225 $$ = cfg_alloc(sizeof(net_addr_roa6));
226 net_fill_roa6($$, net6_prefix(&$1), net6_pxlen(&$1), $3, $5);
227 if ($3 < (int) net6_pxlen(&$1) || $3 > IP6_MAX_PREFIX_LENGTH)
228 cf_error("Invalid max prefix length %d", $3);
231 net_ip_: net_ip4_ | net_ip6_ ;
232 net_vpn_: net_vpn4_ | net_vpn6_ ;
233 net_roa_: net_roa4_ | net_roa6_ ;
236 net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); }
243 /* Networks - regular */
248 if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
249 cf_error("IPv6 network expected");
250 $$ = * SYM_VAL($1).net;
257 if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
258 cf_error("IP network expected");
259 $$ = * SYM_VAL($1).net;
266 if ($1->class != (SYM_CONSTANT | T_NET))
267 cf_error("Network expected");
268 $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
275 | net_vpn4_ { $$ = *$1; }
276 | net_vpn6_ { $$ = *$1; }
277 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
278 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
280 if ($1->class == (SYM_CONSTANT | T_IP))
281 net_fill_ip_host(&($$), SYM_VAL($1).ip);
282 else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
283 $$ = * SYM_VAL($1).net;
285 cf_error("IP address or network expected");
289 label_stack_start: NUM
291 $$ = cfg_allocz(sizeof(mpls_label_stack));
298 | label_stack '/' NUM {
299 if ($1->len >= MPLS_MAX_LABEL_STACK)
300 cf_error("Too many labels in stack");
301 $1->stack[$1->len++] = $3;
308 $$ = tm_parse_datetime($1);
310 cf_error("Invalid date and time");
317 if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
324 | /* empty */ { $$ = NULL; }