Пример #1
0
def source(tokeniser):
    data = tokeniser()
    if data.count('.') == 3 and data.count(':') == 0:
        ip, netmask = data.split('/')
        raw = concat_bytes_i(character(int(_)) for _ in ip.split('.'))
        yield Flow4Source(raw, int(netmask))
    elif data.count('/') == 1:
        ip, netmask = data.split('/')
        offset = 0
        yield Flow6Source(IP.pton(ip), int(netmask), int(offset))
    else:
        ip, netmask, offset = data.split('/')
        yield Flow6Source(IP.pton(ip), int(netmask), int(offset))
Пример #2
0
def source(tokeniser):
    data = tokeniser()
    if data.count('.') == 3 and data.count(':') == 0:
        ip, netmask = data.split('/')
        raw = b''.join(bytes([int(_)]) for _ in ip.split('.'))
        yield Flow4Source(raw, int(netmask))
    elif data.count('/') == 1:
        ip, netmask = data.split('/')
        offset = 0
        yield Flow6Source(IP.pton(ip), int(netmask), int(offset))
    else:
        ip, netmask, offset = data.split('/')
        yield Flow6Source(IP.pton(ip), int(netmask), int(offset))
Пример #3
0
def source(tokeniser):
    data = tokeniser()
    if data.count('/') == 1:
        ip, netmask = data.split('/')
        raw = ''.join(chr(int(_)) for _ in ip.split('.'))
        yield Flow4Source(raw, int(netmask))
    else:
        ip, netmask, offset = data.split('/')
        yield Flow6Source(IP.pton(ip), int(netmask), int(offset))
Пример #4
0
    def source(self, scope, name, command, tokens):
        try:
            data = tokens.pop(0)
            if data.count('/') == 1:
                ip, netmask = data.split('/')
                raw = ''.join(chr(int(_)) for _ in ip.split('.'))

                if not scope[-1]['announce'][-1].nlri.add(
                        Flow4Source(raw, int(netmask))):
                    return self.error.set('Flow can only have one destination')

            else:
                ip, netmask, offset = data.split('/')
                change = scope[-1]['announce'][-1]
                change.nlri.afi = AFI(AFI.ipv6)
                if not change.nlri.add(
                        Flow6Source(IP.pton(ip), int(netmask), int(offset))):
                    return self.error.set('Flow can only have one destination')
            return True

        except (IndexError, ValueError):
            return self.error.set(self.syntax)