44 #include <sys/socket.h>
45 #include <sys/types.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/param.h>
54 #include <qb/qbdefs.h>
63 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
64 #define TOKEN_TIMEOUT 1000
65 #define JOIN_TIMEOUT 50
66 #define MERGE_TIMEOUT 200
67 #define DOWNCHECK_TIMEOUT 1000
68 #define FAIL_TO_RECV_CONST 2500
69 #define SEQNO_UNCHANGED_CONST 30
70 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
71 #define MAX_NETWORK_DELAY 50
72 #define WINDOW_SIZE 50
73 #define MAX_MESSAGES 17
74 #define MISS_COUNT_CONST 5
75 #define RRP_PROBLEM_COUNT_TIMEOUT 2000
76 #define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT 10
77 #define RRP_PROBLEM_COUNT_THRESHOLD_MIN 2
78 #define RRP_AUTORECOVERY_CHECK_TIMEOUT 1000
80 #define DEFAULT_PORT 5405
82 static char error_string_response[512];
90 if (strcmp(param_name,
"totem.token") == 0)
92 if (strcmp(param_name,
"totem.token_retransmit") == 0)
94 if (strcmp(param_name,
"totem.hold") == 0)
96 if (strcmp(param_name,
"totem.token_retransmits_before_loss_const") == 0)
98 if (strcmp(param_name,
"totem.join") == 0)
100 if (strcmp(param_name,
"totem.send_join") == 0)
102 if (strcmp(param_name,
"totem.consensus") == 0)
104 if (strcmp(param_name,
"totem.merge") == 0)
106 if (strcmp(param_name,
"totem.downcheck") == 0)
108 if (strcmp(param_name,
"totem.fail_recv_const") == 0)
110 if (strcmp(param_name,
"totem.seqno_unchanged_const") == 0)
112 if (strcmp(param_name,
"totem.rrp_token_expired_timeout") == 0)
114 if (strcmp(param_name,
"totem.rrp_problem_count_timeout") == 0)
116 if (strcmp(param_name,
"totem.rrp_problem_count_threshold") == 0)
118 if (strcmp(param_name,
"totem.rrp_problem_count_mcast_threshold") == 0)
120 if (strcmp(param_name,
"totem.rrp_autorecovery_check_timeout") == 0)
122 if (strcmp(param_name,
"totem.heartbeat_failures_allowed") == 0)
124 if (strcmp(param_name,
"totem.max_network_delay") == 0)
126 if (strcmp(param_name,
"totem.window_size") == 0)
128 if (strcmp(param_name,
"totem.max_messages") == 0)
130 if (strcmp(param_name,
"totem.miss_count_const") == 0)
137 static void totem_volatile_config_read (
struct totem_config *totem_config)
168 static int totem_get_crypto(
struct totem_config *totem_config)
171 const char *tmp_cipher;
172 const char *tmp_hash;
175 tmp_cipher =
"aes256";
178 if (strcmp (str,
"off") == 0) {
186 if (strcmp(str,
"none") == 0) {
189 if (strcmp(str,
"aes256") == 0) {
190 tmp_cipher =
"aes256";
192 if (strcmp(str,
"aes192") == 0) {
193 tmp_cipher =
"aes192";
195 if (strcmp(str,
"aes128") == 0) {
196 tmp_cipher =
"aes128";
198 if (strcmp(str,
"3des") == 0) {
205 if (strcmp(str,
"none") == 0) {
208 if (strcmp(str,
"md5") == 0) {
211 if (strcmp(str,
"sha1") == 0) {
214 if (strcmp(str,
"sha256") == 0) {
217 if (strcmp(str,
"sha384") == 0) {
220 if (strcmp(str,
"sha512") == 0) {
226 if ((strcmp(tmp_cipher,
"none") != 0) &&
227 (strcmp(tmp_hash,
"none") == 0)) {
240 static uint16_t generate_cluster_id (
const char *cluster_name)
245 for (i = 0; i < strlen(cluster_name); i++) {
247 value += cluster_name[i];
250 return (value & 0xFFFF);
253 static int get_cluster_mcast_addr (
254 const char *cluster_name,
256 unsigned int ringnumber,
261 char addr[INET6_ADDRSTRLEN + 1];
264 if (cluster_name == NULL) {
268 clusterid = generate_cluster_id(cluster_name) + ringnumber;
269 memset (res, 0,
sizeof(*res));
271 switch (bindnet->
family) {
273 snprintf(addr,
sizeof(addr),
"239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
276 snprintf(addr,
sizeof(addr),
"ff15::%x", clusterid);
290 static int find_local_node_in_nodelist(
struct totem_config *totem_config)
293 const char *iter_key;
296 int local_node_pos = -1;
298 int interface_up, interface_num;
304 &bind_addr, &interface_up, &interface_num,
312 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
317 if (strcmp(tmp_key,
"ring0_addr") != 0) {
333 local_node_pos = node_pos;
338 return (local_node_pos);
341 static void put_nodelist_members_to_config(
struct totem_config *totem_config)
344 const char *iter_key, *iter_key2;
351 unsigned int ringnumber = 0;
355 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
360 if (strcmp(tmp_key,
"ring0_addr") != 0) {
367 res = sscanf(iter_key2,
"nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
368 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
392 static void config_convert_nodelist_to_interface(
struct totem_config *totem_config)
395 const char *iter_key;
401 unsigned int ringnumber = 0;
414 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
419 if (strcmp(tmp_key,
"ring0_addr") != 0) {
437 for (list = addrs.
next; list != &addrs; list = list->
next) {
460 res = sscanf(iter_key,
"nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
461 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
479 struct totem_config *totem_config,
480 const char **error_string,
485 unsigned int ringnumber = 0;
486 int member_count = 0;
488 const char *iter_key;
489 const char *member_iter_key;
494 char *cluster_name = NULL;
501 memset (totem_config, 0,
sizeof (
struct totem_config));
504 *error_string =
"Out of memory trying to allocate ethernet interface storage area";
511 strcpy (totem_config->
rrp_mode,
"none");
515 if (totem_get_crypto(totem_config) != 0) {
516 *error_string =
"crypto_cipher requires crypto_hash with value other than none";
522 *error_string =
"totem.rrp_mode is too long";
527 strcpy (totem_config->
rrp_mode, str);
535 if (strcmp (str,
"yes") == 0) {
551 if (strcmp(str,
"ipv4") == 0) {
554 if (strcmp(str,
"ipv6") == 0) {
563 totem_volatile_config_read(totem_config);
569 config_convert_nodelist_to_interface(totem_config);
576 res = sscanf(iter_key,
"totem.interface.%[^.].%s", ringnumber_key, tmp_key);
581 if (strcmp(tmp_key,
"bindnetaddr") != 0) {
587 ringnumber = atoi(ringnumber_key);
589 if (ringnumber >= INTERFACE_MAX) {
592 snprintf (error_string_response,
sizeof(error_string_response),
593 "parse error in config: interface ring number %u is bigger then allowed maximum %u\n",
594 ringnumber, INTERFACE_MAX - 1);
596 *error_string = error_string_response;
621 res = get_cluster_mcast_addr (cluster_name,
631 if (strcmp (str,
"yes") == 0) {
665 while ((member_iter_key =
icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
666 if (member_count == 0) {
708 if (strcmp (str,
"udpu") == 0) {
712 if (strcmp (str,
"iba") == 0) {
728 local_node_pos = find_local_node_in_nodelist(totem_config);
729 if (local_node_pos != -1) {
734 nodeid_set = (totem_config->
node_id != 0);
749 put_nodelist_members_to_config(totem_config);
752 add_totem_config_notification(totem_config);
757 static int totem_set_volatile_defaults (
758 struct totem_config *totem_config,
759 const char **error_string)
761 static char local_error_reason[512];
762 const char *error_reason = local_error_reason;
781 snprintf (local_error_reason,
sizeof(local_error_reason),
782 "The max_network_delay parameter (%d ms) may not be less then (%d ms).",
800 snprintf (local_error_reason,
sizeof(local_error_reason),
801 "The token timeout parameter (%d ms) may not be less then (%d ms).",
817 snprintf (local_error_reason,
sizeof(local_error_reason),
818 "The token retransmit timeout parameter (%d ms) may not be less then (%d ms).",
824 snprintf (local_error_reason,
sizeof(local_error_reason),
825 "The token hold timeout parameter (%d ms) may not be less then (%d ms).",
835 snprintf (local_error_reason,
sizeof(local_error_reason),
836 "The join timeout parameter (%d ms) may not be less then (%d ms).",
846 snprintf (local_error_reason,
sizeof(local_error_reason),
847 "The consensus timeout parameter (%d ms) may not be less then (%d ms).",
857 snprintf (local_error_reason,
sizeof(local_error_reason),
858 "The merge timeout parameter (%d ms) may not be less then (%d ms).",
868 snprintf (local_error_reason,
sizeof(local_error_reason),
869 "The downcheck timeout parameter (%d ms) may not be less then (%d ms).",
887 snprintf (local_error_reason,
sizeof(local_error_reason),
888 "The RRP problem count timeout parameter (%d ms) may not be less then (%d ms).",
899 snprintf (local_error_reason,
sizeof(local_error_reason),
900 "The RRP problem count threshold (%d problem count) may not be less then (%d problem count).",
905 snprintf (local_error_reason,
sizeof(local_error_reason),
906 "The RRP multicast problem count threshold (%d problem count) may not be less then (%d problem count).",
916 snprintf (local_error_reason,
sizeof(local_error_reason),
917 "The RRP token expired timeout parameter (%d ms) may not be less then (%d ms).",
929 snprintf (error_string_response,
sizeof(error_string_response),
930 "parse error in config: %s\n", error_reason);
931 *error_string = error_string_response;
937 struct totem_config *totem_config,
938 const char **error_string)
940 static char local_error_reason[512];
941 char parse_error[512];
942 const char *error_reason = local_error_reason;
947 error_reason =
"No interfaces defined";
962 error_reason =
"No multicast address specified";
967 error_reason =
"No multicast port specified";
972 error_reason =
"Invalid TTL (should be 0..255)";
977 error_reason =
"Can only set ttl on multicast transport types";
984 error_reason =
"An IPV6 network requires that a node ID be specified.";
990 error_reason =
"Multicast address family does not match bind address family";
995 error_reason =
"Not all bind address belong to the same IP family";
999 error_reason =
"mcastaddr is not a correct multicast address.";
1005 if (totem_config->
version != 2) {
1006 error_reason =
"This totem parser can only parse version 2 configurations.";
1010 totem_set_volatile_defaults(totem_config, error_string);
1015 if (strcmp (totem_config->
rrp_mode,
"none") &&
1016 strcmp (totem_config->
rrp_mode,
"active") &&
1017 strcmp (totem_config->
rrp_mode,
"passive")) {
1018 snprintf (local_error_reason,
sizeof(local_error_reason),
1019 "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->
rrp_mode);
1023 if (strcmp (totem_config->
rrp_mode,
"none") == 0) {
1026 if (interface_max < totem_config->interface_count) {
1027 snprintf (parse_error,
sizeof(parse_error),
1028 "%d is too many configured interfaces for the rrp_mode setting %s.",
1031 error_reason = parse_error;
1035 if (totem_config->
net_mtu == 0) {
1042 snprintf (error_string_response,
sizeof(error_string_response),
1043 "parse error in config: %s\n", error_reason);
1044 *error_string = error_string_response;
1049 static int read_keyfile (
1050 const char *key_location,
1051 struct totem_config *totem_config,
1052 const char **error_string)
1056 ssize_t expected_key_len =
sizeof (totem_config->
private_key);
1058 char error_str[100];
1059 const char *error_ptr;
1061 fd = open (key_location, O_RDONLY);
1063 error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
1064 snprintf (error_string_response,
sizeof(error_string_response),
1065 "Could not open %s: %s\n",
1066 key_location, error_ptr);
1070 res = read (fd, totem_config->
private_key, expected_key_len);
1071 saved_errno = errno;
1075 error_ptr = qb_strerror_r (saved_errno, error_str,
sizeof(error_str));
1076 snprintf (error_string_response,
sizeof(error_string_response),
1077 "Could not read %s: %s\n",
1078 key_location, error_ptr);
1084 if (res != expected_key_len) {
1085 snprintf (error_string_response,
sizeof(error_string_response),
1086 "Could only read %d bits of 1024 bits from %s.\n",
1087 res * 8, key_location);
1094 *error_string = error_string_response;
1099 struct totem_config *totem_config,
1100 const char **error_string)
1103 char *key_location = NULL;
1117 res = read_keyfile(key_location, totem_config, error_string);
1125 if (key_len >
sizeof (totem_config->
private_key)) {
1126 sprintf(error_string_response,
"key is too long");
1133 sprintf(error_string_response,
"can't store private key");
1141 const char *filename = getenv(
"COROSYNC_TOTEM_AUTHKEY_FILE");
1144 res = read_keyfile(filename, totem_config, error_string);
1153 *error_string = error_string_response;
1158 static void totem_change_notify(
1160 const char *key_name,
1166 const char *error_string;
1176 param = totem_get_param_by_name((
struct totem_config *)user_data, key_name);
1185 totem_set_volatile_defaults((
struct totem_config *)user_data, &error_string);
1190 memcpy(param, new_val.
data, new_val.
len);
1198 static void totem_reload_notify(
1200 const char *key_name,
1205 struct totem_config *totem_config = (
struct totem_config *)user_data;
1206 uint32_t local_node_pos;
1209 if (*(uint8_t *)new_val.
data == 0) {
1219 put_nodelist_members_to_config (totem_config);
1220 totem_volatile_config_read (totem_config);
1223 local_node_pos = find_local_node_in_nodelist(totem_config);
1224 if (local_node_pos != -1) {
1230 static void add_totem_config_notification(
struct totem_config *totem_config)
1236 totem_change_notify,
1242 totem_reload_notify,
unsigned int clear_node_high_bit
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
#define RRP_PROBLEM_COUNT_TIMEOUT
struct totem_interface * interfaces
unsigned int interface_count
const char * totemip_print(const struct totem_ip_address *addr)
void icmap_iter_finalize(icmap_iter_t iter)
totem_transport_t transport_number
int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family)
#define DOWNCHECK_TIMEOUT
unsigned int token_hold_timeout
struct totem_ip_address member_list[PROCESSOR_COUNT_MAX]
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN]
char rrp_mode[TOTEM_RRP_MODE_BYTES]
unsigned char addr[TOTEMIP_ADDRLEN]
unsigned int rrp_problem_count_timeout
cs_error_t icmap_set_string(const char *key_name, const char *value)
int totemip_is_mcast(struct totem_ip_address *addr)
#define RRP_AUTORECOVERY_CHECK_TIMEOUT
unsigned int downcheck_timeout
unsigned int private_key_len
#define SEQNO_UNCHANGED_CONST
unsigned int max_network_delay
unsigned int heartbeat_failures_allowed
unsigned int send_join_timeout
unsigned int rrp_problem_count_threshold
#define ICMAP_TRACK_DELETE
#define RRP_PROBLEM_COUNT_THRESHOLD_MIN
#define ICMAP_KEYNAME_MAXLEN
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
int totem_config_keyread(struct totem_config *totem_config, const char **error_string)
#define ICMAP_TRACK_MODIFY
unsigned int token_retransmits_before_loss_const
int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit)
#define FAIL_TO_RECV_CONST
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
unsigned int seqno_unchanged_const
unsigned int miss_count_const
unsigned int join_timeout
int totem_config_validate(struct totem_config *totem_config, const char **error_string)
struct totem_ip_address mcast_addr
unsigned int rrp_autorecovery_check_timeout
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
unsigned int fail_to_recv_const
#define TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
#define TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
#define MAX_NETWORK_DELAY
unsigned int token_timeout
unsigned int consensus_timeout
int totemip_getifaddrs(struct list_head *addrs)
#define PROCESSOR_COUNT_MAX
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
unsigned int broadcast_use
unsigned int rrp_problem_count_mcast_threshold
cs_error_t icmap_get_string(const char *key_name, char **str)
#define list_entry(ptr, type, member)
unsigned int max_messages
char * crypto_cipher_type
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
unsigned int merge_timeout
unsigned int token_retransmit_timeout
struct totem_ip_address bindnet
icmap_iter_t icmap_iter_init(const char *prefix)
int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
struct totem_ip_address ip_addr
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
unsigned int rrp_token_expired_timeout
qb_map_iter_t * icmap_iter_t
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
#define ICMAP_TRACK_PREFIX
#define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT