summaryrefslogtreecommitdiff
path: root/bird1-openwrt/bird1-ipv4-openwrt/src/model/gen_proto.lua
blob: 1544d18f5ecabc48983015bbe0ee21ddfe81d23e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
--[[ 
Copyright (C) 2014-2017 - Eloi Carbo

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
--]]

require("luci.sys")
local http = require "luci.http"
local uci = luci.model.uci.cursor()

-- Repeated Strings
local common_string = "Valid options are:<br />" .. "1. all (All the routes)<br />" .. "2. none (No routes)<br />" .. "3. filter <b>Your_Filter_Name</b>      (Call a specific filter from any of the available in the filters files)"
local imp_string = "Set if the protocol must import routes.<br />" .. common_string
local exp_string = "Set if the protocol must export routes.<br />" .. common_string

m=Map("bird4", "Bird4 general protocol's configuration.")

-- Optional parameters lists
local protoptions = {
	{["name"]="table", ["help"]="Auxiliar table for routing", ["depends"]={"static","kernel"}},
	{["name"]="import", ["help"]=imp_string, ["depends"]={"kernel"}},
	{["name"]="export", ["help"]=exp_string, ["depends"]={"kernel"}},
	{["name"]="scan_time", ["help"]="Time between scans", ["depends"]={"kernel","device"}},
	{["name"]="kernel_table", ["help"]="Set which table must be used as auxiliar kernel table", ["depends"]={"kernel"}},
	{["name"]="learn", ["help"]="Learn routes", ["depends"]={"kernel"}},
	{["name"]="persist", ["help"]="Store routes. After a restart, routes willstill be configured", ["depends"]={"kernel"}}
}

local routeroptions = {
	{["name"]="prefix",["help"]="",["depends"]={"router","special","iface","multipath","recursive"}},
	{["name"]="via",["help"]="",["depends"]={"router","multipath"}},
	{["name"]="attribute",["help"]="",["depends"]={"special"}},
	{["name"]="iface",["help"]="",["depends"]={"iface"}},
	{["name"]="ip",["help"]="",["depends"]={"recursive"}}
}


--
-- KERNEL PROTOCOL
--
sect_kernel_protos = m:section(TypedSection, "kernel", "Kernel options", "Configuration of the kernel protocols. First Instance MUST be Primary table (no table or kernel_table fields).")
sect_kernel_protos.addremove = true
sect_kernel_protos.anonymous = false

-- Default kernel parameters
disabled = sect_kernel_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
disabled.default=0

-- Optional parameters
for _,o in ipairs(protoptions) do
	if o.name ~= nil then
		for _, d in ipairs(o.depends) do
			if d == "kernel" then
				if o.name == "learn" or o.name == "persist" then
					value = sect_kernel_protos:option(Flag, o.name, translate(o.name), translate(o.help))
				elseif o.name == "table" then 
					value = sect_kernel_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
					uci:foreach("bird4", "table",
						function (s)
							value:value(s.name)
						end)
					value:value("")
					value.default = ""
				else
					value = sect_kernel_protos:option(Value, o.name, translate(o.name), translate(o.help))
				end
				value.optional = true
				value.rmempty = true
			end
		end

	end
end


--
-- DEVICE PROTOCOL
--
sect_device_protos = m:section(TypedSection, "device", "Device options", "Configuration of the device protocols.")
sect_device_protos.addremove = true
sect_device_protos.anonymous = false

-- Default kernel parameters

disabled = sect_device_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
disabled.default=0

-- Optional parameters
for _,o in ipairs(protoptions) do
	if o.name ~= nil then
		for _, d in ipairs(o.depends) do
			if d == "device" then
				value = sect_device_protos:option(Value, o.name, translate(o.name), translate(o.help))
				value.optional = true
				value.rmempty = true
			end
		end
	end
end


--
-- PIPE PROTOCOL
--
sect_pipe_protos = m:section(TypedSection, "pipe", "Pipe options",     "Configuration of the Pipe protocols.")
sect_pipe_protos.addremove = true
sect_pipe_protos.anonymous = false

-- Default Pipe parameters
disabled = sect_pipe_protos:option(Flag, "disabled", "Disabled", "If this  option is true, the protocol will not be configured. This protocol will connect the configured 'Table' to the 'Peer Table'.")
disabled.default=0

table = sect_pipe_protos:option(ListValue, "table", "Table", "Select the Primary Table to connect.")
table.optional = false
uci:foreach("bird4", "table",
  function (s)
    table:value(s.name)
  end)
table:value("")
table.default = ""

peer_table = sect_pipe_protos:option(ListValue, "peer_table", "Peer Table", "Select the Secondary Table to connect.")
table.optional = false
uci:foreach("bird4", "table",
  function (s)
    peer_table:value(s.name)
  end)
peer_table:value("")
peer_table.default = ""

mode = sect_pipe_protos:option(ListValue, "mode", "Mode", "Select <b>transparent</b> to retransmit all routes and their attributes<br />Select <b>opaque</b> to retransmit optimal routes (similar to what other protocols do)")
mode.optional = false
mode:value("transparent")
mode:value("opaque")
mode.default = "transparent"

import = sect_pipe_protos:option(Value, "import", "Import",imp_string)
import.optional=true

export = sect_pipe_protos:option(Value, "export", "Export", exp_string)
export.optional=true


--
-- DIRECT PROTOCOL
--
sect_direct_protos = m:section(TypedSection, "direct", "Direct options", "Configuration of the Direct protocols.")
sect_direct_protos.addremove = true
sect_direct_protos.anonymous = false

-- Default Direct parameters
disabled = sect_direct_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured. This protocol will connect the configured 'Table' to the 'Peer Table'.")
disabled.optional = false
disabled.default = 0

interface = sect_direct_protos:option(Value, "interface", "Interfaces", "By default Direct will generate device routes for all the interfaces. To restrict this behaviour, select a number of patterns to match your desired interfaces:" .. "<br />" .. "1. All the strings <b>MUST</b> be quoted: \"pattern\"" .. "<br />" .. "2. Use * (star) to match patterns: \"eth*\" (<b>include</b> all eth... interfaces)" .. "<br />" .. "3. You can add \"-\" (minus) to exclude patterns: \"-em*\" (<b>exclude</b> all em... interfaces)." .. "<br />" .. "4. Separate several patterns using , (coma): \"-em*\", \"eth*\" (<b>exclude</b> em... and <b>include</b> all eth... interfaces).")
interface.optional = false
interface.default = "\"*\""


--
-- STATIC PROTOCOL
--
sect_static_protos = m:section(TypedSection, "static", "Static options", "Configuration of the static protocols.")
sect_static_protos.addremove = true
sect_static_protos.anonymous = false

-- Default kernel parameters
disabled = sect_static_protos:option(Flag, "disabled", "Disabled", "If this option is true, the protocol will not be configured.")
disabled.default=0

-- Optional parameters
for _,o in ipairs(protoptions) do
    if o.name ~= nil then
        for _, d in ipairs(o.depends) do
            if d == "static" then
                if o.name == "table" then
                    value = sect_static_protos:option(ListValue, o.name, translate(o.name), translate(o.help))
                    uci:foreach("bird4", "table",
                        function (s)
                            value:value(s.name)
                        end)
                    value:value("")
                    value.default = ""
                else
                    value = sect_static_protos:option(Value, o.name, translate(o.name), translate(o.help))
                end
                    value.optional = true
                    value.rmempty = true
            end
        end
    end
end


--
-- ROUTES FOR STATIC PROTOCOL
--
sect_routes = m:section(TypedSection, "route", "Routes configuration", "Configuration of the routes used in static protocols.")
sect_routes.addremove = true
sect_routes.anonymous = true

instance = sect_routes:option(ListValue, "instance", "Route instance", "")
i = 0
uci:foreach("bird4", "static",
	function (s)
		instance:value(s[".name"])
	end)

prefix = sect_routes:option(Value, "prefix", "Route prefix", "")

type = sect_routes:option(ListValue, "type", "Type of route", "")
type:value("router")
type:value("special")
type:value("iface")
type:value("recursive")
type:value("multipath")

valueVia = sect_routes:option(Value, "via", "Via", "")
valueVia.optional = false
valueVia:depends("type", "router")
valueVia.datatype = "ip4addr"

listVia = sect_routes:option(DynamicList, "l_via", "Via", "")
listVia:depends("type", "multipath")
listVia.optional=false
listVia.datatype = "ip4addr"

attribute = sect_routes:option(ListValue, "attribute", "Attribute", "")
attribute:depends("type", "special")
attribute:value("unreachable")
attribute:value("prohibit")
attribute:value("blackhole")

iface  = sect_routes:option(ListValue, "iface", "Interface", "")
iface:depends("type", "iface")
uci:foreach("network", "interface",
	function(section)
        if section[".name"] ~= "loopback" then
            iface:value(section[".name"])
        end
	end)

ip =  sect_routes:option(Value, "ip", "IP address", "")
ip:depends("type", "ip")
ip.datatype = [[ or"ip4addr", "ip6addr" ]]

function m.on_commit(self,map)
        luci.sys.exec('/etc/init.d/bird4 restart')
end

return m