45 #include <sys/socket.h>
46 #include <sys/types.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
53 #include <sys/param.h>
54 #include <sys/utsname.h>
57 #include <qb/qblist.h>
58 #include <qb/qbdefs.h>
68 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
69 #define TOKEN_TIMEOUT 3000
70 #define TOKEN_WARNING 75
71 #define TOKEN_COEFFICIENT 650
72 #define JOIN_TIMEOUT 50
73 #define MERGE_TIMEOUT 200
74 #define DOWNCHECK_TIMEOUT 1000
75 #define FAIL_TO_RECV_CONST 2500
76 #define SEQNO_UNCHANGED_CONST 30
77 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
78 #define MINIMUM_TIMEOUT_HOLD (int)(MINIMUM_TIMEOUT * 0.8 - (1000/HZ))
79 #define MAX_NETWORK_DELAY 50
80 #define WINDOW_SIZE 50
81 #define MAX_MESSAGES 17
82 #define MISS_COUNT_CONST 5
83 #define BLOCK_UNLISTED_IPS 1
84 #define CANCEL_TOKEN_HOLD_ON_RETRANSMIT 0
86 #define UDP_NETMTU 1500
89 #define KNET_PING_INTERVAL 1000
90 #define KNET_PING_TIMEOUT 2000
91 #define KNET_PING_PRECISION 2048
92 #define KNET_PONG_COUNT 2
93 #define KNET_PMTUD_INTERVAL 30
95 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP
97 #define DEFAULT_PORT 5405
99 static char error_string_response[768];
105 if (strcmp(param_name,
"totem.token") == 0)
107 if (strcmp(param_name,
"totem.token_warning") == 0)
109 if (strcmp(param_name,
"totem.token_retransmit") == 0)
111 if (strcmp(param_name,
"totem.hold") == 0)
113 if (strcmp(param_name,
"totem.token_retransmits_before_loss_const") == 0)
115 if (strcmp(param_name,
"totem.join") == 0)
117 if (strcmp(param_name,
"totem.send_join") == 0)
119 if (strcmp(param_name,
"totem.consensus") == 0)
121 if (strcmp(param_name,
"totem.merge") == 0)
123 if (strcmp(param_name,
"totem.downcheck") == 0)
125 if (strcmp(param_name,
"totem.fail_recv_const") == 0)
127 if (strcmp(param_name,
"totem.seqno_unchanged_const") == 0)
129 if (strcmp(param_name,
"totem.heartbeat_failures_allowed") == 0)
131 if (strcmp(param_name,
"totem.max_network_delay") == 0)
133 if (strcmp(param_name,
"totem.window_size") == 0)
135 if (strcmp(param_name,
"totem.max_messages") == 0)
137 if (strcmp(param_name,
"totem.miss_count_const") == 0)
139 if (strcmp(param_name,
"totem.knet_pmtud_interval") == 0)
141 if (strcmp(param_name,
"totem.knet_mtu") == 0)
143 if (strcmp(param_name,
"totem.knet_compression_threshold") == 0)
145 if (strcmp(param_name,
"totem.knet_compression_level") == 0)
147 if (strcmp(param_name,
"totem.knet_compression_model") == 0)
149 if (strcmp(param_name,
"totem.block_unlisted_ips") == 0)
151 if (strcmp(param_name,
"totem.cancel_token_hold_on_retransmit") == 0)
161 static void totem_volatile_config_set_uint32_value (
struct totem_config *totem_config,
icmap_map_t map,
162 const char *key_name,
const char *deleted_key,
unsigned int default_value,
163 int allow_zero_value)
168 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
169 (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
170 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
183 strcpy(runtime_key_name,
"runtime.config.");
184 strcat(runtime_key_name, key_name);
186 icmap_set_uint32_r(map, runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
189 static void totem_volatile_config_set_int32_value (
struct totem_config *totem_config,
icmap_map_t map,
190 const char *key_name,
const char *deleted_key,
int default_value,
191 int allow_zero_value)
196 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
197 (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
198 *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
211 strcpy(runtime_key_name,
"runtime.config.");
212 strcat(runtime_key_name, key_name);
214 icmap_set_int32_r(map, runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
217 static void totem_volatile_config_set_string_value (
struct totem_config *totem_config,
icmap_map_t map,
218 const char *key_name,
const char *deleted_key,
const char *default_value)
222 char *new_config_value;
223 const void *config_value;
225 config_value = totem_get_param_by_name(totem_config, key_name);
229 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
237 free(new_config_value);
250 strcpy(runtime_key_name,
"runtime.config.");
251 strcat(runtime_key_name, key_name);
263 static void totem_volatile_config_set_boolean_value (
struct totem_config *totem_config,
icmap_map_t map,
264 const char *key_name,
const char *deleted_key,
unsigned int default_value)
273 if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
280 if (strcmp(str,
"yes") == 0) {
282 }
else if (strcmp(str,
"no") == 0) {
298 strcpy(runtime_key_name,
"runtime.config.");
299 strcat(runtime_key_name, key_name);
301 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = val;
315 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.token_retransmits_before_loss_const", deleted_key,
318 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.token", deleted_key,
TOKEN_TIMEOUT, 0);
320 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.token_warning", deleted_key,
TOKEN_WARNING, 1);
333 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.max_network_delay", deleted_key,
MAX_NETWORK_DELAY, 0);
335 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.window_size", deleted_key,
WINDOW_SIZE, 0);
337 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.max_messages", deleted_key,
MAX_MESSAGES, 0);
339 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.miss_count_const", deleted_key,
MISS_COUNT_CONST, 0);
340 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.knet_pmtud_interval", deleted_key,
KNET_PMTUD_INTERVAL, 0);
341 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.knet_mtu", deleted_key,
KNET_MTU, 0);
343 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.token_retransmit", deleted_key,
346 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.hold", deleted_key,
349 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.join", deleted_key,
JOIN_TIMEOUT, 0);
351 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.consensus", deleted_key,
354 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.merge", deleted_key,
MERGE_TIMEOUT, 0);
356 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.downcheck", deleted_key,
DOWNCHECK_TIMEOUT, 0);
358 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.fail_recv_const", deleted_key,
FAIL_TO_RECV_CONST, 0);
360 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.seqno_unchanged_const", deleted_key,
363 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.send_join", deleted_key, 0, 1);
365 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.heartbeat_failures_allowed", deleted_key, 0, 1);
367 totem_volatile_config_set_uint32_value(totem_config, temp_map,
"totem.knet_compression_threshold", deleted_key, 0, 1);
369 totem_volatile_config_set_int32_value(totem_config, temp_map,
"totem.knet_compression_level", deleted_key, 0, 1);
371 totem_volatile_config_set_string_value(totem_config, temp_map,
"totem.knet_compression_model", deleted_key,
"none");
373 totem_volatile_config_set_boolean_value(totem_config, temp_map,
"totem.block_unlisted_ips", deleted_key,
376 totem_volatile_config_set_boolean_value(totem_config, temp_map,
"totem.cancel_token_hold_on_retransmit",
381 struct totem_config *totem_config,
383 const char **error_string)
386 static char local_error_reason[512];
387 static char addr_str_buf[INET6_ADDRSTRLEN];
388 const char *error_reason = local_error_reason;
391 int i, j, num_configured, members;
392 uint32_t tmp_config_value;
395 snprintf (local_error_reason,
sizeof(local_error_reason),
396 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
402 snprintf (local_error_reason,
sizeof(local_error_reason),
403 "The token timeout parameter (%d ms) may not be less than (%d ms).",
409 snprintf (local_error_reason,
sizeof(local_error_reason),
410 "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
417 snprintf (local_error_reason,
sizeof(local_error_reason),
418 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
422 snprintf (local_error_reason,
sizeof(local_error_reason),
423 "Not appropriate token or token_retransmits_before_loss_const value set");
429 snprintf (local_error_reason,
sizeof(local_error_reason),
430 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
436 snprintf (local_error_reason,
sizeof(local_error_reason),
437 "The join timeout parameter (%d ms) may not be less than (%d ms).",
443 snprintf (local_error_reason,
sizeof(local_error_reason),
444 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
450 snprintf (local_error_reason,
sizeof(local_error_reason),
451 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
457 snprintf (local_error_reason,
sizeof(local_error_reason),
458 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
464 snprintf (local_error_reason,
sizeof(local_error_reason),
465 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
475 if (num_configured == 0) {
482 if (num_configured > 1) {
486 assert(members != -1);
487 for (i=0; i < members; i++) {
488 snprintf(name_key,
sizeof(name_key),
"nodelist.node.%d.name", i);
491 snprintf (local_error_reason,
sizeof(local_error_reason),
492 "for a multi-link configuration, all nodes must have a 'name' attribute");
504 snprintf (local_error_reason,
sizeof(local_error_reason),
505 "Not all nodes have the same number of links");
519 sizeof(addr_str_buf));
521 snprintf (local_error_reason,
sizeof(local_error_reason),
522 "Nodes for link %d have different IP families "
523 "(compared %s with %s)", i,
535 snprintf (error_string_response,
sizeof(error_string_response),
536 "parse error in config: %s\n", error_reason);
537 *error_string = error_string_response;
542 static int totem_get_crypto(
struct totem_config *totem_config,
icmap_map_t map,
const char **error_string)
545 const char *tmp_cipher;
546 const char *tmp_hash;
547 const char *tmp_model;
548 char *crypto_model_str;
555 crypto_model_str = NULL;
557 tmp_model = crypto_model_str;
563 if (strcmp(str,
"on") == 0) {
564 tmp_cipher =
"aes256";
571 if (strcmp(str,
"none") == 0) {
574 if (strcmp(str,
"aes256") == 0) {
575 tmp_cipher =
"aes256";
577 if (strcmp(str,
"aes192") == 0) {
578 tmp_cipher =
"aes192";
580 if (strcmp(str,
"aes128") == 0) {
581 tmp_cipher =
"aes128";
587 if (strcmp(str,
"none") == 0) {
590 if (strcmp(str,
"md5") == 0) {
593 if (strcmp(str,
"sha1") == 0) {
596 if (strcmp(str,
"sha256") == 0) {
599 if (strcmp(str,
"sha384") == 0) {
602 if (strcmp(str,
"sha512") == 0) {
608 if ((strcmp(tmp_cipher,
"none") != 0) &&
609 (strcmp(tmp_hash,
"none") == 0)) {
610 *error_string =
"crypto_cipher requires crypto_hash with value other than none";
613 goto out_free_crypto_model_str;
616 if (strcmp(tmp_model,
"none") == 0) {
620 *error_string =
"invalid crypto_model";
623 goto out_free_crypto_model_str;
641 out_free_crypto_model_str:
642 free(crypto_model_str);
647 static int nodelist_byname(
icmap_map_t map,
const char *find_name,
int strip_domain)
650 const char *iter_key;
653 unsigned int node_pos;
655 unsigned int namelen;
659 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
664 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
670 namelen = strlen(name);
674 dot = strchr(name,
'.');
676 namelen = dot - name;
679 if (strncmp(find_name, name, namelen) == 0 &&
680 strlen(find_name) == namelen) {
690 static int ipaddr_equal(
const struct sockaddr *addr1,
const struct sockaddr *addr2)
693 const void *addr1p, *addr2p;
695 if (addr1->sa_family != addr2->sa_family)
698 switch (addr1->sa_family) {
700 addrlen =
sizeof(
struct in_addr);
701 addr1p = &((
struct sockaddr_in *)addr1)->sin_addr;
702 addr2p = &((
struct sockaddr_in *)addr2)->sin_addr;
705 addrlen =
sizeof(
struct in6_addr);
706 addr1p = &((
struct sockaddr_in6 *)addr1)->sin6_addr;
707 addr2p = &((
struct sockaddr_in6 *)addr2)->sin6_addr;
713 return (memcmp(addr1p, addr2p, addrlen) == 0);
720 static int find_local_node(
icmap_map_t map,
int use_cache)
722 char nodename2[PATH_MAX];
725 const char *iter_key;
726 unsigned int cached_pos;
729 struct ifaddrs *ifa, *ifa_list;
734 struct utsname utsname;
743 res = uname(&utsname);
747 node = utsname.nodename;
750 node_pos = nodelist_byname(map, node, 0);
759 strcpy(nodename2, node);
760 dot = strrchr(nodename2,
'.');
764 node_pos = nodelist_byname(map, nodename2, 0);
769 dot = strrchr(nodename2,
'.');
772 node_pos = nodelist_byname(map, nodename2, 1);
782 if (getifaddrs(&ifa_list))
785 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
789 strcpy(nodename2, node);
794 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
798 if (sa->sa_family == AF_INET) {
799 salen =
sizeof(
struct sockaddr_in);
801 if (sa->sa_family == AF_INET6) {
802 salen =
sizeof(
struct sockaddr_in6);
805 if (getnameinfo(sa, salen,
806 nodename2,
sizeof(nodename2),
809 node_pos = nodelist_byname(map, nodename2, 0);
816 dot = strchr(nodename2,
'.');
820 node_pos = nodelist_byname(map, nodename2, 0);
829 if (getnameinfo(sa,
sizeof(*sa),
830 nodename2,
sizeof(nodename2),
831 NULL, 0, NI_NUMERICHOST))
834 node_pos = nodelist_byname(map, nodename2, 0);
843 freeifaddrs(ifa_list);
862 char *dbnodename = NULL;
863 struct addrinfo hints;
864 struct addrinfo *result = NULL, *rp = NULL;
866 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
873 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
880 memset(&hints, 0,
sizeof(
struct addrinfo));
881 hints.ai_family = AF_UNSPEC;
882 hints.ai_socktype = SOCK_DGRAM;
884 hints.ai_protocol = IPPROTO_UDP;
886 if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
890 for (rp = result; rp != NULL; rp = rp->ai_next) {
891 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
893 ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
894 freeaddrinfo(result);
901 freeaddrinfo(result);
905 freeifaddrs(ifa_list);
927 if (strcmp(str,
"ipv4") == 0) {
930 if (strcmp(str,
"ipv6") == 0) {
933 if (strcmp(str,
"ipv6-4") == 0) {
936 if (strcmp(str,
"ipv4-6") == 0) {
945 static uint16_t generate_cluster_id (
const char *cluster_name)
950 for (i = 0; i < strlen(cluster_name); i++) {
952 value += cluster_name[i];
955 return (value & 0xFFFF);
958 static int get_cluster_mcast_addr (
959 const char *cluster_name,
960 unsigned int linknumber,
965 char addr[INET6_ADDRSTRLEN + 1];
968 if (cluster_name == NULL) {
972 clusterid = generate_cluster_id(cluster_name) + linknumber;
973 memset (res, 0,
sizeof(*res));
975 switch (ip_version) {
978 snprintf(addr,
sizeof(addr),
"239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
982 snprintf(addr,
sizeof(addr),
"ff15::%x", clusterid);
996 static unsigned int generate_nodeid(
997 struct totem_config *totem_config,
1008 memcpy (&nodeid, &totemip.addr, sizeof (
unsigned int));
1010 #if __BYTE_ORDER == __LITTLE_ENDIAN
1011 nodeid =
swab32 (nodeid);
1015 nodeid &= 0x7FFFFFFF;
1020 static int check_for_duplicate_nodeids(
1021 struct totem_config *totem_config,
1022 const char **error_string)
1026 const char *iter_key;
1030 char *ring0_addr=NULL;
1031 char *ring0_addr1=NULL;
1032 unsigned int node_pos;
1033 unsigned int node_pos1;
1034 unsigned int last_node_pos = -1;
1036 unsigned int nodeid1;
1041 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1051 if (last_node_pos == node_pos) {
1054 last_node_pos = node_pos;
1068 nodeid = generate_nodeid(totem_config, ring0_addr);
1077 while (((iter_key =
icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
1078 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos1, tmp_key);
1079 if ((res != 2) || (node_pos1 >= node_pos)) {
1083 if (strcmp(tmp_key,
"nodeid") != 0) {
1094 nodeid1 = generate_nodeid(totem_config, ring0_addr1);
1095 if (nodeid1 == -1) {
1100 if (nodeid == nodeid1) {
1102 snprintf (error_string_response,
sizeof(error_string_response),
1103 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
1104 autogenerated?
"(autogenerated from ":
"",
1105 autogenerated?ring0_addr:
"",
1106 autogenerated?
")":
"");
1107 *error_string = error_string_response;
1123 static void calc_knet_ping_timers(
struct totem_config *totem_config)
1128 for (interface = 0;
interface <
INTERFACE_MAX; interface++) {
1138 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1139 "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1146 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1147 "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1160 static int compute_and_set_totempg_interfaces(
struct totem_interface *set1,
1163 int ring_no, set1_pos, set2_pos;
1167 memset(&empty_ip_address, 0,
sizeof(empty_ip_address));
1170 if (!set1[ring_no].configured && !set2[ring_no].configured) {
1174 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1175 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1180 if (memcmp(&set1[ring_no].member_list[set1_pos],
1181 &set2[ring_no].member_list[set2_pos],
1183 memset(&set1[ring_no].member_list[set1_pos], 0,
1185 memset(&set2[ring_no].member_list[set2_pos], 0,
1193 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1198 if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1200 "removing dynamic member %s for ring %u",
1207 if (!set2[ring_no].configured) {
1210 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1215 if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1217 "adding dynamic member %s for ring %u",
1233 static void configure_link_params(
struct totem_config *totem_config,
icmap_map_t map)
1239 int local_node_pos = find_local_node(map, 0);
1276 static void configure_totem_links(
struct totem_config *totem_config,
icmap_map_t map)
1292 static int check_things_have_not_changed(
struct totem_config *totem_config,
const char **error_string)
1296 char addr_buf[INET6_ADDRSTRLEN];
1305 "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1325 strncpy(addr_buf, ip_str,
sizeof(addr_buf));
1326 addr_buf[
sizeof(addr_buf) - 1] =
'\0';
1328 "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1340 snprintf (error_string_response,
sizeof(error_string_response),
1341 "To reconfigure an interface it must be deleted and recreated. A working interface needs to be available to corosync at all times");
1342 *error_string = error_string_response;
1349 static int put_nodelist_members_to_config(
struct totem_config *totem_config,
icmap_map_t map,
1350 int reload,
const char **error_string)
1353 const char *iter_key, *iter_key2;
1355 unsigned int node_pos;
1358 char *node_addr_str;
1360 unsigned int linknumber = 0;
1362 int last_node_pos = -1;
1374 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1379 if (node_pos == last_node_pos) {
1382 last_node_pos = node_pos;
1395 res = sscanf(iter_key2,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1396 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1399 if (linknumber >= INTERFACE_MAX) {
1400 snprintf (error_string_response,
sizeof(error_string_response),
1401 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1402 linknumber, INTERFACE_MAX - 1);
1403 *error_string = error_string_response;
1420 nodeid = generate_nodeid(totem_config, str);
1422 sprintf(error_string_response,
1423 "An IPV6 network requires that a node ID be specified "
1424 "for address '%s'.", node_addr_str);
1425 *error_string = error_string_response;
1447 sprintf(error_string_response,
1448 "Knet requires an explicit nodeid to be specified "
1449 "for address '%s'.", node_addr_str);
1450 *error_string = error_string_response;
1456 sprintf(error_string_response,
1457 "Knet requires nodeid to be less than %u "
1458 "for address '%s'.", KNET_MAX_HOST, node_addr_str);
1459 *error_string = error_string_response;
1472 sprintf(error_string_response,
"failed to parse node address '%s'\n", node_addr_str);
1473 *error_string = error_string_response;
1478 free(node_addr_str);
1484 free(node_addr_str);
1492 configure_link_params(totem_config, map);
1496 if (check_things_have_not_changed(totem_config, error_string) == -1) {
1503 static void config_convert_nodelist_to_interface(
icmap_map_t map,
struct totem_config *totem_config)
1509 char *node_addr_str;
1510 unsigned int linknumber = 0;
1512 const char *iter_key;
1514 node_pos = find_local_node(map, 1);
1515 if (node_pos > -1) {
1522 res = sscanf(iter_key,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1523 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1533 free(node_addr_str);
1539 static int get_interface_params(
struct totem_config *totem_config,
icmap_map_t map,
1540 const char **error_string, uint64_t *warnings,
1544 unsigned int linknumber = 0;
1545 int member_count = 0;
1548 const char *iter_key;
1549 const char *member_iter_key;
1555 char *cluster_name = NULL;
1574 cluster_name = NULL;
1579 res = sscanf(iter_key,
"totem.interface.%[^.].%s", linknumber_key, tmp_key);
1589 linknumber = atoi(linknumber_key);
1591 if (linknumber >= INTERFACE_MAX) {
1592 snprintf (error_string_response,
sizeof(error_string_response),
1593 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1594 linknumber, INTERFACE_MAX - 1);
1596 *error_string = error_string_response;
1613 sprintf(error_string_response,
"failed to parse bindnet address '%s'\n", str);
1614 *error_string = error_string_response;
1633 sprintf(error_string_response,
"failed to parse mcast address '%s'\n", str);
1634 *error_string = error_string_response;
1656 (void)get_cluster_mcast_addr (cluster_name,
1664 if (strcmp (str,
"yes") == 0) {
1700 if (strcmp(str,
"sctp") == 0) {
1703 else if (strcmp(str,
"udp") == 0) {
1707 *error_string =
"Unrecognised knet_transport. expected 'udp' or 'sctp'";
1748 while ((member_iter_key =
icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1749 if (member_count == 0) {
1763 sprintf(error_string_response,
"failed to parse node address '%s'\n", str);
1764 *error_string = error_string_response;
1789 struct totem_config *totem_config,
1790 const char **error_string,
1794 char *str, *ring0_addr_str;
1803 memset (totem_config, 0,
sizeof (
struct totem_config));
1806 *error_string =
"Out of memory trying to allocate ethernet interface storage area";
1812 if (strcmp (str,
"udpu") == 0) {
1814 }
else if (strcmp (str,
"udp") == 0) {
1816 }
else if (strcmp (str,
"knet") == 0) {
1819 *error_string =
"Invalid transport type. Should be udpu, udp or knet";
1830 strcpy (totem_config->
link_mode,
"passive");
1846 *error_string =
"totem.link_mode is too long";
1861 if (strcmp (str,
"yes") == 0) {
1871 totem_config->
ip_version = totem_config_get_ip_version(totem_config);
1888 free(ring0_addr_str);
1948 if (local_node_pos != -1) {
1950 assert(totem_config->
node_id == 0);
1957 *error_string =
"Knet requires an explicit nodeid for the local node";
1967 totem_config->
node_id = generate_nodeid(totem_config, str);
1968 if (totem_config->
node_id == -1) {
1969 *error_string =
"An IPV6 network requires that a node ID be specified";
1994 calc_knet_ping_timers(totem_config);
1999 add_totem_config_notification(totem_config);
2006 struct totem_config *totem_config,
2007 const char **error_string)
2009 static char local_error_reason[512];
2010 char parse_error[512];
2011 const char *error_reason = local_error_reason;
2014 int num_configured = 0;
2022 if (num_configured == 0) {
2023 error_reason =
"No interfaces defined";
2029 error_reason =
"No valid name found for local host";
2049 snprintf (local_error_reason,
sizeof(local_error_reason),
2050 "No multicast address specified for interface %u", i);
2055 snprintf (local_error_reason,
sizeof(local_error_reason),
2056 "No multicast port specified for interface %u", i);
2061 snprintf (local_error_reason,
sizeof(local_error_reason),
2062 "Invalid TTL (should be 0..255) for interface %u", i);
2067 snprintf (local_error_reason,
sizeof(local_error_reason),
2068 "Can only set ttl on multicast transport types for interface %u", i);
2072 snprintf (local_error_reason,
sizeof(local_error_reason),
2073 "Invalid link priority (should be 0..255) for interface %u", i);
2078 snprintf (local_error_reason,
sizeof(local_error_reason),
2079 "Can only set link priority on knet transport type for interface %u", i);
2085 snprintf (local_error_reason,
sizeof(local_error_reason),
2086 "An IPV6 network requires that a node ID be specified for interface %u", i);
2092 snprintf (local_error_reason,
sizeof(local_error_reason),
2093 "Multicast address family does not match bind address family for interface %u", i);
2098 snprintf (local_error_reason,
sizeof(local_error_reason),
2099 "mcastaddr is not a correct multicast address for interface %u", i);
2105 if (totem_config->
version != 2) {
2106 error_reason =
"This totem parser can only parse version 2 configurations.";
2114 if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
2121 if (strcmp (totem_config->
link_mode,
"active") &&
2122 strcmp (totem_config->
link_mode,
"rr") &&
2123 strcmp (totem_config->
link_mode,
"passive")) {
2124 snprintf (local_error_reason,
sizeof(local_error_reason),
2125 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->
link_mode);
2134 if (interface_max < num_configured) {
2135 snprintf (parse_error,
sizeof(parse_error),
2136 "%d is too many configured interfaces for non-Knet transport.",
2138 error_reason = parse_error;
2147 snprintf (parse_error,
sizeof(parse_error),
2148 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2149 error_reason = parse_error;
2154 if (totem_config->
net_mtu == 0) {
2156 totem_config->
net_mtu = KNET_MAX_PACKET_SIZE;
2166 snprintf (error_string_response,
sizeof(error_string_response),
2167 "parse error in config: %s\n", error_reason);
2168 *error_string = error_string_response;
2173 static int read_keyfile (
2174 const char *key_location,
2175 struct totem_config *totem_config,
2176 const char **error_string)
2181 char error_str[100];
2182 const char *error_ptr;
2184 fd = open (key_location, O_RDONLY);
2186 error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
2187 snprintf (error_string_response,
sizeof(error_string_response),
2188 "Could not open %s: %s\n",
2189 key_location, error_ptr);
2194 saved_errno = errno;
2198 error_ptr = qb_strerror_r (saved_errno, error_str,
sizeof(error_str));
2199 snprintf (error_string_response,
sizeof(error_string_response),
2200 "Could not read %s: %s\n",
2201 key_location, error_ptr);
2206 snprintf (error_string_response,
sizeof(error_string_response),
2207 "Could only read %d bits of minimum %u bits from %s.\n",
2217 *error_string = error_string_response;
2222 struct totem_config *totem_config,
2224 const char **error_string)
2227 char *key_location = NULL;
2247 res = read_keyfile(key_location, totem_config, error_string);
2255 if (key_len >
sizeof(totem_config->
private_key)) {
2256 sprintf(error_string_response,
"key is too long");
2260 sprintf(error_string_response,
"key is too short");
2267 sprintf(error_string_response,
"can't load private key");
2275 res = read_keyfile(
COROSYSCONFDIR "/authkey", totem_config, error_string);
2288 *error_string = error_string_response;
2295 if (totem_get_crypto(totem_config, map, error_string) != 0) {
2304 static void debug_dump_totem_config(
const struct totem_config *totem_config)
2313 if (token_warning_ms < totem_config->token_retransmit_timeout)
2315 "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) "
2316 "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2329 "seqno unchanged const (%d rotations) Maximum network MTU %d",
2332 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2341 static void totem_change_notify(
2343 const char *key_name,
2348 struct totem_config *totem_config = (
struct totem_config *)user_data;
2351 const char *deleted_key = NULL;
2352 const char *error_string;
2361 param = totem_get_param_by_name((
struct totem_config *)user_data, key_name);
2367 if (!param && strcmp(key_name,
"totem.token_coefficient") != 0)
2375 deleted_key = key_name;
2387 debug_dump_totem_config(totem_config);
2399 struct totem_config *totem_config,
2401 const char **error_string)
2403 uint64_t warnings = 0LL;
2405 get_interface_params(totem_config, map, error_string, &warnings, 1);
2406 if (put_nodelist_members_to_config (totem_config, map, 1, error_string)) {
2410 calc_knet_ping_timers(totem_config);
2413 debug_dump_totem_config(totem_config);
2416 (void)find_local_node(map, 0);
2422 struct totem_config *totem_config,
2428 new_interfaces = malloc (
sizeof (
struct totem_interface) * INTERFACE_MAX);
2429 assert(new_interfaces != NULL);
2433 configure_totem_links(totem_config, map);
2436 res = compute_and_set_totempg_interfaces(totem_config->
orig_interfaces, new_interfaces);
2441 free(new_interfaces);
2451 static void add_totem_config_notification(
struct totem_config *totem_config)
2457 totem_change_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)
char knet_compression_model[CONFIG_STRING_LEN_MAX]
#define BLOCK_UNLISTED_IPS
cs_error_t icmap_get_uint8_r(const icmap_map_t map, const char *key_name, uint8_t *u8)
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
cs_error_t icmap_set_int32_r(const icmap_map_t map, const char *key_name, int32_t value)
char crypto_hash_type[CONFIG_STRING_LEN_MAX]
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)
struct totem_ip_address local_ip
icmap_map_t icmap_get_global_map(void)
Return global icmap.
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
cs_error_t icmap_get_int32_r(const icmap_map_t map, const char *key_name, int32_t *i32)
unsigned int send_join_timeout
int totemconfig_commit_new_params(struct totem_config *totem_config, icmap_map_t map)
cs_error_t icmap_set_string_r(const icmap_map_t map, const char *key_name, const char *value)
#define ICMAP_TRACK_DELETE
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
unsigned int block_unlisted_ips
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
#define ICMAP_TRACK_MODIFY
unsigned int token_retransmits_before_loss_const
#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
cs_error_t icmap_set_uint32_r(const icmap_map_t map, const char *key_name, uint32_t value)
#define CANCEL_TOKEN_HOLD_ON_RETRANSMIT
cs_error_t icmap_get_string_r(const icmap_map_t map, const char *key_name, char **str)
int totem_volatile_config_validate(struct totem_config *totem_config, icmap_map_t temp_map, const char **error_string)
struct totem_ip_address mcast_addr
#define LOGSYS_LEVEL_ERROR
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
#define LOGSYS_LEVEL_DEBUG
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
unsigned int fail_to_recv_const
cs_error_t icmap_get_uint32_r(const icmap_map_t map, const char *key_name, uint32_t *u32)
#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
cs_error_t icmap_get_uint16_r(const icmap_map_t map, const char *key_name, uint16_t *u16)
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
#define swab32(x)
The swab32 macro.
#define MAX_NETWORK_DELAY
void totem_volatile_config_read(struct totem_config *totem_config, icmap_map_t temp_map, const char *deleted_key)
unsigned int token_timeout
char crypto_cipher_type[CONFIG_STRING_LEN_MAX]
unsigned int consensus_timeout
#define PROCESSOR_COUNT_MAX
unsigned int token_warning
int totempg_reconfigure(void)
char crypto_model[CONFIG_STRING_LEN_MAX]
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
unsigned int broadcast_use
cs_error_t icmap_get_r(const icmap_map_t map, const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Same as icmap_get but it's reentrant and operates on given icmap_map.
int totemconfig_configure_new_params(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
int totem_reread_crypto_config(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
#define KNET_PING_PRECISION
struct totem_interface * orig_interfaces
unsigned int cancel_token_hold_on_retransmit
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_SET
#define KNET_PMTUD_INTERVAL
unsigned int max_messages
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.
int totem_config_keyread(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
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_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
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 MINIMUM_TIMEOUT_HOLD
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", ...
#define CONFIG_STRING_LEN_MAX
int totempg_member_add(const struct totem_ip_address *member, int ring_no)