1 /* $NetBSD: ntp_parser.y,v 1.6 2013/12/28 03:20:14 christos Exp $ */ 2 3 /* ntp_parser.y 4 * 5 * The parser for the NTP configuration file. 6 * 7 * Written By: Sachin Kamboj 8 * University of Delaware 9 * Newark, DE 19711 10 * Copyright (c) 2006 11 */ 12 13 %{ 14 #ifdef HAVE_CONFIG_H 15 # include <config.h> 16 #endif 17 18 #include "ntp.h" 19 #include "ntpd.h" 20 #include "ntp_machine.h" 21 #include "ntp_stdlib.h" 22 #include "ntp_filegen.h" 23 #include "ntp_scanner.h" 24 #include "ntp_config.h" 25 #include "ntp_crypto.h" 26 27 #include "ntpsim.h" /* HMS: Do we really want this all the time? */ 28 /* SK: It might be a good idea to always 29 include the simulator code. That way 30 someone can use the same configuration file 31 for both the simulator and the daemon 32 */ 33 34 35 struct FILE_INFO *ip_file; /* configuration file stream */ 36 37 #define YYMALLOC emalloc 38 #define YYFREE free 39 #define YYERROR_VERBOSE 40 #define YYMAXDEPTH 1000 /* stop the madness sooner */ 41 void yyerror(const char *msg); 42 extern int input_from_file; /* else from ntpq :config */ 43 %} 44 45 /* 46 * Enable generation of token names array even without YYDEBUG. 47 * We access via token_name() defined below. 48 */ 49 %token-table 50 51 %union { 52 char * String; 53 double Double; 54 int Integer; 55 unsigned U_int; 56 gen_fifo * Generic_fifo; 57 attr_val * Attr_val; 58 attr_val_fifo * Attr_val_fifo; 59 int_fifo * Int_fifo; 60 string_fifo * String_fifo; 61 address_node * Address_node; 62 address_fifo * Address_fifo; 63 setvar_node * Set_var; 64 server_info * Sim_server; 65 server_info_fifo * Sim_server_fifo; 66 script_info * Sim_script; 67 script_info_fifo * Sim_script_fifo; 68 } 69 70 /* TERMINALS (do not appear left of colon) */ 71 %token <Integer> T_Abbrev 72 %token <Integer> T_Age 73 %token <Integer> T_All 74 %token <Integer> T_Allan 75 %token <Integer> T_Allpeers 76 %token <Integer> T_Auth 77 %token <Integer> T_Autokey 78 %token <Integer> T_Automax 79 %token <Integer> T_Average 80 %token <Integer> T_Bclient 81 %token <Integer> T_Beacon 82 %token <Integer> T_Broadcast 83 %token <Integer> T_Broadcastclient 84 %token <Integer> T_Broadcastdelay 85 %token <Integer> T_Burst 86 %token <Integer> T_Calibrate 87 %token <Integer> T_Ceiling 88 %token <Integer> T_Clockstats 89 %token <Integer> T_Cohort 90 %token <Integer> T_ControlKey 91 %token <Integer> T_Crypto 92 %token <Integer> T_Cryptostats 93 %token <Integer> T_Ctl 94 %token <Integer> T_Day 95 %token <Integer> T_Default 96 %token <Integer> T_Digest 97 %token <Integer> T_Disable 98 %token <Integer> T_Discard 99 %token <Integer> T_Dispersion 100 %token <Double> T_Double /* not a token */ 101 %token <Integer> T_Driftfile 102 %token <Integer> T_Drop 103 %token <Integer> T_Ellipsis /* "..." not "ellipsis" */ 104 %token <Integer> T_Enable 105 %token <Integer> T_End 106 %token <Integer> T_False 107 %token <Integer> T_File 108 %token <Integer> T_Filegen 109 %token <Integer> T_Filenum 110 %token <Integer> T_Flag1 111 %token <Integer> T_Flag2 112 %token <Integer> T_Flag3 113 %token <Integer> T_Flag4 114 %token <Integer> T_Flake 115 %token <Integer> T_Floor 116 %token <Integer> T_Freq 117 %token <Integer> T_Fudge 118 %token <Integer> T_Host 119 %token <Integer> T_Huffpuff 120 %token <Integer> T_Iburst 121 %token <Integer> T_Ident 122 %token <Integer> T_Ignore 123 %token <Integer> T_Incalloc 124 %token <Integer> T_Incmem 125 %token <Integer> T_Initalloc 126 %token <Integer> T_Initmem 127 %token <Integer> T_Includefile 128 %token <Integer> T_Integer /* not a token */ 129 %token <Integer> T_Interface 130 %token <Integer> T_Intrange /* not a token */ 131 %token <Integer> T_Io 132 %token <Integer> T_Ipv4 133 %token <Integer> T_Ipv4_flag 134 %token <Integer> T_Ipv6 135 %token <Integer> T_Ipv6_flag 136 %token <Integer> T_Kernel 137 %token <Integer> T_Key 138 %token <Integer> T_Keys 139 %token <Integer> T_Keysdir 140 %token <Integer> T_Kod 141 %token <Integer> T_Mssntp 142 %token <Integer> T_Leapfile 143 %token <Integer> T_Limited 144 %token <Integer> T_Link 145 %token <Integer> T_Listen 146 %token <Integer> T_Logconfig 147 %token <Integer> T_Logfile 148 %token <Integer> T_Loopstats 149 %token <Integer> T_Lowpriotrap 150 %token <Integer> T_Manycastclient 151 %token <Integer> T_Manycastserver 152 %token <Integer> T_Mask 153 %token <Integer> T_Maxage 154 %token <Integer> T_Maxclock 155 %token <Integer> T_Maxdepth 156 %token <Integer> T_Maxdist 157 %token <Integer> T_Maxmem 158 %token <Integer> T_Maxpoll 159 %token <Integer> T_Mem 160 %token <Integer> T_Memlock 161 %token <Integer> T_Minclock 162 %token <Integer> T_Mindepth 163 %token <Integer> T_Mindist 164 %token <Integer> T_Minimum 165 %token <Integer> T_Minpoll 166 %token <Integer> T_Minsane 167 %token <Integer> T_Mode 168 %token <Integer> T_Mode7 169 %token <Integer> T_Monitor 170 %token <Integer> T_Month 171 %token <Integer> T_Mru 172 %token <Integer> T_Multicastclient 173 %token <Integer> T_Nic 174 %token <Integer> T_Nolink 175 %token <Integer> T_Nomodify 176 %token <Integer> T_Nomrulist 177 %token <Integer> T_None 178 %token <Integer> T_Nonvolatile 179 %token <Integer> T_Nopeer 180 %token <Integer> T_Noquery 181 %token <Integer> T_Noselect 182 %token <Integer> T_Noserve 183 %token <Integer> T_Notrap 184 %token <Integer> T_Notrust 185 %token <Integer> T_Ntp 186 %token <Integer> T_Ntpport 187 %token <Integer> T_NtpSignDsocket 188 %token <Integer> T_Orphan 189 %token <Integer> T_Orphanwait 190 %token <Integer> T_Panic 191 %token <Integer> T_Peer 192 %token <Integer> T_Peerstats 193 %token <Integer> T_Phone 194 %token <Integer> T_Pid 195 %token <Integer> T_Pidfile 196 %token <Integer> T_Pool 197 %token <Integer> T_Port 198 %token <Integer> T_Preempt 199 %token <Integer> T_Prefer 200 %token <Integer> T_Protostats 201 %token <Integer> T_Pw 202 %token <Integer> T_Randfile 203 %token <Integer> T_Rawstats 204 %token <Integer> T_Refid 205 %token <Integer> T_Requestkey 206 %token <Integer> T_Reset 207 %token <Integer> T_Restrict 208 %token <Integer> T_Revoke 209 %token <Integer> T_Rlimit 210 %token <Integer> T_Saveconfigdir 211 %token <Integer> T_Server 212 %token <Integer> T_Setvar 213 %token <Integer> T_Source 214 %token <Integer> T_Stacksize 215 %token <Integer> T_Statistics 216 %token <Integer> T_Stats 217 %token <Integer> T_Statsdir 218 %token <Integer> T_Step 219 %token <Integer> T_Stepout 220 %token <Integer> T_Stratum 221 %token <String> T_String /* not a token */ 222 %token <Integer> T_Sys 223 %token <Integer> T_Sysstats 224 %token <Integer> T_Tick 225 %token <Integer> T_Time1 226 %token <Integer> T_Time2 227 %token <Integer> T_Timer 228 %token <Integer> T_Timingstats 229 %token <Integer> T_Tinker 230 %token <Integer> T_Tos 231 %token <Integer> T_Trap 232 %token <Integer> T_True 233 %token <Integer> T_Trustedkey 234 %token <Integer> T_Ttl 235 %token <Integer> T_Type 236 %token <Integer> T_U_int /* Not a token */ 237 %token <Integer> T_Unconfig 238 %token <Integer> T_Unpeer 239 %token <Integer> T_Version 240 %token <Integer> T_WanderThreshold /* Not a token */ 241 %token <Integer> T_Week 242 %token <Integer> T_Wildcard 243 %token <Integer> T_Xleave 244 %token <Integer> T_Year 245 %token <Integer> T_Flag /* Not a token */ 246 %token <Integer> T_EOC 247 248 249 /* NTP Simulator Tokens */ 250 %token <Integer> T_Simulate 251 %token <Integer> T_Beep_Delay 252 %token <Integer> T_Sim_Duration 253 %token <Integer> T_Server_Offset 254 %token <Integer> T_Duration 255 %token <Integer> T_Freq_Offset 256 %token <Integer> T_Wander 257 %token <Integer> T_Jitter 258 %token <Integer> T_Prop_Delay 259 %token <Integer> T_Proc_Delay 260 261 262 263 /*** NON-TERMINALS ***/ 264 %type <Integer> access_control_flag 265 %type <Int_fifo> ac_flag_list 266 %type <Address_node> address 267 %type <Integer> address_fam 268 %type <Address_fifo> address_list 269 %type <Integer> boolean 270 %type <Integer> client_type 271 %type <Integer> counter_set_keyword 272 %type <Int_fifo> counter_set_list 273 %type <Attr_val> crypto_command 274 %type <Attr_val_fifo> crypto_command_list 275 %type <Integer> crypto_str_keyword 276 %type <Attr_val> discard_option 277 %type <Integer> discard_option_keyword 278 %type <Attr_val_fifo> discard_option_list 279 %type <Integer> enable_disable 280 %type <Attr_val> filegen_option 281 %type <Attr_val_fifo> filegen_option_list 282 %type <Integer> filegen_type 283 %type <Attr_val> fudge_factor 284 %type <Integer> fudge_factor_bool_keyword 285 %type <Integer> fudge_factor_dbl_keyword 286 %type <Attr_val_fifo> fudge_factor_list 287 %type <Attr_val_fifo> integer_list 288 %type <Attr_val_fifo> integer_list_range 289 %type <Attr_val> integer_list_range_elt 290 %type <Attr_val> integer_range 291 %type <Integer> nic_rule_action 292 %type <Integer> interface_command 293 %type <Integer> interface_nic 294 %type <Address_node> ip_address 295 %type <Integer> link_nolink 296 %type <Attr_val> log_config_command 297 %type <Attr_val_fifo> log_config_list 298 %type <Integer> misc_cmd_dbl_keyword 299 %type <Integer> misc_cmd_str_keyword 300 %type <Integer> misc_cmd_str_lcl_keyword 301 %type <Attr_val> mru_option 302 %type <Integer> mru_option_keyword 303 %type <Attr_val_fifo> mru_option_list 304 %type <Integer> nic_rule_class 305 %type <Double> number 306 %type <Attr_val> option 307 %type <Attr_val> option_flag 308 %type <Integer> option_flag_keyword 309 %type <Attr_val_fifo> option_list 310 %type <Attr_val> option_int 311 %type <Integer> option_int_keyword 312 %type <Attr_val> option_str 313 %type <Integer> option_str_keyword 314 %type <Integer> reset_command 315 %type <Integer> rlimit_option_keyword 316 %type <Attr_val> rlimit_option 317 %type <Attr_val_fifo> rlimit_option_list 318 %type <Integer> stat 319 %type <Int_fifo> stats_list 320 %type <String_fifo> string_list 321 %type <Attr_val> system_option 322 %type <Integer> system_option_flag_keyword 323 %type <Integer> system_option_local_flag_keyword 324 %type <Attr_val_fifo> system_option_list 325 %type <Integer> t_default_or_zero 326 %type <Integer> tinker_option_keyword 327 %type <Attr_val> tinker_option 328 %type <Attr_val_fifo> tinker_option_list 329 %type <Attr_val> tos_option 330 %type <Integer> tos_option_dbl_keyword 331 %type <Integer> tos_option_int_keyword 332 %type <Attr_val_fifo> tos_option_list 333 %type <Attr_val> trap_option 334 %type <Attr_val_fifo> trap_option_list 335 %type <Integer> unpeer_keyword 336 %type <Set_var> variable_assign 337 338 /* NTP Simulator non-terminals */ 339 %type <Attr_val> sim_init_statement 340 %type <Attr_val_fifo> sim_init_statement_list 341 %type <Integer> sim_init_keyword 342 %type <Sim_server_fifo> sim_server_list 343 %type <Sim_server> sim_server 344 %type <Double> sim_server_offset 345 %type <Address_node> sim_server_name 346 %type <Sim_script> sim_act 347 %type <Sim_script_fifo> sim_act_list 348 %type <Integer> sim_act_keyword 349 %type <Attr_val_fifo> sim_act_stmt_list 350 %type <Attr_val> sim_act_stmt 351 352 %% 353 354 /* ntp.conf 355 * Configuration File Grammar 356 * -------------------------- 357 */ 358 359 configuration 360 : command_list 361 ; 362 363 command_list 364 : command_list command T_EOC 365 | command T_EOC 366 | error T_EOC 367 { 368 /* I will need to incorporate much more fine grained 369 * error messages. The following should suffice for 370 * the time being. 371 */ 372 msyslog(LOG_ERR, 373 "syntax error in %s line %d, column %d", 374 ip_file->fname, 375 ip_file->err_line_no, 376 ip_file->err_col_no); 377 } 378 ; 379 380 command : /* NULL STATEMENT */ 381 | server_command 382 | unpeer_command 383 | other_mode_command 384 | authentication_command 385 | monitoring_command 386 | access_control_command 387 | orphan_mode_command 388 | fudge_command 389 | rlimit_command 390 | system_option_command 391 | tinker_command 392 | miscellaneous_command 393 | simulate_command 394 ; 395 396 /* Server Commands 397 * --------------- 398 */ 399 400 server_command 401 : client_type address option_list 402 { 403 peer_node *my_node; 404 405 my_node = create_peer_node($1, $2, $3); 406 APPEND_G_FIFO(cfgt.peers, my_node); 407 } 408 ; 409 410 client_type 411 : T_Server 412 | T_Pool 413 | T_Peer 414 | T_Broadcast 415 | T_Manycastclient 416 ; 417 418 address 419 : ip_address 420 | address_fam T_String 421 { $$ = create_address_node($2, $1); } 422 ; 423 424 ip_address 425 : T_String 426 { $$ = create_address_node($1, AF_UNSPEC); } 427 ; 428 429 address_fam 430 : T_Ipv4_flag 431 { $$ = AF_INET; } 432 | T_Ipv6_flag 433 { $$ = AF_INET6; } 434 ; 435 436 option_list 437 : /* empty list */ 438 { $$ = NULL; } 439 | option_list option 440 { 441 $$ = $1; 442 APPEND_G_FIFO($$, $2); 443 } 444 ; 445 446 option 447 : option_flag 448 | option_int 449 | option_str 450 ; 451 452 option_flag 453 : option_flag_keyword 454 { $$ = create_attr_ival(T_Flag, $1); } 455 ; 456 457 option_flag_keyword 458 : T_Autokey 459 | T_Burst 460 | T_Iburst 461 | T_Noselect 462 | T_Preempt 463 | T_Prefer 464 | T_True 465 | T_Xleave 466 ; 467 468 option_int 469 : option_int_keyword T_Integer 470 { $$ = create_attr_ival($1, $2); } 471 | option_int_keyword T_U_int 472 { $$ = create_attr_uval($1, $2); } 473 ; 474 475 option_int_keyword 476 : T_Key 477 | T_Minpoll 478 | T_Maxpoll 479 | T_Ttl 480 | T_Mode 481 | T_Version 482 ; 483 484 option_str 485 : option_str_keyword T_String 486 { $$ = create_attr_sval($1, $2); } 487 ; 488 489 option_str_keyword 490 : T_Ident 491 ; 492 493 494 /* unpeer commands 495 * --------------- 496 */ 497 498 unpeer_command 499 : unpeer_keyword address 500 { 501 unpeer_node *my_node; 502 503 my_node = create_unpeer_node($2); 504 if (my_node) 505 APPEND_G_FIFO(cfgt.unpeers, my_node); 506 } 507 ; 508 unpeer_keyword 509 : T_Unconfig 510 | T_Unpeer 511 ; 512 513 514 /* Other Modes 515 * (broadcastclient manycastserver multicastclient) 516 * ------------------------------------------------ 517 */ 518 519 other_mode_command 520 : T_Broadcastclient 521 { cfgt.broadcastclient = 1; } 522 | T_Manycastserver address_list 523 { CONCAT_G_FIFOS(cfgt.manycastserver, $2); } 524 | T_Multicastclient address_list 525 { CONCAT_G_FIFOS(cfgt.multicastclient, $2); } 526 ; 527 528 529 530 /* Authentication Commands 531 * ----------------------- 532 */ 533 534 authentication_command 535 : T_Automax T_Integer 536 { 537 attr_val *atrv; 538 539 atrv = create_attr_ival($1, $2); 540 APPEND_G_FIFO(cfgt.vars, atrv); 541 } 542 | T_ControlKey T_Integer 543 { cfgt.auth.control_key = $2; } 544 | T_Crypto crypto_command_list 545 { 546 cfgt.auth.cryptosw++; 547 CONCAT_G_FIFOS(cfgt.auth.crypto_cmd_list, $2); 548 } 549 | T_Keys T_String 550 { cfgt.auth.keys = $2; } 551 | T_Keysdir T_String 552 { cfgt.auth.keysdir = $2; } 553 | T_Requestkey T_Integer 554 { cfgt.auth.request_key = $2; } 555 | T_Revoke T_Integer 556 { cfgt.auth.revoke = $2; } 557 | T_Trustedkey integer_list_range 558 { 559 cfgt.auth.trusted_key_list = $2; 560 561 // if (!cfgt.auth.trusted_key_list) 562 // cfgt.auth.trusted_key_list = $2; 563 // else 564 // LINK_SLIST(cfgt.auth.trusted_key_list, $2, link); 565 } 566 | T_NtpSignDsocket T_String 567 { cfgt.auth.ntp_signd_socket = $2; } 568 ; 569 570 crypto_command_list 571 : /* empty list */ 572 { $$ = NULL; } 573 | crypto_command_list crypto_command 574 { 575 $$ = $1; 576 APPEND_G_FIFO($$, $2); 577 } 578 ; 579 580 crypto_command 581 : crypto_str_keyword T_String 582 { $$ = create_attr_sval($1, $2); } 583 | T_Revoke T_Integer 584 { 585 $$ = NULL; 586 cfgt.auth.revoke = $2; 587 msyslog(LOG_WARNING, 588 "'crypto revoke %d' is deprecated, " 589 "please use 'revoke %d' instead.", 590 cfgt.auth.revoke, cfgt.auth.revoke); 591 } 592 ; 593 594 crypto_str_keyword 595 : T_Host 596 | T_Ident 597 | T_Pw 598 | T_Randfile 599 | T_Digest 600 ; 601 602 603 /* Orphan Mode Commands 604 * -------------------- 605 */ 606 607 orphan_mode_command 608 : T_Tos tos_option_list 609 { CONCAT_G_FIFOS(cfgt.orphan_cmds, $2); } 610 ; 611 612 tos_option_list 613 : tos_option_list tos_option 614 { 615 $$ = $1; 616 APPEND_G_FIFO($$, $2); 617 } 618 | tos_option 619 { 620 $$ = NULL; 621 APPEND_G_FIFO($$, $1); 622 } 623 ; 624 625 tos_option 626 : tos_option_int_keyword T_Integer 627 { $$ = create_attr_dval($1, (double)$2); } 628 | tos_option_dbl_keyword number 629 { $$ = create_attr_dval($1, $2); } 630 | T_Cohort boolean 631 { $$ = create_attr_dval($1, (double)$2); } 632 ; 633 634 tos_option_int_keyword 635 : T_Ceiling 636 | T_Floor 637 | T_Orphan 638 | T_Orphanwait 639 | T_Minsane 640 | T_Beacon 641 ; 642 643 tos_option_dbl_keyword 644 : T_Mindist 645 | T_Maxdist 646 | T_Minclock 647 | T_Maxclock 648 ; 649 650 651 /* Monitoring Commands 652 * ------------------- 653 */ 654 655 monitoring_command 656 : T_Statistics stats_list 657 { CONCAT_G_FIFOS(cfgt.stats_list, $2); } 658 | T_Statsdir T_String 659 { 660 if (input_from_file) { 661 cfgt.stats_dir = $2; 662 } else { 663 YYFREE($2); 664 yyerror("statsdir remote configuration ignored"); 665 } 666 } 667 | T_Filegen stat filegen_option_list 668 { 669 filegen_node *fgn; 670 671 fgn = create_filegen_node($2, $3); 672 APPEND_G_FIFO(cfgt.filegen_opts, fgn); 673 } 674 ; 675 676 stats_list 677 : stats_list stat 678 { 679 $$ = $1; 680 APPEND_G_FIFO($$, create_int_node($2)); 681 } 682 | stat 683 { 684 $$ = NULL; 685 APPEND_G_FIFO($$, create_int_node($1)); 686 } 687 ; 688 689 stat 690 : T_Clockstats 691 | T_Cryptostats 692 | T_Loopstats 693 | T_Peerstats 694 | T_Rawstats 695 | T_Sysstats 696 | T_Timingstats 697 | T_Protostats 698 ; 699 700 filegen_option_list 701 : /* empty list */ 702 { $$ = NULL; } 703 | filegen_option_list filegen_option 704 { 705 $$ = $1; 706 APPEND_G_FIFO($$, $2); 707 } 708 ; 709 710 filegen_option 711 : T_File T_String 712 { 713 if (input_from_file) { 714 $$ = create_attr_sval($1, $2); 715 } else { 716 $$ = NULL; 717 YYFREE($2); 718 yyerror("filegen file remote config ignored"); 719 } 720 } 721 | T_Type filegen_type 722 { 723 if (input_from_file) { 724 $$ = create_attr_ival($1, $2); 725 } else { 726 $$ = NULL; 727 yyerror("filegen type remote config ignored"); 728 } 729 } 730 | link_nolink 731 { 732 const char *err; 733 734 if (input_from_file) { 735 $$ = create_attr_ival(T_Flag, $1); 736 } else { 737 $$ = NULL; 738 if (T_Link == $1) 739 err = "filegen link remote config ignored"; 740 else 741 err = "filegen nolink remote config ignored"; 742 yyerror(err); 743 } 744 } 745 | enable_disable 746 { $$ = create_attr_ival(T_Flag, $1); } 747 ; 748 749 link_nolink 750 : T_Link 751 | T_Nolink 752 ; 753 754 enable_disable 755 : T_Enable 756 | T_Disable 757 ; 758 759 filegen_type 760 : T_None 761 | T_Pid 762 | T_Day 763 | T_Week 764 | T_Month 765 | T_Year 766 | T_Age 767 ; 768 769 770 /* Access Control Commands 771 * ----------------------- 772 */ 773 774 access_control_command 775 : T_Discard discard_option_list 776 { 777 CONCAT_G_FIFOS(cfgt.discard_opts, $2); 778 } 779 | T_Mru mru_option_list 780 { 781 CONCAT_G_FIFOS(cfgt.mru_opts, $2); 782 } 783 | T_Restrict address ac_flag_list 784 { 785 restrict_node *rn; 786 787 rn = create_restrict_node($2, NULL, $3, 788 ip_file->line_no); 789 APPEND_G_FIFO(cfgt.restrict_opts, rn); 790 } 791 | T_Restrict ip_address T_Mask ip_address ac_flag_list 792 { 793 restrict_node *rn; 794 795 rn = create_restrict_node($2, $4, $5, 796 ip_file->line_no); 797 APPEND_G_FIFO(cfgt.restrict_opts, rn); 798 } 799 | T_Restrict T_Default ac_flag_list 800 { 801 restrict_node *rn; 802 803 rn = create_restrict_node(NULL, NULL, $3, 804 ip_file->line_no); 805 APPEND_G_FIFO(cfgt.restrict_opts, rn); 806 } 807 | T_Restrict T_Ipv4_flag T_Default ac_flag_list 808 { 809 restrict_node *rn; 810 811 rn = create_restrict_node( 812 create_address_node( 813 estrdup("0.0.0.0"), 814 AF_INET), 815 create_address_node( 816 estrdup("0.0.0.0"), 817 AF_INET), 818 $4, 819 ip_file->line_no); 820 APPEND_G_FIFO(cfgt.restrict_opts, rn); 821 } 822 | T_Restrict T_Ipv6_flag T_Default ac_flag_list 823 { 824 restrict_node *rn; 825 826 rn = create_restrict_node( 827 create_address_node( 828 estrdup("::"), 829 AF_INET6), 830 create_address_node( 831 estrdup("::"), 832 AF_INET6), 833 $4, 834 ip_file->line_no); 835 APPEND_G_FIFO(cfgt.restrict_opts, rn); 836 } 837 | T_Restrict T_Source ac_flag_list 838 { 839 restrict_node * rn; 840 841 APPEND_G_FIFO($3, create_int_node($2)); 842 rn = create_restrict_node( 843 NULL, NULL, $3, ip_file->line_no); 844 APPEND_G_FIFO(cfgt.restrict_opts, rn); 845 } 846 ; 847 848 ac_flag_list 849 : /* empty list is allowed */ 850 { $$ = NULL; } 851 | ac_flag_list access_control_flag 852 { 853 $$ = $1; 854 APPEND_G_FIFO($$, create_int_node($2)); 855 } 856 ; 857 858 access_control_flag 859 : T_Flake 860 | T_Ignore 861 | T_Kod 862 | T_Mssntp 863 | T_Limited 864 | T_Lowpriotrap 865 | T_Nomodify 866 | T_Nomrulist 867 | T_Nopeer 868 | T_Noquery 869 | T_Noserve 870 | T_Notrap 871 | T_Notrust 872 | T_Ntpport 873 | T_Version 874 ; 875 876 discard_option_list 877 : discard_option_list discard_option 878 { 879 $$ = $1; 880 APPEND_G_FIFO($$, $2); 881 } 882 | discard_option 883 { 884 $$ = NULL; 885 APPEND_G_FIFO($$, $1); 886 } 887 ; 888 889 discard_option 890 : discard_option_keyword T_Integer 891 { $$ = create_attr_ival($1, $2); } 892 ; 893 894 discard_option_keyword 895 : T_Average 896 | T_Minimum 897 | T_Monitor 898 ; 899 900 mru_option_list 901 : mru_option_list mru_option 902 { 903 $$ = $1; 904 APPEND_G_FIFO($$, $2); 905 } 906 | mru_option 907 { 908 $$ = NULL; 909 APPEND_G_FIFO($$, $1); 910 } 911 ; 912 913 mru_option 914 : mru_option_keyword T_Integer 915 { $$ = create_attr_ival($1, $2); } 916 ; 917 918 mru_option_keyword 919 : T_Incalloc 920 | T_Incmem 921 | T_Initalloc 922 | T_Initmem 923 | T_Maxage 924 | T_Maxdepth 925 | T_Maxmem 926 | T_Mindepth 927 ; 928 929 /* Fudge Commands 930 * -------------- 931 */ 932 933 fudge_command 934 : T_Fudge address fudge_factor_list 935 { 936 addr_opts_node *aon; 937 938 aon = create_addr_opts_node($2, $3); 939 APPEND_G_FIFO(cfgt.fudge, aon); 940 } 941 ; 942 943 fudge_factor_list 944 : fudge_factor_list fudge_factor 945 { 946 $$ = $1; 947 APPEND_G_FIFO($$, $2); 948 } 949 | fudge_factor 950 { 951 $$ = NULL; 952 APPEND_G_FIFO($$, $1); 953 } 954 ; 955 956 fudge_factor 957 : fudge_factor_dbl_keyword number 958 { $$ = create_attr_dval($1, $2); } 959 | fudge_factor_bool_keyword boolean 960 { $$ = create_attr_ival($1, $2); } 961 | T_Stratum T_Integer 962 { $$ = create_attr_ival($1, $2); } 963 | T_Abbrev T_String 964 { $$ = create_attr_sval($1, $2); } 965 | T_Refid T_String 966 { $$ = create_attr_sval($1, $2); } 967 ; 968 969 fudge_factor_dbl_keyword 970 : T_Time1 971 | T_Time2 972 ; 973 974 fudge_factor_bool_keyword 975 : T_Flag1 976 | T_Flag2 977 | T_Flag3 978 | T_Flag4 979 ; 980 981 /* rlimit Commands 982 * --------------- 983 */ 984 985 rlimit_command 986 : T_Rlimit rlimit_option_list 987 { CONCAT_G_FIFOS(cfgt.rlimit, $2); } 988 ; 989 990 rlimit_option_list 991 : rlimit_option_list rlimit_option 992 { 993 $$ = $1; 994 APPEND_G_FIFO($$, $2); 995 } 996 | rlimit_option 997 { 998 $$ = NULL; 999 APPEND_G_FIFO($$, $1); 1000 } 1001 ; 1002 1003 rlimit_option 1004 : rlimit_option_keyword T_Integer 1005 { $$ = create_attr_ival($1, $2); } 1006 ; 1007 1008 rlimit_option_keyword 1009 : T_Memlock 1010 | T_Stacksize 1011 | T_Filenum 1012 ; 1013 1014 1015 /* Command for System Options 1016 * -------------------------- 1017 */ 1018 1019 system_option_command 1020 : T_Enable system_option_list 1021 { CONCAT_G_FIFOS(cfgt.enable_opts, $2); } 1022 | T_Disable system_option_list 1023 { CONCAT_G_FIFOS(cfgt.disable_opts, $2); } 1024 ; 1025 1026 system_option_list 1027 : system_option_list system_option 1028 { 1029 $$ = $1; 1030 APPEND_G_FIFO($$, $2); 1031 } 1032 | system_option 1033 { 1034 $$ = NULL; 1035 APPEND_G_FIFO($$, $1); 1036 } 1037 ; 1038 1039 system_option 1040 : system_option_flag_keyword 1041 { $$ = create_attr_ival(T_Flag, $1); } 1042 | system_option_local_flag_keyword 1043 { 1044 if (input_from_file) { 1045 $$ = create_attr_ival(T_Flag, $1); 1046 } else { 1047 char err_str[128]; 1048 1049 $$ = NULL; 1050 snprintf(err_str, sizeof(err_str), 1051 "enable/disable %s remote configuration ignored", 1052 keyword($1)); 1053 yyerror(err_str); 1054 } 1055 } 1056 ; 1057 1058 system_option_flag_keyword 1059 : T_Auth 1060 | T_Bclient 1061 | T_Calibrate 1062 | T_Kernel 1063 | T_Monitor 1064 | T_Ntp 1065 ; 1066 1067 system_option_local_flag_keyword 1068 : T_Mode7 1069 | T_Stats 1070 ; 1071 1072 /* Tinker Commands 1073 * --------------- 1074 */ 1075 1076 tinker_command 1077 : T_Tinker tinker_option_list 1078 { CONCAT_G_FIFOS(cfgt.tinker, $2); } 1079 ; 1080 1081 tinker_option_list 1082 : tinker_option_list tinker_option 1083 { 1084 $$ = $1; 1085 APPEND_G_FIFO($$, $2); 1086 } 1087 | tinker_option 1088 { 1089 $$ = NULL; 1090 APPEND_G_FIFO($$, $1); 1091 } 1092 ; 1093 1094 tinker_option 1095 : tinker_option_keyword number 1096 { $$ = create_attr_dval($1, $2); } 1097 ; 1098 1099 tinker_option_keyword 1100 : T_Allan 1101 | T_Dispersion 1102 | T_Freq 1103 | T_Huffpuff 1104 | T_Panic 1105 | T_Step 1106 | T_Stepout 1107 | T_Tick 1108 ; 1109 1110 1111 /* Miscellaneous Commands 1112 * ---------------------- 1113 */ 1114 1115 miscellaneous_command 1116 : interface_command 1117 | reset_command 1118 | misc_cmd_dbl_keyword number 1119 { 1120 attr_val *av; 1121 1122 av = create_attr_dval($1, $2); 1123 APPEND_G_FIFO(cfgt.vars, av); 1124 } 1125 | misc_cmd_str_keyword T_String 1126 { 1127 attr_val *av; 1128 1129 av = create_attr_sval($1, $2); 1130 APPEND_G_FIFO(cfgt.vars, av); 1131 } 1132 | misc_cmd_str_lcl_keyword T_String 1133 { 1134 char error_text[64]; 1135 attr_val *av; 1136 1137 if (input_from_file) { 1138 av = create_attr_sval($1, $2); 1139 APPEND_G_FIFO(cfgt.vars, av); 1140 } else { 1141 YYFREE($2); 1142 snprintf(error_text, sizeof(error_text), 1143 "%s remote config ignored", 1144 keyword($1)); 1145 yyerror(error_text); 1146 } 1147 } 1148 | T_Includefile T_String command 1149 { 1150 if (!input_from_file) { 1151 yyerror("remote includefile ignored"); 1152 break; 1153 } 1154 if (curr_include_level >= MAXINCLUDELEVEL) { 1155 fprintf(stderr, "getconfig: Maximum include file level exceeded.\n"); 1156 msyslog(LOG_ERR, "getconfig: Maximum include file level exceeded."); 1157 } else { 1158 fp[curr_include_level + 1] = F_OPEN(FindConfig($2), "r"); 1159 if (fp[curr_include_level + 1] == NULL) { 1160 fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig($2)); 1161 msyslog(LOG_ERR, "getconfig: Couldn't open <%s>", FindConfig($2)); 1162 } else { 1163 ip_file = fp[++curr_include_level]; 1164 } 1165 } 1166 } 1167 | T_End 1168 { 1169 while (curr_include_level != -1) 1170 FCLOSE(fp[curr_include_level--]); 1171 } 1172 | T_Driftfile drift_parm 1173 { /* see drift_parm below for actions */ } 1174 | T_Logconfig log_config_list 1175 { CONCAT_G_FIFOS(cfgt.logconfig, $2); } 1176 | T_Phone string_list 1177 { CONCAT_G_FIFOS(cfgt.phone, $2); } 1178 | T_Setvar variable_assign 1179 { APPEND_G_FIFO(cfgt.setvar, $2); } 1180 | T_Trap ip_address trap_option_list 1181 { 1182 addr_opts_node *aon; 1183 1184 aon = create_addr_opts_node($2, $3); 1185 APPEND_G_FIFO(cfgt.trap, aon); 1186 } 1187 | T_Ttl integer_list 1188 { CONCAT_G_FIFOS(cfgt.ttl, $2); } 1189 ; 1190 1191 misc_cmd_dbl_keyword 1192 : T_Broadcastdelay 1193 | T_Nonvolatile 1194 | T_Tick 1195 ; 1196 1197 misc_cmd_str_keyword 1198 : T_Ident 1199 | T_Leapfile 1200 | T_Pidfile 1201 ; 1202 1203 misc_cmd_str_lcl_keyword 1204 : T_Logfile 1205 | T_Saveconfigdir 1206 ; 1207 1208 drift_parm 1209 : T_String 1210 { 1211 attr_val *av; 1212 1213 av = create_attr_sval(T_Driftfile, $1); 1214 APPEND_G_FIFO(cfgt.vars, av); 1215 } 1216 | T_String T_Double 1217 { 1218 attr_val *av; 1219 1220 av = create_attr_sval(T_Driftfile, $1); 1221 APPEND_G_FIFO(cfgt.vars, av); 1222 av = create_attr_dval(T_WanderThreshold, $2); 1223 APPEND_G_FIFO(cfgt.vars, av); 1224 } 1225 | /* Null driftfile, indicated by empty string "" */ 1226 { 1227 attr_val *av; 1228 1229 av = create_attr_sval(T_Driftfile, ""); 1230 APPEND_G_FIFO(cfgt.vars, av); 1231 } 1232 ; 1233 1234 variable_assign 1235 : T_String '=' T_String t_default_or_zero 1236 { $$ = create_setvar_node($1, $3, $4); } 1237 ; 1238 1239 t_default_or_zero 1240 : T_Default 1241 | /* empty, no "default" modifier */ 1242 { $$ = 0; } 1243 ; 1244 1245 trap_option_list 1246 : /* empty list */ 1247 { $$ = NULL; } 1248 | trap_option_list trap_option 1249 { 1250 $$ = $1; 1251 APPEND_G_FIFO($$, $2); 1252 } 1253 ; 1254 1255 trap_option 1256 : T_Port T_Integer 1257 { $$ = create_attr_ival($1, $2); } 1258 | T_Interface ip_address 1259 { 1260 $$ = create_attr_sval($1, estrdup($2->address)); 1261 destroy_address_node($2); 1262 } 1263 ; 1264 1265 log_config_list 1266 : log_config_list log_config_command 1267 { 1268 $$ = $1; 1269 APPEND_G_FIFO($$, $2); 1270 } 1271 | log_config_command 1272 { 1273 $$ = NULL; 1274 APPEND_G_FIFO($$, $1); 1275 } 1276 ; 1277 1278 log_config_command 1279 : T_String 1280 { 1281 char prefix; 1282 char * type; 1283 1284 switch ($1[0]) { 1285 1286 case '+': 1287 case '-': 1288 case '=': 1289 prefix = $1[0]; 1290 type = $1 + 1; 1291 break; 1292 1293 default: 1294 prefix = '='; 1295 type = $1; 1296 } 1297 1298 $$ = create_attr_sval(prefix, estrdup(type)); 1299 YYFREE($1); 1300 } 1301 ; 1302 1303 interface_command 1304 : interface_nic nic_rule_action nic_rule_class 1305 { 1306 nic_rule_node *nrn; 1307 1308 nrn = create_nic_rule_node($3, NULL, $2); 1309 APPEND_G_FIFO(cfgt.nic_rules, nrn); 1310 } 1311 | interface_nic nic_rule_action T_String 1312 { 1313 nic_rule_node *nrn; 1314 1315 nrn = create_nic_rule_node(0, $3, $2); 1316 APPEND_G_FIFO(cfgt.nic_rules, nrn); 1317 } 1318 ; 1319 1320 interface_nic 1321 : T_Interface 1322 | T_Nic 1323 ; 1324 1325 nic_rule_class 1326 : T_All 1327 | T_Ipv4 1328 | T_Ipv6 1329 | T_Wildcard 1330 ; 1331 1332 nic_rule_action 1333 : T_Listen 1334 | T_Ignore 1335 | T_Drop 1336 ; 1337 1338 reset_command 1339 : T_Reset counter_set_list 1340 { CONCAT_G_FIFOS(cfgt.reset_counters, $2); } 1341 ; 1342 1343 counter_set_list 1344 : counter_set_list counter_set_keyword 1345 { 1346 $$ = $1; 1347 APPEND_G_FIFO($$, create_int_node($2)); 1348 } 1349 | counter_set_keyword 1350 { 1351 $$ = NULL; 1352 APPEND_G_FIFO($$, create_int_node($1)); 1353 } 1354 ; 1355 1356 counter_set_keyword 1357 : T_Allpeers 1358 | T_Auth 1359 | T_Ctl 1360 | T_Io 1361 | T_Mem 1362 | T_Sys 1363 | T_Timer 1364 ; 1365 1366 1367 1368 /* Miscellaneous Rules 1369 * ------------------- 1370 */ 1371 1372 integer_list 1373 : integer_list T_Integer 1374 { 1375 $$ = $1; 1376 APPEND_G_FIFO($$, create_int_node($2)); 1377 } 1378 | T_Integer 1379 { 1380 $$ = NULL; 1381 APPEND_G_FIFO($$, create_int_node($1)); 1382 } 1383 ; 1384 1385 integer_list_range 1386 : integer_list_range integer_list_range_elt 1387 { 1388 $$ = $1; 1389 APPEND_G_FIFO($$, $2); 1390 } 1391 | integer_list_range_elt 1392 { 1393 $$ = NULL; 1394 APPEND_G_FIFO($$, $1); 1395 } 1396 ; 1397 1398 integer_list_range_elt 1399 : T_Integer 1400 { $$ = create_attr_ival('i', $1); } 1401 | integer_range 1402 ; 1403 1404 integer_range 1405 : '(' T_Integer T_Ellipsis T_Integer ')' 1406 { $$ = create_attr_rangeval('-', $2, $4); } 1407 ; 1408 1409 string_list 1410 : string_list T_String 1411 { 1412 $$ = $1; 1413 APPEND_G_FIFO($$, create_string_node($2)); 1414 } 1415 | T_String 1416 { 1417 $$ = NULL; 1418 APPEND_G_FIFO($$, create_string_node($1)); 1419 } 1420 ; 1421 1422 address_list 1423 : address_list address 1424 { 1425 $$ = $1; 1426 APPEND_G_FIFO($$, $2); 1427 } 1428 | address 1429 { 1430 $$ = NULL; 1431 APPEND_G_FIFO($$, $1); 1432 } 1433 ; 1434 1435 boolean 1436 : T_Integer 1437 { 1438 if ($1 != 0 && $1 != 1) { 1439 yyerror("Integer value is not boolean (0 or 1). Assuming 1"); 1440 $$ = 1; 1441 } else { 1442 $$ = $1; 1443 } 1444 } 1445 | T_True { $$ = 1; } 1446 | T_False { $$ = 0; } 1447 ; 1448 1449 number 1450 : T_Integer { $$ = (double)$1; } 1451 | T_Double 1452 ; 1453 1454 1455 /* Simulator Configuration Commands 1456 * -------------------------------- 1457 */ 1458 1459 simulate_command 1460 : sim_conf_start '{' sim_init_statement_list sim_server_list '}' 1461 { 1462 sim_node *sn; 1463 1464 sn = create_sim_node($3, $4); 1465 APPEND_G_FIFO(cfgt.sim_details, sn); 1466 1467 /* Revert from ; to \n for end-of-command */ 1468 old_config_style = 1; 1469 } 1470 ; 1471 1472 /* The following is a terrible hack to get the configuration file to 1473 * treat newlines as whitespace characters within the simulation. 1474 * This is needed because newlines are significant in the rest of the 1475 * configuration file. 1476 */ 1477 sim_conf_start 1478 : T_Simulate { old_config_style = 0; } 1479 ; 1480 1481 sim_init_statement_list 1482 : sim_init_statement_list sim_init_statement T_EOC 1483 { 1484 $$ = $1; 1485 APPEND_G_FIFO($$, $2); 1486 } 1487 | sim_init_statement T_EOC 1488 { 1489 $$ = NULL; 1490 APPEND_G_FIFO($$, $1); 1491 } 1492 ; 1493 1494 sim_init_statement 1495 : sim_init_keyword '=' number 1496 { $$ = create_attr_dval($1, $3); } 1497 ; 1498 1499 sim_init_keyword 1500 : T_Beep_Delay 1501 | T_Sim_Duration 1502 ; 1503 1504 sim_server_list 1505 : sim_server_list sim_server 1506 { 1507 $$ = $1; 1508 APPEND_G_FIFO($$, $2); 1509 } 1510 | sim_server 1511 { 1512 $$ = NULL; 1513 APPEND_G_FIFO($$, $1); 1514 } 1515 ; 1516 1517 sim_server 1518 : sim_server_name '{' sim_server_offset sim_act_list '}' 1519 { $$ = create_sim_server($1, $3, $4); } 1520 ; 1521 1522 sim_server_offset 1523 : T_Server_Offset '=' number T_EOC 1524 { $$ = $3; } 1525 ; 1526 1527 sim_server_name 1528 : T_Server '=' address 1529 { $$ = $3; } 1530 ; 1531 1532 sim_act_list 1533 : sim_act_list sim_act 1534 { 1535 $$ = $1; 1536 APPEND_G_FIFO($$, $2); 1537 } 1538 | sim_act 1539 { 1540 $$ = NULL; 1541 APPEND_G_FIFO($$, $1); 1542 } 1543 ; 1544 1545 sim_act 1546 : T_Duration '=' number '{' sim_act_stmt_list '}' 1547 { $$ = create_sim_script_info($3, $5); } 1548 ; 1549 1550 sim_act_stmt_list 1551 : sim_act_stmt_list sim_act_stmt T_EOC 1552 { 1553 $$ = $1; 1554 APPEND_G_FIFO($$, $2); 1555 } 1556 | sim_act_stmt T_EOC 1557 { 1558 $$ = NULL; 1559 APPEND_G_FIFO($$, $1); 1560 } 1561 ; 1562 1563 sim_act_stmt 1564 : sim_act_keyword '=' number 1565 { $$ = create_attr_dval($1, $3); } 1566 ; 1567 1568 sim_act_keyword 1569 : T_Freq_Offset 1570 | T_Wander 1571 | T_Jitter 1572 | T_Prop_Delay 1573 | T_Proc_Delay 1574 ; 1575 1576 %% 1577 1578 void 1579 yyerror( 1580 const char *msg 1581 ) 1582 { 1583 int retval; 1584 1585 ip_file->err_line_no = ip_file->prev_token_line_no; 1586 ip_file->err_col_no = ip_file->prev_token_col_no; 1587 1588 msyslog(LOG_ERR, 1589 "line %d column %d %s", 1590 ip_file->err_line_no, 1591 ip_file->err_col_no, 1592 msg); 1593 if (!input_from_file) { 1594 /* Save the error message in the correct buffer */ 1595 retval = snprintf(remote_config.err_msg + remote_config.err_pos, 1596 MAXLINE - remote_config.err_pos, 1597 "column %d %s", 1598 ip_file->err_col_no, msg); 1599 1600 /* Increment the value of err_pos */ 1601 if (retval > 0) 1602 remote_config.err_pos += retval; 1603 1604 /* Increment the number of errors */ 1605 ++remote_config.no_errors; 1606 } 1607 } 1608 1609 1610 /* 1611 * token_name - convert T_ token integers to text 1612 * example: token_name(T_Server) returns "T_Server" 1613 */ 1614 const char * 1615 token_name( 1616 int token 1617 ) 1618 { 1619 return yytname[YYTRANSLATE(token)]; 1620 } 1621 1622 1623 /* Initial Testing function -- ignore */ 1624 #if 0 1625 int main(int argc, char *argv[]) 1626 { 1627 ip_file = FOPEN(argv[1], "r"); 1628 if (!ip_file) 1629 fprintf(stderr, "ERROR!! Could not open file: %s\n", argv[1]); 1630 yyparse(); 1631 return 0; 1632 } 1633 #endif 1634 1635