netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND net-next  0/2] Remove duplicate code around MTU
@ 2021-07-20 20:06 Vadim Fedorenko
  2021-07-20 20:06 ` [PATCH RESEND net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2021-07-20 20:06 UTC (permalink / raw)
  To: David Ahern
  Cc: Jakub Kicinski, David S. Miller, netdev, Hideaki YOSHIFUJI,
	Vadim Fedorenko, Pablo Neira Ayuso, Florian Westphal

This patchset is intended to remove duplicated code around MTU calculation
and consolidate in one function. Also it alignes IPv4 and IPv6 code in
functions naming and usage

Vadim Fedorenko (2):
  net: ipv6: introduce ip6_dst_mtu_maybe_forward
  net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward

 include/net/ip.h                   | 22 ++++++++++++++++++----
 include/net/ip6_route.h            |  5 +++--
 net/ipv4/route.c                   | 21 +--------------------
 net/ipv6/ip6_output.c              |  2 +-
 net/ipv6/route.c                   | 20 +-------------------
 net/netfilter/nf_flow_table_core.c |  2 +-
 6 files changed, 25 insertions(+), 47 deletions(-)

-- 
2.18.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH RESEND net-next  1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward
  2021-07-20 20:06 [PATCH RESEND net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
@ 2021-07-20 20:06 ` Vadim Fedorenko
  2021-07-20 20:06 ` [PATCH RESEND net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
  2021-07-21 16:00 ` [PATCH RESEND net-next 0/2] Remove duplicate code around MTU patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2021-07-20 20:06 UTC (permalink / raw)
  To: David Ahern
  Cc: Jakub Kicinski, David S. Miller, netdev, Hideaki YOSHIFUJI,
	Vadim Fedorenko, Pablo Neira Ayuso, Florian Westphal

Replace ip6_dst_mtu_forward with ip6_dst_mtu_maybe_forward and
reuse this code in ip6_mtu. Actually these two functions were
almost duplicates, this change will simplify the maintaince of
mtu calculation code.

Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
Reviewed-by: David Ahern <dsahern@kernel.org>
---
 include/net/ip6_route.h            |  5 +++--
 net/ipv6/ip6_output.c              |  2 +-
 net/ipv6/route.c                   | 20 +-------------------
 net/netfilter/nf_flow_table_core.c |  2 +-
 4 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 625a38ccb5d9..820eae3ea95f 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -316,12 +316,13 @@ static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *
 	       !lwtunnel_cmp_encap(nha->fib_nh_lws, nhb->fib_nh_lws);
 }
 
-static inline unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst)
+static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst,
+						     bool forwarding)
 {
 	struct inet6_dev *idev;
 	unsigned int mtu;
 
-	if (dst_metric_locked(dst, RTAX_MTU)) {
+	if (!forwarding || dst_metric_locked(dst, RTAX_MTU)) {
 		mtu = dst_metric_raw(dst, RTAX_MTU);
 		if (mtu)
 			goto out;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 01bea76e3891..f6bc7828a480 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -607,7 +607,7 @@ int ip6_forward(struct sk_buff *skb)
 		}
 	}
 
-	mtu = ip6_dst_mtu_forward(dst);
+	mtu = ip6_dst_mtu_maybe_forward(dst, true);
 	if (mtu < IPV6_MIN_MTU)
 		mtu = IPV6_MIN_MTU;
 
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 7b756a7dc036..da2c651325e2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3201,25 +3201,7 @@ static unsigned int ip6_default_advmss(const struct dst_entry *dst)
 
 INDIRECT_CALLABLE_SCOPE unsigned int ip6_mtu(const struct dst_entry *dst)
 {
-	struct inet6_dev *idev;
-	unsigned int mtu;
-
-	mtu = dst_metric_raw(dst, RTAX_MTU);
-	if (mtu)
-		goto out;
-
-	mtu = IPV6_MIN_MTU;
-
-	rcu_read_lock();
-	idev = __in6_dev_get(dst->dev);
-	if (idev)
-		mtu = idev->cnf.mtu6;
-	rcu_read_unlock();
-
-out:
-	mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
-
-	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
+	return ip6_dst_mtu_maybe_forward(dst, false);
 }
 EXPORT_INDIRECT_CALLABLE(ip6_mtu);
 
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 1e50908b1b7e..8fe024a0ae46 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -99,7 +99,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true);
 		break;
 	case NFPROTO_IPV6:
-		flow_tuple->mtu = ip6_dst_mtu_forward(dst);
+		flow_tuple->mtu = ip6_dst_mtu_maybe_forward(dst, true);
 		break;
 	}
 
-- 
2.18.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH RESEND net-next  2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
  2021-07-20 20:06 [PATCH RESEND net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
  2021-07-20 20:06 ` [PATCH RESEND net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
@ 2021-07-20 20:06 ` Vadim Fedorenko
  2021-07-21 16:00 ` [PATCH RESEND net-next 0/2] Remove duplicate code around MTU patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2021-07-20 20:06 UTC (permalink / raw)
  To: David Ahern
  Cc: Jakub Kicinski, David S. Miller, netdev, Hideaki YOSHIFUJI,
	Vadim Fedorenko, Pablo Neira Ayuso, Florian Westphal

Consolidate IPv4 MTU code the same way it is done in IPv6 to have code
aligned in both address families

Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
Reviewed-by: David Ahern <dsahern@kernel.org>
---
 include/net/ip.h | 22 ++++++++++++++++++----
 net/ipv4/route.c | 21 +--------------------
 2 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/include/net/ip.h b/include/net/ip.h
index d9683bef8684..9192444f2964 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -436,18 +436,32 @@ static inline bool ip_sk_ignore_df(const struct sock *sk)
 static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
 						    bool forwarding)
 {
+	const struct rtable *rt = container_of(dst, struct rtable, dst);
 	struct net *net = dev_net(dst->dev);
 	unsigned int mtu;
 
 	if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
 	    ip_mtu_locked(dst) ||
-	    !forwarding)
-		return dst_mtu(dst);
+	    !forwarding) {
+		mtu = rt->rt_pmtu;
+		if (mtu && time_before(jiffies, rt->dst.expires))
+			goto out;
+	}
 
 	/* 'forwarding = true' case should always honour route mtu */
 	mtu = dst_metric_raw(dst, RTAX_MTU);
-	if (!mtu)
-		mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);
+	if (mtu)
+		goto out;
+
+	mtu = READ_ONCE(dst->dev->mtu);
+
+	if (unlikely(ip_mtu_locked(dst))) {
+		if (rt->rt_uses_gateway && mtu > 576)
+			mtu = 576;
+	}
+
+out:
+	mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
 
 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
 }
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 99c06944501a..04754d55b3c1 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1299,26 +1299,7 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
 
 INDIRECT_CALLABLE_SCOPE unsigned int ipv4_mtu(const struct dst_entry *dst)
 {
-	const struct rtable *rt = (const struct rtable *)dst;
-	unsigned int mtu = rt->rt_pmtu;
-
-	if (!mtu || time_after_eq(jiffies, rt->dst.expires))
-		mtu = dst_metric_raw(dst, RTAX_MTU);
-
-	if (mtu)
-		goto out;
-
-	mtu = READ_ONCE(dst->dev->mtu);
-
-	if (unlikely(ip_mtu_locked(dst))) {
-		if (rt->rt_uses_gateway && mtu > 576)
-			mtu = 576;
-	}
-
-out:
-	mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
-
-	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
+	return ip_dst_mtu_maybe_forward(dst, false);
 }
 EXPORT_INDIRECT_CALLABLE(ipv4_mtu);
 
-- 
2.18.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH RESEND net-next  0/2] Remove duplicate code around MTU
  2021-07-20 20:06 [PATCH RESEND net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
  2021-07-20 20:06 ` [PATCH RESEND net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
  2021-07-20 20:06 ` [PATCH RESEND net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
@ 2021-07-21 16:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-21 16:00 UTC (permalink / raw)
  To: Vadim Fedorenko; +Cc: dsahern, kuba, davem, netdev, yoshfuji, pablo, fw

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Tue, 20 Jul 2021 23:06:26 +0300 you wrote:
> This patchset is intended to remove duplicated code around MTU calculation
> and consolidate in one function. Also it alignes IPv4 and IPv6 code in
> functions naming and usage
> 
> Vadim Fedorenko (2):
>   net: ipv6: introduce ip6_dst_mtu_maybe_forward
>   net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
> 
> [...]

Here is the summary with links:
  - [RESEND,net-next,1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward
    https://git.kernel.org/netdev/net-next/c/427faee167bc
  - [RESEND,net-next,2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
    https://git.kernel.org/netdev/net-next/c/ac6627a28dbf

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-21 16:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-20 20:06 [PATCH RESEND net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
2021-07-20 20:06 ` [PATCH RESEND net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-20 20:06 ` [PATCH RESEND net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-21 16:00 ` [PATCH RESEND net-next 0/2] Remove duplicate code around MTU patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).