ipspace / netlab

Making virtual networking labs suck less
https://netlab.tools
Other
439 stars 66 forks source link

Analysis: changes needed to cope with #830 #831

Closed ipspace closed 1 year ago

ipspace commented 1 year ago

830 changed the way global VRF data is merged with node VRF data. The node VRF data structures contain just parts of global VRF data during most of the transformation process, which means that some other module using "node or global VRF" logic might use incorrect values.

We need to find all references to node.vrfs executed before VRF post_link_transform hook and fix them to use get_node_vrf_data abstraction function.

ipspace commented 1 year ago

Modules that are transformed after VRF module

ack --yaml 'transform_after.*vrf' netsim/modules -l
netsim/modules/gateway.yml
netsim/modules/evpn.yml
netsim/modules/ospf.yml
netsim/modules/eigrp.yml
netsim/modules/vxlan.yml
netsim/modules/isis.yml

BGP is transformed before VRF

ipspace commented 1 year ago

Files referencing 'vrfs' in one way or another:

netsim/augment/groups.py
netsim/extra/ebgp.utils/plugin.py
netsim/extra/proxy-arp/plugin.py
netsim/modules/vrf.py
netsim/modules/evpn.py
netsim/modules/bgp.py
netsim/modules/_dataplane.py
netsim/modules/mpls.py
netsim/modules/__init__.py
netsim/modules/_routing.py
netsim/data/validate.py
netsim/devices/junos.py
netsim/devices/arubacx.py

That leaves us with EVPN, BGP, MPLS modules, and __init__ and _routing routines.

ipspace commented 1 year ago

EVPN:

EVPN post-transform is executed after VRF post-transform. The module is OK as-is.

ipspace commented 1 year ago

MPLS:

MPLS post-transform is executed after VRF post-transform. The module is OK as-is.

ipspace commented 1 year ago

☣️ modules __init__ uses node VRF data in copy_node_data_into_interfaces which is called before module post-transform hooks, so it's potentially dangerous. Have to create a test case (example: OSPF area for VRF interfaces) to prove it.

ipspace commented 1 year ago

_routing library uses node VRF data primarily in build_vrf_interface_list. It also refers to node VRF data in remove_vrf_routing_blocks and remove_unused_igp.

build_vrf_interface_list is only used by OSPF (the only VRF-aware IGP) in its post-transform hook. remove_unused_igp is used by several modules (MPLS, OSPF, IS-IS) in post-transform hooks. remove_vrf_routing_blocks is used by OSPF and BGP.

☣️ The only questionable reference is remove_vrf_routing_blocks in BGP. Let's try to build a test case ;)

ipspace commented 1 year ago

☣️ BGP module uses node VRF data to build per-VRF neighbor list. The only race condition could arise if the global VRF has bgp set to False.

ipspace commented 1 year ago

Update: the VRF module copies global- into VRF data in the post_link_transform hook. It's OK to use VRF data in post-transform hook.