The commit 09de73638a62207c268482982fce7ee96a9d6ba1 ("pluto:
first attempt to replace pluto select loop with libevent") causes
pluto to retransmit forever.

This patch fixes this by stopping retransmissions after the count
reaches MAXIMUM_RETRANSMITS_PER_EXCHANGE.

diff --git a/programs/pluto/timer.c b/programs/pluto/timer.c
index 700b018..f4299a9 100644
--- a/programs/pluto/timer.c
+++ b/programs/pluto/timer.c
@@ -62,6 +62,9 @@ static unsigned long retrans_delay(struct state *st, unsigned 
long delay_ms)
        unsigned long delay_cap = deltamillisecs(c->r_timeout); /* ms */
        u_int8_t x = st->st_retransmit++;       /* ??? odd type */
 
+       if (x > MAXIMUM_RETRANSMITS_PER_EXCHANGE)
+               return 0;
+
        /*
         * Very carefully calculate capped exponential backoff.
         * The test is expressed as a right shift to avoid overflow.
@@ -70,8 +73,7 @@ static unsigned long retrans_delay(struct state *st, unsigned 
long delay_ms)
         * Surely a bound of 12 (factor of 2048) is safe and more than enough.
         */
 
-       delay_ms = (x > MAXIMUM_RETRANSMITS_PER_EXCHANGE ||
-                       delay_cap >> x < delay_ms) ?
+       delay_ms = delay_cap >> x < delay_ms ?
                delay_cap : delay_ms << x;
 
        whack_log(RC_RETRANSMISSION,
@@ -128,8 +130,10 @@ static void retransmit_v1_msg(struct state *st)
                delay_ms = c->r_interval;
        }
 
+       if (delay_ms != 0)
+               delay_ms = retrans_delay(st, delay_ms);
+
        if (delay_ms != 0) {
-               delay_ms =  retrans_delay(st, delay_ms);
                resend_ike_v1_msg(st, "EVENT_v1_RETRANSMIT");
                event_schedule_ms(EVENT_v1_RETRANSMIT, delay_ms, st);
        } else {
@@ -241,8 +245,10 @@ static void retransmit_v2_msg(struct state *st)
                delay_ms = c->r_interval;
        }
 
+       if (delay_ms != 0)
+               delay_ms = retrans_delay(st, delay_ms);
+
        if (delay_ms != 0) {
-               delay_ms =  retrans_delay(st, delay_ms);
                send_ike_msg(st, "EVENT_v2_RETRANSMIT");
                event_schedule_ms(EVENT_v2_RETRANSMIT, delay_ms, st);
                return;
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
_______________________________________________
Swan-dev mailing list
[email protected]
https://lists.libreswan.org/mailman/listinfo/swan-dev

Reply via email to