Exemplo n.º 1
0
 def ssh(self):
     protocol = 'ssh'
     
     nextCmd = self.expect(Keyword)
     if nextCmd == 'server':
         if self.sshEnabled == False:
             t = taglib.tag("service", taglib.protocol_name(protocol))
             t.implied_by(taglib.env_tags.device, self.lineNum)
             self.sshEnabled = True
             t = taglib.tag("service", "SSHv2")
             t.implied_by(taglib.env_tags.device, self.lineNum)
         
             version = self.accept(Keyword)
             if not version == 'v2':
                 t = taglib.tag("service", "SSHv1")
                 t.implied_by(taglib.env_tags.device, self.lineNum)
                 
     self.skipTo(EndOfCommand)
Exemplo n.º 2
0
    def ssh(self):
        protocol = 'ssh'

        nextCmd = self.expect(Keyword)
        if nextCmd == 'server':
            if self.sshEnabled == False:
                t = taglib.tag("service", taglib.protocol_name(protocol))
                t.implied_by(taglib.env_tags.device, self.lineNum)
                self.sshEnabled = True
                t = taglib.tag("service", "SSHv2")
                t.implied_by(taglib.env_tags.device, self.lineNum)

                version = self.accept(Keyword)
                if not version == 'v2':
                    t = taglib.tag("service", "SSHv1")
                    t.implied_by(taglib.env_tags.device, self.lineNum)

        self.skipTo(EndOfCommand)
Exemplo n.º 3
0
    def ip(self, if_tag=None, version=None, active=True):
        ra_line = None
        ra_suppress = False
        ra_prefix = []
        if_prefix = []
        cmd = self.expect(Keyword)

        if False:
            pass

        elif cmd == 'address':
            name = self.accept(String)
            ipaddress = self.accept(Literal)
            if ipaddress:
                self.accept(
                    Punctuation)  # allow detection of address/prefix length
                if name:
                    ipaddress = IPy.intToIp(
                        IPy.IP(ipaddress).int()
                        | ipv6_general_prefixes[name].int(), 6)
                address = ipaddress + "/" + self.expect(Literal)
                if active:
                    ifaddr_tag = taglib.ip_address_tag(
                        address, kind="interface address")
                    address_tag = taglib.ip_address_tag(address)
                    subnet_tag = taglib.ip_subnet_tag(address)
                    ifaddr_tag.implied_by(if_tag, self.lineNum)
                    address_tag.implied_by(ifaddr_tag, self.lineNum)
                    subnet_tag.implied_by(address_tag, self.lineNum)
                    if version:
                        version_tag = taglib.tag("IP version", version)
                        version_tag.implied_by(if_tag, self.lineNum)

                        # add router advertisement by default on multi-access networks
                        if version == 'IPv6' and re.search(
                                r"eth|srp", if_tag.name, re.I):
                            if_prefix.append(subnet_tag.name)
                            ra_line = self.lineNum

            self.skipTo(EndOfCommand)

        elif cmd == 'general-prefix':
            name = self.expect(String)
            ipaddress = self.expect(Literal)
            self.expect(Punctuation)
            address = ipaddress + "/" + self.expect(Literal)
            ipv6_general_prefixes[name] = IPy.IP(address)
            self.expect(EndOfCommand)

        elif cmd == 'helper-address':
            if self.accept(Keyword):
                self.expect(Literal)
            t = taglib.tag("BOOTP relay", self.expect(Literal))
            t.implied_by(taglib.env_tags.device, self.lineNum)
            self.expect(EndOfCommand)

        elif cmd == 'http':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                t = taglib.tag("service", "HTTP")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            elif nextCmd == 'secure-server':
                t = taglib.tag("service", "HTTPS")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)

        elif cmd == 'nd':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'prefix':
                nd_prefix = None
                default_prefix = self.accept(Keyword)
                if not default_prefix:
                    nd_prefix = self.expect(Literal) + self.expect(
                        Punctuation) + self.expect(Literal)
                keyword = self.accept(Keyword)
                if keyword is None or not 'no-ad' in keyword:
                    if nd_prefix:
                        ra_prefix.append(nd_prefix)
            elif nextCmd == 'suppress-ra':
                ra_suppress = True
            self.skipTo(EndOfCommand)

        elif cmd == 'scp':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                nextCmd = self.expect(Keyword)
                if nextCmd == 'enable':
                    t = taglib.tag("service", taglib.protocol_name(cmd))
                    t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)

        else:
            self.skipTo(EndOfCommand)

        return (ra_suppress, ra_line, if_prefix, ra_prefix)
Exemplo n.º 4
0
    def ip(self, if_tag=None, if_name=None, version=None):
        ra_line = None
        ra_suppress = False
        ra_prefix = []
        if_prefix = []
        cmd = self.expect(Keyword)

        if False:
            pass

        elif cmd == 'address':
            name = self.accept(String)
            ipaddress = self.accept(Literal)
            if ipaddress:
                self.accept(Punctuation)    # allow detection of address/prefix length
                if name:
                    ipaddress = IPy.intToIp(IPy.IP(ipaddress).int() | ipv6_general_prefixes[name].int(), 6)
                address = ipaddress + "/" + self.expect(Literal)
                if if_name:
                    if version == 'IPv4':
                        if_addrs4.setdefault(if_name, ipaddress)
                    elif version == 'IPv6':
                        if_addrs6.setdefault(if_name, ipaddress)
                ifaddr_tag = taglib.ip_address_tag(address, 
                                                   kind="interface address")
                address_tag = taglib.ip_address_tag(address)
                subnet_tag = taglib.ip_subnet_tag(address)
                ifaddr_tag.implied_by(if_tag, self.lineNum)
                address_tag.implied_by(ifaddr_tag, self.lineNum)
                subnet_tag.implied_by(address_tag, self.lineNum)
                if version:
                    version_tag = taglib.tag("IP version", version)
                    version_tag.implied_by(if_tag, self.lineNum)
                    
                    # add router advertisement by default on multi-access networks
                    if version == 'IPv6':
                        ipv6_addresses = True
                        if re.search(r"eth|fddi|port-channel", if_tag.name, re.I):
                            if_prefix.append(subnet_tag.name)
                            ra_line = self.lineNum
                    
            self.skipTo(EndOfCommand)

        elif cmd == 'cef':
            if not version:
                version = "IPv4"
            distributed = self.accept(Keyword)
            if distributed == "distributed":
                cef = " ".join((version, distributed))
            else:
                cef = version
            t = taglib.tag("Cisco express forwarding", cef)
            t.implied_by(device_tag, self.lineNum)
            self.skipTo(EndOfCommand)
        
        elif cmd == 'domain name' or cmd == 'domain-name':
            t = taglib.tag("domain name", self.expect(String))
            t.implied_by(taglib.env_tags.device, self.lineNum)
            self.expect(EndOfCommand)

        elif cmd == 'general-prefix':
            name = self.expect(String)
            ipaddress = self.expect(Literal)
            self.expect(Punctuation)
            address = ipaddress + "/" + self.expect(Literal)
            ipv6_general_prefixes[name] = IPy.IP(address)
            self.expect(EndOfCommand)
            
        elif cmd == 'helper-address':
            t = taglib.tag("BOOTP relay", self.expect(Literal))
            t.implied_by(taglib.env_tags.device, self.lineNum)
            self.expect(EndOfCommand)
            
        elif cmd == 'http':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                t = taglib.tag("service", "HTTP")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            elif nextCmd == 'secure-server':
                t = taglib.tag("service", "HTTPS")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)

        elif cmd == 'name-server':
            t = taglib.tag("name server", self.expect(Literal))
            t.implied_by(taglib.env_tags.device, self.lineNum)
            self.expect(EndOfCommand)
        
        elif cmd == 'nd':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'prefix':
                ra_line = self.lineNum
                nd_prefix = None
                default_prefix = self.accept(Keyword)
                if not default_prefix:
                    nd_prefix = self.expect(Literal) + self.expect(Punctuation) + self.expect(Literal)
                keyword = self.accept(Keyword)
                if keyword is None or not 'no-ad' in keyword:
                    if nd_prefix:
                        ra_prefix.append(nd_prefix)
            elif nextCmd == 'suppress-ra':
                ra_line = self.lineNum
                ra_suppress = True
            self.skipTo(EndOfCommand)
        
        elif cmd == 'scp':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                nextCmd = self.expect(Keyword)
                if nextCmd == 'enable':
                    t = taglib.tag("service", taglib.protocol_name(cmd))
                    t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)

        elif cmd == 'ssh':
            if self.sshEnabled == False:
                t = taglib.tag("service", taglib.protocol_name(cmd))
                t.implied_by(taglib.env_tags.device, self.lineNum)
                self.sshEnabled = True
            nextCmd = self.expect(Keyword)
            if nextCmd == 'version':
                version = self.expect(Literal)
                if version == '2':
                    t = taglib.tag("service", taglib.protocol_name(cmd))
                    t.implied_by(taglib.env_tags.device, self.lineNum)
                    t = taglib.tag("service", "SSHv2")
                    t.implied_by(taglib.env_tags.device, self.lineNum)
                elif version == '1':
                    t = taglib.tag("service", taglib.protocol_name(cmd))
                    t.implied_by(taglib.env_tags.device, self.lineNum)
                    t = taglib.tag("service", "SSHv1")
                    t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)


        elif cmd == 'unicast-routing':
            ipv6_unicast_routing = self.lineNum
            self.expect(EndOfCommand)
            
        else:
            self.skipTo(EndOfCommand)
        return (ra_suppress, ra_line, if_prefix, ra_prefix)
Exemplo n.º 5
0
def main(filename):
    lines = open(filename, 'rU')
    
    n = 0
    for line in lines:
        n += 1
        
        if re.match(r'Syntax error at token detail', line):
            lines.close()
            taglib.default_filename = filename = re.sub(r'-detail', '', filename)
            main(filename)
            return

        # time
        m = re.match(r'configure sntp-client (primary|secondary) (?:server )? "?([\w\d.-]+)"?( vr [\w\d.]+)?', line)
        if m:
            which, server, vr = m.groups()
            taglib.tag("NTP server", server).implied_by(taglib.env_tags.device, line=n)
            continue

        # dns
        m = re.match(r'configure dns-client add domain-suffix ([\w\d.-]+)', line)
        if m:
            server = m.group(1)
            taglib.tag("domain name", server).implied_by(taglib.env_tags.device, line=n)
            continue
            
        m = re.match(r'configure dns-client add (name-server )?([\w\d.-]+)( vr [\w\d.]+)?', line)
        if m:
            ignore, server, vr = m.groups()
            taglib.tag("name server", server).implied_by(taglib.env_tags.device, line=n)
            continue
            
        m = re.match(r'configure dns-client default-domain ([\w\d.-]+)', line)
        if m:
            server = m.group(1)
            taglib.tag("domain name", server).implied_by(taglib.env_tags.device, line=n)
            continue

        # radius
        m = re.match(r'configure radius (?:mgmt-access )?(primary|secondary) server ([\w\d.-]+)( [\d]+)? client-ip ([\w\d.-]+)( vr [\w\d.]+)?', line)
        if m:
            which, server, port, client, vr = m.groups()
            taglib.tag("RADIUS server", server).implied_by(taglib.env_tags.device, line=n)
            continue

        # tacacs+
        m = re.match(r'configure tacacs (primary|secondary) server ([\w\d.-]+)( [\d]+)? client-ip ([\w\d.-]+)( vr [\w\d.]+)?', line)
        if m:
            which, server, port, client, vr = m.groups()
            taglib.tag("TACACS+ server", server).implied_by(taglib.env_tags.device, line=n)
            continue

        # interfaces
        m = re.match(r'create vlan "?([\w\d.-]+)"?', line)
        if m:
            vlan = m.group(1)
            vlanTag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlanTag.implied_by(taglib.env_tags.snapshot, line=n)
            taglib.env_tags.device.implied_by(vlanTag, line=n)
            continue
        m = re.match(r'configure vlan "?([\w\d]+)"? tag ([\d]+)', line)
        if m:
            vlan, vlan_id = m.group(1), int(m.group(2))
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_id_tag = taglib.tag("VLAN ID", vlan_id, sort_name="%05d" % vlan_id)
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(vlan_id_tag, line=n)
            continue
        m = re.match(r'config(?:ure)? vlan "?([\w\d]+)"? ipaddress ([\d.]+)\s+([\d.]+)\s+', line)
        if m:
            vlan, ipaddress, mask = m.groups()
            address = ipaddress + "/" + mask
            ifaddr_tag = taglib.ip_address_tag(address, "interface address")
            address_tag = taglib.ip_address_tag(address)
            subnet_tag = taglib.ip_subnet_tag(address)
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(ifaddr_tag, line=n)
            ifaddr_tag.implies(address_tag, line=n)
            address_tag.implies(subnet_tag, line=n)
            continue
        m = re.match(r'configure "?([\w\d]+)"? ipaddress ([a-fA-F\d:]+)/([\d]+)\s+', line)
        if m:
            vlan, ipaddress, mask = m.groups()
            address = ipaddress + "/" + mask
            ifaddr_tag = taglib.ip_address_tag(address, "interface address")
            address_tag = taglib.ip_address_tag(address)
            subnet_tag = taglib.ip_subnet_tag(address)
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(ifaddr_tag, line=n)
            ifaddr_tag.implies(address_tag, line=n)
            address_tag.implies(subnet_tag, line=n)
            continue

        # dhcp/bootp
        m = re.match(r'configure bootprelay add ([\w\d.-]+)', line)
        if m:
            relay = m.group(1)
            taglib.tag("BOOTP relay", relay).implied_by(taglib.env_tags.device, line=n)
            continue

        # accounts
        m = re.match(r'create account (admin|user) "?([\w\d.-]+)"?\s+.*', line)
        if m:
            account = m.group(2)
            taglib.tag("user", account).implied_by(taglib.env_tags.device, line=n)
            continue
        m = re.match(r'configure account (admin|user).*', line)
        if m:
            account = m.group(1)
            taglib.tag("user", account).implied_by(taglib.env_tags.device, line=n)
            continue

        # protocols
        m = re.match(r'enable (bgp|igmp|MLD|msdp|rip|ripng)$', line)
        if m:
            protocolTag = taglib.tag("routing protocol", taglib.protocol_name(m.group(1)))
            protocolTag.implied_by(taglib.env_tags.device, line=n)
            continue
        m = re.match(r'enable (igmp|MLD) snooping.*', line)
        if m:
            protocol = m.group(1)
            protocolTag = taglib.tag("routing protocol", taglib.protocol_name(protocol))
            protocolTag.implied_by(taglib.env_tags.device, line=n)
            continue
        m = re.match(r'configure DVMRP add vlan "?([\w\d.-]+)"?', line)
        if m:
            vlan = m.group(1)
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            taglib.tag("routing protocol", "DVMRP").implied_by(vlan_tag, n)
            continue
        m = re.match(r'configure ospf add vlan "?([\w\d.-]+)"? area ([\d.]+).*', line)
        if m:
            vlan, area = m.groups()
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPF area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPF"), line=n)
            continue
        m = re.match(r'configure ospf vlan ([\w\d.-]+) area ([\d.]+)', line)
        if m:
            vlan, area = m.groups()
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPF area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPF"), line=n)
            continue
        m = re.match(r'configure ospfv3 domain ([\w\d.-]+) add vlan ([\w\d.-]+) instance-id ([\d]+) area ([\d.]+)', line)
        if m:
            domain, vlan, instance, area = m.groups()
            vlan_tag = taglib.tag("interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPFv3 area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPFv3"), line=n)
            continue

        # services
        serviceLabelDict = {'ssh':'SSHv1', 'ssh1':'SSHv1', 'ssh2':'SSHv2', 'telnet':'TELNET',
                            'web':'HTTP'}
        m = re.match(r'enable (ssh2|telnet|web)( access-profile ([\w\d.-]+)( port ([\d]+))?)?', line)
        if m:
            service = m.group(1)
            taglib.tag("service", serviceLabelDict[service]).implied_by(taglib.env_tags.device, n)
            continue
        m = re.match(r'configure telnet( access-profile ([\w\d.-]+))?( port ([\d]+))?( vr ([\w\d.-]+))?', line)
        if m:
            taglib.tag("service", "TELNET").implied_by(taglib.env_tags.device, n)
            continue
 def service_tag(e):
     if not e.tag.endswith("}comment"):
         t = taglib.tag("service", taglib.protocol_name(e.tag))
         t.implied_by(taglib.env_tags.device, e.sourceline)
Exemplo n.º 7
0
def main(filename):
    lines = open(filename, 'rU')

    n = 0
    for line in lines:
        n += 1

        if re.match(r'Syntax error at token detail', line):
            lines.close()
            taglib.default_filename = filename = re.sub(
                r'-detail', '', filename)
            main(filename)
            return

        # time
        m = re.match(
            r'configure sntp-client (primary|secondary) (?:server )? "?([\w\d.-]+)"?( vr [\w\d.]+)?',
            line)
        if m:
            which, server, vr = m.groups()
            taglib.tag("NTP server", server).implied_by(taglib.env_tags.device,
                                                        line=n)
            continue

        # dns
        m = re.match(r'configure dns-client add domain-suffix ([\w\d.-]+)',
                     line)
        if m:
            server = m.group(1)
            taglib.tag("domain name",
                       server).implied_by(taglib.env_tags.device, line=n)
            continue

        m = re.match(
            r'configure dns-client add (name-server )?([\w\d.-]+)( vr [\w\d.]+)?',
            line)
        if m:
            ignore, server, vr = m.groups()
            taglib.tag("name server",
                       server).implied_by(taglib.env_tags.device, line=n)
            continue

        m = re.match(r'configure dns-client default-domain ([\w\d.-]+)', line)
        if m:
            server = m.group(1)
            taglib.tag("domain name",
                       server).implied_by(taglib.env_tags.device, line=n)
            continue

        # radius
        m = re.match(
            r'configure radius (?:mgmt-access )?(primary|secondary) server ([\w\d.-]+)( [\d]+)? client-ip ([\w\d.-]+)( vr [\w\d.]+)?',
            line)
        if m:
            which, server, port, client, vr = m.groups()
            taglib.tag("RADIUS server",
                       server).implied_by(taglib.env_tags.device, line=n)
            continue

        # tacacs+
        m = re.match(
            r'configure tacacs (primary|secondary) server ([\w\d.-]+)( [\d]+)? client-ip ([\w\d.-]+)( vr [\w\d.]+)?',
            line)
        if m:
            which, server, port, client, vr = m.groups()
            taglib.tag("TACACS+ server",
                       server).implied_by(taglib.env_tags.device, line=n)
            continue

        # interfaces
        m = re.match(r'create vlan "?([\w\d.-]+)"?', line)
        if m:
            vlan = m.group(1)
            vlanTag = taglib.tag("interface",
                                 "%s %s" % (taglib.env_tags.device.name, vlan))
            vlanTag.implied_by(taglib.env_tags.snapshot, line=n)
            taglib.env_tags.device.implied_by(vlanTag, line=n)
            continue
        m = re.match(r'configure vlan "?([\w\d]+)"? tag ([\d]+)', line)
        if m:
            vlan, vlan_id = m.group(1), int(m.group(2))
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_id_tag = taglib.tag("VLAN ID",
                                     vlan_id,
                                     sort_name="%05d" % vlan_id)
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(vlan_id_tag, line=n)
            continue
        m = re.match(
            r'config(?:ure)? vlan "?([\w\d]+)"? ipaddress ([\d.]+)\s+([\d.]+)\s+',
            line)
        if m:
            vlan, ipaddress, mask = m.groups()
            address = ipaddress + "/" + mask
            ifaddr_tag = taglib.ip_address_tag(address, "interface address")
            address_tag = taglib.ip_address_tag(address)
            subnet_tag = taglib.ip_subnet_tag(address)
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(ifaddr_tag, line=n)
            ifaddr_tag.implies(address_tag, line=n)
            address_tag.implies(subnet_tag, line=n)
            continue
        m = re.match(
            r'configure "?([\w\d]+)"? ipaddress ([a-fA-F\d:]+)/([\d]+)\s+',
            line)
        if m:
            vlan, ipaddress, mask = m.groups()
            address = ipaddress + "/" + mask
            ifaddr_tag = taglib.ip_address_tag(address, "interface address")
            address_tag = taglib.ip_address_tag(address)
            subnet_tag = taglib.ip_subnet_tag(address)
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            vlan_tag.implied_by(taglib.env_tags.snapshot, line=n)
            vlan_tag.implies(taglib.env_tags.device, line=n)
            vlan_tag.implies(ifaddr_tag, line=n)
            ifaddr_tag.implies(address_tag, line=n)
            address_tag.implies(subnet_tag, line=n)
            continue

        # dhcp/bootp
        m = re.match(r'configure bootprelay add ([\w\d.-]+)', line)
        if m:
            relay = m.group(1)
            taglib.tag("BOOTP relay", relay).implied_by(taglib.env_tags.device,
                                                        line=n)
            continue

        # accounts
        m = re.match(r'create account (admin|user) "?([\w\d.-]+)"?\s+.*', line)
        if m:
            account = m.group(2)
            taglib.tag("user", account).implied_by(taglib.env_tags.device,
                                                   line=n)
            continue
        m = re.match(r'configure account (admin|user).*', line)
        if m:
            account = m.group(1)
            taglib.tag("user", account).implied_by(taglib.env_tags.device,
                                                   line=n)
            continue

        # protocols
        m = re.match(r'enable (bgp|igmp|MLD|msdp|rip|ripng)$', line)
        if m:
            protocolTag = taglib.tag("routing protocol",
                                     taglib.protocol_name(m.group(1)))
            protocolTag.implied_by(taglib.env_tags.device, line=n)
            continue
        m = re.match(r'enable (igmp|MLD) snooping.*', line)
        if m:
            protocol = m.group(1)
            protocolTag = taglib.tag("routing protocol",
                                     taglib.protocol_name(protocol))
            protocolTag.implied_by(taglib.env_tags.device, line=n)
            continue
        m = re.match(r'configure DVMRP add vlan "?([\w\d.-]+)"?', line)
        if m:
            vlan = m.group(1)
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            taglib.tag("routing protocol", "DVMRP").implied_by(vlan_tag, n)
            continue
        m = re.match(
            r'configure ospf add vlan "?([\w\d.-]+)"? area ([\d.]+).*', line)
        if m:
            vlan, area = m.groups()
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPF area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPF"), line=n)
            continue
        m = re.match(r'configure ospf vlan ([\w\d.-]+) area ([\d.]+)', line)
        if m:
            vlan, area = m.groups()
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPF area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPF"), line=n)
            continue
        m = re.match(
            r'configure ospfv3 domain ([\w\d.-]+) add vlan ([\w\d.-]+) instance-id ([\d]+) area ([\d.]+)',
            line)
        if m:
            domain, vlan, instance, area = m.groups()
            vlan_tag = taglib.tag(
                "interface", "%s %s" % (taglib.env_tags.device.name, vlan))
            area_tag = taglib.tag("OSPFv3 area", area)
            area_tag.implied_by(vlan_tag, line=n)
            area_tag.implies(taglib.tag("routing protocol", "OSPFv3"), line=n)
            continue

        # services
        serviceLabelDict = {
            'ssh': 'SSHv1',
            'ssh1': 'SSHv1',
            'ssh2': 'SSHv2',
            'telnet': 'TELNET',
            'web': 'HTTP'
        }
        m = re.match(
            r'enable (ssh2|telnet|web)( access-profile ([\w\d.-]+)( port ([\d]+))?)?',
            line)
        if m:
            service = m.group(1)
            taglib.tag("service", serviceLabelDict[service]).implied_by(
                taglib.env_tags.device, n)
            continue
        m = re.match(
            r'configure telnet( access-profile ([\w\d.-]+))?( port ([\d]+))?( vr ([\w\d.-]+))?',
            line)
        if m:
            taglib.tag("service", "TELNET").implied_by(taglib.env_tags.device,
                                                       n)
            continue
 def service_tag(e):
     if not e.tag.endswith("}comment"):
         t = taglib.tag("service", taglib.protocol_name(e.tag))
         t.implied_by(taglib.env_tags.device, e.sourceline)
Exemplo n.º 9
0
    def ip(self, if_tag=None, version=None, active=True):
        ra_line = None
        ra_suppress = False
        ra_prefix = []
        if_prefix = []
        cmd = self.expect(Keyword)

        if False:
            pass

        elif cmd == 'address':
            name = self.accept(String)
            ipaddress = self.accept(Literal)
            if ipaddress:
                self.accept(Punctuation)    # allow detection of address/prefix length
                if name:
                    ipaddress = IPy.intToIp(IPy.IP(ipaddress).int() | ipv6_general_prefixes[name].int(), 6)
                address = ipaddress + "/" + self.expect(Literal)
                if active:
                    ifaddr_tag = taglib.ip_address_tag(address, 
                                                       kind="interface address")
                    address_tag = taglib.ip_address_tag(address)
                    subnet_tag = taglib.ip_subnet_tag(address)
                    ifaddr_tag.implied_by(if_tag, self.lineNum)
                    address_tag.implied_by(ifaddr_tag, self.lineNum)
                    subnet_tag.implied_by(address_tag, self.lineNum)
                    if version:
                        version_tag = taglib.tag("IP version", version)
                        version_tag.implied_by(if_tag, self.lineNum)
                        
                        # add router advertisement by default on multi-access networks
                        if version == 'IPv6' and re.search(r"eth|srp", if_tag.name, re.I):
                            if_prefix.append(subnet_tag.name)
                            ra_line = self.lineNum
                
            self.skipTo(EndOfCommand)

        elif cmd == 'general-prefix':
            name = self.expect(String)
            ipaddress = self.expect(Literal)
            self.expect(Punctuation)
            address = ipaddress + "/" + self.expect(Literal)
            ipv6_general_prefixes[name] = IPy.IP(address)
            self.expect(EndOfCommand)
            
        elif cmd == 'helper-address':
            if self.accept(Keyword):
                self.expect(Literal)
            t = taglib.tag("BOOTP relay", self.expect(Literal))
            t.implied_by(taglib.env_tags.device, self.lineNum)
            self.expect(EndOfCommand)
            
        elif cmd == 'http':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                t = taglib.tag("service", "HTTP")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            elif nextCmd == 'secure-server':
                t = taglib.tag("service", "HTTPS")
                t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)
            
        elif cmd == 'nd':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'prefix':
                nd_prefix = None
                default_prefix = self.accept(Keyword)
                if not default_prefix:
                    nd_prefix = self.expect(Literal) + self.expect(Punctuation) + self.expect(Literal)
                keyword = self.accept(Keyword)
                if keyword is None or not 'no-ad' in keyword:
                    if nd_prefix:
                        ra_prefix.append(nd_prefix)
            elif nextCmd == 'suppress-ra':
                ra_suppress = True
            self.skipTo(EndOfCommand)
                
        elif cmd == 'scp':
            nextCmd = self.expect(Keyword)
            if nextCmd == 'server':
                nextCmd = self.expect(Keyword)
                if nextCmd == 'enable':
                    t = taglib.tag("service", taglib.protocol_name(cmd))
                    t.implied_by(taglib.env_tags.device, self.lineNum)
            self.skipTo(EndOfCommand)

        else:
            self.skipTo(EndOfCommand)
            
        return (ra_suppress, ra_line, if_prefix, ra_prefix)