44 #include <sys/socket.h> 45 #include <sys/types.h> 50 #include <netinet/in.h> 51 #include <arpa/inet.h> 52 #include <sys/param.h> 53 #include <sys/utsname.h> 56 #include <qb/qblist.h> 57 #include <qb/qbdefs.h> 67 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4 68 #define TOKEN_TIMEOUT 1000 69 #define TOKEN_WARNING 75 70 #define TOKEN_COEFFICIENT 650 71 #define JOIN_TIMEOUT 50 72 #define MERGE_TIMEOUT 200 73 #define DOWNCHECK_TIMEOUT 1000 74 #define FAIL_TO_RECV_CONST 2500 75 #define SEQNO_UNCHANGED_CONST 30 76 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3 77 #define MAX_NETWORK_DELAY 50 78 #define WINDOW_SIZE 50 79 #define MAX_MESSAGES 17 80 #define MISS_COUNT_CONST 5 83 #define KNET_PING_INTERVAL 1000 84 #define KNET_PING_TIMEOUT 2000 85 #define KNET_PING_PRECISION 2048 86 #define KNET_PONG_COUNT 2 87 #define KNET_PMTUD_INTERVAL 30 88 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP 90 #define DEFAULT_PORT 5405 92 static char error_string_response[768];
98 if (strcmp(param_name,
"totem.token") == 0)
100 if (strcmp(param_name,
"totem.token_warning") == 0)
102 if (strcmp(param_name,
"totem.token_retransmit") == 0)
104 if (strcmp(param_name,
"totem.hold") == 0)
106 if (strcmp(param_name,
"totem.token_retransmits_before_loss_const") == 0)
108 if (strcmp(param_name,
"totem.join") == 0)
110 if (strcmp(param_name,
"totem.send_join") == 0)
112 if (strcmp(param_name,
"totem.consensus") == 0)
114 if (strcmp(param_name,
"totem.merge") == 0)
116 if (strcmp(param_name,
"totem.downcheck") == 0)
118 if (strcmp(param_name,
"totem.fail_recv_const") == 0)
120 if (strcmp(param_name,
"totem.seqno_unchanged_const") == 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)
132 if (strcmp(param_name,
"totem.knet_pmtud_interval") == 0)
134 if (strcmp(param_name,
"totem.knet_compression_threshold") == 0)
136 if (strcmp(param_name,
"totem.knet_compression_level") == 0)
138 if (strcmp(param_name,
"totem.knet_compression_model") == 0)
148 static void totem_volatile_config_set_uint32_value (
struct totem_config *totem_config,
149 const char *key_name,
const char *deleted_key,
unsigned int default_value,
150 int allow_zero_value)
155 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
156 (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
157 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
170 strcpy(runtime_key_name,
"runtime.config.");
171 strcat(runtime_key_name, key_name);
173 icmap_set_uint32(runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
176 static void totem_volatile_config_set_int32_value (
struct totem_config *totem_config,
177 const char *key_name,
const char *deleted_key,
int default_value,
178 int allow_zero_value)
183 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
184 (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
185 *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
198 strcpy(runtime_key_name,
"runtime.config.");
199 strcat(runtime_key_name, key_name);
201 icmap_set_int32(runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
204 static void totem_volatile_config_set_string_value (
struct totem_config *totem_config,
205 const char *key_name,
const char *deleted_key,
const char *default_value)
209 void *old_config_ptr;
211 config_value = totem_get_param_by_name(totem_config, key_name);
212 old_config_ptr = *config_value;
214 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
217 *config_value = strdup(default_value);
219 free(old_config_ptr);
231 strcpy(runtime_key_name,
"runtime.config.");
232 strcat(runtime_key_name, key_name);
243 static void totem_volatile_config_read (
struct totem_config *totem_config,
const char *deleted_key)
247 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_retransmits_before_loss_const", deleted_key,
250 totem_volatile_config_set_uint32_value(totem_config,
"totem.token", deleted_key,
TOKEN_TIMEOUT, 0);
252 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_warning", deleted_key,
TOKEN_WARNING, 1);
265 totem_volatile_config_set_uint32_value(totem_config,
"totem.max_network_delay", deleted_key,
MAX_NETWORK_DELAY, 0);
267 totem_volatile_config_set_uint32_value(totem_config,
"totem.window_size", deleted_key,
WINDOW_SIZE, 0);
269 totem_volatile_config_set_uint32_value(totem_config,
"totem.max_messages", deleted_key,
MAX_MESSAGES, 0);
271 totem_volatile_config_set_uint32_value(totem_config,
"totem.miss_count_const", deleted_key,
MISS_COUNT_CONST, 0);
272 totem_volatile_config_set_uint32_value(totem_config,
"totem.knet_pmtud_interval", deleted_key,
KNET_PMTUD_INTERVAL, 0);
274 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_retransmit", deleted_key,
277 totem_volatile_config_set_uint32_value(totem_config,
"totem.hold", deleted_key,
280 totem_volatile_config_set_uint32_value(totem_config,
"totem.join", deleted_key,
JOIN_TIMEOUT, 0);
282 totem_volatile_config_set_uint32_value(totem_config,
"totem.consensus", deleted_key,
285 totem_volatile_config_set_uint32_value(totem_config,
"totem.merge", deleted_key,
MERGE_TIMEOUT, 0);
287 totem_volatile_config_set_uint32_value(totem_config,
"totem.downcheck", deleted_key,
DOWNCHECK_TIMEOUT, 0);
289 totem_volatile_config_set_uint32_value(totem_config,
"totem.fail_recv_const", deleted_key,
FAIL_TO_RECV_CONST, 0);
291 totem_volatile_config_set_uint32_value(totem_config,
"totem.seqno_unchanged_const", deleted_key,
294 totem_volatile_config_set_uint32_value(totem_config,
"totem.send_join", deleted_key, 0, 1);
296 totem_volatile_config_set_uint32_value(totem_config,
"totem.heartbeat_failures_allowed", deleted_key, 0, 1);
298 totem_volatile_config_set_uint32_value(totem_config,
"totem.knet_compression_threshold", deleted_key, 0, 1);
300 totem_volatile_config_set_int32_value(totem_config,
"totem.knet_compression_level", deleted_key, 0, 1);
302 totem_volatile_config_set_string_value(totem_config,
"totem.knet_compression_model", deleted_key,
"none");
307 static int totem_volatile_config_validate (
308 struct totem_config *totem_config,
309 const char **error_string)
311 static char local_error_reason[512];
312 const char *error_reason = local_error_reason;
315 int i, num_configured, members;
318 snprintf (local_error_reason,
sizeof(local_error_reason),
319 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
325 snprintf (local_error_reason,
sizeof(local_error_reason),
326 "The token timeout parameter (%d ms) may not be less than (%d ms).",
332 snprintf (local_error_reason,
sizeof(local_error_reason),
333 "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
339 snprintf (local_error_reason,
sizeof(local_error_reason),
340 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
346 snprintf (local_error_reason,
sizeof(local_error_reason),
347 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
353 snprintf (local_error_reason,
sizeof(local_error_reason),
354 "The join timeout parameter (%d ms) may not be less than (%d ms).",
360 snprintf (local_error_reason,
sizeof(local_error_reason),
361 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
367 snprintf (local_error_reason,
sizeof(local_error_reason),
368 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
374 snprintf (local_error_reason,
sizeof(local_error_reason),
375 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
381 snprintf (local_error_reason,
sizeof(local_error_reason),
382 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
395 if (num_configured > 1) {
399 snprintf(name_key,
sizeof(name_key),
"nodelist.node.%d.name", i);
402 snprintf (local_error_reason,
sizeof(local_error_reason),
403 "for a multi-link configuration, all nodes must have a 'name' attribute");
408 for (i=0; i<num_configured; i++) {
410 snprintf (local_error_reason,
sizeof(local_error_reason),
411 "Not all nodes have the same number of links");
423 snprintf (error_string_response,
sizeof(error_string_response),
424 "parse error in config: %s\n", error_reason);
425 *error_string = error_string_response;
430 static int totem_get_crypto(
struct totem_config *totem_config,
const char **error_string)
433 const char *tmp_cipher;
434 const char *tmp_hash;
435 const char *tmp_model;
442 if (strcmp(str,
"nss") == 0) {
445 if (strcmp(str,
"openssl") == 0) {
446 tmp_model =
"openssl";
454 if (strcmp(str,
"none") == 0) {
457 if (strcmp(str,
"aes256") == 0) {
458 tmp_cipher =
"aes256";
460 if (strcmp(str,
"aes192") == 0) {
461 tmp_cipher =
"aes192";
463 if (strcmp(str,
"aes128") == 0) {
464 tmp_cipher =
"aes128";
466 if (strcmp(str,
"3des") == 0) {
473 if (strcmp(str,
"none") == 0) {
476 if (strcmp(str,
"md5") == 0) {
479 if (strcmp(str,
"sha1") == 0) {
482 if (strcmp(str,
"sha256") == 0) {
485 if (strcmp(str,
"sha384") == 0) {
488 if (strcmp(str,
"sha512") == 0) {
494 if ((strcmp(tmp_cipher,
"none") != 0) &&
495 (strcmp(tmp_hash,
"none") == 0)) {
496 *error_string =
"crypto_cipher requires crypto_hash with value other than none";
500 if (strcmp(tmp_model,
"none") == 0) {
501 *error_string =
"crypto_model should be 'nss' or 'openssl'";
516 static int nodelist_byname(
const char *find_name,
int strip_domain)
519 const char *iter_key;
522 unsigned int node_pos;
524 unsigned int namelen;
528 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
533 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
539 namelen = strlen(name);
543 dot = strchr(name,
'.');
545 namelen = name - dot - 1;
548 if (strncmp(find_name, name, namelen) == 0 &&
549 strlen(find_name) == strlen(name)) {
559 static int ipaddr_equal(
struct sockaddr_storage *addr1,
struct sockaddr_storage *addr2)
563 if (addr1->ss_family != addr2->ss_family)
566 if (addr1->ss_family == AF_INET) {
567 addrlen =
sizeof(
struct sockaddr_in);
569 if (addr1->ss_family == AF_INET6) {
570 addrlen =
sizeof(
struct sockaddr_in6);
574 if (memcmp(addr1, addr2, addrlen) == 0)
585 static int find_local_node(
int use_cache)
587 char nodename2[PATH_MAX];
590 const char *iter_key;
591 unsigned int cached_pos;
594 struct ifaddrs *ifa, *ifa_list;
599 struct utsname utsname;
608 res = uname(&utsname);
612 node = utsname.nodename;
615 node_pos = nodelist_byname(node, 0);
624 strcpy(nodename2, node);
625 dot = strrchr(nodename2,
'.');
629 node_pos = nodelist_byname(nodename2, 0);
634 dot = strrchr(nodename2,
'.');
637 node_pos = nodelist_byname(nodename2, 1);
647 if (getifaddrs(&ifa_list))
650 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
654 strcpy(nodename2, node);
659 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
663 if (sa->sa_family == AF_INET) {
664 salen =
sizeof(
struct sockaddr_in);
666 if (sa->sa_family == AF_INET6) {
667 salen =
sizeof(
struct sockaddr_in6);
670 if (getnameinfo(sa, salen,
671 nodename2,
sizeof(nodename2),
674 node_pos = nodelist_byname(nodename2, 0);
681 dot = strchr(nodename2,
'.');
685 node_pos = nodelist_byname(nodename2, 0);
694 if (getnameinfo(sa,
sizeof(*sa),
695 nodename2,
sizeof(nodename2),
696 NULL, 0, NI_NUMERICHOST))
699 node_pos = nodelist_byname(nodename2, 0);
708 freeifaddrs(ifa_list);
727 char *dbnodename = NULL;
728 struct addrinfo hints;
729 struct addrinfo *result = NULL, *rp = NULL;
731 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
738 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
745 memset(&hints, 0,
sizeof(
struct addrinfo));
746 hints.ai_family = AF_UNSPEC;
747 hints.ai_socktype = SOCK_DGRAM;
749 hints.ai_protocol = IPPROTO_UDP;
751 if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
755 for (rp = result; rp != NULL; rp = rp->ai_next) {
756 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
758 ipaddr_equal((
struct sockaddr_storage *)rp->ai_addr,
759 (
struct sockaddr_storage *)ifa->ifa_addr)) {
760 freeaddrinfo(result);
767 freeaddrinfo(result);
771 freeifaddrs(ifa_list);
793 if (strcmp(str,
"ipv4") == 0) {
796 if (strcmp(str,
"ipv6") == 0) {
799 if (strcmp(str,
"ipv6-4") == 0) {
802 if (strcmp(str,
"ipv4-6") == 0) {
811 static uint16_t generate_cluster_id (
const char *cluster_name)
816 for (i = 0; i < strlen(cluster_name); i++) {
818 value += cluster_name[i];
821 return (value & 0xFFFF);
824 static int get_cluster_mcast_addr (
825 const char *cluster_name,
826 unsigned int linknumber,
831 char addr[INET6_ADDRSTRLEN + 1];
834 if (cluster_name == NULL) {
838 clusterid = generate_cluster_id(cluster_name) + linknumber;
839 memset (res, 0,
sizeof(*res));
841 switch (ip_version) {
844 snprintf(addr,
sizeof(addr),
"239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
848 snprintf(addr,
sizeof(addr),
"ff15::%x", clusterid);
862 static unsigned int generate_nodeid(
863 struct totem_config *totem_config,
874 memcpy (&nodeid, &totemip.addr, sizeof (
unsigned int));
876 #if __BYTE_ORDER == __LITTLE_ENDIAN 881 nodeid &= 0x7FFFFFFF;
886 static int check_for_duplicate_nodeids(
887 struct totem_config *totem_config,
888 const char **error_string)
892 const char *iter_key;
896 char *ring0_addr=NULL;
897 char *ring0_addr1=NULL;
898 unsigned int node_pos;
899 unsigned int node_pos1;
900 unsigned int last_node_pos = -1;
902 unsigned int nodeid1;
907 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
917 if (last_node_pos == node_pos) {
920 last_node_pos = node_pos;
934 nodeid = generate_nodeid(totem_config, ring0_addr);
943 while (((iter_key =
icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
944 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos1, tmp_key);
945 if ((res != 2) || (node_pos1 >= node_pos)) {
949 if (strcmp(tmp_key,
"nodeid") != 0) {
960 nodeid1 = generate_nodeid(totem_config, ring0_addr1);
966 if (nodeid == nodeid1) {
968 snprintf (error_string_response,
sizeof(error_string_response),
969 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
970 autogenerated?
"(autogenerated from ":
"",
971 autogenerated?ring0_addr:
"",
972 autogenerated?
")":
"");
974 *error_string = error_string_response;
990 static void calc_knet_ping_timers(
struct totem_config *totem_config)
995 for (interface = 0;
interface < INTERFACE_MAX; interface++) {
1005 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1006 "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1013 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1014 "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1029 int ring_no, set1_pos, set2_pos;
1032 memset(&empty_ip_address, 0,
sizeof(empty_ip_address));
1035 if (!set1[ring_no].configured && !set2[ring_no].configured) {
1039 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1040 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1045 if (memcmp(&set1[ring_no].member_list[set1_pos],
1046 &set2[ring_no].member_list[set2_pos],
1048 memset(&set1[ring_no].member_list[set1_pos], 0,
1050 memset(&set2[ring_no].member_list[set2_pos], 0,
1058 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1063 if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1065 "removing dynamic member %s for ring %u",
1072 if (!set2[ring_no].configured) {
1075 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1080 if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1082 "adding dynamic member %s for ring %u",
1095 static void reconfigure_links(
struct totem_config *totem_config)
1102 int local_node_pos = find_local_node(0);
1120 local_ip.nodeid = totem_config->
node_id;
1142 static void check_things_have_not_changed(
struct totem_config *totem_config)
1146 char addr_buf[INET6_ADDRSTRLEN];
1154 "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1166 strncpy(addr_buf, ip_str,
sizeof(addr_buf));
1167 addr_buf[
sizeof(addr_buf) - 1] =
'\0';
1169 "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1179 log_printf(
LOGSYS_LEVEL_ERROR,
"To reconfigure an interface it must be deleted and recreated. A working interface needs to be available to corosync at all times");
1184 static int put_nodelist_members_to_config(
struct totem_config *totem_config,
int reload,
const char **error_string)
1187 const char *iter_key, *iter_key2;
1189 unsigned int node_pos;
1192 char *node_addr_str;
1194 unsigned int linknumber = 0;
1196 int last_node_pos = -1;
1205 new_interfaces = malloc (
sizeof (
struct totem_interface) * INTERFACE_MAX);
1206 assert(new_interfaces != NULL);
1219 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1224 if (node_pos == last_node_pos) {
1227 last_node_pos = node_pos;
1240 res = sscanf(iter_key2,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1241 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1255 nodeid = generate_nodeid(totem_config, str);
1257 "Generated nodeid = 0x%x for %s", nodeid, str);
1270 sprintf(error_string_response,
"failed to parse node address '%s'\n", node_addr_str);
1271 *error_string = error_string_response;
1276 free(node_addr_str);
1282 free(node_addr_str);
1292 reconfigure_links(totem_config);
1296 check_things_have_not_changed(totem_config);
1298 compute_interfaces_diff(totem_config->
orig_interfaces, new_interfaces);
1300 free(new_interfaces);
1305 static void config_convert_nodelist_to_interface(
struct totem_config *totem_config)
1311 char *node_addr_str;
1312 unsigned int linknumber = 0;
1314 const char *iter_key;
1316 node_pos = find_local_node(1);
1317 if (node_pos > -1) {
1324 res = sscanf(iter_key,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1325 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1335 free(node_addr_str);
1341 static int get_interface_params(
struct totem_config *totem_config,
1342 const char **error_string, uint64_t *warnings,
1346 unsigned int linknumber = 0;
1347 int member_count = 0;
1350 const char *iter_key;
1351 const char *member_iter_key;
1357 char *cluster_name = NULL;
1374 cluster_name = NULL;
1379 res = sscanf(iter_key,
"totem.interface.%[^.].%s", linknumber_key, tmp_key);
1389 linknumber = atoi(linknumber_key);
1391 if (linknumber >= INTERFACE_MAX) {
1394 snprintf (error_string_response,
sizeof(error_string_response),
1395 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1396 linknumber, INTERFACE_MAX - 1);
1398 *error_string = error_string_response;
1414 sprintf(error_string_response,
"failed to parse bindnet address '%s'\n", str);
1415 *error_string = error_string_response;
1433 sprintf(error_string_response,
"failed to parse mcast address '%s'\n", str);
1434 *error_string = error_string_response;
1448 (void)get_cluster_mcast_addr (cluster_name,
1456 if (strcmp (str,
"yes") == 0) {
1492 if (strcmp(str,
"sctp") == 0) {
1495 else if (strcmp(str,
"udp") == 0) {
1499 *error_string =
"Unrecognised knet_transport. expected 'udp' or 'sctp'";
1539 while ((member_iter_key =
icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1540 if (member_count == 0) {
1554 sprintf(error_string_response,
"failed to parse node address '%s'\n", str);
1555 *error_string = error_string_response;
1577 struct totem_config *totem_config,
1578 const char **error_string,
1582 char *str, *ring0_addr_str;
1591 memset (totem_config, 0,
sizeof (
struct totem_config));
1594 *error_string =
"Out of memory trying to allocate ethernet interface storage area";
1600 if (strcmp (str,
"udpu") == 0) {
1604 if (strcmp (str,
"udp") == 0) {
1608 if (strcmp (str,
"knet") == 0) {
1618 strcpy (totem_config->
link_mode,
"passive");
1622 if (totem_get_crypto(totem_config, error_string) != 0) {
1628 *error_string =
"totem.link_mode is too long";
1641 if (strcmp (str,
"yes") == 0) {
1651 totem_config->
ip_version = totem_config_get_ip_version(totem_config);
1657 config_convert_nodelist_to_interface(totem_config);
1666 config_convert_nodelist_to_interface(totem_config);
1668 free(ring0_addr_str);
1680 res = get_interface_params(totem_config, error_string, warnings, 0);
1727 local_node_pos = find_local_node(1);
1728 if (local_node_pos != -1) {
1732 nodeid_set = (totem_config->
node_id != 0);
1737 *error_string =
"Knet requires an explicit nodeid for the local node";
1747 totem_config->
node_id = generate_nodeid(totem_config, str);
1757 if (put_nodelist_members_to_config(totem_config, 0, error_string)) {
1765 totem_volatile_config_read(totem_config, NULL);
1767 calc_knet_ping_timers(totem_config);
1771 add_totem_config_notification(totem_config);
1778 struct totem_config *totem_config,
1779 const char **error_string)
1781 static char local_error_reason[512];
1782 char parse_error[512];
1783 static char addr_str_buf[INET6_ADDRSTRLEN];
1784 const char *error_reason = local_error_reason;
1787 int num_configured = 0;
1795 if (num_configured == 0) {
1796 error_reason =
"No interfaces defined";
1802 error_reason =
"No valid name found for local host";
1822 error_reason =
"No multicast address specified";
1827 error_reason =
"No multicast port specified";
1832 error_reason =
"Invalid TTL (should be 0..255)";
1837 error_reason =
"Can only set ttl on multicast transport types";
1841 error_reason =
"Invalid link priority (should be 0..255)";
1846 error_reason =
"Can only set link priority on knet transport type";
1853 error_reason =
"An IPV6 network requires that a node ID be specified.";
1859 error_reason =
"Multicast address family does not match bind address family";
1864 error_reason =
"mcastaddr is not a correct multicast address.";
1873 memcpy(addr_str_buf,
1875 sizeof(addr_str_buf));
1877 snprintf (local_error_reason,
sizeof(local_error_reason),
1878 "Nodes for link %d have different IP families " 1879 "(compared %s with %s)", i,
1888 if (totem_config->
version != 2) {
1889 error_reason =
"This totem parser can only parse version 2 configurations.";
1893 if (totem_volatile_config_validate(totem_config, error_string) == -1) {
1897 if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
1904 if (strcmp (totem_config->
link_mode,
"active") &&
1905 strcmp (totem_config->
link_mode,
"rr") &&
1906 strcmp (totem_config->
link_mode,
"passive")) {
1907 snprintf (local_error_reason,
sizeof(local_error_reason),
1908 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->
link_mode);
1917 if (interface_max < num_configured) {
1918 snprintf (parse_error,
sizeof(parse_error),
1919 "%d is too many configured interfaces for non-Knet transport.",
1921 error_reason = parse_error;
1930 snprintf (parse_error,
sizeof(parse_error),
1931 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
1932 error_reason = parse_error;
1937 if (totem_config->
net_mtu == 0) {
1939 totem_config->
net_mtu = KNET_MAX_PACKET_SIZE;
1949 snprintf (error_string_response,
sizeof(error_string_response),
1950 "parse error in config: %s\n", error_reason);
1951 *error_string = error_string_response;
1956 static int read_keyfile (
1957 const char *key_location,
1958 struct totem_config *totem_config,
1959 const char **error_string)
1964 char error_str[100];
1965 const char *error_ptr;
1967 fd = open (key_location, O_RDONLY);
1969 error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
1970 snprintf (error_string_response,
sizeof(error_string_response),
1971 "Could not open %s: %s\n",
1972 key_location, error_ptr);
1977 saved_errno = errno;
1981 error_ptr = qb_strerror_r (saved_errno, error_str,
sizeof(error_str));
1982 snprintf (error_string_response,
sizeof(error_string_response),
1983 "Could not read %s: %s\n",
1984 key_location, error_ptr);
1989 snprintf (error_string_response,
sizeof(error_string_response),
1990 "Could only read %d bits of minimum %u bits from %s.\n",
2000 *error_string = error_string_response;
2005 struct totem_config *totem_config,
2006 const char **error_string)
2009 char *key_location = NULL;
2023 res = read_keyfile(key_location, totem_config, error_string);
2031 if (key_len >
sizeof(totem_config->
private_key)) {
2032 sprintf(error_string_response,
"key is too long");
2036 sprintf(error_string_response,
"key is too short");
2043 sprintf(error_string_response,
"can't load private key");
2051 res = read_keyfile(
COROSYSCONFDIR "/authkey", totem_config, error_string);
2059 *error_string = error_string_response;
2064 static void debug_dump_totem_config(
const struct totem_config *totem_config)
2073 if (token_warning_ms < totem_config->token_retransmit_timeout)
2075 "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) " 2076 "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2089 "seqno unchanged const (%d rotations) Maximum network MTU %d",
2092 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2100 static void totem_change_notify(
2102 const char *key_name,
2107 struct totem_config *totem_config = (
struct totem_config *)user_data;
2110 const char *deleted_key = NULL;
2111 const char *error_string;
2120 param = totem_get_param_by_name((
struct totem_config *)user_data, key_name);
2126 if (!param && strcmp(key_name,
"totem.token_coefficient") != 0)
2134 deleted_key = key_name;
2144 totem_volatile_config_read (totem_config, deleted_key);
2146 debug_dump_totem_config(totem_config);
2147 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2156 static void totem_reload_notify(
2158 const char *key_name,
2163 struct totem_config *totem_config = (
struct totem_config *)user_data;
2164 const char *error_string;
2168 if (*(uint8_t *)new_val.
data == 0) {
2174 get_interface_params(totem_config, &error_string, &warnings, 1);
2175 if (put_nodelist_members_to_config (totem_config, 1, &error_string)) {
2178 totem_volatile_config_read (totem_config, NULL);
2180 calc_knet_ping_timers(totem_config);
2183 debug_dump_totem_config(totem_config);
2184 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2193 (void)find_local_node(0);
2206 static void add_totem_config_notification(
struct totem_config *totem_config)
2212 totem_change_notify,
2218 totem_reload_notify,
unsigned int clear_node_high_bit
int totempg_iface_set(struct totem_ip_address *interface_addr, unsigned short ip_port, unsigned int iface_no)
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
#define LOGSYS_LEVEL_INFO
struct totem_interface * interfaces
The totem_ip_address struct.
const char * totemip_print(const struct totem_ip_address *addr)
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
totem_transport_t transport_number
#define DOWNCHECK_TIMEOUT
unsigned int token_hold_timeout
struct totem_ip_address member_list[PROCESSOR_COUNT_MAX]
uint32_t knet_compression_threshold
char link_mode[TOTEM_LINK_MODE_BYTES]
unsigned int knet_pmtud_interval
unsigned char addr[TOTEMIP_ADDRLEN]
cs_error_t icmap_set_string(const char *key_name, const char *value)
int totemip_is_mcast(struct totem_ip_address *addr)
unsigned int downcheck_timeout
#define KNET_DEFAULT_TRANSPORT
unsigned int private_key_len
#define SEQNO_UNCHANGED_CONST
unsigned int max_network_delay
#define log_printf(level, format, args...)
unsigned int heartbeat_failures_allowed
unsigned int send_join_timeout
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
#define ICMAP_TRACK_DELETE
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
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
char * knet_compression_model
#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)
#define TOTEM_CONFIG_BINDNETADDR_NODELIST_SET
struct totem_ip_address mcast_addr
#define LOGSYS_LEVEL_ERROR
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Retrieve value of key key_name and store it in user preallocated value pointer.
#define LOGSYS_LEVEL_DEBUG
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
unsigned int fail_to_recv_const
#define TOKEN_COEFFICIENT
int totempg_member_remove(const struct totem_ip_address *member, int ring_no)
#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
int knet_compression_level
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
#define swab32(x)
The swab32 macro.
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
#define MAX_NETWORK_DELAY
unsigned int token_timeout
unsigned int consensus_timeout
#define PROCESSOR_COUNT_MAX
unsigned int token_warning
int totempg_reconfigure(void)
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
unsigned int broadcast_use
#define KNET_PING_PRECISION
struct totem_interface * orig_interfaces
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
#define KNET_PMTUD_INTERVAL
unsigned int max_messages
char * crypto_cipher_type
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Set read-only access for given key (key_name) or prefix, If prefix is set.
unsigned int merge_timeout
enum totem_ip_version_enum ip_version
unsigned int token_retransmit_timeout
struct totem_ip_address bindnet
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
qb_map_iter_t * icmap_iter_t
Itterator type.
Structure passed as new_value and old_value in change callback.
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)
Add tracking function for given key_name.
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
int totempg_member_add(const struct totem_ip_address *member, int ring_no)