diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-12-03 15:17:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-08 16:26:20 +0100 |
commit | 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch) | |
tree | 35e16f100466e4e00657199b38bb3d87d52bf73f /protocols/luci-proto-relay | |
parent | 9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff) |
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names
* Make each LuCI module its own standalone package
* Deploy a shared luci.mk which is used by each module Makefile
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'protocols/luci-proto-relay')
3 files changed, 256 insertions, 0 deletions
diff --git a/protocols/luci-proto-relay/Makefile b/protocols/luci-proto-relay/Makefile new file mode 100644 index 000000000..d9c04f76a --- /dev/null +++ b/protocols/luci-proto-relay/Makefile @@ -0,0 +1,14 @@ +# +# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org> +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=Support for relayd pseudo bridges +LUCI_DEPENDS:=+relayd + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/protocols/luci-proto-relay/luasrc/model/cbi/admin_network/proto_relay.lua b/protocols/luci-proto-relay/luasrc/model/cbi/admin_network/proto_relay.lua new file mode 100644 index 000000000..017bb9bfa --- /dev/null +++ b/protocols/luci-proto-relay/luasrc/model/cbi/admin_network/proto_relay.lua @@ -0,0 +1,77 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 +]]-- + +local map, section, net = ... + +local ipaddr, network +local forward_bcast, forward_dhcp, gateway, expiry, retry, table + + +ipaddr = section:taboption("general", Value, "ipaddr", + translate("Local IPv4 address"), + translate("Address to access local relay bridge")) + +ipaddr.datatype = "ip4addr" + + +network = s:taboption("general", DynamicList, "network", translate("Relay between networks")) +network.widget = "checkbox" +network.exclude = arg[1] +network.template = "cbi/network_netlist" +network.nocreate = true +network.nobridges = true +network.novirtual = true +network:depends("proto", "relay") + + +forward_bcast = section:taboption("advanced", Flag, "forward_bcast", + translate("Forward broadcast traffic")) + +forward_bcast.default = forward_bcast.enabled + + +forward_dhcp = section:taboption("advanced", Flag, "forward_dhcp", + translate("Forward DHCP traffic")) + +forward_dhcp.default = forward_dhcp.enabled + + +gateway = section:taboption("advanced", Value, "gateway", + translate("Use DHCP gateway"), + translate("Override the gateway in DHCP responses")) + +gateway.datatype = "ip4addr" +gateway:depends("forward_dhcp", forward_dhcp.enabled) + + +expiry = section:taboption("advanced", Value, "expiry", + translate("Host expiry timeout"), + translate("Specifies the maximum amount of seconds after which hosts are presumed to be dead")) + +expiry.placeholder = "30" +expiry.datatype = "min(1)" + + +retry = section:taboption("advanced", Value, "retry", + translate("ARP retry threshold"), + translate("Specifies the maximum amount of failed ARP requests until hosts are presumed to be dead")) + +retry.placeholder = "5" +retry.datatype = "min(1)" + + +table = section:taboption("advanced", Value, "table", + translate("Use routing table"), + translate("Override the table used for internal routes")) + +table.placeholder = "16800" +table.datatype = "range(0,65535)" diff --git a/protocols/luci-proto-relay/luasrc/model/network/proto_relay.lua b/protocols/luci-proto-relay/luasrc/model/network/proto_relay.lua new file mode 100644 index 000000000..42bd1f846 --- /dev/null +++ b/protocols/luci-proto-relay/luasrc/model/network/proto_relay.lua @@ -0,0 +1,165 @@ +--[[ +LuCI - Network model - relay protocol extension + +Copyright 2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +]]-- + +local netmod = luci.model.network +local device = luci.util.class(netmod.interface) + +netmod:register_pattern_virtual("^relay-%w") + +local proto = netmod:register_protocol("relay") + +function proto.get_i18n(self) + return luci.i18n.translate("Relay bridge") +end + +function proto.ifname(self) + return "relay-" .. self.sid +end + +function proto.opkg_package(self) + return "relayd" +end + +function proto.is_installed(self) + return nixio.fs.access("/etc/init.d/relayd") +end + +function proto.is_floating(self) + return true +end + +function proto.is_virtual(self) + return true +end + +function proto.get_interface(self) + return device(self.sid, self) +end + +function proto.get_interfaces(self) + if not self.ifaces then + local ifs = { } + local _, net, dev + + for net in luci.util.imatch(self:_get("network")) do + net = netmod:get_network(net) + if net then + dev = net:get_interface() + if dev then + ifs[dev:name()] = dev + end + end + end + + for dev in luci.util.imatch(self:_get("ifname")) do + dev = netmod:get_interface(dev) + if dev then + ifs[dev:name()] = dev + end + end + + self.ifaces = { } + + for _, dev in luci.util.kspairs(ifs) do + self.ifaces[#self.ifaces+1] = dev + end + end + + return self.ifaces +end + +function proto.uptime(self) + local net + local upt = 0 + for net in luci.util.imatch(self:_get("network")) do + net = netmod:get_network(net) + if net then + upt = math.max(upt, net:uptime()) + end + end + return upt +end + + +function device.__init__(self, ifname, network) + self.ifname = ifname + self.network = network +end + +function device.type(self) + return "tunnel" +end + +function device.is_up(self) + if self.network then + local _, dev + for _, dev in ipairs(self.network:get_interfaces()) do + if not dev:is_up() then + return false + end + end + return true + end + return false +end + +function device._stat(self, what) + local v = 0 + if self.network then + local _, dev + for _, dev in ipairs(self.network:get_interfaces()) do + v = v + dev[what](dev) + end + end + return v +end + +function device.rx_bytes(self) return self:_stat("rx_bytes") end +function device.tx_bytes(self) return self:_stat("tx_bytes") end +function device.rx_packets(self) return self:_stat("rx_packets") end +function device.tx_packets(self) return self:_stat("tx_packets") end + +function device.mac(self) + if self.network then + local _, dev + for _, dev in ipairs(self.network:get_interfaces()) do + return dev:mac() + end + end +end + +function device.ipaddrs(self) + local addrs = { } + if self.network then + addrs[1] = luci.ip.IPv4(self.network:_get("ipaddr")) + end + return addrs +end + +function device.ip6addrs(self) + return { } +end + +function device.shortname(self) + return "%s %q" % { luci.i18n.translate("Relay"), self.ifname } +end + +function device.get_type_i18n(self) + return luci.i18n.translate("Relay Bridge") +end |