Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / chrony.aug
1 (*
2 Module: Chrony
3   Parses the chrony config file
4
5 Author: Pat Riehecky <riehecky@fnal.gov>
6
7 About: Reference
8   This lens tries to keep as close as possible to chrony config syntax
9
10   See http://chrony.tuxfamily.org/manual.html#Configuration-file
11
12 About: License
13   This file is licenced under the LGPL v2+, like the rest of Augeas.
14
15 About: Lens Usage
16   To be documented
17
18 About: Configuration files
19   This lens applies to /etc/chrony.conf
20
21   See <filter>.
22 *)
23
24 module Chrony =
25   autoload xfm
26
27 (************************************************************************
28  * Group: Import provided expressions
29  ************************************************************************)
30     (* View: empty *)
31     let empty   = Util.empty
32
33     (* View: eol *)
34     let eol     = Util.eol
35
36     (* View: space *)
37     let space   = Sep.space
38
39     (* Variable: email_addr *)
40     let email_addr = Rx.email_addr
41
42     (* Variable: word *)
43     let word       = Rx.word
44
45     (* Variable: integer *)
46     let integer    = Rx.relinteger
47
48     (* Variable: decimal *)
49     let decimal    = Rx.reldecimal
50
51     (* Variable: ip *)
52     let ip         = Rx.ip
53
54     (* Variable: path *)
55     let path       = Rx.fspath
56
57 (************************************************************************
58  * Group: Create required expressions
59  ************************************************************************)
60     (* Variable: hex *)
61     let hex = /[0-9a-fA-F]+/
62
63     (* Variable: number *)
64     let number = integer | decimal | decimal . /[eE]/ . integer | hex
65
66     (* Variable: address_re *)
67     let address_re = Rx.ip | Rx.hostname
68
69     (*
70        View: comment
71             from 4.2.1 of the upstream doc
72             Chrony comments start with: ! ; # or % and must be on their own line
73     *)
74     let comment = Util.comment_generic /[ \t]*[!;#%][ \t]*/ "# "
75
76     (* Variable: no_space
77          No spaces or comment characters
78     *)
79     let no_space   = /[^ \t\r\n!;#%]+/
80
81     (* Variable: cmd_options
82          Server/Peer/Pool options with values
83     *)
84     let cmd_options = "asymmetry"
85                     | "certset"
86                     | "extfield"
87                     | "filter"
88                     | "key"
89                     | /maxdelay((dev)?ratio)?/
90                     | /(min|max)poll/
91                     | /(min|max)samples/
92                     | "maxsources"
93                     | "mindelay"
94                     | "offset"
95                     | "polltarget"
96                     | "port"
97                     | "presend"
98                     | "version"
99
100     (* Variable: cmd_flags
101          Server/Peer/Pool options without values
102     *)
103     let cmd_flags = "auto_offline"|"iburst"|"noselect"|"offline"|"prefer"
104                   |"copy"|"require"|"trust"|"xleave"|"burst"|"nts"
105
106     (* Variable: ntp_source
107          Server/Peer/Pool key names
108     *)
109     let ntp_source = "server"|"peer"|"pool"
110
111     (* Variable: allowdeny_types
112          Key names for access configuration
113     *)
114     let allowdeny_types = "allow"|"deny"|"cmdallow"|"cmddeny"
115
116     (* Variable: hwtimestamp_options
117          HW timestamping options with values
118     *)
119     let hwtimestamp_options = "minpoll"|"precision"|"rxcomp"|"txcomp"
120                             |"minsamples"|"maxsamples"|"rxfilter"
121
122     (* Variable: hwtimestamp_flags
123          HW timestamping options without values
124     *)
125     let hwtimestamp_flags = "nocrossts"
126
127     (* Variable: local_options
128          local options with values
129     *)
130     let local_options = "stratum"|"distance"
131
132     (* Variable: local_flags
133          local options without values
134     *)
135     let local_flags = "orphan"
136
137     (* Variable: ratelimit_options
138          Rate limiting options with values
139     *)
140     let ratelimit_options = "interval"|"burst"|"leak"
141
142     (* Variable: refclock_options
143          refclock options with values
144     *)
145     let refclock_options = "refid"|"lock"|"poll"|"dpoll"|"filter"|"rate"
146                             |"minsamples"|"maxsamples"|"offset"|"delay"
147                             |"precision"|"maxdispersion"|"stratum"|"width"
148
149     (* Variable: refclock_flags
150          refclock options without values
151     *)
152     let refclock_flags = "noselect"|"pps"|"prefer"|"require"|"tai"|"trust"
153
154     (* Variable: flags
155          Options without values
156     *)
157     let flags = "dumponexit"
158               | "generatecommandkey"
159               | "lock_all"
160               | "manual"
161               | "noclientlog"
162               | "nosystemcert"
163               | "rtconutc"
164               | "rtcsync"
165
166     (* Variable: log_flags
167         log has a specific options list
168     *)
169     let log_flags = "measurements"|"rawmeasurements"|"refclocks"|"rtc"
170                   |"statistics"|"tempcomp"|"tracking"
171
172     (* Variable: simple_keys
173          Options with single values
174     *)
175     let simple_keys = "acquisitionport" | "authselectmode" | "bindacqaddress"
176                     | "bindaddress" | "bindcmdaddress" | "bindacqdevice"
177                     | "bindcmddevice" | "binddevice" | "clientloglimit"
178                     | "clockprecision" | "combinelimit" | "commandkey"
179                     | "cmdport" | "corrtimeratio" | "driftfile"
180                     | "dscp"
181                     | "dumpdir" | "hwclockfile" | "include" | "keyfile"
182                     | "leapsecmode" | "leapsectz" | "linux_freq_scale"
183                     | "linux_hz" | "logbanner" | "logchange" | "logdir"
184                     | "maxclockerror" | "maxdistance" | "maxdrift"
185                     | "maxjitter" | "maxsamples" | "maxslewrate"
186                     | "maxntsconnections"
187                     | "maxupdateskew" | "minsamples" | "minsources"
188                     | "nocerttimecheck" | "ntsdumpdir" | "ntsntpserver"
189                     | "ntsport" | "ntsprocesses" | "ntsrefresh" | "ntsrotate"
190                     | "ntsservercert" | "ntsserverkey" | "ntstrustedcerts"
191                     | "ntpsigndsocket" | "pidfile" | "ptpport"
192                     | "port" | "reselectdist" | "rtcautotrim" | "rtcdevice"
193                     | "rtcfile" | "sched_priority" | "stratumweight" | "user"
194
195 (************************************************************************
196  * Group: Make some sub-lenses for use in later lenses
197  ************************************************************************)
198     (* View: host_flags *)
199     let host_flags = [ space . key cmd_flags ]
200     (* View: host_options *)
201     let host_options = [ space . key cmd_options . space . store number ]
202     (* View: log_flag_list *)
203     let log_flag_list = [ space . key log_flags ]
204     (* View: store_address *)
205     let store_address = [ label "address" . store address_re ]
206
207 (************************************************************************
208  * Group: Lenses for parsing out sections
209  ************************************************************************)
210     (* View: all_flags
211         options without any arguments
212     *)
213     let all_flags = [ Util.indent . key flags . eol ]
214
215     (* View: kv
216         options with only one arg can be directly mapped to key = value
217     *)
218     let kv = [ Util.indent . key simple_keys . space . (store no_space) . eol ]
219
220     (* Property: Options with multiple values
221     
222       Each of these gets their own parsing block
223       - server|peer|pool <address> <options>
224       - allow|deny|cmdallow|cmddeny [all] [<address[/subnet]>]
225       - log <options>
226       - broadcast <interval> <address> <optional port>
227       - fallbackdrift <min> <max>
228       - hwtimestamp <interface> <options>
229       - initstepslew <threshold> <addr> <optional extra addrs>
230       - local <options>
231       - mailonchange <emailaddress> <threshold>
232       - makestep <threshold> <limit>
233       - maxchange <threshold> <delay> <limit>
234       - ratelimit|cmdratelimit|ntsratelimit <options>
235       - refclock <driver> <parameter> <options>
236       - smoothtime <maxfreq> <maxwander> <options>
237       - tempcomp <sensorfile> <interval> (<t0> <k0> <k1> <k2> | <pointfile> )
238       - confdir|sourcedir <directories>
239     *)
240
241     (* View: host_list
242         Find all NTP sources and their flags/options
243     *)
244     let host_list = [ Util.indent . key ntp_source
245                          . space . store address_re
246                          . ( host_flags | host_options )*
247                          . eol ]
248
249     (* View: allowdeny
250         allow/deny/cmdallow/cmddeny has a specific syntax
251     *)
252     let allowdeny = [ Util.indent . key allowdeny_types
253                         . [ space . key "all" ]?
254                         . ( space . store ( no_space - "all" ) )?
255                         . eol ]
256
257     (* View: log_list
258         log has a specific options list
259     *)
260     let log_list = [ Util.indent . key "log" . log_flag_list+ . eol ]
261
262     (* View: bcast
263          broadcast has specific syntax
264     *)
265     let bcast = [ Util.indent . key "broadcast"
266                       . space . [ label "interval" . store integer ]
267                       . space . store_address
268                       . ( space . [ label "port" . store integer ] )?
269                       . eol ]
270
271     (* View: bcast
272          confdir and sourcedir have specific syntax
273     *)
274     let dir_list = [ Util.indent . key /(conf|source)dir/
275                       . [ label "directory" . space . store no_space ]+
276                       . eol ]
277
278     (* View: fdrift
279          fallbackdrift has specific syntax
280     *)
281     let fdrift = [ Util.indent . key "fallbackdrift"
282                       . space . [ label "min" . store integer ]
283                       . space . [ label "max" . store integer ]
284                       . eol ]
285
286     (* View: hwtimestamp
287          hwtimestamp has specific syntax
288     *)
289     let hwtimestamp = [ Util.indent . key "hwtimestamp"
290                       . space . [ label "interface" . store no_space ]
291                       . ( space . ( [ key hwtimestamp_flags ]
292                          | [ key hwtimestamp_options . space
293                              . store no_space ] )
294                         )*
295                       . eol ]
296     (* View: istepslew
297          initstepslew has specific syntax
298     *)
299     let istepslew = [ Util.indent . key "initstepslew" 
300                          . space . [ label "threshold" . store number ]
301                          . ( space . store_address )+
302                          . eol ]
303
304     (* View: local
305          local has specific syntax
306     *)
307     let local = [ Util.indent . key "local"
308                       . ( space . ( [ key local_flags ]
309                          | [ key local_options . space . store no_space ] )
310                         )*
311                       . eol ]
312
313     (* View: email
314          mailonchange has specific syntax
315     *)
316     let email = [ Util.indent . key "mailonchange" . space
317                      . [ label "emailaddress" . store email_addr ]
318                      . space
319                      . [ label "threshold" . store number ]
320                      . eol ]
321
322     (* View: makestep
323          makestep has specific syntax
324     *)
325     let makestep = [ Util.indent . key "makestep"
326                       . space
327                       . [ label "threshold" . store number ]
328                       . space
329                       . [ label "limit" . store integer ]
330                       . eol ]
331
332     (* View: maxchange
333          maxchange has specific syntax
334     *)
335     let maxchange = [ Util.indent . key "maxchange"
336                       . space
337                       . [ label "threshold" . store number ]
338                       . space
339                       . [ label "delay" . store integer ]
340                       . space
341                       . [ label "limit" . store integer ]
342                       . eol ]
343
344     (* View: ratelimit
345          ratelimit/cmdratelimit has specific syntax
346     *)
347     let ratelimit = [ Util.indent . key /(cmd|nts)?ratelimit/
348                       . [ space . key ratelimit_options
349                               . space . store no_space ]*
350                       . eol ]
351     (* View: refclock
352          refclock has specific syntax
353     *)
354     let refclock = [ Util.indent . key "refclock"
355                       . space
356                       . [ label "driver" . store word ]
357                       . space
358                       . [ label "parameter" . store no_space ]
359                       . ( space . ( [ key refclock_flags ]
360                          | [ key refclock_options . space . store no_space ] )
361                         )*
362                       . eol ]
363
364     (* View: smoothtime
365          smoothtime has specific syntax
366     *)
367     let smoothtime = [ Util.indent . key "smoothtime"
368                       . space
369                       . [ label "maxfreq" . store number ]
370                       . space
371                       . [ label "maxwander" . store number ]
372                       . ( space . [ key "leaponly" ] )?
373                       . eol ]
374
375     (* View: tempcomp
376          tempcomp has specific syntax
377     *)
378     let tempcomp = [ Util.indent . key "tempcomp"
379                       . space
380                       . [ label "sensorfile" . store path ]
381                       . space
382                       . [ label "interval" . store number ]
383                       . space
384                       . ( [ label "t0" . store number ] . space
385                               . [ label "k0" . store number ] . space
386                               . [ label "k1" . store number ] . space
387                               . [ label "k2" . store number ]
388                               | [ label "pointfile" . store path ] )
389                       . eol ]
390
391 (************************************************************************
392  * Group: Final lense summary
393  ************************************************************************)
394 (* View: settings
395  *   All supported chrony settings
396  *)
397 let settings = host_list | allowdeny | log_list | bcast | fdrift | istepslew
398              | local | email | makestep | maxchange | refclock | smoothtime
399              | dir_list | hwtimestamp | ratelimit | tempcomp | kv | all_flags
400
401 (*
402  * View: lns
403  *   The crony lens
404  *)
405 let lns = ( empty | comment | settings )*
406
407 (* View: filter
408  *   The files parsed by default
409  *)
410 let filter = incl "/etc/chrony.conf"
411
412 let xfm = transform lns filter
413