Imported Upstream version 1.8.0
[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: number *)
61     let number = integer | decimal | decimal . /[eE]/ . integer
62
63     (* Variable: address_re *)
64     let address_re = Rx.ip | Rx.hostname
65
66     (*
67        View: comment
68             from 4.2.1 of the upstream doc
69             Chrony comments start with: ! ; # or % and must be on their own line
70     *)
71     let comment = Util.comment_generic /[ \t]*[!;#%][ \t]*/ "# "
72
73     (* Variable: no_space
74          No spaces or comment characters
75     *)
76     let no_space   = /[^ \t\r\n!;#%]+/
77
78     (* Variable: cmd_options
79          Server/Peer/Pool options with values
80     *)
81     let cmd_options = "key"
82                     | /maxdelay((dev)?ratio)?/
83                     | /(min|max)poll/
84                     | /(min|max)samples/
85                     | "maxsources"
86                     | "offset"
87                     | "polltarget"
88                     | "port"
89                     | "presend"
90                     | "version"
91
92     (* Variable: cmd_flags
93          Server/Peer/Pool options without values
94     *)
95     let cmd_flags = "auto_offline"|"iburst"|"noselect"|"offline"|"prefer"
96                   |"require"|"trust"|"xleave"
97
98     (* Variable: ntp_source
99          Server/Peer/Pool key names
100     *)
101     let ntp_source = "server"|"peer"|"pool"
102
103     (* Variable: allowdeny_types
104          Key names for access configuration
105     *)
106     let allowdeny_types = "allow"|"deny"|"cmdallow"|"cmddeny"
107
108     (* Variable: hwtimestamp_options
109          HW timestamping options with values
110     *)
111     let hwtimestamp_options = "minpoll"|"precision"|"rxcomp"|"txcomp"
112
113     (* Variable: hwtimestamp_flags
114          HW timestamping options without values
115     *)
116     let hwtimestamp_flags = "nocrossts"
117
118     (* Variable: local_options
119          local options with values
120     *)
121     let local_options = "stratum"|"distance"
122
123     (* Variable: local_flags
124          local options without values
125     *)
126     let local_flags = "orphan"
127
128     (* Variable: ratelimit_options
129          Rate limiting options with values
130     *)
131     let ratelimit_options = "interval"|"burst"|"leak"
132
133     (* Variable: refclock_options
134          refclock options with values
135     *)
136     let refclock_options = "refid"|"lock"|"poll"|"dpoll"|"filter"|"rate"
137                             |"minsamples"|"maxsamples"|"offset"|"delay"
138                             |"precision"|"maxdispersion"
139
140     (* Variable: refclock_flags
141          refclock options without values
142     *)
143     let refclock_flags = "noselect"|"prefer"|"require"|"trust"
144
145     (* Variable: flags
146          Options without values
147     *)
148     let flags = "dumponexit"
149               | "generatecommandkey"
150               | "lock_all"
151               | "manual"
152               | "noclientlog"
153               | "rtconutc"
154               | "rtcsync"
155
156     (* Variable: log_flags
157         log has a specific options list
158     *)
159     let log_flags = "measurements"|"rawmeasurements"|"refclocks"|"rtc"
160                   |"statistics"|"tempcomp"|"tracking"
161
162     (* Variable: simple_keys
163          Options with single values
164     *)
165     let simple_keys = "acquisitionport" | "bindacqaddress"
166                     | "bindaddress" | "bindcmdaddress" | "clientloglimit"
167                     | "combinelimit" | "commandkey"
168                     | "cmdport" | "corrtimeratio" | "driftfile"
169                     | "dumpdir" | "hwclockfile" | "include" | "keyfile"
170                     | "leapsecmode" | "leapsectz" | "linux_freq_scale"
171                     | "linux_hz" | "logbanner" | "logchange" | "logdir"
172                     | "maxclockerror" | "maxdistance" | "maxdrift"
173                     | "maxjitter" | "maxsamples" | "maxslewrate"
174                     | "maxupdateskew" | "minsamples" | "minsources"
175                     | "ntpsigndsocket" | "pidfile"
176                     | "port" | "reselectdist" | "rtcautotrim" | "rtcdevice"
177                     | "rtcfile" | "sched_priority" | "stratumweight" | "user"
178
179 (************************************************************************
180  * Group: Make some sub-lenses for use in later lenses
181  ************************************************************************)
182     (* View: host_flags *)
183     let host_flags = [ space . key cmd_flags ]
184     (* View: host_options *)
185     let host_options = [ space . key cmd_options . space . store number ]
186     (* View: log_flag_list *)
187     let log_flag_list = [ space . key log_flags ]
188     (* View: store_address *)
189     let store_address = [ label "address" . store address_re ]
190
191 (************************************************************************
192  * Group: Lenses for parsing out sections
193  ************************************************************************)
194     (* View: all_flags
195         options without any arguments
196     *)
197     let all_flags = [ Util.indent . key flags . eol ]
198
199     (* View: kv
200         options with only one arg can be directly mapped to key = value
201     *)
202     let kv = [ Util.indent . key simple_keys . space . (store no_space) . eol ]
203
204     (* Property: Options with multiple values
205     
206       Each of these gets their own parsing block
207       - server|peer|pool <address> <options>
208       - allow|deny|cmdallow|cmddeny [all] [<address[/subnet]>]
209       - log <options>
210       - broadcast <interval> <address> <optional port>
211       - fallbackdrift <min> <max>
212       - hwtimestamp <interface> <options>
213       - initstepslew <threshold> <addr> <optional extra addrs>
214       - local <options>
215       - mailonchange <emailaddress> <threshold>
216       - makestep <threshold> <limit>
217       - maxchange <threshold> <delay> <limit>
218       - ratelimit|cmdratelimit <options>
219       - refclock <driver> <parameter> <options>
220       - smoothtime <maxfreq> <maxwander> <options>
221       - tempcomp <sensorfile> <interval> (<t0> <k0> <k1> <k2> | <pointfile> )
222     *)
223
224     (* View: host_list
225         Find all NTP sources and their flags/options
226     *)
227     let host_list = [ Util.indent . key ntp_source
228                          . space . store address_re
229                          . ( host_flags | host_options )*
230                          . eol ]
231
232     (* View: allowdeny
233         allow/deny/cmdallow/cmddeny has a specific syntax
234     *)
235     let allowdeny = [ Util.indent . key allowdeny_types
236                         . [ space . key "all" ]?
237                         . ( space . store ( no_space - "all" ) )?
238                         . eol ]
239
240     (* View: log_list
241         log has a specific options list
242     *)
243     let log_list = [ Util.indent . key "log" . log_flag_list+ . eol ]
244
245     (* View: bcast
246          broadcast has specific syntax
247     *)
248     let bcast = [ Util.indent . key "broadcast"
249                       . space . [ label "interval" . store integer ]
250                       . space . store_address
251                       . ( space . [ label "port" . store integer ] )?
252                       . eol ]
253
254     (* View: fdrift
255          fallbackdrift has specific syntax
256     *)
257     let fdrift = [ Util.indent . key "fallbackdrift"
258                       . space . [ label "min" . store integer ]
259                       . space . [ label "max" . store integer ]
260                       . eol ]
261
262     (* View: hwtimestamp
263          hwtimestamp has specific syntax
264     *)
265     let hwtimestamp = [ Util.indent . key "hwtimestamp"
266                       . space . [ label "interface" . store no_space ]
267                       . ( space . ( [ key hwtimestamp_flags ]
268                          | [ key hwtimestamp_options . space . store number ] )
269                         )*
270                       . eol ]
271     (* View: istepslew
272          initstepslew has specific syntax
273     *)
274     let istepslew = [ Util.indent . key "initstepslew" 
275                          . space . [ label "threshold" . store number ]
276                          . ( space . store_address )+
277                          . eol ]
278
279     (* View: local
280          local has specific syntax
281     *)
282     let local = [ Util.indent . key "local"
283                       . ( space . ( [ key local_flags ]
284                          | [ key local_options . space . store no_space ] )
285                         )*
286                       . eol ]
287
288     (* View: email
289          mailonchange has specific syntax
290     *)
291     let email = [ Util.indent . key "mailonchange" . space
292                      . [ label "emailaddress" . store email_addr ]
293                      . space
294                      . [ label "threshold" . store number ]
295                      . eol ]
296
297     (* View: makestep
298          makestep has specific syntax
299     *)
300     let makestep = [ Util.indent . key "makestep"
301                       . space
302                       . [ label "threshold" . store number ]
303                       . space
304                       . [ label "limit" . store integer ]
305                       . eol ]
306
307     (* View: maxchange
308          maxchange has specific syntax
309     *)
310     let maxchange = [ Util.indent . key "maxchange"
311                       . space
312                       . [ label "threshold" . store number ]
313                       . space
314                       . [ label "delay" . store integer ]
315                       . space
316                       . [ label "limit" . store integer ]
317                       . eol ]
318
319     (* View: ratelimit
320          ratelimit/cmdratelimit has specific syntax
321     *)
322     let ratelimit = [ Util.indent . key /(cmd)?ratelimit/
323                       . [ space . key ratelimit_options
324                               . space . store no_space ]*
325                       . eol ]
326     (* View: refclock
327          refclock has specific syntax
328     *)
329     let refclock = [ Util.indent . key "refclock"
330                       . space
331                       . [ label "driver" . store word ]
332                       . space
333                       . [ label "parameter" . store no_space ]
334                       . ( space . ( [ key refclock_flags ]
335                          | [ key refclock_options . space . store no_space ] )
336                         )*
337                       . eol ]
338
339     (* View: smoothtime
340          smoothtime has specific syntax
341     *)
342     let smoothtime = [ Util.indent . key "smoothtime"
343                       . space
344                       . [ label "maxfreq" . store number ]
345                       . space
346                       . [ label "maxwander" . store number ]
347                       . ( space . [ key "leaponly" ] )?
348                       . eol ]
349
350     (* View: tempcomp
351          tempcomp has specific syntax
352     *)
353     let tempcomp = [ Util.indent . key "tempcomp"
354                       . space
355                       . [ label "sensorfile" . store path ]
356                       . space
357                       . [ label "interval" . store number ]
358                       . space
359                       . ( [ label "t0" . store number ] . space
360                               . [ label "k0" . store number ] . space
361                               . [ label "k1" . store number ] . space
362                               . [ label "k2" . store number ]
363                               | [ label "pointfile" . store path ] )
364                       . eol ]
365
366 (************************************************************************
367  * Group: Final lense summary
368  ************************************************************************)
369 (* View: settings
370  *   All supported chrony settings
371  *)
372 let settings = host_list | allowdeny | log_list | bcast | fdrift | istepslew
373              | local | email | makestep | maxchange | refclock | smoothtime
374              | hwtimestamp | ratelimit | tempcomp | kv | all_flags
375
376 (*
377  * View: lns
378  *   The crony lens
379  *)
380 let lns = ( empty | comment | settings )*
381
382 (* View: filter
383  *   The files parsed by default
384  *)
385 let filter = incl "/etc/chrony.conf"
386
387 let xfm = transform lns filter
388