• Gerrit Renker's avatar
    [DCCP] ccid3: Simplify calculation for reverse lookup of p · bfe24a6c
    Gerrit Renker authored
     This simplifies the calculation of a value p for a given fval when the
     first loss interval is computed (RFC 3448, 6.3.1). It makes use of the
     two new functions scaled_div/scaled_div32 to provide overflow protection.
    
     Additionally, protection against divide-by-zero is extended - in this
     case the function will return the maximally possible value of p=100%.
    
    Background:
    
     The maximum fval, f(100%), is approximately 244, i.e. the scaled value of fval
     should never exceed 244E6, which fits easily into u32. The problem is the scaling
     by 10^6, since additionally R(TT) is in microseconds.
     This is resolved by breaking the division into two stages: the first stage
     computes fval=(s*10^6)/R, stores that into u64; the second stage computes
     fval = (fval*10^6)/X_recv and complains if overflow is reached for u32.
     This case is safe since the TFRC reverse-lookup routine then returns p=100%.
    Signed-off-by: default avatarGerrit Renker <gerrit@erg.abdn.ac.uk>
    Acked-by: default avatarIan McDonald <ian.mcdonald@jandi.co.nz>
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@mandriva.com>
    bfe24a6c
ccid3.c 37 KB