corosync  3.0.3
totemconfig.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 MontaVista Software, Inc.
3  * Copyright (c) 2006-2018 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 <ifaddrs.h>
49 #include <netdb.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
52 #include <sys/param.h>
53 #include <sys/utsname.h>
54 
55 #include <corosync/swab.h>
56 #include <qb/qblist.h>
57 #include <qb/qbdefs.h>
58 #include <libknet.h>
59 #include <corosync/totem/totem.h>
60 #include <corosync/config.h>
61 #include <corosync/logsys.h>
62 #include <corosync/icmap.h>
63 
64 #include "util.h"
65 #include "totemconfig.h"
66 
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
83 
84 /* Currently all but PONG_COUNT match the defaults in libknet.h */
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
91 
92 #define DEFAULT_PORT 5405
93 
94 static char error_string_response[768];
95 
96 static void add_totem_config_notification(struct totem_config *totem_config);
97 
98 static void *totem_get_param_by_name(struct totem_config *totem_config, const char *param_name)
99 {
100  if (strcmp(param_name, "totem.token") == 0)
101  return &totem_config->token_timeout;
102  if (strcmp(param_name, "totem.token_warning") == 0)
103  return &totem_config->token_warning;
104  if (strcmp(param_name, "totem.token_retransmit") == 0)
105  return &totem_config->token_retransmit_timeout;
106  if (strcmp(param_name, "totem.hold") == 0)
107  return &totem_config->token_hold_timeout;
108  if (strcmp(param_name, "totem.token_retransmits_before_loss_const") == 0)
109  return &totem_config->token_retransmits_before_loss_const;
110  if (strcmp(param_name, "totem.join") == 0)
111  return &totem_config->join_timeout;
112  if (strcmp(param_name, "totem.send_join") == 0)
113  return &totem_config->send_join_timeout;
114  if (strcmp(param_name, "totem.consensus") == 0)
115  return &totem_config->consensus_timeout;
116  if (strcmp(param_name, "totem.merge") == 0)
117  return &totem_config->merge_timeout;
118  if (strcmp(param_name, "totem.downcheck") == 0)
119  return &totem_config->downcheck_timeout;
120  if (strcmp(param_name, "totem.fail_recv_const") == 0)
121  return &totem_config->fail_to_recv_const;
122  if (strcmp(param_name, "totem.seqno_unchanged_const") == 0)
123  return &totem_config->seqno_unchanged_const;
124  if (strcmp(param_name, "totem.heartbeat_failures_allowed") == 0)
125  return &totem_config->heartbeat_failures_allowed;
126  if (strcmp(param_name, "totem.max_network_delay") == 0)
127  return &totem_config->max_network_delay;
128  if (strcmp(param_name, "totem.window_size") == 0)
129  return &totem_config->window_size;
130  if (strcmp(param_name, "totem.max_messages") == 0)
131  return &totem_config->max_messages;
132  if (strcmp(param_name, "totem.miss_count_const") == 0)
133  return &totem_config->miss_count_const;
134  if (strcmp(param_name, "totem.knet_pmtud_interval") == 0)
135  return &totem_config->knet_pmtud_interval;
136  if (strcmp(param_name, "totem.knet_compression_threshold") == 0)
137  return &totem_config->knet_compression_threshold;
138  if (strcmp(param_name, "totem.knet_compression_level") == 0)
139  return &totem_config->knet_compression_level;
140  if (strcmp(param_name, "totem.knet_compression_model") == 0)
141  return &totem_config->knet_compression_model;
142  if (strcmp(param_name, "totem.block_unlisted_ips") == 0)
143  return &totem_config->block_unlisted_ips;
144 
145  return NULL;
146 }
147 
148 /*
149  * Read key_name from icmap. If key is not found or key_name == delete_key or if allow_zero is false
150  * and readed value is zero, default value is used and stored into totem_config.
151  */
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)
155 {
156  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
157 
158  if (icmap_get_uint32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
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;
162  }
163 
164  /*
165  * Store totem_config value to cmap runtime section
166  */
167  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
168  /*
169  * This shouldn't happen
170  */
171  return ;
172  }
173 
174  strcpy(runtime_key_name, "runtime.config.");
175  strcat(runtime_key_name, key_name);
176 
177  icmap_set_uint32(runtime_key_name, *(uint32_t *)totem_get_param_by_name(totem_config, key_name));
178 }
179 
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)
183 {
184  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
185 
186  if (icmap_get_int32(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
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;
190  }
191 
192  /*
193  * Store totem_config value to cmap runtime section
194  */
195  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
196  /*
197  * This shouldn't happen
198  */
199  return ;
200  }
201 
202  strcpy(runtime_key_name, "runtime.config.");
203  strcat(runtime_key_name, key_name);
204 
205  icmap_set_int32(runtime_key_name, *(int32_t *)totem_get_param_by_name(totem_config, key_name));
206 }
207 
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)
210 {
211  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
212  void **config_value;
213  void *old_config_ptr;
214 
215  config_value = totem_get_param_by_name(totem_config, key_name);
216  old_config_ptr = *config_value;
217  if (icmap_get_string(key_name, totem_get_param_by_name(totem_config, key_name)) != CS_OK ||
218  (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
219 
220  /* Need to strdup() here so that the free() below works for a default and a configured value */
221  *config_value = strdup(default_value);
222  }
223  free(old_config_ptr);
224 
225  /*
226  * Store totem_config value to cmap runtime section
227  */
228  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
229  /*
230  * This shouldn't happen
231  */
232  return ;
233  }
234 
235  strcpy(runtime_key_name, "runtime.config.");
236  strcat(runtime_key_name, key_name);
237 
238  icmap_set_string(runtime_key_name, (char *)*config_value);
239 }
240 
241 /*
242  * Read string value stored in key_name from icmap, use it as a boolean (yes/no) type, convert it
243  * to integer value (1/0) and store into totem_config.
244  *
245  * If key is not found or key_name == delete_key default value is used
246  * and stored into totem_config.
247  */
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)
250 {
251  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
252  char *str;
253  int val;
254 
255  str = NULL;
256  val = default_value;
257 
258  if ((deleted_key != NULL && strcmp(deleted_key, key_name) == 0) ||
259  (icmap_get_string(key_name, &str) != CS_OK)) {
260  /*
261  * Do nothing. str is NULL (icmap_get_string ether not called or
262  * not changed str).
263  */
264  } else {
265  if (strcmp(str, "yes") == 0) {
266  val = 1;
267  } else if (strcmp(str, "no") == 0) {
268  val = 0;
269  }
270  free(str);
271  }
272 
273  /*
274  * Store totem_config value to cmap runtime section
275  */
276  if (strlen("runtime.config.") + strlen(key_name) >= ICMAP_KEYNAME_MAXLEN) {
277  /*
278  * This shouldn't happen
279  */
280  return ;
281  }
282 
283  strcpy(runtime_key_name, "runtime.config.");
284  strcat(runtime_key_name, key_name);
285 
286  *(uint32_t *)totem_get_param_by_name(totem_config, key_name) = val;
287 
288  icmap_set_uint32(runtime_key_name, val);
289 }
290 
291 /*
292  * Read and validate config values from cmap and store them into totem_config. If key doesn't exists,
293  * default value is stored. deleted_key is name of key beeing processed by delete operation
294  * from cmap. It is considered as non existing even if it can be read. Can be NULL.
295  */
296 static void totem_volatile_config_read (struct totem_config *totem_config, const char *deleted_key)
297 {
298  uint32_t u32;
299 
300  totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmits_before_loss_const", deleted_key,
302 
303  totem_volatile_config_set_uint32_value(totem_config, "totem.token", deleted_key, TOKEN_TIMEOUT, 0);
304 
305  totem_volatile_config_set_uint32_value(totem_config, "totem.token_warning", deleted_key, TOKEN_WARNING, 1);
306 
307  if (totem_config->interfaces[0].member_count > 2) {
308  u32 = TOKEN_COEFFICIENT;
309  icmap_get_uint32("totem.token_coefficient", &u32);
310  totem_config->token_timeout += (totem_config->interfaces[0].member_count - 2) * u32;
311 
312  /*
313  * Store totem_config value to cmap runtime section
314  */
315  icmap_set_uint32("runtime.config.totem.token", totem_config->token_timeout);
316  }
317 
318  totem_volatile_config_set_uint32_value(totem_config, "totem.max_network_delay", deleted_key, MAX_NETWORK_DELAY, 0);
319 
320  totem_volatile_config_set_uint32_value(totem_config, "totem.window_size", deleted_key, WINDOW_SIZE, 0);
321 
322  totem_volatile_config_set_uint32_value(totem_config, "totem.max_messages", deleted_key, MAX_MESSAGES, 0);
323 
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);
326 
327  totem_volatile_config_set_uint32_value(totem_config, "totem.token_retransmit", deleted_key,
328  (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)), 0);
329 
330  totem_volatile_config_set_uint32_value(totem_config, "totem.hold", deleted_key,
331  (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)), 0);
332 
333  totem_volatile_config_set_uint32_value(totem_config, "totem.join", deleted_key, JOIN_TIMEOUT, 0);
334 
335  totem_volatile_config_set_uint32_value(totem_config, "totem.consensus", deleted_key,
336  (int)(float)(1.2 * totem_config->token_timeout), 0);
337 
338  totem_volatile_config_set_uint32_value(totem_config, "totem.merge", deleted_key, MERGE_TIMEOUT, 0);
339 
340  totem_volatile_config_set_uint32_value(totem_config, "totem.downcheck", deleted_key, DOWNCHECK_TIMEOUT, 0);
341 
342  totem_volatile_config_set_uint32_value(totem_config, "totem.fail_recv_const", deleted_key, FAIL_TO_RECV_CONST, 0);
343 
344  totem_volatile_config_set_uint32_value(totem_config, "totem.seqno_unchanged_const", deleted_key,
346 
347  totem_volatile_config_set_uint32_value(totem_config, "totem.send_join", deleted_key, 0, 1);
348 
349  totem_volatile_config_set_uint32_value(totem_config, "totem.heartbeat_failures_allowed", deleted_key, 0, 1);
350 
351  totem_volatile_config_set_uint32_value(totem_config, "totem.knet_compression_threshold", deleted_key, 0, 1);
352 
353  totem_volatile_config_set_int32_value(totem_config, "totem.knet_compression_level", deleted_key, 0, 1);
354 
355  totem_volatile_config_set_string_value(totem_config, "totem.knet_compression_model", deleted_key, "none");
356 
357  totem_volatile_config_set_boolean_value(totem_config, "totem.block_unlisted_ips", deleted_key,
359 }
360 
361 static int totem_volatile_config_validate (
362  struct totem_config *totem_config,
363  const char **error_string)
364 {
365  static char local_error_reason[512];
366  const char *error_reason = local_error_reason;
367  char name_key[ICMAP_KEYNAME_MAXLEN];
368  char *name_str;
369  int i, num_configured, members;
370  uint32_t tmp_config_value;
371 
372  if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
373  snprintf (local_error_reason, sizeof(local_error_reason),
374  "The max_network_delay parameter (%d ms) may not be less than (%d ms).",
375  totem_config->max_network_delay, MINIMUM_TIMEOUT);
376  goto parse_error;
377  }
378 
379  if (totem_config->token_timeout < MINIMUM_TIMEOUT) {
380  snprintf (local_error_reason, sizeof(local_error_reason),
381  "The token timeout parameter (%d ms) may not be less than (%d ms).",
382  totem_config->token_timeout, MINIMUM_TIMEOUT);
383  goto parse_error;
384  }
385 
386  if (totem_config->token_warning > 100 || totem_config->token_warning < 0) {
387  snprintf (local_error_reason, sizeof(local_error_reason),
388  "The token warning parameter (%d%%) must be between 0 (disabled) and 100.",
389  totem_config->token_warning);
390  goto parse_error;
391  }
392 
393  if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) {
394  if (icmap_get_uint32("totem.token_retransmit", &tmp_config_value) == CS_OK) {
395  snprintf (local_error_reason, sizeof(local_error_reason),
396  "The token retransmit timeout parameter (%d ms) may not be less than (%d ms).",
398  goto parse_error;
399  } else {
400  snprintf (local_error_reason, sizeof(local_error_reason),
401  "Not appropriate token or token_retransmits_before_loss_const value set");
402  goto parse_error;
403  }
404  }
405 
406  if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT_HOLD) {
407  snprintf (local_error_reason, sizeof(local_error_reason),
408  "The token hold timeout parameter (%d ms) may not be less than (%d ms).",
410  goto parse_error;
411  }
412 
413  if (totem_config->join_timeout < MINIMUM_TIMEOUT) {
414  snprintf (local_error_reason, sizeof(local_error_reason),
415  "The join timeout parameter (%d ms) may not be less than (%d ms).",
416  totem_config->join_timeout, MINIMUM_TIMEOUT);
417  goto parse_error;
418  }
419 
420  if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) {
421  snprintf (local_error_reason, sizeof(local_error_reason),
422  "The consensus timeout parameter (%d ms) may not be less than (%d ms).",
423  totem_config->consensus_timeout, MINIMUM_TIMEOUT);
424  goto parse_error;
425  }
426 
427  if (totem_config->consensus_timeout < totem_config->join_timeout) {
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).",
430  totem_config->consensus_timeout, totem_config->join_timeout);
431  goto parse_error;
432  }
433 
434  if (totem_config->merge_timeout < MINIMUM_TIMEOUT) {
435  snprintf (local_error_reason, sizeof(local_error_reason),
436  "The merge timeout parameter (%d ms) may not be less than (%d ms).",
437  totem_config->merge_timeout, MINIMUM_TIMEOUT);
438  goto parse_error;
439  }
440 
441  if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) {
442  snprintf (local_error_reason, sizeof(local_error_reason),
443  "The downcheck timeout parameter (%d ms) may not be less than (%d ms).",
444  totem_config->downcheck_timeout, MINIMUM_TIMEOUT);
445  goto parse_error;
446  }
447 
448  /* Check that we have nodelist 'name' if there is more than one link */
449  num_configured = 0;
450  members = -1;
451  for (i = 0; i < INTERFACE_MAX; i++) {
452  if (totem_config->interfaces[i].configured) {
453  if (num_configured == 0) {
454  members = totem_config->interfaces[i].member_count;
455  }
456  num_configured++;
457  }
458  }
459 
460  if (num_configured > 1) {
461  /*
462  * This assert is here just to make compiler happy
463  */
464  assert(members != -1);
465  for (i=0; i < members; i++) {
466  snprintf(name_key, sizeof(name_key), "nodelist.node.%d.name", i);
467 
468  if (icmap_get_string(name_key, &name_str) != CS_OK) {
469  snprintf (local_error_reason, sizeof(local_error_reason),
470  "for a multi-link configuration, all nodes must have a 'name' attribute");
471  goto parse_error;
472  }
473  }
474 
475  for (i=0; i < INTERFACE_MAX; i++) {
476  if (!totem_config->interfaces[i].configured) {
477  continue;
478  }
479  if (totem_config->interfaces[i].member_count != members) {
480  snprintf (local_error_reason, sizeof(local_error_reason),
481  "Not all nodes have the same number of links");
482  goto parse_error;
483  }
484  }
485 
486 
487 
488  }
489 
490  return 0;
491 
492 parse_error:
493  snprintf (error_string_response, sizeof(error_string_response),
494  "parse error in config: %s\n", error_reason);
495  *error_string = error_string_response;
496  return (-1);
497 
498 }
499 
500 static int totem_get_crypto(struct totem_config *totem_config, const char **error_string)
501 {
502  char *str;
503  const char *tmp_cipher;
504  const char *tmp_hash;
505  const char *tmp_model;
506 
507  tmp_hash = "none";
508  tmp_cipher = "none";
509  tmp_model = "none";
510 
511  if (icmap_get_string("totem.crypto_model", &str) == CS_OK) {
512  if (strcmp(str, "nss") == 0) {
513  tmp_model = "nss";
514  }
515  if (strcmp(str, "openssl") == 0) {
516  tmp_model = "openssl";
517  }
518  free(str);
519  } else {
520  tmp_model = "nss";
521  }
522 
523  if (icmap_get_string("totem.secauth", &str) == CS_OK) {
524  if (strcmp(str, "on") == 0) {
525  tmp_cipher = "aes256";
526  tmp_hash = "sha256";
527  }
528  free(str);
529  }
530 
531  if (icmap_get_string("totem.crypto_cipher", &str) == CS_OK) {
532  if (strcmp(str, "none") == 0) {
533  tmp_cipher = "none";
534  }
535  if (strcmp(str, "aes256") == 0) {
536  tmp_cipher = "aes256";
537  }
538  if (strcmp(str, "aes192") == 0) {
539  tmp_cipher = "aes192";
540  }
541  if (strcmp(str, "aes128") == 0) {
542  tmp_cipher = "aes128";
543  }
544  free(str);
545  }
546 
547  if (icmap_get_string("totem.crypto_hash", &str) == CS_OK) {
548  if (strcmp(str, "none") == 0) {
549  tmp_hash = "none";
550  }
551  if (strcmp(str, "md5") == 0) {
552  tmp_hash = "md5";
553  }
554  if (strcmp(str, "sha1") == 0) {
555  tmp_hash = "sha1";
556  }
557  if (strcmp(str, "sha256") == 0) {
558  tmp_hash = "sha256";
559  }
560  if (strcmp(str, "sha384") == 0) {
561  tmp_hash = "sha384";
562  }
563  if (strcmp(str, "sha512") == 0) {
564  tmp_hash = "sha512";
565  }
566  free(str);
567  }
568 
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";
572  return -1;
573  }
574 
575  if (strcmp(tmp_model, "none") == 0) {
576  *error_string = "crypto_model should be 'nss' or 'openssl'";
577  return -1;
578  }
579 
580  free(totem_config->crypto_cipher_type);
581  free(totem_config->crypto_hash_type);
582  free(totem_config->crypto_model);
583 
584  totem_config->crypto_cipher_type = strdup(tmp_cipher);
585  totem_config->crypto_hash_type = strdup(tmp_hash);
586  totem_config->crypto_model = strdup(tmp_model);
587 
588  return 0;
589 }
590 
591 static int nodelist_byname(const char *find_name, int strip_domain)
592 {
593  icmap_iter_t iter;
594  const char *iter_key;
595  char name_str[ICMAP_KEYNAME_MAXLEN];
596  int res = 0;
597  unsigned int node_pos;
598  char *name;
599  unsigned int namelen;
600 
601  iter = icmap_iter_init("nodelist.node.");
602  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
603  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
604  if (res != 2) {
605  continue;
606  }
607  /* ring0_addr is allowed as a fallback */
608  if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
609  continue;
610  }
611  if (icmap_get_string(iter_key, &name) != CS_OK) {
612  continue;
613  }
614  namelen = strlen(name);
615 
616  if (strip_domain) {
617  char *dot;
618  dot = strchr(name, '.');
619  if (dot) {
620  namelen = name - dot - 1;
621  }
622  }
623  if (strncmp(find_name, name, namelen) == 0 &&
624  strlen(find_name) == strlen(name)) {
625  icmap_iter_finalize(iter);
626  return node_pos;
627  }
628  }
629  icmap_iter_finalize(iter);
630  return -1;
631 }
632 
633 /* Compare two addresses - only address part (sin_addr/sin6_addr) is checked */
634 static int ipaddr_equal(const struct sockaddr *addr1, const struct sockaddr *addr2)
635 {
636  int addrlen = 0;
637  const void *addr1p, *addr2p;
638 
639  if (addr1->sa_family != addr2->sa_family)
640  return 0;
641 
642  switch (addr1->sa_family) {
643  case AF_INET:
644  addrlen = sizeof(struct in_addr);
645  addr1p = &((struct sockaddr_in *)addr1)->sin_addr;
646  addr2p = &((struct sockaddr_in *)addr2)->sin_addr;
647  break;
648  case AF_INET6:
649  addrlen = sizeof(struct in6_addr);
650  addr1p = &((struct sockaddr_in6 *)addr1)->sin6_addr;
651  addr2p = &((struct sockaddr_in6 *)addr2)->sin6_addr;
652  break;
653  default:
654  assert(0);
655  }
656 
657  return (memcmp(addr1p, addr2p, addrlen) == 0);
658 }
659 
660 
661 /* Finds the local node and returns its position in the nodelist.
662  * Uses nodelist.local_node_pos as a cache to save effort
663  */
664 static int find_local_node(int use_cache)
665 {
666  char nodename2[PATH_MAX];
667  char name_str[ICMAP_KEYNAME_MAXLEN];
668  icmap_iter_t iter;
669  const char *iter_key;
670  unsigned int cached_pos;
671  char *dot = NULL;
672  const char *node;
673  struct ifaddrs *ifa, *ifa_list;
674  struct sockaddr *sa;
675  int found = 0;
676  int node_pos = -1;
677  int res;
678  struct utsname utsname;
679 
680  /* Check for cached value first */
681  if (use_cache) {
682  if (icmap_get_uint32("nodelist.local_node_pos", &cached_pos) == CS_OK) {
683  return cached_pos;
684  }
685  }
686 
687  res = uname(&utsname);
688  if (res) {
689  return -1;
690  }
691  node = utsname.nodename;
692 
693  /* 1. Exact match */
694  node_pos = nodelist_byname(node, 0);
695  if (node_pos > -1) {
696  found = 1;
697  goto ret_found;
698  }
699 
700  /* 2. Try to match with increasingly more
701  * specific versions of it
702  */
703  strcpy(nodename2, node);
704  dot = strrchr(nodename2, '.');
705  while (dot) {
706  *dot = '\0';
707 
708  node_pos = nodelist_byname(nodename2, 0);
709  if (node_pos > -1) {
710  found = 1;
711  goto ret_found;
712  }
713  dot = strrchr(nodename2, '.');
714  }
715 
716  node_pos = nodelist_byname(nodename2, 1);
717  if (node_pos > -1) {
718  found = 1;
719  goto ret_found;
720  }
721 
722  /*
723  * The corosync.conf name may not be related to uname at all,
724  * they may match a hostname on some network interface.
725  */
726  if (getifaddrs(&ifa_list))
727  return -1;
728 
729  for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
730  socklen_t salen = 0;
731 
732  /* Restore this */
733  strcpy(nodename2, node);
734  sa = ifa->ifa_addr;
735  if (!sa) {
736  continue;
737  }
738  if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6) {
739  continue;
740  }
741 
742  if (sa->sa_family == AF_INET) {
743  salen = sizeof(struct sockaddr_in);
744  }
745  if (sa->sa_family == AF_INET6) {
746  salen = sizeof(struct sockaddr_in6);
747  }
748 
749  if (getnameinfo(sa, salen,
750  nodename2, sizeof(nodename2),
751  NULL, 0, 0) == 0) {
752 
753  node_pos = nodelist_byname(nodename2, 0);
754  if (node_pos > -1) {
755  found = 1;
756  goto out;
757  }
758 
759  /* Truncate this name and try again */
760  dot = strchr(nodename2, '.');
761  if (dot) {
762  *dot = '\0';
763 
764  node_pos = nodelist_byname(nodename2, 0);
765  if (node_pos > -1) {
766  found = 1;
767  goto out;
768  }
769  }
770  }
771 
772  /* See if it's the IP address that's in corosync.conf */
773  if (getnameinfo(sa, sizeof(*sa),
774  nodename2, sizeof(nodename2),
775  NULL, 0, NI_NUMERICHOST))
776  continue;
777 
778  node_pos = nodelist_byname(nodename2, 0);
779  if (node_pos > -1) {
780  found = 1;
781  goto out;
782  }
783  }
784 
785  out:
786  if (found) {
787  freeifaddrs(ifa_list);
788  goto ret_found;
789  }
790 
791  /*
792  * This section covers the usecase where the nodename specified in cluster.conf
793  * is an alias specified in /etc/hosts. For example:
794  * <ipaddr> hostname alias1 alias2
795  * and <clusternode name="alias2">
796  * the above calls use uname and getnameinfo does not return aliases.
797  * here we take the name specified in cluster.conf, resolve it to an address
798  * and then compare against all known local ip addresses.
799  * if we have a match, we found our nodename. In theory this chunk of code
800  * could replace all the checks above, but let's avoid any possible regressions
801  * and use it as last.
802  */
803 
804  iter = icmap_iter_init("nodelist.node.");
805  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
806  char *dbnodename = NULL;
807  struct addrinfo hints;
808  struct addrinfo *result = NULL, *rp = NULL;
809 
810  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, name_str);
811  if (res != 2) {
812  continue;
813  }
814  /* 'ring0_addr' is allowed as a fallback, but 'name' will be found first
815  * because the names are in alpha order.
816  */
817  if (strcmp(name_str, "name") && strcmp(name_str, "ring0_addr")) {
818  continue;
819  }
820  if (icmap_get_string(iter_key, &dbnodename) != CS_OK) {
821  continue;
822  }
823 
824  memset(&hints, 0, sizeof(struct addrinfo));
825  hints.ai_family = AF_UNSPEC;
826  hints.ai_socktype = SOCK_DGRAM;
827  hints.ai_flags = 0;
828  hints.ai_protocol = IPPROTO_UDP;
829 
830  if (getaddrinfo(dbnodename, NULL, &hints, &result)) {
831  continue;
832  }
833 
834  for (rp = result; rp != NULL; rp = rp->ai_next) {
835  for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
836  if (ifa->ifa_addr &&
837  ipaddr_equal(rp->ai_addr, ifa->ifa_addr)) {
838  freeaddrinfo(result);
839  found = 1;
840  goto out2;
841  }
842  }
843  }
844 
845  freeaddrinfo(result);
846  }
847 out2:
848  icmap_iter_finalize(iter);
849  freeifaddrs(ifa_list);
850 
851 ret_found:
852  if (found) {
853  res = icmap_set_uint32("nodelist.local_node_pos", node_pos);
854  }
855 
856  return node_pos;
857 }
858 
859 static enum totem_ip_version_enum totem_config_get_ip_version(struct totem_config *totem_config)
860 {
861  enum totem_ip_version_enum res;
862  char *str;
863 
864  res = TOTEM_IP_VERSION_6_4;
865 
866  if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
867  res = TOTEM_IP_VERSION_4;
868  }
869 
870  if (icmap_get_string("totem.ip_version", &str) == CS_OK) {
871  if (strcmp(str, "ipv4") == 0) {
872  res = TOTEM_IP_VERSION_4;
873  }
874  if (strcmp(str, "ipv6") == 0) {
875  res = TOTEM_IP_VERSION_6;
876  }
877  if (strcmp(str, "ipv6-4") == 0) {
878  res = TOTEM_IP_VERSION_6_4;
879  }
880  if (strcmp(str, "ipv4-6") == 0) {
881  res = TOTEM_IP_VERSION_4_6;
882  }
883  free(str);
884  }
885 
886  return (res);
887 }
888 
889 static uint16_t generate_cluster_id (const char *cluster_name)
890 {
891  int i;
892  int value = 0;
893 
894  for (i = 0; i < strlen(cluster_name); i++) {
895  value <<= 1;
896  value += cluster_name[i];
897  }
898 
899  return (value & 0xFFFF);
900 }
901 
902 static int get_cluster_mcast_addr (
903  const char *cluster_name,
904  unsigned int linknumber,
905  enum totem_ip_version_enum ip_version,
906  struct totem_ip_address *res)
907 {
908  uint16_t clusterid;
909  char addr[INET6_ADDRSTRLEN + 1];
910  int err;
911 
912  if (cluster_name == NULL) {
913  return (-1);
914  }
915 
916  clusterid = generate_cluster_id(cluster_name) + linknumber;
917  memset (res, 0, sizeof(*res));
918 
919  switch (ip_version) {
920  case TOTEM_IP_VERSION_4:
922  snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
923  break;
924  case TOTEM_IP_VERSION_6:
926  snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
927  break;
928  default:
929  /*
930  * Unknown family
931  */
932  return (-1);
933  }
934 
935  err = totemip_parse (res, addr, ip_version);
936 
937  return (err);
938 }
939 
940 static unsigned int generate_nodeid(
941  struct totem_config *totem_config,
942  char *addr)
943 {
944  unsigned int nodeid;
945  struct totem_ip_address totemip;
946 
947  /* AF_INET hard-coded here because auto-generated nodeids
948  are only for IPv4 */
949  if (totemip_parse(&totemip, addr, TOTEM_IP_VERSION_4) != 0)
950  return -1;
951 
952  memcpy (&nodeid, &totemip.addr, sizeof (unsigned int));
953 
954 #if __BYTE_ORDER == __LITTLE_ENDIAN
955  nodeid = swab32 (nodeid);
956 #endif
957 
958  if (totem_config->clear_node_high_bit) {
959  nodeid &= 0x7FFFFFFF;
960  }
961  return nodeid;
962 }
963 
964 static int check_for_duplicate_nodeids(
965  struct totem_config *totem_config,
966  const char **error_string)
967 {
968  icmap_iter_t iter;
969  icmap_iter_t subiter;
970  const char *iter_key;
971  int res = 0;
972  int retval = 0;
973  char tmp_key[ICMAP_KEYNAME_MAXLEN];
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;
979  unsigned int nodeid;
980  unsigned int nodeid1;
981  int autogenerated;
982 
983  iter = icmap_iter_init("nodelist.node.");
984  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
985  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
986  if (res != 2) {
987  continue;
988  }
989 
990  /*
991  * This relies on the fact the icmap keys are always returned in order
992  * so all of the keys for a node will be grouped together. We're basically
993  * just running the code below once for each node.
994  */
995  if (last_node_pos == node_pos) {
996  continue;
997  }
998  last_node_pos = node_pos;
999 
1000  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
1001  autogenerated = 0;
1002 
1003  /* Generated nodeids are only allowed for UDP/UDPU so ring0_addr is valid here */
1004  if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
1005 
1006  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
1007  if (icmap_get_string(tmp_key, &ring0_addr) != CS_OK) {
1008  continue;
1009  }
1010 
1011  /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
1012  nodeid = generate_nodeid(totem_config, ring0_addr);
1013  if (nodeid == -1) {
1014  continue;
1015  }
1016  autogenerated = 1;
1017  }
1018 
1019  node_pos1 = 0;
1020  subiter = icmap_iter_init("nodelist.node.");
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)) {
1024  continue;
1025  }
1026 
1027  if (strcmp(tmp_key, "nodeid") != 0) {
1028  continue;
1029  }
1030 
1031  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
1032  if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
1033 
1034  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos1);
1035  if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
1036  continue;
1037  }
1038  nodeid1 = generate_nodeid(totem_config, ring0_addr1);
1039  if (nodeid1 == -1) {
1040  continue;
1041  }
1042  }
1043 
1044  if (nodeid == nodeid1) {
1045  retval = -1;
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?")":"");
1051  log_printf (LOGSYS_LEVEL_ERROR, error_string_response);
1052  *error_string = error_string_response;
1053  break;
1054  }
1055  }
1056  icmap_iter_finalize(subiter);
1057  }
1058  icmap_iter_finalize(iter);
1059  return retval;
1060 }
1061 
1062 
1063 /*
1064  * This needs to be done last of all. It would be nice to do it when reading the
1065  * interface params, but the totem params need to have them to be read first. We
1066  * need both, so this is a way round that circular dependancy.
1067  */
1068 static void calc_knet_ping_timers(struct totem_config *totem_config)
1069 {
1070  char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
1071  int interface;
1072 
1073  for (interface = 0; interface < INTERFACE_MAX; interface++) {
1074 
1075  if (totem_config->interfaces[interface].configured) {
1076  if (!totem_config->interfaces[interface].knet_pong_count) {
1077  totem_config->interfaces[interface].knet_pong_count = KNET_PONG_COUNT;
1078  }
1079  if (!totem_config->interfaces[interface].knet_ping_timeout) {
1080  totem_config->interfaces[interface].knet_ping_timeout =
1081  totem_config->token_timeout / totem_config->interfaces[interface].knet_pong_count;
1082  }
1083  snprintf(runtime_key_name, sizeof(runtime_key_name),
1084  "runtime.config.totem.interface.%d.knet_ping_timeout", interface);
1085  icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_timeout);
1086 
1087  if (!totem_config->interfaces[interface].knet_ping_interval) {
1088  totem_config->interfaces[interface].knet_ping_interval =
1089  totem_config->token_timeout / (totem_config->interfaces[interface].knet_pong_count * 2);
1090  }
1091  snprintf(runtime_key_name, sizeof(runtime_key_name),
1092  "runtime.config.totem.interface.%d.knet_ping_interval", interface);
1093  icmap_set_uint32(runtime_key_name, totem_config->interfaces[interface].knet_ping_interval);
1094  }
1095  }
1096 }
1097 
1098 /*
1099  * Compute difference between two set of totem interface arrays. set1 and set2
1100  * are changed so for same ring, ip existing in both set1 and set2 are cleared
1101  * (set to 0), and ips which are only in set1 or set2 remains untouched.
1102  * totempg_node_add/remove is called.
1103  */
1104 static void compute_interfaces_diff(struct totem_interface *set1,
1105  struct totem_interface *set2)
1106 {
1107  int ring_no, set1_pos, set2_pos;
1108  struct totem_ip_address empty_ip_address;
1109 
1110  memset(&empty_ip_address, 0, sizeof(empty_ip_address));
1111 
1112  for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
1113  if (!set1[ring_no].configured && !set2[ring_no].configured) {
1114  continue;
1115  }
1116 
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++) {
1119  /*
1120  * For current ring_no remove all set1 items existing
1121  * in set2
1122  */
1123  if (memcmp(&set1[ring_no].member_list[set1_pos],
1124  &set2[ring_no].member_list[set2_pos],
1125  sizeof(struct totem_ip_address)) == 0) {
1126  memset(&set1[ring_no].member_list[set1_pos], 0,
1127  sizeof(struct totem_ip_address));
1128  memset(&set2[ring_no].member_list[set2_pos], 0,
1129  sizeof(struct totem_ip_address));
1130  }
1131  }
1132  }
1133  }
1134 
1135  for (ring_no = 0; ring_no < INTERFACE_MAX; ring_no++) {
1136  for (set1_pos = 0; set1_pos < set1[ring_no].member_count; set1_pos++) {
1137  /*
1138  * All items which remained in set1 doesn't exists in set2 any longer so
1139  * node has to be removed.
1140  */
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",
1144  totemip_print(&set1[ring_no].member_list[set1_pos]),
1145  ring_no);
1146 
1147  totempg_member_remove(&set1[ring_no].member_list[set1_pos], ring_no);
1148  }
1149  }
1150  if (!set2[ring_no].configured) {
1151  continue;
1152  }
1153  for (set2_pos = 0; set2_pos < set2[ring_no].member_count; set2_pos++) {
1154  /*
1155  * All items which remained in set2 doesn't existed in set1 so this is no node
1156  * and has to be added.
1157  */
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",
1161  totemip_print(&set2[ring_no].member_list[set2_pos]),
1162  ring_no);
1163 
1164  totempg_member_add(&set2[ring_no].member_list[set2_pos], ring_no);
1165  }
1166  }
1167  }
1168 }
1169 
1170 /*
1171  * Reconfigure links in totempg. Sets new local IP address and adds params for new links.
1172  */
1173 static void reconfigure_links(struct totem_config *totem_config)
1174 {
1175  int i;
1176  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1177  char *addr_string;
1178  struct totem_ip_address local_ip;
1179  int err;
1180  int local_node_pos = find_local_node(0);
1181 
1182  for (i = 0; i<INTERFACE_MAX; i++) {
1183  if (!totem_config->interfaces[i].configured) {
1184  continue;
1185  }
1186 
1187  log_printf(LOGSYS_LEVEL_INFO, "Configuring link %d\n", i);
1188 
1189  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring%u_addr", local_node_pos, i);
1190  if (icmap_get_string(tmp_key, &addr_string) != CS_OK) {
1191  continue;
1192  }
1193 
1194  err = totemip_parse(&local_ip, addr_string, totem_config->ip_version);
1195  if (err != 0) {
1196  continue;
1197  }
1198  local_ip.nodeid = totem_config->node_id;
1199 
1200  /* In case this is a new link, fill in the defaults if there was no interface{} section for it */
1201  if (!totem_config->interfaces[i].knet_link_priority)
1202  totem_config->interfaces[i].knet_link_priority = 1;
1203 
1204  /* knet_ping_interval & knet_ping_timeout are set later once we know all the other params */
1205 
1206  if (!totem_config->interfaces[i].knet_ping_precision)
1208  if (!totem_config->interfaces[i].knet_pong_count)
1209  totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
1210  if (!totem_config->interfaces[i].knet_transport)
1211  totem_config->interfaces[i].knet_transport = KNET_TRANSPORT_UDP;
1212  if (!totem_config->interfaces[i].ip_port)
1213  totem_config->interfaces[i].ip_port = DEFAULT_PORT + i;
1214 
1215  totempg_iface_set(&local_ip, totem_config->interfaces[i].ip_port, i);
1216  }
1217 }
1218 
1219 /* Check for differences in config that can't be done on-the-fly and print an error */
1220 static void check_things_have_not_changed(struct totem_config *totem_config)
1221 {
1222  int i,j;
1223  const char *ip_str;
1224  char addr_buf[INET6_ADDRSTRLEN];
1225  int changed = 0;
1226 
1227  for (i = 0; i<INTERFACE_MAX; i++) {
1228  if (totem_config->interfaces[i].configured &&
1229  totem_config->orig_interfaces[i].configured) {
1230  if (totem_config->interfaces[i].knet_transport !=
1231  totem_config->orig_interfaces[i].knet_transport) {
1233  "New config has different knet transport for link %d. Internal value was NOT changed.\n", i);
1234  changed = 1;
1235  }
1236  for (j=0; j < min(totem_config->interfaces[i].member_count, totem_config->orig_interfaces[i].member_count); j++) {
1237  if (memcmp(&totem_config->interfaces[i].member_list[j],
1238  &totem_config->orig_interfaces[i].member_list[j],
1239  sizeof(struct totem_ip_address))) {
1240 
1241  ip_str = totemip_print(&totem_config->orig_interfaces[i].member_list[j]);
1242 
1243  /* if ip_str is NULL then the old address was invalid and is allowed to change */
1244  if (ip_str) {
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",
1249  i, addr_buf, totemip_print(&totem_config->interfaces[i].member_list[j]));
1250  changed = 1;
1251  }
1252  }
1253  }
1254  }
1255  }
1256 
1257  if (changed) {
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");
1259  }
1260 }
1261 
1262 
1263 static int put_nodelist_members_to_config(struct totem_config *totem_config, int reload, const char **error_string)
1264 {
1265  icmap_iter_t iter, iter2;
1266  const char *iter_key, *iter_key2;
1267  int res = 0;
1268  unsigned int node_pos;
1269  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1270  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
1271  char *node_addr_str;
1272  int member_count;
1273  unsigned int linknumber = 0;
1274  int i, j;
1275  int last_node_pos = -1;
1276  struct totem_interface *new_interfaces = NULL;
1277 
1278  if (reload) {
1279  /*
1280  * We need to compute diff only for reload. Also for initial configuration
1281  * not all totem structures are initialized so corosync will crash during
1282  * member_add/remove
1283  */
1284  new_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
1285  assert(new_interfaces != NULL);
1286  }
1287 
1288  /* Clear out nodelist so we can put the new one in if needed */
1289  for (i = 0; i < INTERFACE_MAX; i++) {
1290  for (j = 0; j < PROCESSOR_COUNT_MAX; j++) {
1291  memset(&totem_config->interfaces[i].member_list[j], 0, sizeof(struct totem_ip_address));
1292  }
1293  totem_config->interfaces[i].member_count = 0;
1294  }
1295 
1296  iter = icmap_iter_init("nodelist.node.");
1297  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1298  res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
1299  if (res != 2) {
1300  continue;
1301  }
1302  /* If it's the same as the last node_pos then skip it */
1303  if (node_pos == last_node_pos) {
1304  continue;
1305  }
1306  last_node_pos = node_pos;
1307 
1308  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
1309  iter2 = icmap_iter_init(tmp_key);
1310  while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
1311  unsigned int nodeid;
1312  char *str;
1313 
1314  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
1315  if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
1316  nodeid = 0;
1317  }
1318 
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) {
1321  continue;
1322  }
1323 
1324  if (icmap_get_string(iter_key2, &node_addr_str) != CS_OK) {
1325  continue;
1326  }
1327 
1328  /* Generate nodeids if they are not provided and transport is UDP/U */
1329  if (!nodeid &&
1330  (totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
1331  totem_config->transport_number == TOTEM_TRANSPORT_UDPU)) {
1332  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
1333  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1334  nodeid = generate_nodeid(totem_config, str);
1335  if (nodeid == -1) {
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;
1340  free(str);
1341 
1342  return (-1);
1343  }
1344 
1346  "Generated nodeid = " CS_PRI_NODE_ID " for %s", nodeid, str);
1347  free(str);
1348  }
1349  }
1350 
1351  member_count = totem_config->interfaces[linknumber].member_count;
1352  res = totemip_parse(&totem_config->interfaces[linknumber].member_list[member_count],
1353  node_addr_str, totem_config->ip_version);
1354  if (res == 0) {
1355  totem_config->interfaces[linknumber].member_list[member_count].nodeid = nodeid;
1356  totem_config->interfaces[linknumber].member_count++;
1357  totem_config->interfaces[linknumber].configured = 1;
1358  } else {
1359  sprintf(error_string_response, "failed to parse node address '%s'\n", node_addr_str);
1360  *error_string = error_string_response;
1361 
1362  memset(&totem_config->interfaces[linknumber].member_list[member_count], 0,
1363  sizeof(struct totem_ip_address));
1364 
1365  free(node_addr_str);
1366  icmap_iter_finalize(iter2);
1367  icmap_iter_finalize(iter);
1368  return -1;
1369  }
1370 
1371  free(node_addr_str);
1372  }
1373 
1374  icmap_iter_finalize(iter2);
1375  }
1376 
1377  icmap_iter_finalize(iter);
1378 
1379  if (reload) {
1380  log_printf(LOGSYS_LEVEL_DEBUG, "About to reconfigure links from nodelist.\n");
1381  reconfigure_links(totem_config);
1382 
1383  memcpy(new_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
1384 
1385  check_things_have_not_changed(totem_config);
1386 
1387  compute_interfaces_diff(totem_config->orig_interfaces, new_interfaces);
1388 
1389  free(new_interfaces);
1390  }
1391  return 0;
1392 }
1393 
1394 static void config_convert_nodelist_to_interface(struct totem_config *totem_config)
1395 {
1396  int res = 0;
1397  int node_pos;
1398  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1399  char tmp_key2[ICMAP_KEYNAME_MAXLEN];
1400  char *node_addr_str;
1401  unsigned int linknumber = 0;
1402  icmap_iter_t iter;
1403  const char *iter_key;
1404 
1405  node_pos = find_local_node(1);
1406  if (node_pos > -1) {
1407  /*
1408  * We found node, so create interface section
1409  */
1410  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
1411  iter = icmap_iter_init(tmp_key);
1412  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
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) {
1415  continue ;
1416  }
1417 
1418  if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) {
1419  continue;
1420  }
1421 
1422  snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
1423  icmap_set_string(tmp_key2, node_addr_str);
1424  free(node_addr_str);
1425  }
1426  icmap_iter_finalize(iter);
1427  }
1428 }
1429 
1430 static int get_interface_params(struct totem_config *totem_config,
1431  const char **error_string, uint64_t *warnings,
1432  int reload)
1433 {
1434  int res = 0;
1435  unsigned int linknumber = 0;
1436  int member_count = 0;
1437  int i;
1438  icmap_iter_t iter, member_iter;
1439  const char *iter_key;
1440  const char *member_iter_key;
1441  char linknumber_key[ICMAP_KEYNAME_MAXLEN];
1442  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1443  uint8_t u8;
1444  uint32_t u32;
1445  char *str;
1446  char *cluster_name = NULL;
1447  enum totem_ip_version_enum tmp_ip_version = TOTEM_IP_VERSION_4;
1448 
1449  if (reload) {
1450  for (i=0; i<INTERFACE_MAX; i++) {
1451  /*
1452  * Set back to defaults things that might have been configured and
1453  * now have been taken out of corosync.conf. These won't be caught by the
1454  * code below which only looks at interface{} sections that actually exist.
1455  */
1456  totem_config->interfaces[i].configured = 0;
1457  totem_config->interfaces[i].knet_ping_timeout = 0;
1458  totem_config->interfaces[i].knet_ping_interval = 0;
1460  totem_config->interfaces[i].knet_pong_count = KNET_PONG_COUNT;
1461  }
1462  }
1463  if (icmap_get_string("totem.cluster_name", &cluster_name) != CS_OK) {
1464  cluster_name = NULL;
1465  }
1466 
1467  iter = icmap_iter_init("totem.interface.");
1468  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1469  res = sscanf(iter_key, "totem.interface.%[^.].%s", linknumber_key, tmp_key);
1470  if (res != 2) {
1471  continue;
1472  }
1473 
1474  if (strcmp(tmp_key, "bindnetaddr") != 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1475  continue;
1476  }
1477 
1478  member_count = 0;
1479  linknumber = atoi(linknumber_key);
1480 
1481  if (linknumber >= INTERFACE_MAX) {
1482  free(cluster_name);
1483 
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);
1487 
1488  *error_string = error_string_response;
1489  return -1;
1490  }
1491 
1492  /* These things are only valid for the initial read */
1493  if (!reload) {
1494  /*
1495  * Get the bind net address
1496  */
1497  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", linknumber);
1498 
1499  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1500  res = totemip_parse (&totem_config->interfaces[linknumber].bindnet, str,
1501  totem_config->ip_version);
1502 
1503  if (res) {
1504  sprintf(error_string_response, "failed to parse bindnet address '%s'\n", str);
1505  *error_string = error_string_response;
1506  free(str);
1507 
1508  return -1;
1509  }
1510 
1511  free(str);
1512  }
1513 
1514  /*
1515  * Get interface multicast address
1516  */
1517  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", linknumber);
1518  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1519  res = totemip_parse (&totem_config->interfaces[linknumber].mcast_addr, str,
1520  totem_config->ip_version);
1521 
1522  if (res) {
1523  sprintf(error_string_response, "failed to parse mcast address '%s'\n", str);
1524  *error_string = error_string_response;
1525  free(str);
1526 
1527  return -1;
1528  }
1529 
1530  free(str);
1531  } else if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1532  /*
1533  * User not specified address -> autogenerate one from cluster_name key
1534  * (if available). Return code is intentionally ignored, because
1535  * udpu doesn't need mcastaddr and validity of mcastaddr for udp is
1536  * checked later anyway.
1537  */
1538 
1539  if (totem_config->interfaces[0].bindnet.family == AF_INET) {
1540  tmp_ip_version = TOTEM_IP_VERSION_4;
1541  } else if (totem_config->interfaces[0].bindnet.family == AF_INET6) {
1542  tmp_ip_version = TOTEM_IP_VERSION_6;
1543  }
1544 
1545  (void)get_cluster_mcast_addr (cluster_name,
1546  linknumber,
1547  tmp_ip_version,
1548  &totem_config->interfaces[linknumber].mcast_addr);
1549  }
1550 
1551  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.broadcast", linknumber);
1552  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1553  if (strcmp (str, "yes") == 0) {
1554  totem_config->broadcast_use = 1;
1555  }
1556  free(str);
1557  }
1558  }
1559 
1560  /* These things are only valid for the initial read OR a newly-defined link */
1561  if (!reload || (totem_config->interfaces[linknumber].configured == 0)) {
1562 
1563  /*
1564  * Get mcast port
1565  */
1566  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", linknumber);
1567  if (icmap_get_uint16(tmp_key, &totem_config->interfaces[linknumber].ip_port) != CS_OK) {
1568  if (totem_config->broadcast_use) {
1569  totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + (2 * linknumber);
1570  } else {
1571  totem_config->interfaces[linknumber].ip_port = DEFAULT_PORT + linknumber;
1572  }
1573  }
1574 
1575  /*
1576  * Get the TTL
1577  */
1578  totem_config->interfaces[linknumber].ttl = 1;
1579 
1580  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.ttl", linknumber);
1581 
1582  if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
1583  totem_config->interfaces[linknumber].ttl = u8;
1584  }
1585 
1586  totem_config->interfaces[linknumber].knet_transport = KNET_DEFAULT_TRANSPORT;
1587  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_transport", linknumber);
1588  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1589  if (strcmp(str, "sctp") == 0) {
1590  totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_SCTP;
1591  }
1592  else if (strcmp(str, "udp") == 0) {
1593  totem_config->interfaces[linknumber].knet_transport = KNET_TRANSPORT_UDP;
1594  }
1595  else {
1596  *error_string = "Unrecognised knet_transport. expected 'udp' or 'sctp'";
1597  return -1;
1598  }
1599  }
1600  }
1601  totem_config->interfaces[linknumber].configured = 1;
1602 
1603  /*
1604  * Get the knet link params
1605  */
1606  totem_config->interfaces[linknumber].knet_link_priority = 1;
1607  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_link_priority", linknumber);
1608 
1609  if (icmap_get_uint8(tmp_key, &u8) == CS_OK) {
1610  totem_config->interfaces[linknumber].knet_link_priority = u8;
1611  }
1612 
1613  totem_config->interfaces[linknumber].knet_ping_interval = 0; /* real default applied later */
1614  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_interval", linknumber);
1615  if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1616  totem_config->interfaces[linknumber].knet_ping_interval = u32;
1617  }
1618  totem_config->interfaces[linknumber].knet_ping_timeout = 0; /* real default applied later */
1619  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_timeout", linknumber);
1620  if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1621  totem_config->interfaces[linknumber].knet_ping_timeout = u32;
1622  }
1623  totem_config->interfaces[linknumber].knet_ping_precision = KNET_PING_PRECISION;
1624  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_ping_precision", linknumber);
1625  if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1626  totem_config->interfaces[linknumber].knet_ping_precision = u32;
1627  }
1628  totem_config->interfaces[linknumber].knet_pong_count = KNET_PONG_COUNT;
1629  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.knet_pong_count", linknumber);
1630  if (icmap_get_uint32(tmp_key, &u32) == CS_OK) {
1631  totem_config->interfaces[linknumber].knet_pong_count = u32;
1632  }
1633 
1634  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.member.", linknumber);
1635  member_iter = icmap_iter_init(tmp_key);
1636  while ((member_iter_key = icmap_iter_next(member_iter, NULL, NULL)) != NULL) {
1637  if (member_count == 0) {
1638  if (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK) {
1639  free(str);
1641  break;
1642  } else {
1644  }
1645  }
1646 
1647  if (icmap_get_string(member_iter_key, &str) == CS_OK) {
1648  res = totemip_parse (&totem_config->interfaces[linknumber].member_list[member_count++],
1649  str, totem_config->ip_version);
1650  if (res) {
1651  sprintf(error_string_response, "failed to parse node address '%s'\n", str);
1652  *error_string = error_string_response;
1653 
1654  icmap_iter_finalize(member_iter);
1655  icmap_iter_finalize(iter);
1656  free(str);
1657  return -1;
1658  }
1659 
1660  free(str);
1661  }
1662  }
1663  icmap_iter_finalize(member_iter);
1664 
1665  totem_config->interfaces[linknumber].member_count = member_count;
1666 
1667  }
1668  icmap_iter_finalize(iter);
1669 
1670  return 0;
1671 }
1672 
1673 extern int totem_config_read (
1674  struct totem_config *totem_config,
1675  const char **error_string,
1676  uint64_t *warnings)
1677 {
1678  int res = 0;
1679  char *str, *ring0_addr_str;
1680  char tmp_key[ICMAP_KEYNAME_MAXLEN];
1681  uint16_t u16;
1682  int i;
1683  int local_node_pos;
1684  int nodeid_set;
1685 
1686  *warnings = 0;
1687 
1688  memset (totem_config, 0, sizeof (struct totem_config));
1689  totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
1690  if (totem_config->interfaces == 0) {
1691  *error_string = "Out of memory trying to allocate ethernet interface storage area";
1692  return -1;
1693  }
1694 
1695  totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1696  if (icmap_get_string("totem.transport", &str) == CS_OK) {
1697  if (strcmp (str, "udpu") == 0) {
1698  totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
1699  }
1700 
1701  if (strcmp (str, "udp") == 0) {
1702  totem_config->transport_number = TOTEM_TRANSPORT_UDP;
1703  }
1704 
1705  if (strcmp (str, "knet") == 0) {
1706  totem_config->transport_number = TOTEM_TRANSPORT_KNET;
1707  }
1708 
1709  free(str);
1710  }
1711 
1712  memset (totem_config->interfaces, 0,
1713  sizeof (struct totem_interface) * INTERFACE_MAX);
1714 
1715  strcpy (totem_config->link_mode, "passive");
1716 
1717  icmap_get_uint32("totem.version", (uint32_t *)&totem_config->version);
1718 
1719  if (totem_get_crypto(totem_config, error_string) != 0) {
1720  return -1;
1721  }
1722 
1723  if (icmap_get_string("totem.link_mode", &str) == CS_OK) {
1724  if (strlen(str) >= TOTEM_LINK_MODE_BYTES) {
1725  *error_string = "totem.link_mode is too long";
1726  free(str);
1727 
1728  return -1;
1729  }
1730  strcpy (totem_config->link_mode, str);
1731  free(str);
1732  }
1733 
1734  icmap_get_uint32("totem.nodeid", &totem_config->node_id);
1735 
1736  totem_config->clear_node_high_bit = 0;
1737  if (icmap_get_string("totem.clear_node_high_bit", &str) == CS_OK) {
1738  if (strcmp (str, "yes") == 0) {
1739  totem_config->clear_node_high_bit = 1;
1740  }
1741  free(str);
1742  }
1743 
1744  icmap_get_uint32("totem.threads", &totem_config->threads);
1745 
1746  icmap_get_uint32("totem.netmtu", &totem_config->net_mtu);
1747 
1748  totem_config->ip_version = totem_config_get_ip_version(totem_config);
1749 
1750  if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) {
1751  /*
1752  * We were not able to find ring 0 bindnet addr. Try to use nodelist informations
1753  */
1754  config_convert_nodelist_to_interface(totem_config);
1755  } else {
1756  if (icmap_get_string("nodelist.node.0.ring0_addr", &ring0_addr_str) == CS_OK) {
1757  /*
1758  * Both bindnetaddr and ring0_addr are set.
1759  * Log warning information, and use nodelist instead
1760  */
1762 
1763  config_convert_nodelist_to_interface(totem_config);
1764 
1765  free(ring0_addr_str);
1766  }
1767 
1768  free(str);
1769  }
1770 
1771  /*
1772  * Broadcast option is global but set in interface section,
1773  * so reset before processing interfaces.
1774  */
1775  totem_config->broadcast_use = 0;
1776 
1777  res = get_interface_params(totem_config, error_string, warnings, 0);
1778  if (res < 0) {
1779  return res;
1780  }
1781 
1782  /*
1783  * Use broadcast is global, so if set, make sure to fill mcast addr correctly
1784  * broadcast is only supported for UDP so just do interface 0;
1785  */
1786  if (totem_config->broadcast_use) {
1787  totemip_parse (&totem_config->interfaces[0].mcast_addr,
1788  "255.255.255.255", TOTEM_IP_VERSION_4);
1789  }
1790 
1791 
1792  /*
1793  * Store automatically generated items back to icmap only for UDP
1794  */
1795  if (totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1796  for (i = 0; i < INTERFACE_MAX; i++) {
1797  if (!totem_config->interfaces[i].configured) {
1798  continue;
1799  }
1800  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastaddr", i);
1801  if (icmap_get_string(tmp_key, &str) == CS_OK) {
1802  free(str);
1803  } else {
1804  str = (char *)totemip_print(&totem_config->interfaces[i].mcast_addr);
1805  icmap_set_string(tmp_key, str);
1806  }
1807 
1808  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.mcastport", i);
1809  if (icmap_get_uint16(tmp_key, &u16) != CS_OK) {
1810  icmap_set_uint16(tmp_key, totem_config->interfaces[i].ip_port);
1811  }
1812  }
1813  }
1814 
1815  /*
1816  * Check existence of nodelist
1817  */
1818  if ((icmap_get_string("nodelist.node.0.name", &str) == CS_OK) ||
1819  (icmap_get_string("nodelist.node.0.ring0_addr", &str) == CS_OK)) {
1820  free(str);
1821  /*
1822  * find local node
1823  */
1824  local_node_pos = find_local_node(1);
1825  if (local_node_pos != -1) {
1826 
1827  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", local_node_pos);
1828 
1829  nodeid_set = (totem_config->node_id != 0);
1830  if (icmap_get_uint32(tmp_key, &totem_config->node_id) == CS_OK && nodeid_set) {
1832  }
1833  if ((totem_config->transport_number == TOTEM_TRANSPORT_KNET) && (!totem_config->node_id)) {
1834  *error_string = "Knet requires an explicit nodeid for the local node";
1835  return -1;
1836  }
1837 
1838  if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
1839  totem_config->transport_number == TOTEM_TRANSPORT_UDPU) && (!totem_config->node_id)) {
1840 
1841  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
1842  icmap_get_string(tmp_key, &str);
1843 
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";
1847 
1848  free(str);
1849  return (-1);
1850  }
1851 
1852  totem_config->interfaces[0].member_list[local_node_pos].nodeid = totem_config->node_id;
1853 
1854  free(str);
1855  }
1856 
1857  /* Users must not change this */
1858  icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
1859  }
1860 
1861  if (put_nodelist_members_to_config(totem_config, 0, error_string)) {
1862  return -1;
1863  }
1864  }
1865 
1866  /*
1867  * Get things that might change in the future (and can depend on totem_config->interfaces);
1868  */
1869  totem_volatile_config_read(totem_config, NULL);
1870 
1871  calc_knet_ping_timers(totem_config);
1872 
1873  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
1874 
1875  add_totem_config_notification(totem_config);
1876 
1877  return 0;
1878 }
1879 
1880 
1882  struct totem_config *totem_config,
1883  const char **error_string)
1884 {
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;
1889  int i,j;
1890  uint32_t u32;
1891  int num_configured = 0;
1892  unsigned int interface_max = INTERFACE_MAX;
1893 
1894  for (i = 0; i < INTERFACE_MAX; i++) {
1895  if (totem_config->interfaces[i].configured) {
1896  num_configured++;
1897  }
1898  }
1899  if (num_configured == 0) {
1900  error_reason = "No interfaces defined";
1901  goto parse_error;
1902  }
1903 
1904  /* Check we found a local node name */
1905  if (icmap_get_uint32("nodelist.local_node_pos", &u32) != CS_OK) {
1906  error_reason = "No valid name found for local host";
1907  goto parse_error;
1908  }
1909 
1910  for (i = 0; i < INTERFACE_MAX; i++) {
1911  /*
1912  * Some error checking of parsed data to make sure its valid
1913  */
1914 
1915  struct totem_ip_address null_addr;
1916 
1917  if (!totem_config->interfaces[i].configured) {
1918  continue;
1919  }
1920 
1921  memset (&null_addr, 0, sizeof (struct totem_ip_address));
1922 
1923  if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP) &&
1924  memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr,
1925  sizeof (struct totem_ip_address)) == 0) {
1926  error_reason = "No multicast address specified";
1927  goto parse_error;
1928  }
1929 
1930  if (totem_config->interfaces[i].ip_port == 0) {
1931  error_reason = "No multicast port specified";
1932  goto parse_error;
1933  }
1934 
1935  if (totem_config->interfaces[i].ttl > 255) {
1936  error_reason = "Invalid TTL (should be 0..255)";
1937  goto parse_error;
1938  }
1939  if (totem_config->transport_number != TOTEM_TRANSPORT_UDP &&
1940  totem_config->interfaces[i].ttl != 1) {
1941  error_reason = "Can only set ttl on multicast transport types";
1942  goto parse_error;
1943  }
1944  if (totem_config->interfaces[i].knet_link_priority > 255) {
1945  error_reason = "Invalid link priority (should be 0..255)";
1946  goto parse_error;
1947  }
1948  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET &&
1949  totem_config->interfaces[i].knet_link_priority != 1) {
1950  error_reason = "Can only set link priority on knet transport type";
1951  goto parse_error;
1952  }
1953 
1954  if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 &&
1955  totem_config->node_id == 0) {
1956 
1957  error_reason = "An IPV6 network requires that a node ID be specified.";
1958  goto parse_error;
1959  }
1960 
1961  if (totem_config->broadcast_use == 0 && totem_config->transport_number == TOTEM_TRANSPORT_UDP) {
1962  if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) {
1963  error_reason = "Multicast address family does not match bind address family";
1964  goto parse_error;
1965  }
1966 
1967  if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) {
1968  error_reason = "mcastaddr is not a correct multicast address.";
1969  goto parse_error;
1970  }
1971  }
1972  /* Verify that all nodes on the same knet link have the same IP family */
1973  for (j=1; j<totem_config->interfaces[i].member_count; j++) {
1974  if (totem_config->interfaces[i].configured) {
1975  if (totem_config->interfaces[i].member_list[j].family !=
1976  totem_config->interfaces[i].member_list[0].family) {
1977  memcpy(addr_str_buf,
1978  totemip_print(&(totem_config->interfaces[i].member_list[j])),
1979  sizeof(addr_str_buf));
1980 
1981  snprintf (local_error_reason, sizeof(local_error_reason),
1982  "Nodes for link %d have different IP families "
1983  "(compared %s with %s)", i,
1984  addr_str_buf,
1985  totemip_print(&(totem_config->interfaces[i].member_list[0])));
1986  goto parse_error;
1987  }
1988  }
1989  }
1990  }
1991 
1992  if (totem_config->version != 2) {
1993  error_reason = "This totem parser can only parse version 2 configurations.";
1994  goto parse_error;
1995  }
1996 
1997  if (totem_volatile_config_validate(totem_config, error_string) == -1) {
1998  return (-1);
1999  }
2000 
2001  if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
2002  return (-1);
2003  }
2004 
2005  /*
2006  * KNET Link values validation
2007  */
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);
2013  goto parse_error;
2014  }
2015 
2016  /* Only Knet does multiple interfaces */
2017  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
2018  interface_max = 1;
2019  }
2020 
2021  if (interface_max < num_configured) {
2022  snprintf (parse_error, sizeof(parse_error),
2023  "%d is too many configured interfaces for non-Knet transport.",
2024  num_configured);
2025  error_reason = parse_error;
2026  goto parse_error;
2027  }
2028 
2029  /* Only knet allows crypto */
2030  if (totem_config->transport_number != TOTEM_TRANSPORT_KNET) {
2031  if ((strcmp(totem_config->crypto_cipher_type, "none") != 0) ||
2032  (strcmp(totem_config->crypto_hash_type, "none") != 0)) {
2033 
2034  snprintf (parse_error, sizeof(parse_error),
2035  "crypto_cipher & crypto_hash are only valid for the Knet transport.");
2036  error_reason = parse_error;
2037  goto parse_error;
2038  }
2039  }
2040 
2041  if (totem_config->net_mtu == 0) {
2042  if (totem_config->transport_number == TOTEM_TRANSPORT_KNET) {
2043  totem_config->net_mtu = KNET_MAX_PACKET_SIZE;
2044  }
2045  else {
2046  totem_config->net_mtu = 1500;
2047  }
2048  }
2049 
2050  return 0;
2051 
2052 parse_error:
2053  snprintf (error_string_response, sizeof(error_string_response),
2054  "parse error in config: %s\n", error_reason);
2055  *error_string = error_string_response;
2056  return (-1);
2057 
2058 }
2059 
2060 static int read_keyfile (
2061  const char *key_location,
2062  struct totem_config *totem_config,
2063  const char **error_string)
2064 {
2065  int fd;
2066  int res;
2067  int saved_errno;
2068  char error_str[100];
2069  const char *error_ptr;
2070 
2071  fd = open (key_location, O_RDONLY);
2072  if (fd == -1) {
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);
2077  goto parse_error;
2078  }
2079 
2080  res = read (fd, totem_config->private_key, TOTEM_PRIVATE_KEY_LEN_MAX);
2081  saved_errno = errno;
2082  close (fd);
2083 
2084  if (res == -1) {
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);
2089  goto parse_error;
2090  }
2091 
2092  if (res < TOTEM_PRIVATE_KEY_LEN_MIN) {
2093  snprintf (error_string_response, sizeof(error_string_response),
2094  "Could only read %d bits of minimum %u bits from %s.\n",
2095  res * 8, TOTEM_PRIVATE_KEY_LEN_MIN * 8, key_location);
2096  goto parse_error;
2097  }
2098 
2099  totem_config->private_key_len = res;
2100 
2101  return 0;
2102 
2103 parse_error:
2104  *error_string = error_string_response;
2105  return (-1);
2106 }
2107 
2109  struct totem_config *totem_config,
2110  const char **error_string)
2111 {
2112  int got_key = 0;
2113  char *key_location = NULL;
2114  int res;
2115  size_t key_len;
2116 
2117  memset (totem_config->private_key, 0, sizeof(totem_config->private_key));
2118  totem_config->private_key_len = 0;
2119 
2120  if (strcmp(totem_config->crypto_cipher_type, "none") == 0 &&
2121  strcmp(totem_config->crypto_hash_type, "none") == 0) {
2122  return (0);
2123  }
2124 
2125  /* cmap may store the location of the key file */
2126  if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) {
2127  res = read_keyfile(key_location, totem_config, error_string);
2128  free(key_location);
2129  if (res) {
2130  goto key_error;
2131  }
2132  got_key = 1;
2133  } else { /* Or the key itself may be in the cmap */
2134  if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) {
2135  if (key_len > sizeof(totem_config->private_key)) {
2136  sprintf(error_string_response, "key is too long");
2137  goto key_error;
2138  }
2139  if (key_len < TOTEM_PRIVATE_KEY_LEN_MIN) {
2140  sprintf(error_string_response, "key is too short");
2141  goto key_error;
2142  }
2143  if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) {
2144  totem_config->private_key_len = key_len;
2145  got_key = 1;
2146  } else {
2147  sprintf(error_string_response, "can't load private key");
2148  goto key_error;
2149  }
2150  }
2151  }
2152 
2153  /* In desperation we read the default filename */
2154  if (!got_key) {
2155  res = read_keyfile(COROSYSCONFDIR "/authkey", totem_config, error_string);
2156  if (res)
2157  goto key_error;
2158  }
2159 
2160  return (0);
2161 
2162 key_error:
2163  *error_string = error_string_response;
2164  return (-1);
2165 
2166 }
2167 
2168 static void debug_dump_totem_config(const struct totem_config *totem_config)
2169 {
2170 
2171  log_printf(LOGSYS_LEVEL_DEBUG, "Token Timeout (%d ms) retransmit timeout (%d ms)",
2172  totem_config->token_timeout, totem_config->token_retransmit_timeout);
2173  if (totem_config->token_warning) {
2174  uint32_t token_warning_ms = totem_config->token_warning * totem_config->token_timeout / 100;
2175  log_printf(LOGSYS_LEVEL_DEBUG, "Token warning every %d ms (%d%% of Token Timeout)",
2176  token_warning_ms, totem_config->token_warning);
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.",
2181  token_warning_ms, totem_config->token_retransmit_timeout);
2182 
2183  } else
2184  log_printf(LOGSYS_LEVEL_DEBUG, "Token warnings disabled");
2185  log_printf(LOGSYS_LEVEL_DEBUG, "token hold (%d ms) retransmits before loss (%d retrans)",
2186  totem_config->token_hold_timeout, totem_config->token_retransmits_before_loss_const);
2187  log_printf(LOGSYS_LEVEL_DEBUG, "join (%d ms) send_join (%d ms) consensus (%d ms) merge (%d ms)",
2188  totem_config->join_timeout, totem_config->send_join_timeout, totem_config->consensus_timeout,
2189  totem_config->merge_timeout);
2190  log_printf(LOGSYS_LEVEL_DEBUG, "downcheck (%d ms) fail to recv const (%d msgs)",
2191  totem_config->downcheck_timeout, totem_config->fail_to_recv_const);
2193  "seqno unchanged const (%d rotations) Maximum network MTU %d",
2194  totem_config->seqno_unchanged_const, totem_config->net_mtu);
2196  "window size per rotation (%d messages) maximum messages per rotation (%d messages)",
2197  totem_config->window_size, totem_config->max_messages);
2198  log_printf(LOGSYS_LEVEL_DEBUG, "missed count const (%d messages)", totem_config->miss_count_const);
2199  log_printf(LOGSYS_LEVEL_DEBUG, "heartbeat_failures_allowed (%d)",
2200  totem_config->heartbeat_failures_allowed);
2201  log_printf(LOGSYS_LEVEL_DEBUG, "max_network_delay (%d ms)", totem_config->max_network_delay);
2202 }
2203 
2204 static void totem_change_notify(
2205  int32_t event,
2206  const char *key_name,
2207  struct icmap_notify_value new_val,
2208  struct icmap_notify_value old_val,
2209  void *user_data)
2210 {
2211  struct totem_config *totem_config = (struct totem_config *)user_data;
2212  uint32_t *param;
2213  uint8_t reloading;
2214  const char *deleted_key = NULL;
2215  const char *error_string;
2216 
2217  /*
2218  * If a full reload is in progress then don't do anything until it's done and
2219  * can reconfigure it all atomically
2220  */
2221  if (icmap_get_uint8("config.reload_in_progress", &reloading) == CS_OK && reloading)
2222  return;
2223 
2224  param = totem_get_param_by_name((struct totem_config *)user_data, key_name);
2225  /*
2226  * Process change only if changed key is found in totem_config (-> param is not NULL)
2227  * or for special key token_coefficient. token_coefficient key is not stored in
2228  * totem_config, but it is used for computation of token timeout.
2229  */
2230  if (!param && strcmp(key_name, "totem.token_coefficient") != 0)
2231  return;
2232 
2233  /*
2234  * Values other than UINT32 are not supported, or needed (yet)
2235  */
2236  switch (event) {
2237  case ICMAP_TRACK_DELETE:
2238  deleted_key = key_name;
2239  break;
2240  case ICMAP_TRACK_ADD:
2241  case ICMAP_TRACK_MODIFY:
2242  deleted_key = NULL;
2243  break;
2244  default:
2245  break;
2246  }
2247 
2248  totem_volatile_config_read (totem_config, deleted_key);
2249  log_printf(LOGSYS_LEVEL_DEBUG, "Totem related config key changed. Dumping actual totem config.");
2250  debug_dump_totem_config(totem_config);
2251  if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2252  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
2253  /*
2254  * TODO: Consider corosync exit and/or load defaults for volatile
2255  * values. For now, log error seems to be enough
2256  */
2257  }
2258 }
2259 
2260 static void totem_reload_notify(
2261  int32_t event,
2262  const char *key_name,
2263  struct icmap_notify_value new_val,
2264  struct icmap_notify_value old_val,
2265  void *user_data)
2266 {
2267  struct totem_config *totem_config = (struct totem_config *)user_data;
2268  const char *error_string;
2269  uint64_t warnings;
2270 
2271  /* Reload has completed */
2272  if (*(uint8_t *)new_val.data == 0) {
2273 
2274  totem_config->orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
2275  assert(totem_config->orig_interfaces != NULL);
2276  memcpy(totem_config->orig_interfaces, totem_config->interfaces, sizeof (struct totem_interface) * INTERFACE_MAX);
2277 
2278  get_interface_params(totem_config, &error_string, &warnings, 1);
2279  if (put_nodelist_members_to_config (totem_config, 1, &error_string)) {
2280  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
2281  }
2282  totem_volatile_config_read (totem_config, NULL);
2283 
2284  calc_knet_ping_timers(totem_config);
2285 
2286  log_printf(LOGSYS_LEVEL_DEBUG, "Configuration reloaded. Dumping actual totem config.");
2287  debug_dump_totem_config(totem_config);
2288  if (totem_volatile_config_validate(totem_config, &error_string) == -1) {
2289  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
2290  /*
2291  * TODO: Consider corosync exit and/or load defaults for volatile
2292  * values. For now, log error seems to be enough
2293  */
2294  }
2295 
2296  /* Reinstate the local_node_pos */
2297  (void)find_local_node(0);
2298 
2299  /* Reconfigure network params as appropriate */
2301 
2302  free(totem_config->orig_interfaces);
2303 
2304  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
2305  } else {
2306  icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
2307  }
2308 }
2309 
2310 static void add_totem_config_notification(struct totem_config *totem_config)
2311 {
2313 
2314  icmap_track_add("totem.",
2316  totem_change_notify,
2317  totem_config,
2318  &icmap_track);
2319 
2320  icmap_track_add("config.reload_in_progress",
2322  totem_reload_notify,
2323  totem_config,
2324  &icmap_track);
2325 }
unsigned int clear_node_high_bit
Definition: totem.h:161
unsigned short family
Definition: coroapi.h:113
int totempg_iface_set(struct totem_ip_address *interface_addr, unsigned short ip_port, unsigned int iface_no)
Definition: totempg.c:1434
int knet_ping_precision
Definition: totem.h:92
#define BLOCK_UNLISTED_IPS
Definition: totemconfig.c:82
#define min(a, b)
Definition: exec/util.h:66
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
Definition: icmap.c:1093
#define LOGSYS_LEVEL_INFO
Definition: logsys.h:75
int knet_link_priority
Definition: totem.h:89
uint32_t value
struct totem_interface * interfaces
Definition: totem.h:158
totem_ip_version_enum
Definition: totemip.h:70
The totem_ip_address struct.
Definition: coroapi.h:111
#define DEFAULT_PORT
Definition: totemconfig.c:92
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:264
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1114
totem_transport_t transport_number
Definition: totem.h:230
#define CS_PRI_NODE_ID
Definition: corotypes.h:59
#define DOWNCHECK_TIMEOUT
Definition: totemconfig.c:73
unsigned int token_hold_timeout
Definition: totem.h:180
int member_count
Definition: totem.h:88
struct totem_ip_address member_list[PROCESSOR_COUNT_MAX]
Definition: totem.h:95
uint32_t knet_compression_threshold
Definition: totem.h:226
#define TOKEN_WARNING
Definition: totemconfig.c:69
char link_mode[TOTEM_LINK_MODE_BYTES]
Definition: totem.h:198
unsigned int knet_pmtud_interval
Definition: totem.h:162
char * crypto_model
Definition: totem.h:218
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
#define COROSYSCONFDIR
Definition: config.h:11
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:625
int totemip_is_mcast(struct totem_ip_address *addr)
Definition: totemip.c:142
unsigned int downcheck_timeout
Definition: totem.h:192
#define KNET_DEFAULT_TRANSPORT
Definition: totemconfig.c:90
unsigned int private_key_len
Definition: totem.h:169
#define SEQNO_UNCHANGED_CONST
Definition: totemconfig.c:75
unsigned int max_network_delay
Definition: totem.h:208
#define log_printf(level, format, args...)
Definition: logsys.h:323
unsigned int heartbeat_failures_allowed
Definition: totem.h:206
unsigned int send_join_timeout
Definition: totem.h:186
unsigned int window_size
Definition: totem.h:210
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
Definition: icmap.c:884
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
#define INTERFACE_MAX
Definition: coroapi.h:88
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
unsigned int block_unlisted_ips
Definition: totem.h:236
#define MINIMUM_TIMEOUT
Definition: totemconfig.c:76
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
Definition: icmap.c:866
uint16_t ttl
Definition: totem.h:86
unsigned int node_id
Definition: totem.h:160
int totem_config_keyread(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:2108
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
unsigned int token_retransmits_before_loss_const
Definition: totem.h:182
uint8_t configured
Definition: totem.h:87
char * knet_compression_model
Definition: totem.h:224
#define FAIL_TO_RECV_CONST
Definition: totemconfig.c:74
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:595
unsigned int seqno_unchanged_const
Definition: totem.h:196
void * user_data
Definition: sam.c:127
unsigned int miss_count_const
Definition: totem.h:232
unsigned int join_timeout
Definition: totem.h:184
int totem_config_validate(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:1881
const void * data
Definition: icmap.h:94
unsigned int nodeid
Definition: coroapi.h:112
#define TOTEM_CONFIG_BINDNETADDR_NODELIST_SET
Definition: totemconfig.h:48
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
int knet_transport
Definition: totem.h:94
char * crypto_hash_type
Definition: totem.h:222
struct totem_ip_address mcast_addr
Definition: totem.h:84
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:72
unsigned char private_key[TOTEM_PRIVATE_KEY_LEN_MAX]
Definition: totem.h:167
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.
Definition: icmap.c:723
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:76
cs_error_t icmap_set_uint16(const char *key_name, uint16_t value)
Definition: icmap.c:583
unsigned int fail_to_recv_const
Definition: totem.h:194
#define TOKEN_COEFFICIENT
Definition: totemconfig.c:70
int totempg_member_remove(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1552
#define TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
Definition: totemconfig.h:46
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:890
uint8_t param
#define TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
Definition: totemconfig.h:45
uint16_t ip_port
Definition: totem.h:85
int knet_compression_level
Definition: totem.h:228
int totemip_parse(struct totem_ip_address *totemip, const char *addr, enum totem_ip_version_enum ip_version)
Definition: totemip.c:314
#define swab32(x)
The swab32 macro.
Definition: swab.h:51
#define WINDOW_SIZE
Definition: totemconfig.c:79
int version
Definition: totem.h:153
unsigned int net_mtu
Definition: totem.h:202
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
Definition: icmap.c:589
#define MAX_NETWORK_DELAY
Definition: totemconfig.c:78
#define TOKEN_TIMEOUT
Definition: totemconfig.c:68
#define MERGE_TIMEOUT
Definition: totemconfig.c:72
unsigned int token_timeout
Definition: totem.h:174
#define JOIN_TIMEOUT
Definition: totemconfig.c:71
unsigned int consensus_timeout
Definition: totem.h:188
#define PROCESSOR_COUNT_MAX
Definition: coroapi.h:96
unsigned int token_warning
Definition: totem.h:176
int totempg_reconfigure(void)
Definition: totempg.c:1559
#define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST
Definition: totemconfig.c:67
#define MISS_COUNT_CONST
Definition: totemconfig.c:81
unsigned int broadcast_use
Definition: totem.h:216
#define KNET_PING_PRECISION
Definition: totemconfig.c:87
struct totem_interface * orig_interfaces
Definition: totem.h:159
#define KNET_PONG_COUNT
Definition: totemconfig.c:88
int knet_pong_count
Definition: totem.h:93
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
Definition: icmap.c:854
int knet_ping_interval
Definition: totem.h:90
int knet_ping_timeout
Definition: totem.h:91
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:571
#define KNET_PMTUD_INTERVAL
Definition: totemconfig.c:89
unsigned int max_messages
Definition: totem.h:212
char * crypto_cipher_type
Definition: totem.h:220
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.
Definition: icmap.c:1223
unsigned int merge_timeout
Definition: totem.h:190
enum totem_ip_version_enum ip_version
Definition: totem.h:234
unsigned int token_retransmit_timeout
Definition: totem.h:178
struct totem_ip_address bindnet
Definition: totem.h:82
unsigned int nodeid
Definition: coroapi.h:75
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1087
cs_error_t icmap_get_uint16(const char *key_name, uint16_t *u16)
Definition: icmap.c:878
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
Definition: totemconfig.h:47
#define MAX_MESSAGES
Definition: totemconfig.c:80
#define MINIMUM_TIMEOUT_HOLD
Definition: totemconfig.c:77
unsigned int threads
Definition: totem.h:204
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
Structure passed as new_value and old_value in change callback.
Definition: icmap.h:91
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.
Definition: icmap.c:1157
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
Definition: totemconfig.c:1673
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
Definition: icmap.h:85
int totempg_member_add(const struct totem_ip_address *member, int ring_no)
Definition: totempg.c:1545