summaryrefslogtreecommitdiff
path: root/common/conflex.c
blob: 8ce024af5916c5b978289895f3b3ad35f3359dc2 (plain)
1
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
124
125
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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
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
294
295
296
297
298
299
300
301
302
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
506
507
508
509
510
511
512
513
514
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
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
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
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
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
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
1069
1070
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
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
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
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
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
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
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
1418
1419
1420
1421
1422
1423
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
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
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
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
/* conflex.c

   Lexical scanner for dhcpd config file... */

/*
 * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
 * Copyright (c) 1995-2003 by Internet Software Consortium
 *
 * 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/.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *   Internet Systems Consortium, Inc.
 *   950 Charter Street
 *   Redwood City, CA 94063
 *   <info@isc.org>
 *   https://www.isc.org/
 *
 */

#include "dhcpd.h"
#include <ctype.h>

static int get_char (struct parse *);
static void unget_char(struct parse *, int);
static void skip_to_eol (struct parse *);
static enum dhcp_token read_whitespace(int c, struct parse *cfile);
static enum dhcp_token read_string (struct parse *);
static enum dhcp_token read_number (int, struct parse *);
static enum dhcp_token read_num_or_name (int, struct parse *);
static enum dhcp_token intern (char *, enum dhcp_token);

isc_result_t new_parse (cfile, file, inbuf, buflen, name, eolp)
	struct parse **cfile;
	int file;
	char *inbuf;
	unsigned buflen;
	const char *name;
	int eolp;
{
	isc_result_t status = ISC_R_SUCCESS;
	struct parse *tmp;

	tmp = dmalloc(sizeof(struct parse), MDL);
	if (tmp == NULL) {
		return (ISC_R_NOMEMORY);
	}

	/*
	 * We don't need to initialize things to zero here, since 
	 * dmalloc() returns memory that is set to zero.
	 */
	tmp->tlname = name;
	tmp->lpos = tmp -> line = 1;
	tmp->cur_line = tmp->line1;
	tmp->prev_line = tmp->line2;
	tmp->token_line = tmp->cur_line;
	tmp->cur_line[0] = tmp->prev_line[0] = 0;
	tmp->file = file;
	tmp->eol_token = eolp;

	if (inbuf != NULL) {
		tmp->inbuf = inbuf;
		tmp->buflen = buflen;
		tmp->bufsiz = 0;
	} else {
		struct stat sb;

		if (fstat(file, &sb) < 0) {
			status = ISC_R_IOERROR;
			goto cleanup;
		}

		if (sb.st_size == 0)
			goto cleanup;

		tmp->bufsiz = tmp->buflen = (size_t) sb.st_size;
		tmp->inbuf = mmap(NULL, tmp->bufsiz, PROT_READ, MAP_SHARED,
				  file, 0);

		if (tmp->inbuf == MAP_FAILED) {
			status = ISC_R_IOERROR;
			goto cleanup;
		}
	}

	*cfile = tmp;
	return (ISC_R_SUCCESS);

cleanup:
	dfree(tmp, MDL);
	return (status);
}

isc_result_t end_parse (cfile)
	struct parse **cfile;
{
	/* "Memory" config files have no file. */
	if ((*cfile)->file != -1) {
		munmap((*cfile)->inbuf, (*cfile)->bufsiz);
		close((*cfile)->file);
	}

	if ((*cfile)->saved_state != NULL) {
		dfree((*cfile)->saved_state, MDL);
	}
		
	dfree(*cfile, MDL);
	*cfile = NULL;
	return ISC_R_SUCCESS;
}

/*
 * Save the current state of the parser.
 *
 * Only one state may be saved. Any previous saved state is
 * lost.
 */
isc_result_t
save_parse_state(struct parse *cfile) {
	/*
	 * Free any previous saved state.
	 */
	if (cfile->saved_state != NULL) {
		dfree(cfile->saved_state, MDL);
	}

	/*
	 * Save our current state.
	 */
	cfile->saved_state = dmalloc(sizeof(struct parse), MDL);
	if (cfile->saved_state == NULL) {
		return ISC_R_NOMEMORY;
	}
	memcpy(cfile->saved_state, cfile, sizeof(*cfile));
	return ISC_R_SUCCESS;
}

/*
 * Return the parser to the previous saved state.
 *
 * You must call save_parse_state() every time before calling
 * restore_parse_state().
 *
 * Note: When the read function callback is in use in ldap mode,
 * a call to get_char() may reallocate the buffer and will append
 * config data to the buffer until a state restore.
 * Do not restore to the (freed) pointer and size, but use new one.
 */
isc_result_t
restore_parse_state(struct parse *cfile) {
	struct parse *saved_state;
#if defined(LDAP_CONFIGURATION)
	char *inbuf = cfile->inbuf;
	size_t size = cfile->bufsiz;
#endif

	if (cfile->saved_state == NULL) {
		return DHCP_R_NOTYET;
	}

	saved_state = cfile->saved_state;
	memcpy(cfile, saved_state, sizeof(*cfile));
	dfree(saved_state, MDL);
	cfile->saved_state = NULL;

#if defined(LDAP_CONFIGURATION)
	cfile->inbuf = inbuf;
	cfile->bufsiz = size;
#endif
	return ISC_R_SUCCESS;
}

static int get_char (cfile)
	struct parse *cfile;
{
	/* My kingdom for WITH... */
	int c;

	if (cfile->bufix == cfile->buflen) {
#if !defined(LDAP_CONFIGURATION)
		c = EOF;
#else /* defined(LDAP_CONFIGURATION) */
		if (cfile->read_function != NULL)
			c = cfile->read_function(cfile);
		else
			c = EOF;
#endif
	} else {
		c = cfile->inbuf [cfile->bufix];
		cfile->bufix++;
	}

	if (!cfile->ugflag) {
		if (c == EOL) {
			if (cfile->cur_line == cfile->line1) {	
				cfile->cur_line = cfile->line2;
				cfile->prev_line = cfile->line1;
			} else {
				cfile->cur_line = cfile->line1;
				cfile->prev_line = cfile->line2;
			}
			cfile->line++;
			cfile->lpos = 1;
			cfile->cur_line [0] = 0;
		} else if (c != EOF) {
			if (cfile->lpos <= 80) {
				cfile->cur_line [cfile->lpos - 1] = c;
				cfile->cur_line [cfile->lpos] = 0;
			}
			cfile->lpos++;
		}
	} else
		cfile->ugflag = 0;
	return c;		
}

/*
 * Return a character to our input buffer.
 */
static void
unget_char(struct parse *cfile, int c) {
	if (c != EOF) {
		cfile->bufix--;
		cfile->ugflag = 1;	/* do not put characters into
					   our error buffer on the next
					   call to get_char() */
	}
}

/*
 * GENERAL NOTE ABOUT TOKENS
 *
 * We normally only want non-whitespace tokens. There are some 
 * circumstances where we *do* want to see whitespace (for example
 * when parsing IPv6 addresses).
 *
 * Generally we use the next_token() function to read tokens. This 
 * in turn calls get_next_token, which does *not* return tokens for
 * whitespace. Rather, it skips these.
 *
 * When we need to see whitespace, we us next_raw_token(), which also
 * returns the WHITESPACE token.
 *
 * The peek_token() and peek_raw_token() functions work as expected.
 *
 * Warning: if you invoke peek_token(), then if there is a whitespace
 * token, it will be lost, and subsequent use of next_raw_token() or
 * peek_raw_token() will NOT see it.
 */

static enum dhcp_token
get_raw_token(struct parse *cfile) {
	int c;
	enum dhcp_token ttok;
	static char tb [2];
	int l, p;

	do {
		l = cfile -> line;
		p = cfile -> lpos;

		c = get_char (cfile);
		if (!((c == '\n') && cfile->eol_token) && 
		    isascii(c) && isspace(c)) {
		    	ttok = read_whitespace(c, cfile);
			break;
		}
		if (c == '#') {
			skip_to_eol (cfile);
			continue;
		}
		if (c == '"') {
			cfile -> lexline = l;
			cfile -> lexchar = p;
			ttok = read_string (cfile);
			break;
		}
		if ((isascii (c) && isdigit (c)) || c == '-') {
			cfile -> lexline = l;
			cfile -> lexchar = p;
			ttok = read_number (c, cfile);
			break;
		} else if (isascii (c) && isalpha (c)) {
			cfile -> lexline = l;
			cfile -> lexchar = p;
			ttok = read_num_or_name (c, cfile);
			break;
		} else if (c == EOF) {
			ttok = END_OF_FILE;
			cfile -> tlen = 0;
			break;
		} else {
			cfile -> lexline = l;
			cfile -> lexchar = p;
			tb [0] = c;
			tb [1] = 0;
			cfile -> tval = tb;
			cfile -> tlen = 1;
			ttok = c;
			break;
		}
	} while (1);
	return ttok;
}

/*
 * The get_next_token() function consumes the next token and
 * returns it to the caller.
 *
 * Since the code is almost the same for "normal" and "raw" 
 * input, we pass a flag to alter the way it works.
 */

static enum dhcp_token 
get_next_token(const char **rval, unsigned *rlen, 
	       struct parse *cfile, isc_boolean_t raw) {
	int rv;

	if (cfile -> token) {
		if (cfile -> lexline != cfile -> tline)
			cfile -> token_line = cfile -> cur_line;
		cfile -> lexchar = cfile -> tlpos;
		cfile -> lexline = cfile -> tline;
		rv = cfile -> token;
		cfile -> token = 0;
	} else {
		rv = get_raw_token(cfile);
		cfile -> token_line = cfile -> cur_line;
	}

	if (!raw) {
		while (rv == WHITESPACE) {
			rv = get_raw_token(cfile);
			cfile->token_line = cfile->cur_line;
		}
	}
	
	if (rval)
		*rval = cfile -> tval;
	if (rlen)
		*rlen = cfile -> tlen;
#ifdef DEBUG_TOKENS
	fprintf (stderr, "%s:%d ", cfile -> tval, rv);
#endif
	return rv;
}


/*
 * Get the next token from cfile and return it.
 *
 * If rval is non-NULL, set the pointer it contains to 
 * the contents of the token.
 *
 * If rlen is non-NULL, set the integer it contains to 
 * the length of the token.
 */

enum dhcp_token
next_token(const char **rval, unsigned *rlen, struct parse *cfile) {
	return get_next_token(rval, rlen, cfile, ISC_FALSE);
}


/*
 * The same as the next_token() function above, but will return space
 * as the WHITESPACE token.
 */

enum dhcp_token
next_raw_token(const char **rval, unsigned *rlen, struct parse *cfile) {
	return get_next_token(rval, rlen, cfile, ISC_TRUE);
}


/*
 * The do_peek_token() function checks the next token without
 * consuming it, and returns it to the caller.
 *
 * Since the code is almost the same for "normal" and "raw" 
 * input, we pass a flag to alter the way it works. (See the 
 * warning in the GENERAL NOTES ABOUT TOKENS above though.)
 */

enum dhcp_token
do_peek_token(const char **rval, unsigned int *rlen,
	      struct parse *cfile, isc_boolean_t raw) {
	int x;

	if (!cfile->token || (!raw && (cfile->token == WHITESPACE))) {
		cfile -> tlpos = cfile -> lexchar;
		cfile -> tline = cfile -> lexline;

		do {
			cfile->token = get_raw_token(cfile);
		} while (!raw && (cfile->token == WHITESPACE));

		if (cfile -> lexline != cfile -> tline)
			cfile -> token_line = cfile -> prev_line;

		x = cfile -> lexchar;
		cfile -> lexchar = cfile -> tlpos;
		cfile -> tlpos = x;

		x = cfile -> lexline;
		cfile -> lexline = cfile -> tline;
		cfile -> tline = x;
	}
	if (rval)
		*rval = cfile -> tval;
	if (rlen)
		*rlen = cfile -> tlen;
#ifdef DEBUG_TOKENS
	fprintf (stderr, "(%s:%d) ", cfile -> tval, cfile -> token);
#endif
	return cfile -> token;
}


/*
 * Get the next token from cfile and return it, leaving it for a 
 * subsequent call to next_token().
 *
 * Note that it WILL consume whitespace tokens.
 *
 * If rval is non-NULL, set the pointer it contains to 
 * the contents of the token.
 *
 * If rlen is non-NULL, set the integer it contains to 
 * the length of the token.
 */

enum dhcp_token
peek_token(const char **rval, unsigned *rlen, struct parse *cfile) {
	return do_peek_token(rval, rlen, cfile, ISC_FALSE);
}


/*
 * The same as the peek_token() function above, but will return space
 * as the WHITESPACE token.
 */

enum dhcp_token
peek_raw_token(const char **rval, unsigned *rlen, struct parse *cfile) {
	return do_peek_token(rval, rlen, cfile, ISC_TRUE);
}

static void skip_to_eol (cfile)
	struct parse *cfile;
{
	int c;
	do {
		c = get_char (cfile);
		if (c == EOF)
			return;
		if (c == EOL) {
			return;
		}
	} while (1);
}

static enum dhcp_token
read_whitespace(int c, struct parse *cfile) {
	int ofs;

	/*
	 * Read as much whitespace as we have available.
	 */
	ofs = 0;
	do {
		if (ofs >= (sizeof(cfile->tokbuf) - 1)) {
			/*
			 * As the file includes a huge amount of whitespace,
			 * it's probably broken.
			 * Print out a warning and bail out.
			 */
			parse_warn(cfile,
				   "whitespace too long, buffer overflow.");
			log_fatal("Exiting");
		}
		cfile->tokbuf[ofs++] = c;
		c = get_char(cfile);
		if (c == EOF)
			return END_OF_FILE;
	} while (!((c == '\n') && cfile->eol_token) && 
		 isascii(c) && isspace(c));

	/*
	 * Put the last (non-whitespace) character back.
	 */
	unget_char(cfile, c);

	/*
	 * Return our token.
	 */
	cfile->tokbuf[ofs] = '\0';
	cfile->tlen = ofs;
	cfile->tval = cfile->tokbuf;
	return WHITESPACE;
}

static enum dhcp_token read_string (cfile)
	struct parse *cfile;
{
	int i;
	int bs = 0;
	int c;
	int value = 0;
	int hex = 0;

	for (i = 0; i < sizeof cfile -> tokbuf; i++) {
	      again:
		c = get_char (cfile);
		if (c == EOF) {
			parse_warn (cfile, "eof in string constant");
			break;
		}
		if (bs == 1) {
			switch (c) {
			      case 't':
				cfile -> tokbuf [i] = '\t';
				break;
			      case 'r':
				cfile -> tokbuf [i] = '\r';
				break;
			      case 'n':
				cfile -> tokbuf [i] = '\n';
				break;
			      case 'b':
				cfile -> tokbuf [i] = '\b';
				break;
			      case '0':
			      case '1':
			      case '2':
			      case '3':
				hex = 0;
				value = c - '0';
				++bs;
				goto again;
			      case 'x':
				hex = 1;
				value = 0;
				++bs;
				goto again;
			      default:
				cfile -> tokbuf [i] = c;
				break;
			}
			bs = 0;
		} else if (bs > 1) {
			if (hex) {
				if (c >= '0' && c <= '9') {
					value = value * 16 + (c - '0');
				} else if (c >= 'a' && c <= 'f') {
					value = value * 16 + (c - 'a' + 10);
				} else if (c >= 'A' && c <= 'F') {
					value = value * 16 + (c - 'A' + 10);
				} else {
					parse_warn (cfile,
						    "invalid hex digit: %x",
						    c);
					bs = 0;
					continue;
				}
				if (++bs == 4) {
					cfile -> tokbuf [i] = value;
					bs = 0;
				} else
					goto again;
			} else {
				if (c >= '0' && c <= '7') {
					value = value * 8 + (c - '0');
				} else {
				    if (value != 0) {
					parse_warn (cfile,
						    "invalid octal digit %x",
						    c);
					continue;
				    } else
					cfile -> tokbuf [i] = 0;
				    bs = 0;
				}
				if (++bs == 4) {
					cfile -> tokbuf [i] = value;
					bs = 0;
				} else
					goto again;
			}
		} else if (c == '\\') {
			bs = 1;
			goto again;
		} else if (c == '"')
			break;
		else
			cfile -> tokbuf [i] = c;
	}
	/* Normally, I'd feel guilty about this, but we're talking about
	   strings that'll fit in a DHCP packet here... */
	if (i == sizeof cfile -> tokbuf) {
		parse_warn (cfile,
			    "string constant larger than internal buffer");
		--i;
	}
	cfile -> tokbuf [i] = 0;
	cfile -> tlen = i;
	cfile -> tval = cfile -> tokbuf;
	return STRING;
}

static enum dhcp_token read_number (c, cfile)
	int c;
	struct parse *cfile;
{
	int i = 0;
	int token = NUMBER;

	cfile -> tokbuf [i++] = c;
	for (; i < sizeof cfile -> tokbuf; i++) {
		c = get_char (cfile);

		/* Promote NUMBER -> NUMBER_OR_NAME -> NAME, never demote.
		 * Except in the case of '0x' syntax hex, which gets called
		 * a NAME at '0x', and returned to NUMBER_OR_NAME once it's
		 * verified to be at least 0xf or less.
		 */
		switch(isascii(c) ? token : BREAK) {
		    case NUMBER:
			if(isdigit(c))
				break;
			/* FALLTHROUGH */
		    case NUMBER_OR_NAME:
			if(isxdigit(c)) {
				token = NUMBER_OR_NAME;
				break;
			}
			/* FALLTHROUGH */
		    case NAME:
			if((i == 2) && isxdigit(c) &&
				(cfile->tokbuf[0] == '0') &&
				((cfile->tokbuf[1] == 'x') ||
				 (cfile->tokbuf[1] == 'X'))) {
				token = NUMBER_OR_NAME;
				break;
			} else if(((c == '-') || (c == '_') || isalnum(c))) {
				token = NAME;
				break;
			}
			/* FALLTHROUGH */
		    case BREAK:
			/* At this point c is either EOF or part of the next
			 * token.  If not EOF, rewind the file one byte so
			 * the next token is read from there.
			 */
			unget_char(cfile, c);
			goto end_read;

		    default:
			log_fatal("read_number():%s:%d: impossible case", MDL);
		}

		cfile -> tokbuf [i] = c;
	}

	if (i == sizeof cfile -> tokbuf) {
		parse_warn (cfile,
			    "numeric token larger than internal buffer");
		--i;
	}

  end_read:
	cfile -> tokbuf [i] = 0;
	cfile -> tlen = i;
	cfile -> tval = cfile -> tokbuf;

	/*
	 * If this entire token from start to finish was "-", such as
	 * the middle parameter in "42 - 7", return just the MINUS token.
	 */
	if ((i == 1) && (cfile->tokbuf[i] == '-'))
		return MINUS;
	else
		return token;
}

static enum dhcp_token read_num_or_name (c, cfile)
	int c;
	struct parse *cfile;
{
	int i = 0;
	enum dhcp_token rv = NUMBER_OR_NAME;
	cfile -> tokbuf [i++] = c;
	for (; i < sizeof cfile -> tokbuf; i++) {
		c = get_char (cfile);
		if (!isascii (c) ||
		    (c != '-' && c != '_' && !isalnum (c))) {
		    	unget_char(cfile, c);
			break;
		}
		if (!isxdigit (c))
			rv = NAME;
		cfile -> tokbuf [i] = c;
	}
	if (i == sizeof cfile -> tokbuf) {
		parse_warn (cfile, "token larger than internal buffer");
		--i;
	}
	cfile -> tokbuf [i] = 0;
	cfile -> tlen = i;
	cfile -> tval = cfile -> tokbuf;
	return intern(cfile->tval, rv);
}

static enum dhcp_token
intern(char *atom, enum dhcp_token dfv) {
	if (!isascii(atom[0]))
		return dfv;

	switch (tolower((unsigned char)atom[0])) {
	      case '-':
		if (atom [1] == 0)
			return MINUS;
		break;

	      case 'a':
		if (!strcasecmp(atom + 1, "bandoned"))
			return TOKEN_ABANDONED;
		if (!strcasecmp(atom + 1, "ctive"))
			return TOKEN_ACTIVE;
		if (!strncasecmp(atom + 1, "dd", 2)) {
			if (atom[3] == '\0')
				return TOKEN_ADD;
			else if (!strcasecmp(atom + 3, "ress"))
				return ADDRESS;
			break;
		}
		if (!strcasecmp(atom + 1, "fter"))
			return AFTER;
		if (isascii(atom[1]) &&
		    (tolower((unsigned char)atom[1]) == 'l')) {
			if (!strcasecmp(atom + 2, "gorithm"))
				return ALGORITHM;
			if (!strcasecmp(atom + 2, "ias"))
				return ALIAS;
			if (isascii(atom[2]) &&
			    (tolower((unsigned char)atom[2]) == 'l')) {
				if (atom[3] == '\0')
					return ALL;
				else if (!strcasecmp(atom + 3, "ow"))
					return ALLOW;
				break;
			}
			if (!strcasecmp(atom + 2, "so"))
				return TOKEN_ALSO;
			break;
		}
		if (isascii(atom[1]) &&
		    (tolower((unsigned char)atom[1]) == 'n')) {
			if (!strcasecmp(atom + 2, "d"))
				return AND;
			if (!strcasecmp(atom + 2, "ycast-mac"))
				return ANYCAST_MAC;
			break;
		}
		if (!strcasecmp(atom + 1, "ppend"))
			return APPEND;
		if (!strcasecmp(atom + 1, "rray"))
			return ARRAY;
		if (isascii(atom[1]) &&
		    (tolower((unsigned char)atom[1]) == 't')) {
			if (atom[2] == '\0')
				return AT;
			if (!strcasecmp(atom + 2, "sfp"))
				return ATSFP;
			break;
		}
		if (!strcasecmp(atom + 1, "uthoring-byte-order"))
			return AUTHORING_BYTE_ORDER;
		if (!strncasecmp(atom + 1, "ut", 2)) {
			if (isascii(atom[3]) &&
			    (tolower((unsigned char)atom[3]) == 'h')) {
				if (!strncasecmp(atom + 4, "enticat", 7)) {
					if (!strcasecmp(atom + 11, "ed"))
						return AUTHENTICATED;
					if (!strcasecmp(atom + 11, "ion"))
						return AUTHENTICATION;
					break;
				}
				if (!strcasecmp(atom + 4, "oritative"))
					return AUTHORITATIVE;
				break;
			}
			if (!strcasecmp(atom + 3, "o-partner-down"))
				return AUTO_PARTNER_DOWN;
			break;
		}
		break;
	      case 'b':
		if (!strcasecmp (atom + 1, "ackup"))
			return TOKEN_BACKUP;
		if (!strcasecmp (atom + 1, "ootp"))
			return TOKEN_BOOTP;
		if (!strcasecmp (atom + 1, "inding"))
			return BINDING;
		if (!strcasecmp (atom + 1, "inary-to-ascii"))
			return BINARY_TO_ASCII;
		if (!strcasecmp (atom + 1, "ackoff-cutoff"))
			return BACKOFF_CUTOFF;
		if (!strcasecmp (atom + 1, "ooting"))
			return BOOTING;
		if (!strcasecmp (atom + 1, "oot-unknown-clients"))
			return BOOT_UNKNOWN_CLIENTS;
		if (!strcasecmp (atom + 1, "reak"))
			return BREAK;
		if (!strcasecmp (atom + 1, "illing"))
			return BILLING;
		if (!strcasecmp (atom + 1, "oolean"))
			return BOOLEAN;
		if (!strcasecmp (atom + 1, "alance"))
			return BALANCE;
		if (!strcasecmp (atom + 1, "ound"))
			return BOUND;
		if (!strcasecmp(atom+1, "ig-endian")) {
			return TOKEN_BIG_ENDIAN;
		}
		break;
	      case 'c':
		if (!strcasecmp(atom + 1, "ase"))
			return CASE;
		if (!strcasecmp(atom + 1, "heck"))
			return CHECK;
		if (!strcasecmp(atom + 1, "iaddr"))
			return CIADDR;
		if (isascii(atom[1]) &&
		    tolower((unsigned char)atom[1]) == 'l') {
			if (!strcasecmp(atom + 2, "ass"))
				return CLASS;
			if (!strncasecmp(atom + 2, "ient", 4)) {
				if (!strcasecmp(atom + 6, "s"))
					return CLIENTS;
				if (atom[6] == '-') {
					if (!strcasecmp(atom + 7, "hostname"))
						return CLIENT_HOSTNAME;
					if (!strcasecmp(atom + 7, "identifier"))
						return CLIENT_IDENTIFIER;
					if (!strcasecmp(atom + 7, "state"))
						return CLIENT_STATE;
					if (!strcasecmp(atom + 7, "updates"))
						return CLIENT_UPDATES;
					break;
				}
				break;
			}
			if (!strcasecmp(atom + 2, "ose"))
				return TOKEN_CLOSE;
			if (!strcasecmp(atom + 2, "tt"))
				return CLTT;
			break;
		}
		if (isascii(atom[1]) &&
		    tolower((unsigned char)atom[1]) == 'o') {
			if (!strcasecmp(atom + 2, "de"))
				return CODE;
			if (isascii(atom[2]) &&
			    tolower((unsigned char)atom[2]) == 'm') {
				if (!strcasecmp(atom + 3, "mit"))
					return COMMIT;
				if (!strcasecmp(atom + 3,
						"munications-interrupted"))
					return COMMUNICATIONS_INTERRUPTED;
				if (!strcasecmp(atom + 3, "pressed"))
					return COMPRESSED;
				break;
			}
			if (isascii(atom[2]) &&
			    tolower((unsigned char)atom[2]) == 'n') {
				if (!strcasecmp(atom + 3, "cat"))
					return CONCAT;
				if (!strcasecmp(atom + 3, "fig-option"))
					return CONFIG_OPTION;
				if (!strcasecmp(atom + 3, "flict-done"))
					return CONFLICT_DONE;
				if (!strcasecmp(atom + 3, "nect"))
					return CONNECT;
				break;
			}
			break;
		}
		if (!strcasecmp(atom + 1, "reate"))
			return TOKEN_CREATE;
		break;
	      case 'd':
		if (!strcasecmp(atom + 1, "b-time-format"))
			return DB_TIME_FORMAT;
		if (!strcasecmp (atom + 1, "omain"))
			return DOMAIN;
		if (!strncasecmp (atom + 1, "omain-", 6)) {
			if (!strcasecmp(atom + 7, "name"))
				return DOMAIN_NAME;
			if (!strcasecmp(atom + 7, "list"))
				return DOMAIN_LIST;
		}
		if (!strcasecmp (atom + 1, "o-forward-updates"))
			return DO_FORWARD_UPDATE;
		/* do-forward-update is included for historical reasons */
		if (!strcasecmp (atom + 1, "o-forward-update"))
			return DO_FORWARD_UPDATE;
		if (!strcasecmp (atom + 1, "ebug"))
			return TOKEN_DEBUG;
		if (!strcasecmp (atom + 1, "eny"))
			return DENY;
		if (!strcasecmp (atom + 1, "eleted"))
			return TOKEN_DELETED;
		if (!strcasecmp (atom + 1, "elete"))
			return TOKEN_DELETE;
		if (!strncasecmp (atom + 1, "efault", 6)) {
			if (!atom [7])
				return DEFAULT;
			if (!strcasecmp(atom + 7, "-duid"))
				return DEFAULT_DUID;
			if (!strcasecmp (atom + 7, "-lease-time"))
				return DEFAULT_LEASE_TIME;
			break;
		}
		if (!strncasecmp (atom + 1, "ynamic", 6)) {
			if (!atom [7])
				return DYNAMIC;
			if (!strncasecmp (atom + 7, "-bootp", 6)) {
				if (!atom [13])
					return DYNAMIC_BOOTP;
				if (!strcasecmp (atom + 13, "-lease-cutoff"))
					return DYNAMIC_BOOTP_LEASE_CUTOFF;
				if (!strcasecmp (atom + 13, "-lease-length"))
					return DYNAMIC_BOOTP_LEASE_LENGTH;
				break;
			}
		}
		if (!strcasecmp (atom + 1, "uplicates"))
			return DUPLICATES;
		if (!strcasecmp (atom + 1, "eclines"))
			return DECLINES;
		if (!strncasecmp (atom + 1, "efine", 5)) {
			if (!strcasecmp (atom + 6, "d"))
				return DEFINED;
			if (!atom [6])
				return DEFINE;
		}
		break;
	      case 'e':
		if (isascii (atom [1]) && 
		    tolower((unsigned char)atom[1]) == 'x') {
			if (!strcasecmp (atom + 2, "tract-int"))
				return EXTRACT_INT;
			if (!strcasecmp (atom + 2, "ists"))
				return EXISTS;
			if (!strcasecmp (atom + 2, "piry"))
				return EXPIRY;
			if (!strcasecmp (atom + 2, "pire"))
				return EXPIRE;
			if (!strcasecmp (atom + 2, "pired"))
				return TOKEN_EXPIRED;
		}
		if (!strcasecmp (atom + 1, "ncode-int"))
			return ENCODE_INT;
		if (!strcasecmp(atom + 1, "poch"))
			return EPOCH;
		if (!strcasecmp (atom + 1, "thernet"))
			return ETHERNET;
		if (!strcasecmp (atom + 1, "nds"))
			return ENDS;
		if (!strncasecmp (atom + 1, "ls", 2)) {
			if (!strcasecmp (atom + 3, "e"))
				return ELSE;
			if (!strcasecmp (atom + 3, "if"))
				return ELSIF;
			break;
		}
		if (!strcasecmp (atom + 1, "rror"))
			return ERROR;
		if (!strcasecmp (atom + 1, "val"))
			return EVAL;
		if (!strcasecmp (atom + 1, "ncapsulate"))
			return ENCAPSULATE;
		if (!strcasecmp(atom + 1, "xecute"))
			return EXECUTE;
		if (!strcasecmp(atom+1, "n")) {
			return EN;
		}
		break;
	      case 'f':
		if (!strcasecmp (atom + 1, "atal"))
			return FATAL;
		if (!strcasecmp (atom + 1, "ilename"))
			return FILENAME;
		if (!strcasecmp (atom + 1, "ixed-address"))
			return FIXED_ADDR;
		if (!strcasecmp (atom + 1, "ixed-address6"))
			return FIXED_ADDR6;
		if (!strcasecmp (atom + 1, "ixed-prefix6"))
			return FIXED_PREFIX6;
		if (!strcasecmp (atom + 1, "ddi"))
			return TOKEN_FDDI;
		if (!strcasecmp (atom + 1, "ormerr"))
			return NS_FORMERR;
		if (!strcasecmp (atom + 1, "unction"))
			return FUNCTION;
		if (!strcasecmp (atom + 1, "ailover"))
			return FAILOVER;
		if (!strcasecmp (atom + 1, "ree"))
			return TOKEN_FREE;
		break;
	      case 'g':
		if (!strncasecmp(atom + 1, "et", 2)) {
			if (!strcasecmp(atom + 3, "-lease-hostnames"))
				return GET_LEASE_HOSTNAMES;
			if (!strcasecmp(atom + 3, "hostbyname"))
				return GETHOSTBYNAME;
			if (!strcasecmp(atom + 3, "hostname"))
				return GETHOSTNAME;
			break;
		}
		if (!strcasecmp (atom + 1, "iaddr"))
			return GIADDR;
		if (!strcasecmp (atom + 1, "roup"))
			return GROUP;
		break;
	      case 'h':
		if (!strcasecmp(atom + 1, "ash"))
			return HASH;
		if (!strcasecmp (atom + 1, "ba"))
			return HBA;
		if (!strcasecmp (atom + 1, "ost"))
			return HOST;
		if (!strcasecmp (atom + 1, "ost-decl-name"))
			return HOST_DECL_NAME;
		if (!strcasecmp(atom + 1, "ost-identifier"))
			return HOST_IDENTIFIER;
		if (!strcasecmp (atom + 1, "ardware"))
			return HARDWARE;
		if (!strcasecmp (atom + 1, "ostname"))
			return HOSTNAME;
		if (!strcasecmp (atom + 1, "elp"))
			return TOKEN_HELP;
		if (!strcasecmp (atom + 1, "ex")) {
			return TOKEN_HEX;
		}
		break;
	      case 'i':
	      	if (!strcasecmp(atom+1, "a-na")) 
			return IA_NA;
	      	if (!strcasecmp(atom+1, "a-ta")) 
			return IA_TA;
	      	if (!strcasecmp(atom+1, "a-pd")) 
			return IA_PD;
	      	if (!strcasecmp(atom+1, "aaddr")) 
			return IAADDR;
	      	if (!strcasecmp(atom+1, "aprefix")) 
			return IAPREFIX;
		if (!strcasecmp (atom + 1, "nclude"))
			return INCLUDE;
		if (!strcasecmp (atom + 1, "nteger"))
			return INTEGER;
		if (!strcasecmp (atom  + 1, "nfiniband"))
			return TOKEN_INFINIBAND;
		if (!strcasecmp (atom + 1, "nfinite"))
			return INFINITE;
		if (!strcasecmp (atom + 1, "nfo"))
			return INFO;
		if (!strcasecmp (atom + 1, "p-address"))
			return IP_ADDRESS;
		if (!strcasecmp (atom + 1, "p6-address"))
			return IP6_ADDRESS;
		if (!strcasecmp (atom + 1, "nitial-interval"))
			return INITIAL_INTERVAL;
		if (!strcasecmp (atom + 1, "nitial-delay"))
			return INITIAL_DELAY;
		if (!strcasecmp (atom + 1, "nterface"))
			return INTERFACE;
		if (!strcasecmp (atom + 1, "dentifier"))
			return IDENTIFIER;
		if (!strcasecmp (atom + 1, "f"))
			return IF;
		if (!strcasecmp (atom + 1, "s"))
			return IS;
		if (!strcasecmp (atom + 1, "gnore"))
			return IGNORE;
		break;
	      case 'k':
		if (!strncasecmp (atom + 1, "nown", 4)) {
			if (!strcasecmp (atom + 5, "-clients"))
				return KNOWN_CLIENTS;
			if (!atom[5])
				return KNOWN;
			break;
		}
		if (!strcasecmp (atom + 1, "ey"))
			return KEY;
		break;
	      case 'l':
		if (!strcasecmp (atom + 1, "case"))
			return LCASE;
		if (!strcasecmp (atom + 1, "ease"))
			return LEASE;
		if (!strcasecmp(atom + 1, "ease6"))
			return LEASE6;
		if (!strcasecmp (atom + 1, "eased-address"))
			return LEASED_ADDRESS;
		if (!strcasecmp (atom + 1, "ease-time"))
			return LEASE_TIME;
		if (!strcasecmp(atom + 1, "easequery"))
			return LEASEQUERY;
		if (!strcasecmp(atom + 1, "ength"))
			return LENGTH;
		if (!strcasecmp (atom + 1, "imit"))
			return LIMIT;
		if (!strcasecmp (atom + 1, "et"))
			return LET;
		if (!strcasecmp (atom + 1, "oad"))
			return LOAD;
		if (!strcasecmp(atom + 1, "ocal"))
			return LOCAL;
		if (!strcasecmp (atom + 1, "og"))
			return LOG;
		if (!strcasecmp(atom+1, "lt")) {
			return LLT;
		}
		if (!strcasecmp(atom+1, "l")) {
			return LL;
		}
		if (!strcasecmp(atom+1, "ittle-endian")) {
			return TOKEN_LITTLE_ENDIAN;
		}
		if (!strcasecmp (atom + 1, "ease-id-format")) {
			return LEASE_ID_FORMAT;
		}
		break;
	      case 'm':
		if (!strncasecmp (atom + 1, "ax", 2)) {
			if (!atom [3])
				return TOKEN_MAX;
			if (!strcasecmp (atom + 3, "-balance"))
				return MAX_BALANCE;
			if (!strncasecmp (atom + 3, "-lease-", 7)) {
				if (!strcasecmp(atom + 10, "misbalance"))
					return MAX_LEASE_MISBALANCE;
				if (!strcasecmp(atom + 10, "ownership"))
					return MAX_LEASE_OWNERSHIP;
				if (!strcasecmp(atom + 10, "time"))
					return MAX_LEASE_TIME;
			}
			if (!strcasecmp(atom + 3, "-life"))
				return MAX_LIFE;
			if (!strcasecmp (atom + 3, "-transmit-idle"))
				return MAX_TRANSMIT_IDLE;
			if (!strcasecmp (atom + 3, "-response-delay"))
				return MAX_RESPONSE_DELAY;
			if (!strcasecmp (atom + 3, "-unacked-updates"))
				return MAX_UNACKED_UPDATES;
		}
		if (!strncasecmp (atom + 1, "in-", 3)) {
			if (!strcasecmp (atom + 4, "balance"))
				return MIN_BALANCE;
			if (!strcasecmp (atom + 4, "lease-time"))
				return MIN_LEASE_TIME;
			if (!strcasecmp (atom + 4, "secs"))
				return MIN_SECS;
			break;
		}
		if (!strncasecmp (atom + 1, "edi", 3)) {
			if (!strcasecmp (atom + 4, "a"))
				return MEDIA;
			if (!strcasecmp (atom + 4, "um"))
				return MEDIUM;
			break;
		}
		if (!strcasecmp (atom + 1, "atch"))
			return MATCH;
		if (!strcasecmp (atom + 1, "embers"))
			return MEMBERS;
		if (!strcasecmp (atom + 1, "y"))
			return MY;
		if (!strcasecmp (atom + 1, "clt"))
			return MCLT;
		break;
	      case 'n':
		if (!strcasecmp (atom + 1, "ormal"))
			return NORMAL;
		if (!strcasecmp (atom + 1, "ameserver"))
			return NAMESERVER;
		if (!strcasecmp (atom + 1, "etmask"))
			return NETMASK;
		if (!strcasecmp (atom + 1, "ever"))
			return NEVER;
		if (!strcasecmp (atom + 1, "ext-server"))
			return NEXT_SERVER;
		if (!strcasecmp (atom + 1, "ot"))
			return TOKEN_NOT;
		if (!strcasecmp (atom + 1, "o"))
			return TOKEN_NO;
		if (!strcasecmp (atom + 1, "oerror"))
			return NS_NOERROR;
		if (!strcasecmp (atom + 1, "otauth"))
			return NS_NOTAUTH;
		if (!strcasecmp (atom + 1, "otimp"))
			return NS_NOTIMP;
		if (!strcasecmp (atom + 1, "otzone"))
			return NS_NOTZONE;
		if (!strcasecmp (atom + 1, "xdomain"))
			return NS_NXDOMAIN;
		if (!strcasecmp (atom + 1, "xrrset"))
			return NS_NXRRSET;
		if (!strcasecmp (atom + 1, "ull"))
			return TOKEN_NULL;
		if (!strcasecmp (atom + 1, "ext"))
			return TOKEN_NEXT;
		if (!strcasecmp (atom + 1, "ew"))
			return TOKEN_NEW;
		break;
	      case 'o':
		if (!strcasecmp (atom + 1, "mapi"))
			return OMAPI;
		if (!strcasecmp (atom + 1, "r"))
			return OR;
		if (!strcasecmp (atom + 1, "n"))
			return ON;
		if (!strcasecmp (atom + 1, "pen"))
			return TOKEN_OPEN;
		if (!strcasecmp (atom + 1, "ption"))
			return OPTION;
		if (!strcasecmp (atom + 1, "ne-lease-per-client"))
			return ONE_LEASE_PER_CLIENT;
		if (!strcasecmp (atom + 1, "f"))
			return OF;
		if (!strcasecmp (atom + 1, "wner"))
			return OWNER;
		if (!strcasecmp (atom + 1, "ctal")) {
			return TOKEN_OCTAL;
		}
		break;
	      case 'p':
		if (!strcasecmp (atom + 1, "arse-vendor-option"))
			return PARSE_VENDOR_OPT;
		if (!strcasecmp (atom + 1, "repend"))
			return PREPEND;
		if (!strcasecmp(atom + 1, "referred-life"))
			return PREFERRED_LIFE;
		if (!strcasecmp (atom + 1, "acket"))
			return PACKET;
		if (!strcasecmp (atom + 1, "ool"))
			return POOL;
		if (!strcasecmp (atom + 1, "ool6"))
			return POOL6;
		if (!strcasecmp (atom + 1, "refix6"))
			return PREFIX6;
		if (!strcasecmp (atom + 1, "seudo"))
			return PSEUDO;
		if (!strcasecmp (atom + 1, "eer"))
			return PEER;
		if (!strcasecmp (atom + 1, "rimary"))
			return PRIMARY;
		if (!strcasecmp (atom + 1, "rimary6"))
			return PRIMARY6;
		if (!strncasecmp (atom + 1, "artner", 6)) {
			if (!atom [7])
				return PARTNER;
			if (!strcasecmp (atom + 7, "-down"))
				return PARTNER_DOWN;
		}
		if (!strcasecmp (atom + 1, "ort"))
			return PORT;
		if (!strcasecmp (atom + 1, "otential-conflict"))
			return POTENTIAL_CONFLICT;
		if (!strcasecmp (atom + 1, "ick-first-value") ||
		    !strcasecmp (atom + 1, "ick"))
			return PICK;
		if (!strcasecmp (atom + 1, "aused"))
			return PAUSED;
		break;
	      case 'r':
		if (!strcasecmp(atom + 1, "ange"))
			return RANGE;
		if (!strcasecmp(atom + 1, "ange6"))
			return RANGE6;
		if (isascii(atom[1]) &&
		    (tolower((unsigned char)atom[1]) == 'e')) {
			if (!strcasecmp(atom + 2, "bind"))
				return REBIND;
			if (!strcasecmp(atom + 2, "boot"))
				return REBOOT;
			if (!strcasecmp(atom + 2, "contact-interval"))
				return RECONTACT_INTERVAL;
			if (!strncasecmp(atom + 2, "cover", 5)) {
				if (atom[7] == '\0')
					return RECOVER;
				if (!strcasecmp(atom + 7, "-done"))
					return RECOVER_DONE;
				if (!strcasecmp(atom + 7, "-wait"))
					return RECOVER_WAIT;
				break;
			}
			if (!strcasecmp(atom + 2, "fresh"))
				return REFRESH;
			if (!strcasecmp(atom + 2, "fused"))
				return NS_REFUSED;
			if (!strcasecmp(atom + 2, "ject"))
				return REJECT;
			if (!strcasecmp(atom + 2, "lease"))
				return RELEASE;
			if (!strcasecmp(atom + 2, "leased"))
				return TOKEN_RELEASED;
			if (!strcasecmp(atom + 2, "move"))
				return REMOVE;
			if (!strcasecmp(atom + 2, "new"))
				return RENEW;
			if (!strcasecmp(atom + 2, "quest"))
				return REQUEST;
			if (!strcasecmp(atom + 2, "quire"))
				return REQUIRE;
			if (isascii(atom[2]) &&
			    (tolower((unsigned char)atom[2]) == 's')) {
				if (!strcasecmp(atom + 3, "erved"))
					return TOKEN_RESERVED;
				if (!strcasecmp(atom + 3, "et"))
					return TOKEN_RESET;
				if (!strcasecmp(atom + 3,
						"olution-interrupted"))
					return RESOLUTION_INTERRUPTED;
				break;
			}
			if (!strcasecmp(atom + 2, "try"))
				return RETRY;
			if (!strcasecmp(atom + 2, "turn"))
				return RETURN;
			if (!strcasecmp(atom + 2, "verse"))
				return REVERSE;
			if (!strcasecmp(atom + 2, "wind"))
				return REWIND;
			break;
		}
		break;
	      case 's':
		if (!strcasecmp(atom + 1, "cript"))
			return SCRIPT;
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 'e') {
			if (!strcasecmp(atom + 2, "arch"))
				return SEARCH;
			if (isascii(atom[2]) && 
			    tolower((unsigned char)atom[2]) == 'c') {
				if (!strncasecmp(atom + 3, "ond", 3)) {
                                        if (!strcasecmp(atom + 6, "ary"))
						return SECONDARY;
                                        if (!strcasecmp(atom + 6, "ary6"))
						return SECONDARY6;
                                        if (!strcasecmp(atom + 6, "s"))
                                                return SECONDS;
					break;
				}
                                if (!strcasecmp(atom + 3, "ret"))
                                        return SECRET;
				break;
			}
			if (!strncasecmp(atom + 2, "lect", 4)) {
                                if (atom[6] == '\0')
                                        return SELECT;
                                if (!strcasecmp(atom + 6, "-timeout"))
                                        return SELECT_TIMEOUT;
				break;
			}
                        if (!strcasecmp(atom + 2, "nd"))
                                return SEND;
			if (!strncasecmp(atom + 2, "rv", 2)) {
				if (!strncasecmp(atom + 4, "er", 2)) {
                                        if (atom[6] == '\0')
                                                return TOKEN_SERVER;
					if (atom[6] == '-') {
						if (!strcasecmp(atom + 7,
								"duid")) 
							return SERVER_DUID;
                                                if (!strcasecmp(atom + 7,
								"name"))
                                                        return SERVER_NAME;
                                                if (!strcasecmp(atom + 7,
								"identifier"))
                                                      return SERVER_IDENTIFIER;
						break;
					}
					break;
				}
                                if (!strcasecmp(atom + 4, "fail"))
                                        return NS_SERVFAIL;
				break;
			}
                        if (!strcasecmp(atom + 2, "t"))
                                return TOKEN_SET;
			break;
		}
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 'h') {
                        if (!strcasecmp(atom + 2, "ared-network"))
                                return SHARED_NETWORK;
                        if (!strcasecmp(atom + 2, "utdown"))
                                return SHUTDOWN;
			break;
		}
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 'i') {
                        if (!strcasecmp(atom + 2, "addr"))
                                return SIADDR;
                        if (!strcasecmp(atom + 2, "gned"))
                                return SIGNED;
                        if (!strcasecmp(atom + 2, "ze"))
                                return SIZE;
			break;
		}
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 'p') {
			if (isascii(atom[2]) && 
			    tolower((unsigned char)atom[2]) == 'a') {
                                if (!strcasecmp(atom + 3, "ce"))
                                        return SPACE;
                                if (!strcasecmp(atom + 3, "wn"))
                                        return SPAWN;
				break;
			}
                        if (!strcasecmp(atom + 2, "lit"))
                                return SPLIT;
			break;
		}
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 't') {
			if (isascii(atom[2]) && 
			    tolower((unsigned char)atom[2]) == 'a') {
				if(!strncasecmp(atom + 3, "rt", 2)) {
                                         if (!strcasecmp(atom + 5, "s"))
                                                 return STARTS;
                                         if (!strcasecmp(atom + 5, "up"))
                                                 return STARTUP;
					break;
				}
				if (isascii(atom[3]) &&
				    tolower((unsigned char)atom[3]) == 't') {
                                        if (!strcasecmp(atom + 4, "e"))
                                                return STATE;
                                        if (!strcasecmp(atom + 4, "ic"))
                                                return STATIC;
					break;
				}
			}
                        if (!strcasecmp(atom + 2, "ring"))
                                return STRING_TOKEN;
			break;
		}
                if (!strncasecmp(atom + 1, "ub", 2)) {
                        if (!strcasecmp(atom + 3, "class"))
                                return SUBCLASS;
                        if (!strcasecmp(atom + 3, "net"))
                                return SUBNET;
                        if (!strcasecmp(atom + 3, "net6"))
                                return SUBNET6;
                        if (!strcasecmp(atom + 3, "string"))
                                return SUBSTRING;
                        break;
                }
		if (isascii(atom[1]) && 
		    tolower((unsigned char)atom[1]) == 'u') {
                        if (!strcasecmp(atom + 2, "ffix"))
                                return SUFFIX;
                        if (!strcasecmp(atom + 2, "persede"))
                                return SUPERSEDE;
		}
                if (!strcasecmp(atom + 1, "witch"))
                        return SWITCH;
		break;
	      case 't':
		if (!strcasecmp (atom + 1, "imestamp"))
			return TIMESTAMP;
		if (!strcasecmp (atom + 1, "imeout"))
			return TIMEOUT;
		if (!strcasecmp (atom + 1, "oken-ring"))
			return TOKEN_RING;
		if (!strcasecmp (atom + 1, "ext"))
			return TEXT;
		if (!strcasecmp (atom + 1, "stp"))
			return TSTP;
		if (!strcasecmp (atom + 1, "sfp"))
			return TSFP;
		if (!strcasecmp (atom + 1, "ransmission"))
			return TRANSMISSION;
		if (!strcasecmp(atom + 1, "emporary"))
			return TEMPORARY;
		break;
	      case 'u':
		if (!strcasecmp (atom + 1, "case"))
			return UCASE;
		if (!strcasecmp (atom + 1, "nset"))
			return UNSET;
		if (!strcasecmp (atom + 1, "nsigned"))
			return UNSIGNED;
		if (!strcasecmp (atom + 1, "id"))
			return UID;
		if (!strncasecmp (atom + 1, "se", 2)) {
			if (!strcasecmp (atom + 3, "r-class"))
				return USER_CLASS;
			if (!strcasecmp (atom + 3, "-host-decl-names"))
				return USE_HOST_DECL_NAMES;
			if (!strcasecmp (atom + 3,
					 "-lease-addr-for-default-route"))
				return USE_LEASE_ADDR_FOR_DEFAULT_ROUTE;
			break;
		}
		if (!strncasecmp (atom + 1, "nknown", 6)) {
			if (!strcasecmp (atom + 7, "-clients"))
				return UNKNOWN_CLIENTS;
			if (!strcasecmp (atom + 7, "-state"))
				return UNKNOWN_STATE;
			if (!atom [7])
				return UNKNOWN;
			break;
		}
		if (!strcasecmp (atom + 1, "nauthenticated"))
			return UNAUTHENTICATED;
		if (!strcasecmp (atom + 1, "pdate"))
			return UPDATE;
		break;
	      case 'v':
		if (!strcasecmp (atom + 1, "6relay"))
			return V6RELAY;
		if (!strcasecmp (atom + 1, "6relopt"))
			return V6RELOPT;
		if (!strcasecmp (atom + 1, "endor-class"))
			return VENDOR_CLASS;
		if (!strcasecmp (atom + 1, "endor"))
			return VENDOR;
		break;
	      case 'w':
		if (!strcasecmp (atom + 1, "ith"))
			return WITH;
		if (!strcasecmp(atom + 1, "idth"))
			return WIDTH;
		break;
	      case 'y':
		if (!strcasecmp (atom + 1, "iaddr"))
			return YIADDR;
		if (!strcasecmp (atom + 1, "xdomain"))
			return NS_YXDOMAIN;
		if (!strcasecmp (atom + 1, "xrrset"))
			return NS_YXRRSET;
		break;
	      case 'z':
		if (!strcasecmp (atom + 1, "erolen"))
			return ZEROLEN;
		if (!strcasecmp (atom + 1, "one"))
			return ZONE;
		break;
	}
	return dfv;
}