Skip to content

Commit

Permalink
mctp: Add helper for address match checking
Browse files Browse the repository at this point in the history
Currently, we have a couple of paths that check that an EID matches, or
the match value is MCTP_ADDR_ANY.

Rather than open coding this, add a little helper.

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 c575521 commit 8069b22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/net/mctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ static inline bool mctp_address_ok(mctp_eid_t eid)
return eid >= 8 && eid < 255;
}

static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid)
{
return match == eid || match == MCTP_ADDR_ANY;
}

static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
{
return (struct mctp_hdr *)skb_network_header(skb);
Expand Down
8 changes: 3 additions & 5 deletions net/mctp/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)
if (msk->bind_type != type)
continue;

if (msk->bind_addr != MCTP_ADDR_ANY &&
msk->bind_addr != mh->dest)
if (!mctp_address_matches(msk->bind_addr, mh->dest))
continue;

return msk;
Expand Down Expand Up @@ -616,9 +615,8 @@ static struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
if (tmp->tag & MCTP_HDR_FLAG_TO)
continue;

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

spin_lock(&tmp->lock);
Expand Down

0 comments on commit 8069b22

Please sign in to comment.