Find VRF Associated with Interface

63 views
Skip to first unread message

brian.s...@wwt.com

unread,
Feb 8, 2019, 12:04:33 PM2/8/19
to pyroute2-dev
Hello,

Is there a way to extract the vrf that an interface is associated with?  I don't see it when grabbing the interface info in either of the following methods.  The first method I can see it's a slave to a vrf but don't see the vrf name.

with IPRoute() as ipr:
    interface = ipr.link("get", index=ipr.link_lookup(ifname="ens160")[0])
print(interface)

({'family': 0, '__align': (), 'ifi_type': 1, 'index': 2, 'flags': 69699, 'change': 0, 'attrs': [('IFLA_IFNAME', 'ens160'), ('IFLA_TXQLEN', 1000), ('IFLA_OPERSTATE', 'UP'), ('IFLA_LINKMODE', 0), ('IFLA_MTU', 1500), ('IFLA_GROUP', 0), ('IFLA_PROMISCUITY', 0), ('IFLA_NUM_TX_QUEUES', 2), ('IFLA_GSO_MAX_SEGS', 65535), ('IFLA_GSO_MAX_SIZE', 65536), ('IFLA_NUM_RX_QUEUES', 2), ('IFLA_MASTER', 5), ('IFLA_CARRIER', 1), ('IFLA_QDISC', 'mq'), ('IFLA_IFALIAS', 'management'), ('IFLA_CARRIER_CHANGES', 5), ('IFLA_PROTO_DOWN', 0), ('IFLA_CARRIER_UP_COUNT', 3), ('IFLA_CARRIER_DOWN_COUNT', 2), ('IFLA_MAP', {'mem_start': 0, 'mem_end': 0, 'base_addr': 0, 'irq': 0, 'dma': 0, 'port': 0}), ('IFLA_ADDRESS', '00:50:56:aa:37:1f'), ('IFLA_BROADCAST', 'ff:ff:ff:ff:ff:ff'), ('IFLA_STATS64', {'rx_packets': 6011, 'tx_packets': 3049, 'rx_bytes': 673778, 'tx_bytes': 1211112, 'rx_errors': 0, 'tx_errors': 0, 'rx_dropped': 0, 'tx_dropped': 0, 'multicast': 72, 'collisions': 0, 'rx_length_errors': 0, 'rx_over_errors': 0, 'rx_crc_errors': 0, 'rx_frame_errors': 0, 'rx_fifo_errors': 0, 'rx_missed_errors': 0, 'tx_aborted_errors': 0, 'tx_carrier_errors': 0, 'tx_fifo_errors': 0, 'tx_heartbeat_errors': 0, 'tx_window_errors': 0, 'rx_compressed': 0, 'tx_compressed': 0}), ('IFLA_STATS', {'rx_packets': 6011, 'tx_packets': 3049, 'rx_bytes': 673778, 'tx_bytes': 1211112, 'rx_errors': 0, 'tx_errors': 0, 'rx_dropped': 0, 'tx_dropped': 0, 'multicast': 72, 'collisions': 0, 'rx_length_errors': 0, 'rx_over_errors': 0, 'rx_crc_errors': 0, 'rx_frame_errors': 0, 'rx_fifo_errors': 0, 'rx_missed_errors': 0, 'tx_aborted_errors': 0, 'tx_carrier_errors': 0, 'tx_fifo_errors': 0, 'tx_heartbeat_errors': 0, 'tx_window_errors': 0, 'rx_compressed': 0, 'tx_compressed': 0}), ('IFLA_XDP', '05:00:02:00:00:00:00:00'), ('IFLA_LINKINFO', {'attrs': [('IFLA_INFO_SLAVE_KIND', 'vrf'), ('IFLA_INFO_SLAVE_DATA', '08:00:01:00:fd:00:00:00')]}), ('IFLA_AF_SPEC', {'attrs': [('AF_INET', {'dummy': 65664, 'forwarding': 1, 'mc_forwarding': 0, 'proxy_arp': 0, 'accept_redirects': 1, 'secure_redirects': 1, 'send_redirects': 1, 'shared_media': 1, 'rp_filter': 1, 'accept_source_route': 1, 'bootp_relay': 0, 'log_martians': 0, 'tag': 0, 'arpfilter': 0, 'medium_id': 0, 'noxfrm': 0, 'nopolicy': 0, 'force_igmp_version': 0, 'arp_announce': 0, 'arp_ignore': 0, 'promote_secondaries': 0, 'arp_accept': 0, 'arp_notify': 0, 'accept_local': 0, 'src_vmark': 0, 'proxy_arp_pvlan': 0, 'route_localnet': 0, 'igmpv2_unsolicited_report_interval': 10000, 'igmpv3_unsolicited_report_interval': 1000}), ('AF_INET6', {'attrs': [('IFLA_INET6_FLAGS', 2147483648), ('IFLA_INET6_CACHEINFO', {'max_reasm_len': 65535, 'tstamp': 104097, 'reachable_time': 20284, 'retrans_time': 1000}), ('IFLA_INET6_CONF', {'forwarding': 1, 'hop_limit': 64, 'mtu': 1500, 'accept_ra': 0, 'accept_redirects': 1, 'autoconf': 1, 'dad_transmits': 1, 'router_solicitations': 4294967295, 'router_solicitation_interval': 4000, 'router_solicitation_delay': 1000, 'use_tempaddr': 0, 'temp_valid_lft': 604800, 'temp_preferred_lft': 86400, 'regen_max_retry': 3, 'max_desync_factor': 600, 'max_addresses': 16, 'force_mld_version': 0, 'accept_ra_defrtr': 1, 'accept_ra_pinfo': 1, 'accept_ra_rtr_pref': 1, 'router_probe_interval': 60000, 'accept_ra_rt_info_max_plen': 0, 'proxy_ndp': 0, 'optimistic_dad': 0, 'accept_source_route': 0, 'mc_forwarding': 0, 'disable_ipv6': 0, 'accept_dad': 1, 'force_tllao': 0, 'ndisc_notify': 0}), ('IFLA_INET6_STATS', {'num': 36, 'inpkts': 4, 'inoctets': 224, 'indelivers': 4, 'outforwdatagrams': 0, 'outpkts': 35, 'outoctets': 2912, 'inhdrerrors': 0, 'intoobigerrors': 0, 'innoroutes': 0, 'inaddrerrors': 0, 'inunknownprotos': 0, 'intruncatedpkts': 0, 'indiscards': 0, 'outdiscards': 0, 'outnoroutes': 0, 'reasmtimeout': 0, 'reasmreqds': 0, 'reasmoks': 0, 'reasmfails': 0, 'fragoks': 0, 'fragfails': 0, 'fragcreates': 0, 'inmcastpkts': 4, 'outmcastpkts': 35, 'inbcastpkts': 0, 'outbcastpkts': 0, 'inmcastoctets': 224, 'outmcastoctets': 2912, 'inbcastoctets': 0, 'outbcastoctets': 0, 'csumerrors': 0, 'noectpkts': 4, 'ect1pkts': 0, 'ect0pkts': 0, 'cepkts': 0}), ('IFLA_INET6_ICMP6STATS', {'num': 6, 'inmsgs': 4, 'inerrors': 0, 'outmsgs': 35, 'outerrors': 0, 'csumerrors': 0}), ('IFLA_INET6_TOKEN', '::'), ('IFLA_INET6_ADDR_GEN_MODE', 0)]})]})], 'header': {'length': 1336, 'type': 16, 'flags': 0, 'sequence_number': 256, 'pid': 2853, 'error': None}, 'event': 'RTM_NEWLINK'},)



with IPDB() as ipdb:
    ifaces = ipdb.by_index
    for iface in ifaces:
        if ipdb.interfaces[iface].ifname == 'ens160':
            print(ipdb.interfaces[iface])

{'address': '00:50:56:aa:37:1f', 'broadcast': 'ff:ff:ff:ff:ff:ff', 'ifname': 'ens160', 'mtu': 1500, 'qdisc': 'mq', 'txqlen': 1000, 'operstate': 'UP', 'linkmode': 0, 'ifalias': 'management', 'group': 0, 'promiscuity': 0, 'num_tx_queues': 2, 'num_rx_queues': 2, 'carrier': 1, 'carrier_changes': 5, 'proto_down': 0, 'gso_max_segs': 65535, 'gso_max_size': 65536, 'xdp': '05:00:02:00:00:00:00:00', 'carrier_up_count': 3, 'carrier_down_count': 2, 'index': 2, 'flags': 69699, 'ipdb_scope': 'system', 'ipdb_priority': 0, 'vlans': (), 'ipaddr': (('fe80::250:56ff:feaa:371f', 64), ('10.253.202.32', 23)), 'ports': (), 'family': 0, 'ifi_type': 1, 'neighbours': ('10.253.202.5', '10.253.202.4', '10.253.202.2', '10.253.202.3', '10.253.202.1')}


Peter Saveliev

unread,
Feb 12, 2019, 10:24:42 AM2/12/19
to brian.s...@wwt.com, pyroute2-dev
You can see the master interface index in the IFLA_MASTER attribute.

IPDB, probably, doesn't register master interfaces for the vrf type, I'm to fix that. But IPDB has other limitations and will be obsoleted by NDB this year.

pá 8. 2. 2019 v 18:04 odesílatel <brian.s...@wwt.com> napsal:
--
You received this message because you are subscribed to the Google Groups "pyroute2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

brian.s...@wwt.com

unread,
Feb 12, 2019, 10:26:35 AM2/12/19
to pyroute2-dev
If IPDB is going obsolete do you recommend using IPRoute instead?

Peter Saveliev

unread,
Feb 12, 2019, 10:40:07 AM2/12/19
to brian.s...@wwt.com, pyroute2-dev
Since these modules use completely different approaches, I can not say «scrap all the code and use another module instead», if you already started.

So if you prefer IPDB, let it be, but then you may migrate later this year. The coming module, NDB, will not be a pure drop-in replacement, but there will be a migration process.

The IPDB module will remain in the project as long as there will be other projects depending on it. But there will be no new features in IPDB, only bug fixes.

út 12. 2. 2019 v 16:26 odesílatel <brian.s...@wwt.com> napsal:

Eugene Crosser

unread,
Jul 11, 2019, 9:59:26 AM7/11/19
to pyroute2-dev
Is it possible to do the opposite: obtain the list of interface indices that are enslaved with a given vrf/bridge/bond?

(obviously I can do it by hand, filtering interfaces with the given IFLA_MASTER, but maybe there is a more idiomatic way?)

On Tuesday, February 12, 2019 at 4:24:42 PM UTC+1, Peter Saveliev wrote:
You can see the master interface index in the IFLA_MASTER attribute.

IPDB, probably, doesn't register master interfaces for the vrf type, I'm to fix that. But IPDB has other limitations and will be obsoleted by NDB this year.

pá 8. 2. 2019 v 18:04 odesílatel <brian....@wwt.com> napsal:
To unsubscribe from this group and stop receiving emails from it, send an email to pyrout...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages