Exemple #1
0
 def append_iface (self, n, name, ** kw) :
     iface = Interface (n, name, kw ['mtu'])
     i4 = Inet4 (iface = name, ** kw)
     iface.append_inet4 (i4)
     iface.is_wlan = kw ['wlan'].lower () == 'yes'
     self.if_by_name [name] = iface
     self.ips [iface.inet4 [0]] = True
Exemple #2
0
 def append_iface(self, n, name, **kw):
     iface = Interface(n, name, kw['mtu'])
     i4 = Inet4(iface=name, **kw)
     iface.append_inet4(i4)
     iface.is_wlan = kw['wlan'].lower() == 'yes'
     self.if_by_name[name] = iface
     self.ips[iface.inet4[0]] = True
Exemple #3
0
 def append_iface(self, n, name, **kw):
     iface = Interface(n, name, kw["mtu"])
     i4 = Inet4(iface=name, **kw)
     iface.append_inet4(i4)
     iface.is_wlan = kw["wlan"].lower() == "yes"
     self.if_by_name[name] = iface
     self.ips[iface.inet4[0]] = True
Exemple #4
0
    def __init__ (self, site, request) :
        self.site    = site
        self.request = request
        if 'interfaces' in self.request or 'ips' in self.request :
            st    = Status           (site = site)
            conn  = OLSR_Connections (site = site)
            route = OLSR_Routes      (site = site)
            self.version = st.version
            assert len (st.wlans) <= 1
            interfaces   = {}
            ips          = {}
            count = 0
            for gw, ifname in route.iface_by_gw.iteritems () :
                ip, lq, nlq, etx  = conn.neighbors [gw]
                i4 = Inet4 (ip, None, None, iface = ifname)
                ips [i4] = 1
                is_wlan = True
                if lq == nlq == etx == 1.0 :
                    is_wlan = False
                if ifname in interfaces :
                    iface = interfaces [ifname]
                    if not iface.is_wlan and is_wlan :
                        iface.is_wlan   = True
                        iface.wlan_info = st.wlans [0]
                else :
                    iface = Interface (count, ifname, None)
                    iface.is_wlan = is_wlan
                    if is_wlan :
                        iface.wlan_info = st.wlans [0]
                    count += 1
                    interfaces [ifname] = iface
                if i4 not in iface.inet4 :
                    iface.append_inet4 (i4)
            wl_if = None
            for iface in interfaces.itervalues () :
                if iface.is_wlan :
                    if wl_if :
                        m = "Duplicate wlan: %s/%s" % (iface.name, wl_if.name)
                        raise ValueError (m)
                    wl_if = iface
            # check own ip
            n  = 'unknown'
            i4 = Inet4 (self.request ['ip'], None, None, iface = n)
            if i4 not in ips :
                assert n not in interfaces
                iface = interfaces [n] = Interface (count, n, None)
                iface.append_inet4 (i4)
                iface.is_wlan = False
                if not wl_if and st.wlans :
                    iface.is_wlan   = True
                    iface.wlan_info = st.wlans [0]
                ips [i4] = True

            self.request ['ips']        = ips
            self.request ['interfaces'] = interfaces
            self.request ['version']    = st.version
Exemple #5
0
 def parse (self) :
     root = self.tree.getroot ()
     self.if_by_name = {}
     self.ips        = {}
     for div in root.findall (".//%s" % tag ("div")) :
         self.try_get_version (div)
         if div.get ('id') == 'maincontent' and not self.if_by_name :
             tbl = div.find (".//%s" % tag ("table"))
             for n, tr in enumerate (tbl) :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text in ('Interface', 'Schnittstelle') \
                         , tr [0].text
                     continue
                 name, status, mtu, wlan, ip, mask, bcast = \
                     (x.text for x in tr)
                 if name in self.if_by_name :
                     iface = self.if_by_name [name]
                 else :
                     iface = Interface (n, name, mtu)
                     iface.is_wlan = self.yesno.get (wlan, False)
                 if status == 'DOWN' :
                     continue
                 # append IP address to interface if there is one
                 if ip is not None :
                     if ':' in ip :
                         i6 = Inet6 (ip, mask, bcast, iface = name)
                         iface.append_inet6 (i6)
                     else :
                         i4 = Inet4 (ip, mask, bcast, iface = name)
                         iface.append_inet4 (i4)
                         if not unroutable (i4.ip) :
                             self.if_by_name [name] = iface
                             self.ips [i4] = True
     self.set_version (root)
     if not self.if_by_name :
         raise ValueError, "No interface config found"
     bfw = Backfire_WLAN_Config (site = self.site)
     for d in bfw.wlans :
         if d.name in self.if_by_name :
             iface = self.if_by_name [d.name]
             iface.wlan_info = d
Exemple #6
0
 def parse (self) :
     root = self.tree.getroot ()
     self.if_by_name = {}
     self.ips        = {}
     for div in root.findall (".//%s" % tag ("div")) :
         self.try_get_version (div)
         if div.get ('id') == 'maincontent' and not self.if_by_name :
             tbl = div.find (".//%s" % tag ("table"))
             for n, tr in enumerate (tbl) :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text in ('Interface', 'Schnittstelle') \
                         , tr [0].text
                     continue
                 name, status, mtu, wlan, ip, mask, bcast = \
                     (x.text for x in tr)
                 if name in self.if_by_name :
                     iface = self.if_by_name [name]
                 else :
                     iface = Interface (n, name, mtu)
                     iface.is_wlan = self.yesno.get (wlan, False)
                 if status == 'DOWN' :
                     continue
                 # append IP address to interface if there is one
                 if ip is not None :
                     if ':' in ip :
                         i6 = Inet6 (ip, mask, bcast, iface = name)
                         iface.append_inet6 (i6)
                     else :
                         i4 = Inet4 (ip, mask, bcast, iface = name)
                         iface.append_inet4 (i4)
                         if not unroutable (i4.ip) :
                             self.if_by_name [name] = iface
                             self.ips [i4] = True
     self.set_version (root)
     if not self.if_by_name :
         raise ValueError, "No interface config found"
     bfw = Backfire_WLAN_Config (site = self.site)
     for d in bfw.wlans :
         if d.name in self.if_by_name :
             iface = self.if_by_name [d.name]
             iface.wlan_info = d
Exemple #7
0
 def iface(self, state, new_state, match):
     self.interface = Interface(*match.groups())
     self.interfaces.append(self.interface)
     self.if_by_name[self.interface.name] = self.interface
     self.push(state, new_state, match)
Exemple #8
0
class Interface_Config(Parser):
    re_assign = re.compile(r'^([a-zA-Z0-9_]+)\s*=\s*([a-zA-Z0-9 ]*)$')
    re_brhead = re.compile(r'^bridge name.*$')
    re_bridge = re.compile(r'^(\S+)\s*(\S+)\s*(\S+)\s*(\S+)$')
    re_ifonly = re.compile(r'^\s+(\S+)$')
    re_if     = re.compile \
        (r'^(\d+):\s*(\S+):\s*mtu\s*(\d+)\s*qdisc\s*(\S+)(?:qlen\s*(\d+))?')
    pt_mac = pt_mac
    re_link   = re.compile \
        (r'^\s*link/(\S+)(?:\s*(\S+)\s*brd\s*(\S+))?$' % locals ())
    pt_ip = r'((?:\d{1,3}[.]){3}\d{1,3})'
    re_inet   = re.compile \
        ( r'^\s*inet\s+%(pt_ip)s/(\d+)\s+'
          r'(?:brd\s+%(pt_ip)s\s+)?scope\s+(\S+)\s+(\S+)$'
        % locals ()
        )
    pt_ip6 = r'([0-9a-fA-F:]+)'
    re_inet6  = re.compile \
        ( r'^\s*inet6\s+%(pt_ip6)s/(\d+)\s+scope\s+(\S+)$' % locals ())
    matrix = \
        [ ["init",   re_assign, "init",   "assign"]
        , ["init",   re_brhead, "bridge", None]
        , ["init",   re_if,     "iface",  "iface"]
        , ["init",   None,      "init",   None]
        , ["bridge", re_bridge, "bridge", "bridge"]
        , ["bridge", re_ifonly, "bridge", None]
        , ["bridge", '',        "init",   None]
        , ["iface",  re_link,   "iface",  "link"]
        , ["iface",  re_inet,   "iface",  "inet"]
        , ["iface",  re_inet6,  "iface",  "inet6"]
        , ["iface",  None,      "init",   "pop"]
        ]

    def __init__(self, **kw):
        self.assignments = {}
        self.bridges = []
        self.interfaces = []
        self.if_by_name = {}
        self.__super.__init__(**kw)

    # end def __init__

    def assign(self, state, new_state, match):
        self.assignments[match.group(1)] = match.group(2)

    # end def assign

    def bridge(self, state, new_state, match):
        self.bridges.append(match.groups())

    # end def bridge

    def iface(self, state, new_state, match):
        self.interface = Interface(*match.groups())
        self.interfaces.append(self.interface)
        self.if_by_name[self.interface.name] = self.interface
        self.push(state, new_state, match)

    # end def iface

    def link(self, state, new_state, match):
        self.interface.link = Net_Link(*match.groups())

    # end def link

    def inet(self, state, new_state, match):
        self.interface.append_inet4(Inet4(*match.groups()))

    # end def inet

    def inet6(self, state, new_state, match):
        self.interface.append_inet6(Inet6(*match.groups()))

    # end def inet6

    def __str__(self):
        r = []
        for k, v in self.assignments.iteritems():
            r.append("%(k)s = %(v)s" % locals())
        for b in self.bridges:
            r.append("Bridge: %s" % str(b))
        for i in self.interfaces:
            r.append(str(i))
        return '\n'.join(r)

    # end def __str__
    __repr__ = __str__
Exemple #9
0
 def iface (self, state, new_state, match) :
     self.interface = Interface (* match.groups ())
     self.interfaces.append (self.interface)
     self.if_by_name [self.interface.name] = self.interface
     self.push (state, new_state, match)
Exemple #10
0
class Interface_Config (Parser) :
    re_assign = re.compile (r'^([a-zA-Z0-9_]+)\s*=\s*([a-zA-Z0-9 ]*)$')
    re_brhead = re.compile (r'^bridge name.*$')
    re_bridge = re.compile (r'^(\S+)\s*(\S+)\s*(\S+)\s*(\S+)$')
    re_ifonly = re.compile (r'^\s+(\S+)$')
    re_if     = re.compile \
        (r'^(\d+):\s*(\S+):\s*mtu\s*(\d+)\s*qdisc\s*(\S+)(?:qlen\s*(\d+))?')
    pt_mac    = pt_mac
    re_link   = re.compile \
        (r'^\s*link/(\S+)(?:\s*(\S+)\s*brd\s*(\S+))?$' % locals ())
    pt_ip     = r'((?:\d{1,3}[.]){3}\d{1,3})'
    re_inet   = re.compile \
        ( r'^\s*inet\s+%(pt_ip)s/(\d+)\s+'
          r'(?:brd\s+%(pt_ip)s\s+)?scope\s+(\S+)\s+(\S+)$'
        % locals ()
        )
    pt_ip6    = r'([0-9a-fA-F:]+)'
    re_inet6  = re.compile \
        ( r'^\s*inet6\s+%(pt_ip6)s/(\d+)\s+scope\s+(\S+)$' % locals ())
    matrix = \
        [ ["init",   re_assign, "init",   "assign"]
        , ["init",   re_brhead, "bridge", None]
        , ["init",   re_if,     "iface",  "iface"]
        , ["init",   None,      "init",   None]
        , ["bridge", re_bridge, "bridge", "bridge"]
        , ["bridge", re_ifonly, "bridge", None]
        , ["bridge", '',        "init",   None]
        , ["iface",  re_link,   "iface",  "link"]
        , ["iface",  re_inet,   "iface",  "inet"]
        , ["iface",  re_inet6,  "iface",  "inet6"]
        , ["iface",  None,      "init",   "pop"]
        ]

    def __init__ (self, **kw) :
        self.assignments = {}
        self.bridges     = []
        self.interfaces  = []
        self.if_by_name  = {}
        self.__super.__init__ (**kw)
    # end def __init__

    def assign (self, state, new_state, match) :
        self.assignments [match.group (1)] = match.group (2)
    # end def assign

    def bridge (self, state, new_state, match) :
        self.bridges.append (match.groups ())
    # end def bridge

    def iface (self, state, new_state, match) :
        self.interface = Interface (* match.groups ())
        self.interfaces.append (self.interface)
        self.if_by_name [self.interface.name] = self.interface
        self.push (state, new_state, match)
    # end def iface

    def link (self, state, new_state, match) :
        self.interface.link = Net_Link (* match.groups ())
    # end def link

    def inet (self, state, new_state, match) :
        self.interface.append_inet4 (Inet4 (* match.groups ()))
    # end def inet

    def inet6 (self, state, new_state, match) :
        self.interface.append_inet6 (Inet6 (* match.groups ()))
    # end def inet6

    def __str__ (self) :
        r = []
        for k, v in self.assignments.iteritems () :
            r.append ("%(k)s = %(v)s" % locals ())
        for b in self.bridges :
            r.append ("Bridge: %s" % str (b))
        for i in self.interfaces :
            r.append (str (i))
        return '\n'.join (r)
    # end def __str__
    __repr__ = __str__
Exemple #11
0
    def __init__ (self, site, request, url = url) :
        self.site    = site
        self.request = request
        rtparm = 1
        if url.endswith ('cgi') :
            rtparm = 2
        if 'interfaces' in self.request or 'ips' in self.request :
            rt = Routes  (site = site, url = url + '?post_routes=%s' % rtparm)
            dt = Details (site = site, url = url + '?post_olsr=1')
            self.version = rt.version
            interfaces   = {}
            ips          = {}
            base         = 0
            for count, (ip, ifname) in enumerate (rt.ip_dev.iteritems ()) :
                i4 = Inet4 (ip, None, None, iface = ifname)
                # ignore interfaces with unroutable IPs
                if unroutable (i4.ip) :
                    #print "Unroutable: %s" % i4
                    continue
                ips [i4] = 1
                iface = Interface (count, ifname, None)
                iface.is_wlan = False
                interfaces [ifname] = iface
                iface.append_inet4 (i4)
                base = count
            base += 1
            for count, (ip, ifname) in enumerate (dt.ip_dev.iteritems ()) :
                i4 = Inet4 (ip, None, None, iface = ifname)
                is_wlan = sum (x == 1.0 for x in dt.metric [ip]) != 3
                #print "ip", ip, dt.metric [ip]
                if unroutable (i4.ip) :
                    continue
                if i4 in ips :
                    if ifname not in interfaces :
                        iface = Interface (base + count, ifname, None)
                        interfaces [ifname] = iface
                        iface.append_inet4 (i4)
                    else :
                        iface = interfaces [ifname]
                        if i4 not in iface.inet4 :
                            #print "Oops:", ifname, i4, iface.inet4 [0]
                            del iface.inet4 [0]
                            iface.append_inet4 (i4)
                    iface.is_wlan = is_wlan
                    continue
                ips [i4] = 1
                iface = Interface (base + count, ifname, None)
                iface.is_wlan = is_wlan
                interfaces [ifname] = iface
                iface.append_inet4 (i4)

            # check own ip
            n  = 'unknown'
            i4 = Inet4 (self.request ['ip'], None, None, iface = n)
            assert i4 in ips

            self.request ['ips']        = ips
            self.request ['interfaces'] = interfaces
            self.request ['version']    = rt.version
Exemple #12
0
    def __init__ (self, cmd, scope, debug = False) :
        self.debug     = debug
        self.verbose   = cmd.verbose
        self.anonymize = cmd.anonymize
        if len (cmd.argv) > 0 :
            f  = open (cmd.argv [0])
        else :
            f = sys.stdin
        self.ip4nets = {}
        self.ip6nets = {}
        if cmd.network :
            for n in cmd.network :
                ip, comment = n.split (';', 1)
                if ':' in ip :
                    ip = IP6_Address (ip)
                    self.ip6nets [ip] = comment
                else :
                    ip = IP4_Address (ip)
                    self.ip4nets [ip] = comment
        olsr = get_olsr_container (cmd.olsr_file)
        self.olsr_nodes   = {}
        for t in olsr.topo.forward.iterkeys () :
            self.olsr_nodes [t]   = True
        for t in olsr.topo.reverse.iterkeys () :
            self.olsr_nodes [t]   = True
        self.olsr_mid     = olsr.mid.by_ip
        self.olsr_hna     = olsr.hna
        self.rev_mid      = {}
        for k, v in self.olsr_mid.iteritems () :
            if k not in self.olsr_nodes :
                pyk.fprint ("WARN: MIB %s: not in OLSR Topology" % k)
            #assert k in self.olsr_nodes
            for mid in v :
                assert mid not in self.rev_mid
                self.rev_mid [mid] = True
        self.spider_info  = pickle.load (open (cmd.spider_dump, 'rb'))
        self.spider_devs  = {}
        self.spider_iface = {}
        for ip, dev in self.spider_info.iteritems () :
            if self.verbose :
                pyk.fprint ("IP:", ip)
            # ignore spider errors
            if not isinstance (dev, Guess) :
                continue
            dev.mainip = ip
            dev.done   = False
            for iface in dev.interfaces.itervalues () :
                iface.done = False
                for ip4 in iface.inet4 :
                    i4 = ip4.ip
                    # ignore rfc1918, link local, localnet
                    if unroutable (i4) :
                        continue
                    if  (   i4 in self.spider_devs
                        and self.spider_devs [i4] != dev
                        ) :
                        pyk.fprint ("WARN: Device %s/%s not equal:" % (ip, i4))
                        pyk.fprint ("=" * 60)
                        pyk.fprint (dev.verbose_repr ())
                        pyk.fprint ("-" * 60)
                        pyk.fprint (self.spider_devs [i4].verbose_repr ())
                        pyk.fprint ("=" * 60)
                    elif (   i4 in self.spider_iface
                         and self.spider_iface [i4] != iface
                         ) :
                        assert dev == self.spider_devs [i4]
                        spif = self.spider_iface [i4]
                        pyk.fprint \
                            ( "WARN: Interfaces %s/%s of dev-ip %s share ip %s"
                            % (iface.name, spif.name, ip, i4)
                            )
                        spif.names.append (iface.name)
                        if iface.is_wlan :
                            spif.is_wlan = iface.is_wlan
                            spif.wlan_info = getattr (iface, 'wlan_info', None)
                        if self.verbose :
                            pyk.fprint ("=" * 60)
                            pyk.fprint (iface)
                            pyk.fprint (spif)
                            pyk.fprint ("-" * 60)
                            pyk.fprint (dev.verbose_repr ())
                            pyk.fprint ("=" * 60)
                        iface = spif
                    self.spider_devs  [i4] = dev
                    self.spider_iface [i4] = iface
                    iface.device = dev
            if ip not in self.spider_devs :
                pyk.fprint ("WARN: ip %s not in dev" % ip)
                if self.verbose :
                    pyk.fprint ("=" * 60)
                    pyk.fprint (dev.verbose_repr ())
                    pyk.fprint ("=" * 60)
                name = 'unknown'
                assert name not in dev.interfaces
                iface = Interface (4711, name)
                iface.done = False
                dev.interfaces [name] = iface
                iface.device = dev
                iface.append_inet4 (Inet4 (ip, None, None, iface = name))
                self.spider_iface [ip] = iface
                self.spider_devs  [ip] = dev

        self.scope          = scope
        self.ffm            = self.scope.FFM
        self.pap            = self.scope.GTW.OMP.PAP
        self.mentor         = {}
        self.rsrvd_nets     = {}
        self.ffm_node_by_id = {}
        self.node_by_id     = {}
        self.ip_by_ip       = {}
        self.email_ids      = {}
        self.phone_ids      = {}
        self.person_by_id   = {}
        self.member_by_id   = {}
        self.dev_by_node    = {}
        self.cons_dev       = {}

        self.parser         = SQL_Parser \
            (verbose = False, fix_double_encode = True)
        self.parser.parse (f)
        self.contents       = self.parser.contents
        self.tables         = self.parser.tables
Exemple #13
0
    def __init__(self, cmd, scope, debug=False):
        self.debug = debug
        self.verbose = cmd.verbose
        self.anonymize = cmd.anonymize
        if len(cmd.argv) > 0:
            f = open(cmd.argv[0])
        else:
            f = sys.stdin
        self.ip4nets = {}
        self.ip6nets = {}
        if cmd.network:
            for n in cmd.network:
                ip, comment = n.split(';', 1)
                if ':' in ip:
                    ip = IP6_Address(ip)
                    self.ip6nets[ip] = comment
                else:
                    ip = IP4_Address(ip)
                    self.ip4nets[ip] = comment
        olsr = get_olsr_container(cmd.olsr_file)
        self.olsr_nodes = {}
        for t in olsr.topo.forward.iterkeys():
            self.olsr_nodes[t] = True
        for t in olsr.topo.reverse.iterkeys():
            self.olsr_nodes[t] = True
        self.olsr_mid = olsr.mid.by_ip
        self.olsr_hna = olsr.hna
        self.rev_mid = {}
        for k, v in self.olsr_mid.iteritems():
            if k not in self.olsr_nodes:
                pyk.fprint("WARN: MIB %s: not in OLSR Topology" % k)
            #assert k in self.olsr_nodes
            for mid in v:
                assert mid not in self.rev_mid
                self.rev_mid[mid] = True
        self.spider_info = pickle.load(open(cmd.spider_dump, 'rb'))
        self.spider_devs = {}
        self.spider_iface = {}
        for ip, dev in self.spider_info.iteritems():
            if self.verbose:
                pyk.fprint("IP:", ip)
            # ignore spider errors
            if not isinstance(dev, Guess):
                continue
            dev.mainip = ip
            dev.done = False
            for iface in dev.interfaces.itervalues():
                iface.done = False
                for ip4 in iface.inet4:
                    i4 = ip4.ip
                    # ignore rfc1918, link local, localnet
                    if unroutable(i4):
                        continue
                    if (i4 in self.spider_devs
                            and self.spider_devs[i4] != dev):
                        pyk.fprint("WARN: Device %s/%s not equal:" % (ip, i4))
                        pyk.fprint("=" * 60)
                        pyk.fprint(dev.verbose_repr())
                        pyk.fprint("-" * 60)
                        pyk.fprint(self.spider_devs[i4].verbose_repr())
                        pyk.fprint("=" * 60)
                    elif (i4 in self.spider_iface
                          and self.spider_iface[i4] != iface):
                        assert dev == self.spider_devs[i4]
                        spif = self.spider_iface[i4]
                        pyk.fprint \
                            ( "WARN: Interfaces %s/%s of dev-ip %s share ip %s"
                            % (iface.name, spif.name, ip, i4)
                            )
                        spif.names.append(iface.name)
                        if iface.is_wlan:
                            spif.is_wlan = iface.is_wlan
                            spif.wlan_info = getattr(iface, 'wlan_info', None)
                        if self.verbose:
                            pyk.fprint("=" * 60)
                            pyk.fprint(iface)
                            pyk.fprint(spif)
                            pyk.fprint("-" * 60)
                            pyk.fprint(dev.verbose_repr())
                            pyk.fprint("=" * 60)
                        iface = spif
                    self.spider_devs[i4] = dev
                    self.spider_iface[i4] = iface
                    iface.device = dev
            if ip not in self.spider_devs:
                pyk.fprint("WARN: ip %s not in dev" % ip)
                if self.verbose:
                    pyk.fprint("=" * 60)
                    pyk.fprint(dev.verbose_repr())
                    pyk.fprint("=" * 60)
                name = 'unknown'
                assert name not in dev.interfaces
                iface = Interface(4711, name)
                iface.done = False
                dev.interfaces[name] = iface
                iface.device = dev
                iface.append_inet4(Inet4(ip, None, None, iface=name))
                self.spider_iface[ip] = iface
                self.spider_devs[ip] = dev

        self.scope = scope
        self.ffm = self.scope.FFM
        self.pap = self.scope.GTW.OMP.PAP
        self.mentor = {}
        self.rsrvd_nets = {}
        self.ffm_node_by_id = {}
        self.node_by_id = {}
        self.ip_by_ip = {}
        self.email_ids = {}
        self.phone_ids = {}
        self.person_by_id = {}
        self.member_by_id = {}
        self.dev_by_node = {}
        self.cons_dev = {}

        self.parser         = SQL_Parser \
            (verbose = False, fix_double_encode = True)
        self.parser.parse(f)
        self.contents = self.parser.contents
        self.tables = self.parser.tables
Exemple #14
0
    def __init__(self, site, request):
        self.site = site
        self.request = request
        if 'interfaces' in self.request or 'ips' in self.request:
            st = Status(site=site)
            conn = OLSR_Connections(site=site)
            route = OLSR_Routes(site=site)
            self.version = st.version
            assert len(st.wlans) <= 1
            interfaces = {}
            ips = {}
            count = 0
            for gw, ifname in route.iface_by_gw.iteritems():
                ip, lq, nlq, etx = conn.neighbors[gw]
                i4 = Inet4(ip, None, None, iface=ifname)
                ips[i4] = 1
                is_wlan = True
                if lq == nlq == etx == 1.0:
                    is_wlan = False
                if ifname in interfaces:
                    iface = interfaces[ifname]
                    if not iface.is_wlan and is_wlan:
                        iface.is_wlan = True
                        iface.wlan_info = st.wlans[0]
                else:
                    iface = Interface(count, ifname, None)
                    iface.is_wlan = is_wlan
                    if is_wlan:
                        iface.wlan_info = st.wlans[0]
                    count += 1
                    interfaces[ifname] = iface
                if i4 not in iface.inet4:
                    iface.append_inet4(i4)
            wl_if = None
            for iface in interfaces.itervalues():
                if iface.is_wlan:
                    if wl_if:
                        m = "Duplicate wlan: %s/%s" % (iface.name, wl_if.name)
                        raise ValueError(m)
                    wl_if = iface
            # check own ip
            n = 'unknown'
            i4 = Inet4(self.request['ip'], None, None, iface=n)
            if i4 not in ips:
                assert n not in interfaces
                iface = interfaces[n] = Interface(count, n, None)
                iface.append_inet4(i4)
                iface.is_wlan = False
                if not wl_if and st.wlans:
                    iface.is_wlan = True
                    iface.wlan_info = st.wlans[0]
                ips[i4] = True

            self.request['ips'] = ips
            self.request['interfaces'] = interfaces
            self.request['version'] = st.version
    def __init__(self, site, request, url=url):
        self.site = site
        self.request = request
        rtparm = 1
        if url.endswith('cgi'):
            rtparm = 2
        if 'interfaces' in self.request or 'ips' in self.request:
            rt = Routes(site=site, url=url + '?post_routes=%s' % rtparm)
            dt = Details(site=site, url=url + '?post_olsr=1')
            self.version = rt.version
            interfaces = {}
            ips = {}
            base = 0
            for count, (ip, ifname) in enumerate(pyk.iteritems(rt.ip_dev)):
                i4 = Inet4(ip, None, None, iface=ifname)
                # ignore interfaces with unroutable IPs
                if unroutable(i4.ip):
                    #print ("Unroutable: %s" % i4)
                    continue
                ips[i4] = 1
                iface = Interface(count, ifname, None)
                iface.is_wlan = False
                interfaces[ifname] = iface
                iface.append_inet4(i4)
                base = count
            base += 1
            for count, (ip, ifname) in enumerate(pyk.iteritems(dt.ip_dev)):
                i4 = Inet4(ip, None, None, iface=ifname)
                is_wlan = sum(x == 1.0 for x in dt.metric[ip]) != 3
                #print ("ip", ip, dt.metric [ip])
                if unroutable(i4.ip):
                    continue
                if i4 in ips:
                    if ifname not in interfaces:
                        iface = Interface(base + count, ifname, None)
                        interfaces[ifname] = iface
                        iface.append_inet4(i4)
                    else:
                        iface = interfaces[ifname]
                        if i4 not in iface.inet4:
                            #print ("Oops:", ifname, i4, iface.inet4 [0])
                            del iface.inet4[0]
                            iface.append_inet4(i4)
                    iface.is_wlan = is_wlan
                    continue
                ips[i4] = 1
                iface = Interface(base + count, ifname, None)
                iface.is_wlan = is_wlan
                interfaces[ifname] = iface
                iface.append_inet4(i4)

            # check own ip
            n = 'unknown'
            i4 = Inet4(self.request['ip'], None, None, iface=n)
            assert i4 in ips

            self.request['ips'] = ips
            self.request['interfaces'] = interfaces
            self.request['version'] = rt.version