Skip to contentSkip to conversation

tcp: Register handlers for extra TCP options

PATCH Superseded Mat Martineau 3 participants 12 messages Apr 21, 2017 – Apr 29, 2017

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mat Martineau

author
#0 lore raw

PATCH 1/1 tcp: Register handlers for extra TCP options

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 drivers/infiniband/hw/cxgb4/cm.c |   2 +-
 include/linux/tcp.h              |  17 +++++
 include/net/tcp.h                |  48 +++++++++++++-
 net/ipv4/syncookies.c            |   2 +-
 net/ipv4/tcp.c                   | 135 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_input.c             |  15 +++--
 net/ipv4/tcp_minisocks.c         |   4 +-
 net/ipv4/tcp_output.c            |  35 +++++-----
 net/ipv6/syncookies.c            |   2 +-
 9 files changed, 232 insertions(+), 28 deletions(-)
drivers/infiniband/hw/cxgb4/cm.c +1 -1
index 03a1b0e64fc3..1d1dbfdf5a05 100644
@@ -3748,7 +3748,7 @@ static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
 	 */
 	memset(&tmp_opt, 0, sizeof(tmp_opt));
 	tcp_clear_options(&tmp_opt);
-	tcp_parse_options(skb, &tmp_opt, 0, NULL);
+	tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 	req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
 	memset(req, 0, sizeof(*req));
include/linux/tcp.h +17 -0
index cfc2d9506ce8..9e625a68f5e1 100644
@@ -112,6 +112,23 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 	rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
 }
 
+#define OPTION_SACK_ADVERTISE	(1 << 0)
+#define OPTION_TS		(1 << 1)
+#define OPTION_MD5		(1 << 2)
+#define OPTION_WSCALE		(1 << 3)
+#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
+
+struct tcp_out_options {
+	u16 options;		/* bit field of OPTION_* */
+	u16 mss;		/* 0 to disable */
+	u8 ws;			/* window scale, 0 to disable */
+	u8 num_sack_blocks;	/* number of SACK blocks to include */
+	u8 hash_size;		/* bytes in hash_location */
+	__u8 *hash_location;	/* temporary pointer, overloaded */
+	__u32 tsval, tsecr;	/* need to include OPTION_TS */
+	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
+};
+
 /* This is the max number of SACKS that we'll generate and process. It's safe
  * to increase this, although since:
  *   size = TCPOLEN_SACK_BASE_ALIGNED (4) + n * TCPOLEN_SACK_PERBLOCK (8)
include/net/tcp.h +47 -1

58 lines not on this page · raw message

net/ipv4/syncookies.c +1 -1
index 496b97e17aaf..5697083a2c77 100644
@@ -309,7 +309,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
net/ipv4/tcp.c +135 -0

159 lines not on this page · raw message

net/ipv4/tcp_input.c +10 -5
index a5838858c362..13ab3dff7c3f 100644
@@ -3726,7 +3726,7 @@ static void tcp_parse_fastopen_option(int len, const unsigned char *cookie,
  */
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx, int estab,
-		       struct tcp_fastopen_cookie *foc)
+		       struct tcp_fastopen_cookie *foc, struct tcp_sock *tp)
 {
 	const unsigned char *ptr;
 	const struct tcphdr *th = tcp_hdr(skb);
@@ -3828,6 +3828,11 @@ void tcp_parse_options(const struct sk_buff *skb,
 						ptr + 2, th->syn, foc, true);
 				break;
 
+			default:
+				tcp_extra_options_parse(opcode, opsize, ptr,
+							skb, opt_rx, tp);
+				break;
+
 			}
 			ptr += opsize-2;
 			length -= opsize;
@@ -3873,7 +3878,7 @@ static bool tcp_fast_parse_options(const struct sk_buff *skb,
 			return true;
 	}
 
-	tcp_parse_options(skb, &tp->rx_opt, 1, NULL);
+	tcp_parse_options(skb, &tp->rx_opt, 1, NULL, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -5600,7 +5605,7 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,
 		/* Get original SYNACK MSS value if user MSS sets mss_clamp */
 		tcp_clear_options(&opt);
 		opt.user_mss = opt.mss_clamp = 0;
-		tcp_parse_options(synack, &opt, 0, NULL);
+		tcp_parse_options(synack, &opt, 0, NULL, tp);
 		mss = opt.mss_clamp;
 	}
 
@@ -5653,7 +5658,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 	struct tcp_fastopen_cookie foc = { .len = -1 };
 	int saved_clamp = tp->rx_opt.mss_clamp;
 
-	tcp_parse_options(skb, &tp->rx_opt, 0, &foc);
+	tcp_parse_options(skb, &tp->rx_opt, 0, &foc, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -6316,7 +6321,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
 	tmp_opt.user_mss  = tp->rx_opt.user_mss;
-	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc);
+	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc, tp);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
net/ipv4/tcp_minisocks.c +2 -2
index 8f6373b0cd77..c51bb1b30f08 100644
@@ -98,7 +98,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			if (tmp_opt.rcv_tsecr)
@@ -558,7 +558,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(struct tcphdr)>>2)) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent = req->ts_recent;
net/ipv4/tcp_output.c +18 -17
index ffc9274b2706..840883531996 100644
@@ -41,6 +41,7 @@
 #include <linux/compiler.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
+#include <linux/static_key.h>
 
 /* People can turn this off for buggy TCP's found in printers etc. */
 int sysctl_tcp_retrans_collapse __read_mostly = 1;
@@ -411,23 +412,6 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
 	return tp->snd_una != tp->snd_up;
 }
 
-#define OPTION_SACK_ADVERTISE	(1 << 0)
-#define OPTION_TS		(1 << 1)
-#define OPTION_MD5		(1 << 2)
-#define OPTION_WSCALE		(1 << 3)
-#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
-
-struct tcp_out_options {
-	u16 options;		/* bit field of OPTION_* */
-	u16 mss;		/* 0 to disable */
-	u8 ws;			/* window scale, 0 to disable */
-	u8 num_sack_blocks;	/* number of SACK blocks to include */
-	u8 hash_size;		/* bytes in hash_location */
-	__u8 *hash_location;	/* temporary pointer, overloaded */
-	__u32 tsval, tsecr;	/* need to include OPTION_TS */
-	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
-};
-
 /* Write previously computed TCP options to the packet.
  *
  * Beware: Something in the Internet is very sensitive to the ordering of
@@ -534,6 +518,9 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
 		}
 		ptr += (len + 3) >> 2;
 	}
+
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		tcp_extra_options_write(ptr, opts, tp);
 }
 
 /* Compute TCP options for SYN packets. This is not the final
@@ -601,6 +588,10 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare(skb, TCPHDR_SYN,
+						       remaining, opts, tp);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -661,6 +652,13 @@ static unsigned int tcp_synack_options(struct request_sock *req,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare_req(skb,
+							   TCPHDR_SYN |
+							   TCPHDR_ACK,
+							   remaining, opts,
+							   req);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -694,6 +692,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		size += TCPOLEN_TSTAMP_ALIGNED;
 	}
 
+	size += tcp_extra_options_prepare(skb, 0, MAX_TCP_OPTION_SPACE - size,
+					  opts, tp);
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
net/ipv6/syncookies.c +1 -1
index 895ff650db43..1c246a8f41c3 100644
@@ -160,7 +160,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
Signature · 1 line
2.12.2
#1 lore raw

Hello Mat,

Quoted 14 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Quoted 7 lines

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I haven't yet gone through the patch in details (will do this over the weekend to give suggestions wrt to your questions).

But overall, I think it might be good to use your API for TCP_MD5 (just as an example), or TFO. That way, you can show to netdev how this simplifies the code and that the API allows to actually do what it intends to.

Christoph

Quoted 489 lines

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 drivers/infiniband/hw/cxgb4/cm.c |   2 +-
 include/linux/tcp.h              |  17 +++++
 include/net/tcp.h                |  48 +++++++++++++-
 net/ipv4/syncookies.c            |   2 +-
 net/ipv4/tcp.c                   | 135 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_input.c             |  15 +++--
 net/ipv4/tcp_minisocks.c         |   4 +-
 net/ipv4/tcp_output.c            |  35 +++++-----
 net/ipv6/syncookies.c            |   2 +-
 9 files changed, 232 insertions(+), 28 deletions(-)
drivers/infiniband/hw/cxgb4/cm.c +1 -1
index 03a1b0e64fc3..1d1dbfdf5a05 100644
@@ -3748,7 +3748,7 @@ static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
 	 */
 	memset(&tmp_opt, 0, sizeof(tmp_opt));
 	tcp_clear_options(&tmp_opt);
-	tcp_parse_options(skb, &tmp_opt, 0, NULL);
+	tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 	req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
 	memset(req, 0, sizeof(*req));
include/linux/tcp.h +17 -0
index cfc2d9506ce8..9e625a68f5e1 100644
@@ -112,6 +112,23 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 	rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
 }
 
+#define OPTION_SACK_ADVERTISE	(1 << 0)
+#define OPTION_TS		(1 << 1)
+#define OPTION_MD5		(1 << 2)
+#define OPTION_WSCALE		(1 << 3)
+#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
+
+struct tcp_out_options {
+	u16 options;		/* bit field of OPTION_* */
+	u16 mss;		/* 0 to disable */
+	u8 ws;			/* window scale, 0 to disable */
+	u8 num_sack_blocks;	/* number of SACK blocks to include */
+	u8 hash_size;		/* bytes in hash_location */
+	__u8 *hash_location;	/* temporary pointer, overloaded */
+	__u32 tsval, tsecr;	/* need to include OPTION_TS */
+	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
+};
+
 /* This is the max number of SACKS that we'll generate and process. It's safe
  * to increase this, although since:
  *   size = TCPOLEN_SACK_BASE_ALIGNED (4) + n * TCPOLEN_SACK_PERBLOCK (8)
include/net/tcp.h +47 -1
index cc6ae0a95201..36785427ae90 100644
@@ -429,7 +429,8 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
 		int flags, int *addr_len);
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx,
-		       int estab, struct tcp_fastopen_cookie *foc);
+		       int estab, struct tcp_fastopen_cookie *foc,
+		       struct tcp_sock *tp);
 const u8 *tcp_parse_md5sig_option(const struct tcphdr *th);
 
 /*
@@ -1937,4 +1938,49 @@ static inline void tcp_listendrop(const struct sock *sk)
 	__NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS);
 }
 
+extern struct static_key_false tcp_extra_options_enabled;
+
+struct tcp_extra_option_ops {
+	struct list_head	list;
+	unsigned char		option_kind;
+	void (*parse)(int opsize, const unsigned char *opptr,
+		      const struct sk_buff *skb,
+		      struct tcp_options_received *opt_rx,
+		      struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare)(struct sk_buff *skb, u8 flags,
+				unsigned int remaining,
+				struct tcp_out_options *opts,
+				struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare_req)(struct sk_buff *skb, u8 flags,
+				    unsigned int remaining,
+				    struct tcp_out_options *opts,
+				    struct request_sock *req);
+	void (*write)(__be32 *ptr, struct tcp_out_options *opts,
+		      struct tcp_sock *tp);
+	struct module		*owner;
+};
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req);
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp);
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops);
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops);
+
 #endif	/* _TCP_H */
net/ipv4/syncookies.c +1 -1
index 496b97e17aaf..5697083a2c77 100644
@@ -309,7 +309,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
net/ipv4/tcp.c +135 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -269,6 +269,7 @@
 #include <linux/err.h>
 #include <linux/time.h>
 #include <linux/slab.h>
+#include <linux/static_key.h>
 
 #include <net/icmp.h>
 #include <net/inet_common.h>
@@ -306,6 +307,13 @@ struct percpu_counter tcp_sockets_allocated;
 EXPORT_SYMBOL(tcp_sockets_allocated);
 
 /*
+ * Optional TCP option handlers
+ */
+static DEFINE_SPINLOCK(tcp_option_list_lock);
+static LIST_HEAD(tcp_option_list);
+DEFINE_STATIC_KEY_FALSE(tcp_extra_options_enabled);
+
+/*
  * TCP splice context
  */
 struct tcp_splice_state {
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops *tcp_extra_options_find_kind(unsigned char kind)
+{
+	struct tcp_extra_option_ops *entry;
+
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (entry->option_kind == kind)
+			return entry;
+	}
+
+	return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	entry = tcp_extra_options_find_kind(opcode);
+	if (entry && entry->parse)
+		entry->parse(opsize, opptr, skb, opt_rx, tp);
+	rcu_read_unlock();
+}
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare))
+			continue;
+
+		used += entry->prepare(skb, flags, remaining - used, opts, tp);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare_req))
+			continue;
+
+		used += entry->prepare_req(skb, flags, remaining - used, opts,
+					   req);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->write))
+			continue;
+
+		entry->write(ptr, opts, tp);
+	}
+	rcu_read_unlock();
+}
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops)
+{
+	int ret = 0;
+
+	if (!ops->option_kind)
+		return -EINVAL;
+
+	if (!try_module_get(ops->owner))
+		return -ENOENT;
+
+	spin_lock(&tcp_option_list_lock);
+	if (tcp_extra_options_find_kind(ops->option_kind)) {
+		pr_notice("Option kind %u already registered\n",
+			  ops->option_kind);
+		spin_unlock(&tcp_option_list_lock);
+		module_put(ops->owner);
+		return -EEXIST;
+	}
+
+	list_add_tail_rcu(&ops->list, &tcp_option_list);
+	pr_debug("Option kind %u registered\n", ops->option_kind);
+	spin_unlock(&tcp_option_list_lock);
+
+	static_branch_inc(&tcp_extra_options_enabled);
+
+	return ret;
+}
+
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops)
+{
+	spin_lock(&tcp_option_list_lock);
+	list_del_rcu(&ops->list);
+	spin_unlock(&tcp_option_list_lock);
+
+	synchronize_net();
+
+	static_branch_dec(&tcp_extra_options_enabled);
+
+	module_put(ops->owner);
+}
+
 void tcp_done(struct sock *sk)
 {
 	struct request_sock *req = tcp_sk(sk)->fastopen_rsk;
@@ -3425,6 +3559,7 @@ void __init tcp_init(void)
 		INIT_HLIST_HEAD(&tcp_hashinfo.bhash[i].chain);
 	}
 
+	INIT_LIST_HEAD(&tcp_option_list);
 
 	cnt = tcp_hashinfo.ehash_mask + 1;
 	sysctl_tcp_max_orphans = cnt / 2;
net/ipv4/tcp_input.c +10 -5
index a5838858c362..13ab3dff7c3f 100644
@@ -3726,7 +3726,7 @@ static void tcp_parse_fastopen_option(int len, const unsigned char *cookie,
  */
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx, int estab,
-		       struct tcp_fastopen_cookie *foc)
+		       struct tcp_fastopen_cookie *foc, struct tcp_sock *tp)
 {
 	const unsigned char *ptr;
 	const struct tcphdr *th = tcp_hdr(skb);
@@ -3828,6 +3828,11 @@ void tcp_parse_options(const struct sk_buff *skb,
 						ptr + 2, th->syn, foc, true);
 				break;
 
+			default:
+				tcp_extra_options_parse(opcode, opsize, ptr,
+							skb, opt_rx, tp);
+				break;
+
 			}
 			ptr += opsize-2;
 			length -= opsize;
@@ -3873,7 +3878,7 @@ static bool tcp_fast_parse_options(const struct sk_buff *skb,
 			return true;
 	}
 
-	tcp_parse_options(skb, &tp->rx_opt, 1, NULL);
+	tcp_parse_options(skb, &tp->rx_opt, 1, NULL, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -5600,7 +5605,7 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,
 		/* Get original SYNACK MSS value if user MSS sets mss_clamp */
 		tcp_clear_options(&opt);
 		opt.user_mss = opt.mss_clamp = 0;
-		tcp_parse_options(synack, &opt, 0, NULL);
+		tcp_parse_options(synack, &opt, 0, NULL, tp);
 		mss = opt.mss_clamp;
 	}
 
@@ -5653,7 +5658,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 	struct tcp_fastopen_cookie foc = { .len = -1 };
 	int saved_clamp = tp->rx_opt.mss_clamp;
 
-	tcp_parse_options(skb, &tp->rx_opt, 0, &foc);
+	tcp_parse_options(skb, &tp->rx_opt, 0, &foc, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -6316,7 +6321,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
 	tmp_opt.user_mss  = tp->rx_opt.user_mss;
-	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc);
+	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc, tp);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
net/ipv4/tcp_minisocks.c +2 -2
index 8f6373b0cd77..c51bb1b30f08 100644
@@ -98,7 +98,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			if (tmp_opt.rcv_tsecr)
@@ -558,7 +558,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(struct tcphdr)>>2)) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent = req->ts_recent;
net/ipv4/tcp_output.c +18 -17
index ffc9274b2706..840883531996 100644
@@ -41,6 +41,7 @@
 #include <linux/compiler.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
+#include <linux/static_key.h>
 
 /* People can turn this off for buggy TCP's found in printers etc. */
 int sysctl_tcp_retrans_collapse __read_mostly = 1;
@@ -411,23 +412,6 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
 	return tp->snd_una != tp->snd_up;
 }
 
-#define OPTION_SACK_ADVERTISE	(1 << 0)
-#define OPTION_TS		(1 << 1)
-#define OPTION_MD5		(1 << 2)
-#define OPTION_WSCALE		(1 << 3)
-#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
-
-struct tcp_out_options {
-	u16 options;		/* bit field of OPTION_* */
-	u16 mss;		/* 0 to disable */
-	u8 ws;			/* window scale, 0 to disable */
-	u8 num_sack_blocks;	/* number of SACK blocks to include */
-	u8 hash_size;		/* bytes in hash_location */
-	__u8 *hash_location;	/* temporary pointer, overloaded */
-	__u32 tsval, tsecr;	/* need to include OPTION_TS */
-	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
-};
-
 /* Write previously computed TCP options to the packet.
  *
  * Beware: Something in the Internet is very sensitive to the ordering of
@@ -534,6 +518,9 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
 		}
 		ptr += (len + 3) >> 2;
 	}
+
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		tcp_extra_options_write(ptr, opts, tp);
 }
 
 /* Compute TCP options for SYN packets. This is not the final
@@ -601,6 +588,10 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare(skb, TCPHDR_SYN,
+						       remaining, opts, tp);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -661,6 +652,13 @@ static unsigned int tcp_synack_options(struct request_sock *req,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare_req(skb,
+							   TCPHDR_SYN |
+							   TCPHDR_ACK,
+							   remaining, opts,
+							   req);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -694,6 +692,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		size += TCPOLEN_TSTAMP_ALIGNED;
 	}
 
+	size += tcp_extra_options_prepare(skb, 0, MAX_TCP_OPTION_SPACE - size,
+					  opts, tp);
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
net/ipv6/syncookies.c +1 -1
index 895ff650db43..1c246a8f41c3 100644
@@ -160,7 +160,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
Signature · 6 lines
2.12.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
author
#2 lore raw
In reply to Mat Martineau
Quoted 30 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

---

...

Quoted 36 lines
net/ipv4/tcp.c +28 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops *tcp_extra_options_find_kind(unsigned char kind)
+{
+	struct tcp_extra_option_ops *entry;
+
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (entry->option_kind == kind)
+			return entry;
+	}
+
+	return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	entry = tcp_extra_options_find_kind(opcode);
+	if (entry && entry->parse)
+		entry->parse(opsize, opptr, skb, opt_rx, tp);
+	rcu_read_unlock();
+}

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3327

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();

I think I'll change this to have the caller handle rcu_read_lock/unlock, so the registered option list stays the same between the paired calls to tcp_extra_options_prepare{,_req}() and tcp_extra_options_write(). I'll double-check that nothing blocks or sleeps between those calls.

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare))
+			continue;
+
+		used += entry->prepare(skb, flags, remaining - used, opts, tp);
+	}
+	rcu_read_unlock();
+
+	return used;
+}

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3347

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();

Same applies to this read lock and tcp_extra_options_write below.

Quoted 16 lines
net/ipv4/tcp.c +16 -0
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare_req))
+			continue;
+
+		used += entry->prepare_req(skb, flags, remaining - used, opts,
+					   req);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3373

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->write))
+			continue;
+
+		entry->write(ptr, opts, tp);
+	}
+	rcu_read_unlock();
+}

--
Mat Martineau
Intel OTC

#3 lore raw

Hi Matt,

Good work see my comments inline..

Quoted 6 lines · Mat Martineau
Quoted 3 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Quoted 7 lines
Quoted 7 lines

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Quoted 50 lines
Quoted 19 lines

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

---

...

Quoted 28 lines
net/ipv4/tcp.c +18 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops 
 *tcp_extra_options_find_kind(unsigned char kind)
+{
+    struct tcp_extra_option_ops *entry;
+
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (entry->option_kind == kind)
+            return entry;
+    }
+
+    return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned 
 char *opptr,
+                 const struct sk_buff *skb,
+                 struct tcp_options_received *opt_rx,
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3315

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    entry = tcp_extra_options_find_kind(opcode);
+    if (entry && entry->parse)
+        entry->parse(opsize, opptr, skb, opt_rx, tp);

There does not seems to be a return value, what happens if the parsing fails or the processing requires resetting the connection. For example in MPTCP if checksum required is present but is not configured, the current code returns an error and the connection is reset. We should provide provision to call a default function for an option that does not match, so it can at least be documented and the user may set an option to reset the connection.

Quoted 10 lines
Quoted 10 lines
net/ipv4/tcp.c +10 -0
+    rcu_read_unlock();
+}
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+                       unsigned int remaining,
+                       struct tcp_out_options *opts,
+                       struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+    unsigned int used = 0;
Quoted 16 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3329

Quoted 2 lines
net/ipv4/tcp.c +2 -0
+
+    rcu_read_lock();

I think I'll change this to have the caller handle rcu_read_lock/unlock, so the registered option list stays the same between the paired calls to tcp_extra_options_prepare{,_req}() and tcp_extra_options_write(). I'll double-check that nothing blocks or sleeps between those calls.

Quoted 7 lines
net/ipv4/tcp.c +7 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare))
+            continue;
+
+        used += entry->prepare(skb, flags, remaining - used, opts, tp);
+    }
+    rcu_read_unlock();

Should there be a check to stop calling when no space is left ? This also raises the question of priority, which seems to be based on the place in the list. What happens if there is no space left ? Do you add MPTCP's DSS option or SACK or MD5 ?

Quoted 8 lines
Quoted 8 lines
net/ipv4/tcp.c +7 -0
+
+    return used;
+}
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 
 flags,
+                       unsigned int remaining,
+                       struct tcp_out_options *opts,
Quoted 17 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3347

Quoted 6 lines
net/ipv4/tcp.c +6 -0
+                       struct request_sock *req)
+{
+    struct tcp_extra_option_ops *entry;
+    unsigned int used = 0;
+
+    rcu_read_lock();

Same applies to this read lock and tcp_extra_options_write below.

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare_req))
+            continue;
+
+        used += entry->prepare_req(skb, flags, remaining - used, opts,
+                       req);
+    }
+    rcu_read_unlock();

Again need to check for space, missing out on adding an option due to lack of space is less of an issue here.

Quoted 7 lines
Quoted 7 lines
net/ipv4/tcp.c +7 -0
+
+    return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+                 struct tcp_sock *tp)
+{
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3370

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->write))
+            continue;
+
+        entry->write(ptr, opts, tp);

I think you need a check here to call only options that are in opts ? We should also pass in skb, In case tcp header is needed to generate option values.

Quoted 4 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3317

Quoted 3 lines
net/ipv4/tcp.c +3 -0
+    }
+    rcu_read_unlock();
+}

This is a great framework for handling options, my concern is that the options processing is intertwined with TCP code. Unless we can implement that separately there will not be much benefit. Just search for CONFIG_TCP_MD5SIG, MPTCP related code is also sprinkled all over tcp code. Before we go down this path should we evaluate if that can be achieved ?

I have found a way to make MPTCP work without using tcp_skb_cb, I will post the patch after I clean up the code. However my approach is very specific to MPTCP. If we went with this framework, we would need a generic way to pass the options. I have ideas on how to do that but that would require a lot of changes to the tcp/skb code.

Rao.

Quoted 7 lines
Signature · 6 lines
Mat Martineau
Intel OTC
_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
#4 lore raw
Quoted 16 lines · Rao Shoaib

Hi Matt,

Good work see my comments inline..

Quoted 10 lines · Mat Martineau
Quoted 7 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option
number is not recognized by the normal option parsing code.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants
because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Let me clarify my comment, Why can't we just pass in a flag or the options code can just look at the TCP header, that would avoid keeping two lists.

Rao

author
#5 lore raw
In reply to Rao Shoaib
Quoted 15 lines · Rao Shoaib

Hi Matt,

Good work see my comments inline..

Quoted 9 lines · Mat Martineau
Quoted 6 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Christoph had a good suggestion for getting rid of prepare_req (see that reply).

Quoted 55 lines
Quoted 55 lines
Quoted 19 lines

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

---

...

Quoted 33 lines
net/ipv4/tcp.c +23 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops *tcp_extra_options_find_kind(unsigned 
 char kind)
+{
+    struct tcp_extra_option_ops *entry;
+
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (entry->option_kind == kind)
+            return entry;
+    }
+
+    return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char 
 *opptr,
+                 const struct sk_buff *skb,
+                 struct tcp_options_received *opt_rx,
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
Quoted 8 lines
Quoted 3 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3315

Quoted 3 lines
net/ipv4/tcp.c +3 -0
+    entry = tcp_extra_options_find_kind(opcode);
+    if (entry && entry->parse)
+        entry->parse(opsize, opptr, skb, opt_rx, tp);

There does not seems to be a return value, what happens if the parsing fails or the processing requires resetting the connection. For example in MPTCP if checksum required is present but is not configured, the current code returns an error and the connection is reset.

tcp_parse_options() doesn't have an error path, so I stayed with that approach. But maybe we need something a little different, if MPTCP can't handle the error on a different path (for example by putting something on a work queue to handle the connection reset).

Quoted 3 lines

We should provide provision to call a default function for an option that does not match, so it can at least be documented and the user may set an option to reset the connection.

Unrecognized TCP options are currently ignored - is a wildcard option handler useful for MPTCP or TCP in general?

Quoted 26 lines
Quoted 10 lines
Quoted 10 lines
net/ipv4/tcp.c +9 -0
+    rcu_read_unlock();
+}
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+                       unsigned int remaining,
+                       struct tcp_out_options *opts,
+                       struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
Quoted 16 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3327

Quoted 3 lines
net/ipv4/tcp.c +3 -0
+    unsigned int used = 0;
+
+    rcu_read_lock();

I think I'll change this to have the caller handle rcu_read_lock/unlock, so the registered option list stays the same between the paired calls to tcp_extra_options_prepare{,_req}() and tcp_extra_options_write(). I'll double-check that nothing blocks or sleeps between those calls.

Quoted 7 lines
net/ipv4/tcp.c +7 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare))
+            continue;
+
+        used += entry->prepare(skb, flags, remaining - used, opts, tp);
+    }
+    rcu_read_unlock();
Quoted 4 lines

Should there be a check to stop calling when no space is left ? This also raises the question of priority, which seems to be based on the place in the list. What happens if there is no space left ? Do you add MPTCP's DSS option or SACK or MD5 ?

I think it should keep calling even if there's no space - it might be useful to know a packet is going out with its option space used. The prepare() call will need to handle too little space anyway (even if it's more than 0).

Ordering is an open question. It would be a minor extension to maintain the list ordered by priority when each option is registered. There's a comment before tcp_options_write cautioning that option ordering can be sensitive, but we aren't changing the order of the "normal" TCP options. Still, I think I agree with you that changing the order of options based on who registered first is not great.

Regarding SACK specifically, I placed the prepare() call before SACK so that the registered options would consume space before SACK tried to use up the rest.

Quoted 27 lines
Quoted 7 lines
Quoted 7 lines
net/ipv4/tcp.c +7 -0
+
+    return used;
+}
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+                       unsigned int remaining,
+                       struct tcp_out_options *opts,
Quoted 17 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3347

Quoted 6 lines
net/ipv4/tcp.c +6 -0
+                       struct request_sock *req)
+{
+    struct tcp_extra_option_ops *entry;
+    unsigned int used = 0;
+
+    rcu_read_lock();

Same applies to this read lock and tcp_extra_options_write below.

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare_req))
+            continue;
+
+        used += entry->prepare_req(skb, flags, remaining - used, opts,
+                       req);
+    }
+    rcu_read_unlock();

Again need to check for space, missing out on adding an option due to lack of space is less of an issue here.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
net/ipv4/tcp.c +7 -0
+
+    return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+                 struct tcp_sock *tp)
+{
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3370

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->write))
+            continue;
+
+        entry->write(ptr, opts, tp);

I think you need a check here to call only options that are in opts ?

This code doesn't know which opts are relevant - does it make a big difference if we check here and optionally call, or call and let that function quickly check to see if it needs to write? The list is expected to be short.

Quoted 2 lines

We should also pass in skb, In case tcp header is needed to generate option values.

I was trying to not add a parameter to tcp_options_write, but we can change this if needed. The prepare() call gets the skb pointer, so it could store necessary information (if we figure out where to put it).

Quoted 8 lines
Quoted 4 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3317

Quoted 3 lines
net/ipv4/tcp.c +3 -0
+    }
+    rcu_read_unlock();
+}

This is a great framework for handling options, my concern is that the options processing is intertwined with TCP code. Unless we can implement that separately there will not be much benefit.

Are you suggesting a larger rewrite of TCP option handling overall? Or are you referring to the intertwined MPTCP option handling in the multipath-tcp.org kernel?

Quoted 3 lines

Just search for CONFIG_TCP_MD5SIG, MPTCP related code is also sprinkled all over tcp code. Before we go down this path should we evaluate if that can be achieved ?

As Christoph mentioned, MD5SIG would be one way to validate that the framework provides a useful approach for multiple TCP features. There's still more work to do to see if MPTCP can fit within this framework, and I expect the approach to options to evolve as we learn more.

Quoted 5 lines

I have found a way to make MPTCP work without using tcp_skb_cb, I will post the patch after I clean up the code. However my approach is very specific to MPTCP. If we went with this framework, we would need a generic way to pass the options. I have ideas on how to do that but that would require a lot of changes to the tcp/skb code.

Great, thanks for the update! I look forward to seeing what you've got, maybe we can share some ideas about fitting it with the framework.

Regards,

--
Mat Martineau
Intel OTC

#6 lore raw
Quoted 24 lines · Mat Martineau
Quoted 21 lines · Rao Shoaib

Hi Matt,

Good work see my comments inline..

Quoted 15 lines · Mat Martineau
Quoted 12 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option
number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants
because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

Quoted 6 lines
Quoted 3 lines

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Christoph had a good suggestion for getting rid of prepare_req (see that reply).

Yeah. I should have read his email before replying as there was quite an overlap. I do have to say that looking at socket state when we are down at the transport level just seems strange, but I guess in Linux that is quite common.

Can you guys save me some the trouble of digging through the code and tell me what is the locking strategy for sockets and tcp structures.

Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
net/ipv4/tcp.c +24 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops 
 *tcp_extra_options_find_kind(unsigned char kind)
+{
+    struct tcp_extra_option_ops *entry;
+
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (entry->option_kind == kind)
+            return entry;
+    }
+
+    return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const 
 unsigned char *opptr,
+                 const struct sk_buff *skb,
+                 struct tcp_options_received *opt_rx,
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    entry = tcp_extra_options_find_kind(opcode);
Quoted 8 lines
Quoted 2 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3315

Quoted 2 lines
net/ipv4/tcp.c +2 -0
+    if (entry && entry->parse)
+        entry->parse(opsize, opptr, skb, opt_rx, tp);

There does not seems to be a return value, what happens if the parsing fails or the processing requires resetting the connection. For example in MPTCP if checksum required is present but is not configured, the current code returns an error and the connection is reset.

Quoted 4 lines

tcp_parse_options() doesn't have an error path, so I stayed with that approach. But maybe we need something a little different, if MPTCP can't handle the error on a different path (for example by putting something on a work queue to handle the connection reset).

Take a look at tcp_validate_incoming() -- since MPTCP packets take the slow path.

Quoted 7 lines
Quoted 4 lines

We should provide provision to call a default function for an option that does not match, so it can at least be documented and the user may set an option to reset the connection.

Unrecognized TCP options are currently ignored - is a wildcard option handler useful for MPTCP or TCP in general?

That was just a suggestion to add something for observability.

Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3334

Quoted 8 lines
net/ipv4/tcp.c +7 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare))
+            continue;
+
+        used += entry->prepare(skb, flags, remaining - used, opts, 
 tp);
+    }
+    rcu_read_unlock();
Quoted 4 lines

Should there be a check to stop calling when no space is left ? This also raises the question of priority, which seems to be based on the place in the list. What happens if there is no space left ? Do you add MPTCP's DSS option or SACK or MD5 ?

Quoted 4 lines

I think it should keep calling even if there's no space - it might be useful to know a packet is going out with its option space used. The prepare() call will need to handle too little space anyway (even if it's more than 0).

OK.

Quoted 11 lines

Ordering is an open question. It would be a minor extension to maintain the list ordered by priority when each option is registered. There's a comment before tcp_options_write cautioning that option ordering can be sensitive, but we aren't changing the order of the "normal" TCP options. Still, I think I agree with you that changing the order of options based on who registered first is not great.

Regarding SACK specifically, I placed the prepare() call before SACK so that the registered options would consume space before SACK tried to use up the rest.

Let me figure out how retransmission is being handled. I am worried about the case where sending SACK would be more beneficial than some other option.

Quoted 18 lines

+

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/ipv4/tcp.c +4 -0
+    return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options 

*opts,

net/ipv4/tcp.c +3 -0
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
Quoted 8 lines
Quoted 7 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3370

Quoted 7 lines
net/ipv4/tcp.c +7 -0
+
+    rcu_read_lock();
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->write))
+            continue;
+
+        entry->write(ptr, opts, tp);

I think you need a check here to call only options that are in opts ?

Quoted 1 line

This code doesn't know which opts are relevant -

Actually it does. The options (KIND) to put in the packet have already been chosen.

Quoted 3 lines

does it make a big difference if we check here and optionally call, or call and let that function quickly check to see if it needs to write? The list is expected to be short.

Someone will have to look through the opts list and make a decision. It would be better to do it here but if you have another idea than that is OK.

Quoted 7 lines
Quoted 3 lines

We should also pass in skb, In case tcp header is needed to generate option values.

I was trying to not add a parameter to tcp_options_write, but we can change this if needed. The prepare() call gets the skb pointer, so it could store necessary information (if we figure out where to put it).

I am not sure if that is convenient because when prepare is called headers are not present. There is code in MPTCP that checks for say if the pakcet is a FIN etc.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
net/ipv4/tcp.c +3 -0
+    }
+    rcu_read_unlock();
+}
Quoted 7 lines
Quoted 3 lines

This is a great framework for handling options, my concern is that the options processing is intertwined with TCP code. Unless we can implement that separately there will not be much benefit.

Are you suggesting a larger rewrite of TCP option handling overall? Or are you referring to the intertwined MPTCP option handling in the multipath-tcp.org kernel?

I was trying to point out that if we can not move MPTCP, MD5SIG code out of TCP into a separate module it will be difficult to sell this mechanism to netdev.

Quoted 11 lines
Quoted 4 lines

Just search for CONFIG_TCP_MD5SIG, MPTCP related code is also sprinkled all over tcp code. Before we go down this path should we evaluate if that can be achieved ?

As Christoph mentioned, MD5SIG would be one way to validate that the framework provides a useful approach for multiple TCP features. There's still more work to do to see if MPTCP can fit within this framework, and I expect the approach to options to evolve as we learn more.

This is exactly what I meant to say above.

The design of the options handling framework is pretty good, the details will evolve. So continue on with the good work.

Good Luck,

Rao.

#7 lore raw

Hello Rao,

Quoted 34 lines · Rao Shoaib
Quoted 24 lines · Mat Martineau
Quoted 21 lines · Rao Shoaib

Hi Matt,

Good work see my comments inline..

Quoted 15 lines · Mat Martineau
Quoted 12 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option
number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants
because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

Quoted 6 lines
Quoted 3 lines

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Christoph had a good suggestion for getting rid of prepare_req (see that reply).

Quoted 7 lines

Yeah. I should have read his email before replying as there was quite an overlap. I do have to say that looking at socket state when we are down at the transport level just seems strange, but I guess in Linux that is quite common.

Can you guys save me some the trouble of digging through the code and tell me what is the locking strategy for sockets and tcp structures.

lock_sock() and bh_lock_sock(). The former, used when coming from user-context. All it does it setting sk->sk_lock.owned to 1, so that sock_owned_by_user() returns 1. This prevents other user-context threads from accessing the socket.

bh_lock_sock() is the spin-lock, that one must take when coming from interrupt-context. When it takes a spinlock, it usually checks sock_owned_by_user() to see if another user-space process is currently using the socket as well. If that's the case, it pushes the packet on the backlog-queue (see tcp_v4_rcv), instead of going through the stack.

When the user-context has finished its work, it calls release_sock(), which processes the work that has been queued by interrupt-context "threads" on the backlog-queue.

That's a very quick, rough and high-level explanation :)

Christoph

Quoted 166 lines
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
net/ipv4/tcp.c +24 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops
 *tcp_extra_options_find_kind(unsigned char kind)
+{
+    struct tcp_extra_option_ops *entry;
+
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (entry->option_kind == kind)
+            return entry;
+    }
+
+    return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const
 unsigned char *opptr,
+                 const struct sk_buff *skb,
+                 struct tcp_options_received *opt_rx,
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    entry = tcp_extra_options_find_kind(opcode);
Quoted 8 lines
Quoted 2 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3315

Quoted 2 lines
net/ipv4/tcp.c +2 -0
+    if (entry && entry->parse)
+        entry->parse(opsize, opptr, skb, opt_rx, tp);

There does not seems to be a return value, what happens if the parsing fails or the processing requires resetting the connection. For example in MPTCP if checksum required is present but is not configured, the current code returns an error and the connection is reset.

Quoted 4 lines

tcp_parse_options() doesn't have an error path, so I stayed with that approach. But maybe we need something a little different, if MPTCP can't handle the error on a different path (for example by putting something on a work queue to handle the connection reset).

Take a look at tcp_validate_incoming() -- since MPTCP packets take the slow path.

Quoted 7 lines
Quoted 4 lines

We should provide provision to call a default function for an option that does not match, so it can at least be documented and the user may set an option to reset the connection.

Unrecognized TCP options are currently ignored - is a wildcard option handler useful for MPTCP or TCP in general?

That was just a suggestion to add something for observability.

Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3334

Quoted 8 lines
net/ipv4/tcp.c +7 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare))
+            continue;
+
+        used += entry->prepare(skb, flags, remaining -
 used, opts, tp);
+    }
+    rcu_read_unlock();
Quoted 4 lines

Should there be a check to stop calling when no space is left ? This also raises the question of priority, which seems to be based on the place in the list. What happens if there is no space left ? Do you add MPTCP's DSS option or SACK or MD5 ?

Quoted 4 lines

I think it should keep calling even if there's no space - it might be useful to know a packet is going out with its option space used. The prepare() call will need to handle too little space anyway (even if it's more than 0).

OK.

Quoted 11 lines

Ordering is an open question. It would be a minor extension to maintain the list ordered by priority when each option is registered. There's a comment before tcp_options_write cautioning that option ordering can be sensitive, but we aren't changing the order of the "normal" TCP options. Still, I think I agree with you that changing the order of options based on who registered first is not great.

Regarding SACK specifically, I placed the prepare() call before SACK so that the registered options would consume space before SACK tried to use up the rest.

Let me figure out how retransmission is being handled. I am worried about the case where sending SACK would be more beneficial than some other option.

Quoted 18 lines

+

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/ipv4/tcp.c +4 -0
+    return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct

tcp_out_options *opts,

net/ipv4/tcp.c +3 -0
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
Quoted 8 lines
Quoted 7 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3370

Quoted 7 lines
net/ipv4/tcp.c +7 -0
+
+    rcu_read_lock();
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->write))
+            continue;
+
+        entry->write(ptr, opts, tp);

I think you need a check here to call only options that are in opts ?

Quoted 1 line

This code doesn't know which opts are relevant -

Actually it does. The options (KIND) to put in the packet have already been chosen.

Quoted 3 lines

does it make a big difference if we check here and optionally call, or call and let that function quickly check to see if it needs to write? The list is expected to be short.

Someone will have to look through the opts list and make a decision. It would be better to do it here but if you have another idea than that is OK.

Quoted 7 lines
Quoted 3 lines

We should also pass in skb, In case tcp header is needed to generate option values.

I was trying to not add a parameter to tcp_options_write, but we can change this if needed. The prepare() call gets the skb pointer, so it could store necessary information (if we figure out where to put it).

I am not sure if that is convenient because when prepare is called headers are not present. There is code in MPTCP that checks for say if the pakcet is a FIN etc.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
net/ipv4/tcp.c +3 -0
+    }
+    rcu_read_unlock();
+}
Quoted 7 lines
Quoted 3 lines

This is a great framework for handling options, my concern is that the options processing is intertwined with TCP code. Unless we can implement that separately there will not be much benefit.

Are you suggesting a larger rewrite of TCP option handling overall? Or are you referring to the intertwined MPTCP option handling in the multipath-tcp.org kernel?

I was trying to point out that if we can not move MPTCP, MD5SIG code out of TCP into a separate module it will be difficult to sell this mechanism to netdev.

Quoted 10 lines
Quoted 4 lines

Just search for CONFIG_TCP_MD5SIG, MPTCP related code is also sprinkled all over tcp code. Before we go down this path should we evaluate if that can be achieved ?

As Christoph mentioned, MD5SIG would be one way to validate that the framework provides a useful approach for multiple TCP features. There's still more work to do to see if MPTCP can fit within this framework, and I expect the approach to options to evolve as we learn more.

This is exactly what I meant to say above.

The design of the options handling framework is pretty good, the details will evolve. So continue on with the good work.

Good Luck,

Rao.

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

#8 lore raw
Quoted 16 lines · Christoph Paasch

lock_sock() and bh_lock_sock(). The former, used when coming from user-context. All it does it setting sk->sk_lock.owned to 1, so that sock_owned_by_user() returns 1. This prevents other user-context threads from accessing the socket.

bh_lock_sock() is the spin-lock, that one must take when coming from interrupt-context. When it takes a spinlock, it usually checks sock_owned_by_user() to see if another user-space process is currently using the socket as well. If that's the case, it pushes the packet on the backlog-queue (see tcp_v4_rcv), instead of going through the stack.

When the user-context has finished its work, it calls release_sock(), which processes the work that has been queued by interrupt-context "threads" on the backlog-queue.

Quoted 4 lines

That's a very quick, rough and high-level explanation:)

Christoph

Thanks a lot Christoph.

Rao

author
#9 lore raw
In reply to Rao Shoaib
Quoted 32 lines · Rao Shoaib
Quoted 22 lines · Mat Martineau
Quoted 19 lines · Rao Shoaib

Hi Matt,

Good work see my comments inline..

Quoted 13 lines · Mat Martineau
Quoted 10 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

Quoted 6 lines
Quoted 3 lines

If I understand correctly the only difference should be the options chosen. Why not handle this as is done today, syn and established options ?

Christoph had a good suggestion for getting rid of prepare_req (see that reply).

Quoted 7 lines

Yeah. I should have read his email before replying as there was quite an overlap. I do have to say that looking at socket state when we are down at the transport level just seems strange, but I guess in Linux that is quite common.

Can you guys save me some the trouble of digging through the code and tell me what is the locking strategy for sockets and tcp structures.

Thank you to Christoph for covering this!

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 29 lines
Quoted 29 lines
net/ipv4/tcp.c +18 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops 
 *tcp_extra_options_find_kind(unsigned char kind)
+{
+    struct tcp_extra_option_ops *entry;
+
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (entry->option_kind == kind)
+            return entry;
+    }
+
+    return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned 
 char *opptr,
+                 const struct sk_buff *skb,
+                 struct tcp_options_received *opt_rx,
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3315

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+                 struct tcp_sock *tp)
+{
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    entry = tcp_extra_options_find_kind(opcode);
+    if (entry && entry->parse)
+        entry->parse(opsize, opptr, skb, opt_rx, tp);

There does not seems to be a return value, what happens if the parsing fails or the processing requires resetting the connection. For example in MPTCP if checksum required is present but is not configured, the current code returns an error and the connection is reset.

Quoted 6 lines
Quoted 4 lines

tcp_parse_options() doesn't have an error path, so I stayed with that approach. But maybe we need something a little different, if MPTCP can't handle the error on a different path (for example by putting something on a work queue to handle the connection reset).

Take a look at tcp_validate_incoming() -- since MPTCP packets take the slow path.

Ok, I will look that over. The current TCP code separates the parsing from the actions taken (sending resets, etc), so maybe we can return some information that informs the caller about what actions to take.

Quoted 56 lines
Quoted 7 lines
Quoted 4 lines

We should provide provision to call a default function for an option that does not match, so it can at least be documented and the user may set an option to reset the connection.

Unrecognized TCP options are currently ignored - is a wildcard option handler useful for MPTCP or TCP in general?

That was just a suggestion to add something for observability.

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3334

Quoted 7 lines
net/ipv4/tcp.c +7 -0
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->prepare))
+            continue;
+
+        used += entry->prepare(skb, flags, remaining - used, opts, tp);
+    }
+    rcu_read_unlock();

Should there be a check to stop calling when no space is left ? This also raises the question of priority, which seems to be based on the place in the list. What happens if there is no space left ? Do you add MPTCP's DSS option or SACK or MD5 ?

Quoted 4 lines

I think it should keep calling even if there's no space - it might be useful to know a packet is going out with its option space used. The prepare() call will need to handle too little space anyway (even if it's more than 0).

OK.

Quoted 11 lines

Ordering is an open question. It would be a minor extension to maintain the list ordered by priority when each option is registered. There's a comment before tcp_options_write cautioning that option ordering can be sensitive, but we aren't changing the order of the "normal" TCP options. Still, I think I agree with you that changing the order of options based on who registered first is not great.

Regarding SACK specifically, I placed the prepare() call before SACK so that the registered options would consume space before SACK tried to use up the rest.

Let me figure out how retransmission is being handled. I am worried about the case where sending SACK would be more beneficial than some other option.

Quoted 17 lines

+

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
net/ipv4/tcp.c +6 -0
+    return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+                 struct tcp_sock *tp)
+{
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3370

Quoted 8 lines
net/ipv4/tcp.c +8 -0
+    struct tcp_extra_option_ops *entry;
+
+    rcu_read_lock();
+    list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+        if (unlikely(!entry->write))
+            continue;
+
+        entry->write(ptr, opts, tp);

I think you need a check here to call only options that are in opts ?

Quoted 3 lines
Quoted 1 line

This code doesn't know which opts are relevant -

Actually it does. The options (KIND) to put in the packet have already been chosen.

I wasn't very clear there, sorry about that. Yes, the prepare function did determine what options will be used. But the function here doesn't necessarily understand what will be stored in the opts struct (which we haven't defined yet) - if we have a generic way to represent that that includes the option number, then yes the choice can be made here.

Quoted 5 lines
Quoted 3 lines

does it make a big difference if we check here and optionally call, or call and let that function quickly check to see if it needs to write? The list is expected to be short.

Someone will have to look through the opts list and make a decision. It would be better to do it here but if you have another idea than that is OK.

Ok.

Quoted 20 lines
Quoted 7 lines
Quoted 3 lines

We should also pass in skb, In case tcp header is needed to generate option values.

I was trying to not add a parameter to tcp_options_write, but we can change this if needed. The prepare() call gets the skb pointer, so it could store necessary information (if we figure out where to put it).

I am not sure if that is convenient because when prepare is called headers are not present. There is code in MPTCP that checks for say if the pakcet is a FIN etc.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3317

Quoted 4 lines
net/ipv4/tcp.c +3 -0
+    }
+    rcu_read_unlock();
+}

This is a great framework for handling options, my concern is that the options processing is intertwined with TCP code. Unless we can implement that separately there will not be much benefit.

Quoted 6 lines
Quoted 3 lines

Are you suggesting a larger rewrite of TCP option handling overall? Or are you referring to the intertwined MPTCP option handling in the multipath-tcp.org kernel?

I was trying to point out that if we can not move MPTCP, MD5SIG code out of TCP into a separate module it will be difficult to sell this mechanism to netdev.

Ah, thanks for clarifying.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Just search for CONFIG_TCP_MD5SIG, MPTCP related code is also sprinkled all over tcp code. Before we go down this path should we evaluate if that can be achieved ?

As Christoph mentioned, MD5SIG would be one way to validate that the framework provides a useful approach for multiple TCP features. There's still more work to do to see if MPTCP can fit within this framework, and I expect the approach to options to evolve as we learn more.

Quoted 4 lines

This is exactly what I meant to say above.

The design of the options handling framework is pretty good, the details will evolve. So continue on with the good work.

Ok, thanks again for your help!

--
Mat Martineau
Intel OTC

#10 lore raw
In reply to Mat Martineau
Quoted 232 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 drivers/infiniband/hw/cxgb4/cm.c |   2 +-
 include/linux/tcp.h              |  17 +++++
 include/net/tcp.h                |  48 +++++++++++++-
 net/ipv4/syncookies.c            |   2 +-
 net/ipv4/tcp.c                   | 135 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_input.c             |  15 +++--
 net/ipv4/tcp_minisocks.c         |   4 +-
 net/ipv4/tcp_output.c            |  35 +++++-----
 net/ipv6/syncookies.c            |   2 +-
 9 files changed, 232 insertions(+), 28 deletions(-)
drivers/infiniband/hw/cxgb4/cm.c +1 -1
index 03a1b0e64fc3..1d1dbfdf5a05 100644
@@ -3748,7 +3748,7 @@ static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
 	 */
 	memset(&tmp_opt, 0, sizeof(tmp_opt));
 	tcp_clear_options(&tmp_opt);
-	tcp_parse_options(skb, &tmp_opt, 0, NULL);
+	tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 	req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
 	memset(req, 0, sizeof(*req));
include/linux/tcp.h +17 -0
index cfc2d9506ce8..9e625a68f5e1 100644
@@ -112,6 +112,23 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 	rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
 }
 
+#define OPTION_SACK_ADVERTISE	(1 << 0)
+#define OPTION_TS		(1 << 1)
+#define OPTION_MD5		(1 << 2)
+#define OPTION_WSCALE		(1 << 3)
+#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
+
+struct tcp_out_options {
+	u16 options;		/* bit field of OPTION_* */
+	u16 mss;		/* 0 to disable */
+	u8 ws;			/* window scale, 0 to disable */
+	u8 num_sack_blocks;	/* number of SACK blocks to include */
+	u8 hash_size;		/* bytes in hash_location */
+	__u8 *hash_location;	/* temporary pointer, overloaded */
+	__u32 tsval, tsecr;	/* need to include OPTION_TS */
+	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
+};
+
 /* This is the max number of SACKS that we'll generate and process. It's safe
  * to increase this, although since:
  *   size = TCPOLEN_SACK_BASE_ALIGNED (4) + n * TCPOLEN_SACK_PERBLOCK (8)
include/net/tcp.h +47 -1
index cc6ae0a95201..36785427ae90 100644
@@ -429,7 +429,8 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
 		int flags, int *addr_len);
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx,
-		       int estab, struct tcp_fastopen_cookie *foc);
+		       int estab, struct tcp_fastopen_cookie *foc,
+		       struct tcp_sock *tp);
 const u8 *tcp_parse_md5sig_option(const struct tcphdr *th);
 
 /*
@@ -1937,4 +1938,49 @@ static inline void tcp_listendrop(const struct sock *sk)
 	__NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS);
 }
 
+extern struct static_key_false tcp_extra_options_enabled;
+
+struct tcp_extra_option_ops {
+	struct list_head	list;
+	unsigned char		option_kind;
+	void (*parse)(int opsize, const unsigned char *opptr,
+		      const struct sk_buff *skb,
+		      struct tcp_options_received *opt_rx,
+		      struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare)(struct sk_buff *skb, u8 flags,
+				unsigned int remaining,
+				struct tcp_out_options *opts,
+				struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare_req)(struct sk_buff *skb, u8 flags,
+				    unsigned int remaining,
+				    struct tcp_out_options *opts,
+				    struct request_sock *req);
+	void (*write)(__be32 *ptr, struct tcp_out_options *opts,
+		      struct tcp_sock *tp);
+	struct module		*owner;
+};
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req);
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp);
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops);
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops);
+
 #endif	/* _TCP_H */
net/ipv4/syncookies.c +1 -1
index 496b97e17aaf..5697083a2c77 100644
@@ -309,7 +309,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
net/ipv4/tcp.c +51 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -269,6 +269,7 @@
 #include <linux/err.h>
 #include <linux/time.h>
 #include <linux/slab.h>
+#include <linux/static_key.h>
 
 #include <net/icmp.h>
 #include <net/inet_common.h>
@@ -306,6 +307,13 @@ struct percpu_counter tcp_sockets_allocated;
 EXPORT_SYMBOL(tcp_sockets_allocated);
 
 /*
+ * Optional TCP option handlers
+ */
+static DEFINE_SPINLOCK(tcp_option_list_lock);
+static LIST_HEAD(tcp_option_list);
+DEFINE_STATIC_KEY_FALSE(tcp_extra_options_enabled);
+
+/*
  * TCP splice context
  */
 struct tcp_splice_state {
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops *tcp_extra_options_find_kind(unsigned char kind)
+{
+	struct tcp_extra_option_ops *entry;
+
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (entry->option_kind == kind)
+			return entry;
+	}
+
+	return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	entry = tcp_extra_options_find_kind(opcode);
+	if (entry && entry->parse)
+		entry->parse(opsize, opptr, skb, opt_rx, tp);
+	rcu_read_unlock();
+}
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare))
+			continue;
+
+		used += entry->prepare(skb, flags, remaining - used, opts, tp);

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3342

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req)

As request-sockets are also just regular struct sock_common, I think you can get rid of tcp_extra_options_prepare_req() and in tcp_synack_options() just convert the struct request_sock to struct sock. Users of the API then need to check with sk->sk_state what kind of socket it really is.

Also, you probably should add something similar for tcp_v4_send_ack(), tcp_v4_send_reset() and the IPv6 counterparts.

TCP_MD5 has also some ugly hooks in tcp_v4_send_ack(), so the netdev community might like it if they go away.

Christoph

Quoted 268 lines
net/ipv4/tcp.c +74 -0
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare_req))
+			continue;
+
+		used += entry->prepare_req(skb, flags, remaining - used, opts,
+					   req);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->write))
+			continue;
+
+		entry->write(ptr, opts, tp);
+	}
+	rcu_read_unlock();
+}
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops)
+{
+	int ret = 0;
+
+	if (!ops->option_kind)
+		return -EINVAL;
+
+	if (!try_module_get(ops->owner))
+		return -ENOENT;
+
+	spin_lock(&tcp_option_list_lock);
+	if (tcp_extra_options_find_kind(ops->option_kind)) {
+		pr_notice("Option kind %u already registered\n",
+			  ops->option_kind);
+		spin_unlock(&tcp_option_list_lock);
+		module_put(ops->owner);
+		return -EEXIST;
+	}
+
+	list_add_tail_rcu(&ops->list, &tcp_option_list);
+	pr_debug("Option kind %u registered\n", ops->option_kind);
+	spin_unlock(&tcp_option_list_lock);
+
+	static_branch_inc(&tcp_extra_options_enabled);
+
+	return ret;
+}
+
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops)
+{
+	spin_lock(&tcp_option_list_lock);
+	list_del_rcu(&ops->list);
+	spin_unlock(&tcp_option_list_lock);
+
+	synchronize_net();
+
+	static_branch_dec(&tcp_extra_options_enabled);
+
+	module_put(ops->owner);
+}
+
 void tcp_done(struct sock *sk)
 {
 	struct request_sock *req = tcp_sk(sk)->fastopen_rsk;
@@ -3425,6 +3559,7 @@ void __init tcp_init(void)
 		INIT_HLIST_HEAD(&tcp_hashinfo.bhash[i].chain);
 	}
 
+	INIT_LIST_HEAD(&tcp_option_list);
 
 	cnt = tcp_hashinfo.ehash_mask + 1;
 	sysctl_tcp_max_orphans = cnt / 2;
net/ipv4/tcp_input.c +10 -5
index a5838858c362..13ab3dff7c3f 100644
@@ -3726,7 +3726,7 @@ static void tcp_parse_fastopen_option(int len, const unsigned char *cookie,
  */
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx, int estab,
-		       struct tcp_fastopen_cookie *foc)
+		       struct tcp_fastopen_cookie *foc, struct tcp_sock *tp)
 {
 	const unsigned char *ptr;
 	const struct tcphdr *th = tcp_hdr(skb);
@@ -3828,6 +3828,11 @@ void tcp_parse_options(const struct sk_buff *skb,
 						ptr + 2, th->syn, foc, true);
 				break;
 
+			default:
+				tcp_extra_options_parse(opcode, opsize, ptr,
+							skb, opt_rx, tp);
+				break;
+
 			}
 			ptr += opsize-2;
 			length -= opsize;
@@ -3873,7 +3878,7 @@ static bool tcp_fast_parse_options(const struct sk_buff *skb,
 			return true;
 	}
 
-	tcp_parse_options(skb, &tp->rx_opt, 1, NULL);
+	tcp_parse_options(skb, &tp->rx_opt, 1, NULL, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -5600,7 +5605,7 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,
 		/* Get original SYNACK MSS value if user MSS sets mss_clamp */
 		tcp_clear_options(&opt);
 		opt.user_mss = opt.mss_clamp = 0;
-		tcp_parse_options(synack, &opt, 0, NULL);
+		tcp_parse_options(synack, &opt, 0, NULL, tp);
 		mss = opt.mss_clamp;
 	}
 
@@ -5653,7 +5658,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 	struct tcp_fastopen_cookie foc = { .len = -1 };
 	int saved_clamp = tp->rx_opt.mss_clamp;
 
-	tcp_parse_options(skb, &tp->rx_opt, 0, &foc);
+	tcp_parse_options(skb, &tp->rx_opt, 0, &foc, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -6316,7 +6321,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
 	tmp_opt.user_mss  = tp->rx_opt.user_mss;
-	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc);
+	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc, tp);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
net/ipv4/tcp_minisocks.c +2 -2
index 8f6373b0cd77..c51bb1b30f08 100644
@@ -98,7 +98,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			if (tmp_opt.rcv_tsecr)
@@ -558,7 +558,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(struct tcphdr)>>2)) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent = req->ts_recent;
net/ipv4/tcp_output.c +18 -17
index ffc9274b2706..840883531996 100644
@@ -41,6 +41,7 @@
 #include <linux/compiler.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
+#include <linux/static_key.h>
 
 /* People can turn this off for buggy TCP's found in printers etc. */
 int sysctl_tcp_retrans_collapse __read_mostly = 1;
@@ -411,23 +412,6 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
 	return tp->snd_una != tp->snd_up;
 }
 
-#define OPTION_SACK_ADVERTISE	(1 << 0)
-#define OPTION_TS		(1 << 1)
-#define OPTION_MD5		(1 << 2)
-#define OPTION_WSCALE		(1 << 3)
-#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
-
-struct tcp_out_options {
-	u16 options;		/* bit field of OPTION_* */
-	u16 mss;		/* 0 to disable */
-	u8 ws;			/* window scale, 0 to disable */
-	u8 num_sack_blocks;	/* number of SACK blocks to include */
-	u8 hash_size;		/* bytes in hash_location */
-	__u8 *hash_location;	/* temporary pointer, overloaded */
-	__u32 tsval, tsecr;	/* need to include OPTION_TS */
-	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
-};
-
 /* Write previously computed TCP options to the packet.
  *
  * Beware: Something in the Internet is very sensitive to the ordering of
@@ -534,6 +518,9 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
 		}
 		ptr += (len + 3) >> 2;
 	}
+
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		tcp_extra_options_write(ptr, opts, tp);
 }
 
 /* Compute TCP options for SYN packets. This is not the final
@@ -601,6 +588,10 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare(skb, TCPHDR_SYN,
+						       remaining, opts, tp);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -661,6 +652,13 @@ static unsigned int tcp_synack_options(struct request_sock *req,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare_req(skb,
+							   TCPHDR_SYN |
+							   TCPHDR_ACK,
+							   remaining, opts,
+							   req);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -694,6 +692,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		size += TCPOLEN_TSTAMP_ALIGNED;
 	}
 
+	size += tcp_extra_options_prepare(skb, 0, MAX_TCP_OPTION_SPACE - size,
+					  opts, tp);
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
net/ipv6/syncookies.c +1 -1
index 895ff650db43..1c246a8f41c3 100644
@@ -160,7 +160,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
Signature · 6 lines
2.12.2

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
author
#11 lore raw
Quoted 241 lines · Christoph Paasch
Quoted 239 lines · Mat Martineau

Allow additional TCP options to be handled by registered hook functions.

Option parsing will call the provided 'parse' function when a TCP option number is not recognized by the normal option parsing code.

The 'prepare' and 'prepare_req' functions determine the required space for registered options and store associated data. There are two variants because options must be generated for connections that are associated with either tcp_sock or request_sock structures.

A static key and RCU synchronization are used to minimize the performance impact of these extensible TCP features.

Before this is posted upstream, I plan to split the patch in two parts (at least), since making tcp_out_options public should be separate. The extra parameter for tcp_parse_options may also warrant its own patch. I'd also like to discuss where to store information for the options that are parsed or generated using these hooks, since the tcp_options_received and tcp_out_options structs don't have places to store extra information yet.

I've confirmed that this code builds, but haven't tested yet.

This commit is also available at
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
branch: mptcp

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 drivers/infiniband/hw/cxgb4/cm.c |   2 +-
 include/linux/tcp.h              |  17 +++++
 include/net/tcp.h                |  48 +++++++++++++-
 net/ipv4/syncookies.c            |   2 +-
 net/ipv4/tcp.c                   | 135 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/tcp_input.c             |  15 +++--
 net/ipv4/tcp_minisocks.c         |   4 +-
 net/ipv4/tcp_output.c            |  35 +++++-----
 net/ipv6/syncookies.c            |   2 +-
 9 files changed, 232 insertions(+), 28 deletions(-)
drivers/infiniband/hw/cxgb4/cm.c +1 -1
index 03a1b0e64fc3..1d1dbfdf5a05 100644
@@ -3748,7 +3748,7 @@ static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
 	 */
 	memset(&tmp_opt, 0, sizeof(tmp_opt));
 	tcp_clear_options(&tmp_opt);
-	tcp_parse_options(skb, &tmp_opt, 0, NULL);
+	tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 	req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
 	memset(req, 0, sizeof(*req));
include/linux/tcp.h +17 -0
index cfc2d9506ce8..9e625a68f5e1 100644
@@ -112,6 +112,23 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 	rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
 }
 
+#define OPTION_SACK_ADVERTISE	(1 << 0)
+#define OPTION_TS		(1 << 1)
+#define OPTION_MD5		(1 << 2)
+#define OPTION_WSCALE		(1 << 3)
+#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
+
+struct tcp_out_options {
+	u16 options;		/* bit field of OPTION_* */
+	u16 mss;		/* 0 to disable */
+	u8 ws;			/* window scale, 0 to disable */
+	u8 num_sack_blocks;	/* number of SACK blocks to include */
+	u8 hash_size;		/* bytes in hash_location */
+	__u8 *hash_location;	/* temporary pointer, overloaded */
+	__u32 tsval, tsecr;	/* need to include OPTION_TS */
+	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
+};
+
 /* This is the max number of SACKS that we'll generate and process. It's safe
  * to increase this, although since:
  *   size = TCPOLEN_SACK_BASE_ALIGNED (4) + n * TCPOLEN_SACK_PERBLOCK (8)
include/net/tcp.h +47 -1
index cc6ae0a95201..36785427ae90 100644
@@ -429,7 +429,8 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
 		int flags, int *addr_len);
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx,
-		       int estab, struct tcp_fastopen_cookie *foc);
+		       int estab, struct tcp_fastopen_cookie *foc,
+		       struct tcp_sock *tp);
 const u8 *tcp_parse_md5sig_option(const struct tcphdr *th);
 
 /*
@@ -1937,4 +1938,49 @@ static inline void tcp_listendrop(const struct sock *sk)
 	__NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS);
 }
 
+extern struct static_key_false tcp_extra_options_enabled;
+
+struct tcp_extra_option_ops {
+	struct list_head	list;
+	unsigned char		option_kind;
+	void (*parse)(int opsize, const unsigned char *opptr,
+		      const struct sk_buff *skb,
+		      struct tcp_options_received *opt_rx,
+		      struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare)(struct sk_buff *skb, u8 flags,
+				unsigned int remaining,
+				struct tcp_out_options *opts,
+				struct tcp_sock *tp);
+	/* Return the number of bytes consumed */
+	unsigned int (*prepare_req)(struct sk_buff *skb, u8 flags,
+				    unsigned int remaining,
+				    struct tcp_out_options *opts,
+				    struct request_sock *req);
+	void (*write)(__be32 *ptr, struct tcp_out_options *opts,
+		      struct tcp_sock *tp);
+	struct module		*owner;
+};
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp);
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req);
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp);
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops);
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops);
+
 #endif	/* _TCP_H */
net/ipv4/syncookies.c +1 -1
index 496b97e17aaf..5697083a2c77 100644
@@ -309,7 +309,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
net/ipv4/tcp.c +58 -0
index 04843ae77b9e..e0d0504f005a 100644
@@ -269,6 +269,7 @@
 #include <linux/err.h>
 #include <linux/time.h>
 #include <linux/slab.h>
+#include <linux/static_key.h>
 
 #include <net/icmp.h>
 #include <net/inet_common.h>
@@ -306,6 +307,13 @@ struct percpu_counter tcp_sockets_allocated;
 EXPORT_SYMBOL(tcp_sockets_allocated);
 
 /*
+ * Optional TCP option handlers
+ */
+static DEFINE_SPINLOCK(tcp_option_list_lock);
+static LIST_HEAD(tcp_option_list);
+DEFINE_STATIC_KEY_FALSE(tcp_extra_options_enabled);
+
+/*
  * TCP splice context
  */
 struct tcp_splice_state {
@@ -3279,6 +3287,132 @@ EXPORT_SYMBOL(tcp_md5_hash_key);
 
 #endif
 
+/* Linear search, few entries are expected. The RCU read lock must
+ * be held before calling.
+ */
+static struct tcp_extra_option_ops *tcp_extra_options_find_kind(unsigned char kind)
+{
+	struct tcp_extra_option_ops *entry;
+
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (entry->option_kind == kind)
+			return entry;
+	}
+
+	return NULL;
+}
+
+void tcp_extra_options_parse(int opcode, int opsize, const unsigned char *opptr,
+			     const struct sk_buff *skb,
+			     struct tcp_options_received *opt_rx,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	entry = tcp_extra_options_find_kind(opcode);
+	if (entry && entry->parse)
+		entry->parse(opsize, opptr, skb, opt_rx, tp);
+	rcu_read_unlock();
+}
+
+unsigned int tcp_extra_options_prepare(struct sk_buff *skb, u8 flags,
+				       unsigned int remaining,
+				       struct tcp_out_options *opts,
+				       struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare))
+			continue;
+
+		used += entry->prepare(skb, flags, remaining - used, opts, tp);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+unsigned int tcp_extra_options_prepare_req(struct sk_buff *skb, u8 flags,
Quoted 8 lines

net/ipv4/tcp.c EXPORT_SYMBOL(tcp_md5_hash_key); · line 3342

Quoted 3 lines
net/ipv4/tcp.c +3 -0
+					   unsigned int remaining,
+					   struct tcp_out_options *opts,
+					   struct request_sock *req)

As request-sockets are also just regular struct sock_common, I think you can get rid of tcp_extra_options_prepare_req() and in tcp_synack_options() just convert the struct request_sock to struct sock. Users of the API then need to check with sk->sk_state what kind of socket it really is.

I would definitely prefer to have one prepare function to call - I'll check this out and update the patch.

Quoted 2 lines

Also, you probably should add something similar for tcp_v4_send_ack(), tcp_v4_send_reset() and the IPv6 counterparts.

Thanks for pointing that out, I was too focused on callers of tcp_options_write.

Quoted 2 lines

TCP_MD5 has also some ugly hooks in tcp_v4_send_ack(), so the netdev community might like it if they go away.

Yes, that would be a good way to sell them on the change. That will help me figure out the best way to handle the send_ack/send_reset calls too - not clear whether those need something a little different from the normal prepare/write hooks.

Thanks!

Mat

Quoted 264 lines
Quoted 264 lines
net/ipv4/tcp.c +74 -0
+{
+	struct tcp_extra_option_ops *entry;
+	unsigned int used = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->prepare_req))
+			continue;
+
+		used += entry->prepare_req(skb, flags, remaining - used, opts,
+					   req);
+	}
+	rcu_read_unlock();
+
+	return used;
+}
+
+void tcp_extra_options_write(__be32 *ptr, struct tcp_out_options *opts,
+			     struct tcp_sock *tp)
+{
+	struct tcp_extra_option_ops *entry;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &tcp_option_list, list) {
+		if (unlikely(!entry->write))
+			continue;
+
+		entry->write(ptr, opts, tp);
+	}
+	rcu_read_unlock();
+}
+
+int tcp_register_extra_option(struct tcp_extra_option_ops *ops)
+{
+	int ret = 0;
+
+	if (!ops->option_kind)
+		return -EINVAL;
+
+	if (!try_module_get(ops->owner))
+		return -ENOENT;
+
+	spin_lock(&tcp_option_list_lock);
+	if (tcp_extra_options_find_kind(ops->option_kind)) {
+		pr_notice("Option kind %u already registered\n",
+			  ops->option_kind);
+		spin_unlock(&tcp_option_list_lock);
+		module_put(ops->owner);
+		return -EEXIST;
+	}
+
+	list_add_tail_rcu(&ops->list, &tcp_option_list);
+	pr_debug("Option kind %u registered\n", ops->option_kind);
+	spin_unlock(&tcp_option_list_lock);
+
+	static_branch_inc(&tcp_extra_options_enabled);
+
+	return ret;
+}
+
+void tcp_unregister_extra_option(struct tcp_extra_option_ops *ops)
+{
+	spin_lock(&tcp_option_list_lock);
+	list_del_rcu(&ops->list);
+	spin_unlock(&tcp_option_list_lock);
+
+	synchronize_net();
+
+	static_branch_dec(&tcp_extra_options_enabled);
+
+	module_put(ops->owner);
+}
+
 void tcp_done(struct sock *sk)
 {
 	struct request_sock *req = tcp_sk(sk)->fastopen_rsk;
@@ -3425,6 +3559,7 @@ void __init tcp_init(void)
 		INIT_HLIST_HEAD(&tcp_hashinfo.bhash[i].chain);
 	}
 
+	INIT_LIST_HEAD(&tcp_option_list);
 
 	cnt = tcp_hashinfo.ehash_mask + 1;
 	sysctl_tcp_max_orphans = cnt / 2;
net/ipv4/tcp_input.c +10 -5
index a5838858c362..13ab3dff7c3f 100644
@@ -3726,7 +3726,7 @@ static void tcp_parse_fastopen_option(int len, const unsigned char *cookie,
  */
 void tcp_parse_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx, int estab,
-		       struct tcp_fastopen_cookie *foc)
+		       struct tcp_fastopen_cookie *foc, struct tcp_sock *tp)
 {
 	const unsigned char *ptr;
 	const struct tcphdr *th = tcp_hdr(skb);
@@ -3828,6 +3828,11 @@ void tcp_parse_options(const struct sk_buff *skb,
 						ptr + 2, th->syn, foc, true);
 				break;
 
+			default:
+				tcp_extra_options_parse(opcode, opsize, ptr,
+							skb, opt_rx, tp);
+				break;
+
 			}
 			ptr += opsize-2;
 			length -= opsize;
@@ -3873,7 +3878,7 @@ static bool tcp_fast_parse_options(const struct sk_buff *skb,
 			return true;
 	}
 
-	tcp_parse_options(skb, &tp->rx_opt, 1, NULL);
+	tcp_parse_options(skb, &tp->rx_opt, 1, NULL, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -5600,7 +5605,7 @@ static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,
 		/* Get original SYNACK MSS value if user MSS sets mss_clamp */
 		tcp_clear_options(&opt);
 		opt.user_mss = opt.mss_clamp = 0;
-		tcp_parse_options(synack, &opt, 0, NULL);
+		tcp_parse_options(synack, &opt, 0, NULL, tp);
 		mss = opt.mss_clamp;
 	}
 
@@ -5653,7 +5658,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 	struct tcp_fastopen_cookie foc = { .len = -1 };
 	int saved_clamp = tp->rx_opt.mss_clamp;
 
-	tcp_parse_options(skb, &tp->rx_opt, 0, &foc);
+	tcp_parse_options(skb, &tp->rx_opt, 0, &foc, tp);
 	if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr)
 		tp->rx_opt.rcv_tsecr -= tp->tsoffset;
 
@@ -6316,7 +6321,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
 	tmp_opt.user_mss  = tp->rx_opt.user_mss;
-	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc);
+	tcp_parse_options(skb, &tmp_opt, 0, want_cookie ? NULL : &foc, tp);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
net/ipv4/tcp_minisocks.c +2 -2
index 8f6373b0cd77..c51bb1b30f08 100644
@@ -98,7 +98,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			if (tmp_opt.rcv_tsecr)
@@ -558,7 +558,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(struct tcphdr)>>2)) {
-		tcp_parse_options(skb, &tmp_opt, 0, NULL);
+		tcp_parse_options(skb, &tmp_opt, 0, NULL, NULL);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent = req->ts_recent;
net/ipv4/tcp_output.c +18 -17
index ffc9274b2706..840883531996 100644
@@ -41,6 +41,7 @@
 #include <linux/compiler.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
+#include <linux/static_key.h>
 
 /* People can turn this off for buggy TCP's found in printers etc. */
 int sysctl_tcp_retrans_collapse __read_mostly = 1;
@@ -411,23 +412,6 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
 	return tp->snd_una != tp->snd_up;
 }
 
-#define OPTION_SACK_ADVERTISE	(1 << 0)
-#define OPTION_TS		(1 << 1)
-#define OPTION_MD5		(1 << 2)
-#define OPTION_WSCALE		(1 << 3)
-#define OPTION_FAST_OPEN_COOKIE	(1 << 8)
-
-struct tcp_out_options {
-	u16 options;		/* bit field of OPTION_* */
-	u16 mss;		/* 0 to disable */
-	u8 ws;			/* window scale, 0 to disable */
-	u8 num_sack_blocks;	/* number of SACK blocks to include */
-	u8 hash_size;		/* bytes in hash_location */
-	__u8 *hash_location;	/* temporary pointer, overloaded */
-	__u32 tsval, tsecr;	/* need to include OPTION_TS */
-	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
-};
-
 /* Write previously computed TCP options to the packet.
  *
  * Beware: Something in the Internet is very sensitive to the ordering of
@@ -534,6 +518,9 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
 		}
 		ptr += (len + 3) >> 2;
 	}
+
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		tcp_extra_options_write(ptr, opts, tp);
 }
 
 /* Compute TCP options for SYN packets. This is not the final
@@ -601,6 +588,10 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare(skb, TCPHDR_SYN,
+						       remaining, opts, tp);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -661,6 +652,13 @@ static unsigned int tcp_synack_options(struct request_sock *req,
 		}
 	}
 
+	if (static_branch_unlikely(&tcp_extra_options_enabled))
+		remaining -= tcp_extra_options_prepare_req(skb,
+							   TCPHDR_SYN |
+							   TCPHDR_ACK,
+							   remaining, opts,
+							   req);
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -694,6 +692,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		size += TCPOLEN_TSTAMP_ALIGNED;
 	}
 
+	size += tcp_extra_options_prepare(skb, 0, MAX_TCP_OPTION_SPACE - size,
+					  opts, tp);
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
net/ipv6/syncookies.c +1 -2
index 895ff650db43..1c246a8f41c3 100644
@@ -160,7 +160,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0, NULL);
+	tcp_parse_options(skb, &tcp_opt, 0, NULL, tp);
 
 	if (!cookie_timestamp_decode(&tcp_opt))
 		goto out;
--

2.12.2

Quoted 5 lines
Quoted 4 lines

_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp

--
Mat Martineau
Intel OTC