Skip to content

Commit 8069b22

Browse files
jk-ozlabsdavem330
authored andcommitted
mctp: Add helper for address match checking
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c575521 commit 8069b22

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

include/net/mctp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ static inline bool mctp_address_ok(mctp_eid_t eid)
4545
return eid >= 8 && eid < 255;
4646
}
4747

48+
static inline bool mctp_address_matches(mctp_eid_t match, mctp_eid_t eid)
49+
{
50+
return match == eid || match == MCTP_ADDR_ANY;
51+
}
52+
4853
static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
4954
{
5055
return (struct mctp_hdr *)skb_network_header(skb);

net/mctp/route.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)
6464
if (msk->bind_type != type)
6565
continue;
6666

67-
if (msk->bind_addr != MCTP_ADDR_ANY &&
68-
msk->bind_addr != mh->dest)
67+
if (!mctp_address_matches(msk->bind_addr, mh->dest))
6968
continue;
7069

7170
return msk;
@@ -616,9 +615,8 @@ static struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,
616615
if (tmp->tag & MCTP_HDR_FLAG_TO)
617616
continue;
618617

619-
if (!((tmp->peer_addr == daddr ||
620-
tmp->peer_addr == MCTP_ADDR_ANY) &&
621-
tmp->local_addr == saddr))
618+
if (!(mctp_address_matches(tmp->peer_addr, daddr) &&
619+
tmp->local_addr == saddr))
622620
continue;
623621

624622
spin_lock(&tmp->lock);

0 commit comments

Comments
 (0)