3 Parses /etc/keepalived/keepalived.conf
5 Author: Raphael Pinson <raphink@gmail.com>
8 This lens tries to keep as close as possible to `man 5 keepalived.conf` where possible.
11 This file is licenced under the LGPL v2+, like the rest of Augeas.
16 About: Configuration files
17 This lens applies to /etc/keepalived/keepalived.conf. See <filter>.
20 The <Test_Keepalived> file contains various examples and tests.
27 (************************************************************************
28 * Group: USEFUL PRIMITIVES
29 *************************************************************************)
31 (* Group: Comments and empty lines *)
34 let indent = Util.indent
40 let opt_eol = del /[ \t]*\n?/ " "
43 let sep_spc = Sep.space
46 Map comments in "#comment" nodes *)
47 let comment = Util.comment_generic /[ \t]*[#!][ \t]*/ "# "
50 Map comments at eol *)
51 let comment_eol = Util.comment_generic /[ \t]*[#!][ \t]*/ " # "
53 (* View: comment_or_eol
54 A <comment_eol> or <eol> *)
55 let comment_or_eol = comment_eol | (del /[ \t]*[#!]?\n/ "\n")
59 let empty = Util.empty
61 (* View: sto_email_addr *)
62 let sto_email_addr = store Rx.email_addr
67 (* Variable: word_slash *)
68 let word_slash = word | "/"
71 let sto_word = store word
74 let sto_num = store Rx.relinteger
77 let sto_ipv6 = store Rx.ipv6
79 (* View: sto_to_eol *)
80 let sto_to_eol = store /[^#! \t\n][^#!\n]*[^#! \t\n]|[^#! \t\n]/
83 let field (kw:regexp) (sto:lens) = indent . Build.key_value_line_comment kw sep_spc sto comment_eol
87 let flag (kw:regexp) = [ indent . key kw . comment_or_eol ]
90 An IP <space> port pair *)
91 let ip_port = [ label "ip" . sto_word ] . sep_spc . [ label "port" . sto_num ]
94 A generic block with a title lens.
95 The definition is very similar to Build.block_newlines
96 but uses a different type of <comment>. *)
97 let lens_block (title:lens) (sto:lens) =
99 . Build.block_newlines sto comment . eol ]
102 A simple block with just a block title *)
103 let block (kw:regexp) (sto:lens) = lens_block (key kw) sto
106 A block with a block title and name *)
107 let named_block (kw:string) (sto:lens) = lens_block (key kw . sep_spc . sto_word) sto
109 (* View: named_block_arg_title
110 A title lens for named_block_arg *)
111 let named_block_arg_title (kw:string) (name:string) (arg:string) =
113 . [ label name . sto_word ]
115 . [ label arg . sto_word ]
117 (* View: named_block_arg
118 A block with a block title, a name and an argument *)
119 let named_block_arg (kw:string) (name:string) (arg:string) (sto:lens) =
120 lens_block (named_block_arg_title kw name arg) sto
123 (************************************************************************
124 * Group: GLOBAL CONFIGURATION
125 *************************************************************************)
128 A simple email address entry *)
129 let email = [ indent . label "email" . sto_email_addr . comment_or_eol ]
131 (* View: global_defs_field
132 Possible fields in the global_defs block *)
133 let global_defs_field =
134 let word_re = "smtp_server"|"lvs_id"|"router_id"|"vrrp_mcast_group4"
135 in let ipv6_re = "vrrp_mcast_group6"
136 in let num_re = "smtp_connect_timeout"
137 in block "notification_email" email
138 | field "notification_email_from" sto_email_addr
139 | field word_re sto_word
140 | field num_re sto_num
141 | field ipv6_re sto_ipv6
144 A global_defs block *)
145 let global_defs = block "global_defs" global_defs_field
148 A prefix for IP addresses *)
149 let prefixlen = [ label "prefixlen" . Util.del_str "/" . sto_num ]
152 An IP address or range with an optional mask *)
153 let ipaddr = label "ipaddr" . store /[0-9.-]+/ . prefixlen?
156 A device for IP addresses *)
157 let ipdev = [ key "dev" . sep_spc . sto_word ]
159 (* View: static_ipaddress_field
160 The whole string is fed to ip addr add.
161 You can truncate the string anywhere you like and let ip addr add use defaults for the rest of the string.
162 To be refined with fields according to `ip addr help`.
164 let static_ipaddress_field = [ indent . ipaddr
168 (* View: static_routes_field
169 src $SRC_IP to $DST_IP dev $SRC_DEVICE
171 let static_routes_field = [ indent . label "route"
172 . [ key "src" . sto_word ] . sep_spc
173 . [ key "to" . sto_word ] . sep_spc
174 . [ key "dev" . sto_word ] . comment_or_eol ]
176 (* View: static_routes *)
177 let static_routes = block "static_ipaddress" static_ipaddress_field
178 | block "static_routes" static_routes_field
182 A global configuration entry *)
183 let global_conf = global_defs | static_routes
186 (************************************************************************
187 * Group: VRRP CONFIGURATION
188 *************************************************************************)
190 (*View: vrrp_sync_group_field *)
191 let vrrp_sync_group_field =
192 let to_eol_re = /notify(_master|_backup|_fault)?/
193 in let flag_re = "smtp_alert"
194 in field to_eol_re sto_to_eol
196 | block "group" [ indent . key word . comment_or_eol ]
198 (* View: vrrp_sync_group *)
199 let vrrp_sync_group = named_block "vrrp_sync_group" vrrp_sync_group_field
201 (* View: vrrp_instance_field *)
202 let vrrp_instance_field =
203 let word_re = "state" | "interface" | "lvs_sync_daemon_interface"
204 in let num_re = "virtual_router_id" | "priority" | "advert_int" | /garp_master_(delay|repeat|refresh|refresh_repeat)/
205 in let to_eol_re = /notify(_master|_backup|_fault)?/ | /(mcast|unicast)_src_ip/
206 in let flag_re = "smtp_alert" | "nopreempt" | "ha_suspend" | "debug" | "use_vmac" | "vmac_xmit_base" | "native_ipv6" | "dont_track_primary" | "preempt_delay"
207 in field word_re sto_word
208 | field num_re sto_num
209 | field to_eol_re sto_to_eol
211 | block "authentication" (
212 field /auth_(type|pass)/ sto_word
214 | block "virtual_ipaddress" static_ipaddress_field
215 | block /track_(interface|script)/ ( flag word )
216 | block "unicast_peer" static_ipaddress_field
218 (* View: vrrp_instance *)
219 let vrrp_instance = named_block "vrrp_instance" vrrp_instance_field
221 (* View: vrrp_script_field *)
222 let vrrp_script_field =
223 let num_re = "interval" | "weight" | "fall" | "raise"
224 in let to_eol_re = "script"
225 in field to_eol_re sto_to_eol
226 | field num_re sto_num
228 (* View: vrrp_script *)
229 let vrrp_script = named_block "vrrp_script" vrrp_script_field
233 contains subblocks of VRRP synchronization group(s) and VRRP instance(s) *)
234 let vrrpd_conf = vrrp_sync_group | vrrp_instance | vrrp_script
237 (************************************************************************
238 * Group: REAL SERVER CHECKS CONFIGURATION
239 *************************************************************************)
241 (* View: tcp_check_field *)
242 let tcp_check_field =
243 let word_re = "bindto"
244 in let num_re = /connect_(timeout|port)/
245 in field word_re sto_word
246 | field num_re sto_num
248 (* View: misc_check_field *)
249 let misc_check_field =
250 let flag_re = "misc_dynamic"
251 in let num_re = "misc_timeout"
252 in let to_eol_re = "misc_path"
253 in field num_re sto_num
255 | field to_eol_re sto_to_eol
257 (* View: smtp_host_check_field *)
258 let smtp_host_check_field =
259 let word_re = "connect_ip" | "bindto"
260 in let num_re = "connect_port"
261 in field word_re sto_word
262 | field num_re sto_num
264 (* View: smtp_check_field *)
265 let smtp_check_field =
266 let word_re = "connect_ip" | "bindto"
267 in let num_re = "connect_timeout" | "retry" | "delay_before_retry"
268 in let to_eol_re = "helo_name"
269 in field word_re sto_word
270 | field num_re sto_num
271 | field to_eol_re sto_to_eol
272 | block "host" smtp_host_check_field
274 (* View: http_url_check_field *)
275 let http_url_check_field =
276 let word_re = "digest"
277 in let num_re = "status_code"
278 in let to_eol_re = "path"
279 in field word_re sto_word
280 | field num_re sto_num
281 | field to_eol_re sto_to_eol
283 (* View: http_check_field *)
284 let http_check_field =
285 let num_re = /connect_(timeout|port)/ | "nb_get_retry" | "delay_before_retry"
286 in field num_re sto_num
287 | block "url" http_url_check_field
289 (* View: real_server_field *)
290 let real_server_field =
291 let num_re = "weight"
292 in let flag_re = "inhibit_on_failure"
293 in let to_eol_re = /notify_(up|down)/
294 in field num_re sto_num
296 | field to_eol_re sto_to_eol
297 | block "TCP_CHECK" tcp_check_field
298 | block "MISC_CHECK" misc_check_field
299 | block "SMTP_CHECK" smtp_check_field
300 | block /(HTTP|SSL)_GET/ http_check_field
302 (************************************************************************
303 * Group: LVS CONFIGURATION
304 *************************************************************************)
306 (* View: virtual_server_field *)
307 let virtual_server_field =
308 let num_re = "delay_loop" | "persistence_timeout" | "quorum" | "hysteresis"
309 in let word_re = /lb_(algo|kind)/ | "nat_mask" | "protocol" | "persistence_granularity"
311 in let flag_re = "ops" | "ha_suspend" | "alpha" | "omega"
312 in let to_eol_re = /quorum_(up|down)/
313 in let ip_port_re = "sorry_server"
314 in field num_re sto_num
315 | field word_re sto_word
317 | field to_eol_re sto_to_eol
318 | field ip_port_re ip_port
319 | named_block_arg "real_server" "ip" "port" real_server_field
321 (* View: virtual_server *)
322 let virtual_server = named_block_arg "virtual_server" "ip" "port" virtual_server_field
324 (* View: virtual_server_group_field *)
325 let virtual_server_group_field = [ indent . label "vip"
328 . [ label "port" . sto_num ]
331 (* View: virtual_server_group *)
332 let virtual_server_group = named_block "virtual_server_group" virtual_server_group_field
335 contains subblocks of Virtual server group(s) and Virtual server(s) *)
336 let lvs_conf = virtual_server | virtual_server_group
342 let lns = ( empty | comment | global_conf | vrrpd_conf | lvs_conf )*
344 (* Variable: filter *)
345 let filter = incl "/etc/keepalived/keepalived.conf"
347 let xfm = transform lns filter