dhcp6_parser.yy 25.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")

   This Source Code Form is subject to the terms of the Mozilla Public
   License, v. 2.0. If a copy of the MPL was not distributed with this
   file, You can obtain one at http://mozilla.org/MPL/2.0/. */

%skeleton "lalr1.cc" /* -*- C++ -*- */
%require "3.0.0"
%defines
%define parser_class_name {Dhcp6Parser}
11
%define api.prefix {parser6_}
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%define api.token.constructor
%define api.value.type variant
%define api.namespace {isc::dhcp}
%define parse.assert
%code requires
{
#include <string>
#include <cc/data.h>
#include <dhcp/option.h>
#include <boost/lexical_cast.hpp>
#include <dhcp6/parser_context_decl.h>

using namespace isc::dhcp;
using namespace isc::data;
using namespace std;
}
// The parsing context.
%param { isc::dhcp::Parser6Context& ctx }
%locations
%define parse.trace
%define parse.error verbose
%code
{
#include <dhcp6/parser_context.h>

}

%define api.token.prefix {TOKEN_}
// Tokens in an order which makes sense and related to the intented use.
%token
  END  0  "end of file"
  COMMA ","
  COLON ":"
  LSQUARE_BRACKET "["
  RSQUARE_BRACKET "]"
  LCURLY_BRACKET "{"
  RCURLY_BRACKET "}"
  NULL_TYPE "null"
50
51
52
53

  DHCP6 "Dhcp6"
  INTERFACES_CONFIG "interfaces-config"
  INTERFACES "interfaces"
54

55
  LEASE_DATABASE "lease-database"
56
  HOSTS_DATABASE "hosts-database"
57
  TYPE "type"
58
59
60
  USER "user"
  PASSWORD "password"
  HOST "host"
61
  PERSIST "persist"
62
  LFC_INTERVAL "lfc-interval"
63

64
65
66
67
68
69
70
71
72
  PREFERRED_LIFETIME "preferred-lifetime"
  VALID_LIFETIME "valid-lifetime"
  RENEW_TIMER "renew-timer"
  REBIND_TIMER "rebind-timer"
  SUBNET6 "subnet6"
  OPTION_DATA "option-data"
  NAME "name"
  DATA "data"
  CODE "code"
73
  SPACE "space"
74
  CSV_FORMAT "csv-format"
75

76
77
  POOLS "pools"
  POOL "pool"
78
79
80
81
82
  PD_POOLS "pd-pools"
  PREFIX "prefix"
  PREFIX_LEN "prefix-len"
  DELEGATED_LEN "delegated-len"

83
84
  SUBNET "subnet"
  INTERFACE "interface"
85
  ID "id"
86

87
88
  MAC_SOURCES "mac-sources"
  RELAY_SUPPLIED_OPTIONS "relay-supplied-options"
89
  HOST_RESERVATION_IDENTIFIERS "host-reservation-identifiers"
90

91
92
93
94
95
  CLIENT_CLASSES "client-classes"
  TEST "test"
  CLIENT_CLASS "client-class"

  RESERVATIONS "reservations"
96
97
  IP_ADDRESSES "ip-addresses"
  PREFIXES "prefixes"
98
  DUID "duid"
99
100
  HW_ADDRESS "hw-address"
  HOSTNAME "hostname"
101

102
103
104
105
106
107
108
109
110
  HOOKS_LIBRARIES "hooks-libraries"
  LIBRARY "library"

  EXPIRED_LEASES_PROCESSING "expired-leases-processing"

  SERVER_ID "server-id"
  IDENTIFIER "identifier"
  HTYPE "htype"
  TIME "time"
111
  ENTERPRISE_ID "enterprise-id"
112

113
114
  DHCP4O6_PORT "dhcp4o6-port"

115
116
117
118
119
120
  LOGGING "Logging"
  LOGGERS "loggers"
  OUTPUT_OPTIONS "output_options"
  OUTPUT "output"
  DEBUGLEVEL "debuglevel"
  SEVERITY "severity"
121
122
123
124
125

 // Not real tokens, just a way to signal what the parser is expected to
 // parse.
  TOPLEVEL_DHCP6
  TOPLEVEL_GENERIC_JSON
126
127
128
129
130
131
132
133
134
135
136
137
;

%token <std::string> STRING "constant string"
%token <int64_t> INTEGER "integer"
%token <double> FLOAT "floating point"
%token <bool> BOOLEAN "boolean"

%type <ElementPtr> value

%printer { yyoutput << $$; } <*>;

%%
138

139
140
// The whole grammar starts with a map, because the config file
// constists of Dhcp, Logger and DhcpDdns entries in one big { }.
141
142
// %start map - this will parse everything as generic JSON
// %start dhcp6_map - this will parse everything with Dhcp6 syntax checking
143
144
145
%start start;

start: TOPLEVEL_DHCP6 syntax_map
146
| TOPLEVEL_GENERIC_JSON map2;
147

148
149
// ---- generic JSON parser ---------------------------------

150
151
152
153
154
155
// Values rule
value : INTEGER { $$ = ElementPtr(new IntElement($1)); }
     | FLOAT { $$ = ElementPtr(new DoubleElement($1)); }
     | BOOLEAN { $$ = ElementPtr(new BoolElement($1)); }
     | STRING { $$ = ElementPtr(new StringElement($1)); }
     | NULL_TYPE { $$ = ElementPtr(new NullElement()); }
156
157
     | map2 { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
     | list_generic { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
158
159
    ;

160
map2: LCURLY_BRACKET {
161
162
163
164
165
166
167
168
169
    // This code is executed when we're about to start parsing
    // the content of the map
    ElementPtr m(new MapElement());
    ctx.stack_.push_back(m);
} map_content RCURLY_BRACKET {
    // map parsing completed. If we ever want to do any wrap up
    // (maybe some sanity checking), this would be the best place
    // for it.
};
170
171
172
173

// Assignments rule
map_content:  { /* do nothing, it's an empty map */ }
    | STRING COLON value {
174
175
        // map containing a single entry
        ctx.stack_.back()->set($1, $3);
176
    }
177
    | map_content COMMA STRING COLON value {
178
179
        // map consisting of a shorter map followed by comma and string:value
        ctx.stack_.back()->set($3, $5);
180
181
182
    }
    ;

183
184
185
186
187
188
189
190
191
list_generic: LSQUARE_BRACKET {
    ElementPtr l(new ListElement());
    ctx.stack_.push_back(l);
 } list_content RSQUARE_BRACKET {

 }

// This one is used in syntax parser.
list2: LSQUARE_BRACKET {
192
193
194
    // List parsing about to start
} list_content RSQUARE_BRACKET {
    // list parsing complete. Put any sanity checking here
195
    //ctx.stack_.pop_back();
196
};
197
198
199

list_content: { /* do nothing, it's an empty list */ }
    | value {
200
201
        // List consisting of a single element.
        ctx.stack_.back()->add($1);
202
    }
203
    | list_content COMMA value {
204
205
        // List ending with , and a value.
        ctx.stack_.back()->add($3);
206
207
208
    }
    ;

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// ---- generic JSON parser ends here ----------------------------------

// ---- syntax checking parser starts here -----------------------------

// This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
// objects.
syntax_map: LCURLY_BRACKET {
    // This code is executed when we're about to start parsing
    // the content of the map
    ElementPtr m(new MapElement());
    ctx.stack_.push_back(m);
} global_objects RCURLY_BRACKET {
    // map parsing completed. If we ever want to do any wrap up
    // (maybe some sanity checking), this would be the best place
    // for it.
};

// This represents a single top level entry, e.g. Dhcp6 or DhcpDdns.
global_object: dhcp6_object
| logging_object;

// This represents top-level entries: Dhcp6, Dhcp4, DhcpDdns, Logging
global_objects
: global_object
| global_objects COMMA global_object
;

dhcp6_object: DHCP6 COLON LCURLY_BRACKET {
    // This code is executed when we're about to start parsing
    // the content of the map
    ElementPtr m(new MapElement());
    ctx.stack_.back()->set("Dhcp6", m);
    ctx.stack_.push_back(m);
} global_params RCURLY_BRACKET {
    // map parsing completed. If we ever want to do any wrap up
    // (maybe some sanity checking), this would be the best place
    // for it.
    ctx.stack_.pop_back();
};

249
250
251
252
global_params: global_param
| global_params COMMA global_param;

// These are the parameters that are allowed in the top-level for
253
// Dhcp6.
254
255
256
257
258
259
260
261
global_param
: preferred_lifetime
| valid_lifetime
| renew_timer
| rebind_timer
| subnet6_list
| interfaces_config
| lease_database
262
| hosts_database
263
264
| mac_sources
| relay_supplied_options
265
| host_reservation_identifiers
266
267
| client_classes
| option_data_list
268
269
270
| hooks_libraries
| expired_leases_processing
| server_id
271
| dhcp4o6_port
272
273
274
;

preferred_lifetime: PREFERRED_LIFETIME COLON INTEGER {
275
276
    ElementPtr prf(new IntElement($3));
    ctx.stack_.back()->set("preferred-lifetime", prf);
277
278
279
};

valid_lifetime: VALID_LIFETIME COLON INTEGER {
280
281
    ElementPtr prf(new IntElement($3));
    ctx.stack_.back()->set("valid-lifetime", prf);
282
283
284
};

renew_timer: RENEW_TIMER COLON INTEGER {
285
286
    ElementPtr prf(new IntElement($3));
    ctx.stack_.back()->set("renew-timer", prf);
287
288
};

289
290
291
292
rebind_timer: REBIND_TIMER COLON INTEGER {
    ElementPtr prf(new IntElement($3));
    ctx.stack_.back()->set("rebind-timer", prf);
};
293

294
295
296
297
298
299
300
interfaces_config: INTERFACES_CONFIG COLON {
    ElementPtr i(new MapElement());
    ctx.stack_.back()->set("interfaces-config", i);
    ctx.stack_.push_back(i);
 } LCURLY_BRACKET interface_config_map RCURLY_BRACKET {
    ctx.stack_.pop_back();
};
301

302
303
304
305
interface_config_map: INTERFACES {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("interfaces", l);
    ctx.stack_.push_back(l);
306
 } COLON list2 {
307
308
309
310
311
312
313
314
     ctx.stack_.pop_back();
 }

lease_database: LEASE_DATABASE {
    ElementPtr i(new MapElement());
    ctx.stack_.back()->set("lease-database", i);
    ctx.stack_.push_back(i);
}
315
COLON LCURLY_BRACKET database_map_params {
316
317
     ctx.stack_.pop_back();
} RCURLY_BRACKET;
318

319
320
321
322
323
324
325
326
hosts_database: HOSTS_DATABASE {
    ElementPtr i(new MapElement());
    ctx.stack_.back()->set("hosts-database", i);
    ctx.stack_.push_back(i);
}
COLON LCURLY_BRACKET database_map_params {
     ctx.stack_.pop_back();
} RCURLY_BRACKET;
327

328
329
database_map_params: lease_database_map_param
| database_map_params COMMA lease_database_map_param;
330

331
332
333
334
lease_database_map_param: type
| user
| password
| host
335
| name
336
337
338
| persist
| lfc_interval;
;
339
340

type: TYPE COLON STRING {
341
342
    ElementPtr prf(new StringElement($3));
    ctx.stack_.back()->set("type", prf);
343
344
};

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
user: USER COLON STRING {
    ElementPtr user(new StringElement($3));
    ctx.stack_.back()->set("user", user);
};

password: PASSWORD COLON STRING {
    ElementPtr pwd(new StringElement($3));
    ctx.stack_.back()->set("password", pwd);
};

host: HOST COLON STRING {
    ElementPtr h(new StringElement($3));
    ctx.stack_.back()->set("host", h);
};

name: NAME COLON STRING {
    ElementPtr n(new StringElement($3));
    ctx.stack_.back()->set("name", n);
};

365
366
367
368
369
persist: PERSIST COLON BOOLEAN {
    ElementPtr n(new BoolElement($3));
    ctx.stack_.back()->set("persist", n);
};

370
371
372
373
374
lfc_interval: LFC_INTERVAL COLON INTEGER {
    ElementPtr n(new IntElement($3));
    ctx.stack_.back()->set("lfc-interval", n);
};

375
376
377
378
mac_sources: MAC_SOURCES {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("mac-sources", l);
    ctx.stack_.push_back(l);
379
} COLON LSQUARE_BRACKET mac_sources_list RSQUARE_BRACKET {
380
381
382
    ctx.stack_.pop_back();
};

383
384
385
386
387
388
389
390
391
mac_sources_list: mac_sources_value
| mac_sources_list COMMA mac_sources_value;

mac_sources_value: DUID {
    ElementPtr duid(new StringElement("duid")); ctx.stack_.back()->add(duid);
}| STRING {
    ElementPtr duid(new StringElement($1)); ctx.stack_.back()->add(duid);
};

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
host_reservation_identifiers: HOST_RESERVATION_IDENTIFIERS COLON LSQUARE_BRACKET {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("host-reservation-identifiers", l);
    ctx.stack_.push_back(l);
} host_reservation_identifiers_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};

host_reservation_identifiers_list: host_reservation_identifier
| host_reservation_identifiers_list COMMA host_reservation_identifier;

host_reservation_identifier: DUID {
    ElementPtr duid(new StringElement("duid")); ctx.stack_.back()->add(duid);
}
| HW_ADDRESS {
    ElementPtr hwaddr(new StringElement("hw-address")); ctx.stack_.back()->add(hwaddr);
}

410
411
412
413
relay_supplied_options: RELAY_SUPPLIED_OPTIONS {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("relay-supplied-options", l);
    ctx.stack_.push_back(l);
414
} COLON list2 {
415
416
417
    ctx.stack_.pop_back();
};

418
419
420
421
422
423
424
425
hooks_libraries: HOOKS_LIBRARIES COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("hooks-libraries", l);
    ctx.stack_.push_back(l);
} LSQUARE_BRACKET hooks_libraries_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};

426
hooks_libraries_list: { }
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
| hooks_library
| hooks_libraries_list COMMA hooks_library;

hooks_library: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} hooks_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

hooks_params: hooks_param
| hooks_params hooks_param;

hooks_param: LIBRARY COLON STRING {
    ElementPtr lib(new StringElement($3)); ctx.stack_.back()->set("library", lib);
};

// --- expired-leases-processing ------------------------
expired_leases_processing: EXPIRED_LEASES_PROCESSING COLON LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->set("expired-leases-processing", m);
    ctx.stack_.push_back(m);
} expired_leases_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

expired_leases_params: expired_leases_param
| expired_leases_params COMMA expired_leases_param;

// This is a bit of a simplification. But it can also serve as an example.
// Instead of explicitly listing all allowed expired leases parameters, we
// simply say that all of them as integers.
expired_leases_param: STRING COLON INTEGER {
    ElementPtr value(new IntElement($3)); ctx.stack_.back()->set($1, value);
}

// --- subnet6 ------------------------------------------
465
466
467
468
// This defines subnet6 as a list of maps.
// "subnet6": [ ... ]
subnet6_list: SUBNET6 COLON LSQUARE_BRACKET {
    ElementPtr l(new ListElement());
469
    ctx.stack_.back()->set("subnet6", l);
470
471
    ctx.stack_.push_back(l);
} subnet6_list_content RSQUARE_BRACKET {
472
    ctx.stack_.pop_back();
473
474
475
476
477
478
479
480
481
482
};

// This defines the ... in "subnet6": [ ... ]
// It can either be empty (no subnets defined), have one subnet
// or have multiple subnets separate by comma.
subnet6_list_content: { /* no subnets defined at all */ }
| subnet6
| subnet6_list_content COMMA subnet6
;

483
484
// --- Subnet definitions -------------------------------

485
486
// This defines a single subnet, i.e. a single map with
// subnet6 array.
487
488
489
490
491
subnet6: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} subnet6_params {
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
    // Once we reached this place, the subnet parsing is now complete.
    // If we want to, we can implement default values here.
    // In particular we can do things like this:
    // if (!ctx.stack_.back()->get("interface")) {
    //     ctx.stack_.back()->set("interface", StringElement("loopback"));
    // }
    //
    // We can also stack up one level (Dhcp6) and copy over whatever
    // global parameters we want to:
    // if (!ctx.stack_.back()->get("renew-timer")) {
    //     ElementPtr renew = ctx_stack_[...].get("renew-timer");
    //     if (renew) {
    //         ctx.stack_.back()->set("renew-timer", renew);
    //     }
    // }
507
508
    ctx.stack_.pop_back();
} RCURLY_BRACKET;
509

510
// This defines that subnet can have one or more parameters.
511
subnet6_params: subnet6_param
512
513
| subnet6_params COMMA subnet6_param;

514
515
// This defines a list of allowed parameters for each subnet.
subnet6_param: option_data_list
516
| pools_list
517
| pd_pools_list
518
519
| subnet
| interface
520
| id
521
522
| client_class
| reservations
523
524
;

525
526
527
528
529
530
531
532
533
534
535
536
subnet: SUBNET COLON STRING {
    ElementPtr subnet(new StringElement($3)); ctx.stack_.back()->set("subnet", subnet);
};

interface: INTERFACE COLON STRING {
    ElementPtr iface(new StringElement($3)); ctx.stack_.back()->set("interface", iface);
};

subnet: CLIENT_CLASS COLON STRING {
    ElementPtr cls(new StringElement($3)); ctx.stack_.back()->set("client-class", cls);
};

537
538
539
540
id: ID COLON INTEGER {
    ElementPtr id(new IntElement($3)); ctx.stack_.back()->set("id", id);

};
541

542
543
544
545
// ---- option-data --------------------------

// This defines the "option-data": [ ... ] entry that may appear
// in several places, but most notably in subnet6 entries.
546
547
548
549
550
551
552
option_data_list: OPTION_DATA {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("option-data", l);
    ctx.stack_.push_back(l);
} COLON LSQUARE_BRACKET option_data_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};
553
554
555
556
557
558
559
560
561

// This defines the content of option-data. It may be empty,
// have one entry or multiple entries separated by comma.
option_data_list_content: { }
| option_data_entry
| option_data_list_content COMMA option_data_entry;

// This defines th content of a single entry { ... } within
// option-data list.
562
563
564
565
566
567
568
option_data_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} option_data_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};
569
570
571

// This defines parameters specified inside the map that itself
// is an entry in option-data list.
572
option_data_params: option_data_param
573
574
| option_data_params COMMA option_data_param;

575
option_data_param:
576
577
578
579
| option_data_name
| option_data_data
| option_data_code
| option_data_space
580
| option_data_csv_format
581
582
583
584
;


option_data_name: NAME COLON STRING {
585
    ElementPtr name(new StringElement($3)); ctx.stack_.back()->set("name", name);
586
587
588
};

option_data_data: DATA COLON STRING {
589
    ElementPtr data(new StringElement($3)); ctx.stack_.back()->set("data", data);
590
591
592
};

option_data_code: CODE COLON INTEGER {
593
594
    ElementPtr code(new IntElement($3)); ctx.stack_.back()->set("code", code);
};
595

596
597
598
599
option_data_space: SPACE COLON STRING {
    ElementPtr space(new StringElement($3)); ctx.stack_.back()->set("space", space);
};

600
601
602
603
option_data_csv_format: CSV_FORMAT COLON BOOLEAN {
    ElementPtr space(new BoolElement($3)); ctx.stack_.back()->set("csv-format", space);
};

604
605
606
// ---- pools ------------------------------------

// This defines the "pools": [ ... ] entry that may appear in subnet6.
607
608
609
610
611
612
613
pools_list: POOLS COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("pools", l);
    ctx.stack_.push_back(l);
} LSQUARE_BRACKET pools_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};
614
615
616
617
618
619
620

// Pools may be empty, contain a single pool entry or multiple entries
// separate by commas.
pools_list_content: { }
| pool_entry
| pools_list_content COMMA pool_entry;

621
622
623
624
625
626
627
pool_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} pool_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};
628
629
630
631

pool_params: pool_param
| pool_params COMMA pool_param;

632
pool_param: POOL COLON STRING {
633
    ElementPtr pool(new StringElement($3)); ctx.stack_.back()->set("pool", pool);
634
}
635
| option_data_list;
636
637
// --- end of pools definition -------------------------------

638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
// --- pd-pools ----------------------------------------------
pd_pools_list: PD_POOLS COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("pd-pools", l);
    ctx.stack_.push_back(l);
} LSQUARE_BRACKET pd_pools_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};

// Pools may be empty, contain a single pool entry or multiple entries
// separate by commas.
pd_pools_list_content: { }
| pd_pool_entry
| pd_pools_list_content COMMA pd_pool_entry;

pd_pool_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} pd_pool_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

pd_pool_params: pd_pool_param
| pd_pool_params COMMA pd_pool_param;

pd_pool_param: pd_prefix
| pd_prefix_len
| pd_delegated_len
| option_data_list
;

pd_prefix: PREFIX COLON STRING {
    ElementPtr prf(new StringElement($3)); ctx.stack_.back()->set("prefix", prf);
}

pd_prefix_len: PREFIX_LEN COLON INTEGER {
    ElementPtr prf(new IntElement($3)); ctx.stack_.back()->set("prefix-len", prf);
}

pd_delegated_len: DELEGATED_LEN COLON INTEGER {
    ElementPtr deleg(new IntElement($3)); ctx.stack_.back()->set("delegated-len", deleg);
}



// --- end of pd-pools ---------------------------------------

686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
// --- reservations ------------------------------------------
reservations: RESERVATIONS COLON LSQUARE_BRACKET {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("reservations", l);
    ctx.stack_.push_back(l);
} reservations_list {
    ctx.stack_.pop_back();
} RSQUARE_BRACKET;

reservations_list: { }
| reservation
| reservations_list COMMA reservation;

reservation: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} reservation_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

reservation_params: reservation_param
| reservation_params COMMA reservation_param;

// @todo probably need to add mac-address as well here
reservation_param:
| duid
| reservation_client_classes
714
715
716
717
718
| ip_addresses
| prefixes
| hw_address
| hostname
| option_data_list
719
720
;

721
722
723
724
ip_addresses: IP_ADDRESSES COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("ip-addresses", l);
    ctx.stack_.push_back(l);
725
} list2 {
726
727
728
729
730
731
732
    ctx.stack_.pop_back();
};

prefixes: PREFIXES COLON  {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("prefixes", l);
    ctx.stack_.push_back(l);
733
} list2 {
734
735
736
    ctx.stack_.pop_back();
};

737
738
739
740
duid: DUID COLON STRING {
    ElementPtr d(new StringElement($3)); ctx.stack_.back()->set("duid", d);
};

741
742
743
744
745
746
747
748
hw_address: HW_ADDRESS COLON STRING {
    ElementPtr hw(new StringElement($3)); ctx.stack_.back()->set("hw-address", hw);
};

hostname: HOSTNAME COLON STRING {
    ElementPtr host(new StringElement($3)); ctx.stack_.back()->set("hostname", host);
}

749
750
751
752
reservation_client_classes: CLIENT_CLASSES COLON {
    ElementPtr c(new ListElement());
    ctx.stack_.back()->set("client-classes", c);
    ctx.stack_.push_back(c);
753
} list2 {
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
    ctx.stack_.pop_back();
  };

// --- end of reservations definitions -----------------------

// --- client classes ----------------------------------------
client_classes: CLIENT_CLASSES COLON LSQUARE_BRACKET {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("client-classes", l);
    ctx.stack_.push_back(l);
} client_classes_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};

client_classes_list: client_class
| client_classes_list COMMA client_class;

client_class: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} client_class_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

client_class_params: client_class_param
| client_class_params COMMA client_class_param;

client_class_param:
| client_class_name
| client_class_test
| option_data_list
;

client_class_name: NAME COLON STRING {
    ElementPtr name(new StringElement($3));
    ctx.stack_.back()->set("name", name);
};

client_class_test: TEST COLON STRING {
    ElementPtr test(new StringElement($3));
    ctx.stack_.back()->set("test", test);
}


// --- end of client classes ---------------------------------

801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
// --- server-id ---------------------------------------------
server_id: SERVER_ID COLON LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->set("server-id", m);
    ctx.stack_.push_back(m);
} server_id_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};

server_id_params: server_id_param
| server_id_params COMMA server_id_param;

server_id_param: type
| identifier
| time
816
| htype
817
818
| enterprise_id
| persist;
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

htype: HTYPE COLON INTEGER {
    ElementPtr htype(new IntElement($3));
    ctx.stack_.back()->set("htype", htype);
};

identifier: IDENTIFIER COLON STRING {
    ElementPtr id(new StringElement($3));
    ctx.stack_.back()->set("identifier", id);
};

time: TIME COLON INTEGER {
    ElementPtr time(new IntElement($3));
    ctx.stack_.back()->set("time", time);
};
834
835
836
837
838
839

enterprise_id: ENTERPRISE_ID COLON INTEGER {
    ElementPtr time(new IntElement($3));
    ctx.stack_.back()->set("enterprise-id", time);
};

840
841
// --- end of server-id --------------------------------------

842
843
844
845
846
dhcp4o6_port: DHCP4O6_PORT COLON INTEGER {
    ElementPtr time(new IntElement($3));
    ctx.stack_.back()->set("dhcp4o6-port", time);
};

847
848
849
850
851
852
// --- logging entry -----------------------------------------

// This defines the top level "Logging" object. It parses
// the following "Logging": { ... }. The ... is defined
// by logging_params
logging_object: LOGGING COLON LCURLY_BRACKET {
853
854
855
    ElementPtr m(new MapElement());
    ctx.stack_.back()->set("Logging", m);
    ctx.stack_.push_back(m);
856
} logging_params RCURLY_BRACKET {
857
    ctx.stack_.pop_back();
858
859
860
861
862
863
864
865
866
867
868
869
870
};

// This defines the list of allowed parameters that may appear
// in the top-level Logging object. It can either be a single
// parameter or several parameters separated by commas.
logging_params: logging_param
| logging_params COMMA logging_param;

// There's currently only one parameter defined, which is "loggers".
logging_param: loggers;

// "loggers", the only parameter currently defined in "Logging" object,
// is "Loggers": [ ... ].
871
872
873
874
875
876
877
loggers: LOGGERS COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("loggers", l);
    ctx.stack_.push_back(l);
} LSQUARE_BRACKET loggers_entries RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};
878
879
880
881
882
883
884

// These are the parameters allowed in loggers: either one logger
// entry or multiple entries separate by commas.
loggers_entries: logger_entry
| loggers_entries COMMA logger_entry;

// This defines a single entry defined in loggers in Logging.
885
886
887
888
889
890
891
logger_entry: LCURLY_BRACKET {
    ElementPtr l(new MapElement());
    ctx.stack_.back()->add(l);
    ctx.stack_.push_back(l);
} logger_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};
892
893
894
895

logger_params: logger_param
| logger_params COMMA logger_param;

896
logger_param: logger_name
897
898
899
900
901
| output_options_list
| debuglevel
| severity
;

902
903
904
905
906
907
908
909
910
911
logger_name: NAME COLON STRING {
    ElementPtr name(new StringElement($3)); ctx.stack_.back()->set("name", name);
};

debuglevel: DEBUGLEVEL COLON INTEGER {
    ElementPtr dl(new IntElement($3)); ctx.stack_.back()->set("debuglevel", dl);
};
severity: SEVERITY COLON STRING {
    ElementPtr sev(new StringElement($3)); ctx.stack_.back()->set("severity", sev);
};
912

913
914
915
916
917
918
919
output_options_list: OUTPUT_OPTIONS COLON {
    ElementPtr l(new ListElement());
    ctx.stack_.back()->set("output_options", l);
    ctx.stack_.push_back(l);
} LSQUARE_BRACKET output_options_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
};
920
921
922
923

output_options_list_content: output_entry
| output_options_list_content COMMA output_entry;

924
925
926
927
928
929
930
output_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement());
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} output_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
};
931
932
933
934

output_params: output_param
| output_params COMMA output_param;

935
936
937
output_param: OUTPUT COLON STRING {
    ElementPtr sev(new StringElement($3)); ctx.stack_.back()->set("output", sev);
};
938
939
940



941
942
943
944
%%

void
isc::dhcp::Dhcp6Parser::error(const location_type& loc,
945
                              const std::string& what)
946
947
948
{
    ctx.error(loc, what);
}