Repository navigation
Conversation
Rule numbers determine evaluation order on VyOS, but there was no way to change a rule number after creation — the only option was to delete the rule and re-enter every field under a new number. A reorder backend and routes already existed but had been orphaned since the UI rewrite in 61849de removed the forms that posted to them. Chain and filter rule cards now offer three controls: - Up/down arrows, which swap a rule's number with its neighbour's. The arrow is hidden on the first and last rule of a chain. - A number field, which assigns an explicit rule number. If the number is already in use, that rule and any rules directly following it with no gap in between are each shifted up by one to make room; rules past the first gap are left alone. - A per-chain Resequence button, which rewrites every rule number to 10, 20, 30, ... while preserving relative order. The shared numbering logic lives in the new rule_order_functions module, which both chain_functions and filter_functions call with their own container — chains store rules flat, filters nest them under "rules". All rules being moved are removed before any are re-inserted so that swaps and cascading shifts cannot overwrite one another. reorder_chain_rule_in_data and reorder_filter_rule_in_data keep their names, signatures and form contract. Their behavior on a taken rule number changes from rejecting the request to shifting the occupant, and their tests are updated to match. Redirects no longer pass an empty anchor when validation fails. Note that a config push uses load_merge_candidate and emits only "set" commands, so renumbering adds the new rule number on the device without removing the old one. This already applied to rule deletion, but resequencing makes it much easier to hit, so the Resequence confirm dialog spells it out. Emitting matching "delete firewall" commands is left as follow-up work. No schema change and no migration; "rule-order" keeps its current meaning as a numerically sorted index of the rules that exist.
The chain_view and filter_view routes call list_user_files and list_snapshots, which query MongoDB directly, so the new integration test only passed where a local MongoDB happened to be running and failed in CI. Stub both alongside the data read/write patches. Verified by running the suite against an unreachable MONGODB_URI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rule numbers determine evaluation order on VyOS, but there was no way to change a rule number after creation — the only option was to delete the rule and re-enter every field under a new number. A reorder backend and routes already existed but had been orphaned since the UI rewrite in
61849deremoved the forms that posted to them.All changes verified: 447 tests pass, bandit clean.
Reordering controls
Chain and filter rule cards now offer three controls:
10, 20, 21, 30, moving10to20yields20, 21, 22, 30.10, 20, 30, ...while preserving relative order, to restore gaps in a chain whose numbers have been used up.Both IPv4 and IPv6, chains and filters. Every new form carries a CSRF token like the existing ones.
Implementation
package/rule_order_functions.pyholds the shared numbering logic — the swap/renumber/resequence map builders and a single mutation primitive. Bothchain_functionsandfilter_functionscall it with their own container, since chains store rules flat while filters nest them underrules. This addresses thereorder_*half of the duplication noted in the code review;delete_*_ruleandassemble_*are still duplicated./chain_rule_move,/chain_rules_resequence,/filter_rule_move,/filter_rules_resequence— POST-only,@login_required+@requires_firewall, redirecting back to the chain's anchor like the existing reorder routes.Behavior change
reorder_chain_rule_in_dataandreorder_filter_rule_in_datakeep their names, signatures and form contract, but a taken rule number now shifts the occupant instead of being rejected. Theirtest_duplicate_number_errortests are rewritten to assert the shift.Notes for existing installs
rule-orderkeeps its current meaning as a numerically sorted index of the rules that exist, so existing configs are untouched until someone uses a control.load_merge_candidateandgenerate_configemits onlysetcommands, so renumbering adds the new rule number and leaves the old numbered rule in place. This already applied to rule deletion, but resequencing makes it much easier to hit, so the Resequence confirm dialog spells it out. Emitting matchingdelete firewall ...commands is left as follow-up work.Tests
tests/test_rule_order_functions.py— the pure map builders and the mutation primitive, including the cascade, the999999bound and both container layouts.tests/test_rule_reorder_integration.py— drives the real routes and templates against an in-memory store (no MongoDB), covering render, move, renumber-with-shift and resequence for chains and filters.tests/test_chain_functions.pyandtests/test_filter_functions.py; route tests added totests/test_app_routes.py.