Skip to content

Bfdd yang stuff - #21040

Open
donaldsharp wants to merge 6 commits into
FRRouting:masterfrom
donaldsharp:bfdd_yang_issues
Open

donaldsharp wants to merge 6 commits into
FRRouting:masterfrom
donaldsharp:bfdd_yang_issues

Conversation

@donaldsharp

Copy link
Copy Markdown
Member

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

@frrbot frrbot Bot added bfd mgmt FRR Management Infra tests Topotests, make check, etc yang labels Mar 7, 2026
@greptile-apps

greptile-apps Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR converts the bfdd daemon to use the mgmtd backend, migrates the sbfd reflector configuration to YANG northbound callbacks, moves show/completion commands into bfdd_vty.c, and adds several topotest cases for sbfd reflector management.

Key changes:

  • bfdd is registered as an mgmt_be_client with FRR_MGMTD_BACKEND | FRR_NO_SPLIT_CONFIG; config/oper/rpc xpaths are declared in bfdd.c
  • CLI show callbacks are split out from frr_bfdd_info into a new frr_bfdd_cli_info struct in bfdd_cli.c, which is now compiled into mgmtd/libmgmt_be_nb.la rather than bfdd_libbfd_a
  • YANG model gains a sbfd-reflector list keyed by discriminator with a mandatory IPv6 source-address
  • vtysh node-entering commands for BFD are updated from VTYSH_BFDD to VTYSH_MGMTD
  • mgmtd/subdir.am fixes an incorrect STATICD/RIPD conditional that was previously used to include frr-bfdd.yang.c

Issues found:

  • Echo-mode warning silently dropped: in bfdd_bfd_sessions_single_hop_echo_mode_modify, the NB_EV_VALIDATE case writes to args->errmsg but returns NB_OK, causing the warning to never be displayed to the operator (regression from the original vty_out behavior)
  • No-op source-address modify callback: bfdd_bfd_sbfd_reflector_source_address_modify is a stub that always returns NB_OK without updating the running sbfd_reflector object, creating silent state divergence if a user modifies an existing reflector's source address
  • atol() overflow for large discriminators: in bfdd_cli.c, atol() is used to parse discriminator values up to 4294967295; on 32-bit platforms this overflows a signed long; strtoul() is more appropriate

Confidence Score: 3/5

  • This PR is mostly safe to merge but has two functional regressions in the northbound config callbacks that should be addressed first.
  • The overall architecture (mgmtd backend integration, YANG model addition, build system fix) is sound. However, two issues in bfdd_nb_config.c reduce confidence: (1) the echo-mode operator warning is silently dropped due to errmsg/NB_OK mismatch, and (2) the source-address modify stub silently accepts changes without applying them, which could leave runtime state inconsistent with the config datastore. Additionally, there's a potential overflow issue in bfdd_cli.c with atol() parsing large discriminator values on 32-bit platforms.
  • bfdd/bfdd_nb_config.c requires the most attention — specifically the NB_EV_VALIDATE echo-mode warning and the no-op source-address modify callback. bfdd/bfdd_cli.c should be reviewed for the atol() overflow issue.

Sequence Diagram

sequenceDiagram
    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
Loading

Last reviewed commit: 5e78587

Comment thread bfdd/bfdd_nb_config.c
Comment on lines 1004 to +1014
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greptile looks valid

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bfdd/bfdd_nb_config.c
Comment on lines +1280 to +1283
int bfdd_bfd_sbfd_reflector_source_address_modify(struct nb_cb_modify_args *args)
{
return NB_OK;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greptile looks valid

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming. Two options to fix it:

Option 1 — Update in-place:

Suggested change
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:

Suggested change
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.

Comment thread bfdd/bfdd_cli.c Outdated
Comment on lines 1159 to 1170
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pattern is present throughout the code base?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@riw777
riw777 self-requested a review March 10, 2026 15:12
@vayetze
vayetze requested a review from choppsv1 March 10, 2026 15:22

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just waiting on whether the ai bits need to be fixed

Comment thread bfdd/bfdd_cli.c Outdated
Comment on lines 1159 to 1170
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pattern is present throughout the code base?

@rzalamena rzalamena left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the greptileai comments and I think they should be addressed:

  • Use strtoul() (or strtoull) instead of ato* functions
  • The bfdd_bfd_sbfd_reflector_source_address_modify needs to update the internal data structure source address (or become read only somehow)
  • The bfdd_bfd_sessions_single_hop_echo_mode_modify warning should become a zlog_info or return NB_ERR_VALIDATION to prevent the configuration

Comment thread bfdd/bfdd_nb_config.c
return NB_OK;

discr = yang_dnode_get_uint32(args->dnode, "discriminator");
srcip_str = yang_dnode_get_string(args->dnode, "source-address");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use yang_dnode_get_ipv6 instead of yang_dnode_get_string + inet_pton.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 180 days with no activity. Comment or remove the autoclose label in order to avoid having this PR closed.

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>
@github-actions github-actions Bot removed the autoclose label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bfd bugfix libfrr master mgmt FRR Management Infra size/XXL tests Topotests, make check, etc yang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants