Annotation of embedaddon/strongswan/src/libcharon/sa/task_manager.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2011 Tobias Brunner
                      3:  * HSR Hochschule fuer Technik Rapperswil
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: #include "task_manager.h"
                     17: 
                     18: #include <math.h>
                     19: #include <sa/ikev1/task_manager_v1.h>
                     20: #include <sa/ikev2/task_manager_v2.h>
                     21: 
                     22: /*
                     23:  * See header
                     24:  */
                     25: u_int task_manager_total_retransmit_timeout()
                     26: {
                     27:        double timeout, base, limit = 0, total = 0;
                     28:        int tries, i;
                     29: 
                     30:        tries = lib->settings->get_int(lib->settings, "%s.retransmit_tries",
                     31:                                                                   RETRANSMIT_TRIES, lib->ns);
                     32:        base = lib->settings->get_double(lib->settings, "%s.retransmit_base",
                     33:                                                                         RETRANSMIT_BASE, lib->ns);
                     34:        timeout = lib->settings->get_double(lib->settings, "%s.retransmit_timeout",
                     35:                                                                                RETRANSMIT_TIMEOUT, lib->ns);
                     36:        limit = lib->settings->get_double(lib->settings, "%s.retransmit_limit",
                     37:                                                                          0, lib->ns);
                     38: 
                     39:        for (i = 0; i <= tries; i++)
                     40:        {
                     41:                double interval = timeout * pow(base, i);
                     42:                if (limit)
                     43:                {
                     44:                        interval = min(interval, limit);
                     45:                }
                     46:                total += interval;
                     47:        }
                     48:        return (u_int)total;
                     49: }
                     50: 
                     51: /*
                     52:  * See header
                     53:  */
                     54: task_manager_t *task_manager_create(ike_sa_t *ike_sa)
                     55: {
                     56:        switch (ike_sa->get_version(ike_sa))
                     57:        {
                     58:                case IKEV1:
                     59: #ifdef USE_IKEV1
                     60:                        return &task_manager_v1_create(ike_sa)->task_manager;
                     61: #endif
                     62:                        break;
                     63:                case IKEV2:
                     64: #ifdef USE_IKEV2
                     65:                        return &task_manager_v2_create(ike_sa)->task_manager;
                     66: #endif
                     67:                        break;
                     68:                default:
                     69:                        break;
                     70:        }
                     71:        return NULL;
                     72: }
                     73: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>