Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / interfaces.aug
1 (* Interfaces module for Augeas
2  Author: Free Ekanayaka <free@64studio.com>
3
4  Reference: man interfaces
5
6 *)
7
8 module Interfaces =
9    autoload xfm
10
11 (************************************************************************
12  *                           USEFUL PRIMITIVES
13  *************************************************************************)
14
15 let eol        = Util.eol
16
17 (* Define separators *)
18
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]*)/ " "
22
23 (* Define fields *)
24 let sto_to_eol = store /([^\\ \t\n].*[^\\ \t\n]|[^\\ \t\n])/ . eol
25 let sto_to_spc = store /[^\\ \t\n]+/
26
27 (* Define comments and empty lines *)
28
29 (* note that the comment definition from Util does not support *)
30 (* splitting lines with a backlash                             *)
31 let comment    = Util.comment
32
33 let empty      = Util.empty
34
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 ]
38
39 (* Define reserved words and multi-value options *)
40 let stanza_word =
41    /(source(-directory)?|iface|auto|allow-[a-z-]+|mapping|bond-slaves|bridge-ports)/
42
43 (* Define stanza option indentation *)
44 let stanza_indent = del /[ \t]*/ "   "
45
46 (* Define additional lines for multi-line stanzas *)
47 let stanza_option = [  stanza_indent
48                      . key  ( /[a-z0-9_-]+/ - stanza_word )
49                      . sep_spc
50                      . sto_to_eol ]
51
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 ]+
55
56 (************************************************************************
57  *                              AUTO
58  *************************************************************************)
59
60 let auto = [ array /(allow-)?auto/ "auto" . eol ]
61
62 (************************************************************************
63  *                              GENERIC ALLOW
64  *************************************************************************)
65
66 let allow = [ key ( /allow-[a-z-]+/ - "allow-auto" )
67              . counter "allow_seq"
68              . [ sep_spc . seq "allow_seq" . sto_to_spc ]+
69              . eol ]
70
71 (************************************************************************
72  *                              MAPPING
73  *************************************************************************)
74
75 let mapping = [ stanza_id "mapping"
76                . eol
77                . (stanza_option|comment|empty)+ ]
78
79 (************************************************************************
80  *                              IFACE
81  *************************************************************************)
82
83 let multi_option (t:string) = [ stanza_indent . array t t . eol ]
84
85 let iface   = [ Util.indent
86               . stanza_id    "iface"
87               . stanza_param "family"
88               . stanza_param "method"
89               . eol
90               . ( stanza_option
91                 | multi_option "bond-slaves"
92                 | multi_option "bridge-ports"
93                 | comment
94                 | empty )* ]
95
96 (************************************************************************
97  *                              SOURCE
98  *************************************************************************)
99
100 let source = [ key "source" . sep_spc . sto_to_eol ]
101
102 (************************************************************************
103  *                              SOURCE-DIRECTORY
104  *************************************************************************)
105
106 let source_directory = [ key "source-directory" . sep_spc . sto_to_eol ]
107
108 (************************************************************************
109  *                              STANZAS
110  *************************************************************************)
111
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 *)
117
118 let stanza_single = (auto|allow|source|source_directory) . (comment|empty)*
119 let stanza_multi  = iface|mapping
120
121 (************************************************************************
122  *                              LENS & FILTER
123  *************************************************************************)
124
125    let lns = (comment|empty)* . (stanza_multi | stanza_single)*
126
127    let filter = (incl "/etc/network/interfaces")
128                 . (incl "/etc/network/interfaces.d/*")
129                 . Util.stdexcl
130
131    let xfm = transform lns filter