Blame keepalived/include/check_api.h

Packit c22fc9
/*
Packit c22fc9
 * Soft:        Keepalived is a failover program for the LVS project
Packit c22fc9
 *              <www.linuxvirtualserver.org>. It monitor & manipulate
Packit c22fc9
 *              a loadbalanced server pool using multi-layer checks.
Packit c22fc9
 *
Packit c22fc9
 * Part:        Checkers arguments structures definitions.
Packit c22fc9
 *
Packit c22fc9
 * Author:      Alexandre Cassen, <acassen@linux-vs.org>
Packit c22fc9
 *
Packit c22fc9
 *              This program is distributed in the hope that it will be useful,
Packit c22fc9
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c22fc9
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit c22fc9
 *              See the GNU General Public License for more details.
Packit c22fc9
 *
Packit c22fc9
 *              This program is free software; you can redistribute it and/or
Packit c22fc9
 *              modify it under the terms of the GNU General Public License
Packit c22fc9
 *              as published by the Free Software Foundation; either version
Packit c22fc9
 *              2 of the License, or (at your option) any later version.
Packit c22fc9
 *
Packit c22fc9
 * Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>
Packit c22fc9
 */
Packit c22fc9
Packit c22fc9
#ifndef _CHECK_API_H
Packit c22fc9
#define _CHECK_API_H
Packit c22fc9
Packit c22fc9
#include "config.h"
Packit c22fc9
Packit c22fc9
/* global includes */
Packit c22fc9
#include <stdbool.h>
Packit c22fc9
#include <stdio.h>
Packit c22fc9
#include <sys/socket.h>
Packit c22fc9
Packit c22fc9
/* local includes */
Packit Service dfccb1
#include "list_head.h"
Packit c22fc9
#include "check_data.h"
Packit c22fc9
#include "vector.h"
Packit c22fc9
#include "layer4.h"
Packit c22fc9
Packit c22fc9
/* Checkers structure definition */
Packit c22fc9
typedef struct _checker {
Packit Service dfccb1
	void				(*free_func) (struct _checker *);
Packit Service dfccb1
	void				(*dump_func) (FILE *, const struct _checker *);
Packit Service dfccb1
	thread_func_t			launch;
Packit Service dfccb1
	bool				(*compare) (const struct _checker *, struct _checker *);
Packit c22fc9
	virtual_server_t		*vs;			/* pointer to the checker thread virtualserver */
Packit c22fc9
	real_server_t			*rs;			/* pointer to the checker thread realserver */
Packit c22fc9
	void				*data;
Packit c22fc9
	bool				enabled;		/* Activation flag */
Packit c22fc9
	bool				is_up;			/* Set if checker is up */
Packit c22fc9
	bool				has_run;		/* Set if the checker has completed at least once */
Packit c22fc9
	conn_opts_t			*co;			/* connection options */
Packit c22fc9
	int				alpha;			/* Alpha mode enabled */
Packit c22fc9
	unsigned long			delay_loop;		/* Interval between running checker */
Packit c22fc9
	unsigned long			warmup;			/* max random timeout to start checker */
Packit c22fc9
	unsigned			retry;			/* number of retries before failing */
Packit c22fc9
	unsigned long			delay_before_retry;	/* interval between retries */
Packit c22fc9
	unsigned			retry_it;		/* number of successive failures */
Packit c22fc9
	unsigned			default_retry;		/* number of retries before failing */
Packit c22fc9
	unsigned long			default_delay_before_retry; /* interval between retries */
Packit Service dfccb1
	bool				log_all_failures;	/* Log all failures when checker up */
Packit Service dfccb1
Packit Service dfccb1
	/* Linked list member */
Packit Service dfccb1
	list_head_t			e_list;
Packit c22fc9
} checker_t;
Packit c22fc9
Packit Service dfccb1
typedef struct _checker_ref {
Packit Service dfccb1
	checker_t			*checker;
Packit Service dfccb1
Packit Service dfccb1
	/* Linked list member */
Packit Service dfccb1
	list_head_t			e_list;
Packit Service dfccb1
} checker_ref_t;
Packit Service dfccb1
Packit c22fc9
/* Checkers queue */
Packit Service dfccb1
extern list_head_t checkers_queue;
Packit c22fc9
Packit c22fc9
/* utility macro */
Packit c22fc9
#define CHECKER_ARG(X) ((X)->data)
Packit c22fc9
#define CHECKER_CO(X) (((checker_t *)X)->co)
Packit c22fc9
#define CHECKER_DATA(X) (((checker_t *)X)->data)
Packit Service dfccb1
#define CHECKER_GET_CURRENT() (list_last_entry(&checkers_queue, checker_t, e_list))
Packit c22fc9
#define CHECKER_GET() (CHECKER_DATA(CHECKER_GET_CURRENT()))
Packit c22fc9
#define CHECKER_GET_CO() (((checker_t *)CHECKER_GET_CURRENT())->co)
Packit c22fc9
#define CHECKER_HA_SUSPEND(C) ((C)->vs->ha_suspend)
Packit c22fc9
#define CHECKER_NEW_CO() ((conn_opts_t *) MALLOC(sizeof (conn_opts_t)))
Packit c22fc9
#define FMT_CHK(C) FMT_RS((C)->rs, (C)->vs)
Packit c22fc9
Packit Service dfccb1
#ifdef _CHECKER_DEBUG_
Packit Service dfccb1
extern bool do_checker_debug;
Packit Service dfccb1
#endif
Packit Service dfccb1
Packit c22fc9
/* Prototypes definition */
Packit Service dfccb1
extern void free_checker(checker_t *);
Packit Service dfccb1
extern void free_checker_list(list_head_t *);
Packit c22fc9
extern void init_checkers_queue(void);
Packit Service dfccb1
extern void free_vs_checkers(const virtual_server_t *);
Packit Service dfccb1
extern void free_rs_checkers(const real_server_t *);
Packit Service dfccb1
extern void dump_connection_opts(FILE *, const void *);
Packit Service dfccb1
extern void dump_checker_opts(FILE *, const void *);
Packit Service dfccb1
extern checker_t *queue_checker(void (*) (checker_t *), void (*) (FILE *, const checker_t *)
Packit Service dfccb1
			  , thread_func_t
Packit Service dfccb1
			  , bool (*) (const checker_t *, checker_t *)
Packit c22fc9
			  , void *
Packit Service dfccb1
			  , conn_opts_t *
Packit Service dfccb1
			  , bool);
Packit c22fc9
extern void dequeue_new_checker(void);
Packit c22fc9
extern bool check_conn_opts(conn_opts_t *);
Packit Service dfccb1
extern bool compare_conn_opts(const conn_opts_t *, const conn_opts_t *) __attribute__ ((pure));
Packit c22fc9
extern void dump_checkers_queue(FILE *);
Packit c22fc9
extern void free_checkers_queue(void);
Packit c22fc9
extern void register_checkers_thread(void);
Packit c22fc9
extern void install_checkers_keyword(void);
Packit c22fc9
extern void checker_set_dst_port(struct sockaddr_storage *, uint16_t);
Packit c22fc9
extern void install_checker_common_keywords(bool);
Packit c22fc9
extern void update_checker_activity(sa_family_t, void *, bool);
Packit c22fc9
Packit c22fc9
#endif