1 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local netmod = luci.model.network
5 local device = luci.util.class(netmod.interface)
7 netmod:register_pattern_virtual("^relay%-%w")
9 local proto = netmod:register_protocol("relay")
11 function proto.get_i18n(self)
12 return luci.i18n.translate("Relay bridge")
15 function proto.ifname(self)
16 return "relay-" .. self.sid
19 function proto.opkg_package(self)
23 function proto.is_installed(self)
24 return nixio.fs.access("/etc/init.d/relayd")
27 function proto.is_floating(self)
31 function proto.is_virtual(self)
35 function proto.is_up(self)
36 local iface = self:get_interface()
37 return iface and iface:is_up() or false
40 function proto.get_interface(self)
41 return device(self.sid, self)
44 function proto.get_interfaces(self)
45 if not self.ifaces then
49 for net in luci.util.imatch(self:_get("network")) do
50 net = netmod:get_network(net)
52 dev = net:get_interface()
59 for dev in luci.util.imatch(self:_get("ifname")) do
60 dev = netmod:get_interface(dev)
68 for _, dev in luci.util.kspairs(ifs) do
69 self.ifaces[#self.ifaces+1] = dev
76 function proto.uptime(self)
79 for net in luci.util.imatch(self:_get("network")) do
80 net = netmod:get_network(net)
82 upt = math.max(upt, net:uptime())
88 function proto.errors(self)
93 function device.__init__(self, ifname, network)
95 self.network = network
98 function device.type(self)
102 function device.is_up(self)
105 for _, dev in ipairs(self.network:get_interfaces()) do
106 if not dev:is_up() then
115 function device._stat(self, what)
119 for _, dev in ipairs(self.network:get_interfaces()) do
120 v = v + dev[what](dev)
126 function device.rx_bytes(self) return self:_stat("rx_bytes") end
127 function device.tx_bytes(self) return self:_stat("tx_bytes") end
128 function device.rx_packets(self) return self:_stat("rx_packets") end
129 function device.tx_packets(self) return self:_stat("tx_packets") end
131 function device.mac(self)
134 for _, dev in ipairs(self.network:get_interfaces()) do
140 function device.ipaddrs(self)
143 addrs[1] = luci.ip.IPv4(self.network:_get("ipaddr"))
148 function device.ip6addrs(self)
152 function device.shortname(self)
153 return "%s %q" % { luci.i18n.translate("Relay"), self.ifname }
156 function device.get_type_i18n(self)
157 return luci.i18n.translate("Relay Bridge")