Imported Upstream version 1.3.0
[platform/upstream/augeas.git] / lenses / resolv.aug
1 (*
2 Module: Resolv
3   Parses /etc/resolv.conf
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man resolv.conf` where possible.
9
10 About: Licence
11   This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14
15 About: Configuration files
16   This lens applies to /etc/resolv.conf. See <filter>.
17 *)
18
19 module Resolv =
20 autoload xfm
21
22 (************************************************************************
23  * Group:                 USEFUL PRIMITIVES
24  *************************************************************************)
25
26 (* View: comment *)
27 let comment = Util.comment_generic /[ \t]*[;#][ \t]*/ "# "
28
29 (* View: comment_eol *)
30 let comment_eol = Util.comment_generic /[ \t]*[;#][ \t]*/ " # "
31
32 (* View: empty *)
33 let empty = Util.empty
34
35
36 (************************************************************************
37  * Group:                 MAIN OPTIONS
38  *************************************************************************)
39
40 (* View: netmask
41 A network mask for IP addresses *)
42 let netmask = [ label "netmask" . Util.del_str "/" . store Rx.ip ]
43
44 (* View: ipaddr 
45 An IP address or range with an optional mask *) 
46 let ipaddr = [label "ipaddr" . store Rx.ip . netmask?]
47
48
49 (* View: nameserver
50      A nameserver entry *)
51 let nameserver = Build.key_value_line_comment
52                     "nameserver" Sep.space (store Rx.ip) comment_eol
53
54 (* View: domain *)
55 let domain = Build.key_value_line_comment
56                     "domain" Sep.space (store Rx.word) comment_eol
57
58 (* View: search *)
59 let 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 *)
67 let 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 *)
75 let 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 *)
85 let 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 *)
100 let ip6_dotint = 
101   let negate = [ del "no-" "no-" . label "negate" ]
102     in [ negate? . key "ip6-dotint" ]
103
104 (* View: options 
105      Options values *)
106 let 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 *)
122 let entry = nameserver
123           | domain
124           | search
125           | sortlist
126           | options
127           | lookup
128           | family
129
130 (* View: lns *)
131 let lns = ( empty | comment | entry )*
132
133 (* Variable: filter *)
134 let filter = (incl "/etc/resolv.conf")
135
136 let xfm = transform lns filter
137