Skip to content

Commit

Permalink
mctp: Allow keys matching any local address
Browse files Browse the repository at this point in the history
Currently, we require an exact match on an incoming packet's dest
address, and the key's local_addr field.

In a future change, we may want to set up a key before packets are
routed, meaning we have no local address to match on.

This change allows key lookups to match on local_addr = MCTP_ADDR_ANY.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jeremy Kerr authored and David S. Miller committed Feb 9, 2022
1 parent 8069b22 commit 0de55a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/mctp/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)
static bool mctp_key_match(struct mctp_sk_key *key, mctp_eid_t local,
mctp_eid_t peer, u8 tag)
{
if (key->local_addr != local)
if (!mctp_address_matches(key->local_addr, local))
return false;

if (key->peer_addr != peer)
Expand Down Expand Up @@ -616,7 +616,7 @@ static struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
continue;

if (!(mctp_address_matches(tmp->peer_addr, daddr) &&
tmp->local_addr == saddr))
mctp_address_matches(tmp->local_addr, saddr)))
continue;

spin_lock(&tmp->lock);
Expand Down
8 changes: 8 additions & 0 deletions net/mctp/test/route-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,14 @@ static const struct mctp_route_input_sk_keys_test mctp_route_input_sk_keys_tests
.hdr = RX_HDR(1, 11, 8, FL_S | FL_E | FL_T(1)),
.deliver = true,
},
{
.name = "any local match",
.key_peer_addr = 12,
.key_local_addr = MCTP_ADDR_ANY,
.key_tag = 1,
.hdr = RX_HDR(1, 12, 8, FL_S | FL_E | FL_T(1)),
.deliver = true,
},
};

static void mctp_route_input_sk_keys_to_desc(
Expand Down

0 comments on commit 0de55a7

Please sign in to comment.