Skip to content

Commit f930103

Browse files
edumazetdavem330
authored andcommitted
tcp: Namespaceify sysctl_tcp_sack
Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent eed29f1 commit f930103

8 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎include/net/netns/ipv4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct netns_ipv4 {
122122
int sysctl_tcp_fin_timeout;
123123
unsigned int sysctl_tcp_notsent_lowat;
124124
int sysctl_tcp_tw_reuse;
125+
int sysctl_tcp_sack;
125126
struct inet_timewait_death_row tcp_death_row;
126127
int sysctl_max_syn_backlog;
127128

‎include/net/tcp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
239239
/* sysctl variables for tcp */
240240
extern int sysctl_tcp_timestamps;
241241
extern int sysctl_tcp_window_scaling;
242-
extern int sysctl_tcp_sack;
243242
extern int sysctl_tcp_fastopen;
244243
extern int sysctl_tcp_retrans_collapse;
245244
extern int sysctl_tcp_stdurg;
@@ -520,7 +519,8 @@ u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
520519
u16 *mssp);
521520
__u32 cookie_v4_init_sequence(const struct sk_buff *skb, __u16 *mss);
522521
u64 cookie_init_timestamp(struct request_sock *req);
523-
bool cookie_timestamp_decode(struct tcp_options_received *opt);
522+
bool cookie_timestamp_decode(const struct net *net,
523+
struct tcp_options_received *opt);
524524
bool cookie_ecn_ok(const struct tcp_options_received *opt,
525525
const struct net *net, const struct dst_entry *dst);
526526

‎net/ipv4/syncookies.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ EXPORT_SYMBOL(tcp_get_cookie_sock);
232232
* return false if we decode a tcp option that is disabled
233233
* on the host.
234234
*/
235-
bool cookie_timestamp_decode(struct tcp_options_received *tcp_opt)
235+
bool cookie_timestamp_decode(const struct net *net,
236+
struct tcp_options_received *tcp_opt)
236237
{
237238
/* echoed timestamp, lowest bits contain options */
238239
u32 options = tcp_opt->rcv_tsecr;
@@ -247,7 +248,7 @@ bool cookie_timestamp_decode(struct tcp_options_received *tcp_opt)
247248

248249
tcp_opt->sack_ok = (options & TS_OPT_SACK) ? TCP_SACK_SEEN : 0;
249250

250-
if (tcp_opt->sack_ok && !sysctl_tcp_sack)
251+
if (tcp_opt->sack_ok && !net->ipv4.sysctl_tcp_sack)
251252
return false;
252253

253254
if ((options & TS_OPT_WSCALE_MASK) == TS_OPT_WSCALE_MASK)
@@ -319,7 +320,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
319320
tcp_opt.rcv_tsecr -= tsoff;
320321
}
321322

322-
if (!cookie_timestamp_decode(&tcp_opt))
323+
if (!cookie_timestamp_decode(sock_net(sk), &tcp_opt))
323324
goto out;
324325

325326
ret = NULL;

‎net/ipv4/sysctl_net_ipv4.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,6 @@ static struct ctl_table ipv4_table[] = {
378378
.mode = 0644,
379379
.proc_handler = proc_dointvec
380380
},
381-
{
382-
.procname = "tcp_sack",
383-
.data = &sysctl_tcp_sack,
384-
.maxlen = sizeof(int),
385-
.mode = 0644,
386-
.proc_handler = proc_dointvec
387-
},
388381
{
389382
.procname = "tcp_retrans_collapse",
390383
.data = &sysctl_tcp_retrans_collapse,
@@ -1116,6 +1109,13 @@ static struct ctl_table ipv4_net_table[] = {
11161109
.extra2 = &one,
11171110
},
11181111
#endif
1112+
{
1113+
.procname = "tcp_sack",
1114+
.data = &init_net.ipv4.sysctl_tcp_sack,
1115+
.maxlen = sizeof(int),
1116+
.mode = 0644,
1117+
.proc_handler = proc_dointvec
1118+
},
11191119
{ }
11201120
};
11211121

‎net/ipv4/tcp_input.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878

7979
int sysctl_tcp_timestamps __read_mostly = 1;
8080
int sysctl_tcp_window_scaling __read_mostly = 1;
81-
int sysctl_tcp_sack __read_mostly = 1;
8281
int sysctl_tcp_fack __read_mostly;
8382
int sysctl_tcp_max_reordering __read_mostly = 300;
8483
int sysctl_tcp_dsack __read_mostly = 1;
@@ -3790,7 +3789,7 @@ void tcp_parse_options(const struct net *net,
37903789
break;
37913790
case TCPOPT_SACK_PERM:
37923791
if (opsize == TCPOLEN_SACK_PERM && th->syn &&
3793-
!estab && sysctl_tcp_sack) {
3792+
!estab && net->ipv4.sysctl_tcp_sack) {
37943793
opt_rx->sack_ok = TCP_SACK_SEEN;
37953794
tcp_sack_reset(opt_rx);
37963795
}

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,7 @@ static int __net_init tcp_sk_init(struct net *net)
24652465
net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;
24662466

24672467
net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 256);
2468+
net->ipv4.sysctl_tcp_sack = 1;
24682469

24692470
return 0;
24702471
fail:

‎net/ipv4/tcp_output.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
580580
opts->options |= OPTION_WSCALE;
581581
remaining -= TCPOLEN_WSCALE_ALIGNED;
582582
}
583-
if (likely(sysctl_tcp_sack)) {
583+
if (likely(sock_net(sk)->ipv4.sysctl_tcp_sack)) {
584584
opts->options |= OPTION_SACK_ADVERTISE;
585585
if (unlikely(!(OPTION_TS & opts->options)))
586586
remaining -= TCPOLEN_SACKPERM_ALIGNED;

‎net/ipv6/syncookies.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
170170
tcp_opt.rcv_tsecr -= tsoff;
171171
}
172172

173-
if (!cookie_timestamp_decode(&tcp_opt))
173+
if (!cookie_timestamp_decode(sock_net(sk), &tcp_opt))
174174
goto out;
175175

176176
ret = NULL;

0 commit comments

Comments
 (0)