net: wean netfilter from fib_nh
Subsystems (4)
[email protected]
maintainercover net: wean netfilter from fib_nh
From: David Ahern <[email protected]>
Two netfilter modules reference fib_nh. In both cases the code is only checking if a nexthop in a fib_info uses a specific device. Both instances essentially duplicate code from __fib_validate_source, so move that code into a helper and flip the netfilter modules to use it.
David Ahern (3):
net/ipv4: Move device validation to helper
netfilter: rpfilter: Convert rpfilter_lookup_reverse to new dev helper
netfilter: nft_fib: Convert nft_fib4_eval to new dev helper
include/net/ip_fib.h | 1 + net/ipv4/fib_frontend.c | 44 ++++++++++++++++++++++++--------------- net/ipv4/netfilter/ipt_rpfilter.c | 17 +-------------- net/ipv4/netfilter/nft_fib_ipv4.c | 27 ++++++------------------ 4 files changed, 35 insertions(+), 54 deletions(-)
Signature · 1 line
2.11.0
[email protected]
maintainerPATCH 1/3 net/ipv4: Move device validation to helper
From: David Ahern <[email protected]>
Move the device matching check in __fib_validate_source to a helper and export it for use by netfilter modules. Code move only; no functional change intended.
--- include/net/ip_fib.h | 1 + net/ipv4/fib_frontend.c | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-)
include/net/ip_fib.h +1 -0
@@ -373,6 +373,7 @@ static inline bool fib4_rules_early_flow_dissect(struct net *net,extern const struct nla_policy rtm_ipv4_policy[];void ip_fib_init (void );__be32 fib_compute_spec_dst (struct sk_buff *skb); +bool fib_info_nh_uses_dev (struct fib_info *fi,const struct net_device *dev);int fib_validate_source (struct sk_buff *skb,__be32 src,__be32 dst,u8 tos,int oif,struct net_device *dev,struct in_device *idev,u32 *itag);
net/ipv4/fib_frontend.c +27 -17
57 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerPATCH 2/3 netfilter: rpfilter: Convert rpfilter_lookup_reverse to new dev helper
In reply to [email protected]From: David Ahern <[email protected]>
Convert rpfilter_lookup_reverse to the new device checking helper and remove the duplicate code.
--- net/ipv4/netfilter/ipt_rpfilter.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
net/ipv4/netfilter/ipt_rpfilter.c +1 -16
@@ -36,7 +36,6 @@ static bool rpfilter_lookup_reverse(struct net *net, struct flowi4 *fl4, const struct net_device *dev, u8 flags) {struct fib_result res; -bool dev_match;int ret__maybe_unused ;if (fib_lookup (net, fl4, &res,FIB_LOOKUP_IGNORE_LINKSTATE ))
@@ -46,21 +45,7 @@ static bool rpfilter_lookup_reverse(struct net *net, struct flowi4 *fl4,if (res.type !=RTN_LOCAL || !(flags &XT_RPFILTER_ACCEPT_LOCAL ))return false; } - dev_match = false; -#ifdef CONFIG_IP_ROUTE_MULTIPATH -for (ret =0 ; ret < res.fi->fib_nhs; ret++) { -struct fib_nh *nh = &res.fi->fib_nh[ret]; - -if (nh->nh_dev == dev) { - dev_match = true; -break ; - } - } -#else -if (FIB_RES_DEV (res) == dev) - dev_match = true; -#endif -return dev_match || flags &XT_RPFILTER_LOOSE ; +return fib_info_nh_uses_dev (res.fi, dev) || flags &XT_RPFILTER_LOOSE ; } static bool
Signature · 1 line
2.11.0
[email protected]
maintainerPATCH 3/3 netfilter: nft_fib: Convert nft_fib4_eval to new dev helper
In reply to [email protected]From: David Ahern <[email protected]>
Convert nft_fib4_eval to the new device checking helper and remove the duplicate code.
--- net/ipv4/netfilter/nft_fib_ipv4.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +6 -21
@@ -76,10 +76,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, .flowi4_iif = LOOPBACK_IFINDEX, };const struct net_device *oif; -struct net_device *found; -#ifdef CONFIG_IP_ROUTE_MULTIPATH -int i; -#endif +const struct net_device *found;/* * Do not set flowi4_oif, it restricts results (for example, asking
@@ -146,25 +143,13 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,if (!oif) { found =FIB_RES_DEV (res); - goto ok; - } - -#ifdef CONFIG_IP_ROUTE_MULTIPATH -for (i =0 ; i < res.fi->fib_nhs; i++) { -struct fib_nh *nh = &res.fi->fib_nh[i]; + }else { +if (!fib_info_nh_uses_dev (res.fi, oif)) +return ; -if (nh->nh_dev == oif) { - found = nh->nh_dev; - goto ok; - } + found = oif; } -return ; -#else - found =FIB_RES_DEV (res); -if (found != oif) -return ; -#endif -ok: +switch (priv->result) {case NFT_FIB_RESULT_OIF : *dest = found->ifindex;
Signature · 1 line
2.11.0
Florian Westphal
maintainerQuoted 7 lines · [email protected] <[email protected]> wrote:
From: David Ahern <[email protected]>
Two netfilter modules reference
fib_nh. In both cases the code is only checking if a nexthop in afib_infouses a specific device. Both instances essentially duplicate code from__fib_validate_source, so move that code into a helper and flip the netfilter modules to use it.
Lokks good to me, thanks David.
David Miller
maintainerFrom: [email protected]
Date: Thu, 20 Sep 2018 13:50:46 -0700
Quoted 7 lines
From: David Ahern <[email protected]>
Two netfilter modules reference
fib_nh. In both cases the code is only checking if a nexthop in afib_infouses a specific device. Both instances essentially duplicate code from__fib_validate_source, so move that code into a helper and flip the netfilter modules to use it.
Series applied, thanks David.