ospfd: add instance shutdown command - #21759
Conversation
Greptile SummaryThis PR introduces a Confidence Score: 4/5Mostly safe to merge; three P2 findings around ISM execution timing, GR timer/state interaction during shutdown, and excess AdjOK? events warrant review before landing. All three findings are P2 (non-blocking style/correctness suggestions). The SCHEDULEβEXECUTE change in
Important Files Changed
Sequence DiagramsequenceDiagram
participant Operator
participant ospf_vty
participant ospf_gr
participant ospfd
participant ospf_interface
participant Zebra
Operator->>ospf_vty: shutdown (with GR)
ospf_vty->>ospf_vty: check OSPF_OPAQUE_CAPABLE
ospf_vty->>ospf_gr: ospf_gr_restart_enter(SWITCH_CONTROL_PROCESSOR, now+grace_period)
ospf_gr->>ospf_gr: restart_in_progress=true, start grace timer
ospf_vty->>ospf_gr: ospf_gr_unplanned_start_interface(oi) per interface
ospf_gr-->>ospf_vty: Grace-LSAs flooded to all interfaces
ospf_vty->>ospfd: ospf_shutdown(ospf, true)
ospfd->>ospfd: SET_FLAG OSPF_SHUTDOWN
ospfd->>ospf_interface: ospf_if_down(oi) per interface
ospfd->>ospfd: ospf_area_lsdb_discard_delete + lsdb_delete_all
Note over ospf_gr: Grace period timer running...
Operator->>ospf_vty: no shutdown
ospf_vty->>ospfd: ospf_shutdown(ospf, false)
ospfd->>ospfd: UNSET_FLAG OSPF_SHUTDOWN
ospfd->>ospf_interface: ospf_if_up(oi) per interface [EXECUTE]
ospf_interface->>ospf_interface: ISM_InterfaceUp (synchronous)
ospfd->>ospfd: ospf_asbr_reoriginate()
ospfd-->>Zebra: AS-external LSAs re-flooded
ospf_gr->>ospf_gr: GR completes when adjacencies restored or grace period expires
Prompt To Fix All With AIThis is a comment left during a code review.
Path: ospfd/ospf_interface.c
Line: 857-866
Comment:
**`OSPF_ISM_EVENT_EXECUTE` changes behavior for all existing callers**
The switch from `OSPF_ISM_EVENT_SCHEDULE` (`event_add_event`) to `OSPF_ISM_EVENT_EXECUTE` (`event_execute`) affects every call site of `ospf_if_up`, not just the new shutdown/restart path. Existing callers such as `ospf_router_id_update` (ospfd.c:1118) and the internal downβup cycle at ospf_interface.c:175 now run the ISM state machine synchronously and re-entrantly, whereas before each ISM transition was deferred to the next event-loop iteration. If any of those callers hold shared state that the ISM handler mutates (e.g., neighbor lists, adjacency state), the in-place execution could cause subtle ordering differences. The new `OSPF_SHUTDOWN` guard added on the same line is clearly necessary; the EXECUTE change should be split out and justified separately if intentional for all call sites.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: ospfd/ospfd.c
Line: 2408-2425
Comment:
**Grace period timer can fire while OSPF instance is still shut down**
When `shutdown` is issued with GR enabled, `ospf_gr_restart_enter` starts a grace-period countdown timer (`t_grace_period`). If `no shutdown` is never issued (or is delayed beyond the grace period), `ospf_gr_grace_period_expired` fires while `OSPF_SHUTDOWN` is set and calls `ospf_gr_restart_exit`. That function calls `ospf_router_lsa_update_area` on every area (LSDB was just cleared) and schedules `ospf_spf_calculate_schedule(ospf, SPF_FLAG_GR_FINISH)` while setting `gr_info.finishing_restart = true`. If `no shutdown` is then issued after the timer has already fired, the instance starts with `restart_in_progress = false` and `finishing_restart` potentially still set, causing the GR-finish SPF to race with normal startup SPF runs. Adding a guard in `ospf_gr_grace_period_expired` (or `ospf_gr_restart_exit`) that skips the restart-exit logic when `OSPF_SHUTDOWN` is set would make the state machine cleaner.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: ospfd/ospf_ism.c
Line: 232-234
Comment:
**`ospf_dr_change` triggered on every DR election during GR restart**
Adding `|| oi->ospf->gr_info.restart_in_progress` to the condition means `ospf_dr_change` (and consequently `ospf_nbr_adj_ok` for every neighbor) is called on every invocation of `ospf_dr_election` while the instance is in GR restart β even on point-to-point links or when there are no neighbors. On a busy topology this produces spurious AdjOK? events per DR election cycle until `restart_in_progress` is cleared. Consider narrowing the condition to broadcast/NBMA interfaces where DR election actually matters, or only triggering when neighbors are present (`ospf_interface_neighbor_count(oi) > 0`).
How can I resolve this? If you propose a fix, please make it concise.Reviews (3): Last reviewed commit: "tests: topology test for OSPFv2 shutdown" | Re-trigger Greptile |
5f8f1ce to
29ce36a
Compare
Implement a shutdown command that stops the OSPFv2 instance and gets rid of all state. It also triggers the OSPFv2 graceful restart if configured. Rename the definition `OSPF_GR_SWITCH_REDUNDANT_CARD` to `OSPF_GR_SWITCH_CONTROL_PROCESSOR` to match the RFC 3623 specification. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Once an interface becomes ready to start, there's no need to schedule the "LoopInd" and "InterfaceUp" events, they can be triggered immediately. This solves a race condition where an OSPF interface could start after the OSPF instance was disabled with the "shutdown" command, since the `ospf_shutdown()` function has no way to cancel scheduled ISM events. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
When all neighbors in a broadcast segment have their router priority set to zero, the restarting router won't detect any BDR change when coming back up. It should also preserve its DR status, so it won't detect any DR change. Without detecting any DR/BDR change during the DR election process, the router won't trigger the AdjOk event which is necessary to move forward in the neighbor state machine. To fix this problem, always trigger the AdjOk event at the end of the DR election process when GR is in progress. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Test the new OSPFv2 shutdown feature. The topology tests the following cases: 1. Regular OSPFv2 instance shutdown 2. OSPFv2 instance shutdown with graceful restart The difference between the cases is that when graceful restart is enabled the OSPFv2 instance sends a grace LSA in all OSPF enabled interfaces so the helper routers keep the routes until the instance is not shutdown anymore. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
29ce36a to
a64e0eb
Compare
Introduce the
shutdownOSPFv2 instance command to temporally disable an instance and remove all state.This new command also has the extended functionality when used with graceful restart: it sends grace LSAs to all OSPF enabled interfaces to enable non stop forwarding while the instance is shutdown.