dhcp4_lexer.ll 47.1 KB
Newer Older
1
/* Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

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

%{ /* -*- C++ -*- */
#include <cerrno>
#include <climits>
#include <cstdlib>
#include <string>
#include <dhcp4/parser_context.h>
#include <asiolink/io_address.h>
#include <boost/lexical_cast.hpp>
#include <exceptions/exceptions.h>

// Work around an incompatibility in flex (at least versions
// 2.5.31 through 2.5.33): it generates code that does
// not conform to C89.  See Debian bug 333231
// <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>.
# undef yywrap
# define yywrap() 1

namespace {

bool start_token_flag = false;

isc::dhcp::Parser4Context::ParserType start_token_value;
unsigned int comment_start_line = 0;

};

// To avoid the call to exit... oops!
#define YY_FATAL_ERROR(msg) isc::dhcp::Parser4Context::fatal(msg)
%}

/* noyywrap disables automatic rewinding for the next file to parse. Since we
   always parse only a single string, there's no need to do any wraps. And
   using yywrap requires linking with -lfl, which provides the default yywrap
   implementation that always returns 1 anyway. */
%option noyywrap

/* nounput simplifies the lexer, by removing support for putting a character
   back into the input stream. We never use such capability anyway. */
%option nounput

/* batch means that we'll never use the generated lexer interactively. */
%option batch

/* avoid to get static global variables to remain with C++. */
/* in last resort %option reentrant */

/* Enables debug mode. To see the debug messages, one needs to also set
   yy_flex_debug to 1, then the debug messages will be printed on stderr. */
%option debug

/* I have no idea what this option does, except it was specified in the bison
   examples and Postgres folks added it to remove gcc 4.3 warnings. Let's
   be on the safe side and keep it. */
%option noinput

%x COMMENT
%x DIR_ENTER DIR_INCLUDE DIR_EXIT

/* These are not token expressions yet, just convenience expressions that
   can be used during actual token definitions. Note some can match
   incorrect inputs (e.g., IP addresses) which must be checked. */
int   \-?[0-9]+
blank [ \t\r]

UnicodeEscapeSequence           u[0-9A-Fa-f]{4}
JSONEscapeCharacter             ["\\/bfnrt]
JSONEscapeSequence              {JSONEscapeCharacter}|{UnicodeEscapeSequence}
JSONStandardCharacter           [^\x00-\x1f"\\]
JSONStringCharacter             {JSONStandardCharacter}|\\{JSONEscapeSequence}
JSONString                      \"{JSONStringCharacter}*\"

/* for errors */

BadUnicodeEscapeSequence        u[0-9A-Fa-f]{0,3}[^0-9A-Fa-f]
BadJSONEscapeSequence           [^"\\/bfnrtu]|{BadUnicodeEscapeSequence}
ControlCharacter                [\x00-\x1f]
ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}

%{
// This code run each time a pattern is matched. It updates the location
// by moving it ahead by yyleng bytes. yyleng specifies the length of the
// currently matched token.
#define YY_USER_ACTION  driver.loc_.columns(yyleng);
%}

%%

%{
    // This part of the code is copied over to the verbatim to the top
    // of the generated yylex function. Explanation:
    // http://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html

    // Code run each time yylex is called.
    driver.loc_.step();

    if (start_token_flag) {
        start_token_flag = false;
        switch (start_token_value) {
        case Parser4Context::PARSER_JSON:
        default:
            return isc::dhcp::Dhcp4Parser::make_TOPLEVEL_JSON(driver.loc_);
        case Parser4Context::PARSER_DHCP4:
            return isc::dhcp::Dhcp4Parser::make_TOPLEVEL_DHCP4(driver.loc_);
        case Parser4Context::SUBPARSER_DHCP4:
            return isc::dhcp::Dhcp4Parser::make_SUB_DHCP4(driver.loc_);
        case Parser4Context::PARSER_INTERFACES:
            return isc::dhcp::Dhcp4Parser::make_SUB_INTERFACES4(driver.loc_);
        case Parser4Context::PARSER_SUBNET4:
            return isc::dhcp::Dhcp4Parser::make_SUB_SUBNET4(driver.loc_);
        case Parser4Context::PARSER_POOL4:
            return isc::dhcp::Dhcp4Parser::make_SUB_POOL4(driver.loc_);
        case Parser4Context::PARSER_HOST_RESERVATION:
            return isc::dhcp::Dhcp4Parser::make_SUB_RESERVATION(driver.loc_);
        case Parser4Context::PARSER_OPTION_DATA:
            return isc::dhcp::Dhcp4Parser::make_SUB_OPTION_DATA(driver.loc_);
        case Parser4Context::PARSER_HOOKS_LIBRARY:
            return isc::dhcp::Dhcp4Parser::make_SUB_HOOKS_LIBRARY(driver.loc_);
124
125
        case Parser4Context::PARSER_DHCP_DDNS:
            return isc::dhcp::Dhcp4Parser::make_SUB_DHCP_DDNS(driver.loc_);
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        }
    }
%}

#.* ;

"//"(.*) ;

"/*" {
  BEGIN(COMMENT);
  comment_start_line = driver.loc_.end.line;;
}

<COMMENT>"*/" BEGIN(INITIAL);
<COMMENT>. ;
<COMMENT><<EOF>> {
    isc_throw(Dhcp4ParseError, "Comment not closed. (/* in line " << comment_start_line);
}

"<?" BEGIN(DIR_ENTER);
<DIR_ENTER>"include" BEGIN(DIR_INCLUDE);
<DIR_INCLUDE>\"([^\"\n])+\" {
    // Include directive.

    // Extract the filename.
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);

    driver.includeFile(tmp);
}
<DIR_ENTER,DIR_INCLUDE,DIR_EXIT><<EOF>> {
    isc_throw(Dhcp4ParseError, "Directive not closed.");
}
<DIR_EXIT>"?>" BEGIN(INITIAL);


<*>{blank}+   {
    // Ok, we found a with space. Let's ignore it and update loc variable.
    driver.loc_.step();
}

<*>[\n]+      {
    // Newline found. Let's update the location and continue.
    driver.loc_.lines(yyleng);
    driver.loc_.step();
}


174
\"Dhcp4\" {
175
176
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONFIG:
177
        return isc::dhcp::Dhcp4Parser::make_DHCP4(driver.loc_);
178
    default:
179
        return isc::dhcp::Dhcp4Parser::make_STRING("Dhcp4", driver.loc_);
180
181
182
183
184
185
186
187
188
189
190
191
    }
}

\"interfaces-config\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return  isc::dhcp::Dhcp4Parser::make_INTERFACES_CONFIG(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("interfaces-config", driver.loc_);
    }
}

192
193
194
195
196
197
198
199
200
\"dhcp-socket-type\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::INTERFACES_CONFIG:
        return  isc::dhcp::Dhcp4Parser::make_DHCP_SOCKET_TYPE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("dhcp-socket-type", driver.loc_);
    }
}

Tomek Mrugalski's avatar
Tomek Mrugalski committed
201
202
\"raw\" {
    switch(driver.ctx_) {
203
204
    case isc::dhcp::Parser4Context::DHCP_SOCKET_TYPE:
        return  isc::dhcp::Dhcp4Parser::make_RAW(driver.loc_);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
205
206
207
208
209
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("raw", driver.loc_);
    }
}

210
211
212
213
214
215
216
217
218
219
\"udp\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_SOCKET_TYPE:
    case isc::dhcp::Parser4Context::NCR_PROTOCOL:
        return  isc::dhcp::Dhcp4Parser::make_UDP(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("udp", driver.loc_);
    }
}

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
\"interfaces\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::INTERFACES_CONFIG:
        return  isc::dhcp::Dhcp4Parser::make_INTERFACES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("interfaces", driver.loc_);
    }
}

\"lease-database\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_LEASE_DATABASE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("lease-database", driver.loc_);
    }
}

\"hosts-database\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_HOSTS_DATABASE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("hosts-database", driver.loc_);
    }
}

\"readonly\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_READONLY(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("readonly", driver.loc_);
    }
}

\"type\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
    case isc::dhcp::Parser4Context::OPTION_DEF:
        return isc::dhcp::Dhcp4Parser::make_TYPE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("type", driver.loc_);
    }
}

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
\"memfile\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DATABASE_TYPE:
        return isc::dhcp::Dhcp4Parser::make_MEMFILE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("memfile", driver.loc_);
    }
}

\"mysql\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DATABASE_TYPE:
        return isc::dhcp::Dhcp4Parser::make_MYSQL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("mysql", driver.loc_);
    }
}

\"postgresql\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DATABASE_TYPE:
        return isc::dhcp::Dhcp4Parser::make_POSTGRESQL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("postgresql", driver.loc_);
    }
}

294
295
296
297
298
299
300
301
302
\"cql\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DATABASE_TYPE:
        return isc::dhcp::Dhcp4Parser::make_CQL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("cql", driver.loc_);
    }
}

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
\"user\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_USER(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("user", driver.loc_);
    }
}

\"password\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_PASSWORD(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("password", driver.loc_);
    }
}

\"host\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_HOST(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("host", driver.loc_);
    }
}

Francis Dupont's avatar
Francis Dupont committed
333
334
335
336
337
338
339
340
341
342
\"port\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_PORT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("port", driver.loc_);
    }
}

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
\"persist\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_PERSIST(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("persist", driver.loc_);
    }
}

\"lfc-interval\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_LFC_INTERVAL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("lfc-interval", driver.loc_);
    }
}

363
364
365
366
367
368
369
370
371
372
\"connect-timeout\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_CONNECT_TIMEOUT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("connect-timeout", driver.loc_);
    }
}

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
\"keyspace\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_KEYSPACE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("keyspace", driver.loc_);
    }
}

\"contact-points\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
        return isc::dhcp::Dhcp4Parser::make_CONTACT_POINTS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("contact-points", driver.loc_);
    }
}

393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
\"valid-lifetime\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_VALID_LIFETIME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("valid-lifetime", driver.loc_);
    }
}

\"renew-timer\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_RENEW_TIMER(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("renew-timer", driver.loc_);
    }
}

\"rebind-timer\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_REBIND_TIMER(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("rebind-timer", driver.loc_);
    }
}

\"decline-probation-period\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_DECLINE_PROBATION_PERIOD(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("decline-probation-period", driver.loc_);
    }
}

\"subnet4\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_SUBNET4(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("subnet4", driver.loc_);
    }
}

\"option-def\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_OPTION_DEF(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("option-def", driver.loc_);
    }
}

\"option-data\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
    case isc::dhcp::Parser4Context::SUBNET4:
    case isc::dhcp::Parser4Context::POOLS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
    case isc::dhcp::Parser4Context::CLIENT_CLASS:
        return isc::dhcp::Dhcp4Parser::make_OPTION_DATA(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("option-data", driver.loc_);
    }
}

\"name\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LEASE_DATABASE:
    case isc::dhcp::Parser4Context::HOSTS_DATABASE:
    case isc::dhcp::Parser4Context::OPTION_DEF:
    case isc::dhcp::Parser4Context::OPTION_DATA:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
    case isc::dhcp::Parser4Context::CLIENT_CLASS:
    case isc::dhcp::Parser4Context::LOGGERS:
        return isc::dhcp::Dhcp4Parser::make_NAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("name", driver.loc_);
    }
}

\"data\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DATA:
        return isc::dhcp::Dhcp4Parser::make_DATA(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("data", driver.loc_);
    }
}

\"pools\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_POOLS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("pools", driver.loc_);
    }
}

\"pool\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::POOLS:
        return isc::dhcp::Dhcp4Parser::make_POOL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("pool", driver.loc_);
    }
}

506
507
508
509
510
511
512
513
514
\"user-context\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::POOLS:
        return isc::dhcp::Dhcp4Parser::make_USER_CONTEXT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("user-context", driver.loc_);
    }
}

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
\"subnet\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_SUBNET(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("subnet", driver.loc_);
    }
}

\"interface\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_INTERFACE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("interface", driver.loc_);
    }
}

\"interface-id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_INTERFACE_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("interface-id", driver.loc_);
    }
}

\"id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("id", driver.loc_);
    }
}

\"rapid-commit\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_RAPID_COMMIT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("rapid-commit", driver.loc_);
    }
}

\"reservation-mode\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_RESERVATION_MODE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("reservation-mode", driver.loc_);
    }
}

\"code\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DEF:
    case isc::dhcp::Parser4Context::OPTION_DATA:
        return isc::dhcp::Dhcp4Parser::make_CODE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("code", driver.loc_);
    }
}

\"host-reservation-identifiers\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_HOST_RESERVATION_IDENTIFIERS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("host-reservation-identifiers", driver.loc_);
    }
}

\"Logging\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONFIG:
        return isc::dhcp::Dhcp4Parser::make_LOGGING(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("Logging", driver.loc_);
    }
}

\"loggers\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LOGGING:
        return isc::dhcp::Dhcp4Parser::make_LOGGERS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("loggers", driver.loc_);
    }
}

\"output_options\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LOGGERS:
        return isc::dhcp::Dhcp4Parser::make_OUTPUT_OPTIONS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("output_options", driver.loc_);
    }
}

\"output\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OUTPUT_OPTIONS:
        return isc::dhcp::Dhcp4Parser::make_OUTPUT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("output", driver.loc_);
    }
}

\"debuglevel\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LOGGERS:
        return isc::dhcp::Dhcp4Parser::make_DEBUGLEVEL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("debuglevel", driver.loc_);
    }
}

\"severity\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::LOGGERS:
        return isc::dhcp::Dhcp4Parser::make_SEVERITY(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("severity", driver.loc_);
    }
}

\"client-classes\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_CLIENT_CLASSES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("client-classes", driver.loc_);
    }
}

\"client-class\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
        return isc::dhcp::Dhcp4Parser::make_CLIENT_CLASS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("client-class", driver.loc_);
    }
}

\"test\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
    case isc::dhcp::Parser4Context::CLIENT_CLASS:
        return isc::dhcp::Dhcp4Parser::make_TEST(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("test", driver.loc_);
    }
}

\"reservations\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_RESERVATIONS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("reservations", driver.loc_);
    }
}

\"duid\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_DUID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("duid", driver.loc_);
    }
}

\"hw-address\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_HW_ADDRESS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("hw-address", driver.loc_);
    }
}

\"client-id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_CLIENT_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("client-id", driver.loc_);
    }
}

\"circuit-id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_CIRCUIT_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("circuit-id", driver.loc_);
    }
}

721
722
723
724
725
726
727
728
729
730
\"flex-id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS:
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_FLEX_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("flex-id", driver.loc_);
    }
}

731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
\"hostname\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::RESERVATIONS:
        return isc::dhcp::Dhcp4Parser::make_HOSTNAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("hostname", driver.loc_);
    }
}

\"space\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DEF:
    case isc::dhcp::Parser4Context::OPTION_DATA:
        return isc::dhcp::Dhcp4Parser::make_SPACE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("space", driver.loc_);
    }
}

\"csv-format\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DATA:
        return isc::dhcp::Dhcp4Parser::make_CSV_FORMAT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("csv-format", driver.loc_);
    }
}

\"record-types\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DEF:
        return isc::dhcp::Dhcp4Parser::make_RECORD_TYPES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("record-types", driver.loc_);
    }
}

\"encapsulate\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DEF:
        return isc::dhcp::Dhcp4Parser::make_ENCAPSULATE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("encapsulate", driver.loc_);
    }
}

\"array\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::OPTION_DEF:
        return isc::dhcp::Dhcp4Parser::make_ARRAY(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("array", driver.loc_);
    }
}

\"relay\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_RELAY(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("relay", driver.loc_);
    }
}

\"ip-address\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::RELAY:
    case isc::dhcp::Parser4Context::RESERVATIONS:
    return isc::dhcp::Dhcp4Parser::make_IP_ADDRESS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("ip-address", driver.loc_);
    }
}

\"hooks-libraries\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_HOOKS_LIBRARIES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("hooks-libraries", driver.loc_);
    }
}


\"parameters\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOOKS_LIBRARIES:
        return isc::dhcp::Dhcp4Parser::make_PARAMETERS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("parameters", driver.loc_);
    }
}

\"library\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::HOOKS_LIBRARIES:
        return isc::dhcp::Dhcp4Parser::make_LIBRARY(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("library", driver.loc_);
    }
}

\"expired-leases-processing\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_EXPIRED_LEASES_PROCESSING(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("expired-leases-processing", driver.loc_);
    }
}

Francis Dupont's avatar
Francis Dupont committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
\"reclaim-timer-wait-time\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_RECLAIM_TIMER_WAIT_TIME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("reclaim-timer-wait-time", driver.loc_);
    }
}

\"flush-reclaimed-timer-wait-time\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_FLUSH_RECLAIMED_TIMER_WAIT_TIME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("flush-reclaimed-timer-wait-time", driver.loc_);
    }
}

\"hold-reclaimed-time\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_HOLD_RECLAIMED_TIME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("hold-reclaimed-time", driver.loc_);
    }
}

\"max-reclaim-leases\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_MAX_RECLAIM_LEASES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("max-reclaim-leases", driver.loc_);
    }
}

\"max-reclaim-time\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_MAX_RECLAIM_TIME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("max-reclaim-time", driver.loc_);
    }
}

\"unwarned-reclaim-cycles\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING:
        return isc::dhcp::Dhcp4Parser::make_UNWARNED_RECLAIM_CYCLES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("unwarned-reclaim-cycles", driver.loc_);
    }
}

896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
\"dhcp4o6-port\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_DHCP4O6_PORT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("dhcp4o6-port", driver.loc_);
    }
}

\"control-socket\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_CONTROL_SOCKET(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("control-socket", driver.loc_);
    }
}

\"socket-type\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONTROL_SOCKET:
        return isc::dhcp::Dhcp4Parser::make_SOCKET_TYPE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("socket-type", driver.loc_);
    }
}

\"socket-name\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONTROL_SOCKET:
        return isc::dhcp::Dhcp4Parser::make_SOCKET_NAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("socket-name", driver.loc_);
    }
}

\"dhcp-ddns\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP4:
        return isc::dhcp::Dhcp4Parser::make_DHCP_DDNS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("dhcp-ddns", driver.loc_);
    }
}

941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
\"enable-updates\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_ENABLE_UPDATES(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("enable-updates", driver.loc_);
    }
}

\"qualifying-suffix\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_QUALIFYING_SUFFIX(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("qualifying-suffix", driver.loc_);
    }
}

\"server-ip\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_SERVER_IP(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("server-ip", driver.loc_);
    }
}

\"server-port\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_SERVER_PORT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("server-port", driver.loc_);
    }
}

\"sender-ip\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_SENDER_IP(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("sender-ip", driver.loc_);
    }
}

\"sender-port\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_SENDER_PORT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("sender-port", driver.loc_);
    }
}

\"max-queue-size\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_MAX_QUEUE_SIZE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("max-queue-size", driver.loc_);
    }
}

\"ncr-protocol\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_NCR_PROTOCOL(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("ncr-protocol", driver.loc_);
    }
}

\"ncr-format\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_NCR_FORMAT(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("ncr-format", driver.loc_);
    }
}

\"always-include-fqdn\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_ALWAYS_INCLUDE_FQDN(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("always-include-fqdn", driver.loc_);
    }
}

\"override-no-update\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_OVERRIDE_NO_UPDATE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("override-no-update", driver.loc_);
    }
}

\"override-client-update\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_OVERRIDE_CLIENT_UPDATE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("override-client-update", driver.loc_);
    }
}

\"replace-client-name\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_REPLACE_CLIENT_NAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("replace-client-name", driver.loc_);
    }
}

\"generated-prefix\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::DHCP_DDNS:
        return isc::dhcp::Dhcp4Parser::make_GENERATED_PREFIX(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("generated-prefix", driver.loc_);
    }
}

(?i:\"UDP\") {
    /* dhcp-ddns value keywords are case insensitive */
1069
1070
    if (driver.ctx_ == isc::dhcp::Parser4Context::NCR_PROTOCOL) {
         return isc::dhcp::Dhcp4Parser::make_UDP(driver.loc_);
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"TCP\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::NCR_PROTOCOL) {
        return isc::dhcp::Dhcp4Parser::make_TCP(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"JSON\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::NCR_FORMAT) {
        return isc::dhcp::Dhcp4Parser::make_JSON(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"when-present\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_WHEN_PRESENT(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"true\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_WHEN_PRESENT(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"never\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_NEVER(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"false\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_NEVER(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"always\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_ALWAYS(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

(?i:\"when-not-present\") {
    /* dhcp-ddns value keywords are case insensitive */
    if (driver.ctx_ == isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME) {
        return isc::dhcp::Dhcp4Parser::make_WHEN_NOT_PRESENT(driver.loc_);
    }
    std::string tmp(yytext+1);
    tmp.resize(tmp.size() - 1);
    return isc::dhcp::Dhcp4Parser::make_STRING(tmp, driver.loc_);
}

1157
\"Dhcp6\"  {
1158
1159
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONFIG:
1160
        return isc::dhcp::Dhcp4Parser::make_DHCP6(driver.loc_);
1161
    default:
1162
        return isc::dhcp::Dhcp4Parser::make_STRING("Dhcp6", driver.loc_);
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
    }
}

\"DhcpDdns\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::CONFIG:
        return isc::dhcp::Dhcp4Parser::make_DHCPDDNS(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("DhcpDdns", driver.loc_);
    }
}

\"4o6-interface\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_SUBNET_4O6_INTERFACE(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("4o6-interface", driver.loc_);
    }
}

1184
1185
1186
1187
1188
1189
1190
1191
1192
\"4o6-interface-id\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_SUBNET_4O6_INTERFACE_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("4o6-interface-id", driver.loc_);
    }
}

1193
1194
1195
1196
1197
\"4o6-subnet\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_SUBNET_4O6_SUBNET(driver.loc_);
    default:
1198
        return isc::dhcp::Dhcp4Parser::make_STRING("4o6-subnet", driver.loc_);
1199
1200
1201
    }
}

1202
1203
\"echo-client-id\" {
    switch(driver.ctx_) {
1204
    case isc::dhcp::Parser4Context::DHCP4:
1205
1206
1207
1208
1209
1210
1211
1212
1213
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_ECHO_CLIENT_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("echo-client-id", driver.loc_);
    }
}

\"match-client-id\" {
    switch(driver.ctx_) {
1214
    case isc::dhcp::Parser4Context::DHCP4:
1215
1216
1217
1218
1219
1220
1221
1222
1223
    case isc::dhcp::Parser4Context::SUBNET4:
        return isc::dhcp::Dhcp4Parser::make_MATCH_CLIENT_ID(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("match-client-id", driver.loc_);
    }
}

\"next-server\" {
    switch(driver.ctx_) {
1224
    case isc::dhcp::Parser4Context::DHCP4:
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
    case isc::dhcp::Parser4Context::SUBNET4:
    case isc::dhcp::Parser4Context::RESERVATIONS:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
        return isc::dhcp::Dhcp4Parser::make_NEXT_SERVER(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("next-server", driver.loc_);
    }
}

\"server-hostname\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
    case isc::dhcp::Parser4Context::RESERVATIONS:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
        return isc::dhcp::Dhcp4Parser::make_SERVER_HOSTNAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("server-hostname", driver.loc_);
    }
}

\"boot-file-name\" {
    switch(driver.ctx_) {
    case isc::dhcp::Parser4Context::SUBNET4:
    case isc::dhcp::Parser4Context::RESERVATIONS:
    case isc::dhcp::Parser4Context::CLIENT_CLASSES:
        return isc::dhcp::Dhcp4Parser::make_BOOT_FILE_NAME(driver.loc_);
    default:
        return isc::dhcp::Dhcp4Parser::make_STRING("boot-file-name", driver.loc_);
    }
}


1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267

{JSONString} {
    // A string has been matched. It contains the actual string and single quotes.
    // We need to get those quotes out of the way and just use its content, e.g.
    // for 'foo' we should get foo
    std::string raw(yytext+1);
    size_t len = raw.size() - 1;
    raw.resize(len);
    std::string decoded;
    decoded.reserve(len);
    for (size_t pos = 0; pos < len; ++pos) {
1268
        int b = 0;
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
        char c = raw[pos];
        switch (c) {
        case '"':
            // impossible condition
            driver.error(driver.loc_, "Bad quote in \"" + raw + "\"");
        case '\\':
            ++pos;
            if (pos >= len) {
                // impossible condition
                driver.error(driver.loc_, "Overflow escape in \"" + raw + "\"");
            }
            c = raw[pos];
            switch (c) {
            case '"':
            case '\\':
            case '/':
                decoded.push_back(c);
                break;
            case 'b':
                decoded.push_back('\b');
                break;
            case 'f':
                decoded.push_back('\f');
                break;
            case 'n':
                decoded.push_back('\n');
                break;
            case 'r':
                decoded.push_back('\r');
                break;
            case 't':
                decoded.push_back('\t');
                break;
            case 'u':
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
                // support only \u0000 to \u00ff
                ++pos;
                if (pos + 4 > len) {
                    // impossible condition
                    driver.error(driver.loc_,
                                 "Overflow unicode escape in \"" + raw + "\"");
                }
                if ((raw[pos] != '0') || (raw[pos + 1] != '0')) {
                    driver.error(driver.loc_, "Unsupported unicode escape in \"" + raw + "\"");
                }
                pos += 2;
                c = raw[pos];
                if ((c >= '0') && (c <= '9')) {
                    b = (c - '0') << 4;
                } else if ((c >= 'A') && (c <= 'F')) {
                    b = (c - 'A' + 10) << 4;
                } else if ((c >= 'a') && (c <= 'f')) {
                    b = (c - 'a' + 10) << 4;
                } else {
                    // impossible condition
                    driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
                }
                pos++;
                c = raw[pos];
                if ((c >= '0') && (c <= '9')) {
                    b |= c - '0';
                } else if ((c >= 'A') && (c <= 'F')) {
                    b |= c - 'A' + 10;
                } else if ((c >= 'a') && (c <= 'f')) {
                    b |= c - 'a' + 10;
                } else {
                    // impossible condition
                    driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
                }
                decoded.push_back(static_cast<char>(b & 0xff));
                break;
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
            default:
                // impossible condition
                driver.error(driver.loc_, "Bad escape in \"" + raw + "\"");
            }
            break;
        default:
            if ((c >= 0) && (c < 0x20)) {
                // impossible condition
                driver.error(driver.loc_, "Invalid control in \"" + raw + "\"");
            }
            decoded.push_back(c);
        }
    }

    return isc::dhcp::Dhcp4Parser::make_STRING(decoded, driver.loc_);
}

\"{JSONStringCharacter}*{ControlCharacter}{ControlCharacterFill}*\" {
    // Bad string with a forbidden control character inside
    driver.error(driver.loc_, "Invalid control in " + std::string(yytext));
}

\"{JSONStringCharacter}*\\{BadJSONEscapeSequence}[^\x00-\x1f"]*\" {
    // Bad string with a bad escape inside
    driver.error(driver.loc_, "Bad escape in " + std::string(yytext));
}

\"{JSONStringCharacter}*\\\" {
    // Bad string with an open escape at the end
    driver.error(driver.loc_, "Overflow escape in " + std::string(yytext));
}

"["    { return isc::dhcp::Dhcp4Parser::make_LSQUARE_BRACKET(driver.loc_); }
"]"    { return isc::dhcp::Dhcp4Parser::make_RSQUARE_BRACKET(driver.loc_); }
"{"    { return isc::dhcp::Dhcp4Parser::make_LCURLY_BRACKET(driver.loc_); }
"}"    { return isc::dhcp::Dhcp4Parser::make_RCURLY_BRACKET(driver.loc_); }
","    { return isc::dhcp::Dhcp4Parser::make_COMMA(driver.loc_); }
":"    { return isc::dhcp::Dhcp4Parser::make_COLON(driver.loc_); }

{int} {
    // An integer was found.
    std::string tmp(yytext);
    int64_t integer = 0;
    try {
        // In substring we want to use negative values (e.g. -1).
        // In enterprise-id we need to use values up to 0xffffffff.
        // To cover both of those use cases, we need at least
        // int64_t.
        integer = boost::lexical_cast<int64_t>(tmp);
    } catch (const boost::bad_lexical_cast &) {
        driver.error(driver.loc_, "Failed to convert " + tmp + " to an integer.");
    }

    // The parser needs the string form as double conversion is no lossless
    return isc::dhcp::Dhcp4Parser::make_INTEGER(integer, driver.loc_);
}

[-+]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)? {
    // A floating point was found.
    std::string tmp(yytext);
    double fp = 0.0;
    try {
        fp = boost::lexical_cast<double>(tmp);
    } catch (const boost::bad_lexical_cast &) {
        driver.error(driver.loc_, "Failed to convert " + tmp + " to a floating point.");
    }

    return isc::dhcp::Dhcp4Parser::make_FLOAT(fp, driver.loc_);
}

true|false {
    string tmp(yytext);
    return isc::dhcp::Dhcp4Parser::make_BOOLEAN(tmp == "true", driver.loc_);
}

null {
   return isc::dhcp::Dhcp4Parser::make_NULL_TYPE(driver.loc_);
}

1418
1419
1420
1421
1422
1423
(?i:true) driver.error (driver.loc_, "JSON true reserved keyword is lower case only");

(?i:false) driver.error (driver.loc_, "JSON false reserved keyword is lower case only");

(?i:null) driver.error (driver.loc_, "JSON null reserved keyword is lower case only");

1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
<*>.   driver.error (driver.loc_, "Invalid character: " + std::string(yytext));

<<EOF>> {
    if (driver.states_.empty()) {
        return isc::dhcp::Dhcp4Parser::make_END(driver.loc_);
    }
    driver.loc_ = driver.locs_.back();
    driver.locs_.pop_back();
    driver.file_ = driver.files_.back();
    driver.files_.pop_back();
    if (driver.sfile_) {
        fclose(driver.sfile_);
        driver.sfile_ = 0;
    }
    if (!driver.sfiles_.empty()) {
        driver.sfile_ = driver.sfiles_.back();
        driver.sfiles_.pop_back();
    }
    parser4__delete_buffer(YY_CURRENT_BUFFER);
    parser4__switch_to_buffer(driver.states_.back());
    driver.states_.pop_back();

    BEGIN(DIR_EXIT);
}

%%

using namespace isc::dhcp;

void
Parser4Context::scanStringBegin(const std::string& str, ParserType parser_type)
{
    start_token_flag = true;
    start_token_value = parser_type;

    file_ = "<string>";
    sfile_ = 0;
    loc_.initialize(&file_);
    yy_flex_debug = trace_scanning_;
    YY_BUFFER_STATE buffer;
1464
    buffer = parser4__scan_bytes(str.c_str(), str.size());
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
    if (!buffer) {
        fatal("cannot scan string");
        // fatal() throws an exception so this can't be reached
    }
}

void
Parser4Context::scanFileBegin(FILE * f,
                              const std::string& filename,
                              ParserType parser_type)
{
    start_token_flag = true;
    start_token_value = parser_type;

    file_ = filename;
    sfile_ = f;
    loc_.initialize(&file_);
    yy_flex_debug = trace_scanning_;
    YY_BUFFER_STATE buffer;

Francis Dupont's avatar
Francis Dupont committed
1485
    // See dhcp4_lexer.cc header for available definitions
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
    buffer = parser4__create_buffer(f, 65536 /*buffer size*/);
    if (!buffer) {
        fatal("cannot scan file " + filename);
    }
    parser4__switch_to_buffer(buffer);
}

void
Parser4Context::scanEnd() {
    if (sfile_)
        fclose(sfile_);
    sfile_ = 0;
    static_cast<void>(parser4_lex_destroy());
    // Close files
    while (!sfiles_.empty()) {
        FILE* f = sfiles_.back();
        if (f) {
            fclose(f);
        }
        sfiles_.pop_back();
    }
    // Delete states
    while (!states_.empty()) {
        parser4__delete_buffer(states_.back());
        states_.pop_back();
    }
}

void
Parser4Context::includeFile(const std::string& filename) {
    if (states_.size() > 10) {
        fatal("Too many nested include.");
    }

    FILE* f = fopen(filename.c_str(), "r");
    if (!f) {
        fatal("Can't open include file " + filename);
    }
    if (sfile_) {
        sfiles_.push_back(sfile_);
    }
    sfile_ = f;
    states_.push_back(YY_CURRENT_BUFFER);
    YY_BUFFER_STATE buffer;
    buffer = parser4__create_buffer(f, 65536 /*buffer size*/);
    if (!buffer) {
        fatal( "Can't scan include file " + filename);
    }
    parser4__switch_to_buffer(buffer);
    files_.push_back(file_);
    file_ = filename;
    locs_.push_back(loc_);
    loc_.initialize(&file_);

    BEGIN(INITIAL);
}

namespace {
/// To avoid unused function error
class Dummy {
    // cppcheck-suppress unusedPrivateFunction
    void dummy() { yy_fatal_error("Fix me: how to disable its definition?"); }
};
}