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