Changeset 5405 for luci/trunk/libs/core/luasrc/model/network.lua
- Timestamp:
- 10/15/09 17:30:17 (4 years ago)
- Files:
-
- 1 modified
-
luci/trunk/libs/core/luasrc/model/network.lua (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/libs/core/luasrc/model/network.lua
r5391 r5405 18 18 ]]-- 19 19 20 local type, pairs, ipairs, table, i18n21 = type, pairs, ipairs, table, luci.i18n20 local type, pairs, ipairs, loadfile, table, i18n 21 = type, pairs, ipairs, loadfile, table, luci.i18n 22 22 23 23 local lmo = require "lmo" … … 31 31 module "luci.model.network" 32 32 33 -- load extensions 34 local ext 35 local handler = { } 36 37 for ext in nfs.glob(utl.libpath() .. "/model/network/*.lua") do 38 if nfs.access(ext) then 39 local m = loadfile(ext) 40 if m then 41 handler[#handler+1] = m() 42 end 43 end 44 end 45 46 function foreach_handler(code, ...) 47 local h 48 for _, h in ipairs(handler) do 49 if code(h, ...) then 50 return true 51 end 52 end 53 return false 54 end 33 55 34 56 local ub = uct.bind("network") … … 44 66 brs = { } 45 67 sws = { } 68 69 -- init handler 70 foreach_handler(function(h) 71 h:init(cursor) 72 h:find_interfaces(ifs, brs) 73 end) 46 74 47 75 -- read interface information … … 76 104 end 77 105 end 78 end 106 end 79 107 80 108 -- read bridge informaton … … 151 179 end 152 180 end) 181 182 foreach_handler(function(h) h:del_network(n) end) 153 183 end 154 184 return r … … 180 210 end 181 211 end) 212 213 foreach_handler(function(h) h:rename_network(old, new) end) 182 214 end 183 215 end … … 199 231 200 232 function ignore_interface(self, x) 201 return (x:match("^wmaster%d") or x:match("^wifi%d") 202 or x:match("^hwsim%d") or x:match("^imq%d") or x == "lo") 233 if foreach_handler(function(h) return h:ignore_interface(x) end) then 234 return true 235 else 236 return (x:match("^wmaster%d") or x:match("^wifi%d") 237 or x:match("^hwsim%d") or x:match("^imq%d") or x == "lo") 238 end 203 239 end 204 240 … … 219 255 220 256 function network.add_interface(self, ifname) 257 local ifaces, iface 258 221 259 if type(ifname) ~= "string" then 222 ifname = ifname:name() 223 end 224 if ifs[ifname] then 225 self:ifname(ub:list((self:ifname() or ''), ifname)) 260 ifaces = { ifname:name() } 261 else 262 ifaces = ub:list(ifname) 263 end 264 265 for _, iface in ipairs(ifaces) do 266 if ifs[iface] then 267 -- make sure the interface is removed from all networks 268 local i = interface(iface) 269 local n = i:get_network() 270 if n then n:del_interface(iface) end 271 272 if ifs[iface].handler then 273 ifs[iface].handler:add_interface(self, iface, ifs[iface]) 274 else 275 self:ifname(ub:list((self:ifname() or ''), iface)) 276 end 277 end 226 278 end 227 279 end … … 231 283 ifname = ifname:name() 232 284 end 233 self:ifname(ub:list((self:ifname() or ''), nil, ifname)) 285 286 if ifs[ifname] and ifs[ifname].handler then 287 ifs[ifname].handler:del_interface(self, ifname, ifs[ifname]) 288 else 289 self:ifname(ub:list((self:ifname() or ''), nil, ifname)) 290 end 234 291 end 235 292 … … 243 300 end 244 301 end 302 for iface, _ in pairs(ifs) do 303 if ifs[iface].network == self:name() then 304 ifaces[#ifaces+1] = interface(iface) 305 end 306 end 245 307 return ifaces 246 308 end … … 256 318 for _, i in ipairs(ifaces) do 257 319 if i == iface then 320 return true 321 end 322 end 323 324 for i, _ in pairs(ifs) do 325 if ifs[i].dev and ifs[i].dev.network == self:name() then 258 326 return true 259 327 end … … 290 358 291 359 function interface.type(self) 292 if iwi.type(self.ifname) and iwi.type(self.ifname) ~= "dummy"then293 return "wifi"360 if self.dev and self.dev.type then 361 return self.dev.type 294 362 elseif brs[self.ifname] then 295 363 return "bridge" … … 298 366 else 299 367 return "ethernet" 368 end 369 end 370 371 function interface.shortname(self) 372 if self.dev and self.dev.handler then 373 return self.dev.handler:shortname(self) 374 else 375 return self.ifname 376 end 377 end 378 379 function interface.get_i18n(self) 380 if self.dev and self.dev.handler then 381 return self.dev.handler:get_i18n(self) 382 else 383 return "%s: %q" %{ self:get_type_i18n(), self:name() } 300 384 end 301 385 end … … 374 458 375 459 function interface.get_network(self) 460 if self.dev and self.dev.network then 461 self.network = _M:get_network(self.dev.network) 462 end 463 376 464 if not self.network then 377 465 local net
