* [PATCH net-next 1/2] net: sctp: improve timer slack calculation for transport HBs
2014-06-30 11:52 [PATCH net-next 0/2] Misc SCTP updates Daniel Borkmann
@ 2014-06-30 11:52 ` Daniel Borkmann
2014-06-30 11:52 ` [PATCH net-next 2/2] net: sctp: only warn in proc_sctp_do_alpha_beta if write Daniel Borkmann
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2014-06-30 11:52 UTC (permalink / raw)
To: davem; +Cc: netdev, linux-sctp
RFC4960, section 8.3 says:
On an idle destination address that is allowed to heartbeat,
it is recommended that a HEARTBEAT chunk is sent once per RTO
of that destination address plus the protocol parameter
'HB.interval', with jittering of +/- 50% of the RTO value,
and exponential backoff of the RTO if the previous HEARTBEAT
is unanswered.
Currently, we calculate jitter via sctp_jitter() function first,
and then add its result to the current RTO for the new timeout:
TMO = RTO + (RAND() % RTO) - (RTO / 2)
`------------------------^-=> sctp_jitter()
Instead, we can just simplify all this by directly calculating:
TMO = (RTO / 2) + (RAND() % RTO)
With the help of prandom_u32_max(), we don't need to open code
our own global PRNG, but can instead just make use of the per
CPU implementation of prandom with better quality numbers. Also,
we can now spare us the conditional for divide by zero check
since no div or mod operation needs to be used. Note that
prandom_u32_max() won't emit the same result as a mod operation,
but we really don't care here as we only want to have a random
number scaled into RTO interval.
Note, exponential RTO backoff is handeled elsewhere, namely in
sctp_do_8_2_transport_strike().
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
include/net/sctp/sctp.h | 21 ---------------------
net/sctp/transport.c | 17 +++++++++--------
2 files changed, 9 insertions(+), 29 deletions(-)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 8e4de46..c2035c9 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -388,27 +388,6 @@ static inline int sctp_list_single_entry(struct list_head *head)
return (head->next != head) && (head->next == head->prev);
}
-/* Generate a random jitter in the range of -50% ~ +50% of input RTO. */
-static inline __s32 sctp_jitter(__u32 rto)
-{
- static __u32 sctp_rand;
- __s32 ret;
-
- /* Avoid divide by zero. */
- if (!rto)
- rto = 1;
-
- sctp_rand += jiffies;
- sctp_rand ^= (sctp_rand << 12);
- sctp_rand ^= (sctp_rand >> 20);
-
- /* Choose random number from 0 to rto, then move to -50% ~ +50%
- * of rto.
- */
- ret = sctp_rand % rto - (rto >> 1);
- return ret;
-}
-
/* Break down data chunks at this point. */
static inline int sctp_frag_point(const struct sctp_association *asoc, int pmtu)
{
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index 7dd672f..b10e047 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -594,15 +594,16 @@ void sctp_transport_burst_reset(struct sctp_transport *t)
}
/* What is the next timeout value for this transport? */
-unsigned long sctp_transport_timeout(struct sctp_transport *t)
+unsigned long sctp_transport_timeout(struct sctp_transport *trans)
{
- unsigned long timeout;
- timeout = t->rto + sctp_jitter(t->rto);
- if ((t->state != SCTP_UNCONFIRMED) &&
- (t->state != SCTP_PF))
- timeout += t->hbinterval;
- timeout += jiffies;
- return timeout;
+ /* RTO + timer slack +/- 50% of RTO */
+ unsigned long timeout = (trans->rto >> 1) + prandom_u32_max(trans->rto);
+
+ if (trans->state != SCTP_UNCONFIRMED &&
+ trans->state != SCTP_PF)
+ timeout += trans->hbinterval;
+
+ return timeout + jiffies;
}
/* Reset transport variables to their initial values */
--
1.7.11.7
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net-next 2/2] net: sctp: only warn in proc_sctp_do_alpha_beta if write
2014-06-30 11:52 [PATCH net-next 0/2] Misc SCTP updates Daniel Borkmann
2014-06-30 11:52 ` [PATCH net-next 1/2] net: sctp: improve timer slack calculation for transport HBs Daniel Borkmann
@ 2014-06-30 11:52 ` Daniel Borkmann
2014-06-30 13:04 ` Jiri Pirko
2014-06-30 12:37 ` [PATCH net-next 0/2] Misc SCTP updates Neil Horman
2014-07-03 1:44 ` David Miller
3 siblings, 1 reply; 6+ messages in thread
From: Daniel Borkmann @ 2014-06-30 11:52 UTC (permalink / raw)
To: davem; +Cc: netdev, linux-sctp
Only warn if the value is written to alpha or beta. We don't care
emitting a one-time warning when only reading it.
Reported-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
net/sctp/sysctl.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 12c7e01..2e9ada1 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -424,8 +424,9 @@ static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
- pr_warn_once("Changing rto_alpha or rto_beta may lead to "
- "suboptimal rtt/srtt estimations!\n");
+ if (write)
+ pr_warn_once("Changing rto_alpha or rto_beta may lead to "
+ "suboptimal rtt/srtt estimations!\n");
return proc_dointvec_minmax(ctl, write, buffer, lenp, ppos);
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net-next 0/2] Misc SCTP updates
2014-06-30 11:52 [PATCH net-next 0/2] Misc SCTP updates Daniel Borkmann
2014-06-30 11:52 ` [PATCH net-next 1/2] net: sctp: improve timer slack calculation for transport HBs Daniel Borkmann
2014-06-30 11:52 ` [PATCH net-next 2/2] net: sctp: only warn in proc_sctp_do_alpha_beta if write Daniel Borkmann
@ 2014-06-30 12:37 ` Neil Horman
2014-07-03 1:44 ` David Miller
3 siblings, 0 replies; 6+ messages in thread
From: Neil Horman @ 2014-06-30 12:37 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: davem, netdev, linux-sctp
On Mon, Jun 30, 2014 at 01:52:07PM +0200, Daniel Borkmann wrote:
> Daniel Borkmann (2):
> net: sctp: improve timer slack calculation for transport HBs
> net: sctp: only warn in proc_sctp_do_alpha_beta if write
>
> include/net/sctp/sctp.h | 21 ---------------------
> net/sctp/sysctl.c | 5 +++--
> net/sctp/transport.c | 17 +++++++++--------
> 3 files changed, 12 insertions(+), 31 deletions(-)
>
> --
> 1.7.11.7
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] Misc SCTP updates
2014-06-30 11:52 [PATCH net-next 0/2] Misc SCTP updates Daniel Borkmann
` (2 preceding siblings ...)
2014-06-30 12:37 ` [PATCH net-next 0/2] Misc SCTP updates Neil Horman
@ 2014-07-03 1:44 ` David Miller
3 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2014-07-03 1:44 UTC (permalink / raw)
To: dborkman; +Cc: netdev, linux-sctp
From: Daniel Borkmann <dborkman@redhat.com>
Date: Mon, 30 Jun 2014 13:52:07 +0200
> Daniel Borkmann (2):
> net: sctp: improve timer slack calculation for transport HBs
> net: sctp: only warn in proc_sctp_do_alpha_beta if write
Series applied, thanks Daniel.
^ permalink raw reply [flat|nested] 6+ messages in thread