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