+ end
+ end)
+ end
+ return ifname
+end
+
+function protocol.proto(self)
+ return "none"
+end
+
+function protocol.get_i18n(self)
+ local p = self:proto()
+ if p == "none" then
+ return lng.translate("Unmanaged")
+ elseif p == "static" then
+ return lng.translate("Static address")
+ elseif p == "dhcp" then
+ return lng.translate("DHCP client")
+ else
+ return lng.translate("Unknown")
+ end
+end
+
+function protocol.type(self)
+ return self:_get("type")
+end
+
+function protocol.name(self)
+ return self.sid
+end
+
+function protocol.uptime(self)
+ return self:_ubus("uptime") or 0
+end
+
+function protocol.expires(self)
+ local a = tonumber(_uci_state:get("network", self.sid, "lease_acquired"))
+ local l = tonumber(_uci_state:get("network", self.sid, "lease_lifetime"))
+ if a and l then
+ l = l - (nxo.sysinfo().uptime - a)
+ return l > 0 and l or 0
+ end
+ return -1
+end
+
+function protocol.metric(self)
+ return tonumber(_uci_state:get("network", self.sid, "metric")) or 0
+end
+
+function protocol.ipaddr(self)
+ local addrs = self:_ubus("ipv4-address")
+ return addrs and #addrs > 0 and addrs[1].address
+end
+
+function protocol.netmask(self)
+ local addrs = self:_ubus("ipv4-address")
+ return addrs and #addrs > 0 and
+ ipc.IPv4("0.0.0.0/%d" % addrs[1].mask):mask():string()
+end
+
+function protocol.gwaddr(self)
+ local _, route
+ for _, route in ipairs(self:_ubus("route") or { }) do
+ if route.target == "0.0.0.0" and route.mask == 0 then
+ return route.nexthop
+ end
+ end
+end
+
+function protocol.dnsaddrs(self)
+ local dns = { }
+ local _, addr
+ for _, addr in ipairs(self:_ubus("dns-server") or { }) do
+ if not addr:match(":") then
+ dns[#dns+1] = addr