Statistics
| Branch: | Revision:

iof-bird-daemon / conf / confbase.Y @ cc590a11

History | View | Annotate | Download (2.66 KB)

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_val v;
38
  struct f_path_mask *h;
39
  struct password_item *p;
40
  struct rt_show_data *ra;
41
  void *g;
42
  bird_clock_t time;
43
  struct prefix px;
44
}
45

    
46
%token END CLI_MARKER INVALID_TOKEN
47
%token GEQ LEQ NEQ
48
%token <i> NUM ENUM
49
%token <i32> RTRID
50
%token <a> IPA
51
%token <s> SYM
52
%token <t> TEXT
53

    
54
%type <i> expr bool pxlen
55
%type <time> datetime
56
%type <a> ipa
57
%type <px> prefix prefix_or_ipa
58

    
59
%nonassoc '=' '<' '>' '~' '.' GEQ LEQ NEQ
60
%left '+' '-'
61
%left '*' '/' '%'
62
%left '!'
63

    
64
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
65

    
66
CF_GRAMMAR
67

    
68
/* Basic config file structure */
69

    
70
config: conf_entries END { return 0; }
71
 | CLI_MARKER cli_cmd { return 0; }
72
 ;
73

    
74
conf_entries:
75
   /* EMPTY */
76
 | conf_entries conf
77
 ;
78

    
79
CF_ADDTO(conf, ';')
80

    
81
/* Constant expressions */
82

    
83
expr:
84
   NUM
85
 | '(' term ')' { $$ = f_eval_int($2); }
86
 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
87
 ;
88

    
89
CF_ADDTO(conf, definition)
90
definition:
91
   DEFINE SYM '=' expr ';' {
92
     cf_define_symbol($2, SYM_NUMBER, NULL);
93
     $2->aux = $4;
94
   }
95
 | DEFINE SYM '=' IPA ';' {
96
     cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
97
     *(ip_addr *)$2->def = $4;
98
   }
99
 ;
100

    
101
/* Switches */
102

    
103
bool:
104
   expr {$$ = !!$1; }
105
 | ON { $$ = 1; }
106
 | YES { $$ = 1; }
107
 | OFF { $$ = 0; }
108
 | NO { $$ = 0; }
109
 | /* Silence means agreement */ { $$ = 1; }
110
 ;
111

    
112
/* Addresses, prefixes and netmasks */
113

    
114
ipa:
115
   IPA
116
 | SYM {
117
     if ($1->class != SYM_IPA) cf_error("IP address expected");
118
     $$ = *(ip_addr *)$1->def;
119
   }
120
 ;
121

    
122
prefix:
123
   ipa pxlen {
124
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
125
     $$.addr = $1; $$.len = $2;
126
   }
127
 ;
128

    
129
prefix_or_ipa:
130
   prefix
131
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
132
 ;
133

    
134
pxlen:
135
   '/' expr {
136
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
137
     $$ = $2;
138
   }
139
 | ':' ipa {
140
     $$ = ipa_mklen($2);
141
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
142
   }
143
 ;
144

    
145
datetime:
146
   TEXT {
147
     $$ = tm_parse_date($1);
148
     if (!$$)
149
       cf_error("Invalid date");
150
   }
151
 ;
152

    
153
CF_CODE
154

    
155
CF_END