netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels
@ 2016-05-03 15:10 Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 1/3] gre: remove superfluous pskb_may_pull Jiri Benc
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jiri Benc @ 2016-05-03 15:10 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Graf, pravin shelar, Simon Horman

NOTE: this patchset needs net merged to net-next.

This allows lwtunnel users to get also packets with ETH_P_TEB protocol
specified in GRE header through an ipgre interface. There's really nothing
special about these packets in the case of lwtunnels - it's just an inner
protocol like any other. The only complications stem from keeping
compatibility with other uses of GRE.

This will be used by openvswitch to support eth_push and eth_pop actions.
I'd also like to see tc support for lwtunnels (this feature included) in the
future.

The first patch is not directly related and can be submitted standalone if
needed.

Jiri Benc (3):
  gre: remove superfluous pskb_may_pull
  gre: move iptunnel_pull_header down to ipgre_rcv
  gre: receive also TEB packets for lwtunnels

 include/net/ip_tunnels.h |  1 +
 net/ipv4/gre_demux.c     |  5 +----
 net/ipv4/ip_gre.c        | 48 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 37 insertions(+), 17 deletions(-)

-- 
1.8.3.1

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

* [PATCH net-next 1/3] gre: remove superfluous pskb_may_pull
  2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
@ 2016-05-03 15:10 ` Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 2/3] gre: move iptunnel_pull_header down to ipgre_rcv Jiri Benc
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2016-05-03 15:10 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Graf, pravin shelar, Simon Horman

The call to gre_parse_header is either followed by iptunnel_pull_header, or
in the case of ICMP error path, the actual header is not accessed at all.

In the first case, iptunnel_pull_header will call pskb_may_pull anyway and
it's pointless to do it twice. The only difference is what call will fail
with what error code but the net effect is still the same in all call sites.

In the second case, pskb_may_pull is pointless, as skb->data is at the outer
IP header and not at the GRE header.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
 net/ipv4/gre_demux.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
index a41e73ab1369..d78e2eefc0f7 100644
--- a/net/ipv4/gre_demux.c
+++ b/net/ipv4/gre_demux.c
@@ -114,11 +114,8 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	 */
 	if (greh->flags == 0 && tpi->proto == htons(ETH_P_WCCP)) {
 		tpi->proto = htons(ETH_P_IP);
-		if ((*(u8 *)options & 0xF0) != 0x40) {
+		if ((*(u8 *)options & 0xF0) != 0x40)
 			hdr_len += 4;
-			if (!pskb_may_pull(skb, hdr_len))
-				return -EINVAL;
-		}
 	}
 	return hdr_len;
 }
-- 
1.8.3.1

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

* [PATCH net-next 2/3] gre: move iptunnel_pull_header down to ipgre_rcv
  2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 1/3] gre: remove superfluous pskb_may_pull Jiri Benc
@ 2016-05-03 15:10 ` Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 3/3] gre: receive also TEB packets for lwtunnels Jiri Benc
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2016-05-03 15:10 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Graf, pravin shelar, Simon Horman

This will allow to make the pull dependent on the tunnel type.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
 net/ipv4/ip_gre.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 8260a707b9b8..8f377dad5489 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -260,7 +260,8 @@ static __be32 tunnel_id_to_key(__be64 x)
 #endif
 }
 
-static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
+static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
+		     int hdr_len)
 {
 	struct net *net = dev_net(skb->dev);
 	struct metadata_dst *tun_dst = NULL;
@@ -278,6 +279,9 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
 				  iph->saddr, iph->daddr, tpi->key);
 
 	if (tunnel) {
+		if (iptunnel_pull_header(skb, hdr_len, tpi->proto, false) < 0)
+			goto drop;
+
 		skb_pop_mac_header(skb);
 		if (tunnel->collect_md) {
 			__be16 flags;
@@ -294,6 +298,10 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
 		return PACKET_RCVD;
 	}
 	return PACKET_REJECT;
+
+drop:
+	kfree_skb(skb);
+	return PACKET_RCVD;
 }
 
 static int gre_rcv(struct sk_buff *skb)
@@ -314,10 +322,7 @@ static int gre_rcv(struct sk_buff *skb)
 	if (hdr_len < 0)
 		goto drop;
 
-	if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
-		goto drop;
-
-	if (ipgre_rcv(skb, &tpi) == PACKET_RCVD)
+	if (ipgre_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
 		return 0;
 
 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
-- 
1.8.3.1

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

* [PATCH net-next 3/3] gre: receive also TEB packets for lwtunnels
  2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 1/3] gre: remove superfluous pskb_may_pull Jiri Benc
  2016-05-03 15:10 ` [PATCH net-next 2/3] gre: move iptunnel_pull_header down to ipgre_rcv Jiri Benc
@ 2016-05-03 15:10 ` Jiri Benc
  2016-05-04  7:52 ` [PATCH net-next 0/3] " Simon Horman
  2016-05-04 18:11 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2016-05-03 15:10 UTC (permalink / raw)
  To: netdev; +Cc: Thomas Graf, pravin shelar, Simon Horman

For ipgre interfaces in collect metadata mode, receive also traffic with
encapsulated Ethernet headers. The lwtunnel users are supposed to sort this
out correctly. This allows to have mixed Ethernet + L3-only traffic on the
same lwtunnel interface. This is the same way as VXLAN-GPE behaves.

To keep backwards compatibility and prevent any surprises, gretap interfaces
have priority in receiving packets with Ethernet headers.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
 include/net/ip_tunnels.h |  1 +
 net/ipv4/ip_gre.c        | 39 ++++++++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 6d790910ebdf..d916b4315903 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -160,6 +160,7 @@ struct tnl_ptk_info {
 
 #define PACKET_RCVD	0
 #define PACKET_REJECT	1
+#define PACKET_NEXT	2
 
 #define IP_TNL_HASH_BITS   7
 #define IP_TNL_HASH_SIZE   (1 << IP_TNL_HASH_BITS)
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 8f377dad5489..2b267e71ebf5 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -260,26 +260,20 @@ static __be32 tunnel_id_to_key(__be64 x)
 #endif
 }
 
-static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
-		     int hdr_len)
+static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
+		       struct ip_tunnel_net *itn, int hdr_len, bool raw_proto)
 {
-	struct net *net = dev_net(skb->dev);
 	struct metadata_dst *tun_dst = NULL;
-	struct ip_tunnel_net *itn;
 	const struct iphdr *iph;
 	struct ip_tunnel *tunnel;
 
-	if (tpi->proto == htons(ETH_P_TEB))
-		itn = net_generic(net, gre_tap_net_id);
-	else
-		itn = net_generic(net, ipgre_net_id);
-
 	iph = ip_hdr(skb);
 	tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, tpi->flags,
 				  iph->saddr, iph->daddr, tpi->key);
 
 	if (tunnel) {
-		if (iptunnel_pull_header(skb, hdr_len, tpi->proto, false) < 0)
+		if (__iptunnel_pull_header(skb, hdr_len, tpi->proto,
+					   raw_proto, false) < 0)
 			goto drop;
 
 		skb_pop_mac_header(skb);
@@ -297,13 +291,36 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
 		ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
 		return PACKET_RCVD;
 	}
-	return PACKET_REJECT;
+	return PACKET_NEXT;
 
 drop:
 	kfree_skb(skb);
 	return PACKET_RCVD;
 }
 
+static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
+		     int hdr_len)
+{
+	struct net *net = dev_net(skb->dev);
+	struct ip_tunnel_net *itn;
+	int res;
+
+	if (tpi->proto == htons(ETH_P_TEB))
+		itn = net_generic(net, gre_tap_net_id);
+	else
+		itn = net_generic(net, ipgre_net_id);
+
+	res = __ipgre_rcv(skb, tpi, itn, hdr_len, false);
+	if (res == PACKET_NEXT && tpi->proto == htons(ETH_P_TEB)) {
+		/* ipgre tunnels in collect metadata mode should receive
+		 * also ETH_P_TEB traffic.
+		 */
+		itn = net_generic(net, ipgre_net_id);
+		res = __ipgre_rcv(skb, tpi, itn, hdr_len, true);
+	}
+	return res;
+}
+
 static int gre_rcv(struct sk_buff *skb)
 {
 	struct tnl_ptk_info tpi;
-- 
1.8.3.1

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

* Re: [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels
  2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
                   ` (2 preceding siblings ...)
  2016-05-03 15:10 ` [PATCH net-next 3/3] gre: receive also TEB packets for lwtunnels Jiri Benc
@ 2016-05-04  7:52 ` Simon Horman
  2016-05-04 18:11 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2016-05-04  7:52 UTC (permalink / raw)
  To: Jiri Benc; +Cc: netdev, Thomas Graf, pravin shelar

On Tue, May 03, 2016 at 05:10:05PM +0200, Jiri Benc wrote:
> NOTE: this patchset needs net merged to net-next.
> 
> This allows lwtunnel users to get also packets with ETH_P_TEB protocol
> specified in GRE header through an ipgre interface. There's really nothing
> special about these packets in the case of lwtunnels - it's just an inner
> protocol like any other. The only complications stem from keeping
> compatibility with other uses of GRE.
> 
> This will be used by openvswitch to support eth_push and eth_pop actions.
> I'd also like to see tc support for lwtunnels (this feature included) in the
> future.
> 
> The first patch is not directly related and can be submitted standalone if
> needed.

I have exercised this patch-set using Open vSwitch both with
and without the patchset I posted earlier this afternoon to
make use of this new feature:

"[PATCH v9 net-next 0/7] openvswitch: support for layer 3 encapsulated packets"

All three patches:

Tested-by: Simon Horman <simon.horman@netronome.com>

> Jiri Benc (3):
>   gre: remove superfluous pskb_may_pull
>   gre: move iptunnel_pull_header down to ipgre_rcv
>   gre: receive also TEB packets for lwtunnels
> 
>  include/net/ip_tunnels.h |  1 +
>  net/ipv4/gre_demux.c     |  5 +----
>  net/ipv4/ip_gre.c        | 48 +++++++++++++++++++++++++++++++++++-------------
>  3 files changed, 37 insertions(+), 17 deletions(-)
> 
> -- 
> 1.8.3.1
> 

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

* Re: [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels
  2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
                   ` (3 preceding siblings ...)
  2016-05-04  7:52 ` [PATCH net-next 0/3] " Simon Horman
@ 2016-05-04 18:11 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2016-05-04 18:11 UTC (permalink / raw)
  To: jbenc; +Cc: netdev, tgraf, pshelar, simon.horman

From: Jiri Benc <jbenc@redhat.com>
Date: Tue,  3 May 2016 17:10:05 +0200

> NOTE: this patchset needs net merged to net-next.

Noted.

> This allows lwtunnel users to get also packets with ETH_P_TEB protocol
> specified in GRE header through an ipgre interface. There's really nothing
> special about these packets in the case of lwtunnels - it's just an inner
> protocol like any other. The only complications stem from keeping
> compatibility with other uses of GRE.
> 
> This will be used by openvswitch to support eth_push and eth_pop actions.
> I'd also like to see tc support for lwtunnels (this feature included) in the
> future.
> 
> The first patch is not directly related and can be submitted standalone if
> needed.

Series applied, thanks Jiri.

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

end of thread, other threads:[~2016-05-04 18:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-03 15:10 [PATCH net-next 0/3] gre: receive also TEB packets for lwtunnels Jiri Benc
2016-05-03 15:10 ` [PATCH net-next 1/3] gre: remove superfluous pskb_may_pull Jiri Benc
2016-05-03 15:10 ` [PATCH net-next 2/3] gre: move iptunnel_pull_header down to ipgre_rcv Jiri Benc
2016-05-03 15:10 ` [PATCH net-next 3/3] gre: receive also TEB packets for lwtunnels Jiri Benc
2016-05-04  7:52 ` [PATCH net-next 0/3] " Simon Horman
2016-05-04 18:11 ` David Miller

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