Skip to content

Commit 9711f0b

Browse files
committed
mctpd: Add routes prior to Set Endpoint ID
Route addition now occurs independently, during endpoint_assign_eid(). It is necessary for the route to already exist when the SetEndpointId request is sent, since a peer may expect to be able to initiate communication immediately. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent 47ceb55 commit 9711f0b

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/mctpd.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static int remove_peer(struct peer *peer);
240240
static int query_peer_properties(struct peer *peer);
241241
static int setup_added_peer(struct peer *peer);
242242
static void add_peer_route(struct peer *peer);
243-
static int publish_peer(struct peer *peer, bool add_route);
243+
static int publish_peer(struct peer *peer);
244244
static int unpublish_peer(struct peer *peer);
245245
static int peer_route_update(struct peer *peer, uint16_t type);
246246
static int peer_neigh_update(struct peer *peer, uint16_t type);
@@ -1763,7 +1763,8 @@ static int change_peer_eid(struct peer *peer, mctp_eid_t new_eid)
17631763
n->peers[new_eid] = n->peers[peer->eid];
17641764
n->peers[peer->eid] = NULL;
17651765
peer->eid = new_eid;
1766-
rc = publish_peer(peer, true);
1766+
add_peer_route(peer);
1767+
rc = publish_peer(peer);
17671768
if (rc)
17681769
return rc;
17691770

@@ -1843,6 +1844,11 @@ static int endpoint_assign_eid(struct ctx *ctx, sd_bus_error *berr,
18431844
}
18441845
}
18451846

1847+
/* Add a route to the peer prior to assigning it an EID.
1848+
* The peer may initiate communication immediately, so
1849+
* it should be routable. */
1850+
add_peer_route(peer);
1851+
18461852
rc = endpoint_send_set_endpoint_id(peer, &new_eid);
18471853
if (rc == -ECONNREFUSED)
18481854
sd_bus_error_setf(
@@ -2517,7 +2523,8 @@ static int peer_route_update(struct peer *peer, uint16_t type)
25172523
return -EPROTO;
25182524
}
25192525

2520-
/* Called when a new peer is discovered. Queries properties and publishes */
2526+
/* Called when a new peer is discovered. Queries properties and publishes.
2527+
* The peer's route has already been set up */
25212528
static int setup_added_peer(struct peer *peer)
25222529
{
25232530
int rc;
@@ -2533,7 +2540,7 @@ static int setup_added_peer(struct peer *peer)
25332540
if (rc < 0)
25342541
goto out;
25352542

2536-
rc = publish_peer(peer, true);
2543+
rc = publish_peer(peer);
25372544
out:
25382545
if (rc < 0) {
25392546
remove_peer(peer);
@@ -2572,8 +2579,9 @@ static void add_peer_neigh(struct peer *peer)
25722579
}
25732580

25742581
/* Adds routes/neigh. This is separate from
2575-
publish_peer() because we want a two stage setup of querying
2576-
properties (routed packets) then emitting dbus once finished */
2582+
publish_peer() because a route should exist prior to Set Endpoint ID,
2583+
and it will also need to exist while querying
2584+
properties (using routed packets). */
25772585
static void add_peer_route(struct peer *peer)
25782586
{
25792587
int rc;
@@ -2595,15 +2603,12 @@ static void add_peer_route(struct peer *peer)
25952603
}
25962604
}
25972605

2598-
/* Sets up routes/neigh, creates dbus object and emits added signal */
2599-
static int publish_peer(struct peer *peer, bool add_route)
2606+
/* Creates dbus object and emits added signal.
2607+
* Route/neigh should already have been added. */
2608+
static int publish_peer(struct peer *peer)
26002609
{
26012610
int rc = 0;
26022611

2603-
if (add_route && peer->state == REMOTE) {
2604-
add_peer_route(peer);
2605-
}
2606-
26072612
if (peer->published)
26082613
return 0;
26092614

@@ -2960,7 +2965,7 @@ static int method_net_learn_endpoint(sd_bus_message *call, void *data,
29602965

29612966
query_peer_properties(peer);
29622967

2963-
publish_peer(peer, false);
2968+
publish_peer(peer);
29642969

29652970
peer_path = path_from_peer(peer);
29662971
if (!peer_path)
@@ -3718,7 +3723,8 @@ static int change_net_interface(struct ctx *ctx, int ifindex, uint32_t old_net)
37183723
new_n->peers[peer->eid] = old_n->peers[peer->eid];
37193724
old_n->peers[peer->eid] = NULL;
37203725
peer->net = new_net;
3721-
rc = publish_peer(peer, true);
3726+
add_peer_route(peer);
3727+
rc = publish_peer(peer);
37223728
if (rc) {
37233729
warnx("Error publishing new peer eid %d, net %d after change: %s",
37243730
peer->eid, peer->net, strerror(-rc));
@@ -3773,7 +3779,7 @@ static int add_local_eid(struct ctx *ctx, uint32_t net, int eid)
37733779
warnx("Out of memory");
37743780
}
37753781

3776-
rc = publish_peer(peer, true);
3782+
rc = publish_peer(peer);
37773783
if (rc) {
37783784
warnx("Error publishing local eid %d net %d", eid, net);
37793785
}

0 commit comments

Comments
 (0)