Repository navigation
Bfdd yang stuff - #21040
Bfdd yang stuff#21040donaldsharp wants to merge 6 commits into
Conversation
Greptile SummaryThis PR converts the Key changes:
Issues found:
Confidence Score: 3/5
Sequence DiagramsequenceDiagram
participant Op as Operator (vtysh)
participant Mgmtd as mgmtd
participant BFDD as bfdd daemon
participant NB as Northbound (YANG)
Op->>Mgmtd: "bfd / sbfd reflector ..." (CLI via VTYSH_MGMTD)
Note over Mgmtd: bfdd_cli_init() registered in mgmt_vty_init()
Mgmtd->>Mgmtd: nb_cli_enqueue_change (NB_OP_CREATE/DESTROY)
Mgmtd->>NB: nb_cli_apply_changes()
NB->>Mgmtd: Validates YANG model (frr-bfdd.yang)
Mgmtd->>BFDD: mgmt_be_client sends config xpaths
BFDD->>NB: bfdd_bfd_sbfd_reflector_create / destroy (NB_EV_APPLY)
NB->>BFDD: sbfd_reflector_new / sbfd_reflector_free
Op->>BFDD: "show sbfd reflector" (direct, bfdd_vty.c)
BFDD->>BFDD: sbfd_discr_iterate(_sbfd_reflector_show)
BFDD->>Op: ttable output
Last reviewed commit: 5e78587 |
| case NB_EV_VALIDATE: | ||
| if (echo && !bglobal.bg_use_dplane) { | ||
| #ifdef BFD_LINUX | ||
| snprintf(args->errmsg, args->errmsg_len, | ||
| "Echo mode works correctly for IPv4, but only works when the peer is also FRR for IPv6."); | ||
| #else | ||
| snprintf(args->errmsg, args->errmsg_len, | ||
| "Current implementation of echo mode works only when the peer is also FRR."); | ||
| #endif | ||
| } | ||
| return NB_OK; |
There was a problem hiding this comment.
Echo-mode warning silently dropped
The warning is written to args->errmsg but NB_OK is returned immediately afterwards. The northbound framework only displays the errmsg buffer to the user when the callback returns a non-OK status (e.g., NB_ERR_VALIDATION). Returning NB_OK with a message in errmsg means the warning is completely discarded — this is a regression from the original code that called vty_out() to show the warning to the operator.
If the intent is to keep this as a non-blocking warning (allow the command to succeed), the warning should be issued through a different mechanism (e.g., via vty_out from the CLI layer) or the errmsg block should be removed.
| case NB_EV_VALIDATE: | |
| if (echo && !bglobal.bg_use_dplane) { | |
| #ifdef BFD_LINUX | |
| snprintf(args->errmsg, args->errmsg_len, | |
| "Echo mode works correctly for IPv4, but only works when the peer is also FRR for IPv6."); | |
| #else | |
| snprintf(args->errmsg, args->errmsg_len, | |
| "Current implementation of echo mode works only when the peer is also FRR."); | |
| #endif | |
| } | |
| return NB_OK; | |
| case NB_EV_VALIDATE: | |
| return NB_OK; |
Or, if a warning is needed, it needs to be issued from the CLI command handler rather than from the NB validate callback.
Prompt To Fix With AI
This is a comment left during a code review.
Path: bfdd/bfdd_nb_config.c
Line: 1004-1014
Comment:
**Echo-mode warning silently dropped**
The warning is written to `args->errmsg` but `NB_OK` is returned immediately afterwards. The northbound framework only displays the `errmsg` buffer to the user when the callback returns a *non-OK* status (e.g., `NB_ERR_VALIDATION`). Returning `NB_OK` with a message in `errmsg` means the warning is completely discarded — this is a regression from the original code that called `vty_out()` to show the warning to the operator.
If the intent is to keep this as a non-blocking warning (allow the command to succeed), the warning should be issued through a different mechanism (e.g., via `vty_out` from the CLI layer) or the errmsg block should be removed.
```suggestion
case NB_EV_VALIDATE:
return NB_OK;
```
Or, if a warning is needed, it needs to be issued from the CLI command handler rather than from the NB validate callback.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Agreed — the fix would be to either return NB_ERR_VALIDATION if this should block the command, or move the warning to the CLI layer (e.g., the bfdd_vty.c command handler) using vty_out() if it should be non-blocking.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules and .greptile/config.
| int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args) | ||
| { | ||
| return NB_OK; | ||
| } |
There was a problem hiding this comment.
Stub source-address modify callback silently accepts no-op updates
bfdd_bfd_sbfd_reflector_source_address_modify always returns NB_OK without performing any action. If a user modifies the source-address of an existing reflector (without deleting and re-creating it), the YANG layer will accept the change, the running config will reflect the new value, but the in-memory sbfd_reflector object created during bfdd_bfd_sbfd_reflector_create will retain the old source address. This creates a silent divergence between the YANG data store and the actual runtime state.
If modifying the source-address in-place is not supported, the callback should return NB_ERR_INCONSISTENCY or NB_ERR_NOT_FOUND with a meaningful errmsg explaining that the reflector must be deleted and re-created. Alternatively, the callback should retrieve the running entry via nb_running_get_entry and update the sr->local field.
Prompt To Fix With AI
This is a comment left during a code review.
Path: bfdd/bfdd_nb_config.c
Line: 1280-1283
Comment:
**Stub `source-address` modify callback silently accepts no-op updates**
`bfdd_bfd_sbfd_reflector_source_address_modify` always returns `NB_OK` without performing any action. If a user modifies the `source-address` of an existing reflector (without deleting and re-creating it), the YANG layer will accept the change, the running config will reflect the new value, but the in-memory `sbfd_reflector` object created during `bfdd_bfd_sbfd_reflector_create` will retain the old source address. This creates a silent divergence between the YANG data store and the actual runtime state.
If modifying the source-address in-place is not supported, the callback should return `NB_ERR_INCONSISTENCY` or `NB_ERR_NOT_FOUND` with a meaningful `errmsg` explaining that the reflector must be deleted and re-created. Alternatively, the callback should retrieve the running entry via `nb_running_get_entry` and update the `sr->local` field.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Thanks for confirming. Two options to fix it:
Option 1 — Update in-place:
| int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args) | |
| { | |
| return NB_OK; | |
| } | |
| int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args) | |
| { | |
| struct sbfd_reflector *sr; | |
| const char *srcip_str; | |
| if (args->event != NB_EV_APPLY) | |
| return NB_OK; | |
| sr = nb_running_get_entry(args->dnode, NULL, true); | |
| srcip_str = yang_dnode_get_string(args->dnode, "."); | |
| inet_pton(AF_INET6, srcip_str, &sr->local); | |
| return NB_OK; | |
| } |
Option 2 — Reject with a clear error:
| int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args) | |
| { | |
| return NB_OK; | |
| } | |
| int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args) | |
| { | |
| if (args->event == NB_EV_VALIDATE) | |
| snprintf(args->errmsg, args->errmsg_len, | |
| "source-address cannot be modified in place; delete and re-create the reflector"); | |
| return NB_ERR_INCONSISTENCY; | |
| } |
Option 1 is cleaner UX if sr->local can safely be updated at runtime. Option 2 is safer if the reflector lookup/forwarding logic caches the address elsewhere.
| sbfd_reflector_enqueue_create(vty, atol(pstr), srcip_str); | ||
| } else if (strspn(pstr, "0123456789-") == strlen(pstr)) { | ||
| strlcpy(range_buf, pstr, sizeof(range_buf)); | ||
| char *token = strtok(range_buf, "-"); | ||
|
|
||
| discr_from = 0; | ||
| discr_to = 0; | ||
| if (token) | ||
| discr_from = atol(token); | ||
|
|
||
| token = strtok(NULL, "-"); | ||
| if (token) | ||
| discr_to = atol(token); |
There was a problem hiding this comment.
atol() can overflow for large discriminator values
atol() returns a signed long. On 32-bit platforms where long is 32 bits, discriminator values near UINT32_MAX (e.g., 4294967295) will overflow and produce a large negative value, which is then cast to uint32_t silently. The same issue applies on lines 1167 and 1170 inside the range-parsing branch.
Use strtoul() instead, which is designed for unsigned 32-bit parsing:
| sbfd_reflector_enqueue_create(vty, atol(pstr), srcip_str); | |
| } else if (strspn(pstr, "0123456789-") == strlen(pstr)) { | |
| strlcpy(range_buf, pstr, sizeof(range_buf)); | |
| char *token = strtok(range_buf, "-"); | |
| discr_from = 0; | |
| discr_to = 0; | |
| if (token) | |
| discr_from = atol(token); | |
| token = strtok(NULL, "-"); | |
| if (token) | |
| discr_to = atol(token); | |
| sbfd_reflector_enqueue_create(vty, (uint32_t)strtoul(pstr, NULL, 10), srcip_str); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: bfdd/bfdd_cli.c
Line: 1159-1170
Comment:
**`atol()` can overflow for large discriminator values**
`atol()` returns a signed `long`. On 32-bit platforms where `long` is 32 bits, discriminator values near `UINT32_MAX` (e.g., `4294967295`) will overflow and produce a large negative value, which is then cast to `uint32_t` silently. The same issue applies on lines 1167 and 1170 inside the range-parsing branch.
Use `strtoul()` instead, which is designed for unsigned 32-bit parsing:
```suggestion
sbfd_reflector_enqueue_create(vty, (uint32_t)strtoul(pstr, NULL, 10), srcip_str);
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
I think this pattern is present throughout the code base?
There was a problem hiding this comment.
Yes, atol() appears in 8 files across the codebase, and at least 5 of those assign to uint32_t types (in lib/vty.c, bgpd/bgp_clist.c, isisd/isis_vty_fabricd.c, lib/plist.c, and here in bfdd_cli.c). It's a fairly common pattern.
That said, it's still worth fixing here—the overflow risk is real on 32-bit systems, and using strtoul() is the correct approach for unsigned parsing. If the maintainers decide it's worth addressing codebase-wide, that could be a separate cleanup effort.
5e78587 to
53b73a3
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
riw777
left a comment
There was a problem hiding this comment.
looks good, just waiting on whether the ai bits need to be fixed
| sbfd_reflector_enqueue_create(vty, atol(pstr), srcip_str); | ||
| } else if (strspn(pstr, "0123456789-") == strlen(pstr)) { | ||
| strlcpy(range_buf, pstr, sizeof(range_buf)); | ||
| char *token = strtok(range_buf, "-"); | ||
|
|
||
| discr_from = 0; | ||
| discr_to = 0; | ||
| if (token) | ||
| discr_from = atol(token); | ||
|
|
||
| token = strtok(NULL, "-"); | ||
| if (token) | ||
| discr_to = atol(token); |
There was a problem hiding this comment.
I think this pattern is present throughout the code base?
rzalamena
left a comment
There was a problem hiding this comment.
I agree with the greptileai comments and I think they should be addressed:
- Use
strtoul()(orstrtoull) instead ofato*functions - The
bfdd_bfd_sbfd_reflector_source_address_modifyneeds to update the internal data structure source address (or become read only somehow) - The
bfdd_bfd_sessions_single_hop_echo_mode_modifywarning should become azlog_infoor returnNB_ERR_VALIDATIONto prevent the configuration
| return NB_OK; | ||
|
|
||
| discr = yang_dnode_get_uint32(args->dnode, "discriminator"); | ||
| srcip_str = yang_dnode_get_string(args->dnode, "source-address"); |
There was a problem hiding this comment.
We can use yang_dnode_get_ipv6 instead of yang_dnode_get_string + inet_pton.
|
This PR is stale because it has been open 180 days with no activity. Comment or remove the |
53b73a3 to
9e70f3d
Compare
After commit 7d2889b ("mgmtd: allow info msg on successful config apply"), mgmtd started printing: % Configuration applied with notes: No changes found to be committed! Whenever a CLI command resulted in no config diff -- for example, re-entering an existing sub-mode like `bfd` or `peer ...`, or setting an already-set value. Previously that message was dropped on the floor for normal CLI commands, and only backend apply notes were meant to be shown there. Keep backend apply notes separate from the no-changes case by adding a `changed` flag to the commit reply message (matching edit replies) and only forwarding info strings on actual applied changes. For explicit `mgmt commit` commands, continue to report `MGMTD: No changes found to be committed!` when nothing changed, while keeping regular VTY config commands silent on no-ops. Also avoid passing the internal `"commit abort"` string back as a user-facing apply note. Fixes: 7d2889b ("mgmtd: allow info msg on successful config apply") Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The sbfdd changes came in under PR FRRouting#17336, we as a group missed that bfdd is already converted over to using yang and these new cli's should be using yang. Convert over to yang for these new commands. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This is a show command that does not belong in the bfdd_cli.c file, as that bfdd_cli.c is for northbound code. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Currently there is very little test coverage of sbfdd output being there as well as the yang working correctly. Add some basic manipulation to show that things are working Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This was errouneously placed into bfdd_cli.c it belongs in bfdd_cli.c instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The bfd daemon had basically everything ready for conversion over to mgmtd. Let's pull the trigger and make it happen. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
9e70f3d to
e64dbf9
Compare
a) Convert the sbfd code in bfdd to use yang
b) Move show commands into bfdd_vty.c
c) Add some tests for sbfd
d) Move command completion code into bfdd_vty.c
e) Convert bfdd to use mgmtd