dhcp4_parser.yy 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. /* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
  2. This Source Code Form is subject to the terms of the Mozilla Public
  3. License, v. 2.0. If a copy of the MPL was not distributed with this
  4. file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. %skeleton "lalr1.cc" /* -*- C++ -*- */
  6. %require "3.0.0"
  7. %defines
  8. %define parser_class_name {Dhcp4Parser}
  9. %define api.prefix {parser4_}
  10. %define api.token.constructor
  11. %define api.value.type variant
  12. %define api.namespace {isc::dhcp}
  13. %define parse.assert
  14. %code requires
  15. {
  16. #include <string>
  17. #include <cc/data.h>
  18. #include <dhcp/option.h>
  19. #include <boost/lexical_cast.hpp>
  20. #include <dhcp4/parser_context_decl.h>
  21. using namespace isc::dhcp;
  22. using namespace isc::data;
  23. using namespace std;
  24. }
  25. // The parsing context.
  26. %param { isc::dhcp::Parser4Context& ctx }
  27. %locations
  28. %define parse.trace
  29. %define parse.error verbose
  30. %code
  31. {
  32. #include <dhcp4/parser_context.h>
  33. }
  34. %define api.token.prefix {TOKEN_}
  35. // Tokens in an order which makes sense and related to the intented use.
  36. // Actual regexps for tokens are defined in dhcp4_lexer.ll.
  37. %token
  38. END 0 "end of file"
  39. COMMA ","
  40. COLON ":"
  41. LSQUARE_BRACKET "["
  42. RSQUARE_BRACKET "]"
  43. LCURLY_BRACKET "{"
  44. RCURLY_BRACKET "}"
  45. NULL_TYPE "null"
  46. DHCP4 "Dhcp4"
  47. INTERFACES_CONFIG "interfaces-config"
  48. INTERFACES "interfaces"
  49. ECHO_CLIENT_ID "echo-client-id"
  50. MATCH_CLIENT_ID "match-client-id"
  51. NEXT_SERVER "next-server"
  52. SERVER_HOSTNAME "server-hostname"
  53. BOOT_FILE_NAME "boot-file-name"
  54. LEASE_DATABASE "lease-database"
  55. HOSTS_DATABASE "hosts-database"
  56. TYPE "type"
  57. USER "user"
  58. PASSWORD "password"
  59. HOST "host"
  60. PERSIST "persist"
  61. LFC_INTERVAL "lfc-interval"
  62. READONLY "readonly"
  63. VALID_LIFETIME "valid-lifetime"
  64. RENEW_TIMER "renew-timer"
  65. REBIND_TIMER "rebind-timer"
  66. DECLINE_PROBATION_PERIOD "decline-probation-period"
  67. SUBNET4 "subnet4"
  68. SUBNET_4O6_INTERFACE "4o6-interface"
  69. SUBNET_4O6_INTERFACE_ID "4o6-interface-id"
  70. SUBNET_4O6_SUBNET "4o6-subnet"
  71. OPTION_DEF "option-def"
  72. OPTION_DATA "option-data"
  73. NAME "name"
  74. DATA "data"
  75. CODE "code"
  76. SPACE "space"
  77. CSV_FORMAT "csv-format"
  78. RECORD_TYPES "record-types"
  79. ENCAPSULATE "encapsulate"
  80. ARRAY "array"
  81. POOLS "pools"
  82. POOL "pool"
  83. SUBNET "subnet"
  84. INTERFACE "interface"
  85. INTERFACE_ID "interface-id"
  86. ID "id"
  87. RAPID_COMMIT "rapid-commit"
  88. RESERVATION_MODE "reservation-mode"
  89. HOST_RESERVATION_IDENTIFIERS "host-reservation-identifiers"
  90. CLIENT_CLASSES "client-classes"
  91. TEST "test"
  92. CLIENT_CLASS "client-class"
  93. RESERVATIONS "reservations"
  94. DUID "duid"
  95. HW_ADDRESS "hw-address"
  96. CIRCUIT_ID "circuit-id"
  97. CLIENT_ID "client-id"
  98. HOSTNAME "hostname"
  99. RELAY "relay"
  100. IP_ADDRESS "ip-address"
  101. HOOKS_LIBRARIES "hooks-libraries"
  102. LIBRARY "library"
  103. PARAMETERS "parameters"
  104. EXPIRED_LEASES_PROCESSING "expired-leases-processing"
  105. SERVER_ID "server-id"
  106. IDENTIFIER "identifier"
  107. HTYPE "htype"
  108. TIME "time"
  109. ENTERPRISE_ID "enterprise-id"
  110. DHCP4O6_PORT "dhcp4o6-port"
  111. VERSION "version"
  112. CONTROL_SOCKET "control-socket"
  113. SOCKET_TYPE "socket-type"
  114. SOCKET_NAME "socket-name"
  115. DHCP_DDNS "dhcp-ddns"
  116. /// @todo: Implement proper parsing for those parameters in Dhcp4/dhcp-ddns/*.
  117. /// This should be part of the #5043 ticket. Listing the keywords here for
  118. /// completeness.
  119. // These are tokens defined in Dhcp4/dhcp-ddns/*
  120. // They're not
  121. // ENABLE_UPDATES "enable-updates"
  122. // SERVER_IP "server-ip"
  123. // SENDER_IP "sender-ip"
  124. // SENDER_PORT "sender-port"
  125. // MAX_QUEUE_SIZE "max-queue-size"
  126. // NCR_PROTOCOL "ncr-protocol"
  127. // NCR_FORMAT "ncr-format"
  128. // ALWAYS_INCLUDE_FQDN "always-include-fqdn"
  129. // OVERRDIDE_NO_UPDATE "override-no-update"
  130. // OVERRDIDE_CLIENT_UPDATE "override-client-update"
  131. // REPLACE_CLIENT_NAME "replace-client-name"
  132. // GENERATED_PREFIX "generated-prefix"
  133. // QUALIFYING_SUFFIX "qualifying-suffix"
  134. LOGGING "Logging"
  135. LOGGERS "loggers"
  136. OUTPUT_OPTIONS "output_options"
  137. OUTPUT "output"
  138. DEBUGLEVEL "debuglevel"
  139. SEVERITY "severity"
  140. DHCP6 "Dhcp6"
  141. DHCPDDNS "DhcpDdns"
  142. // Not real tokens, just a way to signal what the parser is expected to
  143. // parse.
  144. TOPLEVEL_JSON
  145. TOPLEVEL_DHCP4
  146. SUB_DHCP4
  147. SUB_INTERFACES4
  148. SUB_SUBNET4
  149. SUB_POOL4
  150. SUB_RESERVATION
  151. SUB_OPTION_DEF
  152. SUB_OPTION_DATA
  153. SUB_HOOKS_LIBRARY
  154. ;
  155. %token <std::string> STRING "constant string"
  156. %token <int64_t> INTEGER "integer"
  157. %token <double> FLOAT "floating point"
  158. %token <bool> BOOLEAN "boolean"
  159. %type <ElementPtr> value
  160. %type <ElementPtr> version_value
  161. %printer { yyoutput << $$; } <*>;
  162. %%
  163. // The whole grammar starts with a map, because the config file
  164. // constists of Dhcp, Logger and DhcpDdns entries in one big { }.
  165. // We made the same for subparsers at the exception of the JSON value.
  166. %start start;
  167. start: TOPLEVEL_JSON { ctx.ctx_ = ctx.NO_KEYWORD; } sub_json
  168. | TOPLEVEL_DHCP4 { ctx.ctx_ = ctx.CONFIG; } syntax_map
  169. | SUB_DHCP4 { ctx.ctx_ = ctx.DHCP4; } sub_dhcp4
  170. | SUB_INTERFACES4 { ctx.ctx_ = ctx.INTERFACES_CONFIG; } sub_interfaces4
  171. | SUB_SUBNET4 { ctx.ctx_ = ctx.SUBNET4; } sub_subnet4
  172. | SUB_POOL4 { ctx.ctx_ = ctx.POOLS; } sub_pool4
  173. | SUB_RESERVATION { ctx.ctx_ = ctx.RESERVATIONS; } sub_reservation
  174. | SUB_OPTION_DEF { ctx.ctx_ = ctx.OPTION_DEF; } sub_option_def
  175. | SUB_OPTION_DATA { ctx.ctx_ = ctx.OPTION_DATA; } sub_option_data
  176. | SUB_HOOKS_LIBRARY { ctx.ctx_ = ctx.HOOKS_LIBRARIES; } sub_hooks_library
  177. ;
  178. // ---- generic JSON parser ---------------------------------
  179. // Note that ctx_ is NO_KEYWORD here
  180. // Values rule
  181. value: INTEGER { $$ = ElementPtr(new IntElement($1, ctx.loc2pos(@1))); }
  182. | FLOAT { $$ = ElementPtr(new DoubleElement($1, ctx.loc2pos(@1))); }
  183. | BOOLEAN { $$ = ElementPtr(new BoolElement($1, ctx.loc2pos(@1))); }
  184. | STRING { $$ = ElementPtr(new StringElement($1, ctx.loc2pos(@1))); }
  185. | NULL_TYPE { $$ = ElementPtr(new NullElement(ctx.loc2pos(@1))); }
  186. | map2 { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
  187. | list_generic { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
  188. ;
  189. sub_json: value {
  190. // Push back the JSON value on the stack
  191. ctx.stack_.push_back($1);
  192. };
  193. map2: LCURLY_BRACKET {
  194. // This code is executed when we're about to start parsing
  195. // the content of the map
  196. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  197. ctx.stack_.push_back(m);
  198. } map_content RCURLY_BRACKET {
  199. // map parsing completed. If we ever want to do any wrap up
  200. // (maybe some sanity checking), this would be the best place
  201. // for it.
  202. };
  203. // Assignments rule
  204. map_content: %empty // empty map
  205. | not_empty_map
  206. ;
  207. not_empty_map: STRING COLON value {
  208. // map containing a single entry
  209. ctx.stack_.back()->set($1, $3);
  210. }
  211. | not_empty_map COMMA STRING COLON value {
  212. // map consisting of a shorter map followed by
  213. // comma and string:value
  214. ctx.stack_.back()->set($3, $5);
  215. }
  216. ;
  217. list_generic: LSQUARE_BRACKET {
  218. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  219. ctx.stack_.push_back(l);
  220. } list_content RSQUARE_BRACKET {
  221. // list parsing complete. Put any sanity checking here
  222. };
  223. // This one is used in syntax parser.
  224. list2: LSQUARE_BRACKET {
  225. // List parsing about to start
  226. } list_content RSQUARE_BRACKET {
  227. // list parsing complete. Put any sanity checking here
  228. //ctx.stack_.pop_back();
  229. };
  230. list_content: %empty // Empty list
  231. | not_empty_list
  232. ;
  233. not_empty_list: value {
  234. // List consisting of a single element.
  235. ctx.stack_.back()->add($1);
  236. }
  237. | not_empty_list COMMA value {
  238. // List ending with , and a value.
  239. ctx.stack_.back()->add($3);
  240. }
  241. ;
  242. // ---- generic JSON parser ends here ----------------------------------
  243. // ---- syntax checking parser starts here -----------------------------
  244. // Unknown keyword in a map
  245. unknown_map_entry: STRING COLON {
  246. const std::string& where = ctx.contextName();
  247. const std::string& keyword = $1;
  248. error(@1,
  249. "got unexpected keyword \"" + keyword + "\" in " + where + " map.");
  250. };
  251. // This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
  252. // objects.
  253. syntax_map: LCURLY_BRACKET {
  254. // This code is executed when we're about to start parsing
  255. // the content of the map
  256. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  257. ctx.stack_.push_back(m);
  258. } global_objects RCURLY_BRACKET {
  259. // map parsing completed. If we ever want to do any wrap up
  260. // (maybe some sanity checking), this would be the best place
  261. // for it.
  262. };
  263. // This represents top-level entries: Dhcp6, Dhcp4, DhcpDdns, Logging
  264. global_objects: global_object
  265. | global_objects COMMA global_object
  266. ;
  267. // This represents a single top level entry, e.g. Dhcp6 or DhcpDdns.
  268. global_object: dhcp4_object
  269. | logging_object
  270. | dhcp6_json_object
  271. | dhcpddns_json_object
  272. | unknown_map_entry
  273. ;
  274. dhcp4_object: DHCP4 {
  275. // This code is executed when we're about to start parsing
  276. // the content of the map
  277. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  278. ctx.stack_.back()->set("Dhcp4", m);
  279. ctx.stack_.push_back(m);
  280. ctx.enter(ctx.DHCP4);
  281. } COLON LCURLY_BRACKET global_params RCURLY_BRACKET {
  282. // map parsing completed. If we ever want to do any wrap up
  283. // (maybe some sanity checking), this would be the best place
  284. // for it.
  285. ctx.stack_.pop_back();
  286. ctx.leave();
  287. };
  288. // subparser: similar to the corresponding rule but without parent
  289. // so the stack is empty at the rule entry.
  290. sub_dhcp4: LCURLY_BRACKET {
  291. // Parse the Dhcp6 map
  292. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  293. ctx.stack_.push_back(m);
  294. } global_params RCURLY_BRACKET {
  295. // parsing completed
  296. };
  297. global_params: global_param
  298. | global_params COMMA global_param
  299. ;
  300. // These are the parameters that are allowed in the top-level for
  301. // Dhcp4.
  302. global_param: valid_lifetime
  303. | renew_timer
  304. | rebind_timer
  305. | decline_probation_period
  306. | subnet4_list
  307. | interfaces_config
  308. | lease_database
  309. | hosts_database
  310. | host_reservation_identifiers
  311. | client_classes
  312. | option_def_list
  313. | option_data_list
  314. | hooks_libraries
  315. | expired_leases_processing
  316. | server_id
  317. | dhcp4o6_port
  318. | version
  319. | control_socket
  320. | dhcp_ddns
  321. | echo_client_id
  322. | match_client_id
  323. | next_server
  324. | unknown_map_entry
  325. ;
  326. valid_lifetime: VALID_LIFETIME COLON INTEGER {
  327. ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
  328. ctx.stack_.back()->set("valid-lifetime", prf);
  329. };
  330. renew_timer: RENEW_TIMER COLON INTEGER {
  331. ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
  332. ctx.stack_.back()->set("renew-timer", prf);
  333. };
  334. rebind_timer: REBIND_TIMER COLON INTEGER {
  335. ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
  336. ctx.stack_.back()->set("rebind-timer", prf);
  337. };
  338. decline_probation_period: DECLINE_PROBATION_PERIOD COLON INTEGER {
  339. ElementPtr dpp(new IntElement($3, ctx.loc2pos(@3)));
  340. ctx.stack_.back()->set("decline-probation-period", dpp);
  341. };
  342. echo_client_id: ECHO_CLIENT_ID COLON BOOLEAN {
  343. ElementPtr echo(new BoolElement($3, ctx.loc2pos(@1)));
  344. ctx.stack_.back()->set("echo-client-id", echo);
  345. };
  346. match_client_id: MATCH_CLIENT_ID COLON BOOLEAN {
  347. ElementPtr match(new BoolElement($3, ctx.loc2pos(@1)));
  348. ctx.stack_.back()->set("match-client-id", match);
  349. };
  350. interfaces_config: INTERFACES_CONFIG {
  351. ElementPtr i(new MapElement(ctx.loc2pos(@1)));
  352. ctx.stack_.back()->set("interfaces-config", i);
  353. ctx.stack_.push_back(i);
  354. ctx.enter(ctx.INTERFACES_CONFIG);
  355. } COLON LCURLY_BRACKET interface_config_map RCURLY_BRACKET {
  356. ctx.stack_.pop_back();
  357. ctx.leave();
  358. };
  359. sub_interfaces4: LCURLY_BRACKET {
  360. // Parse the interfaces-config map
  361. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  362. ctx.stack_.push_back(m);
  363. } interface_config_map RCURLY_BRACKET {
  364. // parsing completed
  365. };
  366. interface_config_map: INTERFACES {
  367. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  368. ctx.stack_.back()->set("interfaces", l);
  369. ctx.stack_.push_back(l);
  370. ctx.enter(ctx.NO_KEYWORD);
  371. } COLON list2 {
  372. ctx.stack_.pop_back();
  373. ctx.leave();
  374. };
  375. lease_database: LEASE_DATABASE {
  376. ElementPtr i(new MapElement(ctx.loc2pos(@1)));
  377. ctx.stack_.back()->set("lease-database", i);
  378. ctx.stack_.push_back(i);
  379. ctx.enter(ctx.LEASE_DATABASE);
  380. } COLON LCURLY_BRACKET database_map_params RCURLY_BRACKET {
  381. ctx.stack_.pop_back();
  382. ctx.leave();
  383. };
  384. hosts_database: HOSTS_DATABASE {
  385. ElementPtr i(new MapElement(ctx.loc2pos(@1)));
  386. ctx.stack_.back()->set("hosts-database", i);
  387. ctx.stack_.push_back(i);
  388. ctx.enter(ctx.HOSTS_DATABASE);
  389. } COLON LCURLY_BRACKET database_map_params RCURLY_BRACKET {
  390. ctx.stack_.pop_back();
  391. ctx.leave();
  392. };
  393. database_map_params: database_map_param
  394. | database_map_params COMMA database_map_param
  395. ;
  396. database_map_param: type
  397. | user
  398. | password
  399. | host
  400. | name
  401. | persist
  402. | lfc_interval
  403. | readonly
  404. | unknown_map_entry
  405. ;
  406. type: TYPE {
  407. ctx.enter(ctx.NO_KEYWORD);
  408. } COLON STRING {
  409. ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
  410. ctx.stack_.back()->set("type", prf);
  411. ctx.leave();
  412. };
  413. user: USER {
  414. ctx.enter(ctx.NO_KEYWORD);
  415. } COLON STRING {
  416. ElementPtr user(new StringElement($4, ctx.loc2pos(@4)));
  417. ctx.stack_.back()->set("user", user);
  418. ctx.leave();
  419. };
  420. password: PASSWORD {
  421. ctx.enter(ctx.NO_KEYWORD);
  422. } COLON STRING {
  423. ElementPtr pwd(new StringElement($4, ctx.loc2pos(@4)));
  424. ctx.stack_.back()->set("password", pwd);
  425. ctx.leave();
  426. };
  427. host: HOST {
  428. ctx.enter(ctx.NO_KEYWORD);
  429. } COLON STRING {
  430. ElementPtr h(new StringElement($4, ctx.loc2pos(@4)));
  431. ctx.stack_.back()->set("host", h);
  432. ctx.leave();
  433. };
  434. name: NAME {
  435. ctx.enter(ctx.NO_KEYWORD);
  436. } COLON STRING {
  437. ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
  438. ctx.stack_.back()->set("name", name);
  439. ctx.leave();
  440. };
  441. persist: PERSIST COLON BOOLEAN {
  442. ElementPtr n(new BoolElement($3, ctx.loc2pos(@3)));
  443. ctx.stack_.back()->set("persist", n);
  444. };
  445. lfc_interval: LFC_INTERVAL COLON INTEGER {
  446. ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
  447. ctx.stack_.back()->set("lfc-interval", n);
  448. };
  449. readonly: READONLY COLON BOOLEAN {
  450. ElementPtr n(new BoolElement($3, ctx.loc2pos(@3)));
  451. ctx.stack_.back()->set("readonly", n);
  452. };
  453. duid_id : DUID {
  454. ElementPtr duid(new StringElement("duid", ctx.loc2pos(@1)));
  455. ctx.stack_.back()->add(duid);
  456. };
  457. host_reservation_identifiers: HOST_RESERVATION_IDENTIFIERS {
  458. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  459. ctx.stack_.back()->set("host-reservation-identifiers", l);
  460. ctx.stack_.push_back(l);
  461. ctx.enter(ctx.HOST_RESERVATION_IDENTIFIERS);
  462. } COLON LSQUARE_BRACKET host_reservation_identifiers_list RSQUARE_BRACKET {
  463. ctx.stack_.pop_back();
  464. ctx.leave();
  465. };
  466. host_reservation_identifiers_list: host_reservation_identifier
  467. | host_reservation_identifiers_list COMMA host_reservation_identifier
  468. ;
  469. host_reservation_identifier: duid_id
  470. | hw_address_id
  471. | circuit_id
  472. | client_id
  473. ;
  474. hw_address_id : HW_ADDRESS {
  475. ElementPtr hwaddr(new StringElement("hw-address", ctx.loc2pos(@1)));
  476. ctx.stack_.back()->add(hwaddr);
  477. };
  478. circuit_id : CIRCUIT_ID {
  479. ElementPtr circuit(new StringElement("circuit-id", ctx.loc2pos(@1)));
  480. ctx.stack_.back()->add(circuit);
  481. };
  482. client_id : CLIENT_ID {
  483. ElementPtr client(new StringElement("client-id", ctx.loc2pos(@1)));
  484. ctx.stack_.back()->add(client);
  485. };
  486. hooks_libraries: HOOKS_LIBRARIES {
  487. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  488. ctx.stack_.back()->set("hooks-libraries", l);
  489. ctx.stack_.push_back(l);
  490. ctx.enter(ctx.HOOKS_LIBRARIES);
  491. } COLON LSQUARE_BRACKET hooks_libraries_list RSQUARE_BRACKET {
  492. ctx.stack_.pop_back();
  493. ctx.leave();
  494. };
  495. hooks_libraries_list: %empty
  496. | not_empty_hooks_libraries_list
  497. ;
  498. not_empty_hooks_libraries_list: hooks_library
  499. | not_empty_hooks_libraries_list COMMA hooks_library
  500. ;
  501. hooks_library: LCURLY_BRACKET {
  502. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  503. ctx.stack_.back()->add(m);
  504. ctx.stack_.push_back(m);
  505. } hooks_params RCURLY_BRACKET {
  506. ctx.stack_.pop_back();
  507. };
  508. sub_hooks_library: LCURLY_BRACKET {
  509. // Parse the hooks-libraries list entry map
  510. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  511. ctx.stack_.push_back(m);
  512. } hooks_params RCURLY_BRACKET {
  513. // parsing completed
  514. };
  515. hooks_params: hooks_param
  516. | hooks_params COMMA hooks_param
  517. | unknown_map_entry
  518. ;
  519. hooks_param: library
  520. | parameters
  521. ;
  522. library: LIBRARY {
  523. ctx.enter(ctx.NO_KEYWORD);
  524. } COLON STRING {
  525. ElementPtr lib(new StringElement($4, ctx.loc2pos(@4)));
  526. ctx.stack_.back()->set("library", lib);
  527. ctx.leave();
  528. };
  529. parameters: PARAMETERS {
  530. ctx.enter(ctx.NO_KEYWORD);
  531. } COLON value {
  532. ctx.stack_.back()->set("parameters", $4);
  533. ctx.leave();
  534. };
  535. // --- expired-leases-processing ------------------------
  536. expired_leases_processing: EXPIRED_LEASES_PROCESSING {
  537. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  538. ctx.stack_.back()->set("expired-leases-processing", m);
  539. ctx.stack_.push_back(m);
  540. ctx.enter(ctx.NO_KEYWORD);
  541. } COLON LCURLY_BRACKET expired_leases_params RCURLY_BRACKET {
  542. ctx.stack_.pop_back();
  543. ctx.leave();
  544. };
  545. expired_leases_params: expired_leases_param
  546. | expired_leases_params COMMA expired_leases_param
  547. ;
  548. // This is a bit of a simplification. But it can also serve as an example.
  549. // Instead of explicitly listing all allowed expired leases parameters, we
  550. // simply say that all of them as integers.
  551. expired_leases_param: STRING COLON INTEGER {
  552. ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
  553. ctx.stack_.back()->set($1, value);
  554. };
  555. // --- subnet4 ------------------------------------------
  556. // This defines subnet4 as a list of maps.
  557. // "subnet4": [ ... ]
  558. subnet4_list: SUBNET4 {
  559. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  560. ctx.stack_.back()->set("subnet4", l);
  561. ctx.stack_.push_back(l);
  562. ctx.enter(ctx.SUBNET4);
  563. } COLON LSQUARE_BRACKET subnet4_list_content RSQUARE_BRACKET {
  564. ctx.stack_.pop_back();
  565. ctx.leave();
  566. };
  567. // This defines the ... in "subnet6": [ ... ]
  568. // It can either be empty (no subnets defined), have one subnet
  569. // or have multiple subnets separate by comma.
  570. subnet4_list_content: %empty
  571. | not_empty_subnet4_list
  572. ;
  573. not_empty_subnet4_list: subnet4
  574. | not_empty_subnet4_list COMMA subnet4
  575. ;
  576. // --- Subnet definitions -------------------------------
  577. // This defines a single subnet, i.e. a single map with
  578. // subnet6 array.
  579. subnet4: LCURLY_BRACKET {
  580. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  581. ctx.stack_.back()->add(m);
  582. ctx.stack_.push_back(m);
  583. } subnet4_params RCURLY_BRACKET {
  584. // Once we reached this place, the subnet parsing is now complete.
  585. // If we want to, we can implement default values here.
  586. // In particular we can do things like this:
  587. // if (!ctx.stack_.back()->get("interface")) {
  588. // ctx.stack_.back()->set("interface", StringElement("loopback"));
  589. // }
  590. //
  591. // We can also stack up one level (Dhcp6) and copy over whatever
  592. // global parameters we want to:
  593. // if (!ctx.stack_.back()->get("renew-timer")) {
  594. // ElementPtr renew = ctx_stack_[...].get("renew-timer");
  595. // if (renew) {
  596. // ctx.stack_.back()->set("renew-timer", renew);
  597. // }
  598. // }
  599. ctx.stack_.pop_back();
  600. };
  601. sub_subnet4: LCURLY_BRACKET {
  602. // Parse the subnet6 list entry map
  603. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  604. ctx.stack_.push_back(m);
  605. } subnet4_params RCURLY_BRACKET {
  606. // parsing completed
  607. };
  608. // This defines that subnet can have one or more parameters.
  609. subnet4_params: subnet4_param
  610. | subnet4_params COMMA subnet4_param
  611. ;
  612. // This defines a list of allowed parameters for each subnet.
  613. subnet4_param: valid_lifetime
  614. | renew_timer
  615. | rebind_timer
  616. | option_data_list
  617. | pools_list
  618. | subnet
  619. | interface
  620. | interface_id
  621. | id
  622. | rapid_commit
  623. | client_class
  624. | reservations
  625. | reservation_mode
  626. | relay
  627. | match_client_id
  628. | next_server
  629. | subnet_4o6_interface
  630. | subnet_4o6_interface_id
  631. | subnet_4o6_subnet
  632. | unknown_map_entry
  633. ;
  634. subnet: SUBNET {
  635. ctx.enter(ctx.NO_KEYWORD);
  636. } COLON STRING {
  637. ElementPtr subnet(new StringElement($4, ctx.loc2pos(@4)));
  638. ctx.stack_.back()->set("subnet", subnet);
  639. ctx.leave();
  640. };
  641. subnet_4o6_interface: SUBNET_4O6_INTERFACE {
  642. ctx.enter(ctx.NO_KEYWORD);
  643. } COLON STRING {
  644. ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
  645. ctx.stack_.back()->set("4o6-interface", iface);
  646. ctx.leave();
  647. };
  648. subnet_4o6_interface_id: SUBNET_4O6_INTERFACE_ID {
  649. ctx.enter(ctx.NO_KEYWORD);
  650. } COLON STRING {
  651. ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
  652. ctx.stack_.back()->set("4o6-interface-id", iface);
  653. ctx.leave();
  654. };
  655. subnet_4o6_subnet: SUBNET_4O6_SUBNET {
  656. ctx.enter(ctx.NO_KEYWORD);
  657. } COLON STRING {
  658. ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
  659. ctx.stack_.back()->set("4o6-subnet", iface);
  660. ctx.leave();
  661. };
  662. interface: INTERFACE {
  663. ctx.enter(ctx.NO_KEYWORD);
  664. } COLON STRING {
  665. ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
  666. ctx.stack_.back()->set("interface", iface);
  667. ctx.leave();
  668. };
  669. interface_id: INTERFACE_ID {
  670. ctx.enter(ctx.NO_KEYWORD);
  671. } COLON STRING {
  672. ElementPtr iface(new StringElement($4, ctx.loc2pos(@4)));
  673. ctx.stack_.back()->set("interface-id", iface);
  674. ctx.leave();
  675. };
  676. client_class: CLIENT_CLASS {
  677. ctx.enter(ctx.CLIENT_CLASS);
  678. } COLON STRING {
  679. ElementPtr cls(new StringElement($4, ctx.loc2pos(@4)));
  680. ctx.stack_.back()->set("client-class", cls);
  681. ctx.leave();
  682. };
  683. reservation_mode: RESERVATION_MODE {
  684. ctx.enter(ctx.NO_KEYWORD);
  685. } COLON STRING {
  686. ElementPtr rm(new StringElement($4, ctx.loc2pos(@4)));
  687. ctx.stack_.back()->set("reservation-mode", rm);
  688. ctx.leave();
  689. };
  690. id: ID COLON INTEGER {
  691. ElementPtr id(new IntElement($3, ctx.loc2pos(@3)));
  692. ctx.stack_.back()->set("id", id);
  693. };
  694. rapid_commit: RAPID_COMMIT COLON BOOLEAN {
  695. ElementPtr rc(new BoolElement($3, ctx.loc2pos(@3)));
  696. ctx.stack_.back()->set("rapid-commit", rc);
  697. };
  698. // ---- option-def --------------------------
  699. // This defines the "option-def": [ ... ] entry that may appear
  700. // at a global option.
  701. option_def_list: OPTION_DEF {
  702. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  703. ctx.stack_.back()->set("option-def", l);
  704. ctx.stack_.push_back(l);
  705. ctx.enter(ctx.OPTION_DEF);
  706. } COLON LSQUARE_BRACKET option_def_list_content RSQUARE_BRACKET {
  707. ctx.stack_.pop_back();
  708. ctx.leave();
  709. };
  710. // This defines the content of option-def. It may be empty,
  711. // have one entry or multiple entries separated by comma.
  712. option_def_list_content: %empty
  713. | not_empty_option_def_list
  714. ;
  715. not_empty_option_def_list: option_def_entry
  716. | not_empty_option_def_list COMMA option_def_entry
  717. ;
  718. // This defines the content of a single entry { ... } within
  719. // option-def list.
  720. option_def_entry: LCURLY_BRACKET {
  721. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  722. ctx.stack_.back()->add(m);
  723. ctx.stack_.push_back(m);
  724. } option_def_params RCURLY_BRACKET {
  725. ctx.stack_.pop_back();
  726. };
  727. // This defines the top level scope when the parser is told to parse a single
  728. // option definition. It's almost exactly the same as option_def_entry, except
  729. // that it does leave its value on stack.
  730. sub_option_def: LCURLY_BRACKET {
  731. // Parse the option-def list entry map
  732. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  733. ctx.stack_.push_back(m);
  734. } option_def_params RCURLY_BRACKET {
  735. // parsing completed
  736. };
  737. // This defines parameters specified inside the map that itself
  738. // is an entry in option-def list.
  739. option_def_params: %empty
  740. | not_empty_option_def_params
  741. ;
  742. not_empty_option_def_params: option_def_param
  743. | not_empty_option_def_params COMMA option_def_param
  744. ;
  745. option_def_param: option_def_name
  746. | option_def_code
  747. | option_def_type
  748. | option_def_record_types
  749. | option_def_space
  750. | option_def_encapsulate
  751. | option_def_array
  752. | unknown_map_entry
  753. ;
  754. option_def_name: name;
  755. code: CODE COLON INTEGER {
  756. ElementPtr code(new IntElement($3, ctx.loc2pos(@3)));
  757. ctx.stack_.back()->set("code", code);
  758. };
  759. option_def_code: code;
  760. option_def_type: type;
  761. option_def_record_types: RECORD_TYPES {
  762. ctx.enter(ctx.NO_KEYWORD);
  763. } COLON STRING {
  764. ElementPtr rtypes(new StringElement($4, ctx.loc2pos(@4)));
  765. ctx.stack_.back()->set("record-types", rtypes);
  766. ctx.leave();
  767. };
  768. space: SPACE {
  769. ctx.enter(ctx.NO_KEYWORD);
  770. } COLON STRING {
  771. ElementPtr space(new StringElement($4, ctx.loc2pos(@4)));
  772. ctx.stack_.back()->set("space", space);
  773. ctx.leave();
  774. };
  775. option_def_space: space;
  776. option_def_encapsulate: ENCAPSULATE {
  777. ctx.enter(ctx.NO_KEYWORD);
  778. } COLON STRING {
  779. ElementPtr encap(new StringElement($4, ctx.loc2pos(@4)));
  780. ctx.stack_.back()->set("encapsulate", encap);
  781. ctx.leave();
  782. };
  783. option_def_array: ARRAY COLON BOOLEAN {
  784. ElementPtr array(new BoolElement($3, ctx.loc2pos(@3)));
  785. ctx.stack_.back()->set("array", array);
  786. };
  787. // ---- option-data --------------------------
  788. // This defines the "option-data": [ ... ] entry that may appear
  789. // in several places, but most notably in subnet4 entries.
  790. option_data_list: OPTION_DATA {
  791. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  792. ctx.stack_.back()->set("option-data", l);
  793. ctx.stack_.push_back(l);
  794. ctx.enter(ctx.OPTION_DATA);
  795. } COLON LSQUARE_BRACKET option_data_list_content RSQUARE_BRACKET {
  796. ctx.stack_.pop_back();
  797. ctx.leave();
  798. };
  799. // This defines the content of option-data. It may be empty,
  800. // have one entry or multiple entries separated by comma.
  801. option_data_list_content: %empty
  802. | not_empty_option_data_list
  803. ;
  804. // This defines the content of option-data list. It can either
  805. // be a single value or multiple entries separated by comma.
  806. not_empty_option_data_list: option_data_entry
  807. | not_empty_option_data_list COMMA option_data_entry
  808. ;
  809. // This defines th content of a single entry { ... } within
  810. // option-data list.
  811. option_data_entry: LCURLY_BRACKET {
  812. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  813. ctx.stack_.back()->add(m);
  814. ctx.stack_.push_back(m);
  815. } option_data_params RCURLY_BRACKET {
  816. ctx.stack_.pop_back();
  817. };
  818. // This defines the top level scope when the parser is told to parse a single
  819. // option data. It's almost exactly the same as option_data_entry, except
  820. // that it does leave its value on stack.
  821. sub_option_data: LCURLY_BRACKET {
  822. // Parse the option-data list entry map
  823. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  824. ctx.stack_.push_back(m);
  825. } option_data_params RCURLY_BRACKET {
  826. // parsing completed
  827. };
  828. // This defines parameters specified inside the map that itself
  829. // is an entry in option-data list. It can either be empty
  830. // or have a non-empty list of parameters.
  831. option_data_params: %empty
  832. | not_empty_option_data_params
  833. ;
  834. // Those parameters can either be a single parameter or
  835. // a list of parameters separated by comma.
  836. not_empty_option_data_params: option_data_param
  837. | not_empty_option_data_params COMMA option_data_param
  838. ;
  839. // Each single option-data parameter can be one of the following
  840. // expressions.
  841. option_data_param: option_data_name
  842. | option_data_data
  843. | option_data_code
  844. | option_data_space
  845. | option_data_csv_format
  846. | unknown_map_entry
  847. ;
  848. option_data_name: name;
  849. option_data_data: DATA {
  850. ctx.enter(ctx.NO_KEYWORD);
  851. } COLON STRING {
  852. ElementPtr data(new StringElement($4, ctx.loc2pos(@4)));
  853. ctx.stack_.back()->set("data", data);
  854. ctx.leave();
  855. };
  856. option_data_code: code;
  857. option_data_space: space;
  858. option_data_csv_format: CSV_FORMAT COLON BOOLEAN {
  859. ElementPtr space(new BoolElement($3, ctx.loc2pos(@3)));
  860. ctx.stack_.back()->set("csv-format", space);
  861. };
  862. // ---- pools ------------------------------------
  863. // This defines the "pools": [ ... ] entry that may appear in subnet4.
  864. pools_list: POOLS {
  865. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  866. ctx.stack_.back()->set("pools", l);
  867. ctx.stack_.push_back(l);
  868. ctx.enter(ctx.POOLS);
  869. } COLON LSQUARE_BRACKET pools_list_content RSQUARE_BRACKET {
  870. ctx.stack_.pop_back();
  871. ctx.leave();
  872. };
  873. // Pools may be empty, contain a single pool entry or multiple entries
  874. // separate by commas.
  875. pools_list_content: %empty
  876. | not_empty_pools_list
  877. ;
  878. not_empty_pools_list: pool_list_entry
  879. | not_empty_pools_list COMMA pool_list_entry
  880. ;
  881. pool_list_entry: LCURLY_BRACKET {
  882. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  883. ctx.stack_.back()->add(m);
  884. ctx.stack_.push_back(m);
  885. } pool_params RCURLY_BRACKET {
  886. ctx.stack_.pop_back();
  887. };
  888. sub_pool4: LCURLY_BRACKET {
  889. // Parse the pool list entry map
  890. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  891. ctx.stack_.push_back(m);
  892. } pool_params RCURLY_BRACKET {
  893. // parsing completed
  894. };
  895. pool_params: pool_param
  896. | pool_params COMMA pool_param
  897. ;
  898. pool_param: pool_entry
  899. | option_data_list
  900. | unknown_map_entry
  901. ;
  902. pool_entry: POOL {
  903. ctx.enter(ctx.NO_KEYWORD);
  904. } COLON STRING {
  905. ElementPtr pool(new StringElement($4, ctx.loc2pos(@4)));
  906. ctx.stack_.back()->set("pool", pool);
  907. ctx.leave();
  908. };
  909. // --- end of pools definition -------------------------------
  910. // --- reservations ------------------------------------------
  911. reservations: RESERVATIONS {
  912. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  913. ctx.stack_.back()->set("reservations", l);
  914. ctx.stack_.push_back(l);
  915. ctx.enter(ctx.RESERVATIONS);
  916. } COLON LSQUARE_BRACKET reservations_list RSQUARE_BRACKET {
  917. ctx.stack_.pop_back();
  918. ctx.leave();
  919. };
  920. reservations_list: %empty
  921. | not_empty_reservations_list
  922. ;
  923. not_empty_reservations_list: reservation
  924. | not_empty_reservations_list COMMA reservation
  925. ;
  926. reservation: LCURLY_BRACKET {
  927. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  928. ctx.stack_.back()->add(m);
  929. ctx.stack_.push_back(m);
  930. } reservation_params RCURLY_BRACKET {
  931. ctx.stack_.pop_back();
  932. };
  933. sub_reservation: LCURLY_BRACKET {
  934. // Parse the reservations list entry map
  935. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  936. ctx.stack_.push_back(m);
  937. } reservation_params RCURLY_BRACKET {
  938. // parsing completed
  939. };
  940. reservation_params: %empty
  941. | not_empty_reservation_params
  942. ;
  943. not_empty_reservation_params: reservation_param
  944. | not_empty_reservation_params COMMA reservation_param
  945. ;
  946. // @todo probably need to add mac-address as well here
  947. reservation_param: duid
  948. | reservation_client_classes
  949. | client_id_value
  950. | circuit_id_value
  951. | ip_address
  952. | hw_address
  953. | hostname
  954. | option_data_list
  955. | next_server
  956. | server_hostname
  957. | boot_file_name
  958. | unknown_map_entry
  959. ;
  960. next_server: NEXT_SERVER {
  961. ctx.enter(ctx.NO_KEYWORD);
  962. } COLON STRING {
  963. ElementPtr next_server(new StringElement($4, ctx.loc2pos(@1)));
  964. ctx.stack_.back()->set("next-server", next_server);
  965. ctx.leave();
  966. };
  967. server_hostname: SERVER_HOSTNAME {
  968. ctx.enter(ctx.NO_KEYWORD);
  969. } COLON STRING {
  970. ElementPtr srv(new StringElement($4, ctx.loc2pos(@1)));
  971. ctx.stack_.back()->set("server-hostname", srv);
  972. ctx.leave();
  973. };
  974. boot_file_name: BOOT_FILE_NAME {
  975. ctx.enter(ctx.NO_KEYWORD);
  976. } COLON STRING {
  977. ElementPtr bootfile(new StringElement($4, ctx.loc2pos(@1)));
  978. ctx.stack_.back()->set("boot-file-name", bootfile);
  979. ctx.leave();
  980. };
  981. ip_address: IP_ADDRESS {
  982. ctx.enter(ctx.NO_KEYWORD);
  983. } COLON STRING {
  984. ElementPtr addr(new StringElement($4, ctx.loc2pos(@1)));
  985. ctx.stack_.back()->set("ip-address", addr);
  986. ctx.leave();
  987. };
  988. duid: DUID {
  989. ctx.enter(ctx.NO_KEYWORD);
  990. } COLON STRING {
  991. ElementPtr d(new StringElement($4, ctx.loc2pos(@4)));
  992. ctx.stack_.back()->set("duid", d);
  993. ctx.leave();
  994. };
  995. hw_address: HW_ADDRESS {
  996. ctx.enter(ctx.NO_KEYWORD);
  997. } COLON STRING {
  998. ElementPtr hw(new StringElement($4, ctx.loc2pos(@4)));
  999. ctx.stack_.back()->set("hw-address", hw);
  1000. ctx.leave();
  1001. };
  1002. client_id_value: CLIENT_ID {
  1003. ctx.enter(ctx.NO_KEYWORD);
  1004. } COLON STRING {
  1005. ElementPtr hw(new StringElement($4, ctx.loc2pos(@4)));
  1006. ctx.stack_.back()->set("client-id", hw);
  1007. ctx.leave();
  1008. };
  1009. circuit_id_value: CIRCUIT_ID {
  1010. ctx.enter(ctx.NO_KEYWORD);
  1011. } COLON STRING {
  1012. ElementPtr hw(new StringElement($4, ctx.loc2pos(@4)));
  1013. ctx.stack_.back()->set("circuit-id", hw);
  1014. ctx.leave();
  1015. };
  1016. hostname: HOSTNAME {
  1017. ctx.enter(ctx.NO_KEYWORD);
  1018. } COLON STRING {
  1019. ElementPtr host(new StringElement($4, ctx.loc2pos(@4)));
  1020. ctx.stack_.back()->set("hostname", host);
  1021. ctx.leave();
  1022. };
  1023. reservation_client_classes: CLIENT_CLASSES {
  1024. ElementPtr c(new ListElement(ctx.loc2pos(@1)));
  1025. ctx.stack_.back()->set("client-classes", c);
  1026. ctx.stack_.push_back(c);
  1027. ctx.enter(ctx.NO_KEYWORD);
  1028. } COLON list2 {
  1029. ctx.stack_.pop_back();
  1030. ctx.leave();
  1031. };
  1032. // --- end of reservations definitions -----------------------
  1033. // --- relay -------------------------------------------------
  1034. relay: RELAY {
  1035. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1036. ctx.stack_.back()->set("relay", m);
  1037. ctx.stack_.push_back(m);
  1038. ctx.enter(ctx.RELAY);
  1039. } COLON LCURLY_BRACKET relay_map RCURLY_BRACKET {
  1040. ctx.stack_.pop_back();
  1041. ctx.leave();
  1042. };
  1043. relay_map: IP_ADDRESS {
  1044. ctx.enter(ctx.NO_KEYWORD);
  1045. } COLON STRING {
  1046. ElementPtr ip(new StringElement($4, ctx.loc2pos(@4)));
  1047. ctx.stack_.back()->set("ip-address", ip);
  1048. ctx.leave();
  1049. };
  1050. // --- end of relay definitions ------------------------------
  1051. // --- client classes ----------------------------------------
  1052. client_classes: CLIENT_CLASSES {
  1053. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  1054. ctx.stack_.back()->set("client-classes", l);
  1055. ctx.stack_.push_back(l);
  1056. ctx.enter(ctx.CLIENT_CLASSES);
  1057. } COLON LSQUARE_BRACKET client_classes_list RSQUARE_BRACKET {
  1058. ctx.stack_.pop_back();
  1059. ctx.leave();
  1060. };
  1061. client_classes_list: client_class
  1062. | client_classes_list COMMA client_class
  1063. ;
  1064. client_class: LCURLY_BRACKET {
  1065. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1066. ctx.stack_.back()->add(m);
  1067. ctx.stack_.push_back(m);
  1068. } client_class_params RCURLY_BRACKET {
  1069. ctx.stack_.pop_back();
  1070. };
  1071. client_class_params: %empty
  1072. | not_empty_client_class_params
  1073. ;
  1074. not_empty_client_class_params: client_class_param
  1075. | not_empty_client_class_params COMMA client_class_param
  1076. ;
  1077. client_class_param: client_class_name
  1078. | client_class_test
  1079. | option_data_list
  1080. | next_server
  1081. | server_hostname
  1082. | boot_file_name
  1083. | unknown_map_entry
  1084. ;
  1085. client_class_name: name;
  1086. client_class_test: TEST {
  1087. ctx.enter(ctx.NO_KEYWORD);
  1088. } COLON STRING {
  1089. ElementPtr test(new StringElement($4, ctx.loc2pos(@4)));
  1090. ctx.stack_.back()->set("test", test);
  1091. ctx.leave();
  1092. };
  1093. // --- end of client classes ---------------------------------
  1094. // --- server-id ---------------------------------------------
  1095. server_id: SERVER_ID {
  1096. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1097. ctx.stack_.back()->set("server-id", m);
  1098. ctx.stack_.push_back(m);
  1099. ctx.enter(ctx.SERVER_ID);
  1100. } COLON LCURLY_BRACKET server_id_params RCURLY_BRACKET {
  1101. ctx.stack_.pop_back();
  1102. ctx.leave();
  1103. };
  1104. server_id_params: server_id_param
  1105. | server_id_params COMMA server_id_param
  1106. ;
  1107. server_id_param: type
  1108. | identifier
  1109. | time
  1110. | htype
  1111. | enterprise_id
  1112. | persist
  1113. | unknown_map_entry
  1114. ;
  1115. htype: HTYPE COLON INTEGER {
  1116. ElementPtr htype(new IntElement($3, ctx.loc2pos(@3)));
  1117. ctx.stack_.back()->set("htype", htype);
  1118. };
  1119. identifier: IDENTIFIER {
  1120. ctx.enter(ctx.NO_KEYWORD);
  1121. } COLON STRING {
  1122. ElementPtr id(new StringElement($4, ctx.loc2pos(@4)));
  1123. ctx.stack_.back()->set("identifier", id);
  1124. ctx.leave();
  1125. };
  1126. time: TIME COLON INTEGER {
  1127. ElementPtr time(new IntElement($3, ctx.loc2pos(@3)));
  1128. ctx.stack_.back()->set("time", time);
  1129. };
  1130. enterprise_id: ENTERPRISE_ID COLON INTEGER {
  1131. ElementPtr time(new IntElement($3, ctx.loc2pos(@3)));
  1132. ctx.stack_.back()->set("enterprise-id", time);
  1133. };
  1134. // --- end of server-id --------------------------------------
  1135. dhcp4o6_port: DHCP4O6_PORT COLON INTEGER {
  1136. ElementPtr time(new IntElement($3, ctx.loc2pos(@3)));
  1137. ctx.stack_.back()->set("dhcp4o6-port", time);
  1138. };
  1139. // code says it is a string, unit test a number
  1140. version: VERSION {
  1141. ctx.enter(ctx.NO_KEYWORD);
  1142. } COLON version_value {
  1143. ctx.stack_.back()->set("version", $4);
  1144. ctx.leave();
  1145. };
  1146. version_value:
  1147. INTEGER { $$ = ElementPtr(new IntElement($1, ctx.loc2pos(@1))); }
  1148. | FLOAT { $$ = ElementPtr(new DoubleElement($1, ctx.loc2pos(@1))); }
  1149. | STRING { $$ = ElementPtr(new StringElement($1, ctx.loc2pos(@1))); }
  1150. ;
  1151. // --- control socket ----------------------------------------
  1152. control_socket: CONTROL_SOCKET {
  1153. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1154. ctx.stack_.back()->set("control-socket", m);
  1155. ctx.stack_.push_back(m);
  1156. ctx.enter(ctx.CONTROL_SOCKET);
  1157. } COLON LCURLY_BRACKET control_socket_params RCURLY_BRACKET {
  1158. ctx.stack_.pop_back();
  1159. ctx.leave();
  1160. };
  1161. control_socket_params: control_socket_param
  1162. | control_socket_params COMMA control_socket_param
  1163. ;
  1164. control_socket_param: socket_type
  1165. | socket_name
  1166. ;
  1167. socket_type: SOCKET_TYPE {
  1168. ctx.enter(ctx.NO_KEYWORD);
  1169. } COLON STRING {
  1170. ElementPtr stype(new StringElement($4, ctx.loc2pos(@4)));
  1171. ctx.stack_.back()->set("socket-type", stype);
  1172. ctx.leave();
  1173. };
  1174. socket_name: SOCKET_NAME {
  1175. ctx.enter(ctx.NO_KEYWORD);
  1176. } COLON STRING {
  1177. ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
  1178. ctx.stack_.back()->set("socket-name", name);
  1179. ctx.leave();
  1180. };
  1181. // --- dhcp ddns ---------------------------------------------
  1182. dhcp_ddns: DHCP_DDNS {
  1183. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1184. ctx.stack_.back()->set("dhcp-ddns", m);
  1185. ctx.stack_.push_back(m);
  1186. ctx.enter(ctx.NO_KEYWORD);
  1187. } COLON LCURLY_BRACKET not_empty_map RCURLY_BRACKET {
  1188. ctx.stack_.pop_back();
  1189. ctx.leave();
  1190. };
  1191. // JSON entries for Dhcp4 and DhcpDdns
  1192. dhcp6_json_object: DHCP6 {
  1193. ctx.enter(ctx.NO_KEYWORD);
  1194. } COLON value {
  1195. ctx.stack_.back()->set("Dhcp6", $4);
  1196. ctx.leave();
  1197. };
  1198. dhcpddns_json_object: DHCPDDNS {
  1199. ctx.enter(ctx.NO_KEYWORD);
  1200. } COLON value {
  1201. ctx.stack_.back()->set("DhcpDdns", $4);
  1202. ctx.leave();
  1203. };
  1204. // --- logging entry -----------------------------------------
  1205. // This defines the top level "Logging" object. It parses
  1206. // the following "Logging": { ... }. The ... is defined
  1207. // by logging_params
  1208. logging_object: LOGGING {
  1209. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1210. ctx.stack_.back()->set("Logging", m);
  1211. ctx.stack_.push_back(m);
  1212. ctx.enter(ctx.LOGGING);
  1213. } COLON LCURLY_BRACKET logging_params RCURLY_BRACKET {
  1214. ctx.stack_.pop_back();
  1215. ctx.leave();
  1216. };
  1217. // This defines the list of allowed parameters that may appear
  1218. // in the top-level Logging object. It can either be a single
  1219. // parameter or several parameters separated by commas.
  1220. logging_params: logging_param
  1221. | logging_params COMMA logging_param
  1222. ;
  1223. // There's currently only one parameter defined, which is "loggers".
  1224. logging_param: loggers;
  1225. // "loggers", the only parameter currently defined in "Logging" object,
  1226. // is "Loggers": [ ... ].
  1227. loggers: LOGGERS {
  1228. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  1229. ctx.stack_.back()->set("loggers", l);
  1230. ctx.stack_.push_back(l);
  1231. ctx.enter(ctx.LOGGERS);
  1232. } COLON LSQUARE_BRACKET loggers_entries RSQUARE_BRACKET {
  1233. ctx.stack_.pop_back();
  1234. ctx.leave();
  1235. };
  1236. // These are the parameters allowed in loggers: either one logger
  1237. // entry or multiple entries separate by commas.
  1238. loggers_entries: logger_entry
  1239. | loggers_entries COMMA logger_entry
  1240. ;
  1241. // This defines a single entry defined in loggers in Logging.
  1242. logger_entry: LCURLY_BRACKET {
  1243. ElementPtr l(new MapElement(ctx.loc2pos(@1)));
  1244. ctx.stack_.back()->add(l);
  1245. ctx.stack_.push_back(l);
  1246. } logger_params RCURLY_BRACKET {
  1247. ctx.stack_.pop_back();
  1248. };
  1249. logger_params: logger_param
  1250. | logger_params COMMA logger_param
  1251. ;
  1252. logger_param: name
  1253. | output_options_list
  1254. | debuglevel
  1255. | severity
  1256. | unknown_map_entry
  1257. ;
  1258. debuglevel: DEBUGLEVEL COLON INTEGER {
  1259. ElementPtr dl(new IntElement($3, ctx.loc2pos(@3)));
  1260. ctx.stack_.back()->set("debuglevel", dl);
  1261. };
  1262. severity: SEVERITY {
  1263. ctx.enter(ctx.NO_KEYWORD);
  1264. } COLON STRING {
  1265. ElementPtr sev(new StringElement($4, ctx.loc2pos(@4)));
  1266. ctx.stack_.back()->set("severity", sev);
  1267. ctx.leave();
  1268. };
  1269. output_options_list: OUTPUT_OPTIONS {
  1270. ElementPtr l(new ListElement(ctx.loc2pos(@1)));
  1271. ctx.stack_.back()->set("output_options", l);
  1272. ctx.stack_.push_back(l);
  1273. ctx.enter(ctx.OUTPUT_OPTIONS);
  1274. } COLON LSQUARE_BRACKET output_options_list_content RSQUARE_BRACKET {
  1275. ctx.stack_.pop_back();
  1276. ctx.leave();
  1277. };
  1278. output_options_list_content: output_entry
  1279. | output_options_list_content COMMA output_entry
  1280. ;
  1281. output_entry: LCURLY_BRACKET {
  1282. ElementPtr m(new MapElement(ctx.loc2pos(@1)));
  1283. ctx.stack_.back()->add(m);
  1284. ctx.stack_.push_back(m);
  1285. } output_params RCURLY_BRACKET {
  1286. ctx.stack_.pop_back();
  1287. };
  1288. output_params: output_param
  1289. | output_params COMMA output_param
  1290. ;
  1291. output_param: OUTPUT {
  1292. ctx.enter(ctx.NO_KEYWORD);
  1293. } COLON STRING {
  1294. ElementPtr sev(new StringElement($4, ctx.loc2pos(@4)));
  1295. ctx.stack_.back()->set("output", sev);
  1296. ctx.leave();
  1297. };
  1298. %%
  1299. void
  1300. isc::dhcp::Dhcp4Parser::error(const location_type& loc,
  1301. const std::string& what)
  1302. {
  1303. ctx.error(loc, what);
  1304. }