Beispiel #1
0
def get_flow_info_from_elan_table(flow):
    m_metadata = inv_flow_parser.get_match_metadata(flow.rdata)
    if m_metadata:
        metadata = m_metadata['metadata']
        mask = m_metadata['metadata-mask']
        elan = inv_flow_parser.get_elan_from_metadata(metadata, mask)
        if elan:
            flow.pdata['lport'] = int(elan, 16)
            flow.pdata['elan-tag'] = int(elan, 16)
        lport = inv_flow_parser.get_lport_from_metadata(metadata, mask)
        if lport:
            flow.pdata['lport'] = int(lport, 16)
    m_ether_dest = inv_flow_parser.get_match_ether_dest(flow.rdata)
    if m_ether_dest:
        flow.pdata['dst-mac'] = m_ether_dest.lower()
    m_ether_src = inv_flow_parser.get_match_ether_src(flow.rdata)
    if m_ether_src:
        flow.pdata['src-mac'] = m_ether_src.lower()
    if not flow.pdata.get('lport'):
        reg6_load = inv_flow_parser.get_act_reg6load(flow.rdata)
        if reg6_load and reg6_load.get('value'):
            # reg6load value is lport lft-shit by 8 bits.
            lport = ('%x' % reg6_load.get('value'))[:-2]
            flow.pdata['lport'] = int(lport, 16)
    return flow.pdata
Beispiel #2
0
def get_flow_info_from_any(flow):
    w_mdata = inv_flow_parser.get_instruction_writemeta(flow.rdata)
    lport = flow.pdata.get('lport') if flow.pdata else None
    serviceid = flow.pdata.get('serviceid') if flow.pdata else None
    if w_mdata:
        metadata = w_mdata['metadata']
        mask = w_mdata['metadata-mask']
        lport = inv_flow_parser.get_lport_from_metadata(
            metadata, mask) if not lport else lport
        if lport:
            flow.pdata['lport'] = int(lport, 16)
        serviceid = inv_flow_parser.get_service_id_from_metadata(
            metadata, mask) if not serviceid else serviceid
        if serviceid:
            flow.pdata['serviceid'] = int(serviceid, 16)
    m_metadata = inv_flow_parser.get_match_metadata(flow.rdata)
    if m_metadata:
        elan = flow.pdata.get('elan-tag')
        vpnid = flow.pdata.get('vpnid')
        metadata = m_metadata['metadata']
        mask = m_metadata['metadata-mask']
        if not lport:
            lport = inv_flow_parser.get_lport_from_metadata(metadata, mask)
            if lport:
                flow.pdata['lport'] = int(lport, 16)
        if not serviceid:
            serviceid = inv_flow_parser.get_service_id_from_metadata(
                metadata, mask)
            if serviceid:
                flow.pdata['serviceid'] = int(serviceid, 16)
        if not elan:
            elan = inv_flow_parser.get_elan_from_metadata(metadata, mask)
            if elan:
                flow.pdata['elan-tag'] = int(elan, 16)
        if not vpnid:
            vpnid = inv_flow_parser.get_vpnid_from_metadata(metadata, mask)
            if vpnid:
                flow.pdata['vpnid'] = vpnid
    if not flow.pdata.get('dst-mac'):
        m_ether_dest = inv_flow_parser.get_match_ether_dest(flow.rdata)
        if m_ether_dest:
            flow.pdata['dst-mac'] = m_ether_dest.lower()
    if not flow.pdata.get('src-mac'):
        m_ether_src = inv_flow_parser.get_match_ether_src(flow.rdata)
        if m_ether_src:
            flow.pdata['src-mac'] = m_ether_src.lower()
    if not flow.pdata.get('dst-ip4'):
        m_ipv4_dest = inv_flow_parser.get_match_ipv4_dest(flow.rdata)
        if m_ipv4_dest:
            flow.pdata['dst-ip4'] = m_ipv4_dest
    if not flow.pdata.get('src-ip4'):
        m_ipv4_src = inv_flow_parser.get_match_ipv4_src(flow.rdata)
        if m_ipv4_src:
            flow.pdata['src-ip4'] = m_ipv4_src
    return flow.pdata
Beispiel #3
0
def get_flow_info_from_acl_table(flow):
    m_metadata = inv_flow_parser.get_match_metadata(flow.rdata)
    if m_metadata:
        metadata = m_metadata['metadata']
        mask = m_metadata['metadata-mask']
        lport = inv_flow_parser.get_lport_from_metadata(metadata, mask)
        if lport:
            flow.pdata['lport'] = int(lport, 16)
    a_conntrk = inv_flow_parser.get_act_conntrack(flow.rdata)
    if a_conntrk and a_conntrk.get('conntrack-zone'):
        flow.pdata['elan-tag'] = a_conntrk.get('conntrack-zone')
    return flow.pdata
Beispiel #4
0
def get_flow_info_from_l3vpn_table(flow):
    label = inv_flow_parser.get_match_mpls(flow.rdata)
    if not label and flow.rdata['table_id'] == 36:
        label = inv_flow_parser.get_match_tunnelid(flow.rdata)
    if label:
        flow.pdata['mpls'] = label
    a_group = inv_flow_parser.get_act_group(flow.rdata)
    if a_group and a_group.get('group-id'):
        flow.pdata['group-id'] = a_group.get('group-id')
    m_metadata = inv_flow_parser.get_match_metadata(flow.rdata)
    if m_metadata:
        metadata = m_metadata['metadata']
        mask = m_metadata['metadata-mask']
        lport = inv_flow_parser.get_lport_from_metadata(metadata, mask)
        if lport:
            flow.pdata['lport'] = int(lport, 16)
        vpnid = inv_flow_parser.get_vpnid_from_metadata(metadata, mask)
        if vpnid:
            flow.pdata['vpnid'] = (metadata & inv_flow_parser.VRFID_MASK) / 2
    return flow.pdata
Beispiel #5
0
def get_flow_info_from_nat_table(flow):
    m_metadata = inv_flow_parser.get_match_metadata(flow.rdata)
    vpnid = None
    if m_metadata:
        metadata = m_metadata['metadata']
        mask = m_metadata['metadata-mask']
        lport = inv_flow_parser.get_lport_from_metadata(metadata, mask)
        if lport:
            flow.pdata['lport'] = int(lport, 16)
        vpnid = inv_flow_parser.get_vpnid_from_metadata(metadata, mask)
        if vpnid:
            flow.pdata['vpnid'] = vpnid
    if not vpnid:
        w_metadata = inv_flow_parser.get_instruction_writemeta(flow.rdata)
        metadata = w_metadata['metadata']
        mask = w_metadata['metadata-mask']
        vpnid = inv_flow_parser.get_vpnid_from_metadata(metadata, mask)
        if vpnid:
            flow.pdata['vpnid'] = vpnid
    m_ipv4_dest = inv_flow_parser.get_match_ipv4_dest(flow.rdata)
    m_ipv4_src = inv_flow_parser.get_match_ipv4_src(flow.rdata)
    a_set_ipv4_dest = inv_flow_parser.get_act_set_ipv4_dest(flow.rdata)
    a_set_ipv4_src = inv_flow_parser.get_act_set_ipv4_src(flow.rdata)
    m_ether_src = inv_flow_parser.get_match_ether_src(flow.rdata)
    if flow.rdata['table_id'] in [25, 27]:
        if a_set_ipv4_dest:
            flow.pdata['int-ip4'] = a_set_ipv4_dest
        if m_ipv4_dest:
            flow.pdata['ext-ip4'] = m_ipv4_dest
        m_ether_dest = inv_flow_parser.get_match_ether_dest(flow.rdata)
        if m_ether_dest:
            flow.pdata['ext-mac'] = m_ether_dest
    if flow.rdata['table_id'] in [26, 28]:
        if a_set_ipv4_src:
            flow.pdata['ext-ip4'] = a_set_ipv4_src
        if m_ipv4_src:
            flow.pdata['int-ip4'] = m_ipv4_src
        m_ether_src = inv_flow_parser.get_match_ether_src(flow.rdata)
        if m_ether_src:
            flow.pdata['ext-mac'] = m_ether_src
    return flow.pdata