src/modules/keepalive/keepalive.h
cf07d3fe
 /**
  * keepalive module - remote destinations probing
fd705268
  *
cf07d3fe
  * Copyright (C) 2017 Guillaume Bour <guillaume@bour.cc>
  *
  * This file is part of Kamailio, a free SIP server.
  *
  * Kamailio is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * Kamailio is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
fd705268
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
cf07d3fe
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 /*! \file
  * \ingroup keepalive
  * \brief Keepalive :: Keepalive
  */
 
 #ifndef _KEEPALIVE_H_
 #define _KEEPALIVE_H_
 
 #include <time.h>
 #include "../../core/sr_module.h"
e8bd86d7
 #include "../../core/locking.h"
9a3a8f15
 #include "../../core/str.h"
 #include "../../core/utils/sruid.h"
9700a8da
 #include "../tm/tm_load.h"
cf07d3fe
 
338e5df6
 #define KA_INACTIVE_DST 1 /*!< inactive destination */
 #define KA_TRYING_DST 2   /*!< temporary trying destination */
 #define KA_DISABLED_DST 4 /*!< admin disabled destination */
 #define KA_PROBING_DST 8  /*!< checking destination */
 #define KA_STATES_ALL 15  /*!< all bits for the states of destination */
cf07d3fe
 
4cebb16b
 extern int ka_ping_interval;
 
338e5df6
 #define ds_skip_dst(flags) ((flags) & (KA_INACTIVE_DST | KA_DISABLED_DST))
cf07d3fe
 
338e5df6
 #define KA_PROBE_NONE 0
 #define KA_PROBE_ALL 1
 #define KA_PROBE_INACTIVE 2
 #define KA_PROBE_ONLYFLAGGED 3
cf07d3fe
 
f6b5f782
 #define KA_FIRST_TRY_DELAY 500 /* First OPTIONS send is done 500 millis after adding the destination */
 
211dc1be
 typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
9700a8da
 typedef void (*ka_response_f)(
 		str *uri, struct tmcb_params *ps, void *user_attr);
cf07d3fe
 
e8bd86d7
 
cf07d3fe
 typedef struct _ka_dest
 {
 	str uri;
338e5df6
 	str owner; // name of destination "owner"
 			   // (module asking to monitor this destination
9a3a8f15
 	str  uuid; // Universal id for this record
cf07d3fe
 	int flags;
 	int state;
338e5df6
 	time_t last_checked, last_up, last_down;
e8bd86d7
 	int counter;	// counts unreachable attemps
f6b5f782
 	ticks_t ping_interval;  /*!< Actual interval between OPTIONS  */
cf07d3fe
 
 	void *user_attr;
 	ka_statechanged_f statechanged_clb;
9700a8da
 	ka_response_f response_clb;
338e5df6
 	struct socket_info *sock;
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
 	unsigned short int port;   /*!< Port of the URI */
 	unsigned short int proto;  /*!< Protocol of the URI */
f6b5f782
 	struct timer_ln *timer;    /*!< Timer firing the OPTIONS test */
cf07d3fe
 	struct _ka_dest *next;
 } ka_dest_t;
 
 typedef struct _ka_destinations_list
 {
e8bd86d7
 	gen_lock_t *lock;
cf07d3fe
 	ka_dest_t *first;
 } ka_destinations_list_t;
 
 extern ka_destinations_list_t *ka_destinations_list;
e8bd86d7
 extern int ka_counter_del;
9a3a8f15
 extern sruid_t ka_sruid;
cf07d3fe
 
4cebb16b
 ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param);
 
 int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
9700a8da
         ka_statechanged_f statechanged_clb, ka_response_f response_clb,
         void *user_attr);
211dc1be
 int ka_destination_state(str *uri);
 int ka_str_copy(str *src, str *dest, char *prefix);
e8bd86d7
 int free_destination(ka_dest_t *dest) ;
 int ka_del_destination(str *uri, str *owner) ;
 int ka_find_destination(str *uri, str *owner, ka_dest_t **target ,ka_dest_t **head);
9a3a8f15
 int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head);
e8bd86d7
 int ka_lock_destination_list();
 int ka_unlock_destination_list();
cf07d3fe
 #endif