5874a7f673ea99de9ab4d44f23bfd8924ca22236
[project/luci.git] / libs / core / luasrc / model / network / proto_ppp.lua
1 --[[
2 LuCI - Network model - 3G, PPP, PPtP, PPPoE and PPPoA protocol extension
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 ]]--
19
20 local netmod = luci.model.network
21 local proto  = luci.util.class(netmod.proto.generic)
22
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"
28
29 function proto.__init__(self, name)
30         self.sid = name
31 end
32
33 function proto.ifname(self)
34         return self:proto() .. "-" .. self.sid
35 end
36
37 function proto.is_floating(self)
38         return (self:proto() ~= "pppoe")
39 end
40
41 function proto.is_virtual(self)
42         return true
43 end
44
45 function proto.get_interfaces(self)
46         if self:is_floating() then
47                 return nil
48         else
49                 return netmod.proto.generic.get_interfaces(self)
50         end
51 end
52
53 function proto.contains_interface(self, ifc)
54         if self:is_floating() then
55                 return (netmod:ifnameof(ifc) == self:ifname())
56         else
57                 return netmod.proto.generic.contains_interface(self, ifname)
58         end
59 end
60
61
62 netmod.proto["3g"]    = proto
63 netmod.proto["ppp"]   = proto
64 netmod.proto["pptp"]  = proto
65 netmod.proto["pppoe"] = proto
66 netmod.proto["pppoa"] = proto