dhcp4_parser.yy 66.8 KB
Newer Older
1
/* Copyright (C) 2016-2019 Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 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 50 51 52

   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 {Dhcp4Parser}
%define api.prefix {parser4_}
%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 <dhcp4/parser_context_decl.h>

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


%define api.token.prefix {TOKEN_}
// Tokens in an order which makes sense and related to the intented use.
// Actual regexps for tokens are defined in dhcp4_lexer.ll.
%token
  END  0  "end of file"
  COMMA ","
  COLON ":"
  LSQUARE_BRACKET "["
  RSQUARE_BRACKET "]"
  LCURLY_BRACKET "{"
  RCURLY_BRACKET "}"
  NULL_TYPE "null"

  DHCP4 "Dhcp4"
53 54
  CONFIG_CONTROL "config-control"
  CONFIG_DATABASES "config-databases"
55 56
  INTERFACES_CONFIG "interfaces-config"
  INTERFACES "interfaces"
57
  DHCP_SOCKET_TYPE "dhcp-socket-type"
58 59
  RAW "raw"
  UDP "udp"
60 61 62
  OUTBOUND_INTERFACE "outbound-interface"
  SAME_AS_INBOUND "same-as-inbound"
  USE_ROUTING "use-routing"
63
  RE_DETECT "re-detect"
64

65 66 67
  SANITY_CHECKS "sanity-checks"
  LEASE_CHECKS "lease-checks"

68 69
  ECHO_CLIENT_ID "echo-client-id"
  MATCH_CLIENT_ID "match-client-id"
70
  AUTHORITATIVE "authoritative"
71 72 73 74
  NEXT_SERVER "next-server"
  SERVER_HOSTNAME "server-hostname"
  BOOT_FILE_NAME "boot-file-name"

75 76
  LEASE_DATABASE "lease-database"
  HOSTS_DATABASE "hosts-database"
77
  HOSTS_DATABASES "hosts-databases"
78
  TYPE "type"
79 80 81
  MEMFILE "memfile"
  MYSQL "mysql"
  POSTGRESQL "postgresql"
82
  CQL "cql"
83 84 85
  USER "user"
  PASSWORD "password"
  HOST "host"
Francis Dupont's avatar
Francis Dupont committed
86
  PORT "port"
87 88 89
  PERSIST "persist"
  LFC_INTERVAL "lfc-interval"
  READONLY "readonly"
90
  CONNECT_TIMEOUT "connect-timeout"
91
  CONTACT_POINTS "contact-points"
92
  KEYSPACE "keyspace"
93 94
  MAX_RECONNECT_TRIES "max-reconnect-tries"
  RECONNECT_WAIT_TIME "reconnect-wait-time"
95 96 97
  REQUEST_TIMEOUT "request-timeout"
  TCP_KEEPALIVE "tcp-keepalive"
  TCP_NODELAY "tcp-nodelay"
98 99 100 101

  VALID_LIFETIME "valid-lifetime"
  RENEW_TIMER "renew-timer"
  REBIND_TIMER "rebind-timer"
102 103 104
  CALCULATE_TEE_TIMES "calculate-tee-times"
  T1_PERCENT "t1-percent"
  T2_PERCENT "t2-percent"
105
  DECLINE_PROBATION_PERIOD "decline-probation-period"
106
  SERVER_TAG "server-tag"
107 108
  SUBNET4 "subnet4"
  SUBNET_4O6_INTERFACE "4o6-interface"
109
  SUBNET_4O6_INTERFACE_ID "4o6-interface-id"
110 111 112 113 114 115 116 117
  SUBNET_4O6_SUBNET "4o6-subnet"
  OPTION_DEF "option-def"
  OPTION_DATA "option-data"
  NAME "name"
  DATA "data"
  CODE "code"
  SPACE "space"
  CSV_FORMAT "csv-format"
118
  ALWAYS_SEND "always-send"
119 120 121 122
  RECORD_TYPES "record-types"
  ENCAPSULATE "encapsulate"
  ARRAY "array"

123 124
  SHARED_NETWORKS "shared-networks"

125 126
  POOLS "pools"
  POOL "pool"
127
  USER_CONTEXT "user-context"
128
  COMMENT "comment"
129 130 131 132 133

  SUBNET "subnet"
  INTERFACE "interface"
  ID "id"
  RESERVATION_MODE "reservation-mode"
134 135
  DISABLED "disabled"
  OUT_OF_POOL "out-of-pool"
136
  GLOBAL "global"
137
  ALL "all"
138 139 140 141

  HOST_RESERVATION_IDENTIFIERS "host-reservation-identifiers"

  CLIENT_CLASSES "client-classes"
142
  REQUIRE_CLIENT_CLASSES "require-client-classes"
143
  TEST "test"
144
  ONLY_IF_REQUIRED "only-if-required"
145 146 147 148 149 150 151 152
  CLIENT_CLASS "client-class"

  RESERVATIONS "reservations"
  DUID "duid"
  HW_ADDRESS "hw-address"
  CIRCUIT_ID "circuit-id"
  CLIENT_ID "client-id"
  HOSTNAME "hostname"
153
  FLEX_ID "flex-id"
154 155 156

  RELAY "relay"
  IP_ADDRESS "ip-address"
157
  IP_ADDRESSES "ip-addresses"
158 159 160 161 162 163

  HOOKS_LIBRARIES "hooks-libraries"
  LIBRARY "library"
  PARAMETERS "parameters"

  EXPIRED_LEASES_PROCESSING "expired-leases-processing"
Francis Dupont's avatar
Francis Dupont committed
164 165 166 167 168 169
  RECLAIM_TIMER_WAIT_TIME "reclaim-timer-wait-time"
  FLUSH_RECLAIMED_TIMER_WAIT_TIME "flush-reclaimed-timer-wait-time"
  HOLD_RECLAIMED_TIME "hold-reclaimed-time"
  MAX_RECLAIM_LEASES "max-reclaim-leases"
  MAX_RECLAIM_TIME "max-reclaim-time"
  UNWARNED_RECLAIM_CYCLES "unwarned-reclaim-cycles"
170 171 172 173 174 175 176

  DHCP4O6_PORT "dhcp4o6-port"

  CONTROL_SOCKET "control-socket"
  SOCKET_TYPE "socket-type"
  SOCKET_NAME "socket-name"

177
  DHCP_QUEUE_CONTROL "dhcp-queue-control"
178

179
  DHCP_DDNS "dhcp-ddns"
180 181 182 183 184 185 186 187 188 189 190 191 192
  ENABLE_UPDATES "enable-updates"
  QUALIFYING_SUFFIX "qualifying-suffix"
  SERVER_IP "server-ip"
  SERVER_PORT "server-port"
  SENDER_IP "sender-ip"
  SENDER_PORT "sender-port"
  MAX_QUEUE_SIZE "max-queue-size"
  NCR_PROTOCOL "ncr-protocol"
  NCR_FORMAT "ncr-format"
  OVERRIDE_NO_UPDATE "override-no-update"
  OVERRIDE_CLIENT_UPDATE "override-client-update"
  REPLACE_CLIENT_NAME "replace-client-name"
  GENERATED_PREFIX "generated-prefix"
193
  TCP "tcp"
194 195 196 197 198
  JSON "JSON"
  WHEN_PRESENT "when-present"
  NEVER "never"
  ALWAYS "always"
  WHEN_NOT_PRESENT "when-not-present"
199 200
  HOSTNAME_CHAR_SET "hostname-char-set"
  HOSTNAME_CHAR_REPLACEMENT "hostname-char-replacement"
201 202 203 204 205 206 207

  LOGGING "Logging"
  LOGGERS "loggers"
  OUTPUT_OPTIONS "output_options"
  OUTPUT "output"
  DEBUGLEVEL "debuglevel"
  SEVERITY "severity"
208 209 210
  FLUSH "flush"
  MAXSIZE "maxsize"
  MAXVER "maxver"
211 212 213

  DHCP6 "Dhcp6"
  DHCPDDNS "DhcpDdns"
214
  CONTROL_AGENT "Control-agent"
215 216 217 218 219 220 221 222 223 224

 // Not real tokens, just a way to signal what the parser is expected to
 // parse.
  TOPLEVEL_JSON
  TOPLEVEL_DHCP4
  SUB_DHCP4
  SUB_INTERFACES4
  SUB_SUBNET4
  SUB_POOL4
  SUB_RESERVATION
Francis Dupont's avatar
Francis Dupont committed
225
  SUB_OPTION_DEFS
226 227 228
  SUB_OPTION_DEF
  SUB_OPTION_DATA
  SUB_HOOKS_LIBRARY
229
  SUB_DHCP_DDNS
230
  SUB_LOGGING
231
  SUB_CONFIG_CONTROL
232 233 234 235 236 237 238 239
;

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

%type <ElementPtr> value
240
%type <ElementPtr> map_value
241
%type <ElementPtr> socket_type
242
%type <ElementPtr> outbound_interface_value
243
%type <ElementPtr> db_type
244
%type <ElementPtr> hr_mode
245 246
%type <ElementPtr> ncr_protocol_value
%type <ElementPtr> replace_client_name_value
247 248 249 250 251 252

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

%%

// The whole grammar starts with a map, because the config file
Francis Dupont's avatar
Francis Dupont committed
253
// consists of Dhcp, Logger and DhcpDdns entries in one big { }.
254 255 256 257 258 259 260 261 262 263
// We made the same for subparsers at the exception of the JSON value.
%start start;

start: TOPLEVEL_JSON { ctx.ctx_ = ctx.NO_KEYWORD; } sub_json
     | TOPLEVEL_DHCP4 { ctx.ctx_ = ctx.CONFIG; } syntax_map
     | SUB_DHCP4 { ctx.ctx_ = ctx.DHCP4; } sub_dhcp4
     | SUB_INTERFACES4 { ctx.ctx_ = ctx.INTERFACES_CONFIG; } sub_interfaces4
     | SUB_SUBNET4 { ctx.ctx_ = ctx.SUBNET4; } sub_subnet4
     | SUB_POOL4 { ctx.ctx_ = ctx.POOLS; } sub_pool4
     | SUB_RESERVATION { ctx.ctx_ = ctx.RESERVATIONS; } sub_reservation
Francis Dupont's avatar
Francis Dupont committed
264
     | SUB_OPTION_DEFS { ctx.ctx_ = ctx.DHCP4; } sub_option_def_list
265 266 267
     | SUB_OPTION_DEF { ctx.ctx_ = ctx.OPTION_DEF; } sub_option_def
     | SUB_OPTION_DATA { ctx.ctx_ = ctx.OPTION_DATA; } sub_option_data
     | SUB_HOOKS_LIBRARY { ctx.ctx_ = ctx.HOOKS_LIBRARIES; } sub_hooks_library
268
     | SUB_DHCP_DDNS { ctx.ctx_ = ctx.DHCP_DDNS; } sub_dhcp_ddns
269
     | SUB_LOGGING { ctx.ctx_ = ctx.LOGGING; } sub_logging
270
     | SUB_CONFIG_CONTROL { ctx.ctx_ = ctx.CONFIG_CONTROL; } sub_config_control
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
     ;

// ---- generic JSON parser ---------------------------------

// Note that ctx_ is NO_KEYWORD here

// Values rule
value: INTEGER { $$ = ElementPtr(new IntElement($1, ctx.loc2pos(@1))); }
     | FLOAT { $$ = ElementPtr(new DoubleElement($1, ctx.loc2pos(@1))); }
     | BOOLEAN { $$ = ElementPtr(new BoolElement($1, ctx.loc2pos(@1))); }
     | STRING { $$ = ElementPtr(new StringElement($1, ctx.loc2pos(@1))); }
     | NULL_TYPE { $$ = ElementPtr(new NullElement(ctx.loc2pos(@1))); }
     | map2 { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
     | list_generic { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
     ;

sub_json: value {
    // Push back the JSON value on the stack
    ctx.stack_.push_back($1);
};

map2: LCURLY_BRACKET {
    // This code is executed when we're about to start parsing
    // the content of the map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    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.
};

303 304
map_value: map2 { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); };

305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
// Assignments rule
map_content: %empty // empty map
           | not_empty_map
           ;

not_empty_map: STRING COLON value {
                  // map containing a single entry
                  ctx.stack_.back()->set($1, $3);
                  }
             | not_empty_map COMMA STRING COLON value {
                  // map consisting of a shorter map followed by
                  // comma and string:value
                  ctx.stack_.back()->set($3, $5);
                  }
             ;

list_generic: LSQUARE_BRACKET {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(l);
} list_content RSQUARE_BRACKET {
    // list parsing complete. Put any sanity checking here
};

list_content: %empty // Empty list
            | not_empty_list
            ;

not_empty_list: value {
                  // List consisting of a single element.
                  ctx.stack_.back()->add($1);
                  }
              | not_empty_list COMMA value {
                  // List ending with , and a value.
                  ctx.stack_.back()->add($3);
                  }
              ;

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
// This one is used in syntax parser and is restricted to strings.
list_strings: LSQUARE_BRACKET {
    // List parsing about to start
} list_strings_content RSQUARE_BRACKET {
    // list parsing complete. Put any sanity checking here
    //ctx.stack_.pop_back();
};

list_strings_content: %empty // Empty list
                    | not_empty_list_strings
                    ;

not_empty_list_strings: STRING {
                          ElementPtr s(new StringElement($1, ctx.loc2pos(@1)));
                          ctx.stack_.back()->add(s);
                          }
                      | not_empty_list_strings COMMA STRING {
                          ElementPtr s(new StringElement($3, ctx.loc2pos(@3)));
                          ctx.stack_.back()->add(s);
                          }
                      ;

364 365 366 367 368 369 370 371 372 373 374 375 376
// ---- generic JSON parser ends here ----------------------------------

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

// Unknown keyword in a map
unknown_map_entry: STRING COLON {
    const std::string& where = ctx.contextName();
    const std::string& keyword = $1;
    error(@1,
          "got unexpected keyword \"" + keyword + "\" in " + where + " map.");
};


377 378
// This defines the top-level { } that holds Control-agent, Dhcp6, Dhcp4,
// DhcpDdns or Logging objects.
379 380 381 382 383 384 385 386 387
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.loc2pos(@1)));
    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.
Francis Dupont's avatar
Francis Dupont committed
388 389 390

    // Dhcp4 is required
    ctx.require("Dhcp4", ctx.loc2pos(@1), ctx.loc2pos(@4));
391 392
};

393 394
// This represents top-level entries: Control-agent, Dhcp6, Dhcp4,
// DhcpDdns, Logging
395 396 397 398
global_objects: global_object
              | global_objects COMMA global_object
              ;

Francis Dupont's avatar
Francis Dupont committed
399
// This represents a single top level entry, e.g. Dhcp4 or DhcpDdns.
400 401 402 403
global_object: dhcp4_object
             | logging_object
             | dhcp6_json_object
             | dhcpddns_json_object
404
             | control_agent_json_object
405 406 407 408 409 410 411 412 413 414 415
             | unknown_map_entry
             ;

dhcp4_object: DHCP4 {
    // This code is executed when we're about to start parsing
    // the content of the map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("Dhcp4", m);
    ctx.stack_.push_back(m);
    ctx.enter(ctx.DHCP4);
} COLON LCURLY_BRACKET global_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
416
    // No global parameter is required
417 418 419 420 421 422 423
    ctx.stack_.pop_back();
    ctx.leave();
};

// subparser: similar to the corresponding rule but without parent
// so the stack is empty at the rule entry.
sub_dhcp4: LCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
424
    // Parse the Dhcp4 map
425 426 427
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} global_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
428
    // No global parameter is required
429 430 431 432 433 434 435 436 437 438 439 440 441 442
    // parsing completed
};

global_params: global_param
             | global_params COMMA global_param
             ;

// These are the parameters that are allowed in the top-level for
// Dhcp4.
global_param: valid_lifetime
            | renew_timer
            | rebind_timer
            | decline_probation_period
            | subnet4_list
443
            | shared_networks
444 445 446
            | interfaces_config
            | lease_database
            | hosts_database
447
            | hosts_databases
448 449 450 451 452 453 454 455
            | host_reservation_identifiers
            | client_classes
            | option_def_list
            | option_data_list
            | hooks_libraries
            | expired_leases_processing
            | dhcp4o6_port
            | control_socket
456
            | dhcp_queue_control
457
            | dhcp_ddns
458 459
            | echo_client_id
            | match_client_id
460
            | authoritative
461
            | next_server
Francis Dupont's avatar
Francis Dupont committed
462 463
            | server_hostname
            | boot_file_name
464 465
            | user_context
            | comment
466
            | sanity_checks
467
            | reservations
468
            | config_control
469
            | server_tag
470
            | reservation_mode
471 472 473
            | calculate_tee_times
            | t1_percent
            | t2_percent
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
            | unknown_map_entry
            ;

valid_lifetime: VALID_LIFETIME COLON INTEGER {
    ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("valid-lifetime", prf);
};

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

rebind_timer: REBIND_TIMER COLON INTEGER {
    ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("rebind-timer", prf);
};

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
calculate_tee_times: CALCULATE_TEE_TIMES COLON BOOLEAN {
    ElementPtr ctt(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("calculate-tee-times", ctt);
};

t1_percent: T1_PERCENT COLON FLOAT {
    ElementPtr t1(new DoubleElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("t1-percent", t1);
};

t2_percent: T2_PERCENT COLON FLOAT {
    ElementPtr t2(new DoubleElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("t2-percent", t2);
};

507 508 509 510 511
decline_probation_period: DECLINE_PROBATION_PERIOD COLON INTEGER {
    ElementPtr dpp(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("decline-probation-period", dpp);
};

512 513 514 515 516 517 518 519
server_tag: SERVER_TAG  {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr stag(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("server-tag", stag);
    ctx.leave();
};

520
echo_client_id: ECHO_CLIENT_ID COLON BOOLEAN {
521
    ElementPtr echo(new BoolElement($3, ctx.loc2pos(@3)));
522 523 524 525
    ctx.stack_.back()->set("echo-client-id", echo);
};

match_client_id: MATCH_CLIENT_ID COLON BOOLEAN {
526
    ElementPtr match(new BoolElement($3, ctx.loc2pos(@3)));
527 528 529
    ctx.stack_.back()->set("match-client-id", match);
};

530 531 532 533 534
authoritative: AUTHORITATIVE COLON BOOLEAN {
    ElementPtr prf(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("authoritative", prf);
};

535

536 537 538 539 540
interfaces_config: INTERFACES_CONFIG {
    ElementPtr i(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("interfaces-config", i);
    ctx.stack_.push_back(i);
    ctx.enter(ctx.INTERFACES_CONFIG);
541
} COLON LCURLY_BRACKET interfaces_config_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
542
    // No interfaces config param is required
543 544 545 546
    ctx.stack_.pop_back();
    ctx.leave();
};

547 548 549 550 551 552
interfaces_config_params: interfaces_config_param
                        | interfaces_config_params COMMA interfaces_config_param
                        ;

interfaces_config_param: interfaces_list
                       | dhcp_socket_type
553
                       | outbound_interface
554
                       | re_detect
Francis Dupont's avatar
Francis Dupont committed
555 556 557
                       | user_context
                       | comment
                       | unknown_map_entry
558 559
                       ;

560 561 562 563
sub_interfaces4: LCURLY_BRACKET {
    // Parse the interfaces-config map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
564
} interfaces_config_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
565
    // No interfaces config param is required
566 567 568
    // parsing completed
};

569
interfaces_list: INTERFACES {
570 571 572 573
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("interfaces", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.NO_KEYWORD);
574
} COLON list_strings {
575 576 577 578
    ctx.stack_.pop_back();
    ctx.leave();
};

579 580 581 582 583
dhcp_socket_type: DHCP_SOCKET_TYPE {
    ctx.enter(ctx.DHCP_SOCKET_TYPE);
} COLON socket_type {
    ctx.stack_.back()->set("dhcp-socket-type", $4);
    ctx.leave();
Tomek Mrugalski's avatar
Tomek Mrugalski committed
584 585
};

586 587 588
socket_type: RAW { $$ = ElementPtr(new StringElement("raw", ctx.loc2pos(@1))); }
           | UDP { $$ = ElementPtr(new StringElement("udp", ctx.loc2pos(@1))); }
           ;
589

590 591 592 593 594
outbound_interface: OUTBOUND_INTERFACE {
    ctx.enter(ctx.OUTBOUND_INTERFACE);
} COLON outbound_interface_value {
    ctx.stack_.back()->set("outbound-interface", $4);
    ctx.leave();
Francis Dupont's avatar
Francis Dupont committed
595
};
596 597 598 599 600 601 602

outbound_interface_value: SAME_AS_INBOUND {
    $$ = ElementPtr(new StringElement("same-as-inbound", ctx.loc2pos(@1)));
} | USE_ROUTING {
    $$ = ElementPtr(new StringElement("use-routing", ctx.loc2pos(@1)));
    } ;

603 604 605 606 607 608
re_detect: RE_DETECT COLON BOOLEAN {
    ElementPtr b(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("re-detect", b);
};


609 610 611 612 613 614
lease_database: LEASE_DATABASE {
    ElementPtr i(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("lease-database", i);
    ctx.stack_.push_back(i);
    ctx.enter(ctx.LEASE_DATABASE);
} COLON LCURLY_BRACKET database_map_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
615 616
    // The type parameter is required
    ctx.require("type", ctx.loc2pos(@4), ctx.loc2pos(@6));
617 618 619 620
    ctx.stack_.pop_back();
    ctx.leave();
};

621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
sanity_checks: SANITY_CHECKS {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("sanity-checks", m);
    ctx.stack_.push_back(m);
    ctx.enter(ctx.SANITY_CHECKS);
} COLON LCURLY_BRACKET sanity_checks_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

sanity_checks_params: sanity_checks_param
                    | sanity_checks_params COMMA sanity_checks_param;

sanity_checks_param: lease_checks;

lease_checks: LEASE_CHECKS {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {

    if ( (string($4) == "none") ||
         (string($4) == "warn") ||
         (string($4) == "fix") ||
         (string($4) == "fix-del") ||
         (string($4) == "del")) {
        ElementPtr user(new StringElement($4, ctx.loc2pos(@4)));
        ctx.stack_.back()->set("lease-checks", user);
        ctx.leave();
    } else {
        error(@4, "Unsupported 'lease-checks value: " + string($4) +
              ", supported values are: none, warn, fix, fix-del, del");
    }
}

654 655 656 657 658 659
hosts_database: HOSTS_DATABASE {
    ElementPtr i(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("hosts-database", i);
    ctx.stack_.push_back(i);
    ctx.enter(ctx.HOSTS_DATABASE);
} COLON LCURLY_BRACKET database_map_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
660 661
    // The type parameter is required
    ctx.require("type", ctx.loc2pos(@4), ctx.loc2pos(@6));
662 663 664 665
    ctx.stack_.pop_back();
    ctx.leave();
};

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
hosts_databases: HOSTS_DATABASES {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("hosts-databases", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.HOSTS_DATABASE);
} COLON LSQUARE_BRACKET database_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

database_list: %empty
             | not_empty_database_list
             ;

not_empty_database_list: database
                       | not_empty_database_list COMMA database
                       ;

database: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} database_map_params RCURLY_BRACKET {
    // The type parameter is required
    ctx.require("type", ctx.loc2pos(@1), ctx.loc2pos(@4));
    ctx.stack_.pop_back();
};

694 695 696 697
database_map_params: database_map_param
                   | database_map_params COMMA database_map_param
                   ;

698
database_map_param: database_type
699 700 701
                  | user
                  | password
                  | host
Francis Dupont's avatar
Francis Dupont committed
702
                  | port
703 704 705 706
                  | name
                  | persist
                  | lfc_interval
                  | readonly
707
                  | connect_timeout
708
                  | contact_points
709 710
                  | max_reconnect_tries
                  | reconnect_wait_time
711 712 713
                  | request_timeout
                  | tcp_keepalive
                  | tcp_nodelay
714
                  | keyspace
715
                  | unknown_map_entry
Francis Dupont's avatar
Francis Dupont committed
716
                  ;
717

718
database_type: TYPE {
719 720 721
    ctx.enter(ctx.DATABASE_TYPE);
} COLON db_type {
    ctx.stack_.back()->set("type", $4);
722 723 724
    ctx.leave();
};

725 726 727
db_type: MEMFILE { $$ = ElementPtr(new StringElement("memfile", ctx.loc2pos(@1))); }
       | MYSQL { $$ = ElementPtr(new StringElement("mysql", ctx.loc2pos(@1))); }
       | POSTGRESQL { $$ = ElementPtr(new StringElement("postgresql", ctx.loc2pos(@1))); }
728
       | CQL { $$ = ElementPtr(new StringElement("cql", ctx.loc2pos(@1))); }
729 730
       ;

731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
user: USER {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr user(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("user", user);
    ctx.leave();
};

password: PASSWORD {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr pwd(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("password", pwd);
    ctx.leave();
};

host: HOST {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr h(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("host", h);
    ctx.leave();
};

Francis Dupont's avatar
Francis Dupont committed
755 756 757 758 759
port: PORT COLON INTEGER {
    ElementPtr p(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("port", p);
};

760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
name: NAME {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("name", name);
    ctx.leave();
};

persist: PERSIST COLON BOOLEAN {
    ElementPtr n(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("persist", n);
};

lfc_interval: LFC_INTERVAL COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("lfc-interval", n);
};

readonly: READONLY COLON BOOLEAN {
    ElementPtr n(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("readonly", n);
};

783 784 785
connect_timeout: CONNECT_TIMEOUT COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("connect-timeout", n);
786 787
};

788 789 790
request_timeout: REQUEST_TIMEOUT COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("request-timeout", n);
Francis Dupont's avatar
Francis Dupont committed
791
};
792 793 794 795

tcp_keepalive: TCP_KEEPALIVE COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("tcp-keepalive", n);
Francis Dupont's avatar
Francis Dupont committed
796
};
797 798 799 800

tcp_nodelay: TCP_NODELAY COLON BOOLEAN {
    ElementPtr n(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("tcp-nodelay", n);
Francis Dupont's avatar
Francis Dupont committed
801
};
802

803 804 805 806
contact_points: CONTACT_POINTS {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr cp(new StringElement($4, ctx.loc2pos(@4)));
807
    ctx.stack_.back()->set("contact-points", cp);
808 809 810 811 812 813 814 815 816 817 818
    ctx.leave();
};

keyspace: KEYSPACE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr ks(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("keyspace", ks);
    ctx.leave();
};

819 820 821 822 823 824 825 826 827
max_reconnect_tries: MAX_RECONNECT_TRIES COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("max-reconnect-tries", n);
};

reconnect_wait_time: RECONNECT_WAIT_TIME COLON INTEGER {
    ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("reconnect-wait-time", n);
};
828

829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
host_reservation_identifiers: HOST_RESERVATION_IDENTIFIERS {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("host-reservation-identifiers", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.HOST_RESERVATION_IDENTIFIERS);
} COLON LSQUARE_BRACKET host_reservation_identifiers_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

host_reservation_identifiers_list: host_reservation_identifier
    | host_reservation_identifiers_list COMMA host_reservation_identifier
    ;

host_reservation_identifier: duid_id
                           | hw_address_id
                           | circuit_id
                           | client_id
847
                           | flex_id
848 849
                           ;

850 851 852 853 854
duid_id : DUID {
    ElementPtr duid(new StringElement("duid", ctx.loc2pos(@1)));
    ctx.stack_.back()->add(duid);
};

855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
hw_address_id : HW_ADDRESS {
    ElementPtr hwaddr(new StringElement("hw-address", ctx.loc2pos(@1)));
    ctx.stack_.back()->add(hwaddr);
};

circuit_id : CIRCUIT_ID {
    ElementPtr circuit(new StringElement("circuit-id", ctx.loc2pos(@1)));
    ctx.stack_.back()->add(circuit);
};

client_id : CLIENT_ID {
    ElementPtr client(new StringElement("client-id", ctx.loc2pos(@1)));
    ctx.stack_.back()->add(client);
};

870 871 872
flex_id: FLEX_ID {
    ElementPtr flex_id(new StringElement("flex-id", ctx.loc2pos(@1)));
    ctx.stack_.back()->add(flex_id);
Francis Dupont's avatar
Francis Dupont committed
873
};
874

875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
hooks_libraries: HOOKS_LIBRARIES {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("hooks-libraries", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.HOOKS_LIBRARIES);
} COLON LSQUARE_BRACKET hooks_libraries_list RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

hooks_libraries_list: %empty
                    | not_empty_hooks_libraries_list
                    ;

not_empty_hooks_libraries_list: hooks_library
    | not_empty_hooks_libraries_list COMMA hooks_library
    ;

hooks_library: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} hooks_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
898 899
    // The library hooks parameter is required
    ctx.require("library", ctx.loc2pos(@1), ctx.loc2pos(@4));
900 901 902 903 904 905 906 907
    ctx.stack_.pop_back();
};

sub_hooks_library: LCURLY_BRACKET {
    // Parse the hooks-libraries list entry map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} hooks_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
908 909
    // The library hooks parameter is required
    ctx.require("library", ctx.loc2pos(@1), ctx.loc2pos(@4));
910 911 912 913 914
    // parsing completed
};

hooks_params: hooks_param
            | hooks_params COMMA hooks_param
915
            | unknown_map_entry
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
            ;

hooks_param: library
           | parameters
           ;

library: LIBRARY {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr lib(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("library", lib);
    ctx.leave();
};

parameters: PARAMETERS {
    ctx.enter(ctx.NO_KEYWORD);
} COLON value {
    ctx.stack_.back()->set("parameters", $4);
    ctx.leave();
};

// --- expired-leases-processing ------------------------
expired_leases_processing: EXPIRED_LEASES_PROCESSING {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("expired-leases-processing", m);
    ctx.stack_.push_back(m);
Francis Dupont's avatar
Francis Dupont committed
942
    ctx.enter(ctx.EXPIRED_LEASES_PROCESSING);
943
} COLON LCURLY_BRACKET expired_leases_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
944
    // No expired lease parameter is required
945 946 947 948 949 950 951 952
    ctx.stack_.pop_back();
    ctx.leave();
};

expired_leases_params: expired_leases_param
                     | expired_leases_params COMMA expired_leases_param
                     ;

Francis Dupont's avatar
Francis Dupont committed
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
expired_leases_param: reclaim_timer_wait_time
                    | flush_reclaimed_timer_wait_time
                    | hold_reclaimed_time
                    | max_reclaim_leases
                    | max_reclaim_time
                    | unwarned_reclaim_cycles
                    ;

reclaim_timer_wait_time: RECLAIM_TIMER_WAIT_TIME COLON INTEGER {
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("reclaim-timer-wait-time", value);
};

flush_reclaimed_timer_wait_time: FLUSH_RECLAIMED_TIMER_WAIT_TIME COLON INTEGER {
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("flush-reclaimed-timer-wait-time", value);
};

hold_reclaimed_time: HOLD_RECLAIMED_TIME COLON INTEGER {
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("hold-reclaimed-time", value);
};

max_reclaim_leases: MAX_RECLAIM_LEASES COLON INTEGER {
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("max-reclaim-leases", value);
};

max_reclaim_time: MAX_RECLAIM_TIME COLON INTEGER {
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("max-reclaim-time", value);
};

unwarned_reclaim_cycles: UNWARNED_RECLAIM_CYCLES COLON INTEGER {
987
    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
Francis Dupont's avatar
Francis Dupont committed
988
    ctx.stack_.back()->set("unwarned-reclaim-cycles", value);
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
};

// --- subnet4 ------------------------------------------
// This defines subnet4 as a list of maps.
// "subnet4": [ ... ]
subnet4_list: SUBNET4 {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("subnet4", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.SUBNET4);
} COLON LSQUARE_BRACKET subnet4_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

Francis Dupont's avatar
Francis Dupont committed
1004
// This defines the ... in "subnet4": [ ... ]
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
// It can either be empty (no subnets defined), have one subnet
// or have multiple subnets separate by comma.
subnet4_list_content: %empty
                    | not_empty_subnet4_list
                    ;

not_empty_subnet4_list: subnet4
                      | not_empty_subnet4_list COMMA subnet4
                      ;

// --- Subnet definitions -------------------------------

// This defines a single subnet, i.e. a single map with
Francis Dupont's avatar
Francis Dupont committed
1018
// subnet4 array.
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
subnet4: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} subnet4_params RCURLY_BRACKET {
    // 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"));
    // }
    //
Francis Dupont's avatar
Francis Dupont committed
1031
    // We can also stack up one level (Dhcp4) and copy over whatever
1032 1033 1034 1035 1036 1037 1038
    // 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);
    //     }
    // }
Francis Dupont's avatar
Francis Dupont committed
1039 1040 1041

    // The subnet subnet4 parameter is required
    ctx.require("subnet", ctx.loc2pos(@1), ctx.loc2pos(@4));
1042 1043 1044 1045
    ctx.stack_.pop_back();
};

sub_subnet4: LCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1046
    // Parse the subnet4 list entry map
1047 1048 1049
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} subnet4_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1050 1051
    // The subnet subnet4 parameter is required
    ctx.require("subnet", ctx.loc2pos(@1), ctx.loc2pos(@4));
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    // parsing completed
};

// This defines that subnet can have one or more parameters.
subnet4_params: subnet4_param
              | subnet4_params COMMA subnet4_param
              ;

// This defines a list of allowed parameters for each subnet.
subnet4_param: valid_lifetime
             | renew_timer
             | rebind_timer
             | option_data_list
             | pools_list
             | subnet
             | interface
             | id
             | client_class
1070
             | require_client_classes
1071 1072 1073
             | reservations
             | reservation_mode
             | relay
1074
             | match_client_id
1075
             | authoritative
1076
             | next_server
Francis Dupont's avatar
Francis Dupont committed
1077 1078
             | server_hostname
             | boot_file_name
1079
             | subnet_4o6_interface
1080
             | subnet_4o6_interface_id
1081
             | subnet_4o6_subnet
1082
             | user_context
1083
             | comment
1084 1085 1086
             | calculate_tee_times
             | t1_percent
             | t2_percent
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
             | unknown_map_entry
             ;

subnet: SUBNET {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr subnet(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("subnet", subnet);
    ctx.leave();
};

subnet_4o6_interface: SUBNET_4O6_INTERFACE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("4o6-interface", iface);
    ctx.leave();
};

1106 1107 1108 1109 1110 1111 1112 1113
subnet_4o6_interface_id: SUBNET_4O6_INTERFACE_ID {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("4o6-interface-id", iface);
    ctx.leave();
};

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
subnet_4o6_subnet: SUBNET_4O6_SUBNET {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("4o6-subnet", iface);
    ctx.leave();
};

interface: INTERFACE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("interface", iface);
    ctx.leave();
};

client_class: CLIENT_CLASS {
1131
    ctx.enter(ctx.NO_KEYWORD);
1132 1133 1134 1135 1136 1137
} COLON STRING {
    ElementPtr cls(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("client-class", cls);
    ctx.leave();
};

1138
require_client_classes: REQUIRE_CLIENT_CLASSES {
1139
    ElementPtr c(new ListElement(ctx.loc2pos(@1)));
1140
    ctx.stack_.back()->set("require-client-classes", c);
1141 1142 1143 1144 1145 1146 1147
    ctx.stack_.push_back(c);
    ctx.enter(ctx.NO_KEYWORD);
} COLON list_strings {
    ctx.stack_.pop_back();
    ctx.leave();
};

1148
reservation_mode: RESERVATION_MODE {
1149 1150 1151
    ctx.enter(ctx.RESERVATION_MODE);
} COLON hr_mode {
    ctx.stack_.back()->set("reservation-mode", $4);
1152 1153 1154
    ctx.leave();
};

1155 1156
hr_mode: DISABLED { $$ = ElementPtr(new StringElement("disabled", ctx.loc2pos(@1))); }
       | OUT_OF_POOL { $$ = ElementPtr(new StringElement("out-of-pool", ctx.loc2pos(@1))); }
1157
       | GLOBAL { $$ = ElementPtr(new StringElement("global", ctx.loc2pos(@1))); }
1158 1159 1160
       | ALL { $$ = ElementPtr(new StringElement("all", ctx.loc2pos(@1))); }
       ;

1161 1162 1163 1164 1165
id: ID COLON INTEGER {
    ElementPtr id(new IntElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("id", id);
};

1166 1167 1168 1169 1170 1171 1172
// ---- shared-networks ---------------------

shared_networks: SHARED_NETWORKS {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("shared-networks", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.SHARED_NETWORK);
1173
} COLON LSQUARE_BRACKET shared_networks_content RSQUARE_BRACKET {
1174 1175 1176 1177
    ctx.stack_.pop_back();
    ctx.leave();
};

1178 1179 1180 1181 1182 1183
// This allows 0 or more shared network definitions.
shared_networks_content: %empty
                       | shared_networks_list
                       ;

// This allows 1 or more shared network definitions.
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
shared_networks_list: shared_network
                    | shared_networks_list COMMA shared_network
                    ;

shared_network: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} shared_network_params RCURLY_BRACKET {
    ctx.stack_.pop_back();
Francis Dupont's avatar
Francis Dupont committed
1194
};
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206

shared_network_params: shared_network_param
                     | shared_network_params COMMA shared_network_param
                     ;

shared_network_param: name
                    | subnet4_list
                    | interface
                    | renew_timer
                    | rebind_timer
                    | option_data_list
                    | match_client_id
1207
                    | authoritative
1208
                    | next_server
Francis Dupont's avatar
Francis Dupont committed
1209 1210
                    | server_hostname
                    | boot_file_name
1211 1212
                    | relay
                    | reservation_mode
1213
                    | client_class
1214
                    | require_client_classes
1215
                    | valid_lifetime
Francis Dupont's avatar
Francis Dupont committed
1216 1217
                    | user_context
                    | comment
1218 1219 1220
                    | calculate_tee_times
                    | t1_percent
                    | t2_percent
1221 1222 1223
                    | unknown_map_entry
                    ;

1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
// ---- option-def --------------------------

// This defines the "option-def": [ ... ] entry that may appear
// at a global option.
option_def_list: OPTION_DEF {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("option-def", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.OPTION_DEF);
} COLON LSQUARE_BRACKET option_def_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

Francis Dupont's avatar
Francis Dupont committed
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
// This defines the top level scope when the parser is told to parse
// option definitions. It works as a subset limited to option
// definitions
sub_option_def_list: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} option_def_list RCURLY_BRACKET {
    // parsing completed
};

1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
// This defines the content of option-def. It may be empty,
// have one entry or multiple entries separated by comma.
option_def_list_content: %empty
                       | not_empty_option_def_list
                       ;

not_empty_option_def_list: option_def_entry
                         | not_empty_option_def_list COMMA option_def_entry
                          ;

// This defines the content of a single entry { ... } within
// option-def list.
option_def_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} option_def_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1265 1266 1267 1268
    // The name, code and type option def parameters are required.
    ctx.require("name", ctx.loc2pos(@1), ctx.loc2pos(@4));
    ctx.require("code", ctx.loc2pos(@1), ctx.loc2pos(@4));
    ctx.require("type", ctx.loc2pos(@1), ctx.loc2pos(@4));
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
    ctx.stack_.pop_back();
};

// This defines the top level scope when the parser is told to parse a single
// option definition. It's almost exactly the same as option_def_entry, except
// that it does leave its value on stack.
sub_option_def: LCURLY_BRACKET {
    // Parse the option-def list entry map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} option_def_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1280 1281 1282 1283
    // The name, code and type option def parameters are required.
    ctx.require("name", ctx.loc2pos(@1), ctx.loc2pos(@4));
    ctx.require("code", ctx.loc2pos(@1), ctx.loc2pos(@4));
    ctx.require("type", ctx.loc2pos(@1), ctx.loc2pos(@4));
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
    // parsing completed
};

// This defines parameters specified inside the map that itself
// is an entry in option-def list.
option_def_params: %empty
                 | not_empty_option_def_params
                 ;

not_empty_option_def_params: option_def_param
                           | not_empty_option_def_params COMMA option_def_param
                           ;

option_def_param: option_def_name
                | option_def_code
                | option_def_type
                | option_def_record_types
                | option_def_space
                | option_def_encapsulate
                | option_def_array
1304 1305
                | user_context
                | comment
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
                | unknown_map_entry
                ;

option_def_name: name;

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

option_def_code: code;

1318 1319 1320 1321 1322 1323 1324
option_def_type: TYPE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("type", prf);
    ctx.leave();
};
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389

option_def_record_types: RECORD_TYPES {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr rtypes(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("record-types", rtypes);
    ctx.leave();
};

space: SPACE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr space(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("space", space);
    ctx.leave();
};

option_def_space: space;

option_def_encapsulate: ENCAPSULATE {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr encap(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("encapsulate", encap);
    ctx.leave();
};

option_def_array: ARRAY COLON BOOLEAN {
    ElementPtr array(new BoolElement($3, ctx.loc2pos(@3)));
    ctx.stack_.back()->set("array", array);
};

// ---- option-data --------------------------

// This defines the "option-data": [ ... ] entry that may appear
// in several places, but most notably in subnet4 entries.
option_data_list: OPTION_DATA {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("option-data", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.OPTION_DATA);
} COLON LSQUARE_BRACKET option_data_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

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

// This defines the content of option-data list. It can either
// be a single value or multiple entries separated by comma.
not_empty_option_data_list: option_data_entry
                          | not_empty_option_data_list COMMA option_data_entry
                          ;

// This defines th content of a single entry { ... } within
// option-data list.
option_data_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} option_data_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1390
    /// @todo: the code or name parameters are required.
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
    ctx.stack_.pop_back();
};

// This defines the top level scope when the parser is told to parse a single
// option data. It's almost exactly the same as option_data_entry, except
// that it does leave its value on stack.
sub_option_data: LCURLY_BRACKET {
    // Parse the option-data list entry map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} option_data_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1402
    /// @todo: the code or name parameters are required.
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
    // parsing completed
};

// This defines parameters specified inside the map that itself
// is an entry in option-data list. It can either be empty
// or have a non-empty list of parameters.
option_data_params: %empty
                  | not_empty_option_data_params
                  ;

// Those parameters can either be a single parameter or
// a list of parameters separated by comma.
not_empty_option_data_params: option_data_param
    | not_empty_option_data_params COMMA option_data_param
    ;

// Each single option-data parameter can be one of the following
// expressions.
option_data_param: option_data_name
                 | option_data_data
                 | option_data_code
                 | option_data_space
                 | option_data_csv_format
1426
                 | option_data_always_send
1427 1428
                 | user_context
                 | comment
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
                 | unknown_map_entry
                 ;

option_data_name: name;

option_data_data: DATA {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr data(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("data", data);
    ctx.leave();
};

option_data_code: code;

option_data_space: space;

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

1451
option_data_always_send: ALWAYS_SEND COLON BOOLEAN {
1452
    ElementPtr persist(new BoolElement($3, ctx.loc2pos(@3)));
1453
    ctx.stack_.back()->set("always-send", persist);
1454 1455
};

1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
// ---- pools ------------------------------------

// This defines the "pools": [ ... ] entry that may appear in subnet4.
pools_list: POOLS {
    ElementPtr l(new ListElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->set("pools", l);
    ctx.stack_.push_back(l);
    ctx.enter(ctx.POOLS);
} COLON LSQUARE_BRACKET pools_list_content RSQUARE_BRACKET {
    ctx.stack_.pop_back();
    ctx.leave();
};

// Pools may be empty, contain a single pool entry or multiple entries
// separate by commas.
pools_list_content: %empty
                  | not_empty_pools_list
                  ;

not_empty_pools_list: pool_list_entry
                    | not_empty_pools_list COMMA pool_list_entry
                    ;

pool_list_entry: LCURLY_BRACKET {
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.back()->add(m);
    ctx.stack_.push_back(m);
} pool_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1484 1485
    // The pool parameter is required.
    ctx.require("pool", ctx.loc2pos(@1), ctx.loc2pos(@4));
1486 1487 1488 1489 1490 1491 1492 1493
    ctx.stack_.pop_back();
};

sub_pool4: LCURLY_BRACKET {
    // Parse the pool list entry map
    ElementPtr m(new MapElement(ctx.loc2pos(@1)));
    ctx.stack_.push_back(m);
} pool_params RCURLY_BRACKET {
Francis Dupont's avatar
Francis Dupont committed
1494 1495
    // The pool parameter is required.
    ctx.require("pool", ctx.loc2pos(@1), ctx.loc2pos(@4));
1496 1497 1498 1499 1500 1501 1502 1503 1504
    // parsing completed
};

pool_params: pool_param
           | pool_params COMMA pool_param
           ;

pool_param: pool_entry
          | option_data_list
1505
          | client_class
1506
          | require_client_classes
1507
          | user_context
1508
          | comment
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
          | unknown_map_entry
          ;

pool_entry: POOL {
    ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
    ElementPtr pool(new StringElement($4, ctx.loc2pos(@4)));
    ctx.stack_.back()->set("pool", pool);
    ctx.leave();
};

1520 1521 1522
user_context: USER_CONTEXT {
    ctx.enter(ctx.NO_KEYWORD);
} COLON map_value {
Francis Dupont's avatar
Francis Dupont committed
1523 1524 1525
    ElementPtr parent = ctx.stack_.back();
    ElementPtr user_context = $4;
    ConstElementPtr old = parent->get("user-context");
Francis Dupont's avatar
Francis Dupont committed
1526 1527

    // Handle already existing user context
Francis Dupont's avatar
Francis Dupont committed
1528
    if (old) {
Francis Dupont's avatar
Francis Dupont committed
1529
        // Check if it was a comment or a duplicate
Francis Dupont's avatar
Francis Dupont committed
1530 1531 1532 1533 1534 1535
        if ((old->size() != 1) || !old->contains("comment")) {
            std::stringstream msg;
            msg << "duplicate user-context entries (previous at "
                << old->getPosition().str() << ")";
            error(@1, msg.str());
        }
Francis Dupont's avatar
Francis Dupont committed
1536
        // Merge the comment
Francis Dupont's avatar
Francis Dupont committed
1537 1538
        user_context->set("comment", old->get("comment"));
    }
Francis Dupont's avatar
Francis Dupont committed
1539 1540

    // Set the user context
Francis Dupont's avatar
Francis Dupont committed
1541
    parent->set("user-context", user_context);
1542 1543 1544 1545 1546
    ctx.leave();
};

comment: COMMENT {
    ctx.enter(ctx.NO_KEYWORD);
Francis Dupont's avatar
Francis Dupont committed
1547 1548
} COLON STRING {
    ElementPtr parent = ctx.stack_.back();
Francis Dupont's avatar
Francis Dupont committed
1549 1550 1551
    ElementPtr user_context(new MapElement(ctx.loc2pos(@1)));
    ElementPtr comment(new StringElement($4, ctx.loc2pos(@4)));
    user_context->set("comment", comment);
Francis Dupont's avatar
Francis Dupont committed
1552 1553

    // Handle already existing user context
Francis Dupont's avatar
Francis Dupont committed
1554 1555
    ConstElementPtr old = parent->get("user-context");
    if (old) {
Francis Dupont's avatar
Francis Dupont committed
1556
        // Check for duplicate comment
Francis Dupont's avatar
Francis Dupont committed
1557
        if (old->contains("comment")) {
Francis Dupont's avatar
Francis Dupont committed
1558 1559 1560 1561 1562 1563
            std::stringstream msg;
            msg << "duplicate user-context/comment entries (previous at "
                << old->getPosition().str() << ")";
            error(@1, msg.str());
        }
        // Merge the user context in the comment
Francis Dupont's avatar
Francis Dupont committed
1564
        merge(user_context, old);
Francis Dupont's avatar
Francis Dupont committed
1565
    }
Francis Dupont's avatar
Francis Dupont committed
1566 1567 1568

    // Set the user context
    parent->set("user-context", user_context);