All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] Remove duplicate code around MTU
@ 2021-07-05 21:36 Vadim Fedorenko
  2021-07-05 21:36 ` [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
  2021-07-05 21:36 ` [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
  0 siblings, 2 replies; 5+ messages in thread
From: Vadim Fedorenko @ 2021-07-05 21:36 UTC (permalink / raw)
  To: David Ahern, netdev
  Cc: Jakub Kicinski, Hideaki YOSHIFUJI, David S. Miller,
	Pablo Neira Ayuso, Florian Westphal, Vadim Fedorenko

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] 5+ messages in thread

* [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward
  2021-07-05 21:36 [PATCH net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
@ 2021-07-05 21:36 ` Vadim Fedorenko
  2021-07-11 16:23   ` David Ahern
  2021-07-05 21:36 ` [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
  1 sibling, 1 reply; 5+ messages in thread
From: Vadim Fedorenko @ 2021-07-05 21:36 UTC (permalink / raw)
  To: David Ahern, netdev
  Cc: Jakub Kicinski, Hideaki YOSHIFUJI, David S. Miller,
	Pablo Neira Ayuso, Florian Westphal, Vadim Fedorenko

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>
---
 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 f14149df5a65..76efb3950b4e 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 984050f35c61..bdfe96fe6fc3 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -577,7 +577,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] 5+ messages in thread

* [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
  2021-07-05 21:36 [PATCH net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
  2021-07-05 21:36 ` [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
@ 2021-07-05 21:36 ` Vadim Fedorenko
  2021-07-11 16:31   ` David Ahern
  1 sibling, 1 reply; 5+ messages in thread
From: Vadim Fedorenko @ 2021-07-05 21:36 UTC (permalink / raw)
  To: David Ahern, netdev
  Cc: Jakub Kicinski, Hideaki YOSHIFUJI, David S. Miller,
	Pablo Neira Ayuso, Florian Westphal, Vadim Fedorenko

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>
---
 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] 5+ messages in thread

* Re: [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward
  2021-07-05 21:36 ` [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
@ 2021-07-11 16:23   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2021-07-11 16:23 UTC (permalink / raw)
  To: Vadim Fedorenko, David Ahern, netdev
  Cc: Jakub Kicinski, Hideaki YOSHIFUJI, David S. Miller,
	Pablo Neira Ayuso, Florian Westphal

On 7/5/21 3:36 PM, Vadim Fedorenko wrote:
> 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>
> ---
>  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(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



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

* Re: [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
  2021-07-05 21:36 ` [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
@ 2021-07-11 16:31   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2021-07-11 16:31 UTC (permalink / raw)
  To: Vadim Fedorenko, David Ahern, netdev
  Cc: Jakub Kicinski, Hideaki YOSHIFUJI, David S. Miller,
	Pablo Neira Ayuso, Florian Westphal

On 7/5/21 3:36 PM, Vadim Fedorenko wrote:
> 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>
> ---
>  include/net/ip.h | 22 ++++++++++++++++++----
>  net/ipv4/route.c | 21 +--------------------
>  2 files changed, 19 insertions(+), 24 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 21:36 [PATCH net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
2021-07-05 21:36 ` [PATCH net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-11 16:23   ` David Ahern
2021-07-05 21:36 ` [PATCH net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-11 16:31   ` David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.