Skip to content

Commit 3fd091e

Browse files
Vladislav YasevichDavid S. Miller
authored andcommitted
[SCTP]: Remove multiple levels of msecs to jiffies conversions.
The SCTP sysctl entries are displayed in milliseconds, but stored internally in jiffies. This results in multiple levels of msecs to jiffies conversion and as a result produces a truncation error. This patch makes things consistent in that we store and display defaults in milliseconds and only convert once for use by association. This patch also adds some sane min/max values so that we don't go off the deep end. Signed-off-by: Vladislav Yasevich <[email protected]> Signed-off-by: Sridhar Samudrala <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ce556b3 commit 3fd091e

File tree

6 files changed

+84
-100
lines changed

6 files changed

+84
-100
lines changed

include/net/sctp/constants.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,20 @@ enum { SCTP_MAX_DUP_TSNS = 16 };
264264
enum { SCTP_MAX_GABS = 16 };
265265

266266
/* Heartbeat interval - 30 secs */
267-
#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT (30 * HZ)
267+
#define SCTP_DEFAULT_TIMEOUT_HEARTBEAT (30*1000)
268268

269269
/* Delayed sack timer - 200ms */
270-
#define SCTP_DEFAULT_TIMEOUT_SACK ((200 * HZ) / 1000)
270+
#define SCTP_DEFAULT_TIMEOUT_SACK (200)
271271

272272
/* RTO.Initial - 3 seconds
273273
* RTO.Min - 1 second
274274
* RTO.Max - 60 seconds
275275
* RTO.Alpha - 1/8
276276
* RTO.Beta - 1/4
277277
*/
278-
#define SCTP_RTO_INITIAL (3 * HZ)
279-
#define SCTP_RTO_MIN (1 * HZ)
280-
#define SCTP_RTO_MAX (60 * HZ)
278+
#define SCTP_RTO_INITIAL (3 * 1000)
279+
#define SCTP_RTO_MIN (1 * 1000)
280+
#define SCTP_RTO_MAX (60 * 1000)
281281

282282
#define SCTP_RTO_ALPHA 3 /* 1/8 when converted to right shifts. */
283283
#define SCTP_RTO_BETA 2 /* 1/4 when converted to right shifts. */
@@ -290,8 +290,7 @@ enum { SCTP_MAX_GABS = 16 };
290290
#define SCTP_DEF_MAX_INIT 6
291291
#define SCTP_DEF_MAX_SEND 10
292292

293-
#define SCTP_DEFAULT_COOKIE_LIFE_SEC 60 /* seconds */
294-
#define SCTP_DEFAULT_COOKIE_LIFE_USEC 0 /* microseconds */
293+
#define SCTP_DEFAULT_COOKIE_LIFE (60 * 1000) /* 60 seconds */
295294

296295
#define SCTP_DEFAULT_MINWINDOW 1500 /* default minimum rwnd size */
297296
#define SCTP_DEFAULT_MAXWINDOW 65535 /* default rwnd size */

include/net/sctp/structs.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ extern struct sctp_globals {
128128
* RTO.Alpha - 1/8 (3 when converted to right shifts.)
129129
* RTO.Beta - 1/4 (2 when converted to right shifts.)
130130
*/
131-
unsigned long rto_initial;
132-
unsigned long rto_min;
133-
unsigned long rto_max;
131+
unsigned int rto_initial;
132+
unsigned int rto_min;
133+
unsigned int rto_max;
134134

135135
/* Note: rto_alpha and rto_beta are really defined as inverse
136136
* powers of two to facilitate integer operations.
@@ -145,13 +145,13 @@ extern struct sctp_globals {
145145
int cookie_preserve_enable;
146146

147147
/* Valid.Cookie.Life - 60 seconds */
148-
unsigned long valid_cookie_life;
148+
unsigned int valid_cookie_life;
149149

150150
/* Delayed SACK timeout 200ms default*/
151-
unsigned long sack_timeout;
151+
unsigned int sack_timeout;
152152

153153
/* HB.interval - 30 seconds */
154-
unsigned long hb_interval;
154+
unsigned int hb_interval;
155155

156156
/* Association.Max.Retrans - 10 attempts
157157
* Path.Max.Retrans - 5 attempts (per destination address)

net/sctp/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ SCTP_STATIC __init int sctp_init(void)
10491049
sctp_rto_beta = SCTP_RTO_BETA;
10501050

10511051
/* Valid.Cookie.Life - 60 seconds */
1052-
sctp_valid_cookie_life = 60 * HZ;
1052+
sctp_valid_cookie_life = SCTP_DEFAULT_COOKIE_LIFE;
10531053

10541054
/* Whether Cookie Preservative is enabled(1) or not(0) */
10551055
sctp_cookie_preserve_enable = 1;

net/sctp/socket.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,14 +3045,14 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
30453045
sp->initmsg.sinit_num_ostreams = sctp_max_outstreams;
30463046
sp->initmsg.sinit_max_instreams = sctp_max_instreams;
30473047
sp->initmsg.sinit_max_attempts = sctp_max_retrans_init;
3048-
sp->initmsg.sinit_max_init_timeo = jiffies_to_msecs(sctp_rto_max);
3048+
sp->initmsg.sinit_max_init_timeo = sctp_rto_max;
30493049

30503050
/* Initialize default RTO related parameters. These parameters can
30513051
* be modified for with the SCTP_RTOINFO socket option.
30523052
*/
3053-
sp->rtoinfo.srto_initial = jiffies_to_msecs(sctp_rto_initial);
3054-
sp->rtoinfo.srto_max = jiffies_to_msecs(sctp_rto_max);
3055-
sp->rtoinfo.srto_min = jiffies_to_msecs(sctp_rto_min);
3053+
sp->rtoinfo.srto_initial = sctp_rto_initial;
3054+
sp->rtoinfo.srto_max = sctp_rto_max;
3055+
sp->rtoinfo.srto_min = sctp_rto_min;
30563056

30573057
/* Initialize default association related parameters. These parameters
30583058
* can be modified with the SCTP_ASSOCINFO socket option.
@@ -3061,8 +3061,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
30613061
sp->assocparams.sasoc_number_peer_destinations = 0;
30623062
sp->assocparams.sasoc_peer_rwnd = 0;
30633063
sp->assocparams.sasoc_local_rwnd = 0;
3064-
sp->assocparams.sasoc_cookie_life =
3065-
jiffies_to_msecs(sctp_valid_cookie_life);
3064+
sp->assocparams.sasoc_cookie_life = sctp_valid_cookie_life;
30663065

30673066
/* Initialize default event subscriptions. By default, all the
30683067
* options are off.
@@ -3072,10 +3071,10 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
30723071
/* Default Peer Address Parameters. These defaults can
30733072
* be modified via SCTP_PEER_ADDR_PARAMS
30743073
*/
3075-
sp->hbinterval = jiffies_to_msecs(sctp_hb_interval);
3074+
sp->hbinterval = sctp_hb_interval;
30763075
sp->pathmaxrxt = sctp_max_retrans_path;
30773076
sp->pathmtu = 0; // allow default discovery
3078-
sp->sackdelay = jiffies_to_msecs(sctp_sack_timeout);
3077+
sp->sackdelay = sctp_sack_timeout;
30793078
sp->param_flags = SPP_HB_ENABLE |
30803079
SPP_PMTUD_ENABLE |
30813080
SPP_SACKDELAY_ENABLE;

net/sctp/sysctl.c

Lines changed: 63 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545
#include <net/sctp/sctp.h>
4646
#include <linux/sysctl.h>
4747

48-
static ctl_handler sctp_sysctl_jiffies_ms;
49-
static long rto_timer_min = 1;
50-
static long rto_timer_max = 86400000; /* One day */
48+
static int zero = 0;
49+
static int one = 1;
50+
static int timer_max = 86400000; /* ms in one day */
51+
static int int_max = INT_MAX;
5152
static long sack_timer_min = 1;
5253
static long sack_timer_max = 500;
5354

@@ -56,153 +57,172 @@ static ctl_table sctp_table[] = {
5657
.ctl_name = NET_SCTP_RTO_INITIAL,
5758
.procname = "rto_initial",
5859
.data = &sctp_rto_initial,
59-
.maxlen = sizeof(long),
60+
.maxlen = sizeof(unsigned int),
6061
.mode = 0644,
61-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
62-
.strategy = &sctp_sysctl_jiffies_ms,
63-
.extra1 = &rto_timer_min,
64-
.extra2 = &rto_timer_max
62+
.proc_handler = &proc_dointvec_minmax,
63+
.strategy = &sysctl_intvec,
64+
.extra1 = &one,
65+
.extra2 = &timer_max
6566
},
6667
{
6768
.ctl_name = NET_SCTP_RTO_MIN,
6869
.procname = "rto_min",
6970
.data = &sctp_rto_min,
70-
.maxlen = sizeof(long),
71+
.maxlen = sizeof(unsigned int),
7172
.mode = 0644,
72-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
73-
.strategy = &sctp_sysctl_jiffies_ms,
74-
.extra1 = &rto_timer_min,
75-
.extra2 = &rto_timer_max
73+
.proc_handler = &proc_dointvec_minmax,
74+
.strategy = &sysctl_intvec,
75+
.extra1 = &one,
76+
.extra2 = &timer_max
7677
},
7778
{
7879
.ctl_name = NET_SCTP_RTO_MAX,
7980
.procname = "rto_max",
8081
.data = &sctp_rto_max,
81-
.maxlen = sizeof(long),
82+
.maxlen = sizeof(unsigned int),
8283
.mode = 0644,
83-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
84-
.strategy = &sctp_sysctl_jiffies_ms,
85-
.extra1 = &rto_timer_min,
86-
.extra2 = &rto_timer_max
84+
.proc_handler = &proc_dointvec_minmax,
85+
.strategy = &sysctl_intvec,
86+
.extra1 = &one,
87+
.extra2 = &timer_max
8788
},
8889
{
8990
.ctl_name = NET_SCTP_VALID_COOKIE_LIFE,
9091
.procname = "valid_cookie_life",
9192
.data = &sctp_valid_cookie_life,
92-
.maxlen = sizeof(long),
93+
.maxlen = sizeof(unsigned int),
9394
.mode = 0644,
94-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
95-
.strategy = &sctp_sysctl_jiffies_ms,
96-
.extra1 = &rto_timer_min,
97-
.extra2 = &rto_timer_max
95+
.proc_handler = &proc_dointvec_minmax,
96+
.strategy = &sysctl_intvec,
97+
.extra1 = &one,
98+
.extra2 = &timer_max
9899
},
99100
{
100101
.ctl_name = NET_SCTP_MAX_BURST,
101102
.procname = "max_burst",
102103
.data = &sctp_max_burst,
103104
.maxlen = sizeof(int),
104105
.mode = 0644,
105-
.proc_handler = &proc_dointvec
106+
.proc_handler = &proc_dointvec_minmax,
107+
.strategy = &sysctl_intvec,
108+
.extra1 = &zero,
109+
.extra2 = &int_max
106110
},
107111
{
108112
.ctl_name = NET_SCTP_ASSOCIATION_MAX_RETRANS,
109113
.procname = "association_max_retrans",
110114
.data = &sctp_max_retrans_association,
111115
.maxlen = sizeof(int),
112116
.mode = 0644,
113-
.proc_handler = &proc_dointvec
117+
.proc_handler = &proc_dointvec_minmax,
118+
.strategy = &sysctl_intvec,
119+
.extra1 = &one,
120+
.extra2 = &int_max
114121
},
115122
{
116123
.ctl_name = NET_SCTP_SNDBUF_POLICY,
117124
.procname = "sndbuf_policy",
118125
.data = &sctp_sndbuf_policy,
119126
.maxlen = sizeof(int),
120127
.mode = 0644,
121-
.proc_handler = &proc_dointvec
128+
.proc_handler = &proc_dointvec,
129+
.strategy = &sysctl_intvec
122130
},
123131
{
124132
.ctl_name = NET_SCTP_RCVBUF_POLICY,
125133
.procname = "rcvbuf_policy",
126134
.data = &sctp_rcvbuf_policy,
127135
.maxlen = sizeof(int),
128136
.mode = 0644,
129-
.proc_handler = &proc_dointvec
137+
.proc_handler = &proc_dointvec,
138+
.strategy = &sysctl_intvec
130139
},
131140
{
132141
.ctl_name = NET_SCTP_PATH_MAX_RETRANS,
133142
.procname = "path_max_retrans",
134143
.data = &sctp_max_retrans_path,
135144
.maxlen = sizeof(int),
136145
.mode = 0644,
137-
.proc_handler = &proc_dointvec
146+
.proc_handler = &proc_dointvec_minmax,
147+
.strategy = &sysctl_intvec,
148+
.extra1 = &one,
149+
.extra2 = &int_max
138150
},
139151
{
140152
.ctl_name = NET_SCTP_MAX_INIT_RETRANSMITS,
141153
.procname = "max_init_retransmits",
142154
.data = &sctp_max_retrans_init,
143155
.maxlen = sizeof(int),
144156
.mode = 0644,
145-
.proc_handler = &proc_dointvec
157+
.proc_handler = &proc_dointvec_minmax,
158+
.strategy = &sysctl_intvec,
159+
.extra1 = &one,
160+
.extra2 = &int_max
146161
},
147162
{
148163
.ctl_name = NET_SCTP_HB_INTERVAL,
149164
.procname = "hb_interval",
150165
.data = &sctp_hb_interval,
151-
.maxlen = sizeof(long),
166+
.maxlen = sizeof(unsigned int),
152167
.mode = 0644,
153-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
154-
.strategy = &sctp_sysctl_jiffies_ms,
155-
.extra1 = &rto_timer_min,
156-
.extra2 = &rto_timer_max
168+
.proc_handler = &proc_dointvec_minmax,
169+
.strategy = &sysctl_intvec,
170+
.extra1 = &one,
171+
.extra2 = &timer_max
157172
},
158173
{
159174
.ctl_name = NET_SCTP_PRESERVE_ENABLE,
160175
.procname = "cookie_preserve_enable",
161176
.data = &sctp_cookie_preserve_enable,
162177
.maxlen = sizeof(int),
163178
.mode = 0644,
164-
.proc_handler = &proc_dointvec
179+
.proc_handler = &proc_dointvec,
180+
.strategy = &sysctl_intvec
165181
},
166182
{
167183
.ctl_name = NET_SCTP_RTO_ALPHA,
168184
.procname = "rto_alpha_exp_divisor",
169185
.data = &sctp_rto_alpha,
170186
.maxlen = sizeof(int),
171-
.mode = 0644,
172-
.proc_handler = &proc_dointvec
187+
.mode = 0444,
188+
.proc_handler = &proc_dointvec,
189+
.strategy = &sysctl_intvec
173190
},
174191
{
175192
.ctl_name = NET_SCTP_RTO_BETA,
176193
.procname = "rto_beta_exp_divisor",
177194
.data = &sctp_rto_beta,
178195
.maxlen = sizeof(int),
179-
.mode = 0644,
180-
.proc_handler = &proc_dointvec
196+
.mode = 0444,
197+
.proc_handler = &proc_dointvec,
198+
.strategy = &sysctl_intvec
181199
},
182200
{
183201
.ctl_name = NET_SCTP_ADDIP_ENABLE,
184202
.procname = "addip_enable",
185203
.data = &sctp_addip_enable,
186204
.maxlen = sizeof(int),
187205
.mode = 0644,
188-
.proc_handler = &proc_dointvec
206+
.proc_handler = &proc_dointvec,
207+
.strategy = &sysctl_intvec
189208
},
190209
{
191210
.ctl_name = NET_SCTP_PRSCTP_ENABLE,
192211
.procname = "prsctp_enable",
193212
.data = &sctp_prsctp_enable,
194213
.maxlen = sizeof(int),
195214
.mode = 0644,
196-
.proc_handler = &proc_dointvec
215+
.proc_handler = &proc_dointvec,
216+
.strategy = &sysctl_intvec
197217
},
198218
{
199219
.ctl_name = NET_SCTP_SACK_TIMEOUT,
200220
.procname = "sack_timeout",
201221
.data = &sctp_sack_timeout,
202222
.maxlen = sizeof(long),
203223
.mode = 0644,
204-
.proc_handler = &proc_doulongvec_ms_jiffies_minmax,
205-
.strategy = &sctp_sysctl_jiffies_ms,
224+
.proc_handler = &proc_dointvec_minmax,
225+
.strategy = &sysctl_intvec,
206226
.extra1 = &sack_timer_min,
207227
.extra2 = &sack_timer_max,
208228
},
@@ -242,37 +262,3 @@ void sctp_sysctl_unregister(void)
242262
{
243263
unregister_sysctl_table(sctp_sysctl_header);
244264
}
245-
246-
/* Strategy function to convert jiffies to milliseconds. */
247-
static int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
248-
void __user *oldval, size_t __user *oldlenp,
249-
void __user *newval, size_t newlen, void **context) {
250-
251-
if (oldval) {
252-
size_t olen;
253-
254-
if (oldlenp) {
255-
if (get_user(olen, oldlenp))
256-
return -EFAULT;
257-
258-
if (olen != sizeof (int))
259-
return -EINVAL;
260-
}
261-
if (put_user((*(int *)(table->data) * 1000) / HZ,
262-
(int __user *)oldval) ||
263-
(oldlenp && put_user(sizeof (int), oldlenp)))
264-
return -EFAULT;
265-
}
266-
if (newval && newlen) {
267-
int new;
268-
269-
if (newlen != sizeof (int))
270-
return -EINVAL;
271-
272-
if (get_user(new, (int __user *)newval))
273-
return -EFAULT;
274-
275-
*(int *)(table->data) = (new * HZ) / 1000;
276-
}
277-
return 1;
278-
}

net/sctp/transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
7575
* parameter 'RTO.Initial'.
7676
*/
7777
peer->rtt = 0;
78-
peer->rto = sctp_rto_initial;
78+
peer->rto = msecs_to_jiffies(sctp_rto_initial);
7979
peer->rttvar = 0;
8080
peer->srtt = 0;
8181
peer->rto_pending = 0;

0 commit comments

Comments
 (0)