Skip to content

bgpd: Fix copy-paste error in SRv6 DT46 SID duplicate install check (CID 1670455) - #21443

Merged
mjstapp merged 1 commit into
FRRouting:masterfrom
cscarpitta:fix_srv6_sid_notify_cid
Apr 2, 2026
Merged

bgpd: Fix copy-paste error in SRv6 DT46 SID duplicate install check (CID 1670455)#21443
mjstapp merged 1 commit into
FRRouting:masterfrom
cscarpitta:fix_srv6_sid_notify_cid

Conversation

@cscarpitta

@cscarpitta cscarpitta commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

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));

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-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a Coverity-reported copy-paste error (CID 1670455) in bgp_zebra_srv6_sid_notify() within the SRv6 DT46 SID duplicate install check. The second sid_same condition was mistakenly comparing bgp_vrf->srv6_unicast[AFI_IP].zebra_sid_last_sent against bgp_vrf->srv6_unicast[AFI_IP6].sid instead of bgp_vrf->srv6_unicast[AFI_IP].sid. While functionally equivalent (since the preceding condition already asserts AFI_IP6.sid == AFI_IP.sid), the fix aligns the expression with its documented intent β€” checking whether AFI_IP has already installed the shared DT46 SID in zebra β€” eliminating the misleading cross-AFI reference.

  • File changed: bgpd/bgp_zebra.c, line 4042
  • Nature of fix: Replaces bgp_vrf->srv6_unicast[AFI_IP6].sid with bgp_vrf->srv6_unicast[AFI_IP].sid in the second sid_same() predicate
  • Functional impact: None at runtime (the outer condition guarantees both SIDs are equal), but the corrected form is unambiguously self-consistent and matches the surrounding comment and block logic

Confidence Score: 5/5

  • Safe to merge β€” the fix is functionally equivalent to the original (outer condition guarantees equality of both SIDs) and removes a legitimate source of reader confusion.
  • The change is a single-token correction with no behavioral difference at runtime. The Coverity finding is valid from a code-clarity perspective, and the fix makes the intent unambiguous. No new logic is introduced, no data structures are changed, and the surrounding control flow is untouched.
  • No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_zebra.c Single-line fix changing AFI_IP6.sid to AFI_IP.sid in the second sid_same condition, correcting the copy-paste error in the SRv6 DT46 duplicate install guard.

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
Loading

Reviews (1): Last reviewed commit: "bgpd: Fix copy-paste error in SRv6 DT46 ..." | Re-trigger Greptile

@mjstapp
mjstapp merged commit a955001 into FRRouting:master Apr 2, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants