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