1 -- Copyright 2011 Jo-Philipp Wich <xm@subsignal.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.get_interface(self)
36 return device(self.sid, self)
39 function proto.get_interfaces(self)
40 if not self.ifaces then
44 for net in luci.util.imatch(self:_get("network")) do
45 net = netmod:get_network(net)
47 dev = net:get_interface()
54 for dev in luci.util.imatch(self:_get("ifname")) do
55 dev = netmod:get_interface(dev)
63 for _, dev in luci.util.kspairs(ifs) do
64 self.ifaces[#self.ifaces+1] = dev
71 function proto.uptime(self)
74 for net in luci.util.imatch(self:_get("network")) do
75 net = netmod:get_network(net)
77 upt = math.max(upt, net:uptime())
84 function device.__init__(self, ifname, network)
86 self.network = network
89 function device.type(self)
93 function device.is_up(self)
96 for _, dev in ipairs(self.network:get_interfaces()) do
97 if not dev:is_up() then
106 function device._stat(self, what)
110 for _, dev in ipairs(self.network:get_interfaces()) do
111 v = v + dev[what](dev)
117 function device.rx_bytes(self) return self:_stat("rx_bytes") end
118 function device.tx_bytes(self) return self:_stat("tx_bytes") end
119 function device.rx_packets(self) return self:_stat("rx_packets") end
120 function device.tx_packets(self) return self:_stat("tx_packets") end
122 function device.mac(self)
125 for _, dev in ipairs(self.network:get_interfaces()) do
131 function device.ipaddrs(self)
134 addrs[1] = luci.ip.IPv4(self.network:_get("ipaddr"))
139 function device.ip6addrs(self)
143 function device.shortname(self)
144 return "%s %q" % { luci.i18n.translate("Relay"), self.ifname }
147 function device.get_type_i18n(self)
148 return luci.i18n.translate("Relay Bridge")