diff mbox series

[net-next] gre: Drop ip_route_output_gre().

Message ID ab7cba47b8558cd4bfe2dc843c38b622a95ee48e.1734527729.git.gnault@redhat.com (mailing list archive)
State Accepted
Commit 29b540795b42a3e610c0d5e9d908a8d6c1333676
Delegated to: Netdev Maintainers
Headers show
Series [net-next] gre: Drop ip_route_output_gre(). | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 10 this patch: 10
netdev/build_tools success Errors and warnings before: 0 (+23) this patch: 0 (+23)
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 2113 this patch: 2113
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1813 this patch: 1813
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 45 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-12-19--12-00 (tests: 881)

Commit Message

Guillaume Nault Dec. 18, 2024, 1:17 p.m. UTC
We already have enough variants of ip_route_output*() functions. We
don't need a GRE specific one in the generic route.h header file.

Furthermore, ip_route_output_gre() is only used once, in ipgre_open(),
where it can be easily replaced by a simple call to
ip_route_output_key().

While there, and for clarity, explicitly set .flowi4_scope to
RT_SCOPE_UNIVERSE instead of relying on the implicit zero
initialisation.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 include/net/route.h | 14 --------------
 net/ipv4/ip_gre.c   | 17 ++++++++++-------
 2 files changed, 10 insertions(+), 21 deletions(-)

Comments

Michal Swiatkowski Dec. 19, 2024, 7:36 a.m. UTC | #1
On Wed, Dec 18, 2024 at 02:17:16PM +0100, Guillaume Nault wrote:
> We already have enough variants of ip_route_output*() functions. We
> don't need a GRE specific one in the generic route.h header file.
> 
> Furthermore, ip_route_output_gre() is only used once, in ipgre_open(),
> where it can be easily replaced by a simple call to
> ip_route_output_key().
> 
> While there, and for clarity, explicitly set .flowi4_scope to
> RT_SCOPE_UNIVERSE instead of relying on the implicit zero
> initialisation.
> 
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
>  include/net/route.h | 14 --------------
>  net/ipv4/ip_gre.c   | 17 ++++++++++-------
>  2 files changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/include/net/route.h b/include/net/route.h
> index 84cb1e04f5cd..6947a155d501 100644
> --- a/include/net/route.h
> +++ b/include/net/route.h
> @@ -185,20 +185,6 @@ static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi
>  	return ip_route_output_flow(net, fl4, sk);
>  }
>  
> -static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4 *fl4,
> -						 __be32 daddr, __be32 saddr,
> -						 __be32 gre_key, __u8 tos, int oif)
> -{
> -	memset(fl4, 0, sizeof(*fl4));
> -	fl4->flowi4_oif = oif;
> -	fl4->daddr = daddr;
> -	fl4->saddr = saddr;
> -	fl4->flowi4_tos = tos;
> -	fl4->flowi4_proto = IPPROTO_GRE;
> -	fl4->fl4_gre_key = gre_key;
> -	return ip_route_output_key(net, fl4);
> -}
> -
>  enum skb_drop_reason
>  ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
>  		      dscp_t dscp, struct net_device *dev,
> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
> index f1f31ebfc793..a020342f618d 100644
> --- a/net/ipv4/ip_gre.c
> +++ b/net/ipv4/ip_gre.c
> @@ -924,15 +924,18 @@ static int ipgre_open(struct net_device *dev)
>  	struct ip_tunnel *t = netdev_priv(dev);
>  
>  	if (ipv4_is_multicast(t->parms.iph.daddr)) {
> -		struct flowi4 fl4;
> +		struct flowi4 fl4 = {
> +			.flowi4_oif = t->parms.link,
> +			.flowi4_tos = t->parms.iph.tos & INET_DSCP_MASK,
> +			.flowi4_scope = RT_SCOPE_UNIVERSE,
> +			.flowi4_proto = IPPROTO_GRE,
> +			.saddr = t->parms.iph.saddr,
> +			.daddr = t->parms.iph.daddr,
> +			.fl4_gre_key = t->parms.o_key,
> +		};
>  		struct rtable *rt;
>  
> -		rt = ip_route_output_gre(t->net, &fl4,
> -					 t->parms.iph.daddr,
> -					 t->parms.iph.saddr,
> -					 t->parms.o_key,
> -					 t->parms.iph.tos & INET_DSCP_MASK,
> -					 t->parms.link);
> +		rt = ip_route_output_key(t->net, &fl4);
>  		if (IS_ERR(rt))
>  			return -EADDRNOTAVAIL;
>  		dev = rt->dst.dev;
> -- 

Looks even better without the memset
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

> 2.39.2
patchwork-bot+netdevbpf@kernel.org Dec. 20, 2024, 4 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 18 Dec 2024 14:17:16 +0100 you wrote:
> We already have enough variants of ip_route_output*() functions. We
> don't need a GRE specific one in the generic route.h header file.
> 
> Furthermore, ip_route_output_gre() is only used once, in ipgre_open(),
> where it can be easily replaced by a simple call to
> ip_route_output_key().
> 
> [...]

Here is the summary with links:
  - [net-next] gre: Drop ip_route_output_gre().
    https://git.kernel.org/netdev/net-next/c/29b540795b42

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/route.h b/include/net/route.h
index 84cb1e04f5cd..6947a155d501 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -185,20 +185,6 @@  static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi
 	return ip_route_output_flow(net, fl4, sk);
 }
 
-static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4 *fl4,
-						 __be32 daddr, __be32 saddr,
-						 __be32 gre_key, __u8 tos, int oif)
-{
-	memset(fl4, 0, sizeof(*fl4));
-	fl4->flowi4_oif = oif;
-	fl4->daddr = daddr;
-	fl4->saddr = saddr;
-	fl4->flowi4_tos = tos;
-	fl4->flowi4_proto = IPPROTO_GRE;
-	fl4->fl4_gre_key = gre_key;
-	return ip_route_output_key(net, fl4);
-}
-
 enum skb_drop_reason
 ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 		      dscp_t dscp, struct net_device *dev,
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index f1f31ebfc793..a020342f618d 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -924,15 +924,18 @@  static int ipgre_open(struct net_device *dev)
 	struct ip_tunnel *t = netdev_priv(dev);
 
 	if (ipv4_is_multicast(t->parms.iph.daddr)) {
-		struct flowi4 fl4;
+		struct flowi4 fl4 = {
+			.flowi4_oif = t->parms.link,
+			.flowi4_tos = t->parms.iph.tos & INET_DSCP_MASK,
+			.flowi4_scope = RT_SCOPE_UNIVERSE,
+			.flowi4_proto = IPPROTO_GRE,
+			.saddr = t->parms.iph.saddr,
+			.daddr = t->parms.iph.daddr,
+			.fl4_gre_key = t->parms.o_key,
+		};
 		struct rtable *rt;
 
-		rt = ip_route_output_gre(t->net, &fl4,
-					 t->parms.iph.daddr,
-					 t->parms.iph.saddr,
-					 t->parms.o_key,
-					 t->parms.iph.tos & INET_DSCP_MASK,
-					 t->parms.link);
+		rt = ip_route_output_key(t->net, &fl4);
 		if (IS_ERR(rt))
 			return -EADDRNOTAVAIL;
 		dev = rt->dst.dev;