]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libcharon/plugins/ha/ha_segments.h
ha: Add getter for the number of segments
[thirdparty/strongswan.git] / src / libcharon / plugins / ha / ha_segments.h
CommitLineData
34d240a6
MW
1/*
2 * Copyright (C) 2008 Martin Willi
1b671669 3 * HSR Hochschule fuer Technik Rapperswil
34d240a6
MW
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.
34d240a6
MW
14 */
15
16/**
d8748966
MW
17 * @defgroup ha_segments ha_segments
18 * @{ @ingroup ha
34d240a6
MW
19 */
20
d8748966
MW
21#ifndef HA_SEGMENTS_H_
22#define HA_SEGMENTS_H_
34d240a6
MW
23
24#include <daemon.h>
25
d8748966 26typedef struct ha_segments_t ha_segments_t;
34d240a6 27
b12c53ce 28typedef uint16_t segment_mask_t;
6921e8d5
MW
29
30/**
31 * maximum number of segments
32 */
33#define SEGMENTS_MAX (sizeof(segment_mask_t)*8)
34
35/**
36 * Get the bit in the mask of a segment
37 */
38#define SEGMENTS_BIT(segment) (0x01 << (segment - 1))
39
d8748966
MW
40#include "ha_socket.h"
41#include "ha_tunnel.h"
42#include "ha_kernel.h"
dbc91f7c 43
34d240a6 44/**
37459ea9 45 * Segmentation of peers into active and passive.
34d240a6 46 */
d8748966 47struct ha_segments_t {
34d240a6 48
310498f3
MW
49 /**
50 * Implements listener interface to catch daemon shutdown.
51 */
52 listener_t listener;
53
34d240a6 54 /**
37459ea9 55 * Activate a set of IKE_SAs identified by a segment.
34d240a6 56 *
c573b11c 57 * @param segment numerical segment to takeover, 0 for all
35a19861 58 * @param notify whether to notify other nodes about activation
34d240a6 59 */
d8748966 60 void (*activate)(ha_segments_t *this, u_int segment, bool notify);
34d240a6
MW
61
62 /**
37459ea9 63 * Deactivate a set of IKE_SAs identified by a segment.
34d240a6 64 *
c573b11c 65 * @param segment numerical segment to takeover, 0 for all
35a19861 66 * @param notify whether to notify other nodes about deactivation
34d240a6 67 */
d8748966 68 void (*deactivate)(ha_segments_t *this, u_int segment, bool notify);
9ffcbea6 69
3912fdb1
MW
70 /**
71 * Handle a status message from the remote node.
72 *
73 * @param mask segments the remote node is serving actively
74 */
d8748966 75 void (*handle_status)(ha_segments_t *this, segment_mask_t mask);
3912fdb1 76
08e266a1
MW
77 /**
78 * Check if a given segment is currently active.
79 *
80 * @param segment segment to check
81 * @return TRUE if segment active
82 */
83 bool (*is_active)(ha_segments_t *this, u_int segment);
84
16a898f5
TB
85 /**
86 * Return the number of segments
87 *
88 * @return number of segments
89 */
90 u_int (*count)(ha_segments_t *this);
91
34d240a6 92 /**
d8748966 93 * Destroy a ha_segments_t.
34d240a6 94 */
d8748966 95 void (*destroy)(ha_segments_t *this);
34d240a6
MW
96};
97
98/**
d8748966 99 * Create a ha_segments instance.
37459ea9
MW
100 *
101 * @param socket socket to communicate segment (de-)activation
dbc91f7c 102 * @param kernel interface to control segments at kernel level
3e8caf6a 103 * @param tunnel HA tunnel
6921e8d5 104 * @param count number of segments the cluster uses
3e8caf6a
MW
105 * @param node node, currently 1 or 0
106 * @param monitor should we use monitoring functionality
37459ea9 107 * @return segment object
34d240a6 108 */
d8748966 109ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
3e8caf6a 110 ha_tunnel_t *tunnel, u_int count, u_int node,
aa334daa 111 bool monitor);
34d240a6 112
83b23011 113#endif /** HA_SEGMENTS_ @}*/