dhcp4_parser.yy 43 KB

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