netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels
@ 2023-10-09  8:20 Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Beniamino Galvani
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

At the moment different UDP tunnels rely on different functions for
IPv4 route lookup, and those functions all implement the same
logic. Only bareudp uses the generic ip_route_output_tunnel(), while
geneve and vxlan basically duplicate it slightly differently.

This series first extends the generic lookup function so that it is
suitable for all UDP tunnel implementations. Then, bareudp, geneve and
vxlan are adapted to use them.

This results in code with less duplication and hopefully better
maintainability.

After this series is merged, IPv6 will be converted in a similar way.

Beniamino Galvani (7):
  ipv4: rename and move ip_route_output_tunnel()
  ipv4: remove "proto" argument from udp_tunnel_dst_lookup()
  ipv4: add new arguments to udp_tunnel_dst_lookup()
  ipv4: use tunnel flow flags for tunnel route lookups
  geneve: add dsfield helper function
  geneve: use generic function for tunnel IPv4 route lookup
  vxlan: use generic function for tunnel IPv4 route lookup

 drivers/net/bareudp.c          |  11 ++--
 drivers/net/geneve.c           | 111 +++++++++++++--------------------
 drivers/net/vxlan/vxlan_core.c | 103 +++++++++++-------------------
 include/net/route.h            |   6 --
 include/net/udp_tunnel.h       |   8 +++
 net/ipv4/route.c               |  48 --------------
 net/ipv4/udp_tunnel_core.c     |  49 +++++++++++++++
 7 files changed, 141 insertions(+), 195 deletions(-)

-- 
2.40.1


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

* [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel()
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-11 18:50   ` David Ahern
  2023-10-09  8:20 ` [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup() Beniamino Galvani
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

At the moment ip_route_output_tunnel() is used only by bareudp.
Ideally, other UDP tunnel implementations should use it, but to do so
the function needs to accept new parameters that are specific for UDP
tunnels, such as the ports.

Prepare for these changes by renaming the function to
udp_tunnel_dst_lookup() and move it to file
net/ipv4/udp_tunnel_core.c.

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/bareudp.c      |  8 +++----
 include/net/route.h        |  6 -----
 include/net/udp_tunnel.h   |  6 +++++
 net/ipv4/route.c           | 48 --------------------------------------
 net/ipv4/udp_tunnel_core.c | 48 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 58 insertions(+), 58 deletions(-)

diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
index 683203f87ae2..63fc32fa1af5 100644
--- a/drivers/net/bareudp.c
+++ b/drivers/net/bareudp.c
@@ -306,8 +306,8 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 	if (!sock)
 		return -ESHUTDOWN;
 
-	rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr, info,
-				    IPPROTO_UDP, use_cache);
+	rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info,
+				   IPPROTO_UDP, use_cache);
 
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
@@ -483,8 +483,8 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
 		struct rtable *rt;
 		__be32 saddr;
 
-		rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr,
-					    info, IPPROTO_UDP, use_cache);
+		rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr,
+					   info, IPPROTO_UDP, use_cache);
 		if (IS_ERR(rt))
 			return PTR_ERR(rt);
 
diff --git a/include/net/route.h b/include/net/route.h
index 5c248a8e3d0e..980ab474eabd 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -136,12 +136,6 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
 				    const struct sock *sk);
-struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
-				      struct net_device *dev,
-				      struct net *net, __be32 *saddr,
-				      const struct ip_tunnel_info *info,
-				      u8 protocol, bool use_cache);
-
 struct dst_entry *ipv4_blackhole_route(struct net *net,
 				       struct dst_entry *dst_orig);
 
diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h
index 21ba0a25f936..11e810ca5088 100644
--- a/include/net/udp_tunnel.h
+++ b/include/net/udp_tunnel.h
@@ -162,6 +162,12 @@ int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
 
 void udp_tunnel_sock_release(struct socket *sock);
 
+struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
+				     struct net_device *dev,
+				     struct net *net, __be32 *saddr,
+				     const struct ip_tunnel_info *info,
+				     u8 protocol, bool use_cache);
+
 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
 				    __be16 flags, __be64 tunnel_id,
 				    int md_size);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index e2bf4602b559..3290a4442b4a 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2885,54 +2885,6 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
 }
 EXPORT_SYMBOL_GPL(ip_route_output_flow);
 
-struct rtable *ip_route_output_tunnel(struct sk_buff *skb,
-				      struct net_device *dev,
-				      struct net *net, __be32 *saddr,
-				      const struct ip_tunnel_info *info,
-				      u8 protocol, bool use_cache)
-{
-#ifdef CONFIG_DST_CACHE
-	struct dst_cache *dst_cache;
-#endif
-	struct rtable *rt = NULL;
-	struct flowi4 fl4;
-	__u8 tos;
-
-#ifdef CONFIG_DST_CACHE
-	dst_cache = (struct dst_cache *)&info->dst_cache;
-	if (use_cache) {
-		rt = dst_cache_get_ip4(dst_cache, saddr);
-		if (rt)
-			return rt;
-	}
-#endif
-	memset(&fl4, 0, sizeof(fl4));
-	fl4.flowi4_mark = skb->mark;
-	fl4.flowi4_proto = protocol;
-	fl4.daddr = info->key.u.ipv4.dst;
-	fl4.saddr = info->key.u.ipv4.src;
-	tos = info->key.tos;
-	fl4.flowi4_tos = RT_TOS(tos);
-
-	rt = ip_route_output_key(net, &fl4);
-	if (IS_ERR(rt)) {
-		netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr);
-		return ERR_PTR(-ENETUNREACH);
-	}
-	if (rt->dst.dev == dev) { /* is this necessary? */
-		netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr);
-		ip_rt_put(rt);
-		return ERR_PTR(-ELOOP);
-	}
-#ifdef CONFIG_DST_CACHE
-	if (use_cache)
-		dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
-#endif
-	*saddr = fl4.saddr;
-	return rt;
-}
-EXPORT_SYMBOL_GPL(ip_route_output_tunnel);
-
 /* called with rcu_read_lock held */
 static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
 			struct rtable *rt, u32 table_id, struct flowi4 *fl4,
diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
index 1e7e4aecdc48..96f93f92b6ce 100644
--- a/net/ipv4/udp_tunnel_core.c
+++ b/net/ipv4/udp_tunnel_core.c
@@ -204,4 +204,52 @@ struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb,  unsigned short family,
 }
 EXPORT_SYMBOL_GPL(udp_tun_rx_dst);
 
+struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
+				     struct net_device *dev,
+				     struct net *net, __be32 *saddr,
+				     const struct ip_tunnel_info *info,
+				     u8 protocol, bool use_cache)
+{
+#ifdef CONFIG_DST_CACHE
+	struct dst_cache *dst_cache;
+#endif
+	struct rtable *rt = NULL;
+	struct flowi4 fl4;
+	__u8 tos;
+
+#ifdef CONFIG_DST_CACHE
+	dst_cache = (struct dst_cache *)&info->dst_cache;
+	if (use_cache) {
+		rt = dst_cache_get_ip4(dst_cache, saddr);
+		if (rt)
+			return rt;
+	}
+#endif
+	memset(&fl4, 0, sizeof(fl4));
+	fl4.flowi4_mark = skb->mark;
+	fl4.flowi4_proto = protocol;
+	fl4.daddr = info->key.u.ipv4.dst;
+	fl4.saddr = info->key.u.ipv4.src;
+	tos = info->key.tos;
+	fl4.flowi4_tos = RT_TOS(tos);
+
+	rt = ip_route_output_key(net, &fl4);
+	if (IS_ERR(rt)) {
+		netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr);
+		return ERR_PTR(-ENETUNREACH);
+	}
+	if (rt->dst.dev == dev) { /* is this necessary? */
+		netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr);
+		ip_rt_put(rt);
+		return ERR_PTR(-ELOOP);
+	}
+#ifdef CONFIG_DST_CACHE
+	if (use_cache)
+		dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
+#endif
+	*saddr = fl4.saddr;
+	return rt;
+}
+EXPORT_SYMBOL_GPL(udp_tunnel_dst_lookup);
+
 MODULE_LICENSE("GPL");
-- 
2.40.1


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

* [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup()
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-11 18:51   ` David Ahern
  2023-10-09  8:20 ` [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup() Beniamino Galvani
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

The function is now UDP-specific, the protocol is always IPPROTO_UDP.

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/bareudp.c      | 4 ++--
 include/net/udp_tunnel.h   | 2 +-
 net/ipv4/udp_tunnel_core.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
index 63fc32fa1af5..6af67cac6bde 100644
--- a/drivers/net/bareudp.c
+++ b/drivers/net/bareudp.c
@@ -307,7 +307,7 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 		return -ESHUTDOWN;
 
 	rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info,
-				   IPPROTO_UDP, use_cache);
+				   use_cache);
 
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
@@ -484,7 +484,7 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
 		__be32 saddr;
 
 		rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr,
-					   info, IPPROTO_UDP, use_cache);
+					   info, use_cache);
 		if (IS_ERR(rt))
 			return PTR_ERR(rt);
 
diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h
index 11e810ca5088..8f110dbd3784 100644
--- a/include/net/udp_tunnel.h
+++ b/include/net/udp_tunnel.h
@@ -166,7 +166,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 				     struct net_device *dev,
 				     struct net *net, __be32 *saddr,
 				     const struct ip_tunnel_info *info,
-				     u8 protocol, bool use_cache);
+				     bool use_cache);
 
 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
 				    __be16 flags, __be64 tunnel_id,
diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
index 96f93f92b6ce..9b0cfd72d5fd 100644
--- a/net/ipv4/udp_tunnel_core.c
+++ b/net/ipv4/udp_tunnel_core.c
@@ -208,7 +208,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 				     struct net_device *dev,
 				     struct net *net, __be32 *saddr,
 				     const struct ip_tunnel_info *info,
-				     u8 protocol, bool use_cache)
+				     bool use_cache)
 {
 #ifdef CONFIG_DST_CACHE
 	struct dst_cache *dst_cache;
@@ -227,7 +227,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 #endif
 	memset(&fl4, 0, sizeof(fl4));
 	fl4.flowi4_mark = skb->mark;
-	fl4.flowi4_proto = protocol;
+	fl4.flowi4_proto = IPPROTO_UDP;
 	fl4.daddr = info->key.u.ipv4.dst;
 	fl4.saddr = info->key.u.ipv4.src;
 	tos = info->key.tos;
-- 
2.40.1


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

* [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup()
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup() Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-11 18:51   ` David Ahern
  2023-10-09  8:20 ` [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups Beniamino Galvani
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

We want to make the function more generic so that it can be used by
other UDP tunnel implementations such as geneve and vxlan. To do that,
add the following arguments:

 - source and destination UDP port;
 - ifindex of the output interface, needed by vxlan;
 - the tos, because in some cases it is not taken from struct
   ip_tunnel_info (for example, when it's inherited from the inner
   packet);
 - the dst cache, because not all tunnel types (e.g. vxlan) want to
   use the one from struct ip_tunnel_info.

With these parameters, the function no longer needs the full struct
ip_tunnel_info as argument and we can pass only the relevant part of
it (struct ip_tunnel_key).

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/bareudp.c      | 11 +++++++----
 include/net/udp_tunnel.h   |  8 +++++---
 net/ipv4/udp_tunnel_core.c | 26 +++++++++++++-------------
 3 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
index 6af67cac6bde..47a9c2a5583c 100644
--- a/drivers/net/bareudp.c
+++ b/drivers/net/bareudp.c
@@ -306,8 +306,10 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 	if (!sock)
 		return -ESHUTDOWN;
 
-	rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info,
-				   use_cache);
+	rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr, &info->key,
+				   0, 0, key->tos,
+				   use_cache ?
+				   (struct dst_cache *)&info->dst_cache : NULL);
 
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
@@ -483,8 +485,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
 		struct rtable *rt;
 		__be32 saddr;
 
-		rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr,
-					   info, use_cache);
+		rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr,
+					   &info->key, 0, 0, info->key.tos,
+					   use_cache ? &info->dst_cache : NULL);
 		if (IS_ERR(rt))
 			return PTR_ERR(rt);
 
diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h
index 8f110dbd3784..4d0578fab01a 100644
--- a/include/net/udp_tunnel.h
+++ b/include/net/udp_tunnel.h
@@ -164,9 +164,11 @@ void udp_tunnel_sock_release(struct socket *sock);
 
 struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 				     struct net_device *dev,
-				     struct net *net, __be32 *saddr,
-				     const struct ip_tunnel_info *info,
-				     bool use_cache);
+				     struct net *net, int oif,
+				     __be32 *saddr,
+				     const struct ip_tunnel_key *key,
+				     __be16 sport, __be16 dport, u8 tos,
+				     struct dst_cache *dst_cache);
 
 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
 				    __be16 flags, __be64 tunnel_id,
diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
index 9b0cfd72d5fd..494685e82856 100644
--- a/net/ipv4/udp_tunnel_core.c
+++ b/net/ipv4/udp_tunnel_core.c
@@ -206,31 +206,31 @@ EXPORT_SYMBOL_GPL(udp_tun_rx_dst);
 
 struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 				     struct net_device *dev,
-				     struct net *net, __be32 *saddr,
-				     const struct ip_tunnel_info *info,
-				     bool use_cache)
+				     struct net *net, int oif,
+				     __be32 *saddr,
+				     const struct ip_tunnel_key *key,
+				     __be16 sport, __be16 dport, u8 tos,
+				     struct dst_cache *dst_cache)
 {
-#ifdef CONFIG_DST_CACHE
-	struct dst_cache *dst_cache;
-#endif
 	struct rtable *rt = NULL;
 	struct flowi4 fl4;
-	__u8 tos;
 
 #ifdef CONFIG_DST_CACHE
-	dst_cache = (struct dst_cache *)&info->dst_cache;
-	if (use_cache) {
+	if (dst_cache) {
 		rt = dst_cache_get_ip4(dst_cache, saddr);
 		if (rt)
 			return rt;
 	}
 #endif
+
 	memset(&fl4, 0, sizeof(fl4));
 	fl4.flowi4_mark = skb->mark;
 	fl4.flowi4_proto = IPPROTO_UDP;
-	fl4.daddr = info->key.u.ipv4.dst;
-	fl4.saddr = info->key.u.ipv4.src;
-	tos = info->key.tos;
+	fl4.flowi4_oif = oif;
+	fl4.daddr = key->u.ipv4.dst;
+	fl4.saddr = key->u.ipv4.src;
+	fl4.fl4_dport = dport;
+	fl4.fl4_sport = sport;
 	fl4.flowi4_tos = RT_TOS(tos);
 
 	rt = ip_route_output_key(net, &fl4);
@@ -244,7 +244,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 		return ERR_PTR(-ELOOP);
 	}
 #ifdef CONFIG_DST_CACHE
-	if (use_cache)
+	if (dst_cache)
 		dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
 #endif
 	*saddr = fl4.saddr;
-- 
2.40.1


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

* [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
                   ` (2 preceding siblings ...)
  2023-10-09  8:20 ` [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup() Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-11 18:52   ` David Ahern
  2023-10-09  8:20 ` [PATCH net-next 5/7] geneve: add dsfield helper function Beniamino Galvani
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

Commit 451ef36bd229 ("ip_tunnels: Add new flow flags field to
ip_tunnel_key") added a new field to struct ip_tunnel_key to control
route lookups. Currently the flag is used by vxlan and geneve tunnels;
use it also in udp_tunnel_dst_lookup() so that it affects all tunnel
types relying on this function.

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 net/ipv4/udp_tunnel_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
index 494685e82856..a87defb2b167 100644
--- a/net/ipv4/udp_tunnel_core.c
+++ b/net/ipv4/udp_tunnel_core.c
@@ -232,6 +232,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 	fl4.fl4_dport = dport;
 	fl4.fl4_sport = sport;
 	fl4.flowi4_tos = RT_TOS(tos);
+	fl4.flowi4_flags = key->flow_flags;
 
 	rt = ip_route_output_key(net, &fl4);
 	if (IS_ERR(rt)) {
-- 
2.40.1


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

* [PATCH net-next 5/7] geneve: add dsfield helper function
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
                   ` (3 preceding siblings ...)
  2023-10-09  8:20 ` [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 6/7] geneve: use generic function for tunnel IPv4 route lookup Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 7/7] vxlan: " Beniamino Galvani
  6 siblings, 0 replies; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

Add a helper function to compute the tos/dsfield. In this way, we can
factor out some duplicate code. Also, the helper will be called from
more places in the next commit.

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/geneve.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 78f9d588f712..572c3e36b209 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -784,6 +784,22 @@ static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb,
 	return err;
 }
 
+static u8 geneve_get_dsfield(struct sk_buff *skb, struct net_device *dev,
+			     const struct ip_tunnel_info *info,
+			     bool *use_cache)
+{
+	struct geneve_dev *geneve = netdev_priv(dev);
+	u8 dsfield;
+
+	dsfield = info->key.tos;
+	if (dsfield == 1 && !geneve->cfg.collect_md) {
+		dsfield = ip_tunnel_get_dsfield(ip_hdr(skb), skb);
+		*use_cache = false;
+	}
+
+	return dsfield;
+}
+
 static struct rtable *geneve_get_v4_rt(struct sk_buff *skb,
 				       struct net_device *dev,
 				       struct geneve_sock *gs4,
@@ -810,11 +826,7 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb,
 	fl4->fl4_sport = sport;
 	fl4->flowi4_flags = info->key.flow_flags;
 
-	tos = info->key.tos;
-	if ((tos == 1) && !geneve->cfg.collect_md) {
-		tos = ip_tunnel_get_dsfield(ip_hdr(skb), skb);
-		use_cache = false;
-	}
+	tos = geneve_get_dsfield(skb, dev, info, &use_cache);
 	fl4->flowi4_tos = RT_TOS(tos);
 	if (full_tos)
 		*full_tos = tos;
@@ -865,12 +877,7 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb,
 	fl6->fl6_dport = dport;
 	fl6->fl6_sport = sport;
 
-	prio = info->key.tos;
-	if ((prio == 1) && !geneve->cfg.collect_md) {
-		prio = ip_tunnel_get_dsfield(ip_hdr(skb), skb);
-		use_cache = false;
-	}
-
+	prio = geneve_get_dsfield(skb, dev, info, &use_cache);
 	fl6->flowlabel = ip6_make_flowinfo(prio, info->key.label);
 	dst_cache = (struct dst_cache *)&info->dst_cache;
 	if (use_cache) {
-- 
2.40.1


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

* [PATCH net-next 6/7] geneve: use generic function for tunnel IPv4 route lookup
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
                   ` (4 preceding siblings ...)
  2023-10-09  8:20 ` [PATCH net-next 5/7] geneve: add dsfield helper function Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-09  8:20 ` [PATCH net-next 7/7] vxlan: " Beniamino Galvani
  6 siblings, 0 replies; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

The route lookup can be done now via generic function
udp_tunnel_dst_lookup() to replace the custom implementation in
geneve_get_v4_rt().

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/geneve.c | 98 +++++++++++++++-----------------------------
 1 file changed, 32 insertions(+), 66 deletions(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 572c3e36b209..23041eeec121 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -800,58 +800,6 @@ static u8 geneve_get_dsfield(struct sk_buff *skb, struct net_device *dev,
 	return dsfield;
 }
 
-static struct rtable *geneve_get_v4_rt(struct sk_buff *skb,
-				       struct net_device *dev,
-				       struct geneve_sock *gs4,
-				       struct flowi4 *fl4,
-				       const struct ip_tunnel_info *info,
-				       __be16 dport, __be16 sport,
-				       __u8 *full_tos)
-{
-	bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
-	struct geneve_dev *geneve = netdev_priv(dev);
-	struct dst_cache *dst_cache;
-	struct rtable *rt = NULL;
-	__u8 tos;
-
-	if (!gs4)
-		return ERR_PTR(-EIO);
-
-	memset(fl4, 0, sizeof(*fl4));
-	fl4->flowi4_mark = skb->mark;
-	fl4->flowi4_proto = IPPROTO_UDP;
-	fl4->daddr = info->key.u.ipv4.dst;
-	fl4->saddr = info->key.u.ipv4.src;
-	fl4->fl4_dport = dport;
-	fl4->fl4_sport = sport;
-	fl4->flowi4_flags = info->key.flow_flags;
-
-	tos = geneve_get_dsfield(skb, dev, info, &use_cache);
-	fl4->flowi4_tos = RT_TOS(tos);
-	if (full_tos)
-		*full_tos = tos;
-
-	dst_cache = (struct dst_cache *)&info->dst_cache;
-	if (use_cache) {
-		rt = dst_cache_get_ip4(dst_cache, &fl4->saddr);
-		if (rt)
-			return rt;
-	}
-	rt = ip_route_output_key(geneve->net, fl4);
-	if (IS_ERR(rt)) {
-		netdev_dbg(dev, "no route to %pI4\n", &fl4->daddr);
-		return ERR_PTR(-ENETUNREACH);
-	}
-	if (rt->dst.dev == dev) { /* is this necessary? */
-		netdev_dbg(dev, "circular route to %pI4\n", &fl4->daddr);
-		ip_rt_put(rt);
-		return ERR_PTR(-ELOOP);
-	}
-	if (use_cache)
-		dst_cache_set_ip4(dst_cache, &rt->dst, fl4->saddr);
-	return rt;
-}
-
 #if IS_ENABLED(CONFIG_IPV6)
 static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb,
 					   struct net_device *dev,
@@ -911,19 +859,28 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 	struct geneve_sock *gs4 = rcu_dereference(geneve->sock4);
 	const struct ip_tunnel_key *key = &info->key;
 	struct rtable *rt;
-	struct flowi4 fl4;
-	__u8 full_tos;
+	bool use_cache;
 	__u8 tos, ttl;
 	__be16 df = 0;
+	__be32 saddr;
 	__be16 sport;
 	int err;
 
 	if (!pskb_inet_may_pull(skb))
 		return -EINVAL;
 
+	if (!gs4)
+		return -EIO;
+
+	use_cache = ip_tunnel_dst_cache_usable(skb, info);
+	tos = geneve_get_dsfield(skb, dev, info, &use_cache);
 	sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
-	rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info,
-			      geneve->cfg.info.key.tp_dst, sport, &full_tos);
+
+	rt = udp_tunnel_dst_lookup(skb, dev, geneve->net, 0, &saddr,
+				   &info->key,
+				   sport, geneve->cfg.info.key.tp_dst, tos,
+				   use_cache ?
+				   (struct dst_cache *)&info->dst_cache : NULL);
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
 
@@ -946,8 +903,8 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 				return -ENOMEM;
 			}
 
-			unclone->key.u.ipv4.dst = fl4.saddr;
-			unclone->key.u.ipv4.src = fl4.daddr;
+			unclone->key.u.ipv4.dst = saddr;
+			unclone->key.u.ipv4.src = info->key.u.ipv4.dst;
 		}
 
 		if (!pskb_may_pull(skb, ETH_HLEN)) {
@@ -961,13 +918,12 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 		return -EMSGSIZE;
 	}
 
+	tos = ip_tunnel_ecn_encap(tos, ip_hdr(skb), skb);
 	if (geneve->cfg.collect_md) {
-		tos = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb);
 		ttl = key->ttl;
 
 		df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
 	} else {
-		tos = ip_tunnel_ecn_encap(full_tos, ip_hdr(skb), skb);
 		if (geneve->cfg.ttl_inherit)
 			ttl = ip_tunnel_get_ttl(ip_hdr(skb), skb);
 		else
@@ -995,7 +951,7 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 	if (unlikely(err))
 		return err;
 
-	udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, fl4.saddr, fl4.daddr,
+	udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, saddr, info->key.u.ipv4.dst,
 			    tos, ttl, df, sport, geneve->cfg.info.key.tp_dst,
 			    !net_eq(geneve->net, dev_net(geneve->dev)),
 			    !(info->key.tun_flags & TUNNEL_CSUM));
@@ -1144,19 +1100,29 @@ static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
 
 	if (ip_tunnel_info_af(info) == AF_INET) {
 		struct rtable *rt;
-		struct flowi4 fl4;
-
 		struct geneve_sock *gs4 = rcu_dereference(geneve->sock4);
+		bool use_cache;
+		__be32 saddr;
+		u8 tos;
+
+		if (!gs4)
+			return -EIO;
+
+		use_cache = ip_tunnel_dst_cache_usable(skb, info);
+		tos = geneve_get_dsfield(skb, dev, info, &use_cache);
 		sport = udp_flow_src_port(geneve->net, skb,
 					  1, USHRT_MAX, true);
 
-		rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info,
-				      geneve->cfg.info.key.tp_dst, sport, NULL);
+		rt = udp_tunnel_dst_lookup(skb, dev, geneve->net, 0, &saddr,
+					   &info->key,
+					   sport, geneve->cfg.info.key.tp_dst,
+					   tos,
+					   use_cache ? &info->dst_cache : NULL);
 		if (IS_ERR(rt))
 			return PTR_ERR(rt);
 
 		ip_rt_put(rt);
-		info->key.u.ipv4.src = fl4.saddr;
+		info->key.u.ipv4.src = saddr;
 #if IS_ENABLED(CONFIG_IPV6)
 	} else if (ip_tunnel_info_af(info) == AF_INET6) {
 		struct dst_entry *dst;
-- 
2.40.1


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

* [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup
  2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
                   ` (5 preceding siblings ...)
  2023-10-09  8:20 ` [PATCH net-next 6/7] geneve: use generic function for tunnel IPv4 route lookup Beniamino Galvani
@ 2023-10-09  8:20 ` Beniamino Galvani
  2023-10-09 10:22   ` kernel test robot
  2023-10-09 16:12   ` kernel test robot
  6 siblings, 2 replies; 14+ messages in thread
From: Beniamino Galvani @ 2023-10-09  8:20 UTC (permalink / raw)
  To: netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Guillaume Nault, linux-kernel

The route lookup can be done now via generic function
udp_tunnel_dst_lookup() to replace the custom implementations in
vxlan_get_route().

Note that this patch only touches IPv4, while IPv6 still uses
vxlan6_get_route(). After IPv6 route lookup gets converted as well,
vxlan_xmit_one() can be simplified by removing local variables that
will be passed via "struct ip_tunnel_key", such as remote_ip,
local_ip, flow_flags, label.

Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/net/vxlan/vxlan_core.c | 103 +++++++++++----------------------
 1 file changed, 35 insertions(+), 68 deletions(-)

diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
index 5b5597073b00..a37a84fae64e 100644
--- a/drivers/net/vxlan/vxlan_core.c
+++ b/drivers/net/vxlan/vxlan_core.c
@@ -2215,57 +2215,6 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst,
 	return 0;
 }
 
-static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, struct net_device *dev,
-				      struct vxlan_sock *sock4,
-				      struct sk_buff *skb, int oif, u8 tos,
-				      __be32 daddr, __be32 *saddr, __be16 dport, __be16 sport,
-				      __u8 flow_flags, struct dst_cache *dst_cache,
-				      const struct ip_tunnel_info *info)
-{
-	bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
-	struct rtable *rt = NULL;
-	struct flowi4 fl4;
-
-	if (!sock4)
-		return ERR_PTR(-EIO);
-
-	if (tos && !info)
-		use_cache = false;
-	if (use_cache) {
-		rt = dst_cache_get_ip4(dst_cache, saddr);
-		if (rt)
-			return rt;
-	}
-
-	memset(&fl4, 0, sizeof(fl4));
-	fl4.flowi4_oif = oif;
-	fl4.flowi4_tos = RT_TOS(tos);
-	fl4.flowi4_mark = skb->mark;
-	fl4.flowi4_proto = IPPROTO_UDP;
-	fl4.daddr = daddr;
-	fl4.saddr = *saddr;
-	fl4.fl4_dport = dport;
-	fl4.fl4_sport = sport;
-	fl4.flowi4_flags = flow_flags;
-
-	rt = ip_route_output_key(vxlan->net, &fl4);
-	if (!IS_ERR(rt)) {
-		if (rt->dst.dev == dev) {
-			netdev_dbg(dev, "circular route to %pI4\n", &daddr);
-			ip_rt_put(rt);
-			return ERR_PTR(-ELOOP);
-		}
-
-		*saddr = fl4.saddr;
-		if (use_cache)
-			dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
-	} else {
-		netdev_dbg(dev, "no route to %pI4\n", &daddr);
-		return ERR_PTR(-ENETUNREACH);
-	}
-	return rt;
-}
-
 #if IS_ENABLED(CONFIG_IPV6)
 static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
 					  struct net_device *dev,
@@ -2418,6 +2367,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 {
 	struct dst_cache *dst_cache;
 	struct ip_tunnel_info *info;
+	struct ip_tunnel_key *pkey;
+	struct ip_tunnel_key key;
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	const struct iphdr *old_iph = ip_hdr(skb);
 	union vxlan_addr *dst;
@@ -2431,6 +2382,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 	int ifindex;
 	int err;
 	u32 flags = vxlan->cfg.flags;
+	bool use_cache;
 	bool udp_sum = false;
 	bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev));
 	__be32 vni = 0;
@@ -2439,9 +2391,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 #endif
 
 	info = skb_tunnel_info(skb);
+	use_cache = ip_tunnel_dst_cache_usable(skb, info);
 
 	if (rdst) {
 		dst = &rdst->remote_ip;
+		memset(&key, 0, sizeof(key));
+		pkey = &key;
+
 		if (vxlan_addr_any(dst)) {
 			if (did_rsc) {
 				/* short-circuited back to local bridge */
@@ -2456,6 +2412,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		vni = (rdst->remote_vni) ? : default_vni;
 		ifindex = rdst->remote_ifindex;
 		local_ip = vxlan->cfg.saddr;
+
+		if (dst->sa.sa_family == AF_INET) {
+			key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr;
+			key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr;
+		} else {
+			key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr;
+			key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr;
+		}
+
 		dst_cache = &rdst->dst_cache;
 		md->gbp = skb->mark;
 		if (flags & VXLAN_F_TTL_INHERIT) {
@@ -2469,6 +2434,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		tos = vxlan->cfg.tos;
 		if (tos == 1)
 			tos = ip_tunnel_get_dsfield(old_iph, skb);
+		if (tos && !info)
+			use_cache = false;
 
 		if (dst->sa.sa_family == AF_INET)
 			udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM_TX);
@@ -2492,6 +2459,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			local_ip.sin6.sin6_addr = info->key.u.ipv6.src;
 		}
 		dst = &remote_ip;
+		pkey = &info->key;
 		dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
 		flow_flags = info->key.flow_flags;
 		vni = tunnel_id_to_key32(info->key.tun_id);
@@ -2517,15 +2485,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
 		struct rtable *rt;
 		__be16 df = 0;
+		__be32 saddr;
 
 		if (!ifindex)
 			ifindex = sock4->sock->sk->sk_bound_dev_if;
 
-		rt = vxlan_get_route(vxlan, dev, sock4, skb, ifindex, tos,
-				     dst->sin.sin_addr.s_addr,
-				     &local_ip.sin.sin_addr.s_addr,
-				     dst_port, src_port, flow_flags,
-				     dst_cache, info);
+		rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, ifindex,
+					   &saddr, pkey, src_port, dst_port,
+					   tos, use_cache ? dst_cache : NULL);
 		if (IS_ERR(rt)) {
 			err = PTR_ERR(rt);
 			goto tx_error;
@@ -2561,16 +2528,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		} else if (err) {
 			if (info) {
 				struct ip_tunnel_info *unclone;
-				struct in_addr src, dst;
 
 				unclone = skb_tunnel_info_unclone(skb);
 				if (unlikely(!unclone))
 					goto tx_error;
 
-				src = remote_ip.sin.sin_addr;
-				dst = local_ip.sin.sin_addr;
-				unclone->key.u.ipv4.src = src.s_addr;
-				unclone->key.u.ipv4.dst = dst.s_addr;
+				unclone->key.u.ipv4.src = pkey->u.ipv4.dst;
+				unclone->key.u.ipv4.dst = saddr;
 			}
 			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
 			dst_release(ndst);
@@ -2584,8 +2548,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		if (err < 0)
 			goto tx_error;
 
-		udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, local_ip.sin.sin_addr.s_addr,
-				    dst->sin.sin_addr.s_addr, tos, ttl, df,
+		udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr,
+				    pkey->u.ipv4.dst, tos, ttl, df,
 				    src_port, dst_port, xnet, !udp_sum);
 #if IS_ENABLED(CONFIG_IPV6)
 	} else {
@@ -3100,11 +3064,14 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
 		struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
 		struct rtable *rt;
 
-		rt = vxlan_get_route(vxlan, dev, sock4, skb, 0, info->key.tos,
-				     info->key.u.ipv4.dst,
-				     &info->key.u.ipv4.src, dport, sport,
-				     info->key.flow_flags, &info->dst_cache,
-				     info);
+		if (!sock4)
+			return -EIO;
+
+		rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, 0,
+					   &info->key.u.ipv4.src,
+					   &info->key,
+					   sport, dport, info->key.tos,
+					   &info->dst_cache);
 		if (IS_ERR(rt))
 			return PTR_ERR(rt);
 		ip_rt_put(rt);
-- 
2.40.1


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

* Re: [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup
  2023-10-09  8:20 ` [PATCH net-next 7/7] vxlan: " Beniamino Galvani
@ 2023-10-09 10:22   ` kernel test robot
  2023-10-09 16:12   ` kernel test robot
  1 sibling, 0 replies; 14+ messages in thread
From: kernel test robot @ 2023-10-09 10:22 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: oe-kbuild-all, David S . Miller, Jakub Kicinski, Paolo Abeni,
	David Ahern, Guillaume Nault, linux-kernel

Hi Beniamino,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Beniamino-Galvani/ipv4-rename-and-move-ip_route_output_tunnel/20231009-162823
base:   net-next/main
patch link:    https://lore.kernel.org/r/20231009082059.2500217-8-b.galvani%40gmail.com
patch subject: [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231009/202310091850.YNLmLI9a-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231009/202310091850.YNLmLI9a-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310091850.YNLmLI9a-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/net/vxlan/vxlan_core.c: In function 'vxlan_xmit_one':
>> drivers/net/vxlan/vxlan_core.c:2381:24: warning: variable 'flow_flags' set but not used [-Wunused-but-set-variable]
    2381 |         __u8 tos, ttl, flow_flags = 0;
         |                        ^~~~~~~~~~


vim +/flow_flags +2381 drivers/net/vxlan/vxlan_core.c

fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2364  
6ab271aaad2535 drivers/net/vxlan/vxlan_core.c Ido Schimmel        2023-03-15  2365  void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
6ab271aaad2535 drivers/net/vxlan/vxlan_core.c Ido Schimmel        2023-03-15  2366  		    __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc)
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2367  {
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2368  	struct dst_cache *dst_cache;
3093fbe7ff4bc7 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2369  	struct ip_tunnel_info *info;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2370  	struct ip_tunnel_key *pkey;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2371  	struct ip_tunnel_key key;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2372  	struct vxlan_dev *vxlan = netdev_priv(dev);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2373  	const struct iphdr *old_iph = ip_hdr(skb);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2374  	union vxlan_addr *dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2375  	union vxlan_addr remote_ip, local_ip;
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2376  	struct vxlan_metadata _md;
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2377  	struct vxlan_metadata *md = &_md;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2378  	unsigned int pkt_len = skb->len;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2379  	__be16 src_port = 0, dst_port;
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2380  	struct dst_entry *ndst = NULL;
7e2fb8bc7ef6c7 drivers/net/vxlan/vxlan_core.c Paul Chaignon       2022-07-25 @2381  	__u8 tos, ttl, flow_flags = 0;
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2382  	int ifindex;
0e6fbc5b6c6218 drivers/net/vxlan.c            Pravin B Shelar     2013-06-17  2383  	int err;
dc5321d79697db drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2384  	u32 flags = vxlan->cfg.flags;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2385  	bool use_cache;
b4ed5cad24c107 drivers/net/vxlan.c            Jiri Benc           2016-02-02  2386  	bool udp_sum = false;
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2387  	bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev));
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2388  	__be32 vni = 0;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2389  #if IS_ENABLED(CONFIG_IPV6)
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2390  	__be32 label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2391  #endif
e4f67addf158f9 drivers/net/vxlan.c            David Stevens       2012-11-20  2392  
61adedf3e3f1d3 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2393  	info = skb_tunnel_info(skb);
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2394  	use_cache = ip_tunnel_dst_cache_usable(skb, info);
3093fbe7ff4bc7 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2395  
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2396  	if (rdst) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2397  		dst = &rdst->remote_ip;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2398  		memset(&key, 0, sizeof(key));
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2399  		pkey = &key;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2400  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2401  		if (vxlan_addr_any(dst)) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2402  			if (did_rsc) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2403  				/* short-circuited back to local bridge */
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2404  				vxlan_encap_bypass(skb, vxlan, vxlan,
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2405  						   default_vni, true);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2406  				return;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2407  			}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2408  			goto drop;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2409  		}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2410  
0dfbdf4102b930 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2411  		dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
3ad7a4b141ebd6 drivers/net/vxlan.c            Roopa Prabhu        2017-01-31  2412  		vni = (rdst->remote_vni) ? : default_vni;
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2413  		ifindex = rdst->remote_ifindex;
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2414  		local_ip = vxlan->cfg.saddr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2415  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2416  		if (dst->sa.sa_family == AF_INET) {
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2417  			key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2418  			key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2419  		} else {
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2420  			key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2421  			key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2422  		}
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2423  
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2424  		dst_cache = &rdst->dst_cache;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2425  		md->gbp = skb->mark;
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2426  		if (flags & VXLAN_F_TTL_INHERIT) {
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2427  			ttl = ip_tunnel_get_ttl(old_iph, skb);
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2428  		} else {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2429  			ttl = vxlan->cfg.ttl;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2430  			if (!ttl && vxlan_addr_multicast(dst))
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2431  				ttl = 1;
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2432  		}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2433  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2434  		tos = vxlan->cfg.tos;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2435  		if (tos == 1)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2436  			tos = ip_tunnel_get_dsfield(old_iph, skb);
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2437  		if (tos && !info)
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2438  			use_cache = false;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2439  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2440  		if (dst->sa.sa_family == AF_INET)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2441  			udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM_TX);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2442  		else
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2443  			udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2444  #if IS_ENABLED(CONFIG_IPV6)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2445  		label = vxlan->cfg.label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2446  #endif
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2447  	} else {
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2448  		if (!info) {
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2449  			WARN_ONCE(1, "%s: Missing encapsulation instructions\n",
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2450  				  dev->name);
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2451  			goto drop;
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2452  		}
b1be00a6c39fda drivers/net/vxlan.c            Jiri Benc           2015-09-24  2453  		remote_ip.sa.sa_family = ip_tunnel_info_af(info);
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2454  		if (remote_ip.sa.sa_family == AF_INET) {
c1ea5d672aaff0 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2455  			remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2456  			local_ip.sin.sin_addr.s_addr = info->key.u.ipv4.src;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2457  		} else {
a725e514dbb444 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2458  			remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2459  			local_ip.sin6.sin6_addr = info->key.u.ipv6.src;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2460  		}
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2461  		dst = &remote_ip;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2462  		pkey = &info->key;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2463  		dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
7e2fb8bc7ef6c7 drivers/net/vxlan/vxlan_core.c Paul Chaignon       2022-07-25  2464  		flow_flags = info->key.flow_flags;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2465  		vni = tunnel_id_to_key32(info->key.tun_id);
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2466  		ifindex = 0;
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2467  		dst_cache = &info->dst_cache;
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2468  		if (info->key.tun_flags & TUNNEL_VXLAN_OPT) {
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2469  			if (info->options_len < sizeof(*md))
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2470  				goto drop;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2471  			md = ip_tunnel_info_opts(info);
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2472  		}
7c383fb2254c44 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2473  		ttl = info->key.ttl;
7c383fb2254c44 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2474  		tos = info->key.tos;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2475  #if IS_ENABLED(CONFIG_IPV6)
e7f70af111f086 drivers/net/vxlan.c            Daniel Borkmann     2016-03-09  2476  		label = info->key.label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2477  #endif
b4ed5cad24c107 drivers/net/vxlan.c            Jiri Benc           2016-02-02  2478  		udp_sum = !!(info->key.tun_flags & TUNNEL_CSUM);
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2479  	}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2480  	src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2481  				     vxlan->cfg.port_max, true);
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2482  
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2483  	rcu_read_lock();
a725e514dbb444 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2484  	if (dst->sa.sa_family == AF_INET) {
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2485  		struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2486  		struct rtable *rt;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2487  		__be16 df = 0;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2488  		__be32 saddr;
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2489  
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2490  		if (!ifindex)
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2491  			ifindex = sock4->sock->sk->sk_bound_dev_if;
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2492  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2493  		rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, ifindex,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2494  					   &saddr, pkey, src_port, dst_port,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2495  					   tos, use_cache ? dst_cache : NULL);
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2496  		if (IS_ERR(rt)) {
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2497  			err = PTR_ERR(rt);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2498  			goto tx_error;
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2499  		}
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2500  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2501  		if (!info) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2502  			/* Bypass encapsulation if the destination is local */
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2503  			err = encap_bypass_if_local(skb, dev, vxlan, dst,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2504  						    dst_port, ifindex, vni,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2505  						    &rt->dst, rt->rt_flags);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2506  			if (err)
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2507  				goto out_unlock;
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2508  
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2509  			if (vxlan->cfg.df == VXLAN_DF_SET) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2510  				df = htons(IP_DF);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2511  			} else if (vxlan->cfg.df == VXLAN_DF_INHERIT) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2512  				struct ethhdr *eth = eth_hdr(skb);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2513  
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2514  				if (ntohs(eth->h_proto) == ETH_P_IPV6 ||
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2515  				    (ntohs(eth->h_proto) == ETH_P_IP &&
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2516  				     old_iph->frag_off & htons(IP_DF)))
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2517  					df = htons(IP_DF);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2518  			}
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2519  		} else if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) {
6ceb31ca5f65ac drivers/net/vxlan.c            Alexander Duyck     2016-02-19  2520  			df = htons(IP_DF);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2521  		}
6ceb31ca5f65ac drivers/net/vxlan.c            Alexander Duyck     2016-02-19  2522  
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2523  		ndst = &rt->dst;
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2524  		err = skb_tunnel_check_pmtu(skb, ndst, vxlan_headroom(flags & VXLAN_F_GPE),
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2525  					    netif_is_any_bridge_port(dev));
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2526  		if (err < 0) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2527  			goto tx_error;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2528  		} else if (err) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2529  			if (info) {
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2530  				struct ip_tunnel_info *unclone;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2531  
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2532  				unclone = skb_tunnel_info_unclone(skb);
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2533  				if (unlikely(!unclone))
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2534  					goto tx_error;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2535  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2536  				unclone->key.u.ipv4.src = pkey->u.ipv4.dst;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2537  				unclone->key.u.ipv4.dst = saddr;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2538  			}
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2539  			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2540  			dst_release(ndst);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2541  			goto out_unlock;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2542  		}
a93bf0ff449064 drivers/net/vxlan.c            Xin Long            2017-12-18  2543  
a0dced17ad9dc0 drivers/net/vxlan.c            Hangbin Liu         2020-08-05  2544  		tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
0e6fbc5b6c6218 drivers/net/vxlan.c            Pravin B Shelar     2013-06-17  2545  		ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2546  		err = vxlan_build_skb(skb, ndst, sizeof(struct iphdr),
54bfd872bf16d4 drivers/net/vxlan.c            Jiri Benc           2016-02-16  2547  				      vni, md, flags, udp_sum);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2548  		if (err < 0)
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2549  			goto tx_error;
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2550  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2551  		udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2552  				    pkey->u.ipv4.dst, tos, ttl, df,
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2553  				    src_port, dst_port, xnet, !udp_sum);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2554  #if IS_ENABLED(CONFIG_IPV6)
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2555  	} else {
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2556  		struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2557  
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2558  		if (!ifindex)
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2559  			ifindex = sock6->sock->sk->sk_bound_dev_if;
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2560  
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2561  		ndst = vxlan6_get_route(vxlan, dev, sock6, skb, ifindex, tos,
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2562  					label, &dst->sin6.sin6_addr,
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2563  					&local_ip.sin6.sin6_addr,
4ecb1d83f6abe8 drivers/net/vxlan.c            Martynas Pumputis   2017-01-11  2564  					dst_port, src_port,
db3c6139e6ead9 drivers/net/vxlan.c            Daniel Borkmann     2016-03-04  2565  					dst_cache, info);
e5d4b29fe86a91 drivers/net/vxlan.c            Jiri Benc           2015-12-07  2566  		if (IS_ERR(ndst)) {
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2567  			err = PTR_ERR(ndst);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2568  			ndst = NULL;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2569  			goto tx_error;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2570  		}
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2571  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2572  		if (!info) {
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2573  			u32 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2574  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2575  			err = encap_bypass_if_local(skb, dev, vxlan, dst,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2576  						    dst_port, ifindex, vni,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2577  						    ndst, rt6i_flags);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2578  			if (err)
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2579  				goto out_unlock;
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2580  		}
35e2d1152b22ea drivers/net/vxlan.c            Jesse Gross         2016-01-20  2581  
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2582  		err = skb_tunnel_check_pmtu(skb, ndst,
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2583  					    vxlan_headroom((flags & VXLAN_F_GPE) | VXLAN_F_IPV6),
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2584  					    netif_is_any_bridge_port(dev));
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2585  		if (err < 0) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2586  			goto tx_error;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2587  		} else if (err) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2588  			if (info) {
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2589  				struct ip_tunnel_info *unclone;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2590  				struct in6_addr src, dst;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2591  
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2592  				unclone = skb_tunnel_info_unclone(skb);
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2593  				if (unlikely(!unclone))
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2594  					goto tx_error;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2595  
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2596  				src = remote_ip.sin6.sin6_addr;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2597  				dst = local_ip.sin6.sin6_addr;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2598  				unclone->key.u.ipv6.src = src;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2599  				unclone->key.u.ipv6.dst = dst;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2600  			}
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2601  
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2602  			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2603  			dst_release(ndst);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2604  			goto out_unlock;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2605  		}
a93bf0ff449064 drivers/net/vxlan.c            Xin Long            2017-12-18  2606  
a0dced17ad9dc0 drivers/net/vxlan.c            Hangbin Liu         2020-08-05  2607  		tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2608  		ttl = ttl ? : ip6_dst_hoplimit(ndst);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2609  		skb_scrub_packet(skb, xnet);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2610  		err = vxlan_build_skb(skb, ndst, sizeof(struct ipv6hdr),
54bfd872bf16d4 drivers/net/vxlan.c            Jiri Benc           2016-02-16  2611  				      vni, md, flags, udp_sum);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2612  		if (err < 0)
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2613  			goto tx_error;
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2614  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2615  		udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev,
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2616  				     &local_ip.sin6.sin6_addr,
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2617  				     &dst->sin6.sin6_addr, tos, ttl,
e7f70af111f086 drivers/net/vxlan.c            Daniel Borkmann     2016-03-09  2618  				     label, src_port, dst_port, !udp_sum);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2619  #endif
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2620  	}
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2621  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX, pkt_len);
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2622  out_unlock:
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2623  	rcu_read_unlock();
4ad169300a7350 drivers/net/vxlan.c            Stephen Hemminger   2013-06-17  2624  	return;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2625  
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2626  drop:
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2627  	dev->stats.tx_dropped++;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2628  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2629  	dev_kfree_skb(skb);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2630  	return;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2631  
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2632  tx_error:
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2633  	rcu_read_unlock();
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2634  	if (err == -ELOOP)
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2635  		dev->stats.collisions++;
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2636  	else if (err == -ENETUNREACH)
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2637  		dev->stats.tx_carrier_errors++;
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2638  	dst_release(ndst);
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2639  	dev->stats.tx_errors++;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2640  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2641  	kfree_skb(skb);
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2642  }
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2643  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup
  2023-10-09  8:20 ` [PATCH net-next 7/7] vxlan: " Beniamino Galvani
  2023-10-09 10:22   ` kernel test robot
@ 2023-10-09 16:12   ` kernel test robot
  1 sibling, 0 replies; 14+ messages in thread
From: kernel test robot @ 2023-10-09 16:12 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: oe-kbuild-all, David S . Miller, Jakub Kicinski, Paolo Abeni,
	David Ahern, Guillaume Nault, linux-kernel

Hi Beniamino,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Beniamino-Galvani/ipv4-rename-and-move-ip_route_output_tunnel/20231009-162823
base:   net-next/main
patch link:    https://lore.kernel.org/r/20231009082059.2500217-8-b.galvani%40gmail.com
patch subject: [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup
config: s390-randconfig-001-20231009 (https://download.01.org/0day-ci/archive/20231010/202310100015.LteDznhb-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231010/202310100015.LteDznhb-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310100015.LteDznhb-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/net/vxlan/vxlan_core.c: In function 'vxlan_xmit_one':
   drivers/net/vxlan/vxlan_core.c:2381:24: warning: variable 'flow_flags' set but not used [-Wunused-but-set-variable]
    2381 |         __u8 tos, ttl, flow_flags = 0;
         |                        ^~~~~~~~~~
>> drivers/net/vxlan/vxlan_core.c:2375:37: warning: variable 'local_ip' set but not used [-Wunused-but-set-variable]
    2375 |         union vxlan_addr remote_ip, local_ip;
         |                                     ^~~~~~~~


vim +/local_ip +2375 drivers/net/vxlan/vxlan_core.c

fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2364  
6ab271aaad2535 drivers/net/vxlan/vxlan_core.c Ido Schimmel        2023-03-15  2365  void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
6ab271aaad2535 drivers/net/vxlan/vxlan_core.c Ido Schimmel        2023-03-15  2366  		    __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc)
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2367  {
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2368  	struct dst_cache *dst_cache;
3093fbe7ff4bc7 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2369  	struct ip_tunnel_info *info;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2370  	struct ip_tunnel_key *pkey;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2371  	struct ip_tunnel_key key;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2372  	struct vxlan_dev *vxlan = netdev_priv(dev);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2373  	const struct iphdr *old_iph = ip_hdr(skb);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2374  	union vxlan_addr *dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05 @2375  	union vxlan_addr remote_ip, local_ip;
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2376  	struct vxlan_metadata _md;
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2377  	struct vxlan_metadata *md = &_md;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2378  	unsigned int pkt_len = skb->len;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2379  	__be16 src_port = 0, dst_port;
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2380  	struct dst_entry *ndst = NULL;
7e2fb8bc7ef6c7 drivers/net/vxlan/vxlan_core.c Paul Chaignon       2022-07-25  2381  	__u8 tos, ttl, flow_flags = 0;
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2382  	int ifindex;
0e6fbc5b6c6218 drivers/net/vxlan.c            Pravin B Shelar     2013-06-17  2383  	int err;
dc5321d79697db drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2384  	u32 flags = vxlan->cfg.flags;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2385  	bool use_cache;
b4ed5cad24c107 drivers/net/vxlan.c            Jiri Benc           2016-02-02  2386  	bool udp_sum = false;
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2387  	bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev));
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2388  	__be32 vni = 0;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2389  #if IS_ENABLED(CONFIG_IPV6)
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2390  	__be32 label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2391  #endif
e4f67addf158f9 drivers/net/vxlan.c            David Stevens       2012-11-20  2392  
61adedf3e3f1d3 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2393  	info = skb_tunnel_info(skb);
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2394  	use_cache = ip_tunnel_dst_cache_usable(skb, info);
3093fbe7ff4bc7 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2395  
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2396  	if (rdst) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2397  		dst = &rdst->remote_ip;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2398  		memset(&key, 0, sizeof(key));
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2399  		pkey = &key;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2400  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2401  		if (vxlan_addr_any(dst)) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2402  			if (did_rsc) {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2403  				/* short-circuited back to local bridge */
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2404  				vxlan_encap_bypass(skb, vxlan, vxlan,
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2405  						   default_vni, true);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2406  				return;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2407  			}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2408  			goto drop;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2409  		}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2410  
0dfbdf4102b930 drivers/net/vxlan.c            Thomas Graf         2015-07-21  2411  		dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
3ad7a4b141ebd6 drivers/net/vxlan.c            Roopa Prabhu        2017-01-31  2412  		vni = (rdst->remote_vni) ? : default_vni;
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2413  		ifindex = rdst->remote_ifindex;
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2414  		local_ip = vxlan->cfg.saddr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2415  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2416  		if (dst->sa.sa_family == AF_INET) {
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2417  			key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2418  			key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2419  		} else {
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2420  			key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2421  			key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2422  		}
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2423  
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2424  		dst_cache = &rdst->dst_cache;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2425  		md->gbp = skb->mark;
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2426  		if (flags & VXLAN_F_TTL_INHERIT) {
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2427  			ttl = ip_tunnel_get_ttl(old_iph, skb);
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2428  		} else {
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2429  			ttl = vxlan->cfg.ttl;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2430  			if (!ttl && vxlan_addr_multicast(dst))
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2431  				ttl = 1;
72f6d71e491e6c drivers/net/vxlan.c            Hangbin Liu         2018-04-17  2432  		}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2433  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2434  		tos = vxlan->cfg.tos;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2435  		if (tos == 1)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2436  			tos = ip_tunnel_get_dsfield(old_iph, skb);
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2437  		if (tos && !info)
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2438  			use_cache = false;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2439  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2440  		if (dst->sa.sa_family == AF_INET)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2441  			udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM_TX);
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2442  		else
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2443  			udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2444  #if IS_ENABLED(CONFIG_IPV6)
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2445  		label = vxlan->cfg.label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2446  #endif
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2447  	} else {
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2448  		if (!info) {
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2449  			WARN_ONCE(1, "%s: Missing encapsulation instructions\n",
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2450  				  dev->name);
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2451  			goto drop;
435be28b0789b3 drivers/net/vxlan.c            Jakub Kicinski      2020-09-25  2452  		}
b1be00a6c39fda drivers/net/vxlan.c            Jiri Benc           2015-09-24  2453  		remote_ip.sa.sa_family = ip_tunnel_info_af(info);
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2454  		if (remote_ip.sa.sa_family == AF_INET) {
c1ea5d672aaff0 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2455  			remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2456  			local_ip.sin.sin_addr.s_addr = info->key.u.ipv4.src;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2457  		} else {
a725e514dbb444 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2458  			remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2459  			local_ip.sin6.sin6_addr = info->key.u.ipv6.src;
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2460  		}
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2461  		dst = &remote_ip;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2462  		pkey = &info->key;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2463  		dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
7e2fb8bc7ef6c7 drivers/net/vxlan/vxlan_core.c Paul Chaignon       2022-07-25  2464  		flow_flags = info->key.flow_flags;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2465  		vni = tunnel_id_to_key32(info->key.tun_id);
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2466  		ifindex = 0;
d71785ffc7e7ca drivers/net/vxlan.c            Paolo Abeni         2016-02-12  2467  		dst_cache = &info->dst_cache;
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2468  		if (info->key.tun_flags & TUNNEL_VXLAN_OPT) {
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2469  			if (info->options_len < sizeof(*md))
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2470  				goto drop;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2471  			md = ip_tunnel_info_opts(info);
eadf52cf185219 drivers/net/vxlan.c            Xin Long            2019-10-29  2472  		}
7c383fb2254c44 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2473  		ttl = info->key.ttl;
7c383fb2254c44 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2474  		tos = info->key.tos;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2475  #if IS_ENABLED(CONFIG_IPV6)
e7f70af111f086 drivers/net/vxlan.c            Daniel Borkmann     2016-03-09  2476  		label = info->key.label;
fba55a66e8ecd1 drivers/net/vxlan/vxlan_core.c Roopa Prabhu        2022-03-01  2477  #endif
b4ed5cad24c107 drivers/net/vxlan.c            Jiri Benc           2016-02-02  2478  		udp_sum = !!(info->key.tun_flags & TUNNEL_CSUM);
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2479  	}
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2480  	src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2481  				     vxlan->cfg.port_max, true);
ee122c79d4227f drivers/net/vxlan.c            Thomas Graf         2015-07-21  2482  
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2483  	rcu_read_lock();
a725e514dbb444 drivers/net/vxlan.c            Jiri Benc           2015-08-20  2484  	if (dst->sa.sa_family == AF_INET) {
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2485  		struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2486  		struct rtable *rt;
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2487  		__be16 df = 0;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2488  		__be32 saddr;
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2489  
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2490  		if (!ifindex)
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2491  			ifindex = sock4->sock->sk->sk_bound_dev_if;
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2492  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2493  		rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, ifindex,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2494  					   &saddr, pkey, src_port, dst_port,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2495  					   tos, use_cache ? dst_cache : NULL);
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2496  		if (IS_ERR(rt)) {
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2497  			err = PTR_ERR(rt);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2498  			goto tx_error;
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2499  		}
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2500  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2501  		if (!info) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2502  			/* Bypass encapsulation if the destination is local */
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2503  			err = encap_bypass_if_local(skb, dev, vxlan, dst,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2504  						    dst_port, ifindex, vni,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2505  						    &rt->dst, rt->rt_flags);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2506  			if (err)
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2507  				goto out_unlock;
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2508  
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2509  			if (vxlan->cfg.df == VXLAN_DF_SET) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2510  				df = htons(IP_DF);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2511  			} else if (vxlan->cfg.df == VXLAN_DF_INHERIT) {
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2512  				struct ethhdr *eth = eth_hdr(skb);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2513  
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2514  				if (ntohs(eth->h_proto) == ETH_P_IPV6 ||
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2515  				    (ntohs(eth->h_proto) == ETH_P_IP &&
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2516  				     old_iph->frag_off & htons(IP_DF)))
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2517  					df = htons(IP_DF);
b4d3069783bccf drivers/net/vxlan.c            Stefano Brivio      2018-11-08  2518  			}
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2519  		} else if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) {
6ceb31ca5f65ac drivers/net/vxlan.c            Alexander Duyck     2016-02-19  2520  			df = htons(IP_DF);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2521  		}
6ceb31ca5f65ac drivers/net/vxlan.c            Alexander Duyck     2016-02-19  2522  
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2523  		ndst = &rt->dst;
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2524  		err = skb_tunnel_check_pmtu(skb, ndst, vxlan_headroom(flags & VXLAN_F_GPE),
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2525  					    netif_is_any_bridge_port(dev));
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2526  		if (err < 0) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2527  			goto tx_error;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2528  		} else if (err) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2529  			if (info) {
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2530  				struct ip_tunnel_info *unclone;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2531  
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2532  				unclone = skb_tunnel_info_unclone(skb);
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2533  				if (unlikely(!unclone))
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2534  					goto tx_error;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2535  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2536  				unclone->key.u.ipv4.src = pkey->u.ipv4.dst;
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2537  				unclone->key.u.ipv4.dst = saddr;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2538  			}
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2539  			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2540  			dst_release(ndst);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2541  			goto out_unlock;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2542  		}
a93bf0ff449064 drivers/net/vxlan.c            Xin Long            2017-12-18  2543  
a0dced17ad9dc0 drivers/net/vxlan.c            Hangbin Liu         2020-08-05  2544  		tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
0e6fbc5b6c6218 drivers/net/vxlan.c            Pravin B Shelar     2013-06-17  2545  		ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2546  		err = vxlan_build_skb(skb, ndst, sizeof(struct iphdr),
54bfd872bf16d4 drivers/net/vxlan.c            Jiri Benc           2016-02-16  2547  				      vni, md, flags, udp_sum);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2548  		if (err < 0)
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2549  			goto tx_error;
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2550  
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2551  		udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr,
b4a6c582b7ff13 drivers/net/vxlan/vxlan_core.c Beniamino Galvani   2023-10-09  2552  				    pkey->u.ipv4.dst, tos, ttl, df,
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2553  				    src_port, dst_port, xnet, !udp_sum);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2554  #if IS_ENABLED(CONFIG_IPV6)
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2555  	} else {
c6fcc4fc5f8b59 drivers/net/vxlan.c            pravin shelar       2016-10-28  2556  		struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2557  
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2558  		if (!ifindex)
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2559  			ifindex = sock6->sock->sk->sk_bound_dev_if;
aab8cc3630e325 drivers/net/vxlan.c            Alexis Bauvin       2018-12-03  2560  
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2561  		ndst = vxlan6_get_route(vxlan, dev, sock6, skb, ifindex, tos,
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2562  					label, &dst->sin6.sin6_addr,
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2563  					&local_ip.sin6.sin6_addr,
4ecb1d83f6abe8 drivers/net/vxlan.c            Martynas Pumputis   2017-01-11  2564  					dst_port, src_port,
db3c6139e6ead9 drivers/net/vxlan.c            Daniel Borkmann     2016-03-04  2565  					dst_cache, info);
e5d4b29fe86a91 drivers/net/vxlan.c            Jiri Benc           2015-12-07  2566  		if (IS_ERR(ndst)) {
8ebd115bb23ac4 drivers/net/vxlan.c            David S. Miller     2016-11-15  2567  			err = PTR_ERR(ndst);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2568  			ndst = NULL;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2569  			goto tx_error;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2570  		}
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2571  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2572  		if (!info) {
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2573  			u32 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags;
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2574  
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2575  			err = encap_bypass_if_local(skb, dev, vxlan, dst,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2576  						    dst_port, ifindex, vni,
49f810f00fa347 drivers/net/vxlan.c            Matthias Schiffer   2017-06-19  2577  						    ndst, rt6i_flags);
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2578  			if (err)
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2579  				goto out_unlock;
fee1fad7c73dd0 drivers/net/vxlan.c            pravin shelar       2016-11-13  2580  		}
35e2d1152b22ea drivers/net/vxlan.c            Jesse Gross         2016-01-20  2581  
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2582  		err = skb_tunnel_check_pmtu(skb, ndst,
94d166c5318c6e drivers/net/vxlan/vxlan_core.c Jiri Benc           2023-07-20  2583  					    vxlan_headroom((flags & VXLAN_F_GPE) | VXLAN_F_IPV6),
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2584  					    netif_is_any_bridge_port(dev));
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2585  		if (err < 0) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2586  			goto tx_error;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2587  		} else if (err) {
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2588  			if (info) {
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2589  				struct ip_tunnel_info *unclone;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2590  				struct in6_addr src, dst;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2591  
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2592  				unclone = skb_tunnel_info_unclone(skb);
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2593  				if (unlikely(!unclone))
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2594  					goto tx_error;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2595  
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2596  				src = remote_ip.sin6.sin6_addr;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2597  				dst = local_ip.sin6.sin6_addr;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2598  				unclone->key.u.ipv6.src = src;
30a93d2b7d5a7c drivers/net/vxlan.c            Antoine Tenart      2021-03-25  2599  				unclone->key.u.ipv6.dst = dst;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2600  			}
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2601  
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2602  			vxlan_encap_bypass(skb, vxlan, vxlan, vni, false);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2603  			dst_release(ndst);
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2604  			goto out_unlock;
fc68c99577cc66 drivers/net/vxlan.c            Stefano Brivio      2020-08-04  2605  		}
a93bf0ff449064 drivers/net/vxlan.c            Xin Long            2017-12-18  2606  
a0dced17ad9dc0 drivers/net/vxlan.c            Hangbin Liu         2020-08-05  2607  		tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2608  		ttl = ttl ? : ip6_dst_hoplimit(ndst);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2609  		skb_scrub_packet(skb, xnet);
f491e56dba511d drivers/net/vxlan.c            Jiri Benc           2016-02-02  2610  		err = vxlan_build_skb(skb, ndst, sizeof(struct ipv6hdr),
54bfd872bf16d4 drivers/net/vxlan.c            Jiri Benc           2016-02-16  2611  				      vni, md, flags, udp_sum);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2612  		if (err < 0)
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2613  			goto tx_error;
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2614  
0770b53bd276a7 drivers/net/vxlan.c            pravin shelar       2016-11-13  2615  		udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev,
1158632b5a2dcc drivers/net/vxlan.c            Brian Russell       2017-02-24  2616  				     &local_ip.sin6.sin6_addr,
272d96a5ab1066 drivers/net/vxlan.c            pravin shelar       2016-08-05  2617  				     &dst->sin6.sin6_addr, tos, ttl,
e7f70af111f086 drivers/net/vxlan.c            Daniel Borkmann     2016-03-09  2618  				     label, src_port, dst_port, !udp_sum);
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2619  #endif
e4c7ed415387cf drivers/net/vxlan.c            Cong Wang           2013-08-31  2620  	}
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2621  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX, pkt_len);
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2622  out_unlock:
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2623  	rcu_read_unlock();
4ad169300a7350 drivers/net/vxlan.c            Stephen Hemminger   2013-06-17  2624  	return;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2625  
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2626  drop:
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2627  	dev->stats.tx_dropped++;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2628  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2629  	dev_kfree_skb(skb);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2630  	return;
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2631  
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2632  tx_error:
56de859e9967c0 drivers/net/vxlan.c            Jakub Kicinski      2017-02-24  2633  	rcu_read_unlock();
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2634  	if (err == -ELOOP)
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2635  		dev->stats.collisions++;
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2636  	else if (err == -ENETUNREACH)
655c3de16540b8 drivers/net/vxlan.c            pravin shelar       2016-11-13  2637  		dev->stats.tx_carrier_errors++;
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2638  	dst_release(ndst);
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2639  	dev->stats.tx_errors++;
4095e0e1328a3c drivers/net/vxlan/vxlan_core.c Nikolay Aleksandrov 2022-03-01  2640  	vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0);
c46b7897ad5ba4 drivers/net/vxlan.c            pravin shelar       2016-11-13  2641  	kfree_skb(skb);
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2642  }
d342894c5d2f8c drivers/net/vxlan.c            stephen hemminger   2012-10-01  2643  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel()
  2023-10-09  8:20 ` [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Beniamino Galvani
@ 2023-10-11 18:50   ` David Ahern
  0 siblings, 0 replies; 14+ messages in thread
From: David Ahern @ 2023-10-11 18:50 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Guillaume Nault,
	linux-kernel

On 10/9/23 2:20 AM, Beniamino Galvani wrote:
> At the moment ip_route_output_tunnel() is used only by bareudp.
> Ideally, other UDP tunnel implementations should use it, but to do so
> the function needs to accept new parameters that are specific for UDP
> tunnels, such as the ports.
> 
> Prepare for these changes by renaming the function to
> udp_tunnel_dst_lookup() and move it to file
> net/ipv4/udp_tunnel_core.c.
> 
> Suggested-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> ---
>  drivers/net/bareudp.c      |  8 +++----
>  include/net/route.h        |  6 -----
>  include/net/udp_tunnel.h   |  6 +++++
>  net/ipv4/route.c           | 48 --------------------------------------
>  net/ipv4/udp_tunnel_core.c | 48 ++++++++++++++++++++++++++++++++++++++
>  5 files changed, 58 insertions(+), 58 deletions(-)
> 

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



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

* Re: [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup()
  2023-10-09  8:20 ` [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup() Beniamino Galvani
@ 2023-10-11 18:51   ` David Ahern
  0 siblings, 0 replies; 14+ messages in thread
From: David Ahern @ 2023-10-11 18:51 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Guillaume Nault,
	linux-kernel

On 10/9/23 2:20 AM, Beniamino Galvani wrote:
> The function is now UDP-specific, the protocol is always IPPROTO_UDP.
> 
> Suggested-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> ---
>  drivers/net/bareudp.c      | 4 ++--
>  include/net/udp_tunnel.h   | 2 +-
>  net/ipv4/udp_tunnel_core.c | 4 ++--
>  3 files changed, 5 insertions(+), 5 deletions(-)
> 

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



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

* Re: [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup()
  2023-10-09  8:20 ` [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup() Beniamino Galvani
@ 2023-10-11 18:51   ` David Ahern
  0 siblings, 0 replies; 14+ messages in thread
From: David Ahern @ 2023-10-11 18:51 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Guillaume Nault,
	linux-kernel

On 10/9/23 2:20 AM, Beniamino Galvani wrote:
> We want to make the function more generic so that it can be used by
> other UDP tunnel implementations such as geneve and vxlan. To do that,
> add the following arguments:
> 
>  - source and destination UDP port;
>  - ifindex of the output interface, needed by vxlan;
>  - the tos, because in some cases it is not taken from struct
>    ip_tunnel_info (for example, when it's inherited from the inner
>    packet);
>  - the dst cache, because not all tunnel types (e.g. vxlan) want to
>    use the one from struct ip_tunnel_info.
> 
> With these parameters, the function no longer needs the full struct
> ip_tunnel_info as argument and we can pass only the relevant part of
> it (struct ip_tunnel_key).
> 
> Suggested-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> ---
>  drivers/net/bareudp.c      | 11 +++++++----
>  include/net/udp_tunnel.h   |  8 +++++---
>  net/ipv4/udp_tunnel_core.c | 26 +++++++++++++-------------
>  3 files changed, 25 insertions(+), 20 deletions(-)
> 

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



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

* Re: [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups
  2023-10-09  8:20 ` [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups Beniamino Galvani
@ 2023-10-11 18:52   ` David Ahern
  0 siblings, 0 replies; 14+ messages in thread
From: David Ahern @ 2023-10-11 18:52 UTC (permalink / raw)
  To: Beniamino Galvani, netdev
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Guillaume Nault,
	linux-kernel

On 10/9/23 2:20 AM, Beniamino Galvani wrote:
> Commit 451ef36bd229 ("ip_tunnels: Add new flow flags field to
> ip_tunnel_key") added a new field to struct ip_tunnel_key to control
> route lookups. Currently the flag is used by vxlan and geneve tunnels;
> use it also in udp_tunnel_dst_lookup() so that it affects all tunnel
> types relying on this function.
> 
> Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> ---
>  net/ipv4/udp_tunnel_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 

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



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

end of thread, other threads:[~2023-10-11 18:52 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-09  8:20 [PATCH net-next 0/7] net: consolidate IPv4 route lookup for UDP tunnels Beniamino Galvani
2023-10-09  8:20 ` [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Beniamino Galvani
2023-10-11 18:50   ` David Ahern
2023-10-09  8:20 ` [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup() Beniamino Galvani
2023-10-11 18:51   ` David Ahern
2023-10-09  8:20 ` [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup() Beniamino Galvani
2023-10-11 18:51   ` David Ahern
2023-10-09  8:20 ` [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups Beniamino Galvani
2023-10-11 18:52   ` David Ahern
2023-10-09  8:20 ` [PATCH net-next 5/7] geneve: add dsfield helper function Beniamino Galvani
2023-10-09  8:20 ` [PATCH net-next 6/7] geneve: use generic function for tunnel IPv4 route lookup Beniamino Galvani
2023-10-09  8:20 ` [PATCH net-next 7/7] vxlan: " Beniamino Galvani
2023-10-09 10:22   ` kernel test robot
2023-10-09 16:12   ` kernel test robot

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).