diff options
Diffstat (limited to 'lib/flow.h')
-rw-r--r-- | lib/flow.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/flow.h b/lib/flow.h index 1f6c1d6ae..902ab1bad 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -1188,4 +1188,26 @@ static inline bool is_stp(const struct flow *flow) && eth_addr_equals(flow->dl_dst, eth_addr_stp)); } +/* Returns true if flow->tp_dst equals 'port'. If 'wc' is nonnull, sets + * appropriate bits in wc->masks.tp_dst to account for the test. + * + * The caller must already have ensured that 'flow' is a protocol for which + * tp_dst is relevant. */ +static inline bool tp_dst_equals(const struct flow *flow, uint16_t port, + struct flow_wildcards *wc) +{ + uint16_t diff = port ^ ntohs(flow->tp_dst); + if (wc) { + if (diff) { + /* Set mask for the most significant mismatching bit. */ + int ofs = raw_clz64((uint64_t) diff << 48); /* range [0,15] */ + wc->masks.tp_dst |= htons(0x8000 >> ofs); + } else { + /* Must match all bits. */ + wc->masks.tp_dst = OVS_BE16_MAX; + } + } + return !diff; +} + #endif /* flow.h */ |