Skip to contentSkip to conversation

tou: Transports over UDP - part I

RFC PATCH In review Tom Herbert 5 participants 15 messages May 23, 2016 – May 26, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover tou: Transports over UDP - part I

Transports over UDP is intended to encapsulate TCP and other transport protocols directly and securely in UDP.

The goal of this work is twofold:

1) Allow applications to run their own transport layer stack (i.e.from userspace). This eliminates dependencies on the OS (e.g. solves a major dependency issue for Facebook on clients).

2) Make transport layer headers (all of L4) invisible to the network so that they can't do intrusive actions at L4. This will be enforced with DTLS in use.

Note that #1 is really about running a transport stack in userspace applications in clients, not necessarily servers. For servers we intend to modified the kernel stack in order to leverage existing implementation for building scalable serves (hence these patches).

This is described in more detail in the Internet Draft:
https://tools.ietf.org/html/draft-herbert-transports-over-udp-00

In Part I we implement a straightforward encapsulation of TCP in GUE. The implements the basic mechanics of TOU encapsulation for TCP, however does not yet implement the IP addressing interactions so therefore so this is not robust to use in the presence of NAT. TOU is enabled per socket with a new socket option. This implementation includes GSO, GRO, and RCO support.

These patches also establish the baseline performance of TOU and isolate the performance cost of UDP encapsulation. Performance results are below.

Tested: Various cases of TOU with IPv4, IPv6 using TCP_STREAM and TCP_RR. Also, tested IPIP for comparing TOU encapsulation to IP tunneling.

    - IPv6 native
      1 TCP_STREAM
	8394 tps
      200 TCP_RR
	1726825 tps
	100/177/361 90/95/99% latencies

    - IPv6 TOU with RCO
      1 TCP_STREAM
	7410 tps
      200 TCP_RR
	1445603 tps
	121/211/395 90/95/99% latencies

    - IPv4 native
      1 TCP_STREAM
	8525 tps
      200 TCP_RR
	1826729 tps
	94/166/345 90/95/99% latencies

    - IPv4 TOU with RCO
      1 TCP_STREAM
	7624 tps
      200 TCP_RR
	1599642 tps
	108/190/377 90/95/99% latencies

    - IPIP with GUE and RCO
      1 TCP_STREAM
	5092 tps
      200 TCP_RR
	1276716 tps
	137/237/445 90/95/99% latencies

Tom Herbert (7):
fou: Get net from sock_net if dev_net unavailable
tou: Base infrastructure for Transport over UDP
ipv4: Support TOU
tcp: Support for TOU
ipv6: Support TOU
tcp6: Support for TOU
tou: Support for GSO

 include/linux/skbuff.h           |   2 +
 include/net/inet_sock.h          |   1 +
 include/net/udp.h                |   2 +
 include/uapi/linux/if_tunnel.h   |  10 +++
 include/uapi/linux/in.h          |   1 +
 include/uapi/linux/in6.h         |   1 +
 net/ipv4/Makefile                |   3 +-
 net/ipv4/af_inet.c               |   4 +
 net/ipv4/fou.c                   |  24 +++++-
 net/ipv4/ip_output.c             |  42 ++++++++--
 net/ipv4/ip_sockglue.c           |   7 ++
 net/ipv4/tcp_ipv4.c              |   9 ++-
 net/ipv4/tou.c                   | 132 +++++++++++++++++++++++++++++++
 net/ipv4/udp_offload.c           | 164 +++++++++++++++++++++++++++++++++++++--
 net/ipv6/inet6_connection_sock.c |  59 ++++++++++++--
 net/ipv6/ipv6_sockglue.c         |   7 ++
 net/ipv6/tcp_ipv6.c              |  11 +--
 net/ipv6/udp_offload.c           | 128 +++++++++++++++---------------
 18 files changed, 512 insertions(+), 95 deletions(-)
 create mode 100644 net/ipv4/tou.c
Signature · 1 line
2.8.0.rc2
#4 lore raw

RFC PATCH 2/7 tou: Base infrastructure for Transport over UDP

Add tou.c that implements common setsockopt functionality. This includes initialization and argument structure for the setsockopt.

---
 include/uapi/linux/if_tunnel.h |  10 ++++
 net/ipv4/Makefile              |   3 +-
 net/ipv4/af_inet.c             |   4 ++
 net/ipv4/tou.c                 | 132 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 net/ipv4/tou.c
include/uapi/linux/if_tunnel.h +10 -0
index af4de90..c6b4afa 100644
@@ -71,6 +71,16 @@ enum tunnel_encap_types {
 #define TUNNEL_ENCAP_FLAG_CSUM6		(1<<1)
 #define TUNNEL_ENCAP_FLAG_REMCSUM	(1<<2)
 
+/* Structure for Transport Over UDP (TOU) encapsulation. This is used in
+ * setsockopt of inet sockets.
+ */
+struct tou_encap {
+	u16			type; /* enum tunnel_encap_types */
+	u16			flags;
+	__be16			sport;
+	__be16			dport;
+};
+
 /* SIT-mode i_flags */
 #define	SIT_ISATAP	0x0001
 
net/ipv4/Makefile +2 -1
index bfa1336..3b46dd6 100644
@@ -12,7 +12,8 @@ obj-y     := route.o inetpeer.o protocol.o \
 	     tcp_offload.o datagram.o raw.o udp.o udplite.o \
 	     udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
 	     fib_frontend.o fib_semantics.o fib_trie.o \
-	     inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o
+	     inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \
+	     tou.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/af_inet.c +4 -0
index 377424e..7a856f8 100644
@@ -120,6 +120,7 @@
 #include <linux/mroute.h>
 #endif
 #include <net/l3mdev.h>
+#include <net/tou.h>
 
 
 /* The inetsw table contains everything that inet_create needs to
@@ -1822,6 +1823,9 @@ static int __init inet_init(void)
 	/* Add UDP-Lite (RFC 3828) */
 	udplite4_register();
 
+	/* Set TOU slab cache (Transport layer encapsulation over UDP) */
+	tou_init();
+
 	ping_init();
 
 	/*
net/ipv4/tou.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.8.0.rc2
#6 lore raw

RFC PATCH 3/7 ipv4: Support TOU

In reply to Tom Herbert

Add tou_encap structure to inet_sock. In transmit path (ip_queue_xmit) check if encapsulation is enabled and call the build header op if it is. Add IP_TOU_ENCAP setsockopt for IPv4 sockets.

---
 include/net/inet_sock.h |  1 +
 include/uapi/linux/in.h |  1 +
 net/ipv4/ip_output.c    | 40 ++++++++++++++++++++++++++++++++++------
 net/ipv4/ip_sockglue.c  |  7 +++++++
 net/ipv4/tou.c          |  2 +-
 5 files changed, 44 insertions(+), 7 deletions(-)
include/net/inet_sock.h +1 -0
index 012b1f9..ce22bc9 100644
@@ -209,6 +209,7 @@ struct inet_sock {
 	__be32			mc_addr;
 	struct ip_mc_socklist __rcu	*mc_list;
 	struct inet_cork_full	cork;
+	struct ip_tunnel_encap	*tou_encap;
 };
 
 #define IPCORK_OPT	1	/* ip-options has been held in ipcork.opt */
include/uapi/linux/in.h +1 -0
index eaf9491..9827bff 100644
@@ -152,6 +152,7 @@ struct in_addr {
 #define MCAST_MSFILTER			48
 #define IP_MULTICAST_ALL		49
 #define IP_UNICAST_IF			50
+#define IP_TOU_ENCAP			51
 
 #define MCAST_EXCLUDE	0
 #define MCAST_INCLUDE	1
net/ipv4/ip_output.c +34 -6
index 124bf0a..e7dbded 100644
@@ -78,6 +78,7 @@
 #include <linux/netfilter_bridge.h>
 #include <linux/netlink.h>
 #include <linux/tcp.h>
+#include <net/ip_tunnels.h>
 
 static int
 ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
@@ -382,11 +383,36 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
 	struct rtable *rt;
 	struct iphdr *iph;
 	int res;
+	__be16 dport, sport;
+	u8 protocol = sk->sk_protocol;
 
 	/* Skip all of this if the packet is already routed,
 	 * f.e. by something like SCTP.
 	 */
 	rcu_read_lock();
+
+	if (inet->tou_encap) {
+		struct ip_tunnel_encap *e = inet->tou_encap;
+		const struct ip_tunnel_encap_ops *ops;
+
+		/* Transport layer protocol over UDP enapsulation */
+		dport = e->dport;
+		sport = e->sport;
+		ops = rcu_dereference(iptun_encaps[e->type]);
+		if (likely(ops && ops->build_header)) {
+			res = ops->build_header(skb, e, &protocol,
+						(struct flowi4 *)fl);
+			if (res < 0)
+				goto fail;
+		} else {
+			res = -EINVAL;
+			goto fail;
+		}
+	} else {
+		dport = inet->inet_dport;
+		sport = inet->inet_sport;
+	}
+
 	inet_opt = rcu_dereference(inet->inet_opt);
 	fl4 = &fl->u.ip4;
 	rt = skb_rtable(skb);
@@ -409,9 +435,9 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
 		 */
 		rt = ip_route_output_ports(net, fl4, sk,
 					   daddr, inet->inet_saddr,
-					   inet->inet_dport,
-					   inet->inet_sport,
-					   sk->sk_protocol,
+					   dport,
+					   sport,
+					   protocol,
 					   RT_CONN_FLAGS(sk),
 					   sk->sk_bound_dev_if);
 		if (IS_ERR(rt))
@@ -434,7 +460,7 @@ packet_routed:
 	else
 		iph->frag_off = 0;
 	iph->ttl      = ip_select_ttl(inet, &rt->dst);
-	iph->protocol = sk->sk_protocol;
+	iph->protocol = protocol;
 	ip_copy_addrs(iph, fl4);
 
 	/* Transport layer set skb->h.foo itself. */
@@ -456,10 +482,12 @@ packet_routed:
 	return res;
 
 no_route:
-	rcu_read_unlock();
 	IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
+	res = -EHOSTUNREACH;
+fail:
+	rcu_read_unlock();
 	kfree_skb(skb);
-	return -EHOSTUNREACH;
+	return res;
 }
 EXPORT_SYMBOL(ip_queue_xmit);
 
net/ipv4/ip_sockglue.c +7 -0
index 71a52f4..0c9d3f0 100644
@@ -42,6 +42,7 @@
 #include <net/transp_v6.h>
 #endif
 #include <net/ip_fib.h>
+#include <net/tou.h>
 
 #include <linux/errqueue.h>
 #include <asm/uaccess.h>
@@ -1162,6 +1163,10 @@ mc_msf_out:
 		inet->min_ttl = val;
 		break;
 
+	case IP_TOU_ENCAP:
+		err = tou_encap_setsockopt(sk, optval, optlen, false);
+		break;
+
 	default:
 		err = -ENOPROTOOPT;
 		break;
@@ -1493,6 +1498,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
 	case IP_MINTTL:
 		val = inet->min_ttl;
 		break;
+	case IPV6_TOU_ENCAP:
+		return tou_encap_getsockopt(sk, optval, len, optlen, false);
 	default:
 		release_sock(sk);
 		return -ENOPROTOOPT;
net/ipv4/tou.c +1 -1
index 601466a..bbb44b6 100644
@@ -61,7 +61,7 @@ int tou_encap_setsockopt(struct sock *sk, char __user *optval, int optlen,
 	encap.dport = te.dport;
 	encap.flags = te.flags;
 
-	hlen = is_ipv6 ? ip6_encap_hlen(e) : ip_encap_hlen(e);
+	hlen = is_ipv6 ? ip6_encap_hlen(&encap) : ip_encap_hlen(&encap);
 	if (hlen < 0)
 		return hlen;
 
Signature · 1 line
2.8.0.rc2
#9 lore raw

RFC PATCH 5/7 ipv6: Support TOU

In reply to Tom Herbert

In transmit path (inet6_csk_xmit) check if encapsulation is enabled and call the build header op if it is. Add IP_TOU_ENCAP setsockopt for IPv6 sockets.

---
 include/uapi/linux/in6.h         |  1 +
 net/ipv6/inet6_connection_sock.c | 56 ++++++++++++++++++++++++++++++++++------
 net/ipv6/ipv6_sockglue.c         |  7 +++++
 3 files changed, 56 insertions(+), 8 deletions(-)
include/uapi/linux/in6.h +1 -0
index 318a482..9a610c3 100644
@@ -282,6 +282,7 @@ struct in6_flowlabel_req {
 #define IPV6_RECVORIGDSTADDR    IPV6_ORIGDSTADDR
 #define IPV6_TRANSPARENT        75
 #define IPV6_UNICAST_IF         76
+#define IPV6_TOU_ENCAP		77
 
 /*
  * Multicast Routing:
net/ipv6/inet6_connection_sock.c +48 -8

107 lines not on this page · raw message

net/ipv6/ipv6_sockglue.c +7 -0
index a9895e1..1697c0e 100644
@@ -52,6 +52,7 @@
 #include <net/udplite.h>
 #include <net/xfrm.h>
 #include <net/compat.h>
+#include <net/tou.h>
 
 #include <asm/uaccess.h>
 
@@ -868,6 +869,9 @@ pref_skip_coa:
 		np->autoflowlabel = valbool;
 		retv = 0;
 		break;
+	case IPV6_TOU_ENCAP:
+		retv = tou_encap_setsockopt(sk, optval, optlen, true);
+		break;
 	}
 
 	release_sock(sk);
@@ -1310,6 +1314,9 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
 		val = np->autoflowlabel;
 		break;
 
+	case IPV6_TOU_ENCAP:
+		return tou_encap_getsockopt(sk, optval, len, optlen, true);
+
 	default:
 		return -ENOPROTOOPT;
 	}
Signature · 1 line
2.8.0.rc2
#1 lore raw

RFC PATCH 1/7 fou: Get net from sock_net if dev_net unavailable

In reply to Tom Herbert

With the implementation of Transports over UDP fou and gue build header may be called before skb->dev is set. This patch checks skb->dev and if it is not set then tries to get net from sock_net.

---
 net/ipv4/fou.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
net/ipv4/fou.c +18 -4
index 5f9207c..96260c6 100644
@@ -807,13 +807,20 @@ int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
 		       u8 *protocol, __be16 *sport, int type)
 {
 	int err;
+	struct net *net;
 
 	err = iptunnel_handle_offloads(skb, type);
 	if (err)
 		return err;
 
-	*sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-						skb, 0, 0, false);
+	if (skb->dev)
+		net = dev_net(skb->dev);
+	else if (skb->sk)
+		net = sock_net(skb->sk);
+	else
+		return -EINVAL;
+
+	*sport = e->sport ? : udp_flow_src_port(net, skb, 0, 0, false);
 
 	return 0;
 }
@@ -845,6 +852,14 @@ int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
 	void *data;
 	bool need_priv = false;
 	int err;
+	struct net *net;
+
+	if (skb->dev)
+		net = dev_net(skb->dev);
+	else if (skb->sk)
+		net = sock_net(skb->sk);
+	else
+		return -EINVAL;
 
 	if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) &&
 	    skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -860,8 +875,7 @@ int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
 		return err;
 
 	/* Get source port (based on flow hash) before skb_push */
-	*sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-						skb, 0, 0, false);
+	*sport = e->sport ? : udp_flow_src_port(net, skb, 0, 0, false);
 
 	hdrlen = sizeof(struct guehdr) + optlen;
 
Signature · 1 line
2.8.0.rc2
#11 lore raw

RFC PATCH 7/7 tou: Support for GSO

In reply to Tom Herbert

Add SKB_GSO_TOU. In udp[64]_ufo_fragment check for SKB_GSO_TOU. If this is set call skb_udp_tou_segment. skb_udp_tou_segment is very similar to skb_udp_tunnel_segment except that we only need to deal with the L4 headers.

---
 include/linux/skbuff.h           |   2 +
 include/net/udp.h                |   2 +
 net/ipv4/fou.c                   |   2 +
 net/ipv4/ip_output.c             |   2 +
 net/ipv4/udp_offload.c           | 164 +++++++++++++++++++++++++++++++++++++--
 net/ipv6/inet6_connection_sock.c |   3 +
 net/ipv6/udp_offload.c           | 128 +++++++++++++++---------------
 7 files changed, 236 insertions(+), 67 deletions(-)
include/linux/skbuff.h +2 -0
index 65968a9..b57e484 100644
@@ -482,6 +482,8 @@ enum {
 	SKB_GSO_PARTIAL = 1 << 13,
 
 	SKB_GSO_TUNNEL_REMCSUM = 1 << 14,
+
+	SKB_GSO_TOU = 1 << 15,
 };
 
 #if BITS_PER_LONG > 32
include/net/udp.h +2 -0
index ae07f37..4423234 100644
@@ -262,6 +262,8 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait);
 struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb,
 				       netdev_features_t features,
 				       bool is_ipv6);
+struct sk_buff *skb_udp_tou_segment(struct sk_buff *skb,
+				    netdev_features_t features, bool is_ipv6);
 int udp_lib_getsockopt(struct sock *sk, int level, int optname,
 		       char __user *optval, int __user *optlen);
 int udp_lib_setsockopt(struct sock *sk, int level, int optname,
net/ipv4/fou.c +2 -0
index 96260c6..1855fc2f 100644
@@ -381,6 +381,8 @@ static struct sk_buff **gue_gro_receive(struct sock *sk,
 	/* Flag this frame as already having an outer encap header */
 	NAPI_GRO_CB(skb)->is_fou = 1;
 
+	skb_set_transport_header(skb, skb_gro_offset(skb));
+
 	rcu_read_lock();
 	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
 	ops = rcu_dereference(offloads[guehdr->proto_ctype]);
net/ipv4/ip_output.c +2 -0
index e7dbded..922c09c 100644
@@ -408,6 +408,8 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
 			res = -EINVAL;
 			goto fail;
 		}
+		skb_shinfo(skb)->gso_type |= SKB_GSO_TOU;
+		skb_set_inner_ipproto(skb, sk->sk_protocol);
 	} else {
 		dport = inet->inet_dport;
 		sport = inet->inet_sport;
net/ipv4/udp_offload.c +159 -5

176 lines not on this page · raw message

net/ipv6/inet6_connection_sock.c +3 -0
index 5f2df4f..3b8b2f4 100644
@@ -187,6 +187,9 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused
 			goto fail;
 		}
 
+		skb_shinfo(skb)->gso_type |= SKB_GSO_TOU;
+		skb_set_inner_ipproto(skb, sk->sk_protocol);
+
 		/* Changing ports and protocol to be routed */
 		fl6.fl6_sport = e->sport;
 		fl6.fl6_dport = e->dport;
net/ipv6/udp_offload.c +66 -62

146 lines not on this page · raw message

Signature · 1 line
2.8.0.rc2
#8 lore raw

RFC PATCH 4/7 tcp: Support for TOU

In reply to Tom Herbert

Need to adjust MSS to account for encapsulation overhead. This is done by add encpasulation header length into icsk_ext_hdr_len.

---
 net/ipv4/tcp_ipv4.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
net/ipv4/tcp_ipv4.c +5 -4
index 3708de2..c344f667 100644
@@ -74,6 +74,7 @@
 #include <net/xfrm.h>
 #include <net/secure_seq.h>
 #include <net/busy_poll.h>
+#include <net/tou.h>
 
 #include <linux/inet.h>
 #include <linux/ipv6.h>
@@ -205,9 +206,9 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	inet->inet_dport = usin->sin_port;
 	sk_daddr_set(sk, daddr);
 
-	inet_csk(sk)->icsk_ext_hdr_len = 0;
+	inet_csk(sk)->icsk_ext_hdr_len = tou_hdr_len(sk);
 	if (inet_opt)
-		inet_csk(sk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
+		inet_csk(sk)->icsk_ext_hdr_len += inet_opt->opt.optlen;
 
 	tp->rx_opt.mss_clamp = TCP_MSS_DEFAULT;
 
@@ -1296,9 +1297,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
 	newinet->mc_index     = inet_iif(skb);
 	newinet->mc_ttl	      = ip_hdr(skb)->ttl;
 	newinet->rcv_tos      = ip_hdr(skb)->tos;
-	inet_csk(newsk)->icsk_ext_hdr_len = 0;
+	inet_csk(sk)->icsk_ext_hdr_len = tou_hdr_len(sk);
 	if (inet_opt)
-		inet_csk(newsk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
+		inet_csk(newsk)->icsk_ext_hdr_len += inet_opt->opt.optlen;
 	newinet->inet_id = newtp->write_seq ^ jiffies;
 
 	if (!dst) {
Signature · 1 line
2.8.0.rc2
#10 lore raw

RFC PATCH 6/7 tcp6: Support for TOU

In reply to Tom Herbert

Need to adjust MSS to account for encapsulation overhead. This is done by add encpasulation header length into icsk_ext_hdr_len.

---
 net/ipv6/tcp_ipv6.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/ipv6/tcp_ipv6.c +6 -5
index 79e33e0..6a3c2e7 100644
@@ -62,6 +62,7 @@
 #include <net/inet_common.h>
 #include <net/secure_seq.h>
 #include <net/busy_poll.h>
+#include <net/tou.h>
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
@@ -210,7 +211,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 		err = tcp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin));
 
 		if (err) {
-			icsk->icsk_ext_hdr_len = exthdrlen;
+			icsk->icsk_ext_hdr_len = tou_hdr_len(sk) + exthdrlen;
 			icsk->icsk_af_ops = &ipv6_specific;
 			sk->sk_backlog_rcv = tcp_v6_do_rcv;
 #ifdef CONFIG_TCP_MD5SIG
@@ -262,9 +263,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	    ipv6_addr_equal(&fl6.daddr, &sk->sk_v6_daddr))
 		tcp_fetch_timewait_stamp(sk, dst);
 
-	icsk->icsk_ext_hdr_len = 0;
+	icsk->icsk_ext_hdr_len = tou_hdr_len(sk);
 	if (opt)
-		icsk->icsk_ext_hdr_len = opt->opt_flen +
+		icsk->icsk_ext_hdr_len += opt->opt_flen +
 					 opt->opt_nflen;
 
 	tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
@@ -1114,9 +1115,9 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
 		opt = ipv6_dup_options(newsk, opt);
 		RCU_INIT_POINTER(newnp->opt, opt);
 	}
-	inet_csk(newsk)->icsk_ext_hdr_len = 0;
+	inet_csk(newsk)->icsk_ext_hdr_len = tou_hdr_len(sk);
 	if (opt)
-		inet_csk(newsk)->icsk_ext_hdr_len = opt->opt_nflen +
+		inet_csk(newsk)->icsk_ext_hdr_len += opt->opt_nflen +
 						    opt->opt_flen;
 
 	tcp_ca_openreq_child(newsk, dst);
Signature · 1 line
2.8.0.rc2
#7 lore raw

Re: [RFC PATCH 3/7] ipv4: Support TOU

In reply to Tom Herbert

On Mon, 2016-05-23 at 15:48 -0700, Tom Herbert wrote:

...

Quoted 6 lines

static int
ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,

net/ipv4/ip_output.c +0 -0
@@ -382,11 +383,36 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
 	struct rtable *rt;
 	struct iphdr *iph;
 	int res;

net/ipv4/ip_output.c int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl) · line 395

Quoted 10 lines
net/ipv4/ip_output.c +5 -0
+	__be16 dport, sport;
+	u8 protocol = sk->sk_protocol;
 
 	/* Skip all of this if the packet is already routed,
 	 * f.e. by something like SCTP.
 	 */
 	rcu_read_lock();
+
+	if (inet->tou_encap) {
+		struct ip_tunnel_encap *e = inet->tou_encap;

You seem to rely on RCU, in spirit at least.

But ...

1) You read inet->tou_encap twice, so the second time could read a NULL and then crash on a NULL dereference.

2) No RCU grace period is respected in tou_encap_setsockopt(), so use after free is possible.

Quoted 7 lines
net/ipv4/ip_output.c +5 -0
+		const struct ip_tunnel_encap_ops *ops;
+
+		/* Transport layer protocol over UDP enapsulation */
 
 
+		dport = e->dport;
+		sport = e->sport;
#12 lore raw

Re: [RFC PATCH 7/7] tou: Support for GSO

In reply to Tom Herbert
Quoted 21 lines · Tom Herbert

Add SKB_GSO_TOU. In udp[64]_ufo_fragment check for SKB_GSO_TOU. If this is set call skb_udp_tou_segment. skb_udp_tou_segment is very similar to skb_udp_tunnel_segment except that we only need to deal with the L4 headers.

---
 include/linux/skbuff.h           |   2 +
 include/net/udp.h                |   2 +
 net/ipv4/fou.c                   |   2 +
 net/ipv4/ip_output.c             |   2 +
 net/ipv4/udp_offload.c           | 164 +++++++++++++++++++++++++++++++++++++--
 net/ipv6/inet6_connection_sock.c |   3 +
 net/ipv6/udp_offload.c           | 128 +++++++++++++++---------------
 7 files changed, 236 insertions(+), 67 deletions(-)
include/linux/skbuff.h +0 -0
index 65968a9..b57e484 100644

include/linux/skbuff.h enum { · line 488

Quoted 7 lines
include/linux/skbuff.h +2 -0
@@ -482,6 +482,8 @@ enum {
        SKB_GSO_PARTIAL = 1 << 13,
 
        SKB_GSO_TUNNEL_REMCSUM = 1 << 14,
+
+       SKB_GSO_TOU = 1 << 15,
 };
 

So where do you add the netdev feature bit? From what I can tell that was overlooked and as a result devices that support FCoE CRC will end up corrupting TOU frames because netif_gso_ok currently ands the two together.

Also I am pretty sure we can offload this on the Intel NICs using the GSO partial approach as we can just stuff the UDP header into the space that we would use for IPv4 options or IPv6 extension headers and it shouldn't complain.

- Alex

#13 lore raw

Re: [RFC PATCH 7/7] tou: Support for GSO

Quoted 24 lines · Alexander Duyck
Quoted 23 lines · Tom Herbert

Add SKB_GSO_TOU. In udp[64]_ufo_fragment check for SKB_GSO_TOU. If this is set call skb_udp_tou_segment. skb_udp_tou_segment is very similar to skb_udp_tunnel_segment except that we only need to deal with the L4 headers.

---
 include/linux/skbuff.h           |   2 +
 include/net/udp.h                |   2 +
 net/ipv4/fou.c                   |   2 +
 net/ipv4/ip_output.c             |   2 +
 net/ipv4/udp_offload.c           | 164 +++++++++++++++++++++++++++++++++++++--
 net/ipv6/inet6_connection_sock.c |   3 +
 net/ipv6/udp_offload.c           | 128 +++++++++++++++---------------
 7 files changed, 236 insertions(+), 67 deletions(-)
include/linux/skbuff.h +0 -0
index 65968a9..b57e484 100644
@@ -482,6 +482,8 @@ enum {
        SKB_GSO_PARTIAL = 1 << 13,
 
Quoted 11 lines

include/linux/skbuff.h enum { · line 488

Quoted 5 lines
include/linux/skbuff.h +2 -0
        SKB_GSO_TUNNEL_REMCSUM = 1 << 14,
+
+       SKB_GSO_TOU = 1 << 15,
 };
 

So where do you add the netdev feature bit? From what I can tell that was overlooked and as a result devices that support FCoE CRC will end up corrupting TOU frames because netif_gso_ok currently ands the two together.

An obvious omission, thanks for pointing it out.

Quoted 5 lines

Also I am pretty sure we can offload this on the Intel NICs using the GSO partial approach as we can just stuff the UDP header into the space that we would use for IPv4 options or IPv6 extension headers and it shouldn't complain.

That would be cool!

Quoted 1 line

- Alex

maintainer
#2 lore raw

Re: [RFC PATCH 1/7] fou: Get net from sock_net if dev_net unavailable

In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Mon, 23 May 2016 15:48:20 -0700

net/ipv4/fou.c int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, · line 811

Quoted 10 lines
net/ipv4/fou.c +1 -0
index 5f9207c..96260c6 100644
@@ -807,13 +807,20 @@ int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
 		       u8 *protocol, __be16 *sport, int type)
 {
 	int err;
+	struct net *net;
 

Please order local variables from longest to shortest line.

net/ipv4/fou.c int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, · line 819

Quoted 10 lines
net/ipv4/fou.c +4 -2
 	err = iptunnel_handle_offloads(skb, type);
 	if (err)
 		return err;
 
-	*sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-						skb, 0, 0, false);
+	if (skb->dev)
+		net = dev_net(skb->dev);
+	else if (skb->sk)
+		net = sock_net(skb->sk);

This is getting rediculous. Why not just put the net namespace pointer into the tunnel encap object?

maintainer
#5 lore raw

Re: [RFC PATCH 2/7] tou: Base infrastructure for Transport over UDP

In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Mon, 23 May 2016 15:48:21 -0700

net/ipv4/tou.c line 29

Quoted 7 lines
net/ipv4/tou.c new file +7 -0
+int tou_encap_setsockopt(struct sock *sk, char __user *optval, int optlen,
+			 bool is_ipv6)
+{
+	struct tou_encap te;
+	struct ip_tunnel_encap encap;
+	struct inet_sock *inet = inet_sk(sk);
+	struct ip_tunnel_encap *e = inet->tou_encap;

This doesn't compile, because you don't add the tou_encap member to inet_sock until patch #3.

#3 lore raw

Re: [RFC PATCH 1/7] fou: Get net from sock_net if dev_net unavailable

In reply to David Miller
Quoted 27 lines · David Miller

From: Tom Herbert <[email protected]>
Date: Mon, 23 May 2016 15:48:20 -0700

net/ipv4/fou.c int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, · line 811

Quoted 10 lines
net/ipv4/fou.c +1 -0
index 5f9207c..96260c6 100644
@@ -807,13 +807,20 @@ int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
                     u8 *protocol, __be16 *sport, int type)
 {
      int err;
+     struct net *net;
 

Please order local variables from longest to shortest line.

net/ipv4/fou.c int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, · line 819

Quoted 10 lines
net/ipv4/fou.c +4 -2
      err = iptunnel_handle_offloads(skb, type);
      if (err)
              return err;
 
-     *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
-                                             skb, 0, 0, false);
+     if (skb->dev)
+             net = dev_net(skb->dev);
+     else if (skb->sk)
+             net = sock_net(skb->sk);
Quoted 2 lines

This is getting rediculous. Why not just put the net namespace pointer into the tunnel encap object?

Thanks, in this case it will be easier to just pass net in as an argument.

Tom

#14 lore raw
In reply to Tom Herbert
Quoted 6 lines · Tom Herbert <tom <at> herbertland.com> writes:

Transports over UDP is intended to encapsulate TCP and other transport protocols directly and securely in UDP.

The goal of this work is twofold:

Quoted 7 lines

1) Allow applications to run their own transport layer stack (i.e.from userspace). This eliminates dependencies on the OS (e.g. solves a major dependency issue for Facebook on clients).

2) Make transport layer headers (all of L4) invisible to the network so that they can't do intrusive actions at L4. This will be enforced with DTLS in use.

Just popping in to note that this has significant similarities with the DeDiS group's Tng project[1], which takes the approach of splitting the "transport layer" into four sub-layers:

1.) Endpoint (What port?)
2.) Flow (Congestion control)
3.) Isolation (Integrity, confidentiality, and preventing middlebox mangling) 4.) Semantic (End-to-end guarantees, fate-sharing, stream vs. dgram vs. seqpacket, etc)

[1] http://dedis.cs.yale.edu/2009/tng/