diff mbox series

[RFC,net-next,2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward

Message ID 20210701011728.22626-3-vfedorenko@novek.ru (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Remove duplicate code around MTU | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1982 this patch: 1982
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 63 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 2072 this patch: 2072
netdev/header_inline success Link

Commit Message

Vadim Fedorenko July 1, 2021, 1:17 a.m. UTC
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(-)

Comments

David Ahern July 1, 2021, 1:40 a.m. UTC | #1
On 6/30/21 7:17 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(-)
> 
> diff --git a/include/net/ip.h b/include/net/ip.h
> index d9683bef8684..ed261f2a40ac 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 = (const struct rtable *)dst;

I realize this a code move from ipv4_mtu, but please use container_of
here; I have been removing the typecasts as code is changed.

>  	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);
>  
>
Vadim Fedorenko July 1, 2021, 9:14 a.m. UTC | #2
On 01.07.2021 02:40, David Ahern wrote:
> On 6/30/21 7:17 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(-)
>>
>> diff --git a/include/net/ip.h b/include/net/ip.h
>> index d9683bef8684..ed261f2a40ac 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 = (const struct rtable *)dst;
> 
> I realize this a code move from ipv4_mtu, but please use container_of
> here; I have been removing the typecasts as code is changed.
> 
No problem, I will change in next iteration
diff mbox series

Patch

diff --git a/include/net/ip.h b/include/net/ip.h
index d9683bef8684..ed261f2a40ac 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 = (const 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);