def p_address_line_3(p):
    '''address_line : SET ADDRESS WORD object_name IP_ADDR opt_slash NUMBER
                    | SET ADDRESS WORD object_name IP_ADDR opt_slash NUMBER words'''
    object_dict[p[4]] = [{
        'address':
        Operator('EQ', Ip(p[5], Ip.CidrToMask(int(p[7]))))
    }]
Пример #2
0
def to_ip_list(string):
    ip_list = []
    sub_list = string.split(',')

    for sub in sub_list:
        sub.split('/')
        mask = Ip.CidrToMask(sub[1]) if len(sub) > 1 else '255.255.255.255'
        ip_list.append(Ip(sub[0], mask))

    return ip_list
Пример #3
0
def p_interface_line_1(p):
    '''interface_line : SET INTERFACE object_name IP IP_ADDR SLASH NUMBER
                      | SET INTERFACE object_name IP IP_ADDR SLASH NUMBER SECONDARY'''
    # detect sub-interface
    if re.match(r'.*/.*\..*', p[3]):
        nameif = p[3].split('.')
        interface = p_info['firewall'].get_interface_by_nameif(nameif[0])
        if not interface:
            interface = Interface(nameif[0], None, None, [])
            p_info['firewall'].interfaces.append(interface)
        sub_if = interface.get_subif_by_nameif(p[3])
        if sub_if:
            sub_if.network = Ip(p[5], Ip.CidrToMask(int(p[7])))
        else:
            interface.sub_interfaces.append(
                Interface(p[3], Ip(p[5], Ip.CidrToMask(int(p[7]))), None, []))
    else:
        interface = p_info['firewall'].get_interface_by_nameif(p[3])
        if interface:
            interface.network = Ip(p[5], Ip.CidrToMask(int(p[7])))
        else:
            p_info['firewall'].interfaces.append(
                Interface(p[3], Ip(p[5], Ip.CidrToMask(int(p[7]))), None, []))
Пример #4
0
def p_addr_set_line_5(p):
    '''addr_set_line : SET SUBNET IP_ADDR SLASH NUMBER'''
    object_dict[p_info['current_object']].append(
        {'address': Operator('EQ', Ip(p[3], Ip.CidrToMask(int(p[5]))))})
Пример #5
0
def p_ip_addr2(p):
    '''ip_addr : IP_ADDR SLASH NUMBER'''
    p[0] = [Ip(p[1], Ip.CidrToMask(int(p[3])))]