Changeset 7543

Show
Ignore:
Timestamp:
09/24/11 02:57:59 (21 months ago)
Author:
jow
Message:

libs/core: add "tunnel" interface type to network model, various optimizations

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/core/luasrc/model/network.lua

    r7502 r7543  
    3131 
    3232 
    33 local ifs, brs, sws, uci_r, uci_s 
     33local ifs, brs, sws, tns, uci_r, uci_s 
    3434 
    3535function _list_del(c, s, o, r) 
     
    175175    brs = { } 
    176176    sws = { } 
     177    tns = { } 
    177178 
    178179    -- read interface information 
     
    182183        local prnt = name:match("^([^%.]+)%.") 
    183184 
    184         if _iface_virtual(name) or not _iface_ignore(name) then 
     185        if _iface_virtual(name) then 
     186            tns[name] = true 
     187        end 
     188 
     189        if tns[name] or not _iface_ignore(name) then 
    185190            ifs[name] = ifs[name] or { 
    186191                idx      = i.ifindex or n, 
     
    746751function network.get_interface(self) 
    747752    if self:is_virtual() then 
    748         return interface(self:proto() .. "-" .. self.sid) 
     753        tns[self:proto() .. "-" .. self.sid] = true 
     754        return interface(self:proto() .. "-" .. self.sid, self) 
    749755    elseif self:is_bridge() then 
    750         return interface("br-" .. self.sid) 
     756        brs["br-" .. self.sid] = true 
     757        return interface("br-" .. self.sid, self) 
    751758    else 
    752759        local ifn = nil 
     
    754761        for ifn in utl.imatch(uci_s:get("network", self.sid, "ifname")) do 
    755762            ifn = ifn:match("^[^:/]+") 
    756             return ifn and interface(ifn) 
     763            return ifn and interface(ifn, self) 
    757764        end 
    758765        ifn = nil 
     
    767774                end 
    768775            end) 
    769         return ifn and interface(ifn) 
     776        return ifn and interface(ifn, self) 
    770777    end 
    771778end 
     
    778785    for ifn in utl.imatch(self:get("ifname")) do 
    779786        ifn = ifn:match("^[^:/]+") 
    780         nfs[ifn] = interface(ifn) 
     787        nfs[ifn] = interface(ifn, self) 
    781788    end 
    782789 
     
    793800                if s.network == self.sid then 
    794801                    ifn = "%s.network%d" %{ s.device, num[s.device] } 
    795                     wfs[ifn] = interface(ifn) 
     802                    wfs[ifn] = interface(ifn, self) 
    796803                end 
    797804            end 
     
    845852 
    846853interface = utl.class() 
    847 function interface.__init__(self, ifname) 
     854function interface.__init__(self, ifname, network) 
    848855    local wif = _wifi_lookup(ifname) 
    849856    if wif then self.wif = wifinet(wif) end 
    850857 
    851     self.ifname = self.ifname or ifname 
    852     self.dev    = ifs[self.ifname] 
     858    self.ifname  = self.ifname or ifname 
     859    self.dev     = ifs[self.ifname] 
     860    self.network = network 
    853861end 
    854862 
     
    858866 
    859867function interface.mac(self) 
    860     return self.dev and self.dev.macaddr or "00:00:00:00:00:00" 
     868    return (self.dev and self.dev.macaddr or "00:00:00:00:00:00"):upper() 
    861869end 
    862870 
     
    874882    elseif brs[self.ifname] then 
    875883        return "bridge" 
     884    elseif tns[self.ifname] then 
     885        return "tunnel" 
    876886    elseif self.ifname:match("%.") then 
    877887        return "vlan" 
     
    916926    elseif x == "vlan" then 
    917927        return i18n.translate("VLAN Interface") 
     928    elseif x == "tunnel" then 
     929        return i18n.translate("Tunnel Interface") 
    918930    else 
    919931        return i18n.translate("Ethernet Adapter") 
     
    9911003 
    9921004function interface.get_network(self) 
    993     if self.dev and self.dev.network then 
    994         self.network = _M:get_network(self.dev.network) 
     1005    if not self.network then 
     1006        if self.dev and self.dev.network then 
     1007            self.network = _M:get_network(self.dev.network) 
     1008        end 
    9951009    end 
    9961010