corosync  2.3.4
totemconfig.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 MontaVista Software, Inc.
3  * Copyright (c) 2006-2013 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Steven Dake (sdake@redhat.com)
8  * Jan Friesse (jfriesse@redhat.com)
9  *
10  * This software licensed under BSD license, the text of which follows:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * - Redistributions of source code must retain the above copyright notice,
16  * this list of conditions and the following disclaimer.
17  * - Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  * - Neither the name of the MontaVista Software, Inc. nor the names of its
21  * contributors may be used to endorse or promote products derived from this
22  * software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #include <config.h>
38 
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <errno.h>
43 #include <unistd.h>
44 #include <sys/socket.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <fcntl.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/param.h>
51 
52 #include <corosync/swab.h>
53 #include <corosync/list.h>
54 #include <qb/qbdefs.h>
55 #include <corosync/totem/totem.h>
56 #include <corosync/config.h>
57 #include <corosync/logsys.h>
58 #include <corosync/icmap.h>
59 
60 #include "util.h"
61 #include "totemconfig.h"
62 
63 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4
64 #define TOKEN_TIMEOUT 1000
65 #define TOKEN_COEFFICIENT 650
66 #define JOIN_TIMEOUT 50
67 #define MERGE_TIMEOUT 200
68 #define DOWNCHECK_TIMEOUT 1000
69 #define FAIL_TO_RECV_CONST 2500
70 #define SEQNO_UNCHANGED_CONST 30
71 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3
72 #define MAX_NETWORK_DELAY 50
73 #define WINDOW_SIZE 50
74 #define MAX_MESSAGES 17
75 #define MISS_COUNT_CONST 5
76 #define RRP_PROBLEM_COUNT_TIMEOUT 2000
77 #define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT 10
78 #define RRP_PROBLEM_COUNT_THRESHOLD_MIN 2
79 #define RRP_AUTORECOVERY_CHECK_TIMEOUT 1000
80 
81 #define DEFAULT_PORT 5405
82 
83 static char error_string_response[512];
84 
85 static void add_totem_config_notification(struct totem_config *totem_config);
86 
87 
88 /* All the volatile parameters are uint32s, luckily */
89 static uint32_t *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
90 {
91  if (strcmp(param_name, "totem.token") == 0)
92  return &totem_config->token_timeout;
93  if (strcmp(param_name, "totem.token_retransmit") == 0)
94  return &totem_config->token_retransmit_timeout;
95  if (strcmp(param_name, "totem.hold") == 0)
96  return &totem_config->token_hold_timeout;
97  if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
98  return &totem_config->token_retransmits_before_loss_const;
99  if (strcmp(param_name, "totem.join") == 0)
100  return &totem_config->join_timeout;
101  if (strcmp(param_name, "totem.send_join") == 0)
102  return &totem_config->send_join_timeout;
103  if (strcmp(param_name, "totem.consensus") == 0)
104  return &totem_config->consensus_timeout;
105  if (strcmp(param_name, "totem.merge") == 0)
106  return &totem_config->merge_timeout;
107  if (strcmp(param_name, "totem.downcheck") == 0)
108  return &totem_config->downcheck_timeout;
109  if (strcmp(param_name, "totem.fail_recv_const") == 0)
110  return &totem_config->fail_to_recv_const;
111  if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
112  return &totem_config->seqno_unchanged_const;
113  if (strcmp(param_name, "totem.rrp_token_expired_timeout") == 0)
114  return &totem_config->rrp_token_expired_timeout;
115  if (strcmp(param_name, "totem.rrp_problem_count_timeout") == 0)
116  return &totem_config->rrp_problem_count_timeout;
117  if (strcmp(param_name, "totem.rrp_problem_count_threshold") == 0)
118  return &totem_config->rrp_problem_count_threshold;
119  if (strcmp(param_name, "totem.rrp_problem_count_mcast_threshold") == 0)
120  return &totem_config->rrp_problem_count_mcast_threshold;
121  if (strcmp(param_name, "totem.rrp_autorecovery_check_timeout") == 0)
122  return &totem_config->rrp_autorecovery_check_timeout;
123  if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
124  return &totem_config->heartbeat_failures_allowed;
125  if (strcmp(param_name, "totem.max_network_delay") == 0)
126  return &totem_config->max_network_delay;
127  if (strcmp(param_name, "totem.window_size") == 0)
128  return &totem_config->window_size;
129  if (strcmp(param_name, "totem.max_messages") == 0)
130  return &totem_config->max_messages;
131  if (strcmp(param_name, "totem.miss_count_const") == 0)
132  return &totem_config->miss_count_const;
133 
134  return NULL;
135 }
136 
137 /*
138  * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
139  * and readed value is zero, default value is used and stored into totem_config.
140  */
141 static void totem_volatile_config_set_value (struct totem_config *totem_config,
142  const char *key_name, const char *deleted_key, unsigned int default_value,
143  int allow_zero_value)
144 {
145 
146  if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
147  (deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
148  (!allow_zero_value && *totem_get_param_by_name(totem_config, key_name) == 0)) {
149  *totem_get_param_by_name(totem_config, key_name) = default_value;
150  }
151 }
152 
153 
154 /*
155  * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
156  * default value is stored. deleted_key is name of key beeing processed by delete operation
157  * from cmap. It is considered as non existing even if it can be read. Can be NULL.
158  */
159 static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
160 {
161  uint32_t u32;
162 
163  totem_volatile_config_set_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
165 
166  totem_volatile_config_set_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
167 
168  if (totem_config->interface_count > 0 && totem_config->interfaces[0].member_count > 2) {
169  u32 = TOKEN_COEFFICIENT;
170  icmap_get_uint32("totem.token_coefficient", &u32);
171  totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
172  }
173 
174  totem_volatile_config_set_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
175 
176  totem_volatile_config_set_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
177 
178  totem_volatile_config_set_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
179 
180  totem_volatile_config_set_value(totem_config, "totem.miss_count_const", deleted_key, MISS_COUNT_CONST, 0);
181 
182  totem_volatile_config_set_value(totem_config, "totem.token_retransmit", deleted_key,
183  (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
184 
185  totem_volatile_config_set_value(totem_config, "totem.hold", deleted_key,
186  (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
187 
188  totem_volatile_config_set_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
189 
190  totem_volatile_config_set_value(totem_config, "totem.consensus", deleted_key,
191  (int)(float)(1.2 * totem_config->token_timeout), 0);
192 
193  totem_volatile_config_set_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
194 
195  totem_volatile_config_set_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
196 
197  totem_volatile_config_set_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
198 
199  totem_volatile_config_set_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
201 
202  totem_volatile_config_set_value(totem_config, "totem.send_join", deleted_key, 0, 1);
203 
204  totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_timeout", deleted_key,
206 
207  totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_threshold", deleted_key,
209 
210  totem_volatile_config_set_value(totem_config, "totem.rrp_problem_count_mcast_threshold", deleted_key,
211  totem_config->rrp_problem_count_threshold * 10, 0);
212 
213  totem_volatile_config_set_value(totem_config, "totem.rrp_token_expired_timeout", deleted_key,
214  totem_config->token_retransmit_timeout, 0);
215 
216  totem_volatile_config_set_value(totem_config, "totem.rrp_autorecovery_check_timeout", deleted_key,
218 
219  totem_volatile_config_set_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
220 }
221 
222 static int totem_volatile_config_validate (
223  struct totem_config *totem_config,
224  const char **error_string)
225 {
226  static char local_error_reason[512];
227  const char *error_reason = local_error_reason;
228 
229  if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
230  snprintf (local_error_reason, sizeof(local_error_reason),
231  "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
232  totem_config->max_network_delay, MINIMUM_TIMEOUT);
233  goto parse_error;
234  }
235 
236  if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
237  snprintf (local_error_reason, sizeof(local_error_reason),
238  "The token timeout parameter (%d ms) may not be less than (%d ms).",
239  totem_config->token_timeout, MINIMUM_TIMEOUT);
240  goto parse_error;
241  }
242 
243  if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
244  snprintf (local_error_reason, sizeof(local_error_reason),
245  "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
247  goto parse_error;
248  }
249 
250  if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) {
251  snprintf (local_error_reason, sizeof(local_error_reason),
252  "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
253  totem_config->token_hold_timeout, MINIMUM_TIMEOUT);
254  goto parse_error;
255  }
256 
257  if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
258  snprintf (local_error_reason, sizeof(local_error_reason),
259  "The join timeout parameter (%d ms) may not be less than (%d ms).",
260  totem_config->join_timeout, MINIMUM_TIMEOUT);
261  goto parse_error;
262  }
263 
264  if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
265  snprintf (local_error_reason, sizeof(local_error_reason),
266  "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
267  totem_config->consensus_timeout, MINIMUM_TIMEOUT);
268  goto parse_error;
269  }
270 
271  if (totem_config->consensus_timeout < totem_config->join_timeout) {
272  snprintf (local_error_reason, sizeof(local_error_reason),
273  "The consensus timeout parameter (%d ms) may not be less than join timeout (%d ms).",
274  totem_config->consensus_timeout, totem_config->join_timeout);
275  goto parse_error;
276  }
277 
278  if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
279  snprintf (local_error_reason, sizeof(local_error_reason),
280  "The merge timeout parameter (%d ms) may not be less than (%d ms).",
281  totem_config->merge_timeout, MINIMUM_TIMEOUT);
282  goto parse_error;
283  }
284 
285  if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
286  snprintf (local_error_reason, sizeof(local_error_reason),
287  "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
288  totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
289  goto parse_error;
290  }
291 
292  if (totem_config->rrp_problem_count_timeout < MINIMUM_TIMEOUT) {
293  snprintf (local_error_reason, sizeof(local_error_reason),
294  "The RRP problem count timeout parameter (%d ms) may not be less than (%d ms).",
296  goto parse_error;
297  }
298 
300  snprintf (local_error_reason, sizeof(local_error_reason),
301  "The RRP problem count threshold (%d problem count) may not be less than (%d problem count).",
303  goto parse_error;
304  }
306  snprintf (local_error_reason, sizeof(local_error_reason),
307  "The RRP multicast problem count threshold (%d problem count) may not be less than (%d problem count).",
309  goto parse_error;
310  }
311 
312  if (totem_config->rrp_token_expired_timeout < MINIMUM_TIMEOUT) {
313  snprintf (local_error_reason, sizeof(local_error_reason),
314  "The RRP token expired timeout parameter (%d ms) may not be less than (%d ms).",
316  goto parse_error;
317  }
318 
319  return 0;
320 
321 parse_error:
322  snprintf (error_string_response, sizeof(error_string_response),
323  "parse error in config: %s\n", error_reason);
324  *error_string = error_string_response;
325  return (-1);
326 
327 }
328 
329 static int totem_get_crypto(struct totem_config *totem_config)
330 {
331  char *str;
332  const char *tmp_cipher;
333  const char *tmp_hash;
334 
335  tmp_hash = "sha1";
336  tmp_cipher = "aes256";
337 
338  if (icmap_get_string("totem.secauth", &str) == CS_OK) {
339  if (strcmp (str, "off") == 0) {
340  tmp_hash = "none";
341  tmp_cipher = "none";
342  }
343  free(str);
344  }
345 
346  if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
347  if (strcmp(str, "none") == 0) {
348  tmp_cipher = "none";
349  }
350  if (strcmp(str, "aes256") == 0) {
351  tmp_cipher = "aes256";
352  }
353  if (strcmp(str, "aes192") == 0) {
354  tmp_cipher = "aes192";
355  }
356  if (strcmp(str, "aes128") == 0) {
357  tmp_cipher = "aes128";
358  }
359  if (strcmp(str, "3des") == 0) {
360  tmp_cipher = "3des";
361  }
362  free(str);
363  }
364 
365  if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
366  if (strcmp(str, "none") == 0) {
367  tmp_hash = "none";
368  }
369  if (strcmp(str, "md5") == 0) {
370  tmp_hash = "md5";
371  }
372  if (strcmp(str, "sha1") == 0) {
373  tmp_hash = "sha1";
374  }
375  if (strcmp(str, "sha256") == 0) {
376  tmp_hash = "sha256";
377  }
378  if (strcmp(str, "sha384") == 0) {
379  tmp_hash = "sha384";
380  }
381  if (strcmp(str, "sha512") == 0) {
382  tmp_hash = "sha512";
383  }
384  free(str);
385  }
386 
387  if ((strcmp(tmp_cipher, "none") != 0) &&
388  (strcmp(tmp_hash, "none") == 0)) {
389  return -1;
390  }
391 
392  free(totem_config->crypto_cipher_type);
393  free(totem_config->crypto_hash_type);
394 
395  totem_config->crypto_cipher_type = strdup(tmp_cipher);
396  totem_config->crypto_hash_type = strdup(tmp_hash);
397 
398  return 0;
399 }
400 
401 static int totem_config_get_ip_version(void)
402 {
403  int res;
404  char *str;
405 
406  res = AF_INET;
407  if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
408  if (strcmp(str, "ipv4") == 0) {
409  res = AF_INET;
410  }
411  if (strcmp(str, "ipv6") == 0) {
412  res = AF_INET6;
413  }
414  free(str);
415  }
416 
417  return (res);
418 }
419 
420 static uint16_t generate_cluster_id (const char *cluster_name)
421 {
422  int i;
423  int value = 0;
424 
425  for (i = 0; i < strlen(cluster_name); i++) {
426  value <<= 1;
427  value += cluster_name[i];
428  }
429 
430  return (value & 0xFFFF);
431 }
432 
433 static int get_cluster_mcast_addr (
434  const char *cluster_name,
435  const struct totem_ip_address *bindnet,
436  unsigned int ringnumber,
437  int ip_version,
438  struct totem_ip_address *res)
439 {
440  uint16_t clusterid;
441  char addr[INET6_ADDRSTRLEN + 1];
442  int err;
443 
444  if (cluster_name == NULL) {
445  return (-1);
446  }
447 
448  clusterid = generate_cluster_id(cluster_name) + ringnumber;
449  memset (res, 0, sizeof(*res));
450 
451  switch (bindnet->family) {
452  case AF_INET:
453  snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
454  break;
455  case AF_INET6:
456  snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
457  break;
458  default:
459  /*
460  * Unknown family
461  */
462  return (-1);
463  }
464 
465  err = totemip_parse (res, addr, ip_version);
466 
467  return (err);
468 }
469 
470 static int find_local_node_in_nodelist(struct totem_config *totem_config)
471 {
472  icmap_iter_t iter;
473  const char *iter_key;
474  int res = 0;
475  unsigned int node_pos;
476  int local_node_pos = -1;
477  struct totem_ip_address bind_addr;
478  int interface_up, interface_num;
479  char tmp_key[ICMAP_KEYNAME_MAXLEN];
480  char *node_addr_str;
481  struct totem_ip_address node_addr;
482 
483  res = totemip_iface_check(&totem_config->interfaces[0].bindnet,
484  &bind_addr, &interface_up, &interface_num,
485  totem_config->clear_node_high_bit);
486  if (res == -1) {
487  return (-1);
488  }
489 
490  iter = icmap_iter_init("nodelist.node.");
491  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
492  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
493  if (res != 2) {
494  continue;
495  }
496 
497  if (strcmp(tmp_key, "ring0_addr") != 0) {
498  continue;
499  }
500 
501  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
502  if (icmap_get_string(tmp_key, &node_addr_str) != CS_OK) {
503  continue;
504  }
505 
506  res = totemip_parse (&node_addr, node_addr_str, totem_config->ip_version);
507  free(node_addr_str);
508  if (res == -1) {
509  continue ;
510  }
511 
512  if (totemip_equal(&bind_addr, &node_addr)) {
513  local_node_pos = node_pos;
514  }
515  }
516  icmap_iter_finalize(iter);
517 
518  return (local_node_pos);
519 }
520 
521 static void put_nodelist_members_to_config(struct totem_config *totem_config)
522 {
523  icmap_iter_t iter, iter2;
524  const char *iter_key, *iter_key2;
525  int res = 0;
526  unsigned int node_pos;
527  char tmp_key[ICMAP_KEYNAME_MAXLEN];
528  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
529  char *node_addr_str;
530  int member_count;
531  unsigned int ringnumber = 0;
532  int i, j;
533 
534  /* Clear out nodelist so we can put the new one in if needed */
535  for (i = 0; i < totem_config->interface_count; i++) {
536  for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
537  memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
538  }
539  totem_config->interfaces[i].member_count = 0;
540  }
541 
542  iter = icmap_iter_init("nodelist.node.");
543  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
544  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
545  if (res != 2) {
546  continue;
547  }
548 
549  if (strcmp(tmp_key, "ring0_addr") != 0) {
550  continue;
551  }
552 
553  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
554  iter2 = icmap_iter_init(tmp_key);
555  while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
556  res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
557  if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
558  continue;
559  }
560 
561  if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
562  continue;
563  }
564 
565  member_count = totem_config->interfaces[ringnumber].member_count;
566 
567  res = totemip_parse(&totem_config->interfaces[ringnumber].member_list[member_count],
568  node_addr_str, totem_config->ip_version);
569  if (res != -1) {
570  totem_config->interfaces[ringnumber].member_count++;
571  }
572  free(node_addr_str);
573  }
574 
575  icmap_iter_finalize(iter2);
576  }
577 
578  icmap_iter_finalize(iter);
579 }
580 
581 /*
582  * Tries to find node (node_pos) in config nodelist which address matches any
583  * local interface. Address can be stored in ring0_addr or if ipaddr_key_prefix is not NULL
584  * key with prefix ipaddr_key is used (there can be multiuple of them)
585  * This function differs * from find_local_node_in_nodelist because it doesn't need bindnetaddr,
586  * but doesn't work when bind addr is network address (so IP must be exact
587  * match).
588  *
589  * Returns 1 on success (address was found, node_pos is then correctly set) or 0 on failure.
590  */
591 int totem_config_find_local_addr_in_nodelist(const char *ipaddr_key_prefix, unsigned int *node_pos)
592 {
593  struct list_head addrs;
594  struct totem_ip_if_address *if_addr;
595  icmap_iter_t iter, iter2;
596  const char *iter_key, *iter_key2;
597  struct list_head *list;
598  const char *ipaddr_key;
599  int ip_version;
600  struct totem_ip_address node_addr;
601  char *node_addr_str;
602  int node_found = 0;
603  int res = 0;
604  char tmp_key[ICMAP_KEYNAME_MAXLEN];
605 
606  if (totemip_getifaddrs(&addrs) == -1) {
607  return 0;
608  }
609 
610  ip_version = totem_config_get_ip_version();
611 
612  iter = icmap_iter_init("nodelist.node.");
613 
614  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
615  res = sscanf(iter_key, "nodelist.node.%u.%s", node_pos, tmp_key);
616  if (res != 2) {
617  continue;
618  }
619 
620  if (strcmp(tmp_key, "ring0_addr") != 0) {
621  continue;
622  }
623 
624  if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
625  continue ;
626  }
627 
628  free(node_addr_str);
629 
630  /*
631  * ring0_addr found -> let's iterate thru ipaddr_key_prefix
632  */
633  snprintf(tmp_key, sizeof(tmp_key), "nodelist.node.%u.%s", *node_pos,
634  (ipaddr_key_prefix != NULL ? ipaddr_key_prefix : "ring0_addr"));
635 
636  iter2 = icmap_iter_init(tmp_key);
637  while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
638  /*
639  * ring0_addr must be exact match, not prefix
640  */
641  ipaddr_key = (ipaddr_key_prefix != NULL ? iter_key2 : tmp_key);
642  if (icmap_get_string(ipaddr_key, &node_addr_str) != CS_OK) {
643  continue ;
644  }
645 
646  if (totemip_parse(&node_addr, node_addr_str, ip_version) == -1) {
647  free(node_addr_str);
648  continue ;
649  }
650  free(node_addr_str);
651 
652  /*
653  * Try to match ip with if_addrs
654  */
655  node_found = 0;
656  for (list = addrs.next; list != &addrs; list = list->next) {
657  if_addr = list_entry(list, struct totem_ip_if_address, list);
658 
659  if (totemip_equal(&node_addr, &if_addr->ip_addr)) {
660  node_found = 1;
661  break;
662  }
663  }
664 
665  if (node_found) {
666  break ;
667  }
668  }
669 
670  icmap_iter_finalize(iter2);
671 
672  if (node_found) {
673  break ;
674  }
675  }
676 
677  icmap_iter_finalize(iter);
678  totemip_freeifaddrs(&addrs);
679 
680  return (node_found);
681 }
682 
683 static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
684 {
685  int res = 0;
686  unsigned int node_pos;
687  char tmp_key[ICMAP_KEYNAME_MAXLEN];
688  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
689  char *node_addr_str;
690  unsigned int ringnumber = 0;
691  icmap_iter_t iter;
692  const char *iter_key;
693 
694  if (totem_config_find_local_addr_in_nodelist(NULL, &node_pos)) {
695  /*
696  * We found node, so create interface section
697  */
698  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
699  iter = icmap_iter_init(tmp_key);
700  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
701  res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2);
702  if (res != 3 || strcmp(tmp_key2, "_addr") != 0) {
703  continue ;
704  }
705 
706  if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
707  continue;
708  }
709 
710  snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", ringnumber);
711  icmap_set_string(tmp_key2, node_addr_str);
712  free(node_addr_str);
713  }
714  icmap_iter_finalize(iter);
715  }
716 }
717 
718 
719 extern int totem_config_read (
720  struct totem_config *totem_config,
721  const char **error_string,
722  uint64_t *warnings)
723 {
724  int res = 0;
725  char *str;
726  unsigned int ringnumber = 0;
727  int member_count = 0;
728  icmap_iter_t iter, member_iter;
729  const char *iter_key;
730  const char *member_iter_key;
731  char ringnumber_key[ICMAP_KEYNAME_MAXLEN];
732  char tmp_key[ICMAP_KEYNAME_MAXLEN];
733  uint8_t u8;
734  uint16_t u16;
735  char *cluster_name = NULL;
736  int i;
737  int local_node_pos;
738  int nodeid_set;
739 
740  *warnings = 0;
741 
742  memset (totem_config, 0, sizeof (struct totem_config));
743  totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
744  if (totem_config->interfaces == 0) {
745  *error_string = "Out of memory trying to allocate ethernet interface storage area";
746  return -1;
747  }
748 
749  memset (totem_config->interfaces, 0,
750  sizeof (struct totem_interface) * INTERFACE_MAX);
751 
752  strcpy (totem_config->rrp_mode, "none");
753 
754  icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
755 
756  if (totem_get_crypto(totem_config) != 0) {
757  *error_string = "crypto_cipher requires crypto_hash with value other than none";
758  return -1;
759  }
760 
761  if (icmap_get_string("totem.rrp_mode", &str) == CS_OK) {
762  if (strlen(str) >= TOTEM_RRP_MODE_BYTES) {
763  *error_string = "totem.rrp_mode is too long";
764  free(str);
765 
766  return -1;
767  }
768  strcpy (totem_config->rrp_mode, str);
769  free(str);
770  }
771 
772  icmap_get_uint32("totem.nodeid", &totem_config->node_id);
773 
774  totem_config->clear_node_high_bit = 0;
775  if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
776  if (strcmp (str, "yes") == 0) {
777  totem_config->clear_node_high_bit = 1;
778  }
779  free(str);
780  }
781 
782  icmap_get_uint32("totem.threads", &totem_config->threads);
783 
784  icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
785 
786  if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
787  cluster_name = NULL;
788  }
789 
790  totem_config->ip_version = totem_config_get_ip_version();
791 
792  if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
793  /*
794  * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
795  */
796  config_convert_nodelist_to_interface(totem_config);
797  } else {
798  free(str);
799  }
800 
801  iter = icmap_iter_init("totem.interface.");
802  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
803  res = sscanf(iter_key, "totem.interface.%[^.].%s", ringnumber_key, tmp_key);
804  if (res != 2) {
805  continue;
806  }
807 
808  if (strcmp(tmp_key, "bindnetaddr") != 0) {
809  continue;
810  }
811 
812  member_count = 0;
813 
814  ringnumber = atoi(ringnumber_key);
815 
816  if (ringnumber >= INTERFACE_MAX) {
817  free(cluster_name);
818 
819  snprintf (error_string_response, sizeof(error_string_response),
820  "parse error in config: interface ring number %u is bigger than allowed maximum %u\n",
821  ringnumber, INTERFACE_MAX - 1);
822 
823  *error_string = error_string_response;
824  return -1;
825  }
826 
827  /*
828  * Get the bind net address
829  */
830  if (icmap_get_string(iter_key, &str) == CS_OK) {
831  res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
832  totem_config->interfaces[ringnumber].mcast_addr.family);
833  free(str);
834  }
835 
836  /*
837  * Get interface multicast address
838  */
839  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", ringnumber);
840  if (icmap_get_string(tmp_key, &str) == CS_OK) {
841  res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, totem_config->ip_version);
842  free(str);
843  } else {
844  /*
845  * User not specified address -> autogenerate one from cluster_name key
846  * (if available)
847  */
848  res = get_cluster_mcast_addr (cluster_name,
849  &totem_config->interfaces[ringnumber].bindnet,
850  ringnumber,
851  totem_config->ip_version,
852  &totem_config->interfaces[ringnumber].mcast_addr);
853  }
854 
855  totem_config->broadcast_use = 0;
856  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", ringnumber);
857  if (icmap_get_string(tmp_key, &str) == CS_OK) {
858  if (strcmp (str, "yes") == 0) {
859  totem_config->broadcast_use = 1;
860  totemip_parse (
861  &totem_config->interfaces[ringnumber].mcast_addr,
862  "255.255.255.255", totem_config->ip_version);
863  }
864  free(str);
865  }
866 
867  /*
868  * Get mcast port
869  */
870  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", ringnumber);
871  if (icmap_get_uint16(tmp_key, &totem_config->interfaces[ringnumber].ip_port) != CS_OK) {
872  if (totem_config->broadcast_use) {
873  totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT + (2 * ringnumber);
874  } else {
875  totem_config->interfaces[ringnumber].ip_port = DEFAULT_PORT;
876  }
877  }
878 
879  /*
880  * Get the TTL
881  */
882  totem_config->interfaces[ringnumber].ttl = 1;
883 
884  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", ringnumber);
885 
886  if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
887  totem_config->interfaces[ringnumber].ttl = u8;
888  }
889 
890  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", ringnumber);
891  member_iter = icmap_iter_init(tmp_key);
892  while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
893  if (member_count == 0) {
894  if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
895  free(str);
897  break;
898  } else {
900  }
901  }
902 
903  if (icmap_get_string(member_iter_key, &str) == CS_OK) {
904  res = totemip_parse (&totem_config->interfaces[ringnumber].member_list[member_count++],
905  str, totem_config->ip_version);
906  }
907  }
908  icmap_iter_finalize(member_iter);
909 
910  totem_config->interfaces[ringnumber].member_count = member_count;
911  totem_config->interface_count++;
912  }
913  icmap_iter_finalize(iter);
914 
915  /*
916  * Store automatically generated items back to icmap
917  */
918  for (i = 0; i < totem_config->interface_count; i++) {
919  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
920  if (icmap_get_string(tmp_key, &str) == CS_OK) {
921  free(str);
922  } else {
923  str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
924  icmap_set_string(tmp_key, str);
925  }
926 
927  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
928  if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
929  icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
930  }
931  }
932 
933  totem_config->transport_number = TOTEM_TRANSPORT_UDP;
934  if (icmap_get_string("totem.transport", &str) == CS_OK) {
935  if (strcmp (str, "udpu") == 0) {
936  totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
937  }
938 
939  if (strcmp (str, "iba") == 0) {
940  totem_config->transport_number = TOTEM_TRANSPORT_RDMA;
941  }
942  free(str);
943  }
944 
945  free(cluster_name);
946 
947  /*
948  * Check existence of nodelist
949  */
950  if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
951  free(str);
952  /*
953  * find local node
954  */
955  local_node_pos = find_local_node_in_nodelist(totem_config);
956  if (local_node_pos != -1) {
957  icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
958 
959  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
960 
961  nodeid_set = (totem_config->node_id != 0);
962  if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
964  }
965 
966  /*
967  * Make localnode ring0_addr read only, so we can be sure that local
968  * node never changes. If rebinding to other IP would be in future
969  * supported, this must be changed and handled properly!
970  */
971  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
972  icmap_set_ro_access(tmp_key, 0, 1);
973  icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
974  }
975 
976  put_nodelist_members_to_config(totem_config);
977  }
978 
979  /*
980  * Get things that might change in the future (and can depend on totem_config->interfaces);
981  */
982  totem_volatile_config_read(totem_config, NULL);
983 
984  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
985 
986  add_totem_config_notification(totem_config);
987 
988  return 0;
989 }
990 
991 
993  struct totem_config *totem_config,
994  const char **error_string)
995 {
996  static char local_error_reason[512];
997  char parse_error[512];
998  const char *error_reason = local_error_reason;
999  int i;
1000  unsigned int interface_max = INTERFACE_MAX;
1001 
1002  if (totem_config->interface_count == 0) {
1003  error_reason = "No interfaces defined";
1004  goto parse_error;
1005  }
1006 
1007  for (i = 0; i < totem_config->interface_count; i++) {
1008  /*
1009  * Some error checking of parsed data to make sure its valid
1010  */
1011 
1012  struct totem_ip_address null_addr;
1013  memset (&null_addr, 0, sizeof (struct totem_ip_address));
1014 
1015  if ((totem_config->transport_number == 0) &&
1016  memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
1017  sizeof (struct totem_ip_address)) == 0) {
1018  error_reason = "No multicast address specified";
1019  goto parse_error;
1020  }
1021 
1022  if (totem_config->interfaces[i].ip_port == 0) {
1023  error_reason = "No multicast port specified";
1024  goto parse_error;
1025  }
1026 
1027  if (totem_config->interfaces[i].ttl > 255) {
1028  error_reason = "Invalid TTL (should be 0..255)";
1029  goto parse_error;
1030  }
1031  if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
1032  totem_config->interfaces[i].ttl != 1) {
1033  error_reason = "Can only set ttl on multicast transport types";
1034  goto parse_error;
1035  }
1036 
1037  if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
1038  totem_config->node_id == 0) {
1039 
1040  error_reason = "An IPV6 network requires that a node ID be specified.";
1041  goto parse_error;
1042  }
1043 
1044  if (totem_config->broadcast_use == 0 && totem_config->transport_number == 0) {
1045  if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
1046  error_reason = "Multicast address family does not match bind address family";
1047  goto parse_error;
1048  }
1049 
1050  if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
1051  error_reason = "Not all bind address belong to the same IP family";
1052  goto parse_error;
1053  }
1054  if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
1055  error_reason = "mcastaddr is not a correct multicast address.";
1056  goto parse_error;
1057  }
1058  }
1059  }
1060 
1061  if (totem_config->version != 2) {
1062  error_reason = "This totem parser can only parse version 2 configurations.";
1063  goto parse_error;
1064  }
1065 
1066  if (totem_volatile_config_validate(totem_config, error_string) == -1) {
1067  return (-1);
1068  }
1069 
1070  /*
1071  * RRP values validation
1072  */
1073  if (strcmp (totem_config->rrp_mode, "none") &&
1074  strcmp (totem_config->rrp_mode, "active") &&
1075  strcmp (totem_config->rrp_mode, "passive")) {
1076  snprintf (local_error_reason, sizeof(local_error_reason),
1077  "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode);
1078  goto parse_error;
1079  }
1080 
1081  if (strcmp (totem_config->rrp_mode, "none") == 0) {
1082  interface_max = 1;
1083  }
1084  if (interface_max < totem_config->interface_count) {
1085  snprintf (parse_error, sizeof(parse_error),
1086  "%d is too many configured interfaces for the rrp_mode setting %s.",
1087  totem_config->interface_count,
1088  totem_config->rrp_mode);
1089  error_reason = parse_error;
1090  goto parse_error;
1091  }
1092 
1093  if (totem_config->net_mtu == 0) {
1094  totem_config->net_mtu = 1500;
1095  }
1096 
1097  return 0;
1098 
1099 parse_error:
1100  snprintf (error_string_response, sizeof(error_string_response),
1101  "parse error in config: %s\n", error_reason);
1102  *error_string = error_string_response;
1103  return (-1);
1104 
1105 }
1106 
1107 static int read_keyfile (
1108  const char *key_location,
1109  struct totem_config *totem_config,
1110  const char **error_string)
1111 {
1112  int fd;
1113  int res;
1114  ssize_t expected_key_len = sizeof (totem_config->private_key);
1115  int saved_errno;
1116  char error_str[100];
1117  const char *error_ptr;
1118 
1119  fd = open (key_location, O_RDONLY);
1120  if (fd == -1) {
1121  error_ptr = qb_strerror_r(errno, error_str, sizeof(error_str));
1122  snprintf (error_string_response, sizeof(error_string_response),
1123  "Could not open %s: %s\n",
1124  key_location, error_ptr);
1125  goto parse_error;
1126  }
1127 
1128  res = read (fd, totem_config->private_key, expected_key_len);
1129  saved_errno = errno;
1130  close (fd);
1131 
1132  if (res == -1) {
1133  error_ptr = qb_strerror_r (saved_errno, error_str, sizeof(error_str));
1134  snprintf (error_string_response, sizeof(error_string_response),
1135  "Could not read %s: %s\n",
1136  key_location, error_ptr);
1137  goto parse_error;
1138  }
1139 
1140  totem_config->private_key_len = expected_key_len;
1141 
1142  if (res != expected_key_len) {
1143  snprintf (error_string_response, sizeof(error_string_response),
1144  "Could only read %d bits of 1024 bits from %s.\n",
1145  res * 8, key_location);
1146  goto parse_error;
1147  }
1148 
1149  return 0;
1150 
1151 parse_error:
1152  *error_string = error_string_response;
1153  return (-1);
1154 }
1155 
1157  struct totem_config *totem_config,
1158  const char **error_string)
1159 {
1160  int got_key = 0;
1161  char *key_location = NULL;
1162  int res;
1163  size_t key_len;
1164 
1165  memset (totem_config->private_key, 0, 128);
1166  totem_config->private_key_len = 128;
1167 
1168  if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
1169  strcmp(totem_config->crypto_hash_type, "none") == 0) {
1170  return (0);
1171  }
1172 
1173  /* cmap may store the location of the key file */
1174  if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
1175  res = read_keyfile(key_location, totem_config, error_string);
1176  free(key_location);
1177  if (res) {
1178  goto key_error;
1179  }
1180  got_key = 1;
1181  } else { /* Or the key itself may be in the cmap */
1182  if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
1183  if (key_len > sizeof (totem_config->private_key)) {
1184  sprintf(error_string_response, "key is too long");
1185  goto key_error;
1186  }
1187  if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
1188  totem_config->private_key_len = key_len;
1189  got_key = 1;
1190  } else {
1191  sprintf(error_string_response, "can't store private key");
1192  goto key_error;
1193  }
1194  }
1195  }
1196 
1197  /* In desperation we read the default filename */
1198  if (!got_key) {
1199  const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
1200  if (!filename)
1201  filename = COROSYSCONFDIR "/authkey";
1202  res = read_keyfile(filename, totem_config, error_string);
1203  if (res)
1204  goto key_error;
1205 
1206  }
1207 
1208  return (0);
1209 
1210 key_error:
1211  *error_string = error_string_response;
1212  return (-1);
1213 
1214 }
1215 
1216 static void debug_dump_totem_config(const struct totem_config *totem_config)
1217 {
1218 
1219  log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
1220  totem_config->token_timeout, totem_config->token_retransmit_timeout);
1221  log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
1222  totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
1223  log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
1224  totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
1225  totem_config->merge_timeout);
1226  log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
1227  totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
1229  "seqno unchanged const (%d rotations) Maximum network MTU %d",
1230  totem_config->seqno_unchanged_const, totem_config->net_mtu);
1232  "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
1233  totem_config->window_size, totem_config->max_messages);
1234  log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
1235  log_printf(LOGSYS_LEVEL_DEBUG, "RRP token expired timeout (%d ms)",
1236  totem_config->rrp_token_expired_timeout);
1237  log_printf(LOGSYS_LEVEL_DEBUG, "RRP token problem counter (%d ms)",
1238  totem_config->rrp_problem_count_timeout);
1239  log_printf(LOGSYS_LEVEL_DEBUG, "RRP threshold (%d problem count)",
1240  totem_config->rrp_problem_count_threshold);
1241  log_printf(LOGSYS_LEVEL_DEBUG, "RRP multicast threshold (%d problem count)",
1242  totem_config->rrp_problem_count_mcast_threshold);
1243  log_printf(LOGSYS_LEVEL_DEBUG, "RRP automatic recovery check timeout (%d ms)",
1244  totem_config->rrp_autorecovery_check_timeout);
1245  log_printf(LOGSYS_LEVEL_DEBUG, "RRP mode set to %s.",
1246  totem_config->rrp_mode);
1247  log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
1248  totem_config->heartbeat_failures_allowed);
1249  log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
1250 }
1251 
1252 static void totem_change_notify(
1253  int32_t event,
1254  const char *key_name,
1255  struct icmap_notify_value new_val,
1256  struct icmap_notify_value old_val,
1257  void *user_data)
1258 {
1259  struct totem_config *totem_config = (struct totem_config *)user_data;
1260  uint32_t *param;
1261  uint8_t reloading;
1262  const char *deleted_key = NULL;
1263  const char *error_string;
1264 
1265  /*
1266  * If a full reload is in progress then don't do anything until it's done and
1267  * can reconfigure it all atomically
1268  */
1269  if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
1270  return;
1271 
1272  param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
1273  /*
1274  * Process change only if changed key is found in totem_config (-> param is not NULL)
1275  * or for special key token_coefficient. token_coefficient key is not stored in
1276  * totem_config, but it is used for computation of token timeout.
1277  */
1278  if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
1279  return;
1280 
1281  /*
1282  * Values other than UINT32 are not supported, or needed (yet)
1283  */
1284  switch (event) {
1285  case ICMAP_TRACK_DELETE:
1286  deleted_key = key_name;
1287  break;
1288  case ICMAP_TRACK_ADD:
1289  case ICMAP_TRACK_MODIFY:
1290  deleted_key = NULL;
1291  break;
1292  default:
1293  break;
1294  }
1295 
1296  totem_volatile_config_read (totem_config, deleted_key);
1297  log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
1298  debug_dump_totem_config(totem_config);
1299  if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
1300  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1301  /*
1302  * TODO: Consider corosync exit and/or load defaults for volatile
1303  * values. For now, log error seems to be enough
1304  */
1305  }
1306 }
1307 
1308 static void totem_reload_notify(
1309  int32_t event,
1310  const char *key_name,
1311  struct icmap_notify_value new_val,
1312  struct icmap_notify_value old_val,
1313  void *user_data)
1314 {
1315  struct totem_config *totem_config = (struct totem_config *)user_data;
1316  uint32_t local_node_pos;
1317  const char *error_string;
1318 
1319  /* Reload has completed */
1320  if (*(uint8_t *)new_val.data == 0) {
1321  put_nodelist_members_to_config (totem_config);
1322  totem_volatile_config_read (totem_config, NULL);
1323  log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
1324  debug_dump_totem_config(totem_config);
1325  if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
1326  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1327  /*
1328  * TODO: Consider corosync exit and/or load defaults for volatile
1329  * values. For now, log error seems to be enough
1330  */
1331  }
1332 
1333  /* Reinstate the local_node_pos */
1334  local_node_pos = find_local_node_in_nodelist(totem_config);
1335  if (local_node_pos != -1) {
1336  icmap_set_uint32("nodelist.local_node_pos", local_node_pos);
1337  }
1338 
1339  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1340  } else {
1341  icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
1342  }
1343 }
1344 
1345 static void add_totem_config_notification(struct totem_config *totem_config)
1346 {
1348 
1349  icmap_track_add("totem.",
1351  totem_change_notify,
1352  totem_config,
1353  &icmap_track);
1354 
1355  icmap_track_add("config.reload_in_progress",
1357  totem_reload_notify,
1358  totem_config,
1359  &icmap_track);
1360 }
unsigned int clear_node_high_bit
Definition: totem.h:117
unsigned short family
Definition: coroapi.h:97
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Definition: icmap.c:1103
#define RRP_PROBLEM_COUNT_TIMEOUT
Definition: totemconfig.c:76
uint32_t value
struct totem_interface * interfaces
Definition: totem.h:114
unsigned int interface_count
Definition: totem.h:115
struct list_head * next
Definition: list.h:47
#define DEFAULT_PORT
Definition: totemconfig.c:81
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:214
void icmap_iter_finalize(icmap_iter_t iter)
Definition: icmap.c:1124
totem_transport_t transport_number
Definition: totem.h:185
int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family)
Definition: totemip.c:263
#define DOWNCHECK_TIMEOUT
Definition: totemconfig.c:68
unsigned int token_hold_timeout
Definition: totem.h:133
int member_count
Definition: totem.h:70
struct totem_ip_address member_list[PROCESSOR_COUNT_MAX]
Definition: totem.h:71
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN]
Definition: totem.h:122
char rrp_mode[TOTEM_RRP_MODE_BYTES]
Definition: totem.h:161
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:67
#define COROSYSCONFDIR
Definition: config.h:11
unsigned int rrp_problem_count_timeout
Definition: totem.h:153
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:641
int totemip_is_mcast(struct totem_ip_address *addr)
Definition: totemip.c:114
#define RRP_AUTORECOVERY_CHECK_TIMEOUT
Definition: totemconfig.c:79
unsigned int downcheck_timeout
Definition: totem.h:145
unsigned int private_key_len
Definition: totem.h:124
Definition: list.h:46
#define SEQNO_UNCHANGED_CONST
Definition: totemconfig.c:70
unsigned int max_network_delay
Definition: totem.h:171
#define log_printf(level, format, args...)
Definition: logsys.h:217
unsigned int heartbeat_failures_allowed
Definition: totem.h:169
unsigned int send_join_timeout
Definition: totem.h:139
unsigned int window_size
Definition: totem.h:173
unsigned int rrp_problem_count_threshold
Definition: totem.h:155
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
#define INTERFACE_MAX
Definition: coroapi.h:75
#define RRP_PROBLEM_COUNT_THRESHOLD_MIN
Definition: totemconfig.c:78
#define ICMAP_KEYNAME_MAXLEN
Definition: icmap.h:48
#define MINIMUM_TIMEOUT
Definition: totemconfig.c:71
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:842
uint16_t ttl
Definition: totem.h:69
unsigned int node_id
Definition: totem.h:116
int totem_config_keyread(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:1156
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
unsigned int token_retransmits_before_loss_const
Definition: totem.h:135
int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit)
Definition: totemip.c:405
#define FAIL_TO_RECV_CONST
Definition: totemconfig.c:69
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:611
unsigned int seqno_unchanged_const
Definition: totem.h:149
void * user_data
Definition: sam.c:126
unsigned int miss_count_const
Definition: totem.h:187
unsigned int join_timeout
Definition: totem.h:137
int totem_config_validate(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:992
const void * data
Definition: icmap.h:93
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
int totem_config_find_local_addr_in_nodelist(const char *ipaddr_key_prefix, unsigned int *node_pos)
Definition: totemconfig.c:591
char * crypto_hash_type
Definition: totem.h:183
struct totem_ip_address mcast_addr
Definition: totem.h:67
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:70
Linked list API.
unsigned int rrp_autorecovery_check_timeout
Definition: totem.h:159
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Definition: icmap.c:739
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:74
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:599
unsigned int fail_to_recv_const
Definition: totem.h:147
#define TOKEN_COEFFICIENT
Definition: totemconfig.c:65
#define TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
Definition: totemconfig.h:47
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:866
uint8_t param
#define TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
Definition: totemconfig.h:46
uint16_t ip_port
Definition: totem.h:68
void totemip_freeifaddrs(struct list_head *addrs)
Definition: totemip.c:389
#define WINDOW_SIZE
Definition: totemconfig.c:73
int version
Definition: totem.h:109
unsigned int net_mtu
Definition: totem.h:165
#define MAX_NETWORK_DELAY
Definition: totemconfig.c:72
#define TOKEN_TIMEOUT
Definition: totemconfig.c:64
int ip_version
Definition: totem.h:189
#define MERGE_TIMEOUT
Definition: totemconfig.c:67
unsigned int token_timeout
Definition: totem.h:129
#define JOIN_TIMEOUT
Definition: totemconfig.c:66
unsigned int consensus_timeout
Definition: totem.h:141
int totemip_getifaddrs(struct list_head *addrs)
Definition: totemip.c:321
#define PROCESSOR_COUNT_MAX
Definition: coroapi.h:83
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
Definition: totemconfig.c:63
#define MISS_COUNT_CONST
Definition: totemconfig.c:75
unsigned int broadcast_use
Definition: totem.h:179
unsigned int rrp_problem_count_mcast_threshold
Definition: totem.h:157
cs_error_t icmap_get_string(const char *key_name, char **str)
Definition: icmap.c:896
#define list_entry(ptr, type, member)
Definition: list.h:84
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:587
unsigned int max_messages
Definition: totem.h:175
char * crypto_cipher_type
Definition: totem.h:181
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Definition: icmap.c:1233
unsigned int merge_timeout
Definition: totem.h:143
unsigned int token_retransmit_timeout
Definition: totem.h:131
struct totem_ip_address bindnet
Definition: totem.h:65
icmap_iter_t icmap_iter_init(const char *prefix)
Definition: icmap.c:1097
int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:71
struct totem_ip_address ip_addr
Definition: totemip.h:72
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:854
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
Definition: totemconfig.h:48
#define MAX_MESSAGES
Definition: totemconfig.c:74
unsigned int rrp_token_expired_timeout
Definition: totem.h:151
unsigned int threads
Definition: totem.h:167
qb_map_iter_t * icmap_iter_t
Definition: icmap.h:121
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)
Definition: icmap.c:1167
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
Definition: totemconfig.c:719
#define ICMAP_TRACK_PREFIX
Definition: icmap.h:84
#define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT
Definition: totemconfig.c:77