confbase.Y 2.92 KB
Newer Older
Martin Mareš's avatar
Martin Mareš committed
1 2 3
/*
 *	BIRD -- Configuration Parser Top
 *
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
Martin Mareš's avatar
Martin Mareš committed
5 6 7 8 9 10
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

CF_HDR

11 12
#define PARSER 1

Martin Mareš's avatar
Martin Mareš committed
13 14
#include "nest/bird.h"
#include "conf/conf.h"
15 16 17
#include "lib/resource.h"
#include "lib/socket.h"
#include "lib/timer.h"
18
#include "lib/string.h"
19
#include "nest/protocol.h"
20
#include "nest/iface.h"
21
#include "nest/route.h"
22
#include "nest/cli.h"
23
#include "filter/filter.h"
Martin Mareš's avatar
Martin Mareš committed
24

25 26
/* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */

Martin Mareš's avatar
Martin Mareš committed
27 28 29 30
CF_DECLS

%union {
  int i;
31
  u32 i32;
Martin Mareš's avatar
Martin Mareš committed
32 33 34
  ip_addr a;
  struct symbol *s;
  char *t;
35
  struct rtable_config *r;
36 37
  struct f_inst *x;
  struct filter *f;
38
  struct f_tree *e;
39
  struct f_trie *trie;
40
  struct f_val v;
41
  struct f_path_mask *h;
Pavel Machek's avatar
Pavel Machek committed
42
  struct password_item *p;
43
  struct rt_show_data *ra;
44
  void *g;
45
  bird_clock_t time;
46
  struct prefix px;
47
  struct proto_spec ps;
48
  struct timeformat *tf;
Martin Mareš's avatar
Martin Mareš committed
49 50
}

51
%token END CLI_MARKER INVALID_TOKEN
Pavel Machek's avatar
Pavel Machek committed
52
%token GEQ LEQ NEQ AND OR
53
%token PO PC
Martin Mareš's avatar
Martin Mareš committed
54
%token <i> NUM ENUM
55
%token <i32> RTRID
Martin Mareš's avatar
Martin Mareš committed
56 57 58 59
%token <a> IPA
%token <s> SYM
%token <t> TEXT

60 61
%type <i> expr bool pxlen
%type <time> datetime
62
%type <a> ipa
Martin Mareš's avatar
Martin Mareš committed
63
%type <px> prefix prefix_or_ipa
64
%type <t> text_or_none
65

66
%nonassoc PREFIX_DUMMY
67
%left AND OR
68
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC
69
%left '+' '-'
70
%left '*' '/' '%'
71
%left '!'
72
%nonassoc '.'
73

74
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
75

Martin Mareš's avatar
Martin Mareš committed
76 77
CF_GRAMMAR

78 79
/* Basic config file structure */

80
config: conf_entries END { return 0; }
81
 | CLI_MARKER cli_cmd { return 0; }
Martin Mareš's avatar
Martin Mareš committed
82 83 84 85
 ;

conf_entries:
   /* EMPTY */
86
 | conf_entries conf
Martin Mareš's avatar
Martin Mareš committed
87 88
 ;

89
CF_ADDTO(conf, ';')
Martin Mareš's avatar
Martin Mareš committed
90

91
/* Constant expressions */
92

93
expr:
94
   NUM
95
 | '(' term ')' { $$ = f_eval_int($2); }
96 97 98 99 100
 | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
 ;

CF_ADDTO(conf, definition)
definition:
101
   DEFINE SYM '=' expr ';' {
102
     cf_define_symbol($2, SYM_NUMBER, NULL);
103 104
     $2->aux = $4;
   }
105 106 107 108
 | DEFINE SYM '=' IPA ';' {
     cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
     *(ip_addr *)$2->def = $4;
   }
109 110
 ;

111 112 113
/* Switches */

bool:
114
   expr {$$ = !!$1; }
115 116 117 118 119 120 121
 | ON { $$ = 1; }
 | YES { $$ = 1; }
 | OFF { $$ = 0; }
 | NO { $$ = 0; }
 | /* Silence means agreement */ { $$ = 1; }
 ;

122 123 124 125 126 127 128 129 130
/* Addresses, prefixes and netmasks */

ipa:
   IPA
 | SYM {
     if ($1->class != SYM_IPA) cf_error("IP address expected");
     $$ = *(ip_addr *)$1->def;
   }
 ;
131

132
prefix:
133
   ipa pxlen {
134 135 136 137 138
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
     $$.addr = $1; $$.len = $2;
   }
 ;

Martin Mareš's avatar
Martin Mareš committed
139 140
prefix_or_ipa:
   prefix
141
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
Martin Mareš's avatar
Martin Mareš committed
142 143
 ;

144
pxlen:
145
   '/' expr {
146
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
147 148
     $$ = $2;
   }
149
 | ':' ipa {
150 151 152 153 154
     $$ = ipa_mklen($2);
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
   }
 ;

Martin Mareš's avatar
Martin Mareš committed
155
datetime:
156
   TEXT {
157
     $$ = tm_parse_datetime($1);
158
     if (!$$)
159
       cf_error("Invalid date and time");
160
   }
Pavel Machek's avatar
Pavel Machek committed
161 162
 ;

163 164 165 166 167
text_or_none:
   TEXT { $$ = $1; }
 |      { $$ = NULL; }
 ;

Martin Mareš's avatar
Martin Mareš committed
168 169 170
CF_CODE

CF_END