bgpd: Fix copy-paste error in SRv6 DT46 SID duplicate install check (CID 1670455) - #21443
Merged
Merged
Conversation
SRv6 End.DT46 uses a single shared SID for both the IPv4 (AFI_IP) and
IPv6 (AFI_IP6) address families within a VRF. When zebra notifies bgpd
that a SID has been assigned, bgpd must install it for both AFIs. To
avoid sending zebra a duplicate ROUTE_ADD, the AFI_IP6 code path first
checks whether AFI_IP has already done the install:
1) do both AFIs currently hold the same SID?
2) has AFI_IP already sent that SID to zebra?
Condition 2 mistakenly compared AFI_IP.zebra_sid_last_sent against
AFI_IP6.sid instead of AFI_IP.sid. Because condition 1 first asserts
that AFI_IP6.sid == AFI_IP.sid, the result is coincidentally correct,
but the expression does not match its stated intent and was flagged as a
copy-paste error by Coverity.
Replace AFI_IP6.sid with AFI_IP.sid in the second sid_same() call so
that the condition reads as intended: "AFI_IP has already sent its own
SID to zebra, so AFI_IP6 can skip the duplicate install."
Fixes: Coverity CID 1670455 (COPY_PASTE_ERROR)
** CID 1670455: Incorrect expression (COPY_PASTE_ERROR)
/bgpd/bgp_zebra.c: 4003 in bgp_zebra_srv6_sid_notify()
_____________________________________________________________________________________________
*** CID 1670455: Incorrect expression (COPY_PASTE_ERROR)
/bgpd/bgp_zebra.c: 4003 in bgp_zebra_srv6_sid_notify()
3997 * set AFI_IP6 zebra_sid_last_sent to the same SID so AFI_IP6
3998 * does not send a duplicate ROUTE_ADD.
3999 */
4000 if (sid_same(bgp_vrf->srv6_unicast[AFI_IP6].sid,
4001 bgp_vrf->srv6_unicast[AFI_IP].sid) &&
4002 sid_same(bgp_vrf->srv6_unicast[AFI_IP].zebra_sid_last_sent,
>>> CID 1670455: Incorrect expression (COPY_PASTE_ERROR)
>>> "sid" in "sid_same(bgp_vrf->srv6_unicast[AFI_IP].zebra_sid_last_sent, bgp_vrf->srv6_unicast[AFI_IP6].sid)" looks like a copy-paste error.
4003 bgp_vrf->srv6_unicast[AFI_IP6].sid)) {
4004 XFREE(MTYPE_BGP_SRV6_SID,
4005 bgp_vrf->srv6_unicast[AFI_IP6].zebra_sid_last_sent);
4006 bgp_vrf->srv6_unicast[AFI_IP6].zebra_sid_last_sent =
4007 XCALLOC(MTYPE_BGP_SRV6_SID,
4008 sizeof(struct in6_addr));
Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
Greptile SummaryThis PR fixes a Coverity-reported copy-paste error (CID 1670455) in
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["bgp_zebra_srv6_sid_notify()\nctx.behavior == END_DT46"] --> B{is_srv6_unicast_dt46_enabled\nAFI_IP6?}
B -- No --> Z["skip AFI_IP6 processing"]
B -- Yes --> C{"sid_same(AFI_IP6.sid,\nAFI_IP.sid)?\n[shared DT46 SID?]"}
C -- No --> E{"sid_same(AFI_IP6.zebra_sid_last_sent,\nAFI_IP6.sid)?"}
E -- No --> F["bgp_srv6_unicast_sid_update(AFI_IP6)\n[install in zebra]"]
E -- Yes --> G["already installed, skip"]
C -- Yes --> D{"sid_same(AFI_IP.zebra_sid_last_sent,\nAFI_IP.sid)?\n[AFI_IP already installed?]"}
D -- "Yes (FIXED: was AFI_IP6.sid)" --> H["Copy AFI_IP6.zebra_sid_last_sent =\nAFI_IP6.sid\n[skip duplicate install]"]
D -- No --> E
Reviews (1): Last reviewed commit: "bgpd: Fix copy-paste error in SRv6 DT46 ..." | Re-trigger Greptile |
mjstapp
approved these changes
Apr 2, 2026
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.
Fixes: Coverity CID 1670455 (COPY_PASTE_ERROR)