dhcp6_parser.yy 45 KB

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