1 (* Interfaces module for Augeas
2 Author: Free Ekanayaka <free@64studio.com>
4 Reference: man interfaces
11 (************************************************************************
13 *************************************************************************)
17 (* Define separators *)
19 (* a line can be extended across multiple lines by making the last *)
20 (* character a backslash *)
21 let sep_spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
24 let sto_to_eol = store /([^\\ \t\n].*[^\\ \t\n]|[^\\ \t\n])/ . eol
25 let sto_to_spc = store /[^\\ \t\n]+/
27 (* Define comments and empty lines *)
29 (* note that the comment definition from Util does not support *)
30 (* splitting lines with a backlash *)
31 let comment = Util.comment
33 let empty = Util.empty
35 (* Define tree stanza_ids *)
36 let stanza_id (t:string) = key t . sep_spc . sto_to_spc
37 let stanza_param (l:string) = [ sep_spc . label l . sto_to_spc ]
39 (* Define reserved words and multi-value options *)
41 /(source(-directory)?|iface|auto|allow-[a-z-]+|mapping|bond-slaves|bridge-ports)/
43 (* Define stanza option indentation *)
44 let stanza_indent = del /[ \t]*/ " "
46 (* Define additional lines for multi-line stanzas *)
47 let stanza_option = [ stanza_indent
48 . key ( /[a-z0-9_-]+/ - stanza_word )
52 (* Define space-separated array *)
53 let array (r:regexp) (t:string) = del r t . label t . counter t
54 . [ sep_spc . seq t . sto_to_spc ]+
56 (************************************************************************
58 *************************************************************************)
60 let auto = [ array /(allow-)?auto/ "auto" . eol ]
62 (************************************************************************
64 *************************************************************************)
66 let allow = [ key ( /allow-[a-z-]+/ - "allow-auto" )
68 . [ sep_spc . seq "allow_seq" . sto_to_spc ]+
71 (************************************************************************
73 *************************************************************************)
75 let mapping = [ stanza_id "mapping"
77 . (stanza_option|comment|empty)+ ]
79 (************************************************************************
81 *************************************************************************)
83 let multi_option (t:string) = [ stanza_indent . array t t . eol ]
85 let iface = [ Util.indent
87 . stanza_param "family"
88 . stanza_param "method"
91 | multi_option "bond-slaves"
92 | multi_option "bridge-ports"
96 (************************************************************************
98 *************************************************************************)
100 let source = [ key "source" . sep_spc . sto_to_eol ]
102 (************************************************************************
104 *************************************************************************)
106 let source_directory = [ key "source-directory" . sep_spc . sto_to_eol ]
108 (************************************************************************
110 *************************************************************************)
112 (* The auto and hotplug stanzas always consist of one line only, while
113 iface and mapping can spand along more lines. Comment nodes are
114 inserted in the tree as direct children of the root node only when they
115 come after an auto or hotplug stanza, otherwise they are considered part
116 of an iface or mapping block *)
118 let stanza_single = (auto|allow|source|source_directory) . (comment|empty)*
119 let stanza_multi = iface|mapping
121 (************************************************************************
123 *************************************************************************)
125 let lns = (comment|empty)* . (stanza_multi | stanza_single)*
127 let filter = (incl "/etc/network/interfaces")
128 . (incl "/etc/network/interfaces.d/*")
131 let xfm = transform lns filter