vtysh marking is ordering dependent (affecting frr-reload)
Describe the bug
The behaviour of vtysh -m can differ based on the ordering of sections in input configuration file. Since frr-reload.py marks all input files this can cause a failure to reload a valid configuration (particularly if the new configuration has already been marked correctly, as these are stripped).
For example, this snippet:
router bgp 65000
end
!
vrf foo
ip route 10.10.0.0/24 blackhole
exit-vrf
is not marked correctly:
line 6: % Unknown command: exit-vrf
router bgp 65000
!
vrf foo
end
ip route 10.10.0.0/24 blackhole
because vtysh treats vrf foo line as vrf-policy foo in BGP mode, rather than the global vrf command.
(put "x" in "[ ]" if you already tried following) [X] Did you check if this is a duplicate issue? [X] Did you test it on the latest FRRouting/frr master branch?
To Reproduce
Steps to reproduce the behavior:
Write the above snippet to a file and use vtysh -m -f <file>.
Expected behavior
Ideally vtysh would mark the sections correctly, however this might be tricky given the issue is caused by overlapping commands between modes. Possibly vtysh could keep looking for a better (absolute) match in parent modes, rather than taking the first match - but that could have its own issues (backwards compatibility, multiple absolute matches etc.)
As a workaround it should be possible to use frr-reload.py without having the inputs marked automatically by vtysh.
Screenshots If applicable, add screenshots to help explain your problem.
Versions
- OS Kernel: [e.g. Linux, OpenBSD, etc] [version]
- FRR Version: [version]
Additional context Add any other context about the problem here.
I was looking at this again and I think that vtysh -m can actually be made to work correctly.
For example, if we add an explicit "exit" line after the BGP section (rather than "end", which vtysh -m ignores), then it all works as intended:
$ cat test.conf
router bgp 65000
exit
!
vrf foo
ip route 10.10.0.0/24 blackhole
exit-vrf
$ sudo vtysh -m -f test.conf
router bgp 65000
exit
!
vrf foo
ip route 10.10.0.0/24 blackhole
exit-vrf
end
end
So the issue then appears to be in frr-reload.py, which does not include the explicit "exit" lines in the configuration which gets applied. So when it calls vtysh -f the same issue occurs - "vrf foo" is treated as "vrf-policy foo" in BGP mode.
Fixed in https://github.com/FRRouting/frr/pull/9331.