]> git.ipfire.org Git - thirdparty/bird.git/blame - conf/confbase.Y
Implements primary address selection base on 'primary' option.
[thirdparty/bird.git] / conf / confbase.Y
CommitLineData
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
9CF_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"
221135d6 16#include "lib/string.h"
c74c0e3c 17#include "nest/protocol.h"
50d8424a 18#include "nest/iface.h"
166b9c49 19#include "nest/route.h"
bc2fb680 20#include "nest/cli.h"
b9d70dc8 21#include "filter/filter.h"
f142750d 22
f2c6c80a
MM
23/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */
24
f142750d
MM
25CF_DECLS
26
27%union {
28 int i;
dce26783 29 u32 i32;
f142750d
MM
30 ip_addr a;
31 struct symbol *s;
32 char *t;
0e02abfd 33 struct rtable_config *r;
e0f2e42f
MM
34 struct f_inst *x;
35 struct filter *f;
38506f71 36 struct f_tree *e;
b1a597e0 37 struct f_trie *trie;
38506f71 38 struct f_val v;
dcab7890 39 struct f_path_mask *h;
9d79fec8 40 struct password_item *p;
730f2e2c 41 struct rt_show_data *ra;
4ab5331c 42 void *g;
aee539f2 43 bird_clock_t time;
758458be 44 struct prefix px;
f142750d
MM
45}
46
2ca3d9a8 47%token END CLI_MARKER INVALID_TOKEN
5f4aee76 48%token GEQ LEQ NEQ AND OR
cf186034 49%token PO PC
944f008a 50%token <i> NUM ENUM
dce26783 51%token <i32> RTRID
f142750d
MM
52%token <a> IPA
53%token <s> SYM
54%token <t> TEXT
55
aee539f2
MM
56%type <i> expr bool pxlen
57%type <time> datetime
e3f2d5fc 58%type <a> ipa
d3abfbc6 59%type <px> prefix prefix_or_ipa
874b8685 60%type <t> text_or_none
0b62c3a7 61
60de3356 62%nonassoc PREFIX_DUMMY
cf186034 63%nonassoc '=' '<' '>' '~' '.' GEQ LEQ NEQ AND OR PO PC
0b62c3a7
MM
64%left '+' '-'
65%left '*' '/' '%'
23b1539b 66%left '!'
0b62c3a7 67
166b9c49 68CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
0b62c3a7 69
f142750d
MM
70CF_GRAMMAR
71
0b62c3a7
MM
72/* Basic config file structure */
73
bc2fb680 74config: conf_entries END { return 0; }
ffb59d24 75 | CLI_MARKER cli_cmd { return 0; }
f142750d
MM
76 ;
77
78conf_entries:
79 /* EMPTY */
7f400d1c 80 | conf_entries conf
f142750d
MM
81 ;
82
7f400d1c 83CF_ADDTO(conf, ';')
f142750d 84
72380a34 85/* Constant expressions */
0b62c3a7 86
c9b66706 87expr:
0b62c3a7 88 NUM
cc590a11 89 | '(' term ')' { $$ = f_eval_int($2); }
0b62c3a7
MM
90 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
91 ;
92
93CF_ADDTO(conf, definition)
94definition:
7f400d1c 95 DEFINE SYM '=' expr ';' {
0e02abfd 96 cf_define_symbol($2, SYM_NUMBER, NULL);
0b62c3a7
MM
97 $2->aux = $4;
98 }
e3f2d5fc
MM
99 | DEFINE SYM '=' IPA ';' {
100 cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
101 *(ip_addr *)$2->def = $4;
102 }
0b62c3a7
MM
103 ;
104
166b9c49
MM
105/* Switches */
106
107bool:
c9b66706 108 expr {$$ = !!$1; }
166b9c49
MM
109 | ON { $$ = 1; }
110 | YES { $$ = 1; }
111 | OFF { $$ = 0; }
112 | NO { $$ = 0; }
113 | /* Silence means agreement */ { $$ = 1; }
114 ;
115
e3f2d5fc
MM
116/* Addresses, prefixes and netmasks */
117
118ipa:
119 IPA
120 | SYM {
121 if ($1->class != SYM_IPA) cf_error("IP address expected");
122 $$ = *(ip_addr *)$1->def;
123 }
124 ;
89d2355d 125
758458be 126prefix:
e3f2d5fc 127 ipa pxlen {
758458be
MM
128 if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
129 $$.addr = $1; $$.len = $2;
130 }
131 ;
132
d3abfbc6
MM
133prefix_or_ipa:
134 prefix
e3f2d5fc 135 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
d3abfbc6
MM
136 ;
137
89d2355d 138pxlen:
e3f2d5fc 139 '/' expr {
6db8c5a6 140 if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
89d2355d
MM
141 $$ = $2;
142 }
e3f2d5fc 143 | ':' ipa {
89d2355d
MM
144 $$ = ipa_mklen($2);
145 if ($$ < 0) cf_error("Invalid netmask %I", $2);
146 }
147 ;
148
16c07e3d 149datetime:
aee539f2 150 TEXT {
0d3effcf 151 $$ = tm_parse_datetime($1);
aee539f2 152 if (!$$)
0d3effcf 153 cf_error("Invalid date and time");
aee539f2 154 }
9d79fec8
PM
155 ;
156
874b8685
OZ
157text_or_none:
158 TEXT { $$ = $1; }
159 | { $$ = NULL; }
160 ;
161
f142750d
MM
162CF_CODE
163
164CF_END