Changeset 7607
- Timestamp:
- 10/04/11 15:32:18 (20 months ago)
- Location:
- luci/trunk/libs/core/luasrc/model
- Files:
-
- 4 modified
-
network.lua (modified) (18 diffs)
-
network/proto_6x4.lua (modified) (1 diff)
-
network/proto_ppp.lua (modified) (1 diff)
-
network/proto_relay.lua (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/libs/core/luasrc/model/network.lua
r7605 r7607 39 39 40 40 41 proto = { } 42 proto.generic = utl.class() 41 protocol = utl.class() 42 43 local _protocols = { } 43 44 44 45 local _interfaces, _bridge, _switch, _tunnel … … 272 273 if utl.instanceof(x, interface) then 273 274 return x:name() 274 elseif utl.instanceof(x, proto .generic) then275 elseif utl.instanceof(x, protocol) then 275 276 return x:ifname() 276 277 elseif type(x) == "string" then … … 278 279 end 279 280 end 281 282 function get_protocols(self) 283 local p = { } 284 local _, v 285 for _, v in ipairs(_protocols) do 286 p[#p+1] = v("__dummy__") 287 end 288 return p 289 end 290 291 function register_protocol(self, protoname) 292 local proto = utl.class(protocol) 293 294 function proto.__init__(self, name) 295 self.sid = name 296 end 297 298 function proto.proto(self) 299 return protoname 300 end 301 302 _protocols[#_protocols+1] = proto 303 _protocols[protoname] = proto 304 305 return proto 306 end 307 308 function register_pattern_virtual(self, pat) 309 IFACE_PATTERNS_VIRTUAL[#IFACE_PATTERNS_VIRTUAL+1] = pat 310 end 311 280 312 281 313 function has_ipv6(self) … … 521 553 522 554 523 function network(name )555 function network(name, proto) 524 556 if name then 525 local p = _uci_real:get("network", name, "proto")526 local c = p and proto[p] or proto.generic557 local p = proto or _uci_real:get("network", name, "proto") 558 local c = p and _protocols[p] or protocol 527 559 return c(name) 528 560 end 529 561 end 530 562 531 function proto .generic.__init__(self, name)563 function protocol.__init__(self, name) 532 564 self.sid = name 533 565 end 534 566 535 function proto .generic._get(self, opt)567 function protocol._get(self, opt) 536 568 local v = _uci_real:get("network", self.sid, opt) 537 569 if type(v) == "table" then … … 541 573 end 542 574 543 function proto .generic._ip(self, opt, family, list)575 function protocol._ip(self, opt, family, list) 544 576 local ip = _uci_state:get("network", self.sid, opt) 545 577 local fc = (family == 6) and ipc.IPv6 or ipc.IPv4 … … 559 591 end 560 592 561 function proto .generic.get(self, opt)593 function protocol.get(self, opt) 562 594 return _get("network", self.sid, opt) 563 595 end 564 596 565 function proto .generic.set(self, opt, val)597 function protocol.set(self, opt, val) 566 598 return _set("network", self.sid, opt, val) 567 599 end 568 600 569 function proto .generic.ifname(self)601 function protocol.ifname(self) 570 602 local p = self:proto() 571 603 if self:is_bridge() then … … 600 632 end 601 633 602 function proto.generic.proto(self) 603 return self:_get("proto") or "none" 604 end 605 606 function proto.generic.type(self) 634 function protocol.proto(self) 635 return "none" 636 end 637 638 function protocol.get_i18n(self) 639 local p = self:proto() 640 if p == "none" then 641 return i18n.translate("Unmanaged") 642 elseif p == "static" then 643 return i18n.translate("Static address") 644 elseif p == "dhcp" then 645 return i18n.translate("DHCP client") 646 else 647 return i18n.translate("Unknown") 648 end 649 end 650 651 function protocol.type(self) 607 652 return self:_get("type") 608 653 end 609 654 610 function proto .generic.name(self)655 function protocol.name(self) 611 656 return self.sid 612 657 end 613 658 614 function proto .generic.uptime(self)659 function protocol.uptime(self) 615 660 local cnt = tonumber(_uci_state:get("network", self.sid, "connect_time")) 616 661 if cnt ~= nil then … … 621 666 end 622 667 623 function proto .generic.expires(self)668 function protocol.expires(self) 624 669 local a = tonumber(_uci_state:get("network", self.sid, "lease_acquired")) 625 670 local l = tonumber(_uci_state:get("network", self.sid, "lease_lifetime")) … … 631 676 end 632 677 633 function proto .generic.metric(self)678 function protocol.metric(self) 634 679 return tonumber(_uci_state:get("network", self.sid, "metric")) or 0 635 680 end 636 681 637 function proto .generic.ipaddr(self)682 function protocol.ipaddr(self) 638 683 return self:_ip("ipaddr", 4) 639 684 end 640 685 641 function proto .generic.netmask(self)686 function protocol.netmask(self) 642 687 return self:_ip("netmask", 4) 643 688 end 644 689 645 function proto .generic.gwaddr(self)690 function protocol.gwaddr(self) 646 691 return self:_ip("gateway", 4) 647 692 end 648 693 649 function proto .generic.dnsaddrs(self)694 function protocol.dnsaddrs(self) 650 695 return self:_ip("dns", 4, true) 651 696 end 652 697 653 function proto .generic.ip6addr(self)698 function protocol.ip6addr(self) 654 699 local ip6 = self:_ip("ip6addr", 6) 655 700 if not ip6 then … … 668 713 end 669 714 670 function proto .generic.gw6addr(self)715 function protocol.gw6addr(self) 671 716 local ip6 = self:_ip("ip6gw", 6) 672 717 if not ip6 then … … 679 724 end 680 725 681 function proto .generic.dns6addrs(self)726 function protocol.dns6addrs(self) 682 727 return self:_ip("dns", 6, true) 683 728 end 684 729 685 function proto.generic.is_bridge(self) 686 return (self:type() == "bridge") 687 end 688 689 function proto.generic.is_virtual(self) 730 function protocol.is_bridge(self) 731 return (not self:is_virtual() and self:type() == "bridge") 732 end 733 734 function protocol.opkg_package(self) 735 return nil 736 end 737 738 function protocol.is_installed(self) 739 return true 740 end 741 742 function protocol.is_virtual(self) 690 743 return false 691 744 end 692 745 693 function proto .generic.is_floating(self)746 function protocol.is_floating(self) 694 747 return false 695 748 end 696 749 697 function proto .generic.is_empty(self)750 function protocol.is_empty(self) 698 751 if self:is_virtual() then 699 752 return false … … 717 770 end 718 771 719 function proto .generic.add_interface(self, ifname)772 function protocol.add_interface(self, ifname) 720 773 ifname = _M:ifnameof(ifname) 721 774 if ifname and not self:is_floating() then … … 738 791 end 739 792 740 function proto .generic.del_interface(self, ifname)793 function protocol.del_interface(self, ifname) 741 794 ifname = _M:ifnameof(ifname) 742 795 if ifname and not self:is_floating() then … … 750 803 end 751 804 752 function proto .generic.get_interface(self)805 function protocol.get_interface(self) 753 806 if self:is_virtual() then 754 807 _tunnel[self:proto() .. "-" .. self.sid] = true … … 779 832 end 780 833 781 function proto .generic.get_interfaces(self)834 function protocol.get_interfaces(self) 782 835 if self:is_bridge() or (self:is_virtual() and not self:is_floating()) then 783 836 local ifaces = { } … … 815 868 end 816 869 817 function proto .generic.contains_interface(self, ifname)870 function protocol.contains_interface(self, ifname) 818 871 ifname = _M:ifnameof(ifname) 819 872 if not ifname then … … 841 894 end 842 895 843 function proto .generic.adminlink(self)896 function protocol.adminlink(self) 844 897 return dsp.build_url("admin", "network", "network", self.sid) 845 898 end … … 1341 1394 1342 1395 1396 -- setup base protocols 1397 _M:register_protocol("static") 1398 _M:register_protocol("dhcp") 1399 _M:register_protocol("none") 1400 1343 1401 -- load protocol extensions 1344 1402 local exts = nfs.dir(utl.libpath() .. "/model/network") -
luci/trunk/libs/core/luasrc/model/network/proto_6x4.lua
r7605 r7607 19 19 20 20 local netmod = luci.model.network 21 local proto = luci.util.class(netmod.proto.generic)22 21 23 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^6to4-%w" 24 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^6in4-%w" 22 local _, p 23 for _, p in ipairs({"6in4", "6to4"}) do 25 24 26 function proto.__init__(self, name) 27 self.sid = name 25 local proto = netmod:register_protocol(p) 26 27 function proto.get_i18n(self) 28 if p == "6in4" then 29 return luci.i18n.translate("IPv6-in-IPv4 (RFC4213)") 30 elseif p == "6to4" then 31 return luci.i18n.translate("IPv6-over-IPv4") 32 end 33 end 34 35 function proto.ifname(self) 36 return p .. "-" .. self.sid 37 end 38 39 function proto.opkg_package(self) 40 return p 41 end 42 43 function proto.is_installed(self) 44 return nixio.fs.access("/lib/network/" .. p .. ".sh") 45 end 46 47 function proto.is_floating(self) 48 return true 49 end 50 51 function proto.is_virtual(self) 52 return true 53 end 54 55 function proto.get_interfaces(self) 56 return nil 57 end 58 59 function proto.contains_interface(self, ifname) 60 return (netmod:ifnameof(ifc) == self:ifname()) 61 end 62 63 netmod:register_pattern_virtual("^%s-%%w" % p) 28 64 end 29 30 function proto.ifname(self)31 return self:proto() .. "-" .. self.sid32 end33 34 function proto.is_floating(self)35 return true36 end37 38 function proto.is_virtual(self)39 return true40 end41 42 function proto.get_interfaces(self)43 return nil44 end45 46 function proto.contains_interface(self, ifname)47 return (netmod:ifnameof(ifc) == self:ifname())48 end49 50 51 netmod.proto["6to4"] = proto52 netmod.proto["6in4"] = proto -
luci/trunk/libs/core/luasrc/model/network/proto_ppp.lua
r7605 r7607 19 19 20 20 local netmod = luci.model.network 21 local proto = luci.util.class(netmod.proto.generic)22 21 23 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^3g-%w" 24 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^ppp-%w" 25 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^pptp-%w" 26 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^pppoe-%w" 27 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^pppoa-%w" 22 local _, p 23 for _, p in ipairs({"ppp", "pptp", "pppoe", "pppoa", "3g"}) do 28 24 29 function proto.__init__(self, name) 30 self.sid = name 25 local proto = netmod:register_protocol(p) 26 27 function proto.get_i18n(self) 28 if p == "ppp" then 29 return luci.i18n.translate("PPP") 30 elseif p == "pptp" then 31 return luci.i18n.translate("PPtP") 32 elseif p == "3g" then 33 return luci.i18n.translate("UMTS/GPRS/EV-DO") 34 elseif p == "pppoe" then 35 return luci.i18n.translate("PPPoE") 36 elseif p == "pppoa" then 37 return luci.i18n.translate("PPPoATM") 38 end 39 end 40 41 function proto.ifname(self) 42 return p .. "-" .. self.sid 43 end 44 45 function proto.opkg_package(self) 46 if p == "ppp" or p == "pptp" then 47 return p 48 elseif p == "3g" then 49 return "comgt" 50 elseif p == "pppoe" then 51 return "ppp-mod-pppoe" 52 elseif p == "pppoa" then 53 return "ppp-mod-pppoa" 54 end 55 end 56 57 function proto.is_installed(self) 58 return nixio.fs.access("/lib/network/" .. p .. ".sh") 59 end 60 61 function proto.is_floating(self) 62 return (p ~= "pppoe") 63 end 64 65 function proto.is_virtual(self) 66 return true 67 end 68 69 function proto.get_interfaces(self) 70 if self:is_floating() then 71 return nil 72 else 73 return netmod.protocol.get_interfaces(self) 74 end 75 end 76 77 function proto.contains_interface(self, ifc) 78 if self:is_floating() then 79 return (netmod:ifnameof(ifc) == self:ifname()) 80 else 81 return netmod.protocol.contains_interface(self, ifname) 82 end 83 end 84 85 netmod:register_pattern_virtual("^%s-%%w" % p) 31 86 end 32 33 function proto.ifname(self)34 return self:proto() .. "-" .. self.sid35 end36 37 function proto.is_floating(self)38 return (self:proto() ~= "pppoe")39 end40 41 function proto.is_virtual(self)42 return true43 end44 45 function proto.get_interfaces(self)46 if self:is_floating() then47 return nil48 else49 return netmod.proto.generic.get_interfaces(self)50 end51 end52 53 function proto.contains_interface(self, ifc)54 if self:is_floating() then55 return (netmod:ifnameof(ifc) == self:ifname())56 else57 return netmod.proto.generic.contains_interface(self, ifname)58 end59 end60 61 62 netmod.proto["3g"] = proto63 netmod.proto["ppp"] = proto64 netmod.proto["pptp"] = proto65 netmod.proto["pppoe"] = proto66 netmod.proto["pppoa"] = proto -
luci/trunk/libs/core/luasrc/model/network/proto_relay.lua
r7605 r7607 19 19 20 20 local netmod = luci.model.network 21 local proto = luci.util.class(netmod.proto.generic)22 21 local device = luci.util.class(netmod.interface) 23 22 24 netmod .IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^relay-%w"23 netmod:register_pattern_virtual("^relay-%w") 25 24 26 function proto.__init__(self, name) 27 self.sid = name 25 local proto = netmod:register_protocol("relay") 26 27 function proto.get_i18n(self) 28 return luci.i18n.translate("Relay bridge") 28 29 end 29 30 30 31 function proto.ifname(self) 31 32 return "relay-" .. self.sid 33 end 34 35 function proto.opkg_package(self) 36 return "relayd" 37 end 38 39 function proto.is_installed(self) 40 return nixio.fs.access("/lib/network/relay.sh") 32 41 end 33 42 … … 155 164 return luci.i18n.translate("Relay Bridge") 156 165 end 157 158 159 netmod.proto.relay = proto
