Skip to content

Conversation

jinliangw
Copy link

Tested:
The bridged MCTP endpoints are removed when interface is removed or when MCTP bridge EID is removed.

set -e
for i in {1..10}; do
  echo "loop: $i start"
  busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/interfaces/mctpusb0 au.com.codeconstruct.MCTP.BusOwner1 SetupEndpoint ay 0
  # MCU needs some time to build routing table
  sleep 5
  for eid in 10 12; do
    busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1 au.com.codeconstruct.MCTP.Network1 LearnEndpoint y $eid
  done
  sleep 1
  busctl call au.com.codeconstruct.MCTP1 /au/com/codeconstruct/mctp1/networks/1/endpoints/8 au.com.codeconstruct.MCTP.Endpoint1 Remove
  sleep 2
  echo "loop: $i done"
done



Sep 24 00:11:19 mctpd[24909]: method_setup_endpoint: peer (nil), eid 8, is_bridge 1 ep type 10
Sep 24 00:11:19 mctpd[24909]: Adding route to peer eid 8 net 1 phys physaddr if 131 hw len 0 0x state 0
Sep 24 00:11:19 mctpd[24909]: physaddr if 131 hw len 0 0x requested allocation of pool size = 4
Sep 24 00:11:19 mctpd[24909]: Adding route to peer eid 8 net 1 phys physaddr if 131 hw len 0 0x state 0
Sep 24 00:11:19 mctpd[24909]: mctpd: emitting endpoint add: /au/com/codeconstruct/mctp1/networks/1/endpoints/8
Sep 24 00:11:19 mctpd[24909]: Allocation accepted
Sep 24 00:11:19 mctpd[24909]: Allocated size of 4, starting from EID 9
Sep 24 00:11:19 mctpd[24909]: Bridge (eid 8) assigned pool [9, 12], size 4
Sep 24 00:11:24 mctpd[24909]: mctpd: emitting endpoint add: /au/com/codeconstruct/mctp1/networks/1/endpoints/10
Sep 24 00:11:24 mctpd[24909]: mctpd: emitting endpoint add: /au/com/codeconstruct/mctp1/networks/1/endpoints/12
Sep 24 00:11:25 mctpd[24909]: mctpd: emitting endpoint remove: /au/com/codeconstruct/mctp1/networks/1/endpoints/10
Sep 24 00:11:25 mctpd[24909]: mctpd: emitting endpoint remove: /au/com/codeconstruct/mctp1/networks/1/endpoints/12
Sep 24 00:11:25 mctpd[24909]: Deleting route to peer eid 8 net 1 phys physaddr if 131 hw len 0 0x state 0
Sep 24 00:11:25 mctpd[24909]: mctpd: emitting endpoint remove: /au/com/codeconstruct/mctp1/networks/1/endpoints/8

src/mctpd.c Outdated
return -EPROTO;
}

if (peer->pool_size > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the condition here, the condition in the for loop will handle this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the check.

src/mctpd.c Outdated
if (peer->pool_size > 0) {
for (i = 0; i < peer->pool_size; i++) {
eid = peer->pool_start + i;
if (eid < 256 && n->peers[eid]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being a uint8_t, eid will always be < 256; the case you're looking to check here will be hidden via an overflow.

If you want to check the pool end validity, you'll need to do so in a larger type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Added the check if (peer->pool_start > 255 - i) to avoid uint8_t overflow.

Tested:
The bridged MCTP endpoints are removed when interface is removed or
when MCTP bridge EID is removed.

Signed-off-by: Jinliang Wang <[email protected]>
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