aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/tcp.h
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2014-09-26 16:37:33 -0400
committerDavid S. Miller <davem@davemloft.net>2014-09-29 00:13:10 -0400
commit30e502a34b8b21fae2c789da102bd9f6e99fef83 (patch)
tree6a56bc051b629e3c0914c3a519d201f357e79ada /include/net/tcp.h
parent55d8694fa82c9b5858ae5a78a210353961f908f9 (diff)
net: tcp: add flag for ca to indicate that ECN is required
This patch adds a flag to TCP congestion algorithms that allows for requesting to mark IPv4/IPv6 sockets with transport as ECN capable, that is, ECT(0), when required by a congestion algorithm. It is currently used and needed in DataCenter TCP (DCTCP), as it requires both peers to assert ECT on all IP packets sent - it uses ECN feedback (i.e. CE, Congestion Encountered information) from switches inside the data center to derive feedback to the end hosts. Therefore, simply add a new flag to icsk_ca_ops. Note that DCTCP's algorithm/behaviour slightly diverges from RFC3168, therefore this is only (!) enabled iff the assigned congestion control ops module has requested this. By that, we can tightly couple this logic really only to the provided congestion control ops. Joint work with Florian Westphal and Glenn Judd. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Glenn Judd <glenn.judd@morganstanley.com> Acked-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r--include/net/tcp.h61
1 files changed, 44 insertions, 17 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index f99b0c072ee5..a12f145cfbc3 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -733,23 +733,6 @@ struct tcp_skb_cb {
733 733
734#define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) 734#define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
735 735
736/* RFC3168 : 6.1.1 SYN packets must not have ECT/ECN bits set
737 *
738 * If we receive a SYN packet with these bits set, it means a network is
739 * playing bad games with TOS bits. In order to avoid possible false congestion
740 * notifications, we disable TCP ECN negociation.
741 */
742static inline void
743TCP_ECN_create_request(struct request_sock *req, const struct sk_buff *skb,
744 struct net *net)
745{
746 const struct tcphdr *th = tcp_hdr(skb);
747
748 if (net->ipv4.sysctl_tcp_ecn && th->ece && th->cwr &&
749 INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield))
750 inet_rsk(req)->ecn_ok = 1;
751}
752
753/* Due to TSO, an SKB can be composed of multiple actual 736/* Due to TSO, an SKB can be composed of multiple actual
754 * packets. To keep these tracked properly, we use this. 737 * packets. To keep these tracked properly, we use this.
755 */ 738 */
@@ -791,7 +774,10 @@ enum tcp_ca_event {
791#define TCP_CA_MAX 128 774#define TCP_CA_MAX 128
792#define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) 775#define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX)
793 776
777/* Algorithm can be set on socket without CAP_NET_ADMIN privileges */
794#define TCP_CONG_NON_RESTRICTED 0x1 778#define TCP_CONG_NON_RESTRICTED 0x1
779/* Requires ECN/ECT set on all packets */
780#define TCP_CONG_NEEDS_ECN 0x2
795 781
796struct tcp_congestion_ops { 782struct tcp_congestion_ops {
797 struct list_head list; 783 struct list_head list;
@@ -840,6 +826,13 @@ u32 tcp_reno_ssthresh(struct sock *sk);
840void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked); 826void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked);
841extern struct tcp_congestion_ops tcp_reno; 827extern struct tcp_congestion_ops tcp_reno;
842 828
829static inline bool tcp_ca_needs_ecn(const struct sock *sk)
830{
831 const struct inet_connection_sock *icsk = inet_csk(sk);
832
833 return icsk->icsk_ca_ops->flags & TCP_CONG_NEEDS_ECN;
834}
835
843static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) 836static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state)
844{ 837{
845 struct inet_connection_sock *icsk = inet_csk(sk); 838 struct inet_connection_sock *icsk = inet_csk(sk);
@@ -857,6 +850,40 @@ static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event)
857 icsk->icsk_ca_ops->cwnd_event(sk, event); 850 icsk->icsk_ca_ops->cwnd_event(sk, event);
858} 851}
859 852
853/* RFC3168 : 6.1.1 SYN packets must not have ECT/ECN bits set
854 *
855 * If we receive a SYN packet with these bits set, it means a
856 * network is playing bad games with TOS bits. In order to
857 * avoid possible false congestion notifications, we disable
858 * TCP ECN negociation.
859 *
860 * Exception: tcp_ca wants ECN. This is required for DCTCP
861 * congestion control; it requires setting ECT on all packets,
862 * including SYN. We inverse the test in this case: If our
863 * local socket wants ECN, but peer only set ece/cwr (but not
864 * ECT in IP header) its probably a non-DCTCP aware sender.
865 */
866static inline void
867TCP_ECN_create_request(struct request_sock *req, const struct sk_buff *skb,
868 const struct sock *listen_sk)
869{
870 const struct tcphdr *th = tcp_hdr(skb);
871 const struct net *net = sock_net(listen_sk);
872 bool th_ecn = th->ece && th->cwr;
873 bool ect, need_ecn;
874
875 if (!th_ecn)
876 return;
877
878 ect = !INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield);
879 need_ecn = tcp_ca_needs_ecn(listen_sk);
880
881 if (!ect && !need_ecn && net->ipv4.sysctl_tcp_ecn)
882 inet_rsk(req)->ecn_ok = 1;
883 else if (ect && need_ecn)
884 inet_rsk(req)->ecn_ok = 1;
885}
886
860/* These functions determine how the current flow behaves in respect of SACK 887/* These functions determine how the current flow behaves in respect of SACK
861 * handling. SACK is negotiated with the peer, and therefore it can vary 888 * handling. SACK is negotiated with the peer, and therefore it can vary
862 * between different flows. 889 * between different flows.