]>
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 | ||
11 | #include "nest/bird.h" | |
12 | #include "conf/conf.h" | |
c74c0e3c MM |
13 | #include "lib/resource.h" |
14 | #include "lib/socket.h" | |
15 | #include "lib/timer.h" | |
16 | #include "nest/protocol.h" | |
50d8424a | 17 | #include "nest/iface.h" |
166b9c49 | 18 | #include "nest/route.h" |
bc2fb680 | 19 | #include "nest/cli.h" |
b9d70dc8 | 20 | #include "filter/filter.h" |
f142750d | 21 | |
f2c6c80a MM |
22 | /* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */ |
23 | ||
f142750d MM |
24 | CF_DECLS |
25 | ||
26 | %union { | |
27 | int i; | |
dce26783 | 28 | u32 i32; |
f142750d MM |
29 | ip_addr a; |
30 | struct symbol *s; | |
31 | char *t; | |
0e02abfd | 32 | struct rtable_config *r; |
e0f2e42f MM |
33 | struct f_inst *x; |
34 | struct filter *f; | |
38506f71 PM |
35 | struct f_tree *e; |
36 | struct f_val v; | |
9d79fec8 | 37 | struct password_item *p; |
730f2e2c | 38 | struct rt_show_data *ra; |
4ab5331c | 39 | void *g; |
aee539f2 | 40 | bird_clock_t time; |
f142750d MM |
41 | } |
42 | ||
2ca3d9a8 | 43 | %token END CLI_MARKER INVALID_TOKEN |
a58dad62 | 44 | %token GEQ LEQ NEQ |
944f008a | 45 | %token <i> NUM ENUM |
dce26783 | 46 | %token <i32> RTRID |
f142750d MM |
47 | %token <a> IPA |
48 | %token <s> SYM | |
49 | %token <t> TEXT | |
50 | ||
aee539f2 MM |
51 | %type <i> expr bool pxlen |
52 | %type <time> datetime | |
0b62c3a7 | 53 | |
a58dad62 | 54 | %nonassoc '=' '<' '>' '~' '.' GEQ LEQ NEQ |
0b62c3a7 MM |
55 | %left '+' '-' |
56 | %left '*' '/' '%' | |
23b1539b | 57 | %left '!' |
0b62c3a7 | 58 | |
166b9c49 | 59 | CF_KEYWORDS(DEFINE, ON, OFF, YES, NO) |
0b62c3a7 | 60 | |
f142750d MM |
61 | CF_GRAMMAR |
62 | ||
0b62c3a7 MM |
63 | /* Basic config file structure */ |
64 | ||
bc2fb680 | 65 | config: conf_entries END { return 0; } |
ffb59d24 | 66 | | CLI_MARKER cli_cmd { return 0; } |
f142750d MM |
67 | ; |
68 | ||
69 | conf_entries: | |
70 | /* EMPTY */ | |
7f400d1c | 71 | | conf_entries conf |
f142750d MM |
72 | ; |
73 | ||
7f400d1c | 74 | CF_ADDTO(conf, ';') |
f142750d | 75 | |
72380a34 | 76 | /* Constant expressions */ |
0b62c3a7 | 77 | |
c9b66706 | 78 | expr: |
0b62c3a7 | 79 | NUM |
c9b66706 MM |
80 | | expr '+' expr { $$ = $1 + $3; } |
81 | | expr '-' expr { $$ = $1 - $3; } | |
82 | | expr '*' expr { $$ = $1 * $3; } | |
83 | | expr '/' expr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); } | |
84 | | expr '%' expr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); } | |
85 | | '(' expr ')' { $$ = $2; } | |
0b62c3a7 MM |
86 | | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; } |
87 | ; | |
88 | ||
89 | CF_ADDTO(conf, definition) | |
90 | definition: | |
7f400d1c | 91 | DEFINE SYM '=' expr ';' { |
0e02abfd | 92 | cf_define_symbol($2, SYM_NUMBER, NULL); |
0b62c3a7 MM |
93 | $2->aux = $4; |
94 | } | |
95 | ; | |
96 | ||
166b9c49 MM |
97 | /* Switches */ |
98 | ||
99 | bool: | |
c9b66706 | 100 | expr {$$ = !!$1; } |
166b9c49 MM |
101 | | ON { $$ = 1; } |
102 | | YES { $$ = 1; } | |
103 | | OFF { $$ = 0; } | |
104 | | NO { $$ = 0; } | |
105 | | /* Silence means agreement */ { $$ = 1; } | |
106 | ; | |
107 | ||
89d2355d MM |
108 | /* Prefixes and netmasks */ |
109 | ||
110 | pxlen: | |
111 | '/' NUM { | |
112 | if ($2 < 0 || $2 > 32) cf_error("Invalid prefix length %d", $2); | |
113 | $$ = $2; | |
114 | } | |
115 | | ':' IPA { | |
116 | $$ = ipa_mklen($2); | |
117 | if ($$ < 0) cf_error("Invalid netmask %I", $2); | |
118 | } | |
119 | ; | |
120 | ||
16c07e3d | 121 | datetime: |
aee539f2 MM |
122 | TEXT { |
123 | $$ = tm_parse_date($1); | |
124 | if (!$$) | |
125 | cf_error("Invalid date"); | |
126 | } | |
9d79fec8 PM |
127 | ; |
128 | ||
f142750d MM |
129 | CF_CODE |
130 | ||
131 | CF_END |