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 MINIMUM_TIMEOUT_HOLD (int)(MINIMUM_TIMEOUT * 0.8 - (1000/HZ)) 78 #define MAX_NETWORK_DELAY 50 79 #define WINDOW_SIZE 50 80 #define MAX_MESSAGES 17 81 #define MISS_COUNT_CONST 5 82 #define BLOCK_UNLISTED_IPS 1 85 #define KNET_PING_INTERVAL 1000 86 #define KNET_PING_TIMEOUT 2000 87 #define KNET_PING_PRECISION 2048 88 #define KNET_PONG_COUNT 2 89 #define KNET_PMTUD_INTERVAL 30 90 #define KNET_DEFAULT_TRANSPORT KNET_TRANSPORT_UDP 92 #define DEFAULT_PORT 5405 94 static char error_string_response[768];
100 if (strcmp(param_name,
"totem.token") == 0)
102 if (strcmp(param_name,
"totem.token_warning") == 0)
104 if (strcmp(param_name,
"totem.token_retransmit") == 0)
106 if (strcmp(param_name,
"totem.hold") == 0)
108 if (strcmp(param_name,
"totem.token_retransmits_before_loss_const") == 0)
110 if (strcmp(param_name,
"totem.join") == 0)
112 if (strcmp(param_name,
"totem.send_join") == 0)
114 if (strcmp(param_name,
"totem.consensus") == 0)
116 if (strcmp(param_name,
"totem.merge") == 0)
118 if (strcmp(param_name,
"totem.downcheck") == 0)
120 if (strcmp(param_name,
"totem.fail_recv_const") == 0)
122 if (strcmp(param_name,
"totem.seqno_unchanged_const") == 0)
124 if (strcmp(param_name,
"totem.heartbeat_failures_allowed") == 0)
126 if (strcmp(param_name,
"totem.max_network_delay") == 0)
128 if (strcmp(param_name,
"totem.window_size") == 0)
130 if (strcmp(param_name,
"totem.max_messages") == 0)
132 if (strcmp(param_name,
"totem.miss_count_const") == 0)
134 if (strcmp(param_name,
"totem.knet_pmtud_interval") == 0)
136 if (strcmp(param_name,
"totem.knet_compression_threshold") == 0)
138 if (strcmp(param_name,
"totem.knet_compression_level") == 0)
140 if (strcmp(param_name,
"totem.knet_compression_model") == 0)
142 if (strcmp(param_name,
"totem.block_unlisted_ips") == 0)
152 static void totem_volatile_config_set_uint32_value (
struct totem_config *totem_config,
153 const char *key_name,
const char *deleted_key,
unsigned int default_value,
154 int allow_zero_value)
159 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
160 (!allow_zero_value && *(uint32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
161 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
174 strcpy(runtime_key_name,
"runtime.config.");
175 strcat(runtime_key_name, key_name);
177 icmap_set_uint32(runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
180 static void totem_volatile_config_set_int32_value (
struct totem_config *totem_config,
181 const char *key_name,
const char *deleted_key,
int default_value,
182 int allow_zero_value)
187 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
188 (!allow_zero_value && *(int32_t *)totem_get_param_by_name(totem_config, key_name) == 0)) {
189 *(int32_t *)totem_get_param_by_name(totem_config, key_name) = default_value;
202 strcpy(runtime_key_name,
"runtime.config.");
203 strcat(runtime_key_name, key_name);
205 icmap_set_int32(runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
208 static void totem_volatile_config_set_string_value (
struct totem_config *totem_config,
209 const char *key_name,
const char *deleted_key,
const char *default_value)
213 void *old_config_ptr;
215 config_value = totem_get_param_by_name(totem_config, key_name);
216 old_config_ptr = *config_value;
218 (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
221 *config_value = strdup(default_value);
223 free(old_config_ptr);
235 strcpy(runtime_key_name,
"runtime.config.");
236 strcat(runtime_key_name, key_name);
248 static void totem_volatile_config_set_boolean_value (
struct totem_config *totem_config,
249 const char *key_name,
const char *deleted_key,
unsigned int default_value)
258 if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
265 if (strcmp(str,
"yes") == 0) {
267 }
else if (strcmp(str,
"no") == 0) {
283 strcpy(runtime_key_name,
"runtime.config.");
284 strcat(runtime_key_name, key_name);
286 *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = val;
296 static void totem_volatile_config_read (
struct totem_config *totem_config,
const char *deleted_key)
300 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_retransmits_before_loss_const", deleted_key,
303 totem_volatile_config_set_uint32_value(totem_config,
"totem.token", deleted_key,
TOKEN_TIMEOUT, 0);
305 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_warning", deleted_key,
TOKEN_WARNING, 1);
318 totem_volatile_config_set_uint32_value(totem_config,
"totem.max_network_delay", deleted_key,
MAX_NETWORK_DELAY, 0);
320 totem_volatile_config_set_uint32_value(totem_config,
"totem.window_size", deleted_key,
WINDOW_SIZE, 0);
322 totem_volatile_config_set_uint32_value(totem_config,
"totem.max_messages", deleted_key,
MAX_MESSAGES, 0);
324 totem_volatile_config_set_uint32_value(totem_config,
"totem.miss_count_const", deleted_key,
MISS_COUNT_CONST, 0);
325 totem_volatile_config_set_uint32_value(totem_config,
"totem.knet_pmtud_interval", deleted_key,
KNET_PMTUD_INTERVAL, 0);
327 totem_volatile_config_set_uint32_value(totem_config,
"totem.token_retransmit", deleted_key,
330 totem_volatile_config_set_uint32_value(totem_config,
"totem.hold", deleted_key,
333 totem_volatile_config_set_uint32_value(totem_config,
"totem.join", deleted_key,
JOIN_TIMEOUT, 0);
335 totem_volatile_config_set_uint32_value(totem_config,
"totem.consensus", deleted_key,
338 totem_volatile_config_set_uint32_value(totem_config,
"totem.merge", deleted_key,
MERGE_TIMEOUT, 0);
340 totem_volatile_config_set_uint32_value(totem_config,
"totem.downcheck", deleted_key,
DOWNCHECK_TIMEOUT, 0);
342 totem_volatile_config_set_uint32_value(totem_config,
"totem.fail_recv_const", deleted_key,
FAIL_TO_RECV_CONST, 0);
344 totem_volatile_config_set_uint32_value(totem_config,
"totem.seqno_unchanged_const", deleted_key,
347 totem_volatile_config_set_uint32_value(totem_config,
"totem.send_join", deleted_key, 0, 1);
349 totem_volatile_config_set_uint32_value(totem_config,
"totem.heartbeat_failures_allowed", deleted_key, 0, 1);
351 totem_volatile_config_set_uint32_value(totem_config,
"totem.knet_compression_threshold", deleted_key, 0, 1);
353 totem_volatile_config_set_int32_value(totem_config,
"totem.knet_compression_level", deleted_key, 0, 1);
355 totem_volatile_config_set_string_value(totem_config,
"totem.knet_compression_model", deleted_key,
"none");
357 totem_volatile_config_set_boolean_value(totem_config,
"totem.block_unlisted_ips", deleted_key,
361 static int totem_volatile_config_validate (
362 struct totem_config *totem_config,
363 const char **error_string)
365 static char local_error_reason[512];
366 const char *error_reason = local_error_reason;
369 int i, num_configured, members;
370 uint32_t tmp_config_value;
373 snprintf (local_error_reason,
sizeof(local_error_reason),
374 "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
380 snprintf (local_error_reason,
sizeof(local_error_reason),
381 "The token timeout parameter (%d ms) may not be less than (%d ms).",
387 snprintf (local_error_reason,
sizeof(local_error_reason),
388 "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
395 snprintf (local_error_reason,
sizeof(local_error_reason),
396 "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
400 snprintf (local_error_reason,
sizeof(local_error_reason),
401 "Not appropriate token or token_retransmits_before_loss_const value set");
407 snprintf (local_error_reason,
sizeof(local_error_reason),
408 "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
414 snprintf (local_error_reason,
sizeof(local_error_reason),
415 "The join timeout parameter (%d ms) may not be less than (%d ms).",
421 snprintf (local_error_reason,
sizeof(local_error_reason),
422 "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
428 snprintf (local_error_reason,
sizeof(local_error_reason),
429 "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
435 snprintf (local_error_reason,
sizeof(local_error_reason),
436 "The merge timeout parameter (%d ms) may not be less than (%d ms).",
442 snprintf (local_error_reason,
sizeof(local_error_reason),
443 "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
453 if (num_configured == 0) {
460 if (num_configured > 1) {
464 assert(members != -1);
465 for (i=0; i < members; i++) {
466 snprintf(name_key,
sizeof(name_key),
"nodelist.node.%d.name", i);
469 snprintf (local_error_reason,
sizeof(local_error_reason),
470 "for a multi-link configuration, all nodes must have a 'name' attribute");
482 snprintf (local_error_reason,
sizeof(local_error_reason),
483 "Not all nodes have the same number of links");
495 snprintf (error_string_response,
sizeof(error_string_response),
496 "parse error in config: %s\n", error_reason);
497 *error_string = error_string_response;
502 static int totem_get_crypto(
struct totem_config *totem_config,
const char **error_string)
505 const char *tmp_cipher;
506 const char *tmp_hash;
507 const char *tmp_model;
514 if (strcmp(str,
"nss") == 0) {
517 if (strcmp(str,
"openssl") == 0) {
518 tmp_model =
"openssl";
526 if (strcmp(str,
"on") == 0) {
527 tmp_cipher =
"aes256";
534 if (strcmp(str,
"none") == 0) {
537 if (strcmp(str,
"aes256") == 0) {
538 tmp_cipher =
"aes256";
540 if (strcmp(str,
"aes192") == 0) {
541 tmp_cipher =
"aes192";
543 if (strcmp(str,
"aes128") == 0) {
544 tmp_cipher =
"aes128";
550 if (strcmp(str,
"none") == 0) {
553 if (strcmp(str,
"md5") == 0) {
556 if (strcmp(str,
"sha1") == 0) {
559 if (strcmp(str,
"sha256") == 0) {
562 if (strcmp(str,
"sha384") == 0) {
565 if (strcmp(str,
"sha512") == 0) {
571 if ((strcmp(tmp_cipher,
"none") != 0) &&
572 (strcmp(tmp_hash,
"none") == 0)) {
573 *error_string =
"crypto_cipher requires crypto_hash with value other than none";
577 if (strcmp(tmp_model,
"none") == 0) {
578 *error_string =
"crypto_model should be 'nss' or 'openssl'";
593 static int nodelist_byname(
const char *find_name,
int strip_domain)
596 const char *iter_key;
599 unsigned int node_pos;
601 unsigned int namelen;
605 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
610 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
616 namelen = strlen(name);
620 dot = strchr(name,
'.');
622 namelen = name - dot - 1;
625 if (strncmp(find_name, name, namelen) == 0 &&
626 strlen(find_name) == strlen(name)) {
636 static int ipaddr_equal(
const struct sockaddr *addr1,
const struct sockaddr *addr2)
639 const void *addr1p, *addr2p;
641 if (addr1->sa_family != addr2->sa_family)
644 switch (addr1->sa_family) {
646 addrlen =
sizeof(
struct in_addr);
647 addr1p = &((
struct sockaddr_in *)addr1)->sin_addr;
648 addr2p = &((
struct sockaddr_in *)addr2)->sin_addr;
651 addrlen =
sizeof(
struct in6_addr);
652 addr1p = &((
struct sockaddr_in6 *)addr1)->sin6_addr;
653 addr2p = &((
struct sockaddr_in6 *)addr2)->sin6_addr;
659 return (memcmp(addr1p, addr2p, addrlen) == 0);
666 static int find_local_node(
int use_cache)
668 char nodename2[PATH_MAX];
671 const char *iter_key;
672 unsigned int cached_pos;
675 struct ifaddrs *ifa, *ifa_list;
680 struct utsname utsname;
689 res = uname(&utsname);
693 node = utsname.nodename;
696 node_pos = nodelist_byname(node, 0);
705 strcpy(nodename2, node);
706 dot = strrchr(nodename2,
'.');
710 node_pos = nodelist_byname(nodename2, 0);
715 dot = strrchr(nodename2,
'.');
718 node_pos = nodelist_byname(nodename2, 1);
728 if (getifaddrs(&ifa_list))
731 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
735 strcpy(nodename2, node);
740 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
744 if (sa->sa_family == AF_INET) {
745 salen =
sizeof(
struct sockaddr_in);
747 if (sa->sa_family == AF_INET6) {
748 salen =
sizeof(
struct sockaddr_in6);
751 if (getnameinfo(sa, salen,
752 nodename2,
sizeof(nodename2),
755 node_pos = nodelist_byname(nodename2, 0);
762 dot = strchr(nodename2,
'.');
766 node_pos = nodelist_byname(nodename2, 0);
775 if (getnameinfo(sa,
sizeof(*sa),
776 nodename2,
sizeof(nodename2),
777 NULL, 0, NI_NUMERICHOST))
780 node_pos = nodelist_byname(nodename2, 0);
789 freeifaddrs(ifa_list);
808 char *dbnodename = NULL;
809 struct addrinfo hints;
810 struct addrinfo *result = NULL, *rp = NULL;
812 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
819 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
826 memset(&hints, 0,
sizeof(
struct addrinfo));
827 hints.ai_family = AF_UNSPEC;
828 hints.ai_socktype = SOCK_DGRAM;
830 hints.ai_protocol = IPPROTO_UDP;
832 if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
836 for (rp = result; rp != NULL; rp = rp->ai_next) {
837 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
839 ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
840 freeaddrinfo(result);
847 freeaddrinfo(result);
851 freeifaddrs(ifa_list);
873 if (strcmp(str,
"ipv4") == 0) {
876 if (strcmp(str,
"ipv6") == 0) {
879 if (strcmp(str,
"ipv6-4") == 0) {
882 if (strcmp(str,
"ipv4-6") == 0) {
891 static uint16_t generate_cluster_id (
const char *cluster_name)
896 for (i = 0; i < strlen(cluster_name); i++) {
898 value += cluster_name[i];
901 return (value & 0xFFFF);
904 static int get_cluster_mcast_addr (
905 const char *cluster_name,
906 unsigned int linknumber,
911 char addr[INET6_ADDRSTRLEN + 1];
914 if (cluster_name == NULL) {
918 clusterid = generate_cluster_id(cluster_name) + linknumber;
919 memset (res, 0,
sizeof(*res));
921 switch (ip_version) {
924 snprintf(addr,
sizeof(addr),
"239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
928 snprintf(addr,
sizeof(addr),
"ff15::%x", clusterid);
942 static unsigned int generate_nodeid(
943 struct totem_config *totem_config,
954 memcpy (&nodeid, &totemip.addr, sizeof (
unsigned int));
956 #if __BYTE_ORDER == __LITTLE_ENDIAN 961 nodeid &= 0x7FFFFFFF;
966 static int check_for_duplicate_nodeids(
967 struct totem_config *totem_config,
968 const char **error_string)
972 const char *iter_key;
976 char *ring0_addr=NULL;
977 char *ring0_addr1=NULL;
978 unsigned int node_pos;
979 unsigned int node_pos1;
980 unsigned int last_node_pos = -1;
982 unsigned int nodeid1;
987 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
997 if (last_node_pos == node_pos) {
1000 last_node_pos = node_pos;
1014 nodeid = generate_nodeid(totem_config, ring0_addr);
1023 while (((iter_key =
icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
1024 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos1, tmp_key);
1025 if ((res != 2) || (node_pos1 >= node_pos)) {
1029 if (strcmp(tmp_key,
"nodeid") != 0) {
1040 nodeid1 = generate_nodeid(totem_config, ring0_addr1);
1041 if (nodeid1 == -1) {
1046 if (nodeid == nodeid1) {
1048 snprintf (error_string_response,
sizeof(error_string_response),
1049 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
1050 autogenerated?
"(autogenerated from ":
"",
1051 autogenerated?ring0_addr:
"",
1052 autogenerated?
")":
"");
1054 *error_string = error_string_response;
1070 static void calc_knet_ping_timers(
struct totem_config *totem_config)
1075 for (interface = 0;
interface < INTERFACE_MAX; interface++) {
1085 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1086 "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1093 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1094 "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1109 int ring_no, set1_pos, set2_pos;
1112 memset(&empty_ip_address, 0,
sizeof(empty_ip_address));
1115 if (!set1[ring_no].configured && !set2[ring_no].configured) {
1119 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1120 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1125 if (memcmp(&set1[ring_no].member_list[set1_pos],
1126 &set2[ring_no].member_list[set2_pos],
1128 memset(&set1[ring_no].member_list[set1_pos], 0,
1130 memset(&set2[ring_no].member_list[set2_pos], 0,
1138 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1143 if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1145 "removing dynamic member %s for ring %u",
1152 if (!set2[ring_no].configured) {
1155 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1160 if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1162 "adding dynamic member %s for ring %u",
1175 static void reconfigure_links(
struct totem_config *totem_config)
1182 int local_node_pos = find_local_node(0);
1200 local_ip.nodeid = totem_config->
node_id;
1222 static void check_things_have_not_changed(
struct totem_config *totem_config)
1226 char addr_buf[INET6_ADDRSTRLEN];
1235 "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1247 strncpy(addr_buf, ip_str,
sizeof(addr_buf));
1248 addr_buf[
sizeof(addr_buf) - 1] =
'\0';
1250 "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1260 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");
1265 static int put_nodelist_members_to_config(
struct totem_config *totem_config,
int reload,
const char **error_string)
1268 const char *iter_key, *iter_key2;
1270 unsigned int node_pos;
1273 char *node_addr_str;
1275 unsigned int linknumber = 0;
1277 int last_node_pos = -1;
1286 new_interfaces = malloc (
sizeof (
struct totem_interface) * INTERFACE_MAX);
1287 assert(new_interfaces != NULL);
1300 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1305 if (node_pos == last_node_pos) {
1308 last_node_pos = node_pos;
1321 res = sscanf(iter_key2,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1322 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1336 nodeid = generate_nodeid(totem_config, str);
1338 sprintf(error_string_response,
1339 "An IPV6 network requires that a node ID be specified " 1340 "for address '%s'.", node_addr_str);
1341 *error_string = error_string_response;
1361 sprintf(error_string_response,
"failed to parse node address '%s'\n", node_addr_str);
1362 *error_string = error_string_response;
1367 free(node_addr_str);
1373 free(node_addr_str);
1383 reconfigure_links(totem_config);
1387 check_things_have_not_changed(totem_config);
1389 compute_interfaces_diff(totem_config->
orig_interfaces, new_interfaces);
1391 free(new_interfaces);
1396 static void config_convert_nodelist_to_interface(
struct totem_config *totem_config)
1402 char *node_addr_str;
1403 unsigned int linknumber = 0;
1405 const char *iter_key;
1407 node_pos = find_local_node(1);
1408 if (node_pos > -1) {
1415 res = sscanf(iter_key,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1416 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1426 free(node_addr_str);
1432 static int get_interface_params(
struct totem_config *totem_config,
1433 const char **error_string, uint64_t *warnings,
1437 unsigned int linknumber = 0;
1438 int member_count = 0;
1441 const char *iter_key;
1442 const char *member_iter_key;
1448 char *cluster_name = NULL;
1467 cluster_name = NULL;
1472 res = sscanf(iter_key,
"totem.interface.%[^.].%s", linknumber_key, tmp_key);
1482 linknumber = atoi(linknumber_key);
1484 if (linknumber >= INTERFACE_MAX) {
1485 snprintf (error_string_response,
sizeof(error_string_response),
1486 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1487 linknumber, INTERFACE_MAX - 1);
1489 *error_string = error_string_response;
1506 sprintf(error_string_response,
"failed to parse bindnet address '%s'\n", str);
1507 *error_string = error_string_response;
1526 sprintf(error_string_response,
"failed to parse mcast address '%s'\n", str);
1527 *error_string = error_string_response;
1549 (void)get_cluster_mcast_addr (cluster_name,
1557 if (strcmp (str,
"yes") == 0) {
1593 if (strcmp(str,
"sctp") == 0) {
1596 else if (strcmp(str,
"udp") == 0) {
1600 *error_string =
"Unrecognised knet_transport. expected 'udp' or 'sctp'";
1641 while ((member_iter_key =
icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1642 if (member_count == 0) {
1656 sprintf(error_string_response,
"failed to parse node address '%s'\n", str);
1657 *error_string = error_string_response;
1682 struct totem_config *totem_config,
1683 const char **error_string,
1687 char *str, *ring0_addr_str;
1696 memset (totem_config, 0,
sizeof (
struct totem_config));
1699 *error_string =
"Out of memory trying to allocate ethernet interface storage area";
1705 if (strcmp (str,
"udpu") == 0) {
1709 if (strcmp (str,
"udp") == 0) {
1713 if (strcmp (str,
"knet") == 0) {
1723 strcpy (totem_config->
link_mode,
"passive");
1727 if (totem_get_crypto(totem_config, error_string) != 0) {
1733 *error_string =
"totem.link_mode is too long";
1746 if (strcmp (str,
"yes") == 0) {
1756 totem_config->
ip_version = totem_config_get_ip_version(totem_config);
1762 config_convert_nodelist_to_interface(totem_config);
1771 config_convert_nodelist_to_interface(totem_config);
1773 free(ring0_addr_str);
1785 res = get_interface_params(totem_config, error_string, warnings, 0);
1832 local_node_pos = find_local_node(1);
1833 if (local_node_pos != -1) {
1837 nodeid_set = (totem_config->
node_id != 0);
1842 *error_string =
"Knet requires an explicit nodeid for the local node";
1852 totem_config->
node_id = generate_nodeid(totem_config, str);
1853 if (totem_config->
node_id == -1) {
1854 *error_string =
"An IPV6 network requires that a node ID be specified";
1869 if (put_nodelist_members_to_config(totem_config, 0, error_string)) {
1877 totem_volatile_config_read(totem_config, NULL);
1879 calc_knet_ping_timers(totem_config);
1883 add_totem_config_notification(totem_config);
1890 struct totem_config *totem_config,
1891 const char **error_string)
1893 static char local_error_reason[512];
1894 char parse_error[512];
1895 static char addr_str_buf[INET6_ADDRSTRLEN];
1896 const char *error_reason = local_error_reason;
1899 int num_configured = 0;
1907 if (num_configured == 0) {
1908 error_reason =
"No interfaces defined";
1914 error_reason =
"No valid name found for local host";
1934 error_reason =
"No multicast address specified";
1939 error_reason =
"No multicast port specified";
1944 error_reason =
"Invalid TTL (should be 0..255)";
1949 error_reason =
"Can only set ttl on multicast transport types";
1953 error_reason =
"Invalid link priority (should be 0..255)";
1958 error_reason =
"Can only set link priority on knet transport type";
1965 error_reason =
"An IPV6 network requires that a node ID be specified.";
1971 error_reason =
"Multicast address family does not match bind address family";
1976 error_reason =
"mcastaddr is not a correct multicast address.";
1985 memcpy(addr_str_buf,
1987 sizeof(addr_str_buf));
1989 snprintf (local_error_reason,
sizeof(local_error_reason),
1990 "Nodes for link %d have different IP families " 1991 "(compared %s with %s)", i,
2000 if (totem_config->
version != 2) {
2001 error_reason =
"This totem parser can only parse version 2 configurations.";
2005 if (totem_volatile_config_validate(totem_config, error_string) == -1) {
2009 if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
2016 if (strcmp (totem_config->
link_mode,
"active") &&
2017 strcmp (totem_config->
link_mode,
"rr") &&
2018 strcmp (totem_config->
link_mode,
"passive")) {
2019 snprintf (local_error_reason,
sizeof(local_error_reason),
2020 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->
link_mode);
2029 if (interface_max < num_configured) {
2030 snprintf (parse_error,
sizeof(parse_error),
2031 "%d is too many configured interfaces for non-Knet transport.",
2033 error_reason = parse_error;
2042 snprintf (parse_error,
sizeof(parse_error),
2043 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2044 error_reason = parse_error;
2049 if (totem_config->
net_mtu == 0) {
2051 totem_config->
net_mtu = KNET_MAX_PACKET_SIZE;
2061 snprintf (error_string_response,
sizeof(error_string_response),
2062 "parse error in config: %s\n", error_reason);
2063 *error_string = error_string_response;
2068 static int read_keyfile (
2069 const char *key_location,
2070 struct totem_config *totem_config,
2071 const char **error_string)
2076 char error_str[100];
2077 const char *error_ptr;
2079 fd = open (key_location, O_RDONLY);
2081 error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
2082 snprintf (error_string_response,
sizeof(error_string_response),
2083 "Could not open %s: %s\n",
2084 key_location, error_ptr);
2089 saved_errno = errno;
2093 error_ptr = qb_strerror_r (saved_errno, error_str,
sizeof(error_str));
2094 snprintf (error_string_response,
sizeof(error_string_response),
2095 "Could not read %s: %s\n",
2096 key_location, error_ptr);
2101 snprintf (error_string_response,
sizeof(error_string_response),
2102 "Could only read %d bits of minimum %u bits from %s.\n",
2112 *error_string = error_string_response;
2117 struct totem_config *totem_config,
2118 const char **error_string)
2121 char *key_location = NULL;
2135 res = read_keyfile(key_location, totem_config, error_string);
2143 if (key_len >
sizeof(totem_config->
private_key)) {
2144 sprintf(error_string_response,
"key is too long");
2148 sprintf(error_string_response,
"key is too short");
2155 sprintf(error_string_response,
"can't load private key");
2163 res = read_keyfile(
COROSYSCONFDIR "/authkey", totem_config, error_string);
2171 *error_string = error_string_response;
2176 static void debug_dump_totem_config(
const struct totem_config *totem_config)
2185 if (token_warning_ms < totem_config->token_retransmit_timeout)
2187 "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) " 2188 "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2201 "seqno unchanged const (%d rotations) Maximum network MTU %d",
2204 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2212 static void totem_change_notify(
2214 const char *key_name,
2219 struct totem_config *totem_config = (
struct totem_config *)user_data;
2222 const char *deleted_key = NULL;
2223 const char *error_string;
2232 param = totem_get_param_by_name((
struct totem_config *)user_data, key_name);
2238 if (!param && strcmp(key_name,
"totem.token_coefficient") != 0)
2246 deleted_key = key_name;
2256 totem_volatile_config_read (totem_config, deleted_key);
2258 debug_dump_totem_config(totem_config);
2259 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2268 static void totem_reload_notify(
2270 const char *key_name,
2275 struct totem_config *totem_config = (
struct totem_config *)user_data;
2276 const char *error_string;
2277 uint64_t warnings = 0;
2280 if (*(uint8_t *)new_val.
data == 0) {
2286 get_interface_params(totem_config, &error_string, &warnings, 1);
2287 if (put_nodelist_members_to_config (totem_config, 1, &error_string)) {
2290 totem_volatile_config_read (totem_config, NULL);
2292 calc_knet_ping_timers(totem_config);
2295 debug_dump_totem_config(totem_config);
2296 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2305 (void)find_local_node(0);
2318 static void add_totem_config_notification(
struct totem_config *totem_config)
2324 totem_change_notify,
2330 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)
#define BLOCK_UNLISTED_IPS
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.
unsigned int block_unlisted_ips
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
#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", ...
int totempg_member_add(const struct totem_ip_address *member, int ring_no)