Skip to content

bgpd: remove unneeded sort of communities in rmap delete - #22151

Merged
Jafaral merged 1 commit into
FRRouting:masterfrom
mjstapp:fix_rmap_comm_del
Jun 2, 2026
Merged

bgpd: remove unneeded sort of communities in rmap delete#22151
Jafaral merged 1 commit into
FRRouting:masterfrom
mjstapp:fix_rmap_comm_del

Conversation

@mjstapp

@mjstapp mjstapp commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

When routemaps delete from a community list, don't need to re-sort the community list: the delete code preserves the sorted order.
this was F-079 from the 2026_05_27 batch of reports from Qifan Zhang

@frrbot frrbot Bot added the bgp label Jun 1, 2026
@github-actions github-actions Bot added master size/S rebase PR needs rebase labels Jun 1, 2026
@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown

Greptile Summary

This PR removes a redundant sort-and-dedup step (*_uniq_sort()) that followed *_list_match_delete() in three route-map community delete handlers (route_set_lcommunity_delete, route_set_community_delete, route_set_ecommunity_delete).

  • The intermediate merge variable and the *_uniq_sort() call are eliminated; the dup returned by *_list_match_delete() is used directly as new. This avoids an extra heap allocation and a full sort on every route-map application.
  • The claim is valid: each *_list_match_delete() function iterates in forward order, records indices to remove, then deletes them in reverse-index order using memmove β€” preserving the relative order of survivors. Because the input community is already interned/sorted with no duplicates, the output needs neither a re-sort nor a dedup.

Confidence Score: 5/5

This is a safe, well-reasoned cleanup that removes redundant memory allocations and sorting in three symmetric code paths without changing observable behavior.

The *_list_match_delete functions iterate in forward order and delete entries in reverse-index order via memmove, which provably preserves the sorted order of surviving elements. Because communities are already interned without duplicates, the removed *_uniq_sort call was doing no useful work. Memory ownership transfers cleanly β€” the dup is now used directly as new with the same lifetime and free/intern path as before. No behavioral difference is introduced.

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_routemap.c Removes the intermediate merge variable and the uniq_sort() call in three symmetric community-delete handlers; the deletion functions preserve sorted order in-place, so the optimization is correct.

Sequence Diagram

sequenceDiagram
    participant RM as route_set_*_delete
    participant DUP as community_dup
    participant DEL as *_list_match_delete
    participant SORT as *_uniq_sort (removed)
    participant ATTR as bgp_attr_set_*

    Note over RM,ATTR: Before this PR
    RM->>DUP: dup(old)
    DUP-->>RM: merge (heap alloc)
    RM->>DEL: match_delete(merge, list)
    DEL-->>RM: merge (in-place, sorted)
    RM->>SORT: uniq_sort(merge)
    SORT-->>RM: new (another heap alloc)
    RM->>RM: free(merge)
    RM->>ATTR: set_attr(new) or free(new)

    Note over RM,ATTR: After this PR
    RM->>DUP: dup(old)
    DUP-->>RM: new (heap alloc)
    RM->>DEL: match_delete(new, list)
    DEL-->>RM: new (in-place, sorted preserved)
    RM->>ATTR: set_attr(new) or free(new)
Loading

Reviews (1): Last reviewed commit: "bgpd: remove unneeded sort of communitie..." | Re-trigger Greptile

@mjstapp

mjstapp commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport stable/10.6 stable/10.5

@mergify

mergify Bot commented Jun 1, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.5

βœ… Backports have been created

Details

When routemaps delete from a community list, don't need to
re-sort the community list: the delete code preserves the sorted
order.

Signed-off-by: Mark Stapp <mjs@cisco.com>
Reported-by: Qifan Zhang <qzhang@paloaltonetworks.com>
@mjstapp
mjstapp force-pushed the fix_rmap_comm_del branch from adef297 to a603e0f Compare June 1, 2026 19:33

@Jafaral Jafaral 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.

Thanks!

@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

@riw777

riw777 commented Jun 1, 2026

Copy link
Copy Markdown
Member

It seems like this should be labeled a bug fix?

@Jafaral
Jafaral merged commit 182263b into FRRouting:master Jun 2, 2026
23 checks passed
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: remove unneeded sort of communities in rmap delete (backport #22151)
donaldsharp added a commit that referenced this pull request Jun 2, 2026
bgpd: remove unneeded sort of communities in rmap delete (backport #22151)
@mjstapp
mjstapp deleted the fix_rmap_comm_del branch June 9, 2026 15:39
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.

3 participants