Skip to content

mctpd: Remove downstream peers when bridge node is removed - #173

Closed
potinlai wants to merge 1 commit into
CodeConstruct:mainfrom
potinlai:potin-remove-learn-eid
Closed

potinlai wants to merge 1 commit into
CodeConstruct:mainfrom
potinlai:potin-remove-learn-eid

Conversation

@potinlai

Copy link
Copy Markdown
Contributor

Currently, remove_bridged_peers() checks 'if (!sources)' and returns
early if bridge_ep_poll.sources is NULL. The sources array is only
allocated when periodic bridge endpoint polling is enabled.

However, downstream endpoints within the allocated bridge pool range
can still be discovered and added to the network via the LearnEndpoint
D-Bus method (or static assignment) even when periodic polling is not
active.

When a bridge node is removed, the early return in
remove_bridged_peers() causes the pool iteration loop to be skipped if
polling was inactive. As a result, downstream node EID objects remain
registered in mctpd and published on D-Bus as orphaned endpoints.

Fix this by:

  1. Replacing the early 'if (!sources) return 0;' check with network
    validation ('if (!n) return -EPROTO;').
  2. Guarding polling timer teardown with 'if (sources && sources[idx])'.

This ensures remove_bridged_peers() always iterates across the bridge's
allocated pool range [pool_start, pool_end] and invokes remove_peer() on
all existing downstream node EID objects when the parent bridge node is
removed.

@jk-ozlabs jk-ozlabs self-assigned this Aug 21, 2026
@potinlai

potinlai commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping on this review.
Please kindly let me know if any concerns of the changes.

@jk-ozlabs

Copy link
Copy Markdown
Member

Are you able to add a test case to cover this?

@potinlai
potinlai force-pushed the potin-remove-learn-eid branch from 1745357 to 763e2e5 Compare October 12, 2026 09:22
Currently, remove_bridged_peers() checks 'if (!sources)' and returns
early if bridge_ep_poll.sources is NULL. The sources array is only
allocated when periodic bridge endpoint polling is enabled.

However, downstream endpoints within the allocated bridge pool range
can still be discovered and added to the network via the LearnEndpoint
D-Bus method (or static assignment) even when periodic polling is not
active.

When a bridge node is removed, the early return in
remove_bridged_peers() causes the pool iteration loop to be skipped if
polling was inactive. As a result, downstream node EID objects remain
registered in mctpd and published on D-Bus as orphaned endpoints.

Fix this by:
1. Replacing the early 'if (!sources) return 0;' check with network
   validation ('if (!n) return -EPROTO;').
2. Guarding polling timer teardown with 'if (sources && sources[idx])'.

This ensures remove_bridged_peers() always iterates across the bridge's
allocated pool range [pool_start, pool_end] and invokes remove_peer() on
all existing downstream node EID objects when the parent bridge node is
removed.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
@potinlai
potinlai force-pushed the potin-remove-learn-eid branch from 763e2e5 to 0c3eccd Compare October 12, 2026 09:25
@potinlai

Copy link
Copy Markdown
Contributor Author

Are you able to add a test case to cover this?

Test case added, please have a review.
Thank you.

@jk-ozlabs

Copy link
Copy Markdown
Member

Test case added, please have a review. Thank you.

Nice one, thanks! I'll check it out.

@jk-ozlabs

Copy link
Copy Markdown
Member

I have merged this, with a minor change to the testcase formatting (and ordering within the file), but github has not detected this as a merge. Closing manually, thanks for the contribution!

@jk-ozlabs jk-ozlabs closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants