tcp: split tcp_ecn sysctl knob to distinguish between IPv4 and IPv6
Subsystems (4)
PATCH 1/1 tcp: split tcp_ecn sysctl knob to distinguish between IPv4 and IPv6
ECN could be more reliable when used with IPv6 (I don't have proofs). For people who want to try ECN with IPv6 but still have problems connecting to destinations because of broken IPv4 routers this switch allows one to enable ECN just for IPv6.
Perhaps ECN could be enabled by default in future.
--- include/net/sock.h | 1 + include/net/tcp.h | 8 +++++--- net/ipv4/syncookies.c | 6 ++++-- net/ipv4/sysctl_net_ipv4.c | 2 +- net/ipv4/tcp_input.c | 2 -- net/ipv4/tcp_ipv4.c | 3 ++- net/ipv4/tcp_output.c | 2 +- net/ipv6/syncookies.c | 3 ++- net/ipv6/sysctl_net_ipv6.c | 8 ++++++++ net/ipv6/tcp_ipv6.c | 4 +++- 10 files changed, 27 insertions(+), 12 deletions(-)
include/net/sock.h +1 -0
@@ -944,6 +944,7 @@ struct proto {int *sysctl_rmem;int max_header;bool no_autobind; +int ecn;struct kmem_cache *slab;unsigned int obj_size;
include/net/tcp.h +5 -3
@@ -266,7 +266,6 @@ extern int sysctl_tcp_abort_on_overflow;extern int sysctl_tcp_max_orphans;extern int sysctl_tcp_fack;extern int sysctl_tcp_reordering; -extern int sysctl_tcp_ecn;extern int sysctl_tcp_dsack;extern int sysctl_tcp_wmem[3 ];extern int sysctl_tcp_rmem[3 ];
@@ -351,6 +350,7 @@ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk) }extern struct proto tcp_prot; +extern struct proto tcpv6_prot;#define TCP_INC_STATS (net, field) SNMP_INC_STATS((net)->mib.tcp_statistics, field)#define TCP_INC_STATS_BH (net, field) SNMP_INC_STATS_BH((net)->mib.tcp_statistics, field)
@@ -504,7 +504,8 @@ static inline __u32 cookie_v4_init_sequence(struct sock *sk,#endif extern __u32 cookie_init_timestamp (struct request_sock *req); -extern bool cookie_check_timestamp (struct tcp_options_received *opt,bool *); +extern bool cookie_check_timestamp (struct tcp_options_received *opt, +int sysctl_tcp_ecn,bool *ecn_ok);/* From net/ipv6/syncookies.c */ extern struct sock *cookie_v6_check (struct sock *sk,struct sk_buff *skb);
@@ -728,7 +729,8 @@ struct tcp_skb_cb {* notifications, we disable TCP ECN negociation. */ static inline void -TCP_ECN_create_request (struct request_sock *req,const struct sk_buff *skb) +TCP_ECN_create_request (struct request_sock *req, +const struct sk_buff *skb,int sysctl_tcp_ecn) {const struct tcphdr *th =tcp_hdr (skb);
net/ipv4/syncookies.c +4 -2
@@ -232,7 +232,8 @@ static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,* * return false if we decode an option that should not be. */ -bool cookie_check_timestamp (struct tcp_options_received *tcp_opt,bool *ecn_ok) +bool cookie_check_timestamp (struct tcp_options_received *tcp_opt, +int sysctl_tcp_ecn,bool *ecn_ok) {/* echoed timestamp, lowest bits contain options */ u32 options = tcp_opt->rcv_tsecr &TSMASK ;
@@ -278,6 +279,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,struct rtable *rt;__u8 rcv_wscale;bool ecn_ok = false; +int sysctl_tcp_ecn = sk->sk_prot->ecn;struct flowi4 fl4;if (!sysctl_tcp_syncookies || !th->ack || th->rst)
@@ -295,7 +297,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,memset (&tcp_opt,0 ,sizeof (tcp_opt));tcp_parse_options (skb, &tcp_opt, &hash_location,0 ,NULL ); -if (!cookie_check_timestamp (&tcp_opt, &ecn_ok)) +if (!cookie_check_timestamp (&tcp_opt, sysctl_tcp_ecn, &ecn_ok)) goto out; ret =NULL ;
net/ipv4/sysctl_net_ipv4.c +1 -1
@@ -539,7 +539,7 @@ static struct ctl_table ipv4_table[] = { }, { .procname = "tcp_ecn", - .data = &sysctl_tcp_ecn, + .data = &tcp_prot.ecn, .maxlen = sizeof(int), .mode =0644 , .proc_handler = proc_dointvec
net/ipv4/tcp_input.c +0 -2
@@ -81,8 +81,6 @@ int sysctl_tcp_sack __read_mostly = 1;int sysctl_tcp_fack__read_mostly =1 ;int sysctl_tcp_reordering__read_mostly =TCP_FASTRETRANS_THRESH ;EXPORT_SYMBOL (sysctl_tcp_reordering); -int sysctl_tcp_ecn__read_mostly =2 ; -EXPORT_SYMBOL (sysctl_tcp_ecn);int sysctl_tcp_dsack__read_mostly =1 ;int sysctl_tcp_app_win__read_mostly =31 ;int sysctl_tcp_adv_win_scale__read_mostly =1 ;
net/ipv4/tcp_ipv4.c +2 -1
@@ -1568,7 +1568,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) goto drop_and_free;if (!want_cookie || tmp_opt.tstamp_ok) -TCP_ECN_create_request (req, skb); +TCP_ECN_create_request (req, skb, tcp_prot.ecn);if (want_cookie) { isn =cookie_v4_init_sequence (sk, skb, &req->mss);
@@ -2874,6 +2874,7 @@ struct proto tcp_prot = { .rsk_prot = &tcp_request_sock_ops, .h.hashinfo = &tcp_hashinfo, .no_autobind = true, + .ecn =2 , #ifdef CONFIG_COMPAT .compat_setsockopt = compat_tcp_setsockopt, .compat_getsockopt = compat_tcp_getsockopt,
net/ipv4/tcp_output.c +1 -1
@@ -314,7 +314,7 @@ static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk); tp->ecn_flags =0 ; -if (sysctl_tcp_ecn ==1 ) { +if (sk->sk_prot->ecn ==1 ) {TCP_SKB_CB (skb)->tcp_flags |=TCPHDR_ECE |TCPHDR_CWR ; tp->ecn_flags =TCP_ECN_OK ; }
net/ipv6/syncookies.c +2 -1
@@ -163,6 +163,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)struct dst_entry *dst;__u8 rcv_wscale;bool ecn_ok = false; +int sysctl_tcp_ecn = sk->sk_prot->ecn;if (!sysctl_tcp_syncookies || !th->ack || th->rst) goto out;
@@ -179,7 +180,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)memset (&tcp_opt,0 ,sizeof (tcp_opt));tcp_parse_options (skb, &tcp_opt, &hash_location,0 ,NULL ); -if (!cookie_check_timestamp (&tcp_opt, &ecn_ok)) +if (!cookie_check_timestamp (&tcp_opt, sysctl_tcp_ecn, &ecn_ok)) goto out; ret =NULL ;
net/ipv6/sysctl_net_ipv6.c +8 -0
@@ -15,6 +15,7 @@#include <net/ipv6.h> #include <net/addrconf.h> #include <net/inet_frag.h> +#include <net/tcp.h> static ctl_table ipv6_table_template[] = { {
@@ -24,6 +25,13 @@ static ctl_table ipv6_table_template[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "tcp_ecn", + .data = &tcpv6_prot.ecn, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, { } };
net/ipv6/tcp_ipv6.c +3 -1
@@ -1027,7 +1027,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) treq->rmt_addr =ipv6_hdr (skb)->saddr; treq->loc_addr =ipv6_hdr (skb)->daddr;if (!want_cookie || tmp_opt.tstamp_ok) -TCP_ECN_create_request (req, skb); +TCP_ECN_create_request (req, skb, tcpv6_prot.ecn); treq->iif = sk->sk_bound_dev_if;
@@ -1955,6 +1955,7 @@ struct proto tcpv6_prot = { .rsk_prot = &tcp6_request_sock_ops, .h.hashinfo = &tcp_hashinfo, .no_autobind = true, + .ecn =2 , #ifdef CONFIG_COMPAT .compat_setsockopt = compat_tcp_setsockopt, .compat_getsockopt = compat_tcp_getsockopt,
@@ -1963,6 +1964,7 @@ struct proto tcpv6_prot = { .proto_cgroup = tcp_proto_cgroup,#endif }; +EXPORT_SYMBOL (tcpv6_prot);static const struct inet6_protocol tcpv6_protocol = { .early_demux = tcp_v6_early_demux,
include/net/sock.h struct proto { · line 948
Quoted 10 lines · On Mon, 31 Dec 2012 18:35:33 +0100 Hannes Frederic Sowa…
include/net/sock.h +1
-0@@ -944,6 +944,7 @@ struct proto {int *sysctl_rmem;int max_header;bool no_autobind; +int ecn;
Why isn't this a bool?
Quoted 14 lines · Stephen Hemminger
include/net/sock.h struct proto { · line 948
Quoted 10 lines · On Mon, 31 Dec 2012 18:35:33 +0100 Hannes Frederic Sowa…
include/net/sock.h +1
-0@@ -944,6 +944,7 @@ struct proto {int *sysctl_rmem;int max_header;bool no_autobind; +int ecn;Why isn't this a bool?
It is a tristate: disable ecn(0), request ecn(1) and accept ecn(2).
Quoted 8 lines · On Mon, 31 Dec 2012 18:35:33 +0100 Hannes Frederic Sowa…
ECN could be more reliable when used with IPv6 (I don't have proofs). For people who want to try ECN with IPv6 but still have problems connecting to destinations because of broken IPv4 routers this switch allows one to enable ECN just for IPv6.
Perhaps ECN could be enabled by default in future.
Signed-off-by Hannes Frederic Sowa <[email protected]>
Any new or modified sysctl should be documented in:
Documentation/networking/ip-sysctl.txt
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Mon, 31 Dec 2012 18:35:33 +0100 Hannes Frederic Sowa…
ECN could be more reliable when used with IPv6 (I don't have proofs). For people who want to try ECN with IPv6 but still have problems connecting to destinations because of broken IPv4 routers this switch allows one to enable ECN just for IPv6.
Quoted 6 lines
Quoted 3 lines
Perhaps ECN could be enabled by default in future.
Signed-off-by Hannes Frederic Sowa <[email protected]>Any new or modified sysctl should be documented in:
Documentation/networking/ip-sysctl.txt
Ack. I'll wait a bit for further feedback and will submit a -v2 with updated documentation.