Revision 04632fd7 conf/confbase.Y

View differences:

conf/confbase.Y
41 41
  ip_addr a;
42 42
  ip4_addr ip4;
43 43
  ip6_addr ip6;
44
  net_addr_union net;
44
  net_addr net;
45 45
  net_addr *net_ptr;
46 46
  struct symbol *s;
47 47
  char *t;
......
76 76
%token <t> TEXT
77 77
%type <iface> ipa_scope
78 78

  
79
%type <i> expr bool pxlen4 pxlen6
79
%type <i> expr bool pxlen4
80 80
%type <i32> expr_us
81 81
%type <time> datetime
82
%type <a> ipa ipa_raw
83
%type <net> net_ip4 net_ip6 net_ip net_or_ipa
84
%type <net_ptr> net_any
82
%type <a> ipa
83
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
84
%type <net_ptr> net_ net_any
85 85

  
86 86
%type <t> text opttext
87 87

  
......
151 151
 | /* Silence means agreement */ { $$ = 1; }
152 152
 ;
153 153

  
154
/* Addresses, prefixes and netmasks */
155 154

  
156
ipa_raw:
157
   IP4 { $$ = ipa_from_ip4($1); }
158
 | IP6 { $$ = ipa_from_ip6($1); }
159
 ;
155
/* Addresses */
160 156

  
161 157
ipa:
162
   ipa_raw
158
   IP4 { $$ = ipa_from_ip4($1); }
159
 | IP6 { $$ = ipa_from_ip6($1); }
163 160
 | SYM {
164 161
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
165 162
     $$ = SYM_VAL($1).ip;
......
172 169
 ;
173 170

  
174 171

  
175
/* XXXX - symbols and tests */
172
/* Networks - internal */
176 173

  
177
net_ip4: IP4 pxlen4 { $$.ip4 = NET_ADDR_IP4($1, $2); }
174
pxlen4:
175
   '/' NUM {
176
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
177
     $$ = $2;
178
   }
179
 | ':' IP4 {
180
     $$ = ip4_masklen($2);
181
     if ($$ == 255) cf_error("Invalid netmask %I", $2); /* XXXX */
182
   }
183
 ;
178 184

  
179
net_ip6: IP6 pxlen6 { $$.ip6 = NET_ADDR_IP6($1, $2); }
185
net_ip4_: IP4 pxlen4
186
{
187
  net_fill_ip4(&($$), $1, $2);
188
  if (!net_validate_ip4((net_addr_ip4 *) &($$)))
189
    cf_error("Invalid IPv4 prefix");
190
};
180 191

  
181
net_ip: net_ip4 | net_ip6 ;
192
net_ip6_: IP6 '/' NUM
193
{
194
  net_fill_ip6(&($$), $1, $3);
195
  if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH)
196
    cf_error("Invalid prefix length %d", $3);
197
  if (!net_validate_ip6((net_addr_ip6 *) &($$)))
198
    cf_error("Invalid IPv6 prefix");
199
};
182 200

  
183
net_any: net_ip { $$ = cfg_alloc($1.n.length); net_copy($$, &($1.n)); }
201
net_ip_: net_ip4_ | net_ip6_ ;
184 202

  
185
net_or_ipa:
186
   net_ip4
187
 | net_ip6
188
 | IP4 { $$.ip4 = NET_ADDR_IP4($1, IP4_MAX_PREFIX_LENGTH); }
189
 | IP6 { $$.ip6 = NET_ADDR_IP6($1, IP6_MAX_PREFIX_LENGTH); }
190
 ;
203
net_: net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); } ;
191 204

  
192 205

  
193
pxlen4:
194
   '/' expr {
195
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
196
     $$ = $2;
206
/* Networks - regular */
207

  
208
net_ip6:
209
   net_ip6_
210
 | SYM {
211
     if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
212
       cf_error("IPv6 network expected");
213
     $$ = * SYM_VAL($1).net;
197 214
   }
198
 | ':' IP4 {
199
     $$ = ip4_masklen($2);
200
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
215
 ;
216

  
217
net_ip:
218
   net_ip_
219
 | SYM {
220
     if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
221
       cf_error("IP network expected");
222
     $$ = * SYM_VAL($1).net;
201 223
   }
202 224
 ;
203 225

  
204
pxlen6:
205
   '/' expr {
206
     if ($2 < 0 || $2 > IP6_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
207
     $$ = $2;
226
net_any:
227
   net_
228
 | SYM {
229
     if ($1->class != (SYM_CONSTANT | T_NET))
230
       cf_error("Network expected");
231
     $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
232
   }
233
 ;
234

  
235
net_or_ipa:
236
   net_ip4_
237
 | net_ip6_
238
 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
239
 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
240
 | SYM {
241
     if ($1->class == (SYM_CONSTANT | T_IP))
242
       net_fill_ip_host(&($$), SYM_VAL($1).ip);
243
     else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
244
       $$ = * SYM_VAL($1).net;
245
     else
246
       cf_error("IP address or network expected");
208 247
   }
209 248
 ;
210 249

  
250

  
211 251
datetime:
212 252
   TEXT {
213 253
     $$ = tm_parse_datetime($1);

Also available in: Unified diff