mirror of
https://github.com/torvalds/linux.git
synced 2025-04-12 16:47:42 +00:00
ipv4: fib_rules: Add port mask matching
Extend IPv4 FIB rules to match on source and destination ports using a mask. Note that the mask is only set when not matching on a range. Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Guillaume Nault <gnault@redhat.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://patch.msgid.link/20250217134109.311176-4-idosch@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
da7665947b
commit
79a4e21584
@ -148,6 +148,17 @@ static inline bool fib_rule_port_inrange(const struct fib_rule_port_range *a,
|
||||
ntohs(port) <= a->end;
|
||||
}
|
||||
|
||||
static inline bool fib_rule_port_match(const struct fib_rule_port_range *range,
|
||||
u16 port_mask, __be16 port)
|
||||
{
|
||||
if ((range->start ^ ntohs(port)) & port_mask)
|
||||
return false;
|
||||
if (!port_mask && fib_rule_port_range_set(range) &&
|
||||
!fib_rule_port_inrange(range, port))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool fib_rule_port_range_valid(const struct fib_rule_port_range *a)
|
||||
{
|
||||
return a->start != 0 && a->end != 0 && a->end < 0xffff &&
|
||||
|
@ -201,12 +201,12 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_match(struct fib_rule *rule,
|
||||
if (rule->ip_proto && (rule->ip_proto != fl4->flowi4_proto))
|
||||
return 0;
|
||||
|
||||
if (fib_rule_port_range_set(&rule->sport_range) &&
|
||||
!fib_rule_port_inrange(&rule->sport_range, fl4->fl4_sport))
|
||||
if (!fib_rule_port_match(&rule->sport_range, rule->sport_mask,
|
||||
fl4->fl4_sport))
|
||||
return 0;
|
||||
|
||||
if (fib_rule_port_range_set(&rule->dport_range) &&
|
||||
!fib_rule_port_inrange(&rule->dport_range, fl4->fl4_dport))
|
||||
if (!fib_rule_port_match(&rule->dport_range, rule->dport_mask,
|
||||
fl4->fl4_dport))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user