1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 local fs = require "nixio.fs"
6 local tpl = require "luci.template"
7 local ntm = require "luci.model.network".init()
8 local fwm = require "luci.model.firewall".init()
9 local json = require "luci.jsonc"
11 m = Map("network", translate("Interfaces"))
19 local ifaces, netlist = { }, { }
21 for _, net in ipairs(ntm:get_networks()) do
22 if net:name() ~= "loopback" then
23 local zn = net:zonename()
24 local z = zn and fwm:get_zone(zn) or fwm:get_zone_by_network(net:name())
27 if net:is_alias() then
29 elseif net:is_dynamic() then
33 ifaces[#ifaces+1] = net:name()
34 netlist[#netlist+1] = {
35 net:name(), z and z:name() or "-", z, net, w
44 elseif a[5] ~= b[5] then
51 s = m:section(TypedSection, "interface", translate("Interface Overview"))
52 s.template = "admin_network/iface_overview"
55 function s.cfgsections(self)
56 local _, net, sl = nil, nil, { }
58 for _, net in ipairs(netlist) do
65 o = s:option(Value, "__disable__")
67 function o.write(self, sid, value)
69 m:set(sid, "auto", "")
71 m:set(sid, "auto", "0")
77 o = s:option(Value, "__delete__")
79 function o.write(self, sid, value)
84 if fs.access("/etc/init.d/dsl_control") then
85 local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json"))
86 local modemtype = (ok == true)
87 and (type(boarddata) == "table")
88 and (type(boarddata.dsl) == "table")
89 and (type(boarddata.dsl.modem) == "table")
90 and boarddata.dsl.modem.type
92 dsl = m:section(TypedSection, "dsl", translate("DSL"))
95 annex = dsl:option(ListValue, "annex", translate("Annex"))
96 annex:value("a", translate("Annex A + L + M (all)"))
97 annex:value("b", translate("Annex B (all)"))
98 annex:value("j", translate("Annex J (all)"))
99 annex:value("m", translate("Annex M (all)"))
100 annex:value("bdmt", translate("Annex B G.992.1"))
101 annex:value("b2", translate("Annex B G.992.3"))
102 annex:value("b2p", translate("Annex B G.992.5"))
103 annex:value("at1", translate("ANSI T1.413"))
104 annex:value("admt", translate("Annex A G.992.1"))
105 annex:value("alite", translate("Annex A G.992.2"))
106 annex:value("a2", translate("Annex A G.992.3"))
107 annex:value("a2p", translate("Annex A G.992.5"))
108 annex:value("l", translate("Annex L G.992.3 POTS 1"))
109 annex:value("m2", translate("Annex M G.992.3"))
110 annex:value("m2p", translate("Annex M G.992.5"))
112 tone = dsl:option(ListValue, "tone", translate("Tone"))
113 tone:value("", translate("auto"))
114 tone:value("a", translate("A43C + J43 + A43"))
115 tone:value("av", translate("A43C + J43 + A43 + V43"))
116 tone:value("b", translate("B43 + B43C"))
117 tone:value("bv", translate("B43 + B43C + V43"))
119 if modemtype == "vdsl" then
120 xfer_mode = dsl:option(ListValue, "xfer_mode", translate("Encapsulation mode"))
121 xfer_mode:value("", translate("auto"))
122 xfer_mode:value("atm", translate("ATM (Asynchronous Transfer Mode)"))
123 xfer_mode:value("ptm", translate("PTM/EFM (Packet Transfer Mode)"))
125 line_mode = dsl:option(ListValue, "line_mode", translate("DSL line mode"))
126 line_mode:value("", translate("auto"))
127 line_mode:value("adsl", translate("ADSL"))
128 line_mode:value("vdsl", translate("VDSL"))
130 ds_snr = dsl:option(ListValue, "ds_snr_offset", translate("Downstream SNR offset"))
132 for i = -100, 100, 5 do
133 ds_snr:value(i, translatef("%.1f dB", i / 10))
137 firmware = dsl:option(Value, "firmware", translate("Firmware File"))
142 -- Show ATM bridge section if we have the capabilities
143 if fs.access("/usr/sbin/br2684ctl") then
144 atm = m:section(TypedSection, "atm-bridge", translate("ATM Bridges"),
145 translate("ATM bridges expose encapsulated ethernet in AAL5 " ..
146 "connections as virtual Linux network interfaces which can " ..
147 "be used in conjunction with DHCP or PPP to dial into the " ..
148 "provider network."))
153 atm.create = function(self, section)
154 local sid = TypedSection.create(self, section)
157 m.uci:foreach("network", "atm-bridge",
159 local u = tonumber(s.unit)
160 if u ~= nil and u > max_unit then
165 m.uci:set("network", sid, "unit", max_unit + 1)
166 m.uci:set("network", sid, "atmdev", 0)
167 m.uci:set("network", sid, "encaps", "llc")
168 m.uci:set("network", sid, "payload", "bridged")
169 m.uci:set("network", sid, "vci", 35)
170 m.uci:set("network", sid, "vpi", 8)
175 atm:tab("general", translate("General Setup"))
176 atm:tab("advanced", translate("Advanced Settings"))
178 vci = atm:taboption("general", Value, "vci", translate("ATM Virtual Channel Identifier (VCI)"))
179 vpi = atm:taboption("general", Value, "vpi", translate("ATM Virtual Path Identifier (VPI)"))
180 encaps = atm:taboption("general", ListValue, "encaps", translate("Encapsulation mode"))
181 encaps:value("llc", translate("LLC"))
182 encaps:value("vc", translate("VC-Mux"))
184 atmdev = atm:taboption("advanced", Value, "atmdev", translate("ATM device number"))
185 unit = atm:taboption("advanced", Value, "unit", translate("Bridge unit number"))
186 payload = atm:taboption("advanced", ListValue, "payload", translate("Forwarding mode"))
187 payload:value("bridged", translate("bridged"))
188 payload:value("routed", translate("routed"))
192 local network = require "luci.model.network"
193 if network:has_ipv6() then
194 local s = m:section(NamedSection, "globals", "globals", translate("Global network options"))
195 local o = s:option(Value, "ula_prefix", translate("IPv6 ULA-Prefix"))
196 o.datatype = "ip6addr"