BFD miscellaneous fixes - #21613
Conversation
Greptile SummaryThis PR contains three targeted BFD daemon fixes: (1) aligns the VTY text output of Confidence Score: 5/5Safe to merge; all three fixes are correct and well-scoped The only finding is a P2 style suggestion (unnecessary heap allocation for a stack-suitable struct). All logic is correct: the profile fix properly distinguishes between suppressing the profile reference only vs. the full profile name; the VTY counter guard matches the existing JSON path; and the doc examples match the actual output. bfdd/bfd.c β minor style note on the temporary XCALLOC pattern in bfd_profile_detach Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as NB CLI
participant NB as bfdd_nb_config
participant BFD as bfd.c
participant Hash as bfd_key_hash
Note over CLI,Hash: Profile removal (fix: preserve profile_name on sessions)
CLI->>NB: bfdd_bfd_profile_destroy()
NB->>BFD: bfd_profile_free(bp, suppress=false)
BFD->>BFD: bfd_profile_detach(bp, suppress=false)
BFD->>Hash: hash_iterate(_bfd_profile_detach, info)
Hash->>BFD: _bfd_profile_detach(session)
BFD->>BFD: bfd_profile_remove_reference(bs) bs->profile = NULL (keeps profile_name)
BFD->>BFD: bfd_session_apply(bs) uses peer_profile fallback
Note over CLI,Hash: Full config wipe (suppress=true removes profile_name too)
CLI->>NB: bfdd_bfd_destroy()
NB->>BFD: bfd_profiles_remove()
BFD->>BFD: bfd_profile_free(bp, suppress=true)
BFD->>BFD: bfd_profile_detach(bp, suppress=true)
Hash->>BFD: _bfd_profile_detach(session)
BFD->>BFD: bfd_profile_remove(bs) XFREE(profile_name) + clears profile
Prompt To Fix All With AIThis is a comment left during a code review.
Path: bfdd/bfd.c
Line: 2491-2500
Comment:
**Unnecessary heap allocation for a function-local struct**
`bfd_profile_detach_info` is allocated with `XCALLOC`, passed to `hash_iterate` (which is synchronous), and immediately freed β it never escapes the function. Allocating it on the stack is simpler, avoids an extra mtype definition (`BFDD_PROFILE_DETACH_INFO`), and carries no risk.
```suggestion
static void bfd_profile_detach(struct bfd_profile *bp, bool suppress_profile_from_session_config)
{
struct bfd_profile_detach_info prof_info = {
.bp = bp,
.suppress_config = suppress_profile_from_session_config,
};
hash_iterate(bfd_key_hash, _bfd_profile_detach, &prof_info);
}
```
You can then remove the `DEFINE_MTYPE_STATIC(BFDD, BFDD_PROFILE_DETACH_INFO, ...)` line as well.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "bfdd: fix do not unconfig bfd profile se..." | Re-trigger Greptile |
| static void bfd_profile_detach(struct bfd_profile *bp, bool suppress_profile_from_session_config) | ||
| { | ||
| hash_iterate(bfd_key_hash, _bfd_profile_detach, bp); | ||
| struct bfd_profile_detach_info *prof_info; | ||
|
|
||
| prof_info = XCALLOC(MTYPE_BFDD_PROFILE_DETACH_INFO, sizeof(struct bfd_profile_detach_info)); | ||
| prof_info->bp = bp; | ||
| prof_info->suppress_config = suppress_profile_from_session_config; | ||
| hash_iterate(bfd_key_hash, _bfd_profile_detach, prof_info); | ||
| XFREE(MTYPE_BFDD_PROFILE_DETACH_INFO, prof_info); | ||
| } |
There was a problem hiding this comment.
Unnecessary heap allocation for a function-local struct
bfd_profile_detach_info is allocated with XCALLOC, passed to hash_iterate (which is synchronous), and immediately freed β it never escapes the function. Allocating it on the stack is simpler, avoids an extra mtype definition (BFDD_PROFILE_DETACH_INFO), and carries no risk.
| static void bfd_profile_detach(struct bfd_profile *bp, bool suppress_profile_from_session_config) | |
| { | |
| hash_iterate(bfd_key_hash, _bfd_profile_detach, bp); | |
| struct bfd_profile_detach_info *prof_info; | |
| prof_info = XCALLOC(MTYPE_BFDD_PROFILE_DETACH_INFO, sizeof(struct bfd_profile_detach_info)); | |
| prof_info->bp = bp; | |
| prof_info->suppress_config = suppress_profile_from_session_config; | |
| hash_iterate(bfd_key_hash, _bfd_profile_detach, prof_info); | |
| XFREE(MTYPE_BFDD_PROFILE_DETACH_INFO, prof_info); | |
| } | |
| static void bfd_profile_detach(struct bfd_profile *bp, bool suppress_profile_from_session_config) | |
| { | |
| struct bfd_profile_detach_info prof_info = { | |
| .bp = bp, | |
| .suppress_config = suppress_profile_from_session_config, | |
| }; | |
| hash_iterate(bfd_key_hash, _bfd_profile_detach, &prof_info); | |
| } |
You can then remove the DEFINE_MTYPE_STATIC(BFDD, BFDD_PROFILE_DETACH_INFO, ...) line as well.
Prompt To Fix With AI
This is a comment left during a code review.
Path: bfdd/bfd.c
Line: 2491-2500
Comment:
**Unnecessary heap allocation for a function-local struct**
`bfd_profile_detach_info` is allocated with `XCALLOC`, passed to `hash_iterate` (which is synchronous), and immediately freed β it never escapes the function. Allocating it on the stack is simpler, avoids an extra mtype definition (`BFDD_PROFILE_DETACH_INFO`), and carries no risk.
```suggestion
static void bfd_profile_detach(struct bfd_profile *bp, bool suppress_profile_from_session_config)
{
struct bfd_profile_detach_info prof_info = {
.bp = bp,
.suppress_config = suppress_profile_from_session_config,
};
hash_iterate(bfd_key_hash, _bfd_profile_detach, &prof_info);
}
```
You can then remove the `DEFINE_MTYPE_STATIC(BFDD, BFDD_PROFILE_DETACH_INFO, ...)` line as well.
How can I resolve this? If you propose a fix, please make it concise.| hash_iterate(bfd_key_hash, _bfd_profile_detach, bp); | ||
| struct bfd_profile_detach_info *prof_info; | ||
|
|
||
| prof_info = XCALLOC(MTYPE_BFDD_PROFILE_DETACH_INFO, sizeof(struct bfd_profile_detach_info)); |
There was a problem hiding this comment.
I agreed with greptile this allocation seems unnecessary, the variable could just be put in the stack.
| } | ||
|
|
||
| void bfd_profile_free(struct bfd_profile *bp) | ||
| void bfd_profile_free(struct bfd_profile *bp, bool suppress_profile_from_session_config) |
There was a problem hiding this comment.
suppress_profile_from_session_config seems unnecessary long variable name, please can we make it shorter? suppress_profile maybe?
The json show does not display such counters. Do the same for the non json show. Fixes: 868c4d0 ("bfdd: adjust show commands for SBFD") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
BFD doc needs to be updated. Fixes: 9ae600c ("bfdd, yang: Add a bad packet counter for bfd peers") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
If a profile is used by a BFD session, then removing the profile from the configuration will also remove the configuration of that profile in that BFD session. This should not happen, as from config perspective, the profile config and the profile attached to the bfd session are two distinct elements. Fixes: f6dfa24 ("bfdd: remove profile pointers on removal") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
0556952 to
c21eb14
Compare
|
Waiting on @rzalamena 's comments |
See individual commits.