aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_output.c
diff options
context:
space:
mode:
authorUrsula Braun <ubraun@linux.vnet.ibm.com>2017-10-25 05:01:45 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-26 05:00:29 -0400
commit60e2a7780793bae0debc275a9ccd57f7da0cf195 (patch)
tree8b65c6c4eb3194718df692952e1b5d547c53de2f /net/ipv4/tcp_output.c
parent145686baab68e9c7594fe9269f47da479c25ad79 (diff)
tcp: TCP experimental option for SMC
The SMC protocol [1] relies on the use of a new TCP experimental option [2, 3]. With this option, SMC capabilities are exchanged between peers during the TCP three way handshake. This patch adds support for this experimental option to TCP. References: [1] SMC-R Informational RFC: http://www.rfc-editor.org/info/rfc7609 [2] Shared Use of TCP Experimental Options RFC 6994: https://tools.ietf.org/rfc/rfc6994.txt [3] IANA ExID SMCR: http://www.iana.org/assignments/tcp-parameters/tcp-parameters.xhtml#tcp-exids Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_output.c')
-rw-r--r--net/ipv4/tcp_output.c63
1 files changed, 60 insertions, 3 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 1f01f4c9c738..c8fc512e0bbb 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -41,6 +41,7 @@
41#include <linux/compiler.h> 41#include <linux/compiler.h>
42#include <linux/gfp.h> 42#include <linux/gfp.h>
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/static_key.h>
44 45
45#include <trace/events/tcp.h> 46#include <trace/events/tcp.h>
46 47
@@ -422,6 +423,22 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
422#define OPTION_MD5 (1 << 2) 423#define OPTION_MD5 (1 << 2)
423#define OPTION_WSCALE (1 << 3) 424#define OPTION_WSCALE (1 << 3)
424#define OPTION_FAST_OPEN_COOKIE (1 << 8) 425#define OPTION_FAST_OPEN_COOKIE (1 << 8)
426#define OPTION_SMC (1 << 9)
427
428static void smc_options_write(__be32 *ptr, u16 *options)
429{
430#if IS_ENABLED(CONFIG_SMC)
431 if (static_branch_unlikely(&tcp_have_smc)) {
432 if (unlikely(OPTION_SMC & *options)) {
433 *ptr++ = htonl((TCPOPT_NOP << 24) |
434 (TCPOPT_NOP << 16) |
435 (TCPOPT_EXP << 8) |
436 (TCPOLEN_EXP_SMC_BASE));
437 *ptr++ = htonl(TCPOPT_SMC_MAGIC);
438 }
439 }
440#endif
441}
425 442
426struct tcp_out_options { 443struct tcp_out_options {
427 u16 options; /* bit field of OPTION_* */ 444 u16 options; /* bit field of OPTION_* */
@@ -540,6 +557,41 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
540 } 557 }
541 ptr += (len + 3) >> 2; 558 ptr += (len + 3) >> 2;
542 } 559 }
560
561 smc_options_write(ptr, &options);
562}
563
564static void smc_set_option(const struct tcp_sock *tp,
565 struct tcp_out_options *opts,
566 unsigned int *remaining)
567{
568#if IS_ENABLED(CONFIG_SMC)
569 if (static_branch_unlikely(&tcp_have_smc)) {
570 if (tp->syn_smc) {
571 if (*remaining >= TCPOLEN_EXP_SMC_BASE_ALIGNED) {
572 opts->options |= OPTION_SMC;
573 *remaining -= TCPOLEN_EXP_SMC_BASE_ALIGNED;
574 }
575 }
576 }
577#endif
578}
579
580static void smc_set_option_cond(const struct tcp_sock *tp,
581 const struct inet_request_sock *ireq,
582 struct tcp_out_options *opts,
583 unsigned int *remaining)
584{
585#if IS_ENABLED(CONFIG_SMC)
586 if (static_branch_unlikely(&tcp_have_smc)) {
587 if (tp->syn_smc && ireq->smc_ok) {
588 if (*remaining >= TCPOLEN_EXP_SMC_BASE_ALIGNED) {
589 opts->options |= OPTION_SMC;
590 *remaining -= TCPOLEN_EXP_SMC_BASE_ALIGNED;
591 }
592 }
593 }
594#endif
543} 595}
544 596
545/* Compute TCP options for SYN packets. This is not the final 597/* Compute TCP options for SYN packets. This is not the final
@@ -607,11 +659,14 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
607 } 659 }
608 } 660 }
609 661
662 smc_set_option(tp, opts, &remaining);
663
610 return MAX_TCP_OPTION_SPACE - remaining; 664 return MAX_TCP_OPTION_SPACE - remaining;
611} 665}
612 666
613/* Set up TCP options for SYN-ACKs. */ 667/* Set up TCP options for SYN-ACKs. */
614static unsigned int tcp_synack_options(struct request_sock *req, 668static unsigned int tcp_synack_options(const struct sock *sk,
669 struct request_sock *req,
615 unsigned int mss, struct sk_buff *skb, 670 unsigned int mss, struct sk_buff *skb,
616 struct tcp_out_options *opts, 671 struct tcp_out_options *opts,
617 const struct tcp_md5sig_key *md5, 672 const struct tcp_md5sig_key *md5,
@@ -667,6 +722,8 @@ static unsigned int tcp_synack_options(struct request_sock *req,
667 } 722 }
668 } 723 }
669 724
725 smc_set_option_cond(tcp_sk(sk), ireq, opts, &remaining);
726
670 return MAX_TCP_OPTION_SPACE - remaining; 727 return MAX_TCP_OPTION_SPACE - remaining;
671} 728}
672 729
@@ -3195,8 +3252,8 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
3195 md5 = tcp_rsk(req)->af_specific->req_md5_lookup(sk, req_to_sk(req)); 3252 md5 = tcp_rsk(req)->af_specific->req_md5_lookup(sk, req_to_sk(req));
3196#endif 3253#endif
3197 skb_set_hash(skb, tcp_rsk(req)->txhash, PKT_HASH_TYPE_L4); 3254 skb_set_hash(skb, tcp_rsk(req)->txhash, PKT_HASH_TYPE_L4);
3198 tcp_header_size = tcp_synack_options(req, mss, skb, &opts, md5, foc) + 3255 tcp_header_size = tcp_synack_options(sk, req, mss, skb, &opts, md5,
3199 sizeof(*th); 3256 foc) + sizeof(*th);
3200 3257
3201 skb_push(skb, tcp_header_size); 3258 skb_push(skb, tcp_header_size);
3202 skb_reset_transport_header(skb); 3259 skb_reset_transport_header(skb);