1(*
2Module: Resolv
3  Parses /etc/resolv.conf
4
5Author: Raphael Pinson <raphink@gmail.com>
6
7About: Reference
8  This lens tries to keep as close as possible to `man resolv.conf` where possible.
9
10About: Licence
11  This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13About: Lens Usage
14
15About: Configuration files
16  This lens applies to /etc/resolv.conf. See <filter>.
17*)
18
19module Resolv =
20autoload xfm
21
22(************************************************************************
23 * Group:                 USEFUL PRIMITIVES
24 *************************************************************************)
25
26(* View: comment *)
27let comment = Util.comment_generic /[ \t]*[;#][ \t]*/ "# "
28
29(* View: comment_eol *)
30let comment_eol = Util.comment_generic /[ \t]*[;#][ \t]*/ " # "
31
32(* View: empty *)
33let empty = Util.empty_generic_dos /[ \t]*[#;]?[ \t]*/
34
35
36(************************************************************************
37 * Group:                 MAIN OPTIONS
38 *************************************************************************)
39
40(* View: netmask
41A network mask for IP addresses *)
42let netmask = [ label "netmask" . Util.del_str "/" . store Rx.ip ]
43
44(* View: ipaddr
45An IP address or range with an optional mask *)
46let ipaddr = [label "ipaddr" . store Rx.ip . netmask?]
47
48
49(* View: nameserver
50     A nameserver entry *)
51let nameserver = Build.key_value_line_comment
52                    "nameserver" Sep.space (store Rx.ip) comment_eol
53
54(* View: domain *)
55let domain = Build.key_value_line_comment
56                    "domain" Sep.space (store Rx.word) comment_eol
57
58(* View: search *)
59let search = Build.key_value_line_comment
60                    "search" Sep.space
61                    (Build.opt_list
62                           [label "domain" . store Rx.word]
63                            Sep.space)
64                    comment_eol
65
66(* View: sortlist *)
67let sortlist = Build.key_value_line_comment
68                    "sortlist" Sep.space
69                    (Build.opt_list
70                           ipaddr
71                           Sep.space)
72                    comment_eol
73
74(* View: lookup *)
75let lookup =
76  let lookup_entry = Build.flag("bind"|"file"|"yp")
77    in Build.key_value_line_comment
78             "lookup" Sep.space
79             (Build.opt_list
80                    lookup_entry
81                    Sep.space)
82             comment_eol
83
84(* View: family *)
85let family =
86  let family_entry = Build.flag("inet4"|"inet6")
87    in Build.key_value_line_comment
88             "family" Sep.space
89             (Build.opt_list
90                    family_entry
91                    Sep.space)
92             comment_eol
93
94(************************************************************************
95 * Group:                 SPECIAL OPTIONS
96 *************************************************************************)
97
98(* View: ip6_dotint
99     ip6-dotint option, which supports negation *)
100let ip6_dotint =
101  let negate = [ del "no-" "no-" . label "negate" ]
102    in [ negate? . key "ip6-dotint" ]
103
104(* View: options
105     Options values *)
106let options =
107      let options_entry = Build.key_value ("ndots"|"timeout"|"attempts")
108                                          (Util.del_str ":") (store Rx.integer)
109                        | Build.flag ("debug"|"rotate"|"no-check-names"
110                                     |"inet6"|"ip6-bytestring"|"edns0"
111				     |"single-request-reopen")
112                        | ip6_dotint
113
114            in Build.key_value_line_comment
115                    "options" Sep.space
116                    (Build.opt_list
117                           options_entry
118                           Sep.space)
119                    comment_eol
120
121(* View: entry *)
122let entry = nameserver
123          | domain
124          | search
125          | sortlist
126          | options
127          | lookup
128          | family
129
130(* View: lns *)
131let lns = ( empty | comment | entry )*
132
133(* Variable: filter *)
134let filter = (incl "/etc/resolv.conf")
135
136let xfm = transform lns filter
137