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");
480 snprintf (local_error_reason,
sizeof(local_error_reason),
481 "Not all nodes have the same number of links");
493 snprintf (error_string_response,
sizeof(error_string_response),
494 "parse error in config: %s\n", error_reason);
495 *error_string = error_string_response;
500 static int totem_get_crypto(
struct totem_config *totem_config,
const char **error_string)
503 const char *tmp_cipher;
504 const char *tmp_hash;
505 const char *tmp_model;
512 if (strcmp(str,
"nss") == 0) {
515 if (strcmp(str,
"openssl") == 0) {
516 tmp_model =
"openssl";
524 if (strcmp(str,
"on") == 0) {
525 tmp_cipher =
"aes256";
532 if (strcmp(str,
"none") == 0) {
535 if (strcmp(str,
"aes256") == 0) {
536 tmp_cipher =
"aes256";
538 if (strcmp(str,
"aes192") == 0) {
539 tmp_cipher =
"aes192";
541 if (strcmp(str,
"aes128") == 0) {
542 tmp_cipher =
"aes128";
548 if (strcmp(str,
"none") == 0) {
551 if (strcmp(str,
"md5") == 0) {
554 if (strcmp(str,
"sha1") == 0) {
557 if (strcmp(str,
"sha256") == 0) {
560 if (strcmp(str,
"sha384") == 0) {
563 if (strcmp(str,
"sha512") == 0) {
569 if ((strcmp(tmp_cipher,
"none") != 0) &&
570 (strcmp(tmp_hash,
"none") == 0)) {
571 *error_string =
"crypto_cipher requires crypto_hash with value other than none";
575 if (strcmp(tmp_model,
"none") == 0) {
576 *error_string =
"crypto_model should be 'nss' or 'openssl'";
591 static int nodelist_byname(
const char *find_name,
int strip_domain)
594 const char *iter_key;
597 unsigned int node_pos;
599 unsigned int namelen;
603 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
608 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
614 namelen = strlen(name);
618 dot = strchr(name,
'.');
620 namelen = name - dot - 1;
623 if (strncmp(find_name, name, namelen) == 0 &&
624 strlen(find_name) == strlen(name)) {
634 static int ipaddr_equal(
const struct sockaddr *addr1,
const struct sockaddr *addr2)
637 const void *addr1p, *addr2p;
639 if (addr1->sa_family != addr2->sa_family)
642 switch (addr1->sa_family) {
644 addrlen =
sizeof(
struct in_addr);
645 addr1p = &((
struct sockaddr_in *)addr1)->sin_addr;
646 addr2p = &((
struct sockaddr_in *)addr2)->sin_addr;
649 addrlen =
sizeof(
struct in6_addr);
650 addr1p = &((
struct sockaddr_in6 *)addr1)->sin6_addr;
651 addr2p = &((
struct sockaddr_in6 *)addr2)->sin6_addr;
657 return (memcmp(addr1p, addr2p, addrlen) == 0);
664 static int find_local_node(
int use_cache)
666 char nodename2[PATH_MAX];
669 const char *iter_key;
670 unsigned int cached_pos;
673 struct ifaddrs *ifa, *ifa_list;
678 struct utsname utsname;
687 res = uname(&utsname);
691 node = utsname.nodename;
694 node_pos = nodelist_byname(node, 0);
703 strcpy(nodename2, node);
704 dot = strrchr(nodename2,
'.');
708 node_pos = nodelist_byname(nodename2, 0);
713 dot = strrchr(nodename2,
'.');
716 node_pos = nodelist_byname(nodename2, 1);
726 if (getifaddrs(&ifa_list))
729 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
733 strcpy(nodename2, node);
738 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
742 if (sa->sa_family == AF_INET) {
743 salen =
sizeof(
struct sockaddr_in);
745 if (sa->sa_family == AF_INET6) {
746 salen =
sizeof(
struct sockaddr_in6);
749 if (getnameinfo(sa, salen,
750 nodename2,
sizeof(nodename2),
753 node_pos = nodelist_byname(nodename2, 0);
760 dot = strchr(nodename2,
'.');
764 node_pos = nodelist_byname(nodename2, 0);
773 if (getnameinfo(sa,
sizeof(*sa),
774 nodename2,
sizeof(nodename2),
775 NULL, 0, NI_NUMERICHOST))
778 node_pos = nodelist_byname(nodename2, 0);
787 freeifaddrs(ifa_list);
806 char *dbnodename = NULL;
807 struct addrinfo hints;
808 struct addrinfo *result = NULL, *rp = NULL;
810 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, name_str);
817 if (strcmp(name_str,
"name") && strcmp(name_str,
"ring0_addr")) {
824 memset(&hints, 0,
sizeof(
struct addrinfo));
825 hints.ai_family = AF_UNSPEC;
826 hints.ai_socktype = SOCK_DGRAM;
828 hints.ai_protocol = IPPROTO_UDP;
830 if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
834 for (rp = result; rp != NULL; rp = rp->ai_next) {
835 for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
837 ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
838 freeaddrinfo(result);
845 freeaddrinfo(result);
849 freeifaddrs(ifa_list);
871 if (strcmp(str,
"ipv4") == 0) {
874 if (strcmp(str,
"ipv6") == 0) {
877 if (strcmp(str,
"ipv6-4") == 0) {
880 if (strcmp(str,
"ipv4-6") == 0) {
889 static uint16_t generate_cluster_id (
const char *cluster_name)
894 for (i = 0; i < strlen(cluster_name); i++) {
896 value += cluster_name[i];
899 return (value & 0xFFFF);
902 static int get_cluster_mcast_addr (
903 const char *cluster_name,
904 unsigned int linknumber,
909 char addr[INET6_ADDRSTRLEN + 1];
912 if (cluster_name == NULL) {
916 clusterid = generate_cluster_id(cluster_name) + linknumber;
917 memset (res, 0,
sizeof(*res));
919 switch (ip_version) {
922 snprintf(addr,
sizeof(addr),
"239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
926 snprintf(addr,
sizeof(addr),
"ff15::%x", clusterid);
940 static unsigned int generate_nodeid(
941 struct totem_config *totem_config,
952 memcpy (&nodeid, &totemip.addr, sizeof (
unsigned int));
954 #if __BYTE_ORDER == __LITTLE_ENDIAN 959 nodeid &= 0x7FFFFFFF;
964 static int check_for_duplicate_nodeids(
965 struct totem_config *totem_config,
966 const char **error_string)
970 const char *iter_key;
974 char *ring0_addr=NULL;
975 char *ring0_addr1=NULL;
976 unsigned int node_pos;
977 unsigned int node_pos1;
978 unsigned int last_node_pos = -1;
980 unsigned int nodeid1;
985 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
995 if (last_node_pos == node_pos) {
998 last_node_pos = node_pos;
1012 nodeid = generate_nodeid(totem_config, ring0_addr);
1021 while (((iter_key =
icmap_iter_next(subiter, NULL, NULL)) != NULL) && (node_pos1 < node_pos)) {
1022 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos1, tmp_key);
1023 if ((res != 2) || (node_pos1 >= node_pos)) {
1027 if (strcmp(tmp_key,
"nodeid") != 0) {
1038 nodeid1 = generate_nodeid(totem_config, ring0_addr1);
1039 if (nodeid1 == -1) {
1044 if (nodeid == nodeid1) {
1046 snprintf (error_string_response,
sizeof(error_string_response),
1047 "Nodeid %u%s%s%s appears twice in corosync.conf", nodeid,
1048 autogenerated?
"(autogenerated from ":
"",
1049 autogenerated?ring0_addr:
"",
1050 autogenerated?
")":
"");
1052 *error_string = error_string_response;
1068 static void calc_knet_ping_timers(
struct totem_config *totem_config)
1073 for (interface = 0;
interface < INTERFACE_MAX; interface++) {
1083 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1084 "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1091 snprintf(runtime_key_name,
sizeof(runtime_key_name),
1092 "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1107 int ring_no, set1_pos, set2_pos;
1110 memset(&empty_ip_address, 0,
sizeof(empty_ip_address));
1113 if (!set1[ring_no].configured && !set2[ring_no].configured) {
1117 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1118 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1123 if (memcmp(&set1[ring_no].member_list[set1_pos],
1124 &set2[ring_no].member_list[set2_pos],
1126 memset(&set1[ring_no].member_list[set1_pos], 0,
1128 memset(&set2[ring_no].member_list[set2_pos], 0,
1136 for (set1_pos = 0; set1_pos < set1[ring_no].
member_count; set1_pos++) {
1141 if (memcmp(&set1[ring_no].member_list[set1_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1143 "removing dynamic member %s for ring %u",
1150 if (!set2[ring_no].configured) {
1153 for (set2_pos = 0; set2_pos < set2[ring_no].
member_count; set2_pos++) {
1158 if (memcmp(&set2[ring_no].member_list[set2_pos], &empty_ip_address,
sizeof(empty_ip_address)) != 0) {
1160 "adding dynamic member %s for ring %u",
1173 static void reconfigure_links(
struct totem_config *totem_config)
1180 int local_node_pos = find_local_node(0);
1198 local_ip.nodeid = totem_config->
node_id;
1220 static void check_things_have_not_changed(
struct totem_config *totem_config)
1224 char addr_buf[INET6_ADDRSTRLEN];
1233 "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1245 strncpy(addr_buf, ip_str,
sizeof(addr_buf));
1246 addr_buf[
sizeof(addr_buf) - 1] =
'\0';
1248 "new config has different address for link %d (addr changed from %s to %s). Internal value was NOT changed.\n",
1258 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");
1263 static int put_nodelist_members_to_config(
struct totem_config *totem_config,
int reload,
const char **error_string)
1266 const char *iter_key, *iter_key2;
1268 unsigned int node_pos;
1271 char *node_addr_str;
1273 unsigned int linknumber = 0;
1275 int last_node_pos = -1;
1284 new_interfaces = malloc (
sizeof (
struct totem_interface) * INTERFACE_MAX);
1285 assert(new_interfaces != NULL);
1298 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1303 if (node_pos == last_node_pos) {
1306 last_node_pos = node_pos;
1319 res = sscanf(iter_key2,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1320 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1334 nodeid = generate_nodeid(totem_config, str);
1336 sprintf(error_string_response,
1337 "An IPV6 network requires that a node ID be specified " 1338 "for address '%s'.", node_addr_str);
1339 *error_string = error_string_response;
1359 sprintf(error_string_response,
"failed to parse node address '%s'\n", node_addr_str);
1360 *error_string = error_string_response;
1365 free(node_addr_str);
1371 free(node_addr_str);
1381 reconfigure_links(totem_config);
1385 check_things_have_not_changed(totem_config);
1387 compute_interfaces_diff(totem_config->
orig_interfaces, new_interfaces);
1389 free(new_interfaces);
1394 static void config_convert_nodelist_to_interface(
struct totem_config *totem_config)
1400 char *node_addr_str;
1401 unsigned int linknumber = 0;
1403 const char *iter_key;
1405 node_pos = find_local_node(1);
1406 if (node_pos > -1) {
1413 res = sscanf(iter_key,
"nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
1414 if (res != 3 || strcmp(tmp_key2,
"_addr") != 0) {
1424 free(node_addr_str);
1430 static int get_interface_params(
struct totem_config *totem_config,
1431 const char **error_string, uint64_t *warnings,
1435 unsigned int linknumber = 0;
1436 int member_count = 0;
1439 const char *iter_key;
1440 const char *member_iter_key;
1446 char *cluster_name = NULL;
1464 cluster_name = NULL;
1469 res = sscanf(iter_key,
"totem.interface.%[^.].%s", linknumber_key, tmp_key);
1479 linknumber = atoi(linknumber_key);
1481 if (linknumber >= INTERFACE_MAX) {
1484 snprintf (error_string_response,
sizeof(error_string_response),
1485 "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
1486 linknumber, INTERFACE_MAX - 1);
1488 *error_string = error_string_response;
1504 sprintf(error_string_response,
"failed to parse bindnet address '%s'\n", str);
1505 *error_string = error_string_response;
1523 sprintf(error_string_response,
"failed to parse mcast address '%s'\n", str);
1524 *error_string = error_string_response;
1545 (void)get_cluster_mcast_addr (cluster_name,
1553 if (strcmp (str,
"yes") == 0) {
1589 if (strcmp(str,
"sctp") == 0) {
1592 else if (strcmp(str,
"udp") == 0) {
1596 *error_string =
"Unrecognised knet_transport. expected 'udp' or 'sctp'";
1636 while ((member_iter_key =
icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1637 if (member_count == 0) {
1651 sprintf(error_string_response,
"failed to parse node address '%s'\n", str);
1652 *error_string = error_string_response;
1674 struct totem_config *totem_config,
1675 const char **error_string,
1679 char *str, *ring0_addr_str;
1688 memset (totem_config, 0,
sizeof (
struct totem_config));
1691 *error_string =
"Out of memory trying to allocate ethernet interface storage area";
1697 if (strcmp (str,
"udpu") == 0) {
1701 if (strcmp (str,
"udp") == 0) {
1705 if (strcmp (str,
"knet") == 0) {
1715 strcpy (totem_config->
link_mode,
"passive");
1719 if (totem_get_crypto(totem_config, error_string) != 0) {
1725 *error_string =
"totem.link_mode is too long";
1738 if (strcmp (str,
"yes") == 0) {
1748 totem_config->
ip_version = totem_config_get_ip_version(totem_config);
1754 config_convert_nodelist_to_interface(totem_config);
1763 config_convert_nodelist_to_interface(totem_config);
1765 free(ring0_addr_str);
1777 res = get_interface_params(totem_config, error_string, warnings, 0);
1824 local_node_pos = find_local_node(1);
1825 if (local_node_pos != -1) {
1829 nodeid_set = (totem_config->
node_id != 0);
1834 *error_string =
"Knet requires an explicit nodeid for the local node";
1844 totem_config->
node_id = generate_nodeid(totem_config, str);
1845 if (totem_config->
node_id == -1) {
1846 *error_string =
"An IPV6 network requires that a node ID be specified";
1861 if (put_nodelist_members_to_config(totem_config, 0, error_string)) {
1869 totem_volatile_config_read(totem_config, NULL);
1871 calc_knet_ping_timers(totem_config);
1875 add_totem_config_notification(totem_config);
1882 struct totem_config *totem_config,
1883 const char **error_string)
1885 static char local_error_reason[512];
1886 char parse_error[512];
1887 static char addr_str_buf[INET6_ADDRSTRLEN];
1888 const char *error_reason = local_error_reason;
1891 int num_configured = 0;
1899 if (num_configured == 0) {
1900 error_reason =
"No interfaces defined";
1906 error_reason =
"No valid name found for local host";
1926 error_reason =
"No multicast address specified";
1931 error_reason =
"No multicast port specified";
1936 error_reason =
"Invalid TTL (should be 0..255)";
1941 error_reason =
"Can only set ttl on multicast transport types";
1945 error_reason =
"Invalid link priority (should be 0..255)";
1950 error_reason =
"Can only set link priority on knet transport type";
1957 error_reason =
"An IPV6 network requires that a node ID be specified.";
1963 error_reason =
"Multicast address family does not match bind address family";
1968 error_reason =
"mcastaddr is not a correct multicast address.";
1977 memcpy(addr_str_buf,
1979 sizeof(addr_str_buf));
1981 snprintf (local_error_reason,
sizeof(local_error_reason),
1982 "Nodes for link %d have different IP families " 1983 "(compared %s with %s)", i,
1992 if (totem_config->
version != 2) {
1993 error_reason =
"This totem parser can only parse version 2 configurations.";
1997 if (totem_volatile_config_validate(totem_config, error_string) == -1) {
2001 if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
2008 if (strcmp (totem_config->
link_mode,
"active") &&
2009 strcmp (totem_config->
link_mode,
"rr") &&
2010 strcmp (totem_config->
link_mode,
"passive")) {
2011 snprintf (local_error_reason,
sizeof(local_error_reason),
2012 "The Knet link mode \"%s\" specified is invalid. It must be active, passive or rr.\n", totem_config->
link_mode);
2021 if (interface_max < num_configured) {
2022 snprintf (parse_error,
sizeof(parse_error),
2023 "%d is too many configured interfaces for non-Knet transport.",
2025 error_reason = parse_error;
2034 snprintf (parse_error,
sizeof(parse_error),
2035 "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2036 error_reason = parse_error;
2041 if (totem_config->
net_mtu == 0) {
2043 totem_config->
net_mtu = KNET_MAX_PACKET_SIZE;
2053 snprintf (error_string_response,
sizeof(error_string_response),
2054 "parse error in config: %s\n", error_reason);
2055 *error_string = error_string_response;
2060 static int read_keyfile (
2061 const char *key_location,
2062 struct totem_config *totem_config,
2063 const char **error_string)
2068 char error_str[100];
2069 const char *error_ptr;
2071 fd = open (key_location, O_RDONLY);
2073 error_ptr = qb_strerror_r(errno, error_str,
sizeof(error_str));
2074 snprintf (error_string_response,
sizeof(error_string_response),
2075 "Could not open %s: %s\n",
2076 key_location, error_ptr);
2081 saved_errno = errno;
2085 error_ptr = qb_strerror_r (saved_errno, error_str,
sizeof(error_str));
2086 snprintf (error_string_response,
sizeof(error_string_response),
2087 "Could not read %s: %s\n",
2088 key_location, error_ptr);
2093 snprintf (error_string_response,
sizeof(error_string_response),
2094 "Could only read %d bits of minimum %u bits from %s.\n",
2104 *error_string = error_string_response;
2109 struct totem_config *totem_config,
2110 const char **error_string)
2113 char *key_location = NULL;
2127 res = read_keyfile(key_location, totem_config, error_string);
2135 if (key_len >
sizeof(totem_config->
private_key)) {
2136 sprintf(error_string_response,
"key is too long");
2140 sprintf(error_string_response,
"key is too short");
2147 sprintf(error_string_response,
"can't load private key");
2155 res = read_keyfile(
COROSYSCONFDIR "/authkey", totem_config, error_string);
2163 *error_string = error_string_response;
2168 static void debug_dump_totem_config(
const struct totem_config *totem_config)
2177 if (token_warning_ms < totem_config->token_retransmit_timeout)
2179 "The token warning interval (%d ms) is less than the token retransmit timeout (%d ms) " 2180 "which can lead to spurious token warnings. Consider increasing the token_warning parameter.",
2193 "seqno unchanged const (%d rotations) Maximum network MTU %d",
2196 "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2204 static void totem_change_notify(
2206 const char *key_name,
2211 struct totem_config *totem_config = (
struct totem_config *)user_data;
2214 const char *deleted_key = NULL;
2215 const char *error_string;
2224 param = totem_get_param_by_name((
struct totem_config *)user_data, key_name);
2230 if (!param && strcmp(key_name,
"totem.token_coefficient") != 0)
2238 deleted_key = key_name;
2248 totem_volatile_config_read (totem_config, deleted_key);
2250 debug_dump_totem_config(totem_config);
2251 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2260 static void totem_reload_notify(
2262 const char *key_name,
2267 struct totem_config *totem_config = (
struct totem_config *)user_data;
2268 const char *error_string;
2272 if (*(uint8_t *)new_val.
data == 0) {
2278 get_interface_params(totem_config, &error_string, &warnings, 1);
2279 if (put_nodelist_members_to_config (totem_config, 1, &error_string)) {
2282 totem_volatile_config_read (totem_config, NULL);
2284 calc_knet_ping_timers(totem_config);
2287 debug_dump_totem_config(totem_config);
2288 if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2297 (void)find_local_node(0);
2310 static void add_totem_config_notification(
struct totem_config *totem_config)
2316 totem_change_notify,
2322 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)